From 44c4a2d80d72f1261cfe41ca04ac8e9b826793ca Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Tue, 21 Feb 2023 00:16:05 -0800 Subject: [PATCH] Implement splatarray --- lib/ruby_vm/mjit/insn_compiler.rb | 30 +++++++++++++++++++++++++++--- mjit_c.rb | 7 +++++++ 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 094ffa832d..0ed0924519 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}") - # 54/101 + # 55/101 case insn.name when :nop then nop(jit, ctx, asm) when :getlocal then getlocal(jit, ctx, asm) @@ -57,7 +57,7 @@ module RubyVM::MJIT # duphash when :expandarray then expandarray(jit, ctx, asm) # concatarray - # splatarray + when :splatarray then splatarray(jit, ctx, asm) # newhash # newrange when :pop then pop(jit, ctx, asm) @@ -431,7 +431,31 @@ module RubyVM::MJIT end # concatarray - # splatarray + + # @param jit [RubyVM::MJIT::JITState] + # @param ctx [RubyVM::MJIT::Context] + # @param asm [RubyVM::MJIT::Assembler] + def splatarray(jit, ctx, asm) + flag = jit.operand(0) + + # Save the PC and SP because the callee may allocate + # Note that this modifies REG_SP, which is why we do it first + jit_prepare_routine_call(jit, ctx, asm) + + # Get the operands from the stack + ary_opnd = ctx.stack_pop(1) + + # Call rb_vm_splat_array(flag, ary) + asm.mov(C_ARGS[0], flag) + asm.mov(C_ARGS[1], ary_opnd) + asm.call(C.rb_vm_splat_array) + + stack_ret = ctx.stack_push + asm.mov(stack_ret, C_RET) + + KeepCompiling + end + # newhash # newrange diff --git a/mjit_c.rb b/mjit_c.rb index d8d7d98fde..f169d582a4 100644 --- a/mjit_c.rb +++ b/mjit_c.rb @@ -192,6 +192,13 @@ module RubyVM::MJIT # :nodoc: all Primitive.cexpr! 'SIZET2NUM((size_t)rb_ec_ary_new_from_values)' end + def rb_vm_splat_array + Primitive.cstmt! %{ + extern VALUE rb_vm_splat_array(VALUE flag, VALUE array); + return SIZET2NUM((size_t)rb_vm_splat_array); + } + end + #======================================================================================== # # Old stuff