Skip to content

Commit

Permalink
Implement splatarray
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 6, 2023
1 parent a666079 commit 44c4a2d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
30 changes: 27 additions & 3 deletions lib/ruby_vm/mjit/insn_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def compile(jit, ctx, asm, insn)
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)
Expand Down Expand Up @@ -57,7 +57,7 @@ def compile(jit, ctx, asm, insn)
# 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)
Expand Down Expand Up @@ -431,7 +431,31 @@ def expandarray(jit, ctx, asm)
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

Expand Down
7 changes: 7 additions & 0 deletions mjit_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ def rb_ec_ary_new_from_values
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
Expand Down

0 comments on commit 44c4a2d

Please sign in to comment.