mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 05:55:46 +02:00
Define constants for magic registers
This commit is contained in:
parent
783f730773
commit
5db2ef5e14
2 changed files with 16 additions and 11 deletions
|
@ -7,7 +7,7 @@ module RubyVM::MJIT
|
||||||
# @param ctx [RubyVM::MJIT::Context]
|
# @param ctx [RubyVM::MJIT::Context]
|
||||||
# @param asm [RubyVM::MJIT::X86Assembler]
|
# @param asm [RubyVM::MJIT::X86Assembler]
|
||||||
def putnil(ctx, asm)
|
def putnil(ctx, asm)
|
||||||
asm.mov([:rbx], Qnil)
|
asm.mov([SP], Qnil)
|
||||||
ctx.stack_size += 1
|
ctx.stack_size += 1
|
||||||
KeepCompiling
|
KeepCompiling
|
||||||
end
|
end
|
||||||
|
@ -19,14 +19,14 @@ module RubyVM::MJIT
|
||||||
# TODO: Check interrupts
|
# TODO: Check interrupts
|
||||||
|
|
||||||
# Pop the current frame (ec->cfp++)
|
# Pop the current frame (ec->cfp++)
|
||||||
asm.add(:rsi, C.rb_control_frame_t.size) # rsi = cfp + 1
|
asm.add(CFP, C.rb_control_frame_t.size) # cfp = cfp + 1
|
||||||
asm.mov([:rdi, C.rb_execution_context_t.offsetof(:cfp)], :rsi) # ec->cfp = rsi
|
asm.mov([EC, C.rb_execution_context_t.offsetof(:cfp)], CFP) # ec->cfp = cfp
|
||||||
|
|
||||||
# Return a value
|
# Return a value
|
||||||
asm.mov(:rax, [:rbx])
|
asm.mov(:rax, [SP])
|
||||||
|
|
||||||
# Restore callee-saved registers
|
# Restore callee-saved registers
|
||||||
asm.pop(:rbx)
|
asm.pop(SP)
|
||||||
|
|
||||||
asm.ret
|
asm.ret
|
||||||
EndBlock
|
EndBlock
|
||||||
|
|
|
@ -13,6 +13,11 @@ module RubyVM::MJIT
|
||||||
Qnil = Fiddle::Qnil
|
Qnil = Fiddle::Qnil
|
||||||
Qundef = Fiddle::Qundef
|
Qundef = Fiddle::Qundef
|
||||||
|
|
||||||
|
# Fixed registers
|
||||||
|
EC = :rdi # TODO: change this
|
||||||
|
CFP = :rsi # TODO: change this
|
||||||
|
SP = :rbx
|
||||||
|
|
||||||
class Compiler
|
class Compiler
|
||||||
attr_accessor :write_pos
|
attr_accessor :write_pos
|
||||||
|
|
||||||
|
@ -65,10 +70,10 @@ module RubyVM::MJIT
|
||||||
# @param asm [RubyVM::MJIT::X86Assembler]
|
# @param asm [RubyVM::MJIT::X86Assembler]
|
||||||
def compile_prologue(asm)
|
def compile_prologue(asm)
|
||||||
# Save callee-saved registers used by JITed code
|
# Save callee-saved registers used by JITed code
|
||||||
asm.push(:rbx)
|
asm.push(SP)
|
||||||
|
|
||||||
# Load sp to a register
|
# Load sp to a register
|
||||||
asm.mov(:rbx, [:rsi, C.rb_control_frame_t.offsetof(:sp)]) # rbx = cfp->sp
|
asm.mov(SP, [CFP, C.rb_control_frame_t.offsetof(:sp)]) # rbx = cfp->sp
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param asm [RubyVM::MJIT::X86Assembler]
|
# @param asm [RubyVM::MJIT::X86Assembler]
|
||||||
|
@ -103,16 +108,16 @@ module RubyVM::MJIT
|
||||||
def compile_exit(ctx, asm, exit_pc)
|
def compile_exit(ctx, asm, exit_pc)
|
||||||
# update pc
|
# update pc
|
||||||
asm.mov(:rax, exit_pc) # rax = exit_pc
|
asm.mov(:rax, exit_pc) # rax = exit_pc
|
||||||
asm.mov([:rsi, C.rb_control_frame_t.offsetof(:pc)], :rax) # cfp->pc = rax
|
asm.mov([CFP, C.rb_control_frame_t.offsetof(:pc)], :rax) # cfp->pc = rax
|
||||||
|
|
||||||
# update sp
|
# update sp
|
||||||
if ctx.stack_size > 0
|
if ctx.stack_size > 0
|
||||||
asm.add(:rbx, C.VALUE.size * ctx.stack_size) # rbx += stack_size
|
asm.add(SP, C.VALUE.size * ctx.stack_size) # rbx += stack_size
|
||||||
asm.mov([:rsi, C.rb_control_frame_t.offsetof(:sp)], :rbx) # cfp->sp = rbx
|
asm.mov([CFP, C.rb_control_frame_t.offsetof(:sp)], SP) # cfp->sp = rbx
|
||||||
end
|
end
|
||||||
|
|
||||||
# Restore callee-saved registers
|
# Restore callee-saved registers
|
||||||
asm.pop(:rbx)
|
asm.pop(SP)
|
||||||
|
|
||||||
asm.mov(:rax, Qundef)
|
asm.mov(:rax, Qundef)
|
||||||
asm.ret
|
asm.ret
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue