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

ruby-changes:69437

From: Ian <ko1@a...>
Date: Mon, 25 Oct 2021 23:40:52 +0900 (JST)
Subject: [ruby-changes:69437] e943511455 (master): YJIT: Implement duphash (#5009)

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

From e943511455acfd70dc3bd085038969a11802d688 Mon Sep 17 00:00:00 2001
From: "Ian C. Anderson" <ian@i...>
Date: Mon, 25 Oct 2021 10:40:33 -0400
Subject: YJIT: Implement duphash (#5009)

`duphash` showed up in the top-20 most frequent exit ops for @jhawthorn's benchmark that renders github.com/about

The implementation was almost exactly the same as `duparray`

Co-authored-by: John Hawthorn <john@h...>

Co-authored-by: John Hawthorn <john@h...>
---
 bootstraptest/test_yjit.rb | 10 ++++++++++
 common.mk                  |  1 +
 yjit_codegen.c             | 21 +++++++++++++++++++++
 3 files changed, 32 insertions(+)

diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index 183b19c3ebc..c94c710c4dd 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -2268,3 +2268,13 @@ assert_equal "true", %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L2268
 
     expected == events
 }
+
+# duphash
+assert_equal '{:foo=>123}', %q{
+  def foo
+    {foo: 123}
+  end
+
+  foo
+  foo
+}
diff --git a/common.mk b/common.mk
index c3c599d24d8..1fc59227108 100644
--- a/common.mk
+++ b/common.mk
@@ -16903,6 +16903,7 @@ yjit.$(OBJEXT): $(top_srcdir)/internal/class.h https://github.com/ruby/ruby/blob/trunk/common.mk#L16903
 yjit.$(OBJEXT): $(top_srcdir)/internal/compile.h
 yjit.$(OBJEXT): $(top_srcdir)/internal/compilers.h
 yjit.$(OBJEXT): $(top_srcdir)/internal/gc.h
+yjit.$(OBJEXT): $(top_srcdir)/internal/hash.h
 yjit.$(OBJEXT): $(top_srcdir)/internal/imemo.h
 yjit.$(OBJEXT): $(top_srcdir)/internal/object.h
 yjit.$(OBJEXT): $(top_srcdir)/internal/re.h
diff --git a/yjit_codegen.c b/yjit_codegen.c
index be4d7f01652..374786571c0 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -3,6 +3,7 @@ https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L3
 #include "gc.h"
 #include "internal/compile.h"
 #include "internal/class.h"
+#include "internal/hash.h"
 #include "internal/object.h"
 #include "internal/sanitizers.h"
 #include "internal/string.h"
@@ -895,6 +896,25 @@ gen_duparray(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L896
     return YJIT_KEEP_COMPILING;
 }
 
+// dup hash
+static codegen_status_t
+gen_duphash(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
+{
+    VALUE hash = jit_get_arg(jit, 0);
+
+    // Save the PC and SP because we are allocating
+    jit_prepare_routine_call(jit, ctx, REG0);
+
+    // call rb_hash_resurrect(VALUE hash);
+    jit_mov_gc_ptr(jit, cb, C_ARG_REGS[0], hash);
+    call_ptr(cb, REG0, (void *)rb_hash_resurrect);
+
+    x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_HASH);
+    mov(cb, stack_ret, RAX);
+
+    return YJIT_KEEP_COMPILING;
+}
+
 VALUE rb_vm_splat_array(VALUE flag, VALUE ary);
 
 // call to_a on the array on the stack
@@ -4640,6 +4660,7 @@ yjit_init_codegen(void) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L4660
     yjit_reg_op(BIN(adjuststack), gen_adjuststack);
     yjit_reg_op(BIN(newarray), gen_newarray);
     yjit_reg_op(BIN(duparray), gen_duparray);
+    yjit_reg_op(BIN(duphash), gen_duphash);
     yjit_reg_op(BIN(splatarray), gen_splatarray);
     yjit_reg_op(BIN(expandarray), gen_expandarray);
     yjit_reg_op(BIN(newhash), gen_newhash);
-- 
cgit v1.2.1


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

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