summaryrefslogtreecommitdiff
path: root/lib/mjit/x86_64/assembler.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2022-12-15 22:20:43 -0800
committerTakashi Kokubun <[email protected]>2023-03-05 22:11:20 -0800
commit6fc336fedcbf58cceedd272ecf1ac2f725662f73 (patch)
tree11f64e23cc60e21833a9b3febf4dedc4c8207020 /lib/mjit/x86_64/assembler.rb
parent3fa4d41460f67791d08d9bec2f8add9dd15f0f07 (diff)
Compile a real return value
Diffstat (limited to 'lib/mjit/x86_64/assembler.rb')
-rw-r--r--lib/mjit/x86_64/assembler.rb34
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/mjit/x86_64/assembler.rb b/lib/mjit/x86_64/assembler.rb
index 5458746c9b..be6480bba7 100644
--- a/lib/mjit/x86_64/assembler.rb
+++ b/lib/mjit/x86_64/assembler.rb
@@ -5,22 +5,34 @@ class RubyVM::MJIT::Assembler
@bytes = []
end
- def compile(compiler)
- with_dump_disasm(compiler) do
- RubyVM::MJIT::C.mjit_mark_writable
- write_bytes(compiler.write_addr, @bytes)
- RubyVM::MJIT::C.mjit_mark_executable
-
- compiler.write_pos += @bytes.size
- @bytes.clear
- end
+ def compile(compiler) = with_dump_disasm(compiler) do
+ RubyVM::MJIT::C.mjit_mark_writable
+ write_bytes(compiler.write_addr, @bytes)
+ RubyVM::MJIT::C.mjit_mark_executable
+
+ compiler.write_pos += @bytes.size
+ @bytes.clear
end
- def mov(_reg, val)
- @bytes.push(0xb8, val, 0x00, 0x00, 0x00)
+ def add(_reg, imm)
+ # REX.W [83] RSI ib
+ @bytes.push(0x48, 0x83, 0xc6, imm)
+ end
+
+ def mov(reg, val)
+ case reg
+ when :rax
+ # REX.W [C7] RAX imm32
+ @bytes.push(0x48, 0xc7, 0xc0, val, 0x00, 0x00, 0x00)
+ else
+ # REX.W [89] [rdi+val],rsi
+ @bytes.push(0x48, 0x89, 0x77, reg.last)
+ end
end
def ret
+ # Near return
+ # [C3]
@bytes.push(0xc3)
end