From d33fa7ac3a028893148451ef339c3b3a64feb9ea Mon Sep 17 00:00:00 2001 From: Max Mouratov Date: Sun, 14 Jan 2018 19:23:29 +0500 Subject: [PATCH] JIT: fix USHR, optimize SHR, AND, OR, XOR 1) USHR(-1, -1) wrongly produced -1; 2) The "best_int" check is redundant for all bitwise ops except SHL; 3) SHR, USHR, AND, OR, XOR performed unnecessary tag bit juggling. --- vm/jit_x86.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vm/jit_x86.c b/vm/jit_x86.c index 3b01df2c..cbaee018 100644 --- a/vm/jit_x86.c +++ b/vm/jit_x86.c @@ -1415,18 +1415,23 @@ static void jit_int_op( jit_ctx *ctx, enum IOperation op ) { XMov_rp(ACC,SP,FIELD(0)); is_int(ACC,false,jerr1); is_int(TMP,false,jerr2); - XShr_rc(TMP,1); - XShr_rc(ACC,1); switch( op ) { case IOP_SHL: + XShr_rc(ACC,1); + XShr_rc(TMP,1); XShl_rr(ACC,TMP); + best_int(); break; case IOP_SHR: + XShr_rc(TMP,1); XShr_rr(ACC,TMP); + XOr_rc(ACC,1); break; case IOP_USHR: + XShr_rc(TMP,1); XUShr_rr(ACC,TMP); + XOr_rc(ACC,1); break; case IOP_AND: XAnd_rr(ACC,TMP); @@ -1436,12 +1441,12 @@ static void jit_int_op( jit_ctx *ctx, enum IOperation op ) { break; case IOP_XOR: XXor_rr(ACC,TMP); + XOr_rc(ACC,1); break; default: ERROR; } - best_int(); XJump_near(jend); PATCH_JUMP(jerr1);