summaryrefslogtreecommitdiff
path: root/lib/ruby_vm/mjit/insn_compiler.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2023-02-08 01:17:39 -0800
committerTakashi Kokubun <[email protected]>2023-03-05 22:11:20 -0800
commitd332c6ee126870aa3413de8d96e493b527559181 (patch)
tree65501a6ec0a578c7d29e2c7ee53dae4b5990de5a /lib/ruby_vm/mjit/insn_compiler.rb
parente92edfc7f02edfbc9bedddc5b4e162c00ac141b8 (diff)
Implement getlocal_WC_1
Diffstat (limited to 'lib/ruby_vm/mjit/insn_compiler.rb')
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb42
1 files changed, 38 insertions, 4 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index b30f1e7988..43fd1e9648 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -17,7 +17,7 @@ module RubyVM::MJIT
asm.incr_counter(:mjit_insns_count)
asm.comment("Insn: #{insn.name}")
- # 14/101
+ # 15/101
case insn.name
when :nop then nop(jit, ctx, asm)
# getlocal
@@ -115,6 +115,7 @@ module RubyVM::MJIT
# opt_invokebuiltin_delegate
# opt_invokebuiltin_delegate_leave
when :getlocal_WC_0 then getlocal_WC_0(jit, ctx, asm)
+ when :getlocal_WC_1 then getlocal_WC_1(jit, ctx, asm)
# setlocal_WC_0
# setlocal_WC_1
when :putobject_INT2FIX_0_ then putobject_INT2FIX_0_(jit, ctx, asm)
@@ -516,12 +517,31 @@ module RubyVM::MJIT
asm.mov(:rax, [:rax, -idx * C.VALUE.size])
# Push it to the stack
- asm.mov([SP, C.VALUE.size * ctx.stack_size], :rax)
- ctx.stack_push(1)
+ stack_top = ctx.stack_push
+ asm.mov(stack_top, :rax)
+ KeepCompiling
+ end
+
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def getlocal_WC_1(jit, ctx, asm)
+ # Get operands
+ idx = jit.operand(0)
+ level = 1
+
+ # Get EP
+ ep_reg = jit_get_ep(asm, level)
+
+ # Get a local variable
+ asm.mov(:rax, [ep_reg, -idx * C.VALUE.size])
+
+ # Push it to the stack
+ stack_top = ctx.stack_push
+ asm.mov(stack_top, :rax)
KeepCompiling
end
- # getlocal_WC_1
# setlocal_WC_0
# setlocal_WC_1
@@ -611,6 +631,20 @@ module RubyVM::MJIT
asm.jnz(side_exit(jit, ctx))
end
+ # vm_get_ep
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def jit_get_ep(asm, level)
+ asm.mov(:rax, [CFP, C.rb_control_frame_t.offsetof(:ep)])
+ level.times do
+ # GET_PREV_EP: ep[VM_ENV_DATA_INDEX_SPECVAL] & ~0x03
+ asm.mov(:rax, [:rax, C.VALUE.size * C.VM_ENV_DATA_INDEX_SPECVAL])
+ asm.and(:rax, ~0x03)
+ end
+ return :rax
+ end
+
# vm_getivar
# @param jit [RubyVM::MJIT::JITState]
# @param ctx [RubyVM::MJIT::Context]