diff options
author | Takashi Kokubun <[email protected]> | 2023-01-07 13:21:14 -0800 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-03-05 22:11:20 -0800 |
commit | 62d36dd1277bdfeac609f89bc64589e8856421b8 (patch) | |
tree | 4c90de46486efd2c8912ef970449f4744630a5ba /lib/ruby_vm/mjit/exit_compiler.rb | |
parent | eddec7bc209d721e99a8cd5ceaafd0f2ab270cc3 (diff) |
Implement branch stub
Diffstat (limited to 'lib/ruby_vm/mjit/exit_compiler.rb')
-rw-r--r-- | lib/ruby_vm/mjit/exit_compiler.rb | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/lib/ruby_vm/mjit/exit_compiler.rb b/lib/ruby_vm/mjit/exit_compiler.rb index a1eca9fe23..3a0c12f525 100644 --- a/lib/ruby_vm/mjit/exit_compiler.rb +++ b/lib/ruby_vm/mjit/exit_compiler.rb @@ -47,19 +47,30 @@ module RubyVM::MJIT # @param jit [RubyVM::MJIT::JITState] # @param ctx [RubyVM::MJIT::Context] # @param asm [RubyVM::MJIT::Assembler] - # @param stub [RubyVM::MJIT::BlockStub] - def compile_jump_stub(jit, ctx, asm, stub) - case stub - when BlockStub - asm.comment("block stub hit: #{stub.iseq.body.location.label}@#{C.rb_iseq_path(stub.iseq)}:#{stub.iseq.body.location.first_lineno}") - else - raise "unexpected stub object: #{stub.inspect}" - end + # @param block_stub [RubyVM::MJIT::BlockStub] + def compile_block_stub(jit, ctx, asm, block_stub) + # Call rb_mjit_block_stub_hit + asm.comment("block stub hit: #{block_stub.iseq.body.location.label}@#{C.rb_iseq_path(block_stub.iseq)}:#{iseq_lineno(block_stub.iseq, block_stub.pc)}") + asm.mov(:rdi, to_value(block_stub)) + asm.mov(:esi, ctx.sp_offset) + asm.call(C.rb_mjit_block_stub_hit) + + # Jump to the address returned by rb_mjit_stub_hit + asm.jmp(:rax) + end - # Call rb_mjit_stub_hit - asm.mov(:rdi, to_value(stub)) + # @param jit [RubyVM::MJIT::JITState] + # @param ctx [RubyVM::MJIT::Context] + # @param asm [RubyVM::MJIT::Assembler] + # @param branch_stub [RubyVM::MJIT::BranchStub] + # @param branch_target_p [TrueClass,FalseClass] + def compile_branch_stub(jit, ctx, asm, branch_stub, branch_target_p) + # Call rb_mjit_branch_stub_hit + asm.comment("branch stub hit: #{branch_stub.iseq.body.location.label}@#{C.rb_iseq_path(branch_stub.iseq)}:#{iseq_lineno(branch_stub.iseq, branch_target_p ? branch_stub.branch_target_pc : branch_stub.fallthrough_pc)}") + asm.mov(:rdi, to_value(branch_stub)) asm.mov(:esi, ctx.sp_offset) - asm.call(C.rb_mjit_stub_hit) + asm.mov(:edx, branch_target_p ? 1 : 0) + asm.call(C.rb_mjit_branch_stub_hit) # Jump to the address returned by rb_mjit_stub_hit asm.jmp(:rax) @@ -103,5 +114,9 @@ module RubyVM::MJIT @gc_refs << obj C.to_value(obj) end + + def iseq_lineno(iseq, pc) + C.rb_iseq_line_no(iseq, (pc - iseq.body.iseq_encoded.to_i) / C.VALUE.size) + end end end |