Skip to content

Commit ccc78c2

Browse files
committed
- fix: remove reusing argument on stack
- separate JIT logic and others (switch/case, etc)
1 parent 06c70cd commit ccc78c2

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

vm/jit_x86.c

+32-20
Original file line numberDiff line numberDiff line change
@@ -1621,58 +1621,70 @@ static void jit_make_env( jit_ctx *ctx, int esize ) {
16211621

16221622
static void jit_object_op_gen( jit_ctx *ctx, enum Operation op, int right ) {
16231623
int *next;
1624+
field f;
1625+
int is_opset;
1626+
16241627
INIT_BUFFER;
16251628

1626-
// prepare args
1627-
XPush_r(right?REG_TMP:REG_ACC);
1628-
if( op == OP_SET ) {
1629-
XMov_rp(TMP2,Esp,FIELD(3));
1630-
XPush_r(TMP2);
1631-
}
1632-
XMov_rr(TMP2,Esp);
1633-
XPush_c(0);
1634-
XPush_c((op == OP_SET)?2:1);
1635-
XPush_r(TMP2);
1629+
f = 0;
1630+
is_opset = 0;
16361631
switch( op ) {
16371632
case OP_ADD:
1638-
XPush_c(right?id_radd:id_add);
1633+
f = (right ? id_radd : id_add);
16391634
break;
16401635
case OP_SUB:
1641-
XPush_c(right?id_rsub:id_sub);
1636+
f = (right ? id_rsub : id_sub);
16421637
break;
16431638
case OP_MUL:
1644-
XPush_c(right?id_rmult:id_mult);
1639+
f = (right ? id_rmult : id_mult);
16451640
break;
16461641
case OP_DIV:
1647-
XPush_c(right?id_rdiv:id_div);
1642+
f = (right ? id_rdiv : id_div);
16481643
break;
16491644
case OP_MOD:
1650-
XPush_c(right?id_rmod:id_mod);
1645+
f = (right ? id_rmod : id_mod);
16511646
break;
16521647
case OP_GET:
1653-
XPush_c(id_get);
1648+
f = id_get;
16541649
break;
16551650
case OP_SET:
1656-
XPush_c(id_set);
1651+
f = id_set;
1652+
is_opset = 1;
16571653
break;
16581654
default:
16591655
ERROR;
16601656
}
1657+
1658+
// prepare args
1659+
XPush_r(right?REG_TMP:REG_ACC);
1660+
if( is_opset ) {
1661+
XMov_rp(TMP2,Esp,FIELD(3));
1662+
XPush_r(TMP2);
1663+
}
1664+
XMov_rr(TMP2,Esp);
1665+
XPush_c(0);
1666+
XPush_c(is_opset?2:1);
1667+
XPush_r(TMP2);
1668+
XPush_r(right?REG_ACC:REG_TMP);
1669+
1670+
XPush_c(f);
16611671
XPush_r(right?REG_ACC:REG_TMP);
16621672
XCall_m(val_field);
1673+
stack_pop(Esp,2);
16631674
XCmp_rc(ACC,CONST(val_null));
16641675
XJump(JNeq,next);
1665-
stack_pop(Esp,(op == OP_SET)?7:6);
1676+
stack_pop(Esp,is_opset?6:5);
16661677
runtime_error(11,true); // Unsupported operation
1678+
16671679
PATCH_JUMP(next);
16681680
XPop_r(TMP);
1669-
stack_pop(Esp,1);
1681+
16701682
XPush_r(ACC);
16711683
XPush_r(TMP);
16721684
begin_call();
16731685
XCall_m(val_callEx);
16741686
end_call();
1675-
stack_pop(Esp,(op == OP_SET)?7:6);
1687+
stack_pop(Esp,is_opset?7:6);
16761688
XRet();
16771689
END_BUFFER;
16781690
}

0 commit comments

Comments
 (0)