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

ruby-changes:70316

From: Daniel <ko1@a...>
Date: Sun, 19 Dec 2021 05:59:43 +0900 (JST)
Subject: [ruby-changes:70316] 45f2182438 (master): YJIT: Implement intern

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

From 45f2182438a632b1217ca26f3e89860e2ee58357 Mon Sep 17 00:00:00 2001
From: Daniel Colson <danieljamescolson@g...>
Date: Thu, 16 Dec 2021 19:52:44 -0500
Subject: YJIT: Implement intern

`intern` showed up in the top 20 most frequent exit ops (granted with a
fairly small percentage) in a benchmark run by @jhawthorn on
github/github.

This implementation is similar to gen_anytostring, but with 1
stack pop instead of 2.

Co-authored-by: John Hawthorn <jhawthorn@g...>
---
 test/ruby/test_yjit.rb |  5 +++++
 yjit_codegen.c         | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb
index c0230f74190..6390ab4c011 100644
--- a/test/ruby/test_yjit.rb
+++ b/test/ruby/test_yjit.rb
@@ -256,6 +256,11 @@ class TestYJIT < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_yjit.rb#L256
     assert_no_exits('/#{true}/')
   end
 
+  def test_compile_dynamic_symbol
+    assert_compiles(':"#{"foo"}"', insns: %i[intern])
+    assert_compiles('s = "bar"; :"foo#{s}"', insns: %i[intern])
+  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 eebb129df8a..528d9a45d74 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -4499,6 +4499,25 @@ gen_toregexp(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L4499
     return YJIT_KEEP_COMPILING;
 }
 
+static codegen_status_t
+gen_intern(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
+{
+    // Save the PC and SP because we might allocate
+    jit_prepare_routine_call(jit, ctx, REG0);
+
+    x86opnd_t str = ctx_stack_pop(ctx, 1);
+
+    mov(cb, C_ARG_REGS[0], str);
+
+    call_ptr(cb, REG0, (void *)&rb_str_intern);
+
+    // Push the return value
+    x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_UNKNOWN);
+    mov(cb, stack_ret, RAX);
+
+    return YJIT_KEEP_COMPILING;
+}
+
 static codegen_status_t
 gen_getspecial(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
 {
@@ -5010,6 +5029,7 @@ yjit_init_codegen(void) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L5029
     yjit_reg_op(BIN(anytostring), gen_anytostring);
     yjit_reg_op(BIN(objtostring), gen_objtostring);
     yjit_reg_op(BIN(toregexp), gen_toregexp);
+    yjit_reg_op(BIN(intern), gen_intern);
     yjit_reg_op(BIN(getspecial), gen_getspecial);
     yjit_reg_op(BIN(getclassvariable), gen_getclassvariable);
     yjit_reg_op(BIN(setclassvariable), gen_setclassvariable);
-- 
cgit v1.2.1


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

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