diff options
author | Maxime Chevalier-Boisvert <[email protected]> | 2021-06-30 16:04:25 -0400 |
---|---|---|
committer | Alan Wu <[email protected]> | 2021-10-20 18:19:37 -0400 |
commit | 6cb4edd73ff23809887a72293b670d9c9de2a8fe (patch) | |
tree | b588529dd6305675fe26097b98abf588fd989471 /yjit_codegen.c | |
parent | 9e0a56fb24ed741d2215a4c4f7e560fa7b88dc8b (diff) |
Implement swap instruction
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r-- | yjit_codegen.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c index 2470853dd1..0c1b0da7a4 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -567,6 +567,28 @@ gen_dupn(jitstate_t* jit, ctx_t* ctx) return YJIT_KEEP_COMPILING; } +// Swap top 2 stack entries +static codegen_status_t +gen_swap(jitstate_t* jit, ctx_t* ctx) +{ + val_type_t type0 = ctx_get_opnd_type(ctx, OPND_STACK(0)); + x86opnd_t opnd0 = ctx_stack_opnd(ctx, 0); + + val_type_t type1 = ctx_get_opnd_type(ctx, OPND_STACK(1)); + x86opnd_t opnd1 = ctx_stack_opnd(ctx, 1); + + mov(cb, REG0, opnd0); + mov(cb, REG1, opnd1); + + ctx_set_opnd_type(ctx, OPND_STACK(0), type1); + ctx_set_opnd_type(ctx, OPND_STACK(1), type0); + + mov(cb, opnd0, REG1); + mov(cb, opnd1, REG0); + + return YJIT_KEEP_COMPILING; +} + // set Nth stack entry to stack top static codegen_status_t gen_setn(jitstate_t* jit, ctx_t* ctx) @@ -3406,6 +3428,7 @@ yjit_init_codegen(void) yjit_reg_op(BIN(nop), gen_nop); yjit_reg_op(BIN(dup), gen_dup); yjit_reg_op(BIN(dupn), gen_dupn); + yjit_reg_op(BIN(swap), gen_swap); yjit_reg_op(BIN(setn), gen_setn); yjit_reg_op(BIN(topn), gen_topn); yjit_reg_op(BIN(pop), gen_pop); |