ruby-changes:68991
From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:19:36 +0900 (JST)
Subject: [ruby-changes:68991] 6cb4edd73f (master): Implement swap instruction
https://git.ruby-lang.org/ruby.git/commit/?id=6cb4edd73f From 6cb4edd73ff23809887a72293b670d9c9de2a8fe Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Wed, 30 Jun 2021 16:04:25 -0400 Subject: Implement swap instruction --- yjit_codegen.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L567 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) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L3428 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); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/