[前][次][番号順一覧][スレッド一覧]

ruby-changes:69236

From: John <ko1@a...>
Date: Thu, 21 Oct 2021 08:24:18 +0900 (JST)
Subject: [ruby-changes:69236] 82f60df5aa (master): Implement generic setlocal

https://git.ruby-lang.org/ruby.git/commit/?id=82f60df5aa

From 82f60df5aa1e25f027a0a3fbd516d1272de39211 Mon Sep 17 00:00:00 2001
From: John Hawthorn <john@h...>
Date: Fri, 17 Sep 2021 08:26:38 -0700
Subject: Implement generic setlocal

---
 yjit_codegen.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/yjit_codegen.c b/yjit_codegen.c
index 0ee6407d23..9f0029712d 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -1322,6 +1322,48 @@ gen_setlocal_wc0(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L1322
     return YJIT_KEEP_COMPILING;
 }
 
+static codegen_status_t
+gen_setlocal_generic(jitstate_t *jit, ctx_t* ctx, uint32_t local_idx, uint32_t level)
+{
+    // Load environment pointer EP at level
+    gen_get_ep(cb, REG0, level);
+
+    // flags & VM_ENV_FLAG_WB_REQUIRED
+    x86opnd_t flags_opnd = mem_opnd(64, REG0, sizeof(VALUE) * VM_ENV_DATA_INDEX_FLAGS);
+    test(cb, flags_opnd, imm_opnd(VM_ENV_FLAG_WB_REQUIRED));
+
+    // Create a size-exit to fall back to the interpreter
+    uint8_t *side_exit = yjit_side_exit(jit, ctx);
+
+    // if (flags & VM_ENV_FLAG_WB_REQUIRED) != 0
+    jnz_ptr(cb, side_exit);
+
+    // Pop the value to write from the stack
+    x86opnd_t stack_top = ctx_stack_pop(ctx, 1);
+    mov(cb, REG1, stack_top);
+
+    // Write the value at the environment pointer
+    const int32_t offs = -(SIZEOF_VALUE * local_idx);
+    mov(cb, mem_opnd(64, REG0, offs), REG1);
+
+    return YJIT_KEEP_COMPILING;
+}
+
+static codegen_status_t
+gen_setlocal(jitstate_t* jit, ctx_t* ctx)
+{
+    int32_t idx = (int32_t)jit_get_arg(jit, 0);
+    int32_t level = (int32_t)jit_get_arg(jit, 1);
+    return gen_setlocal_generic(jit, ctx, idx, level);
+}
+
+static codegen_status_t
+gen_setlocal_wc1(jitstate_t* jit, ctx_t* ctx)
+{
+    int32_t idx = (int32_t)jit_get_arg(jit, 0);
+    return gen_setlocal_generic(jit, ctx, idx, 1);
+}
+
 // Check that `self` is a pointer to an object on the GC heap
 static void
 guard_self_is_heap(codeblock_t *cb, x86opnd_t self_opnd, uint8_t *side_exit, ctx_t *ctx)
@@ -4313,7 +4355,9 @@ yjit_init_codegen(void) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L4355
     yjit_reg_op(BIN(getlocal), gen_getlocal);
     yjit_reg_op(BIN(getlocal_WC_0), gen_getlocal_wc0);
     yjit_reg_op(BIN(getlocal_WC_1), gen_getlocal_wc1);
+    yjit_reg_op(BIN(setlocal), gen_setlocal);
     yjit_reg_op(BIN(setlocal_WC_0), gen_setlocal_wc0);
+    yjit_reg_op(BIN(setlocal_WC_1), gen_setlocal_wc1);
     yjit_reg_op(BIN(getinstancevariable), gen_getinstancevariable);
     yjit_reg_op(BIN(setinstancevariable), gen_setinstancevariable);
     yjit_reg_op(BIN(defined), gen_defined);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]