Cranelift AArch64: Improve the handling of callee-saved registers
SIMD & FP registers are now saved and restored in pairs, similarly to general-purpose registers. Also, only the bottom 64 bits of the registers are saved and restored (in case of non-Baldrdash ABIs), which is the requirement from the Procedure Call Standard for the Arm 64-bit Architecture. As for the callee-saved general-purpose registers, if a procedure needs to save and restore an odd number of them, it no longer uses store and load pair instructions for the last register. Copyright (c) 2021, Arm Limited.
This commit is contained in:
@@ -258,6 +258,28 @@ fn enc_ldst_vec(q: u32, size: u32, rn: Reg, rt: Writable<Reg>) -> u32 {
|
||||
| machreg_to_vec(rt.to_reg())
|
||||
}
|
||||
|
||||
fn enc_ldst_vec_pair(
|
||||
opc: u32,
|
||||
amode: u32,
|
||||
is_load: bool,
|
||||
simm7: SImm7Scaled,
|
||||
rn: Reg,
|
||||
rt: Reg,
|
||||
rt2: Reg,
|
||||
) -> u32 {
|
||||
debug_assert_eq!(opc & 0b11, opc);
|
||||
debug_assert_eq!(amode & 0b11, amode);
|
||||
|
||||
0b00_10110_00_0_0000000_00000_00000_00000
|
||||
| opc << 30
|
||||
| amode << 23
|
||||
| (is_load as u32) << 22
|
||||
| simm7.bits() << 15
|
||||
| machreg_to_vec(rt2) << 10
|
||||
| machreg_to_gpr(rn) << 5
|
||||
| machreg_to_vec(rt)
|
||||
}
|
||||
|
||||
fn enc_vec_rrr(top11: u32, rm: Reg, bit15_10: u32, rn: Reg, rd: Writable<Reg>) -> u32 {
|
||||
(top11 << 21)
|
||||
| (machreg_to_vec(rm) << 16)
|
||||
@@ -923,7 +945,7 @@ impl MachInstEmit for Inst {
|
||||
|
||||
let srcloc = state.cur_srcloc();
|
||||
if srcloc != SourceLoc::default() && !flags.notrap() {
|
||||
// Register the offset at which the actual load instruction starts.
|
||||
// Register the offset at which the actual store instruction starts.
|
||||
sink.add_trap(srcloc, TrapCode::HeapOutOfBounds);
|
||||
}
|
||||
|
||||
@@ -987,7 +1009,7 @@ impl MachInstEmit for Inst {
|
||||
} => {
|
||||
let srcloc = state.cur_srcloc();
|
||||
if srcloc != SourceLoc::default() && !flags.notrap() {
|
||||
// Register the offset at which the actual load instruction starts.
|
||||
// Register the offset at which the actual store instruction starts.
|
||||
sink.add_trap(srcloc, TrapCode::HeapOutOfBounds);
|
||||
}
|
||||
match mem {
|
||||
@@ -1034,6 +1056,120 @@ impl MachInstEmit for Inst {
|
||||
}
|
||||
}
|
||||
}
|
||||
&Inst::FpuLoadP64 {
|
||||
rt,
|
||||
rt2,
|
||||
ref mem,
|
||||
flags,
|
||||
}
|
||||
| &Inst::FpuLoadP128 {
|
||||
rt,
|
||||
rt2,
|
||||
ref mem,
|
||||
flags,
|
||||
} => {
|
||||
let srcloc = state.cur_srcloc();
|
||||
|
||||
if srcloc != SourceLoc::default() && !flags.notrap() {
|
||||
// Register the offset at which the actual load instruction starts.
|
||||
sink.add_trap(srcloc, TrapCode::HeapOutOfBounds);
|
||||
}
|
||||
|
||||
let opc = match self {
|
||||
&Inst::FpuLoadP64 { .. } => 0b01,
|
||||
&Inst::FpuLoadP128 { .. } => 0b10,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let rt = rt.to_reg();
|
||||
let rt2 = rt2.to_reg();
|
||||
|
||||
match mem {
|
||||
&PairAMode::SignedOffset(reg, simm7) => {
|
||||
assert!(simm7.scale_ty == F64 || simm7.scale_ty == I8X16);
|
||||
sink.put4(enc_ldst_vec_pair(opc, 0b10, true, simm7, reg, rt, rt2));
|
||||
}
|
||||
&PairAMode::PreIndexed(reg, simm7) => {
|
||||
assert!(simm7.scale_ty == F64 || simm7.scale_ty == I8X16);
|
||||
sink.put4(enc_ldst_vec_pair(
|
||||
opc,
|
||||
0b11,
|
||||
true,
|
||||
simm7,
|
||||
reg.to_reg(),
|
||||
rt,
|
||||
rt2,
|
||||
));
|
||||
}
|
||||
&PairAMode::PostIndexed(reg, simm7) => {
|
||||
assert!(simm7.scale_ty == F64 || simm7.scale_ty == I8X16);
|
||||
sink.put4(enc_ldst_vec_pair(
|
||||
opc,
|
||||
0b01,
|
||||
true,
|
||||
simm7,
|
||||
reg.to_reg(),
|
||||
rt,
|
||||
rt2,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
&Inst::FpuStoreP64 {
|
||||
rt,
|
||||
rt2,
|
||||
ref mem,
|
||||
flags,
|
||||
}
|
||||
| &Inst::FpuStoreP128 {
|
||||
rt,
|
||||
rt2,
|
||||
ref mem,
|
||||
flags,
|
||||
} => {
|
||||
let srcloc = state.cur_srcloc();
|
||||
|
||||
if srcloc != SourceLoc::default() && !flags.notrap() {
|
||||
// Register the offset at which the actual store instruction starts.
|
||||
sink.add_trap(srcloc, TrapCode::HeapOutOfBounds);
|
||||
}
|
||||
|
||||
let opc = match self {
|
||||
&Inst::FpuStoreP64 { .. } => 0b01,
|
||||
&Inst::FpuStoreP128 { .. } => 0b10,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
match mem {
|
||||
&PairAMode::SignedOffset(reg, simm7) => {
|
||||
assert!(simm7.scale_ty == F64 || simm7.scale_ty == I8X16);
|
||||
sink.put4(enc_ldst_vec_pair(opc, 0b10, false, simm7, reg, rt, rt2));
|
||||
}
|
||||
&PairAMode::PreIndexed(reg, simm7) => {
|
||||
assert!(simm7.scale_ty == F64 || simm7.scale_ty == I8X16);
|
||||
sink.put4(enc_ldst_vec_pair(
|
||||
opc,
|
||||
0b11,
|
||||
false,
|
||||
simm7,
|
||||
reg.to_reg(),
|
||||
rt,
|
||||
rt2,
|
||||
));
|
||||
}
|
||||
&PairAMode::PostIndexed(reg, simm7) => {
|
||||
assert!(simm7.scale_ty == F64 || simm7.scale_ty == I8X16);
|
||||
sink.put4(enc_ldst_vec_pair(
|
||||
opc,
|
||||
0b01,
|
||||
false,
|
||||
simm7,
|
||||
reg.to_reg(),
|
||||
rt,
|
||||
rt2,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
&Inst::Mov64 { rd, rm } => {
|
||||
assert!(rd.to_reg().get_class() == rm.get_class());
|
||||
assert!(rm.get_class() == RegClass::I64);
|
||||
|
||||
Reference in New Issue
Block a user