summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-18 21:24:28 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-18 21:24:31 -0700
commit2eefd71e0f0fe7ab4c4584fc29902034102c5c4a (patch)
tree138c2e12a5fb2458f2fdc0e68bf23b5b11d3904b
parent81e19b7d9988ced02c80a19ef2ec0f3b7cd8c456 (diff)
downloadruby-2eefd71e0f0fe7ab4c4584fc29902034102c5c4a.tar.gz
RJIT: Implement newrange
-rw-r--r--lib/ruby_vm/rjit/insn_compiler.rb26
-rw-r--r--rjit_c.rb4
-rwxr-xr-xtool/rjit/bindgen.rb1
3 files changed, 28 insertions, 3 deletions
diff --git a/lib/ruby_vm/rjit/insn_compiler.rb b/lib/ruby_vm/rjit/insn_compiler.rb
index 326607d9c4..a66b5c88ef 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}")
- # 79/102
+ # 80/102
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
@@ -54,7 +54,7 @@ module RubyVM::RJIT
when :concatarray then concatarray(jit, ctx, asm)
when :splatarray then splatarray(jit, ctx, asm)
when :newhash then newhash(jit, ctx, asm)
- # newrange
+ when :newrange then newrange(jit, ctx, asm)
when :pop then pop(jit, ctx, asm)
when :dup then dup(jit, ctx, asm)
when :dupn then dupn(jit, ctx, asm)
@@ -1002,7 +1002,27 @@ module RubyVM::RJIT
KeepCompiling
end
- # newrange
+ # @param jit [RubyVM::RJIT::JITState]
+ # @param ctx [RubyVM::RJIT::Context]
+ # @param asm [RubyVM::RJIT::Assembler]
+ def newrange(jit, ctx, asm)
+ flag = jit.operand(0)
+
+ # rb_range_new() allocates and can raise
+ jit_prepare_routine_call(jit, ctx, asm)
+
+ # val = rb_range_new(low, high, (int)flag);
+ asm.mov(C_ARGS[0], ctx.stack_opnd(1))
+ asm.mov(C_ARGS[1], ctx.stack_opnd(0))
+ asm.mov(C_ARGS[2], flag)
+ asm.call(C.rb_range_new)
+
+ ctx.stack_pop(2)
+ 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 3b2072873f..cc0b8b8541 100644
--- a/rjit_c.rb
+++ b/rjit_c.rb
@@ -545,6 +545,10 @@ module RubyVM::RJIT # :nodoc: all
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_obj_is_kind_of) }
end
+ def C.rb_range_new
+ Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_range_new) }
+ end
+
def C.rb_reg_last_match
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_reg_last_match) }
end
diff --git a/tool/rjit/bindgen.rb b/tool/rjit/bindgen.rb
index 639031afe1..17d078377a 100755
--- a/tool/rjit/bindgen.rb
+++ b/tool/rjit/bindgen.rb
@@ -537,6 +537,7 @@ generator = BindingGenerator.new(
rb_reg_match_last
rb_reg_nth_match
rb_gvar_get
+ rb_range_new
],
types: %w[
CALL_DATA