summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-18 21:42:10 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-18 21:42:20 -0700
commit8510f33cc1d7f6b5148d596cfea3fbf734661cd8 (patch)
tree8a9d758ff601da2f4a50e97e99eb9dd77b03447a
parent4a8de3fa8872ed43b33f1ae81ae4767f4334283a (diff)
downloadruby-8510f33cc1d7f6b5148d596cfea3fbf734661cd8.tar.gz
RJIT: Implement intern
-rw-r--r--lib/ruby_vm/rjit/insn_compiler.rb22
-rw-r--r--rjit_c.rb4
-rwxr-xr-xtool/rjit/bindgen.rb1
3 files changed, 24 insertions, 3 deletions
diff --git a/lib/ruby_vm/rjit/insn_compiler.rb b/lib/ruby_vm/rjit/insn_compiler.rb
index ba645d2374..347319dd35 100644
--- a/lib/ruby_vm/rjit/insn_compiler.rb
+++ b/lib/ruby_vm/rjit/insn_compiler.rb
@@ -18,7 +18,7 @@ module RubyVM::RJIT
asm.incr_counter(:rjit_insns_count)
asm.comment("Insn: #{insn.name}")
- # 81/102
+ # 82/102
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
@@ -45,7 +45,7 @@ module RubyVM::RJIT
when :concatstrings then concatstrings(jit, ctx, asm)
when :anytostring then anytostring(jit, ctx, asm)
when :toregexp then toregexp(jit, ctx, asm)
- # intern
+ when :intern then intern(jit, ctx, asm)
when :newarray then newarray(jit, ctx, asm)
# newarraykwsplat
when :duparray then duparray(jit, ctx, asm)
@@ -827,7 +827,23 @@ module RubyVM::RJIT
KeepCompiling
end
- # intern
+ # @param jit [RubyVM::RJIT::JITState]
+ # @param ctx [RubyVM::RJIT::Context]
+ # @param asm [RubyVM::RJIT::Assembler]
+ def intern(jit, ctx, asm)
+ # Save the PC and SP because we might allocate
+ jit_prepare_routine_call(jit, ctx, asm);
+
+ str = ctx.stack_pop(1)
+ asm.mov(C_ARGS[0], str)
+ asm.call(C.rb_str_intern)
+
+ # Push the return value
+ stack_ret = ctx.stack_push
+ asm.mov(stack_ret, C_RET)
+
+ KeepCompiling
+ end
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
diff --git a/rjit_c.rb b/rjit_c.rb
index 9454ab2c1a..a582fd80ba 100644
--- a/rjit_c.rb
+++ b/rjit_c.rb
@@ -593,6 +593,10 @@ module RubyVM::RJIT # :nodoc: all
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_str_getbyte) }
end
+ def C.rb_str_intern
+ Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_str_intern) }
+ end
+
def C.rb_vm_bh_to_procval
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_bh_to_procval) }
end
diff --git a/tool/rjit/bindgen.rb b/tool/rjit/bindgen.rb
index 7cc97d3e3f..9c1cbdfcc9 100755
--- a/tool/rjit/bindgen.rb
+++ b/tool/rjit/bindgen.rb
@@ -541,6 +541,7 @@ generator = BindingGenerator.new(
rb_ary_tmp_new_from_values
rb_reg_new_ary
rb_ary_clear
+ rb_str_intern
],
types: %w[
CALL_DATA