History

Revert "Optimize vswap()"

This reverts commit 63193d1794b037eb4f3b6551596fa8a6d423e0c3. Had some problems (_STATIC_ASSERT) and was too ugly anyway. For retry, I'd suggest to implement a general function static inline void memswap (void *p1, void* p2, size_t n); and then use that. If you do so, please keep the original code as comment.

grischka committed 13 years ago

Commit c5892fe1 parent 2daf8b92 files · +8 −33Browse files

Unified · Split

2 files
  1. tcc.h +0 −4
  2. tccgen.c +8 −29
tcc.h+0−4
@@ -228,10 +228,6 @@ · 227 unmodified lines
228228 #define true 1
229229 typedef int BOOL;
230230
231−#ifndef _STATIC_ASSERT
232−#define _STATIC_ASSERT(cond) do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
233−#endif
234−
235231 #define INCLUDE_STACK_SIZE 32
236232 #define IFDEF_STACK_SIZE 64
237233 #define VSTACK_SIZE 256
tccgen.c+8−29
@@ -458,7 +458,7 @@ static void vseti(int r, int v) · 457 unmodified lines
458458
459459 ST_FUNC void vswap(void)
460460 {
461− unsigned long *vtopl;
461+ SValue tmp;
462462 /* cannot let cpu flags if other instruction are generated. Also
463463 avoid leaving VT_JMP anywhere except on the top of the stack
464464 because it would complicate the code generator. */
@@ -467,35 +467,14 @@ ST_FUNC void vswap(void) · 2 unmodified lines
467467 if (v == VT_CMP || (v & ~1) == VT_JMP)
468468 gv(RC_INT);
469469 }
470+ tmp = vtop[0];
471+ vtop[0] = vtop[-1];
472+ vtop[-1] = tmp;
470473
471− /*
472− * vtop[0], vtop[-1] = vtop[-1], vtop[0]
473− *
474− * vswap is called often and exchanging vtop[0] vs vtop[-1] is hot on
475− * profile, so it is hand optimized
476− */
477− vtopl = (unsigned long *) vtop;
478−# define VSIZEL (sizeof(*vtop) / sizeof(*vtopl))
479−
480− _STATIC_ASSERT( VSIZEL*sizeof(*vtopl) == sizeof(*vtop) );
481− _STATIC_ASSERT( VSIZEL <= 16 ); /* should be enough */
482− switch(VSIZEL) {
483−# define VSWAPL(i) \
484− case i+1: { \
485− unsigned long tmpl; \
486− tmpl = vtopl[i]; \
487− vtopl[i] = vtopl[-1*VSIZEL + i]; \
488− vtopl[-1*VSIZEL + i] = tmpl; \
489− } do {} while (0)
490−
491− VSWAPL(15); VSWAPL(14); VSWAPL(13); VSWAPL(12);
492− VSWAPL(11); VSWAPL(10); VSWAPL( 9); VSWAPL( 8);
493− VSWAPL( 7); VSWAPL( 6); VSWAPL( 5); VSWAPL( 4);
494− VSWAPL( 3); VSWAPL( 2); VSWAPL( 1); VSWAPL( 0);
495− }
496−
497−# undef VSWAPL
498−# undef VSIZEL
474+/* XXX: +2% overall speed possible with optimized memswap
475+ *
476+ * memswap(&vtop[0], &vtop[1], sizeof *vtop);
477+ */
499478 }
500479
501480 ST_FUNC void vpushv(SValue *v)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t