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

ruby-changes:70713

From: Alan <ko1@a...>
Date: Tue, 4 Jan 2022 05:11:46 +0900 (JST)
Subject: [ruby-changes:70713] c717728830 (master): YJIT: Refine comments

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

From c717728830500fcd47534faafd01362a29e90cfd Mon Sep 17 00:00:00 2001
From: Alan Wu <alanwu@r...>
Date: Mon, 3 Jan 2022 12:43:08 -0500
Subject: YJIT: Refine comments

Correct method name, fix copypasta, and add an ASCII illustration.

[ci skip]
---
 yjit_codegen.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/yjit_codegen.c b/yjit_codegen.c
index 21e4813c193..33c1ec65397 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -1308,11 +1308,26 @@ gen_get_ep(codeblock_t *cb, x86opnd_t reg, uint32_t level) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L1308
     }
 }
 
-// Compute the index of a local variable from its slot index
+// Compute the local table index of a variable from its index relative to the
+// environment object.
 static uint32_t
 slot_to_local_idx(const rb_iseq_t *iseq, int32_t slot_idx)
 {
-    // Convoluted rules from local_var_name() in iseq.c
+    // Layout illustration
+    // This is an array of VALUE
+    //                                           | VM_ENV_DATA_SIZE |
+    //                                           v                  v
+    // low addr <+-------+-------+-------+-------+------------------+
+    //           |local 0|local 1|  ...  |local n|       ....       |
+    //           +-------+-------+-------+-------+------------------+
+    //           ^       ^                       ^                  ^
+    //           +-------+---local_table_size----+         cfp->ep--+
+    //                   |                                          |
+    //                   +------------------slot_idx----------------+
+    //
+    // See usages of local_var_name() from iseq.c for similar calculation.
+
+    // FIXME: unsigned to signed cast below can truncate
     int32_t local_table_size = iseq->body->local_table_size;
     int32_t op = slot_idx - VM_ENV_DATA_SIZE;
     int32_t local_idx = local_idx = local_table_size - op - 1;
@@ -1324,6 +1339,8 @@ static codegen_status_t https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L1339
 gen_getlocal_wc0(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
 {
     // Compute the offset from BP to the local
+    // TODO: Type is lindex_t in interpter. The following cast can truncate.
+    //       Not in the mood to dance around signed multiplication UB at the moment...
     int32_t slot_idx = (int32_t)jit_get_arg(jit, 0);
     const int32_t offs = -(SIZEOF_VALUE * slot_idx);
     uint32_t local_idx = slot_to_local_idx(jit->iseq, slot_idx);
@@ -4401,7 +4418,7 @@ gen_setglobal(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L4418
     ID gid = jit_get_arg(jit, 0);
 
     // Save the PC and SP because we might make a Ruby call for
-    // Kernel#set_trace_var
+    // Kernel#trace_var
     jit_prepare_routine_call(jit, ctx, REG0);
 
     mov(cb, C_ARG_REGS[0], imm_opnd(gid));
@@ -4418,8 +4435,7 @@ gen_setglobal(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L4435
 static codegen_status_t
 gen_anytostring(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
 {
-    // Save the PC and SP because we might make a Ruby call for
-    // Kernel#set_trace_var
+    // Might allocate in rb_obj_as_string_result().
     jit_prepare_routine_call(jit, ctx, REG0);
 
     x86opnd_t str = ctx_stack_pop(ctx, 1);
-- 
cgit v1.2.1


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

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