diff options
author | Takashi Kokubun <[email protected]> | 2022-12-28 14:43:04 -0800 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-03-05 22:11:20 -0800 |
commit | 7a19aad8c355c1f476712afa3024a71e630f43dc (patch) | |
tree | 649fee4997826b9daa2f94b96146799d8c838a7f | |
parent | 9352f94a1b7874a254f124ec8e719151d2b02946 (diff) |
Implement putobject
-rw-r--r-- | lib/ruby_vm/mjit/compiler.rb | 59 | ||||
-rw-r--r-- | lib/ruby_vm/mjit/insn_compiler.rb | 24 | ||||
-rw-r--r-- | lib/ruby_vm/mjit/x86_assembler.rb | 14 |
3 files changed, 86 insertions, 11 deletions
diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb index b24cfe6a7b..532dbe01ea 100644 --- a/lib/ruby_vm/mjit/compiler.rb +++ b/lib/ruby_vm/mjit/compiler.rb @@ -153,7 +153,66 @@ module RubyVM::MJIT asm.comment("Insn: #{insn.name}") case insn.name + # nop + # getlocal + # setlocal + # getblockparam + # setblockparam + # getblockparamproxy + # getspecial + # setspecial + # getinstancevariable + # setinstancevariable + # getclassvariable + # setclassvariable + # opt_getconstant_path + # getconstant + # setconstant + # getglobal + # setglobal when :putnil then @insn_compiler.putnil(jit, ctx, asm) + # putself + when :putobject then @insn_compiler.putobject(jit, ctx, asm) + # putspecialobject + # putstring + # concatstrings + # anytostring + # toregexp + # intern + # newarray + # newarraykwsplat + # duparray + # duphash + # expandarray + # concatarray + # splatarray + # newhash + # newrange + # pop + # dup + # dupn + # swap + # opt_reverse + # topn + # setn + # adjuststack + # defined + # checkmatch + # checkkeyword + # checktype + # defineclass + # definemethod + # definesmethod + # send + # opt_send_without_block + # objtostring + # opt_str_freeze + # opt_nil_p + # opt_str_uminus + # opt_newarray_max + # opt_newarray_min + # invokesuper + # invokeblock when :leave then @insn_compiler.leave(jit, ctx, asm) # throw # jump diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb index 091afaa214..405703e3ff 100644 --- a/lib/ruby_vm/mjit/insn_compiler.rb +++ b/lib/ruby_vm/mjit/insn_compiler.rb @@ -4,7 +4,7 @@ module RubyVM::MJIT # sp: rbx # scratch regs: rax class InsnCompiler - # 3/101 + # 4/101 # nop # getlocal @@ -34,7 +34,27 @@ module RubyVM::MJIT end # putself - # putobject + + # @param jit [RubyVM::MJIT::JITState] + # @param ctx [RubyVM::MJIT::Context] + # @param asm [RubyVM::MJIT::X86Assembler] + def putobject(jit, ctx, asm) + # Get operands + val = jit.operand(0) + + # Push it to the stack + # TODO: GC offsets + if asm.imm32?(val) + asm.mov([SP, C.VALUE.size * ctx.stack_size], val) + else # 64-bit immediates can't be directly written to memory + asm.mov(:rax, val) + asm.mov([SP, C.VALUE.size * ctx.stack_size], :rax) + end + + ctx.stack_size += 1 + KeepCompiling + end + # putspecialobject # putstring # concatstrings diff --git a/lib/ruby_vm/mjit/x86_assembler.rb b/lib/ruby_vm/mjit/x86_assembler.rb index 1eef272eb4..fddd39f933 100644 --- a/lib/ruby_vm/mjit/x86_assembler.rb +++ b/lib/ruby_vm/mjit/x86_assembler.rb @@ -245,6 +245,10 @@ module RubyVM::MJIT end end + def imm32?(imm) + (-0x8000_0000..0x7fff_ffff).include?(imm) # TODO: consider uimm + end + private def insn(prefix: nil, opcode:, mod_rm: nil, disp: nil, imm: nil) @@ -347,16 +351,8 @@ module RubyVM::MJIT (-0x80..0x7f).include?(imm) end - def imm32?(imm) - raise "negative imm not supported: #{imm}" if imm.negative? # TODO: support this - # TODO: consider rejecting small values - imm <= 0x7fff_ffff # TODO: consider uimm - end - def imm64?(imm) - raise "negative imm not supported: #{imm}" if imm.negative? # TODO: support this - # TODO: consider rejecting small values - imm <= 0x7fff_ffff_ffff_ffff # TODO: consider uimm + (-0x8000_0000_0000_0000..0x7fff_ffff_ffff_ffff).include?(imm) # TODO: consider uimm end def r32?(reg) |