summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2023-04-18 13:53:37 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2023-04-18 17:16:22 -0700
commitbdffcd6df30d7f21cf1a3a174672e82074800451 (patch)
tree21e7fc3a34f6dc3c8bc1198de32dfa036d23a665
parentb816ea87725d85b0b9cf9628603245041a2d5123 (diff)
downloadruby-bdffcd6df30d7f21cf1a3a174672e82074800451.tar.gz
Update RJIT to support newarray_send
This also adds max / hash support
-rw-r--r--lib/ruby_vm/rjit/insn_compiler.rb69
-rw-r--r--rjit_c.c2
-rw-r--r--rjit_c.rb8
-rwxr-xr-xtool/rjit/bindgen.rb2
4 files changed, 78 insertions, 3 deletions
diff --git a/lib/ruby_vm/rjit/insn_compiler.rb b/lib/ruby_vm/rjit/insn_compiler.rb
index 1788b20c3a..f9debaa40b 100644
--- a/lib/ruby_vm/rjit/insn_compiler.rb
+++ b/lib/ruby_vm/rjit/insn_compiler.rb
@@ -91,8 +91,7 @@ module RubyVM::RJIT
when :opt_str_freeze then opt_str_freeze(jit, ctx, asm)
when :opt_nil_p then opt_nil_p(jit, ctx, asm)
# opt_str_uminus
- # opt_newarray_max
- when :opt_newarray_min then opt_newarray_min(jit, ctx, asm)
+ when :opt_newarray_send then opt_newarray_send(jit, ctx, asm)
when :invokesuper then invokesuper(jit, ctx, asm)
when :invokeblock then invokeblock(jit, ctx, asm)
when :leave then leave(jit, ctx, asm)
@@ -1510,7 +1509,21 @@ module RubyVM::RJIT
end
# opt_str_uminus
- # opt_newarray_max
+
+ # @param jit [RubyVM::RJIT::JITState]
+ # @param ctx [RubyVM::RJIT::Context]
+ # @param asm [RubyVM::RJIT::Assembler]
+ def opt_newarray_send(jit, ctx, asm)
+ type = C.ID2SYM jit.operand(1)
+
+ case type
+ when :min then opt_newarray_min(jit, ctx, asm)
+ when :max then opt_newarray_max(jit, ctx, asm)
+ when :hash then opt_newarray_hash(jit, ctx, asm)
+ else
+ return CantCompile
+ end
+ end
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
@@ -1540,6 +1553,56 @@ module RubyVM::RJIT
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
# @param asm [RubyVM::RJIT::Assembler]
+ def opt_newarray_max(jit, ctx, asm)
+ num = jit.operand(0)
+
+ # Save the PC and SP because we may allocate
+ jit_prepare_routine_call(jit, ctx, asm)
+
+ offset_magnitude = C.VALUE.size * num
+ values_opnd = ctx.sp_opnd(-offset_magnitude)
+ asm.lea(:rax, values_opnd)
+
+ asm.mov(C_ARGS[0], EC)
+ asm.mov(C_ARGS[1], num)
+ asm.mov(C_ARGS[2], :rax)
+ asm.call(C.rb_vm_opt_newarray_max)
+
+ ctx.stack_pop(num)
+ stack_ret = ctx.stack_push(Type::Unknown)
+ asm.mov(stack_ret, C_RET)
+
+ KeepCompiling
+ end
+
+ # @param jit [RubyVM::RJIT::JITState]
+ # @param ctx [RubyVM::RJIT::Context]
+ # @param asm [RubyVM::RJIT::Assembler]
+ def opt_newarray_hash(jit, ctx, asm)
+ num = jit.operand(0)
+
+ # Save the PC and SP because we may allocate
+ jit_prepare_routine_call(jit, ctx, asm)
+
+ offset_magnitude = C.VALUE.size * num
+ values_opnd = ctx.sp_opnd(-offset_magnitude)
+ asm.lea(:rax, values_opnd)
+
+ asm.mov(C_ARGS[0], EC)
+ asm.mov(C_ARGS[1], num)
+ asm.mov(C_ARGS[2], :rax)
+ asm.call(C.rb_vm_opt_newarray_hash)
+
+ ctx.stack_pop(num)
+ stack_ret = ctx.stack_push(Type::Unknown)
+ asm.mov(stack_ret, C_RET)
+
+ KeepCompiling
+ end
+
+ # @param jit [RubyVM::RJIT::JITState]
+ # @param ctx [RubyVM::RJIT::Context]
+ # @param asm [RubyVM::RJIT::Assembler]
def invokesuper(jit, ctx, asm)
cd = C.rb_call_data.new(jit.operand(0))
block = jit.operand(1)
diff --git a/rjit_c.c b/rjit_c.c
index 39cd0e89f2..414518db1e 100644
--- a/rjit_c.c
+++ b/rjit_c.c
@@ -517,6 +517,8 @@ extern VALUE rb_vm_concat_array(VALUE ary1, VALUE ary2st);
extern VALUE rb_vm_get_ev_const(rb_execution_context_t *ec, VALUE orig_klass, ID id, VALUE allow_nil);
extern VALUE rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, ICVARC ic);
extern VALUE rb_vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr);
+extern VALUE rb_vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr);
+extern VALUE rb_vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr);
extern VALUE rb_vm_splat_array(VALUE flag, VALUE array);
extern bool rb_simple_iseq_p(const rb_iseq_t *iseq);
extern bool rb_vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE obj, VALUE v);
diff --git a/rjit_c.rb b/rjit_c.rb
index 591b53b89c..9373507275 100644
--- a/rjit_c.rb
+++ b/rjit_c.rb
@@ -724,6 +724,14 @@ module RubyVM::RJIT # :nodoc: all
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_ic_hit_p) }
end
+ def C.rb_vm_opt_newarray_hash
+ Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_hash) }
+ end
+
+ def C.rb_vm_opt_newarray_max
+ Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_max) }
+ end
+
def C.rb_vm_opt_newarray_min
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_min) }
end
diff --git a/tool/rjit/bindgen.rb b/tool/rjit/bindgen.rb
index 5c9fcfdf4e..1dd3b78bd5 100755
--- a/tool/rjit/bindgen.rb
+++ b/tool/rjit/bindgen.rb
@@ -539,6 +539,8 @@ generator = BindingGenerator.new(
rb_vm_getclassvariable
rb_vm_ic_hit_p
rb_vm_opt_newarray_min
+ rb_vm_opt_newarray_max
+ rb_vm_opt_newarray_hash
rb_vm_setinstancevariable
rb_vm_splat_array
rjit_full_cfunc_return