Logical 'not' must be sign-extended for address operands.

This commit is contained in:
Mike Pall 2009-12-29 01:38:26 +01:00
parent 8a9cfa4b45
commit 374f534715
6 changed files with 35 additions and 27 deletions

View File

@ -37,19 +37,27 @@
|.endif |.endif
| |
|.define RA, ecx |.define RA, ecx
|.if X64; .define RAa, rcx; .else; .define RAa, RA; .endif
|.define RAL, cl |.define RAL, cl
|.define RB, ebp // Must be ebp (C callee-save). |.define RB, ebp // Must be ebp (C callee-save).
|.if X64; .define RBa, rbp; .else; .define RBa, RB; .endif
|.define RC, eax // Must be eax (fcomparepp and others). |.define RC, eax // Must be eax (fcomparepp and others).
|.define RCW, ax |.define RCW, ax
|.define RCH, ah |.define RCH, ah
|.define RCL, al |.define RCL, al
|.define OP, RB |.define OP, RB
|.define RD, RC |.define RD, RC
|.if X64; .define RDa, rax; .else; .define RDa, RD; .endif
|.define RDW, RCW |.define RDW, RCW
|.define RDL, RCL |.define RDL, RCL
|.if X64
|.define RAa, rcx
|.define RBa, rbp
|.define RCa, rax
|.define RDa, rax
|.else
|.define RAa, RA
|.define RBa, RB
|.define RCa, RC
|.define RDa, RD
|.endif
| |
|.if not X64 |.if not X64
|.define FCARG1, ecx // x86 fastcall arguments. |.define FCARG1, ecx // x86 fastcall arguments.
@ -237,7 +245,7 @@
|.macro ins_ABC; movzx RB, RCH; movzx RC, RCL; .endmacro |.macro ins_ABC; movzx RB, RCH; movzx RC, RCL; .endmacro
|.macro ins_AB_; movzx RB, RCH; .endmacro |.macro ins_AB_; movzx RB, RCH; .endmacro
|.macro ins_A_C; movzx RC, RCL; .endmacro |.macro ins_A_C; movzx RC, RCL; .endmacro
|.macro ins_AND; not RD; .endmacro |.macro ins_AND; not RDa; .endmacro
| |
|// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster). |// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster).
|.macro ins_NEXT |.macro ins_NEXT
@ -898,7 +906,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
|->vmeta_tgets: |->vmeta_tgets:
| mov TMP1, RC // RC = GCstr * | mov TMP1, RC // RC = GCstr *
| mov TMP2, LJ_TSTR | mov TMP2, LJ_TSTR
| lea RC, TMP1 // Store temp. TValue in TMP1/TMP2. | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
| cmp PC_OP, BC_GGET | cmp PC_OP, BC_GGET
| jne >1 | jne >1
| lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv. | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv.
@ -919,7 +927,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| fstp TMPQ | fstp TMPQ
|.endif |.endif
} }
| lea RC, TMP1 // Store temp. TValue in TMP1/TMP2. | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
| jmp >1 | jmp >1
| |
|->vmeta_tgetv: |->vmeta_tgetv:
@ -933,7 +941,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| mov L:CARG1d, SAVE_L | mov L:CARG1d, SAVE_L
| mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
| mov CARG2d, RB | mov CARG2d, RB
| mov CARG3d, RC | mov CARG3, RCa // May be 64 bit ptr to stack.
| mov L:RB, L:CARG1d | mov L:RB, L:CARG1d
|.else |.else
| mov ARG2, RB | mov ARG2, RB
@ -971,7 +979,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
|->vmeta_tsets: |->vmeta_tsets:
| mov TMP1, RC // RC = GCstr * | mov TMP1, RC // RC = GCstr *
| mov TMP2, LJ_TSTR | mov TMP2, LJ_TSTR
| lea RC, TMP1 // Store temp. TValue in TMP1/TMP2. | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
| cmp PC_OP, BC_GSET | cmp PC_OP, BC_GSET
| jne >1 | jne >1
| lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv. | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv.
@ -992,7 +1000,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| fstp TMPQ | fstp TMPQ
|.endif |.endif
} }
| lea RC, TMP1 // Store temp. TValue in TMP1/TMP2. | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
| jmp >1 | jmp >1
| |
|->vmeta_tsetv: |->vmeta_tsetv:
@ -1006,7 +1014,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| mov L:CARG1d, SAVE_L | mov L:CARG1d, SAVE_L
| mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
| mov CARG2d, RB | mov CARG2d, RB
| mov CARG3d, RC | mov CARG3, RCa // May be 64 bit ptr to stack.
| mov L:RB, L:CARG1d | mov L:RB, L:CARG1d
|.else |.else
| mov ARG2, RB | mov ARG2, RB
@ -1887,7 +1895,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| |
|7: // Non-standard return case. |7: // Non-standard return case.
| mov BASE, RA | mov BASE, RA
| mov RA, -8 // Results start at BASE+RA = BASE-8. | mov RAa, -8 // Results start at BASE+RA = BASE-8.
| jmp ->vm_return | jmp ->vm_return
| |
if (sse) { if (sse) {
@ -3906,8 +3914,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
| ins_AD // RA = dst, RD = hbits|asize | ins_AD // RA = dst, RD = hbits|asize
|.if X64 |.if X64
| mov L:CARG1d, SAVE_L | mov L:CARG1d, SAVE_L
|1:
| mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
|1:
| mov CARG3d, RD | mov CARG3d, RD
| and RD, 0x7ff | and RD, 0x7ff
| shr CARG3d, 11 | shr CARG3d, 11
@ -3982,7 +3990,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
| mov L:FCARG1, L:RB | mov L:FCARG1, L:RB
| call extern lj_gc_step_fixtop@4 // (lua_State *L) | call extern lj_gc_step_fixtop@4 // (lua_State *L)
| movzx RD, PC_RD // Need to reload RD. | movzx RD, PC_RD // Need to reload RD.
| not RD | not RDa
| jmp <2 | jmp <2
break; break;
@ -4052,7 +4060,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
break; break;
case BC_TGETS: case BC_TGETS:
| ins_ABC // RA = dst, RB = table, RC = str const (~) | ins_ABC // RA = dst, RB = table, RC = str const (~)
| not RC | not RCa
| mov STR:RC, [KBASE+RC*4] | mov STR:RC, [KBASE+RC*4]
| checktab RB, ->vmeta_tgets | checktab RB, ->vmeta_tgets
| mov TAB:RB, [BASE+RB*8] | mov TAB:RB, [BASE+RB*8]
@ -4182,7 +4190,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
break; break;
case BC_TSETS: case BC_TSETS:
| ins_ABC // RA = src, RB = table, RC = str const (~) | ins_ABC // RA = src, RB = table, RC = str const (~)
| not RC | not RCa
| mov STR:RC, [KBASE+RC*4] | mov STR:RC, [KBASE+RC*4]
| checktab RB, ->vmeta_tsets | checktab RB, ->vmeta_tsets
| mov TAB:RB, [BASE+RB*8] | mov TAB:RB, [BASE+RB*8]
@ -4427,7 +4435,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
| test PC, FRAME_TYPE // Lua frame below? | test PC, FRAME_TYPE // Lua frame below?
| jnz <4 | jnz <4
| movzx RD, PC_RA // Need to prepare BASE/KBASE. | movzx RD, PC_RA // Need to prepare BASE/KBASE.
| not RD | not RDa
| lea BASE, [BASE+RD*8] | lea BASE, [BASE+RD*8]
| mov LFUNC:KBASE, [BASE-8] | mov LFUNC:KBASE, [BASE-8]
| mov PROTO:KBASE, LFUNC:KBASE->pt | mov PROTO:KBASE, LFUNC:KBASE->pt
@ -4591,7 +4599,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
break; break;
} }
| movzx RA, PC_RA | movzx RA, PC_RA
| not RA // Note: ~RA = -(RA+1) | not RAa // Note: ~RA = -(RA+1)
| lea BASE, [BASE+RA*8] // base = base - (RA+1)*8 | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8
| mov LFUNC:KBASE, [BASE-8] | mov LFUNC:KBASE, [BASE-8]
| mov PROTO:KBASE, LFUNC:KBASE->pt | mov PROTO:KBASE, LFUNC:KBASE->pt

View File

@ -224,14 +224,14 @@ LJLIB_CF(jit_util_funcbc)
LJLIB_CF(jit_util_funck) LJLIB_CF(jit_util_funck)
{ {
GCproto *pt = check_Lproto(L, 0); GCproto *pt = check_Lproto(L, 0);
MSize idx = (MSize)lj_lib_checkint(L, 2); ptrdiff_t idx = (ptrdiff_t)lj_lib_checkint(L, 2);
if ((int32_t)idx >= 0) { if (idx >= 0) {
if (idx < pt->sizekn) { if (idx < (ptrdiff_t)pt->sizekn) {
setnumV(L->top-1, pt->k.n[idx]); setnumV(L->top-1, pt->k.n[idx]);
return 1; return 1;
} }
} else { } else {
if (~idx < pt->sizekgc) { if (~idx < (ptrdiff_t)pt->sizekgc) {
GCobj *gc = gcref(pt->k.gc[idx]); GCobj *gc = gcref(pt->k.gc[idx]);
setgcV(L, L->top-1, &gc->gch, ~gc->gch.gct); setgcV(L, L->top-1, &gc->gch, ~gc->gch.gct);
return 1; return 1;

View File

@ -107,10 +107,10 @@ restart:
if (ra == slot) { slot = bc_d(ins); goto restart; } if (ra == slot) { slot = bc_d(ins); goto restart; }
break; break;
case BC_GGET: case BC_GGET:
*name = strdata(gco2str(gcref(pt->k.gc[~bc_d(ins)]))); *name = strdata(gco2str(gcref(pt->k.gc[~(ptrdiff_t)bc_d(ins)])));
return "global"; return "global";
case BC_TGETS: case BC_TGETS:
*name = strdata(gco2str(gcref(pt->k.gc[~bc_c(ins)]))); *name = strdata(gco2str(gcref(pt->k.gc[~(ptrdiff_t)bc_c(ins)])));
if (ip > pt->bc) { if (ip > pt->bc) {
BCIns insp = ip[-1]; BCIns insp = ip[-1];
if (bc_op(insp) == BC_MOV && bc_a(insp) == ra+1 && if (bc_op(insp) == BC_MOV && bc_a(insp) == ra+1 &&

View File

@ -169,7 +169,7 @@ GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent)
nuv = fn->l.nupvalues; nuv = fn->l.nupvalues;
base = L->base; base = L->base;
for (i = 0; i < nuv; i++) { for (i = 0; i < nuv; i++) {
int v = pt->uv[i]; ptrdiff_t v = pt->uv[i];
GCupval *uv = v < 0 ? &gcref(puv[~v])->uv : func_finduv(L, base + v); GCupval *uv = v < 0 ? &gcref(puv[~v])->uv : func_finduv(L, base + v);
setgcref(fn->l.uvptr[i], obj2gco(uv)); setgcref(fn->l.uvptr[i], obj2gco(uv));
} }

View File

@ -295,7 +295,7 @@ TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne)
top = curr_top(L); top = curr_top(L);
setcont(top, ne ? lj_cont_condf : lj_cont_condt); setcont(top, ne ? lj_cont_condf : lj_cont_condt);
copyTV(L, top+1, mo); copyTV(L, top+1, mo);
it = ~o1->gch.gct; it = ~(int32_t)o1->gch.gct;
setgcV(L, top+2, &o1->gch, it); setgcV(L, top+2, &o1->gch, it);
setgcV(L, top+3, &o2->gch, it); setgcV(L, top+3, &o2->gch, it);
return top+2; /* Trigger metamethod call. */ return top+2; /* Trigger metamethod call. */

View File

@ -1751,7 +1751,7 @@ void lj_record_ins(jit_State *J)
case BCMpri: setitype(rcv, (int32_t)~rc); rc = TREF_PRI(IRT_NIL+rc); break; case BCMpri: setitype(rcv, (int32_t)~rc); rc = TREF_PRI(IRT_NIL+rc); break;
case BCMnum: { lua_Number n = J->pt->k.n[rc]; case BCMnum: { lua_Number n = J->pt->k.n[rc];
setnumV(rcv, n); ix.key = rc = lj_ir_knumint(J, n); } break; setnumV(rcv, n); ix.key = rc = lj_ir_knumint(J, n); } break;
case BCMstr: { GCstr *s = strref(J->pt->k.gc[~rc]); case BCMstr: { GCstr *s = strref(J->pt->k.gc[~(ptrdiff_t)rc]);
setstrV(J->L, rcv, s); ix.key = rc = lj_ir_kstr(J, s); } break; setstrV(J->L, rcv, s); ix.key = rc = lj_ir_kstr(J, s); } break;
default: break; /* Handled later. */ default: break; /* Handled later. */
} }
@ -1943,7 +1943,7 @@ void lj_record_ins(jit_State *J)
break; break;
case BC_TDUP: case BC_TDUP:
rc = emitir(IRT(IR_TDUP, IRT_TAB), rc = emitir(IRT(IR_TDUP, IRT_TAB),
lj_ir_ktab(J, tabref(J->pt->k.gc[~rc])), 0); lj_ir_ktab(J, tabref(J->pt->k.gc[~(ptrdiff_t)rc])), 0);
break; break;
/* -- Calls and vararg handling ----------------------------------------- */ /* -- Calls and vararg handling ----------------------------------------- */