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.
Unified · Split
| @@ -228,10 +228,6 @@ · 227 unmodified lines | ||
| 228 | 228 | #define true 1 |
| 229 | 229 | typedef int BOOL; |
| 230 | 230 | |
| 231 | −#ifndef _STATIC_ASSERT | |
| 232 | −#define _STATIC_ASSERT(cond) do { (void) sizeof(char [1 - 2*!(cond)]); } while(0) | |
| 233 | −#endif | |
| 234 | − | |
| 235 | 231 | #define INCLUDE_STACK_SIZE 32 |
| 236 | 232 | #define IFDEF_STACK_SIZE 64 |
| 237 | 233 | #define VSTACK_SIZE 256 |
| @@ -458,7 +458,7 @@ static void vseti(int r, int v) · 457 unmodified lines | ||
| 458 | 458 | |
| 459 | 459 | ST_FUNC void vswap(void) |
| 460 | 460 | { |
| 461 | − unsigned long *vtopl; | |
| 461 | + SValue tmp; | |
| 462 | 462 | /* cannot let cpu flags if other instruction are generated. Also |
| 463 | 463 | avoid leaving VT_JMP anywhere except on the top of the stack |
| 464 | 464 | because it would complicate the code generator. */ |
| @@ -467,35 +467,14 @@ ST_FUNC void vswap(void) · 2 unmodified lines | ||
| 467 | 467 | if (v == VT_CMP || (v & ~1) == VT_JMP) |
| 468 | 468 | gv(RC_INT); |
| 469 | 469 | } |
| 470 | + tmp = vtop[0]; | |
| 471 | + vtop[0] = vtop[-1]; | |
| 472 | + vtop[-1] = tmp; | |
| 470 | 473 | |
| 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 | + */ | |
| 499 | 478 | } |
| 500 | 479 | |
| 501 | 480 | ST_FUNC void vpushv(SValue *v) |