summaryrefslogtreecommitdiff
path: root/lib/ruby_vm
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-02-21 00:02:56 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-05 23:28:59 -0800
commit4106487ae8983e8afadef2a56018635645d2b9bb (patch)
treed7a6797bd035012a94ca0bd530845933caddfd45 /lib/ruby_vm
parent3a97d547257b304d48e6c8a1268e882f9a549d80 (diff)
Implement newarray
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7448
Diffstat (limited to 'lib/ruby_vm')
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb39
1 files changed, 36 insertions, 3 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index bbb2fbf9e5..ce280a0688 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -23,7 +23,7 @@ module RubyVM::MJIT
asm.incr_counter(:mjit_insns_count)
asm.comment("Insn: #{insn.name}")
- # 52/101
+ # 53/101
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
@@ -51,7 +51,7 @@ module RubyVM::MJIT
# anytostring
# toregexp
# intern
- # newarray
+ when :newarray then newarray(jit, ctx, asm)
# newarraykwsplat
when :duparray then duparray(jit, ctx, asm)
# duphash
@@ -304,7 +304,40 @@ module RubyVM::MJIT
# anytostring
# toregexp
# intern
- # newarray
+
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def newarray(jit, ctx, asm)
+ n = jit.operand(0)
+
+ # Save the PC and SP because we are allocating
+ jit_prepare_routine_call(jit, ctx, asm)
+
+ # If n is 0, then elts is never going to be read, so we can just pass null
+ if n == 0
+ values_ptr = 0
+ else
+ asm.comment('load pointer to array elts')
+ offset_magnitude = C.VALUE.size * n
+ values_opnd = ctx.sp_opnd(-(offset_magnitude))
+ asm.lea(:rax, values_opnd)
+ values_ptr = :rax
+ end
+
+ # call rb_ec_ary_new_from_values(struct rb_execution_context_struct *ec, long n, const VALUE *elts);
+ asm.mov(C_ARGS[0], EC)
+ asm.mov(C_ARGS[1], n)
+ asm.mov(C_ARGS[2], values_ptr)
+ asm.call(C.rb_ec_ary_new_from_values)
+
+ ctx.stack_pop(n)
+ stack_ret = ctx.stack_push
+ asm.mov(stack_ret, C_RET)
+
+ KeepCompiling
+ end
+
# newarraykwsplat
# @param jit [RubyVM::MJIT::JITState]