summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2021-09-29 13:43:26 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:42 -0400
commit9aed5809e11ab4dc7db044d312d585732cfc1d5f (patch)
tree425fc015f1e28e5062628baf254a31f447143ca2
parent2c0891be204f270028e533bd1196a034a599d8f8 (diff)
Reuse stack swapping logic
-rw-r--r--yjit_codegen.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c
index a38febdb08..b125f0c6f7 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -774,23 +774,29 @@ gen_dupn(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
return YJIT_KEEP_COMPILING;
}
-// Swap top 2 stack entries
-static codegen_status_t
-gen_swap(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
+static void
+stack_swap(ctx_t* ctx, codeblock_t* cb, int offset0, int offset1, x86opnd_t reg0, x86opnd_t reg1)
{
- x86opnd_t opnd0 = ctx_stack_opnd(ctx, 0);
- x86opnd_t opnd1 = ctx_stack_opnd(ctx, 1);
- temp_type_mapping_t mapping0 = ctx_get_opnd_mapping(ctx, OPND_STACK(0));
- temp_type_mapping_t mapping1 = ctx_get_opnd_mapping(ctx, OPND_STACK(1));
+ x86opnd_t opnd0 = ctx_stack_opnd(ctx, offset0);
+ x86opnd_t opnd1 = ctx_stack_opnd(ctx, offset1);
- mov(cb, REG0, opnd0);
- mov(cb, REG1, opnd1);
- mov(cb, opnd0, REG1);
- mov(cb, opnd1, REG0);
+ temp_type_mapping_t mapping0 = ctx_get_opnd_mapping(ctx, OPND_STACK(offset0));
+ temp_type_mapping_t mapping1 = ctx_get_opnd_mapping(ctx, OPND_STACK(offset1));
+
+ mov(cb, reg0, opnd0);
+ mov(cb, reg1, opnd1);
+ mov(cb, opnd0, reg1);
+ mov(cb, opnd1, reg0);
- ctx_set_opnd_mapping(ctx, OPND_STACK(0), mapping1);
- ctx_set_opnd_mapping(ctx, OPND_STACK(1), mapping0);
+ ctx_set_opnd_mapping(ctx, OPND_STACK(offset0), mapping1);
+ ctx_set_opnd_mapping(ctx, OPND_STACK(offset1), mapping0);
+}
+// Swap top 2 stack entries
+static codegen_status_t
+gen_swap(jitstate_t* jit, ctx_t* ctx, codeblock_t* cb)
+{
+ stack_swap(ctx , cb, 0, 1, REG0, REG1);
return YJIT_KEEP_COMPILING;
}
@@ -3460,15 +3466,9 @@ gen_send_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
// that location.
for (int swap_idx = kwarg_idx + 1; swap_idx < req_key_num; swap_idx++) {
if (callee_kwarg == caller_kwargs[swap_idx]) {
- x86opnd_t swap = ctx_stack_opnd(ctx, argc - 1 - swap_idx);
- x86opnd_t kwarg = ctx_stack_opnd(ctx, argc - 1 - kwarg_idx);
-
// First we're going to generate the code that is going
// to perform the actual swapping at runtime.
- mov(cb, REG1, swap);
- mov(cb, R9, kwarg);
- mov(cb, swap, R9);
- mov(cb, kwarg, REG1);
+ stack_swap(ctx, cb, argc - 1 - swap_idx, argc - 1 - kwarg_idx, REG1, R9);
// Next we're going to do some bookkeeping on our end so
// that we know the order that the arguments are