Skip to content

Commit

Permalink
JIT: fix USHR, optimize SHR, AND, OR, XOR
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
murmour committed Jan 14, 2018
1 parent f1846a1 commit 657245f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions vm/jit_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ static void jit_number_op( jit_ctx *ctx, enum Operation op ) {
XMov_rp(TMP2,TMP,FIELD(0));
XCmp_rb(TMP2,VAL_FLOAT);
XJump(JNeq,jnot_float2);

// load floats
XAdd_rc(ACC,4);
XFLd_i(ACC);
Expand Down Expand Up @@ -1358,7 +1358,7 @@ static void jit_number_op( jit_ctx *ctx, enum Operation op ) {
}
if( op != OP_MOD ) {
stack_push(Esp,2);
}
}
XFStp_i(Esp);
XCall_m(alloc_float);
stack_pop(Esp,2);
Expand All @@ -1371,7 +1371,7 @@ static void jit_number_op( jit_ctx *ctx, enum Operation op ) {
PATCH_JUMP(jnot_int2);

begin_call();
XPush_c(GET_PC());
XPush_c(GET_PC());
XPush_r(ACC);
XPush_r(TMP);
XPush_r(VM);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -1477,7 +1482,7 @@ static void jit_int_op( jit_ctx *ctx, enum IOperation op ) {
}
stack_pop(Esp,4);
end_call();

PATCH_JUMP(jend);
pop(1);

Expand Down

0 comments on commit 657245f

Please sign in to comment.