Define constants for magic registers

This commit is contained in:
Takashi Kokubun 2022-12-23 16:23:21 -08:00
Родитель 783f730773
Коммит 5db2ef5e14
2 изменённых файлов: 16 добавлений и 11 удалений

Просмотреть файл

@ -7,7 +7,7 @@ module RubyVM::MJIT
# @param ctx [RubyVM::MJIT::Context]
# @param asm [RubyVM::MJIT::X86Assembler]
def putnil(ctx, asm)
asm.mov([:rbx], Qnil)
asm.mov([SP], Qnil)
ctx.stack_size += 1
KeepCompiling
end
@ -19,14 +19,14 @@ module RubyVM::MJIT
# TODO: Check interrupts
# Pop the current frame (ec->cfp++)
asm.add(:rsi, C.rb_control_frame_t.size) # rsi = cfp + 1
asm.mov([:rdi, C.rb_execution_context_t.offsetof(:cfp)], :rsi) # ec->cfp = rsi
asm.add(CFP, C.rb_control_frame_t.size) # cfp = cfp + 1
asm.mov([EC, C.rb_execution_context_t.offsetof(:cfp)], CFP) # ec->cfp = cfp
# Return a value
asm.mov(:rax, [:rbx])
asm.mov(:rax, [SP])
# Restore callee-saved registers
asm.pop(:rbx)
asm.pop(SP)
asm.ret
EndBlock

Просмотреть файл

@ -13,6 +13,11 @@ module RubyVM::MJIT
Qnil = Fiddle::Qnil
Qundef = Fiddle::Qundef
# Fixed registers
EC = :rdi # TODO: change this
CFP = :rsi # TODO: change this
SP = :rbx
class Compiler
attr_accessor :write_pos
@ -65,10 +70,10 @@ module RubyVM::MJIT
# @param asm [RubyVM::MJIT::X86Assembler]
def compile_prologue(asm)
# Save callee-saved registers used by JITed code
asm.push(:rbx)
asm.push(SP)
# 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
# @param asm [RubyVM::MJIT::X86Assembler]
@ -103,16 +108,16 @@ module RubyVM::MJIT
def compile_exit(ctx, asm, exit_pc)
# update 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
if ctx.stack_size > 0
asm.add(:rbx, C.VALUE.size * ctx.stack_size) # rbx += stack_size
asm.mov([:rsi, C.rb_control_frame_t.offsetof(:sp)], :rbx) # cfp->sp = rbx
asm.add(SP, C.VALUE.size * ctx.stack_size) # rbx += stack_size
asm.mov([CFP, C.rb_control_frame_t.offsetof(:sp)], SP) # cfp->sp = rbx
end
# Restore callee-saved registers
asm.pop(:rbx)
asm.pop(SP)
asm.mov(:rax, Qundef)
asm.ret