From 4e5ef81b869dd15238ccfd5aeef09ce577f9b805 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 6 Nov 2012 17:05:37 +0100 Subject: [PATCH] FFI: Fix recording of bool call result check on x86/x64. --- src/lj_asm_x86.h | 4 ++-- src/lj_crecord.c | 5 +++++ src/lj_target_x86.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h index 4e4f351d..6d7dd5a3 100644 --- a/src/lj_asm_x86.h +++ b/src/lj_asm_x86.h @@ -1815,7 +1815,7 @@ static void asm_intarith(ASMState *as, IRIns *ir, x86Arith xa) int32_t k = 0; if (as->flagmcp == as->mcp) { /* Drop test r,r instruction. */ as->flagmcp = NULL; - as->mcp += (LJ_64 && *as->mcp != XI_TEST) ? 3 : 2; + as->mcp += (LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2; } right = IR(rref)->r; if (ra_hasreg(right)) { @@ -2151,7 +2151,7 @@ static void asm_comp(ASMState *as, IRIns *ir, uint32_t cc) asm_guardcc(as, cc); if (usetest && left != RID_MRM) { /* Use test r,r instead of cmp r,0. */ - emit_rr(as, XO_TEST, r64 + left, left); + emit_rr(as, irt_isu8(ir->t) ? XO_TESTb : XO_TEST, r64 + left, left); if (irl+1 == ir) /* Referencing previous ins? */ as->flagmcp = as->mcp; /* Set flag to drop test r,r if possible. */ } else { diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 9d361a7a..c9cdb261 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -1140,7 +1140,12 @@ static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) tr = TREF_NIL; } else { crec_snap_caller(J); +#if LJ_TARGET_X86ORX64 + /* Note: only the x86/x64 backend supports U8 and only for EQ(tr, 0). */ + lj_ir_set(J, IRTG(IR_NE, IRT_U8), tr, lj_ir_kint(J, 0)); +#else lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0)); +#endif J->postproc = LJ_POST_FIXGUARDSNAP; tr = TREF_TRUE; } diff --git a/src/lj_target_x86.h b/src/lj_target_x86.h index c718bdb5..95b80322 100644 --- a/src/lj_target_x86.h +++ b/src/lj_target_x86.h @@ -205,6 +205,7 @@ typedef enum { XI_ARITHi = 0x81, XI_ARITHi8 = 0x83, XI_PUSHi8 = 0x6a, + XI_TESTb = 0x84, XI_TEST = 0x85, XI_MOVmi = 0xc7, XI_GROUP5 = 0xff, @@ -244,6 +245,7 @@ typedef enum { XO_IMULi = XO_(69), XO_IMULi8 = XO_(6b), XO_CMP = XO_(3b), + XO_TESTb = XO_(84), XO_TEST = XO_(85), XO_GROUP3b = XO_(f6), XO_GROUP3 = XO_(f7),