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

ruby-changes:69113

From: eileencodes <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:52 +0900 (JST)
Subject: [ruby-changes:69113] d2e8b99b5b (master): Implement tostring instruction for yjit

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

From d2e8b99b5bc485b864d25c4293002214b0c64ced Mon Sep 17 00:00:00 2001
From: eileencodes <eileencodes@g...>
Date: Wed, 4 Aug 2021 13:23:34 -0400
Subject: Implement tostring instruction for yjit

Co-authored-by: Aaron Patterson <tenderlove@r...>
---
 test/ruby/test_yjit.rb |  4 ++++
 yjit_codegen.c         | 30 ++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb
index 145305ad09..e485e5f64f 100644
--- a/test/ruby/test_yjit.rb
+++ b/test/ruby/test_yjit.rb
@@ -59,6 +59,10 @@ class TestYJIT < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_yjit.rb#L59
     assert_compiles('$foo = 123; $foo', insns: %i[setglobal], result: 123)
   end
 
+  def test_compile_tostring
+    assert_no_exits('"i am a string #{true}"')
+  end
+
   def test_getlocal_with_level
     assert_compiles(<<~RUBY, insns: %i[getlocal opt_plus], result: [[7]])
       def foo(foo, bar)
diff --git a/yjit_codegen.c b/yjit_codegen.c
index 297d4f4291..ebb75cbdad 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -3494,6 +3494,35 @@ gen_setglobal(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L3494
     return YJIT_KEEP_COMPILING;
 }
 
+static codegen_status_t
+gen_tostring(jitstate_t* jit, ctx_t* ctx)
+{
+    // Save the PC and SP because we might make a Ruby call for
+    // Kernel#set_trace_var
+    jit_save_pc(jit, REG0);
+    jit_save_sp(jit, ctx);
+
+    // Save YJIT registers
+    yjit_save_regs(cb);
+
+    x86opnd_t str = ctx_stack_pop(ctx, 1);
+    x86opnd_t val = ctx_stack_pop(ctx, 1);
+
+    mov(cb, C_ARG_REGS[0], str);
+    mov(cb, C_ARG_REGS[1], val);
+
+    call_ptr(cb, REG0, (void *)&rb_obj_as_string_result);
+
+    // Load YJIT registers
+    yjit_load_regs(cb);
+
+    // Push the return value
+    x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_STRING);
+    mov(cb, stack_ret, RAX);
+
+    return YJIT_KEEP_COMPILING;
+}
+
 static codegen_status_t
 gen_opt_getinlinecache(jitstate_t *jit, ctx_t *ctx)
 {
@@ -3738,6 +3767,7 @@ yjit_init_codegen(void) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L3767
     yjit_reg_op(BIN(leave), gen_leave);
     yjit_reg_op(BIN(getglobal), gen_getglobal);
     yjit_reg_op(BIN(setglobal), gen_setglobal);
+    yjit_reg_op(BIN(tostring), gen_tostring);
 
     yjit_method_codegen_table = st_init_numtable();
 
-- 
cgit v1.2.1


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

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