Thanks to visit codestin.com
Credit goes to github.com

Skip to content

YJIT: A64: Use ADDS/SUBS/CMP (immediate) when possible #10402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions yjit/src/asm/arm64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ pub fn cmp(cb: &mut CodeBlock, rn: A64Opnd, rm: A64Opnd) {

DataReg::cmp(rn.reg_no, rm.reg_no, rn.num_bits).into()
},
(A64Opnd::Reg(rn), A64Opnd::Imm(imm12)) => {
DataImm::cmp(rn.reg_no, (imm12 as u64).try_into().unwrap(), rn.num_bits).into()
},
(A64Opnd::Reg(rn), A64Opnd::UImm(imm12)) => {
DataImm::cmp(rn.reg_no, imm12.try_into().unwrap(), rn.num_bits).into()
},
Expand Down
39 changes: 37 additions & 2 deletions yjit/src/backend/arm64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ impl Assembler
match opnd {
Opnd::Reg(_) | Opnd::CArg(_) | Opnd::InsnOut { .. } => opnd,
Opnd::Mem(_) => split_load_operand(asm, opnd),
Opnd::Imm(_) => asm.load(opnd),
Opnd::Imm(imm) => if ShiftedImmediate::try_from(imm as u64).is_ok() {
opnd
} else {
asm.load(opnd)
}
Opnd::UImm(uimm) => {
if ShiftedImmediate::try_from(uimm).is_ok() {
opnd
Expand Down Expand Up @@ -655,7 +659,7 @@ impl Assembler
},
Insn::Mul { left, right, .. } => {
let opnd0 = split_load_operand(asm, *left);
let opnd1 = split_shifted_immediate(asm, *right);
let opnd1 = split_load_operand(asm, *right);
asm.mul(opnd0, opnd1);
},
Insn::Test { left, right } => {
Expand Down Expand Up @@ -1704,4 +1708,35 @@ mod tests {
0x8: csel x1, x11, x12, lt
"});
}

#[test]
fn test_add_with_immediate() {
let (mut asm, mut cb) = setup_asm();

let out = asm.add(Opnd::Reg(TEMP_REGS[1]), 1.into());
let out = asm.add(out, 1_usize.into());
asm.mov(Opnd::Reg(TEMP_REGS[0]), out);
asm.compile_with_num_regs(&mut cb, 2);

assert_disasm!(cb, "2b0500b16b0500b1e1030baa", {"
0x0: adds x11, x9, #1
0x4: adds x11, x11, #1
0x8: mov x1, x11
"});
}

#[test]
fn test_mul_with_immediate() {
let (mut asm, mut cb) = setup_asm();

let out = asm.mul(Opnd::Reg(TEMP_REGS[1]), 3.into());
asm.mov(Opnd::Reg(TEMP_REGS[0]), out);
asm.compile_with_num_regs(&mut cb, 2);

assert_disasm!(cb, "6b0080d22b7d0b9be1030baa", {"
0x0: mov x11, #3
0x4: mul x11, x9, x11
0x8: mov x1, x11
"});
}
}