diff options
author | Kevin Newton <kddnewton@gmail.com> | 2022-07-15 13:25:26 -0400 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2022-08-29 08:47:00 -0700 |
commit | 160e29b9e5c9419e3275d4bd6de09c9c4f242602 (patch) | |
tree | 01f20b0abf80ebbcd959ac962687f4274f87c606 /yjit/src/utils.rs | |
parent | 6c5008959925d2768e9495a5601b5245784bc87f (diff) | |
download | ruby-160e29b9e5c9419e3275d4bd6de09c9c4f242602.tar.gz |
Port print_str to new backend (https://github.com/Shopify/ruby/pull/318)
* ADR and ADRP for AArch64
* Implement Op::Jbe on X86
* Lera instruction
* Op::BakeString
* LeaPC -> LeaLabel
* Port print_str to the new backend
* Port print_value to the new backend
* Port print_ptr to the new backend
* Write null-terminators in Op::BakeString
* Fix up rebase issues on print-str port
* Add back in panic for X86 backend for unsupported instructions being lowered
* Fix target architecture
Diffstat (limited to 'yjit/src/utils.rs')
-rw-r--r-- | yjit/src/utils.rs | 89 |
1 files changed, 24 insertions, 65 deletions
diff --git a/yjit/src/utils.rs b/yjit/src/utils.rs index dd89413090..98af604193 100644 --- a/yjit/src/utils.rs +++ b/yjit/src/utils.rs @@ -1,7 +1,6 @@ #![allow(dead_code)] // Some functions for print debugging in here -use crate::asm::x86_64::*; -use crate::asm::*; +use crate::backend::ir::*; use crate::cruby::*; use std::slice; @@ -164,34 +163,7 @@ macro_rules! c_callable { } pub(crate) use c_callable; -// Save caller-save registers on the stack before a C call -fn push_regs(cb: &mut CodeBlock) { - push(cb, RAX); - push(cb, RCX); - push(cb, RDX); - push(cb, RSI); - push(cb, RDI); - push(cb, R8); - push(cb, R9); - push(cb, R10); - push(cb, R11); - pushfq(cb); -} - -// Restore caller-save registers from the after a C call -fn pop_regs(cb: &mut CodeBlock) { - popfq(cb); - pop(cb, R11); - pop(cb, R10); - pop(cb, R9); - pop(cb, R8); - pop(cb, RDI); - pop(cb, RSI); - pop(cb, RDX); - pop(cb, RCX); - pop(cb, RAX); -} - +/* pub fn print_int(cb: &mut CodeBlock, opnd: X86Opnd) { c_callable!{ fn print_int_fn(val: i64) { @@ -220,45 +192,40 @@ pub fn print_int(cb: &mut CodeBlock, opnd: X86Opnd) { call(cb, RAX); pop_regs(cb); } +*/ /// Generate code to print a pointer -pub fn print_ptr(cb: &mut CodeBlock, opnd: X86Opnd) { +pub fn print_ptr(asm: &mut Assembler, opnd: Opnd) { c_callable!{ fn print_ptr_fn(ptr: *const u8) { println!("{:p}", ptr); } } - assert!(opnd.num_bits() == 64); + assert!(opnd.rm_num_bits() == 64); - push_regs(cb); - mov(cb, C_ARG_REGS[0], opnd); - mov(cb, RAX, const_ptr_opnd(print_ptr_fn as *const u8)); - call(cb, RAX); - pop_regs(cb); + asm.cpush_all(); + asm.ccall(print_ptr_fn as *const u8, vec![opnd]); + asm.cpop_all(); } /// Generate code to print a value -pub fn print_value(cb: &mut CodeBlock, opnd: X86Opnd) { +pub fn print_value(asm: &mut Assembler, opnd: Opnd) { c_callable!{ fn print_value_fn(val: VALUE) { unsafe { rb_obj_info_dump(val) } } } - assert!(opnd.num_bits() == 64); - - push_regs(cb); - - mov(cb, RDI, opnd); - mov(cb, RAX, const_ptr_opnd(print_value_fn as *const u8)); - call(cb, RAX); + assert!(matches!(opnd, Opnd::Value(_))); - pop_regs(cb); + asm.cpush_all(); + asm.ccall(print_value_fn as *const u8, vec![opnd]); + asm.cpop_all(); } /// Generate code to print constant string to stdout -pub fn print_str(cb: &mut CodeBlock, str: &str) { +pub fn print_str(asm: &mut Assembler, str: &str) { c_callable!{ fn print_str_cfun(ptr: *const u8, num_bytes: usize) { unsafe { @@ -269,26 +236,18 @@ pub fn print_str(cb: &mut CodeBlock, str: &str) { } } - let bytes = str.as_ptr(); - let num_bytes = str.len(); - - push_regs(cb); + asm.cpush_all(); - // Load the string address and jump over the string data - lea(cb, C_ARG_REGS[0], mem_opnd(8, RIP, 5)); - jmp32(cb, num_bytes as i32); + let string_data = asm.new_label("string_data"); + let after_string = asm.new_label("after_string"); - // Write the string chars and a null terminator - for i in 0..num_bytes { - cb.write_byte(unsafe { *bytes.add(i) }); - } + asm.jmp(after_string); + asm.write_label(string_data); + asm.bake_string(str); + asm.write_label(after_string); - // Pass the string length as an argument - mov(cb, C_ARG_REGS[1], uimm_opnd(num_bytes as u64)); + let opnd = asm.lea_label(string_data); + asm.ccall(print_str_cfun as *const u8, vec![opnd, Opnd::UImm(str.len() as u64)]); - // Call the print function - mov(cb, RAX, const_ptr_opnd(print_str_cfun as *const u8)); - call(cb, RAX); - - pop_regs(cb); + asm.cpop_all(); } |