summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2023-03-01 23:38:12 -0800
committerTakashi Kokubun <[email protected]>2023-03-05 23:28:59 -0800
commit357007626ce77cd3cdb9e44568c1794e515792f6 (patch)
tree6ead6dd60f21428a97404f6138a03be3000c8448
parent42adcd5743d68b96391c96d7b23e3890606afb1a (diff)
Implement opt_newarray_min
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7448
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb30
-rw-r--r--mjit_c.rb7
2 files changed, 34 insertions, 3 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index 247cdbe260..9a86181b64 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -22,7 +22,7 @@ module RubyVM::MJIT
asm.incr_counter(:mjit_insns_count)
asm.comment("Insn: #{insn.name}")
- # 61/101
+ # 62/101
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
@@ -81,7 +81,7 @@ module RubyVM::MJIT
when :opt_nil_p then opt_nil_p(jit, ctx, asm)
# opt_str_uminus
# opt_newarray_max
- # opt_newarray_min
+ when :opt_newarray_min then opt_newarray_min(jit, ctx, asm)
when :invokesuper then invokesuper(jit, ctx, asm)
# invokeblock
when :leave then leave(jit, ctx, asm)
@@ -725,7 +725,31 @@ module RubyVM::MJIT
# opt_str_uminus
# opt_newarray_max
- # opt_newarray_min
+
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def opt_newarray_min(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_min)
+
+ ctx.stack_pop(num)
+ stack_ret = ctx.stack_push
+ asm.mov(stack_ret, C_RET)
+
+ KeepCompiling
+ end
# @param jit [RubyVM::MJIT::JITState]
# @param ctx [RubyVM::MJIT::Context]
diff --git a/mjit_c.rb b/mjit_c.rb
index b1c573fe6e..cabc6ccbcf 100644
--- a/mjit_c.rb
+++ b/mjit_c.rb
@@ -254,6 +254,13 @@ module RubyVM::MJIT # :nodoc: all
}
end
+ def rb_vm_opt_newarray_min
+ Primitive.cstmt! %{
+ extern VALUE rb_vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr);
+ return SIZET2NUM((size_t)rb_vm_opt_newarray_min);
+ }
+ end
+
#========================================================================================
#
# Old stuff