mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
ZJIT: Avoid splitting add_into/sub_into for x86_64 (#14177)
* ZJIT: Avoid splitting add_into/sub_into * Require add_into/sub_into to take a Reg
This commit is contained in:
parent
c5c894c6e4
commit
e26ab5dbf2
2 changed files with 42 additions and 9 deletions
|
@ -1889,9 +1889,9 @@ impl Assembler {
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_into(&mut self, left: Opnd, right: Opnd) -> Opnd {
|
pub fn add_into(&mut self, left: Opnd, right: Opnd) {
|
||||||
|
assert!(matches!(left, Opnd::Reg(_)), "Destination of add_into must be Opnd::Reg, but got: {left:?}");
|
||||||
self.push_insn(Insn::Add { left, right, out: left });
|
self.push_insn(Insn::Add { left, right, out: left });
|
||||||
left
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
@ -2233,10 +2233,9 @@ impl Assembler {
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sub_into(&mut self, left: Opnd, right: Opnd) -> Opnd {
|
pub fn sub_into(&mut self, left: Opnd, right: Opnd) {
|
||||||
let out = self.sub(left, right);
|
assert!(matches!(left, Opnd::Reg(_)), "Destination of sub_into must be Opnd::Reg, but got: {left:?}");
|
||||||
self.mov(left, out);
|
self.push_insn(Insn::Sub { left, right, out: left });
|
||||||
out
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|
|
@ -197,9 +197,15 @@ impl Assembler
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// We have to load memory operands to avoid corrupting them
|
// We have to load memory operands to avoid corrupting them
|
||||||
(Opnd::Mem(_) | Opnd::Reg(_), _) => {
|
(Opnd::Mem(_), _) => {
|
||||||
*left = asm.load(*left);
|
*left = asm.load(*left);
|
||||||
},
|
},
|
||||||
|
// We have to load register operands to avoid corrupting them
|
||||||
|
(Opnd::Reg(_), _) => {
|
||||||
|
if *left != *out {
|
||||||
|
*left = asm.load(*left);
|
||||||
|
}
|
||||||
|
},
|
||||||
// The first operand can't be an immediate value
|
// The first operand can't be an immediate value
|
||||||
(Opnd::UImm(_), _) => {
|
(Opnd::UImm(_), _) => {
|
||||||
*left = asm.load(*left);
|
*left = asm.load(*left);
|
||||||
|
@ -1164,7 +1170,21 @@ mod tests {
|
||||||
asm.mov(CFP, sp); // should be merged to add
|
asm.mov(CFP, sp); // should be merged to add
|
||||||
asm.compile_with_num_regs(&mut cb, 1);
|
asm.compile_with_num_regs(&mut cb, 1);
|
||||||
|
|
||||||
assert_eq!(format!("{:x}", cb), "4983c540");
|
assert_disasm!(cb, "4983c540", {"
|
||||||
|
0x0: add r13, 0x40
|
||||||
|
"});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_add_into() {
|
||||||
|
let (mut asm, mut cb) = setup_asm();
|
||||||
|
|
||||||
|
asm.add_into(CFP, Opnd::UImm(0x40));
|
||||||
|
asm.compile_with_num_regs(&mut cb, 1);
|
||||||
|
|
||||||
|
assert_disasm!(cb, "4983c540", {"
|
||||||
|
0x0: add r13, 0x40
|
||||||
|
"});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1175,7 +1195,21 @@ mod tests {
|
||||||
asm.mov(CFP, sp); // should be merged to add
|
asm.mov(CFP, sp); // should be merged to add
|
||||||
asm.compile_with_num_regs(&mut cb, 1);
|
asm.compile_with_num_regs(&mut cb, 1);
|
||||||
|
|
||||||
assert_eq!(format!("{:x}", cb), "4983ed40");
|
assert_disasm!(cb, "4983ed40", {"
|
||||||
|
0x0: sub r13, 0x40
|
||||||
|
"});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sub_into() {
|
||||||
|
let (mut asm, mut cb) = setup_asm();
|
||||||
|
|
||||||
|
asm.sub_into(CFP, Opnd::UImm(0x40));
|
||||||
|
asm.compile_with_num_regs(&mut cb, 1);
|
||||||
|
|
||||||
|
assert_disasm!(cb, "4983ed40", {"
|
||||||
|
0x0: sub r13, 0x40
|
||||||
|
"});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue