--- embedaddon/pcre/sljit/sljitNativeX86_64.c 2012/02/21 23:50:25 1.1.1.2 +++ embedaddon/pcre/sljit/sljitNativeX86_64.c 2012/10/09 09:19:18 1.1.1.3 @@ -97,6 +97,9 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct s compiler->temporaries = temporaries; compiler->saveds = saveds; compiler->flags_saved = 0; +#if (defined SLJIT_DEBUG && SLJIT_DEBUG) + compiler->logical_local_size = local_size; +#endif size = saveds; /* Including the return address saved by the call instruction. */ @@ -105,12 +108,6 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct s if (saveds >= 2) size += saveds - 1; #else - /* Saving the virtual stack pointer. */ - compiler->has_locals = local_size > 0; - if (local_size > 0) { - size += 2; - pushed_size += sizeof(sljit_w); - } if (saveds >= 4) size += saveds - 3; if (temporaries >= 5) { @@ -162,11 +159,6 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct s *buf++ = REX_B; PUSH_REG(reg_lmap[SLJIT_TEMPORARY_EREG2]); } - if (local_size > 0) { - SLJIT_COMPILE_ASSERT(reg_map[SLJIT_LOCALS_REG] >= 8, locals_reg_is_hireg); - *buf++ = REX_B; - PUSH_REG(reg_lmap[SLJIT_LOCALS_REG]); - } #endif #ifndef _WIN64 @@ -204,12 +196,11 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct s #endif } - local_size = ((local_size + pushed_size + 16 - 1) & ~(16 - 1)) - pushed_size; -#ifdef _WIN64 - local_size += 4 * sizeof(sljit_w); + local_size = ((local_size + FIXED_LOCALS_OFFSET + pushed_size + 16 - 1) & ~(16 - 1)) - pushed_size; compiler->local_size = local_size; +#ifdef _WIN64 if (local_size > 1024) { - /* Allocate the stack for the function itself. */ + /* Allocate stack for the callback, which grows the stack. */ buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); FAIL_IF(!buf); INC_SIZE(4); @@ -226,48 +217,29 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct s local_size -= 4 * sizeof(sljit_w); } FAIL_IF(emit_load_imm64(compiler, SLJIT_TEMPORARY_REG1, local_size)); - FAIL_IF(sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_touch_stack))); + FAIL_IF(sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_grow_stack))); } -#else - compiler->local_size = local_size; - if (local_size > 0) { #endif - /* In case of Win64, local_size is always > 4 * sizeof(sljit_w) */ - if (local_size <= 127) { - buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); - FAIL_IF(!buf); - INC_SIZE(4); - *buf++ = REX_W; - *buf++ = 0x83; - *buf++ = 0xc0 | (5 << 3) | 4; - *buf++ = local_size; - } - else { - buf = (sljit_ub*)ensure_buf(compiler, 1 + 7); - FAIL_IF(!buf); - INC_SIZE(7); - *buf++ = REX_W; - *buf++ = 0x81; - *buf++ = 0xc0 | (5 << 3) | 4; - *(sljit_hw*)buf = local_size; - buf += sizeof(sljit_hw); - } -#ifndef _WIN64 + SLJIT_ASSERT(local_size > 0); + if (local_size <= 127) { + buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); + FAIL_IF(!buf); + INC_SIZE(4); + *buf++ = REX_W; + *buf++ = 0x83; + *buf++ = 0xc0 | (5 << 3) | 4; + *buf++ = local_size; } -#endif - -#ifdef _WIN64 - if (compiler->has_locals) { - buf = (sljit_ub*)ensure_buf(compiler, 1 + 5); + else { + buf = (sljit_ub*)ensure_buf(compiler, 1 + 7); FAIL_IF(!buf); - INC_SIZE(5); - *buf++ = REX_W | REX_R; - *buf++ = 0x8d; - *buf++ = 0x40 | (reg_lmap[SLJIT_LOCALS_REG] << 3) | 0x4; - *buf++ = 0x24; - *buf = 4 * sizeof(sljit_w); + INC_SIZE(7); + *buf++ = REX_W; + *buf++ = 0x81; + *buf++ = 0xc0 | (5 << 3) | 4; + *(sljit_hw*)buf = local_size; + buf += sizeof(sljit_hw); } -#endif return SLJIT_SUCCESS; } @@ -281,19 +253,17 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct compiler->temporaries = temporaries; compiler->saveds = saveds; +#if (defined SLJIT_DEBUG && SLJIT_DEBUG) + compiler->logical_local_size = local_size; +#endif + /* Including the return address saved by the call instruction. */ pushed_size = (saveds + 1) * sizeof(sljit_w); #ifdef _WIN64 - compiler->has_locals = local_size > 0; - if (local_size > 0) - pushed_size += sizeof(sljit_w); if (temporaries >= 5) pushed_size += sizeof(sljit_w); #endif - compiler->local_size = ((local_size + pushed_size + 16 - 1) & ~(16 - 1)) - pushed_size; -#ifdef _WIN64 - compiler->local_size += 4 * sizeof(sljit_w); -#endif + compiler->local_size = ((local_size + FIXED_LOCALS_OFFSET + pushed_size + 16 - 1) & ~(16 - 1)) - pushed_size; } SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw) @@ -303,38 +273,36 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct CHECK_ERROR(); check_sljit_emit_return(compiler, op, src, srcw); + ADJUST_LOCAL_OFFSET(src, srcw); compiler->flags_saved = 0; FAIL_IF(emit_mov_before_return(compiler, op, src, srcw)); - if (compiler->local_size > 0) { - if (compiler->local_size <= 127) { - buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); - FAIL_IF(!buf); - INC_SIZE(4); - *buf++ = REX_W; - *buf++ = 0x83; - *buf++ = 0xc0 | (0 << 3) | 4; - *buf = compiler->local_size; - } - else { - buf = (sljit_ub*)ensure_buf(compiler, 1 + 7); - FAIL_IF(!buf); - INC_SIZE(7); - *buf++ = REX_W; - *buf++ = 0x81; - *buf++ = 0xc0 | (0 << 3) | 4; - *(sljit_hw*)buf = compiler->local_size; - } + SLJIT_ASSERT(compiler->local_size > 0); + if (compiler->local_size <= 127) { + buf = (sljit_ub*)ensure_buf(compiler, 1 + 4); + FAIL_IF(!buf); + INC_SIZE(4); + *buf++ = REX_W; + *buf++ = 0x83; + *buf++ = 0xc0 | (0 << 3) | 4; + *buf = compiler->local_size; } + else { + buf = (sljit_ub*)ensure_buf(compiler, 1 + 7); + FAIL_IF(!buf); + INC_SIZE(7); + *buf++ = REX_W; + *buf++ = 0x81; + *buf++ = 0xc0 | (0 << 3) | 4; + *(sljit_hw*)buf = compiler->local_size; + } size = 1 + compiler->saveds; #ifndef _WIN64 if (compiler->saveds >= 2) size += compiler->saveds - 1; #else - if (compiler->has_locals) - size += 2; if (compiler->saveds >= 4) size += compiler->saveds - 3; if (compiler->temporaries >= 5) @@ -346,10 +314,6 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct INC_SIZE(size); #ifdef _WIN64 - if (compiler->has_locals) { - *buf++ = REX_B; - POP_REG(reg_lmap[SLJIT_LOCALS_REG]); - } if (compiler->temporaries >= 5) { *buf++ = REX_B; POP_REG(reg_lmap[SLJIT_TEMPORARY_EREG2]); @@ -475,10 +439,8 @@ static sljit_ub* emit_x86_instruction(struct sljit_com } } -#ifndef _WIN64 - if ((b & 0xf) == SLJIT_LOCALS_REG && (b & 0xf0) == 0) + if ((b & 0xf) == SLJIT_LOCALS_REG && !(b & 0xf0)) b |= SLJIT_LOCALS_REG << 4; -#endif if ((b & 0xf0) != SLJIT_UNUSED) { inst_size += 1; /* SIB byte. */ @@ -580,9 +542,6 @@ static sljit_ub* emit_x86_instruction(struct sljit_com *buf_ptr++ |= 0xc0 + reg_lmap[b]; #endif else if ((b & 0x0f) != SLJIT_UNUSED) { -#ifdef _WIN64 - SLJIT_ASSERT((b & 0xf0) != (SLJIT_LOCALS_REG << 4)); -#endif if ((b & 0xf0) == SLJIT_UNUSED || (b & 0xf0) == (SLJIT_LOCALS_REG << 4)) { if (immb != 0) { if (immb <= 127 && immb >= -128) @@ -671,20 +630,14 @@ static SLJIT_INLINE int call_with_args(struct sljit_co return SLJIT_SUCCESS; } -SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw, int args, int temporaries, int saveds, int local_size) +SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw) { sljit_ub *buf; CHECK_ERROR(); - check_sljit_emit_fast_enter(compiler, dst, dstw, args, temporaries, saveds, local_size); + check_sljit_emit_fast_enter(compiler, dst, dstw); + ADJUST_LOCAL_OFFSET(dst, dstw); - compiler->temporaries = temporaries; - compiler->saveds = saveds; - compiler->local_size = (local_size + sizeof(sljit_uw) - 1) & ~(sizeof(sljit_uw) - 1); -#ifdef _WIN64 - compiler->local_size += 4 * sizeof(sljit_w); -#endif - /* For UNUSED dst. Uncommon, but possible. */ if (dst == SLJIT_UNUSED) dst = TMP_REGISTER; @@ -707,10 +660,8 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_enter(str } } else if (dst & SLJIT_MEM) { -#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) /* REX_W is not necessary (src is not immediate). */ compiler->mode32 = 1; -#endif buf = emit_x86_instruction(compiler, 1, 0, 0, dst, dstw); FAIL_IF(!buf); *buf++ = 0x8f; @@ -724,9 +675,8 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_return(st CHECK_ERROR(); check_sljit_emit_fast_return(compiler, src, srcw); + ADJUST_LOCAL_OFFSET(src, srcw); - CHECK_EXTRA_REGS(src, srcw, (void)0); - if ((src & SLJIT_IMM) && NOT_HALFWORD(srcw)) { FAIL_IF(emit_load_imm64(compiler, TMP_REGISTER, srcw)); src = TMP_REGISTER; @@ -750,10 +700,8 @@ SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_return(st } } else if (src & SLJIT_MEM) { -#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) /* REX_W is not necessary (src is not immediate). */ compiler->mode32 = 1; -#endif buf = emit_x86_instruction(compiler, 1, 0, 0, src, srcw); FAIL_IF(!buf); *buf++ = 0xff;