summaryrefslogtreecommitdiff
path: root/zjit/src/backend/x86_64/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'zjit/src/backend/x86_64/mod.rs')
-rw-r--r--zjit/src/backend/x86_64/mod.rs67
1 files changed, 45 insertions, 22 deletions
diff --git a/zjit/src/backend/x86_64/mod.rs b/zjit/src/backend/x86_64/mod.rs
index cf62cdd7f5..d83fc184f9 100644
--- a/zjit/src/backend/x86_64/mod.rs
+++ b/zjit/src/backend/x86_64/mod.rs
@@ -109,11 +109,6 @@ impl Assembler
vec![RAX_REG, RCX_REG, RDX_REG, RSI_REG, RDI_REG, R8_REG, R9_REG, R10_REG, R11_REG]
}
- /// Get the address that the current frame returns to
- pub fn return_addr_opnd() -> Opnd {
- Opnd::mem(64, Opnd::Reg(RSP_REG), 0)
- }
-
// These are the callee-saved registers in the x86-64 SysV ABI
// RBX, RSP, RBP, and R12–R15
@@ -298,19 +293,24 @@ impl Assembler
let opnd1 = asm.load(*src);
asm.mov(*dest, opnd1);
},
- (Opnd::Mem(_), Opnd::UImm(value)) => {
- // 32-bit values will be sign-extended
- if imm_num_bits(*value as i64) > 32 {
+ (Opnd::Mem(Mem { num_bits, .. }), Opnd::UImm(value)) => {
+ // For 64 bit destinations, 32-bit values will be sign-extended
+ if *num_bits == 64 && imm_num_bits(*value as i64) > 32 {
let opnd1 = asm.load(*src);
asm.mov(*dest, opnd1);
} else {
asm.mov(*dest, *src);
}
},
- (Opnd::Mem(_), Opnd::Imm(value)) => {
- if imm_num_bits(*value) > 32 {
+ (Opnd::Mem(Mem { num_bits, .. }), Opnd::Imm(value)) => {
+ // For 64 bit destinations, 32-bit values will be sign-extended
+ if *num_bits == 64 && imm_num_bits(*value) > 32 {
let opnd1 = asm.load(*src);
asm.mov(*dest, opnd1);
+ } else if uimm_num_bits(*value as u64) <= *num_bits {
+ // If the bit string is short enough for the destination, use the unsigned representation.
+ // Note that 64-bit and negative values are ruled out.
+ asm.mov(*dest, Opnd::UImm(*value as u64));
} else {
asm.mov(*dest, *src);
}
@@ -859,20 +859,17 @@ impl Assembler
}
}
-/*
#[cfg(test)]
mod tests {
- use crate::disasm::assert_disasm;
- #[cfg(feature = "disasm")]
- use crate::disasm::{unindent, disasm_addr_range};
-
+ use crate::assertions::assert_disasm;
use super::*;
fn setup_asm() -> (Assembler, CodeBlock) {
- (Assembler::new(0), CodeBlock::new_dummy(1024))
+ (Assembler::new(), CodeBlock::new_dummy())
}
#[test]
+ #[ignore]
fn test_emit_add_lt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -883,6 +880,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_emit_add_gt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -893,6 +891,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_emit_and_lt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -903,6 +902,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_emit_and_gt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -957,6 +957,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_emit_or_lt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -967,6 +968,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_emit_or_gt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -977,6 +979,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_emit_sub_lt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -987,6 +990,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_emit_sub_gt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -1017,6 +1021,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_emit_xor_lt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -1027,6 +1032,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_emit_xor_gt_32_bits() {
let (mut asm, mut cb) = setup_asm();
@@ -1050,6 +1056,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_merge_lea_mem() {
let (mut asm, mut cb) = setup_asm();
@@ -1064,6 +1071,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_replace_cmp_0() {
let (mut asm, mut cb) = setup_asm();
@@ -1216,6 +1224,7 @@ mod tests {
}
#[test]
+ #[ignore]
fn test_reorder_c_args_with_insn_out() {
let (mut asm, mut cb) = setup_asm();
@@ -1259,15 +1268,16 @@ mod tests {
asm.compile_with_num_regs(&mut cb, 1);
- assert_disasm!(cb, "48837b1001b804000000480f4f03488903", {"
+ assert_disasm!(cb, "48837b1001bf04000000480f4f3b48893b", {"
0x0: cmp qword ptr [rbx + 0x10], 1
- 0x5: mov eax, 4
- 0xa: cmovg rax, qword ptr [rbx]
- 0xe: mov qword ptr [rbx], rax
+ 0x5: mov edi, 4
+ 0xa: cmovg rdi, qword ptr [rbx]
+ 0xe: mov qword ptr [rbx], rdi
"});
}
#[test]
+ #[ignore]
fn test_csel_split() {
let (mut asm, mut cb) = setup_asm();
@@ -1284,6 +1294,19 @@ mod tests {
0x13: mov qword ptr [rbx], rax
"});
}
-}
-*/
+ #[test]
+ fn test_mov_m32_imm32() {
+ let (mut asm, mut cb) = setup_asm();
+
+ let shape_opnd = Opnd::mem(32, C_RET_OPND, 0);
+ asm.mov(shape_opnd, Opnd::UImm(0x8000_0001));
+ asm.mov(shape_opnd, Opnd::Imm(0x8000_0001));
+
+ asm.compile_with_num_regs(&mut cb, 0);
+ assert_disasm!(cb, "c70001000080c70001000080", {"
+ 0x0: mov dword ptr [rax], 0x80000001
+ 0x6: mov dword ptr [rax], 0x80000001
+ "});
+ }
+}