aarch64: Implement iadd for i128 operands
This commit is contained in:
@@ -597,6 +597,8 @@ impl MachInstEmit for Inst {
|
||||
let top11 = match alu_op {
|
||||
ALUOp::Add32 => 0b00001011_000,
|
||||
ALUOp::Add64 => 0b10001011_000,
|
||||
ALUOp::Adc32 => 0b00011010_000,
|
||||
ALUOp::Adc64 => 0b10011010_000,
|
||||
ALUOp::Sub32 => 0b01001011_000,
|
||||
ALUOp::Sub64 => 0b11001011_000,
|
||||
ALUOp::Orr32 => 0b00101010_000,
|
||||
|
||||
@@ -50,6 +50,26 @@ fn test_aarch64_binemit() {
|
||||
"A400068B",
|
||||
"add x4, x5, x6",
|
||||
));
|
||||
insns.push((
|
||||
Inst::AluRRR {
|
||||
alu_op: ALUOp::Adc32,
|
||||
rd: writable_xreg(1),
|
||||
rn: xreg(2),
|
||||
rm: xreg(3),
|
||||
},
|
||||
"4100031A",
|
||||
"adc w1, w2, w3",
|
||||
));
|
||||
insns.push((
|
||||
Inst::AluRRR {
|
||||
alu_op: ALUOp::Adc64,
|
||||
rd: writable_xreg(4),
|
||||
rn: xreg(5),
|
||||
rm: xreg(6),
|
||||
},
|
||||
"A400069A",
|
||||
"adc x4, x5, x6",
|
||||
));
|
||||
insns.push((
|
||||
Inst::AluRRR {
|
||||
alu_op: ALUOp::Sub32,
|
||||
|
||||
@@ -84,6 +84,9 @@ pub enum ALUOp {
|
||||
Asr64,
|
||||
Lsl32,
|
||||
Lsl64,
|
||||
/// Add with carry
|
||||
Adc32,
|
||||
Adc64,
|
||||
}
|
||||
|
||||
/// An ALU operation with three arguments.
|
||||
@@ -1365,6 +1368,23 @@ impl Inst {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create instructions that load a 128-bit constant.
|
||||
pub fn load_constant128(to_regs: ValueRegs<Writable<Reg>>, value: u128) -> SmallVec<[Inst; 4]> {
|
||||
assert_eq!(to_regs.len(), 2, "Expected to load i128 into two registers");
|
||||
|
||||
let lower = value as u64;
|
||||
let upper = (value >> 64) as u64;
|
||||
|
||||
let lower_reg = to_regs.regs()[0];
|
||||
let upper_reg = to_regs.regs()[1];
|
||||
|
||||
let mut load_ins = Inst::load_constant(lower_reg, lower);
|
||||
let load_upper = Inst::load_constant(upper_reg, upper);
|
||||
|
||||
load_ins.extend(load_upper.into_iter());
|
||||
load_ins
|
||||
}
|
||||
|
||||
/// Create instructions that load a 32-bit floating-point constant.
|
||||
pub fn load_fp_constant32<F: FnMut(Type) -> Writable<Reg>>(
|
||||
rd: Writable<Reg>,
|
||||
@@ -3033,30 +3053,15 @@ impl MachInst for Inst {
|
||||
ty: Type,
|
||||
alloc_tmp: F,
|
||||
) -> SmallVec<[Inst; 4]> {
|
||||
let to_reg = to_regs
|
||||
.only_reg()
|
||||
.expect("multi-reg values not supported yet");
|
||||
let value = value as u64;
|
||||
if ty == F64 {
|
||||
Inst::load_fp_constant64(to_reg, value, alloc_tmp)
|
||||
} else if ty == F32 {
|
||||
Inst::load_fp_constant32(to_reg, value as u32, alloc_tmp)
|
||||
} else {
|
||||
// Must be an integer type.
|
||||
debug_assert!(
|
||||
ty == B1
|
||||
|| ty == I8
|
||||
|| ty == B8
|
||||
|| ty == I16
|
||||
|| ty == B16
|
||||
|| ty == I32
|
||||
|| ty == B32
|
||||
|| ty == I64
|
||||
|| ty == B64
|
||||
|| ty == R32
|
||||
|| ty == R64
|
||||
);
|
||||
Inst::load_constant(to_reg, value)
|
||||
let to_reg = to_regs.only_reg();
|
||||
match ty {
|
||||
F64 => Inst::load_fp_constant64(to_reg.unwrap(), value as u64, alloc_tmp),
|
||||
F32 => Inst::load_fp_constant32(to_reg.unwrap(), value as u32, alloc_tmp),
|
||||
B1 | B8 | B16 | B32 | B64 | I8 | I16 | I32 | I64 | R32 | R64 => {
|
||||
Inst::load_constant(to_reg.unwrap(), value as u64)
|
||||
}
|
||||
I128 => Inst::load_constant128(to_regs, value),
|
||||
_ => panic!("Cannot generate constant for type: {}", ty),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3202,6 +3207,8 @@ impl Inst {
|
||||
ALUOp::Asr64 => ("asr", OperandSize::Size64),
|
||||
ALUOp::Lsl32 => ("lsl", OperandSize::Size32),
|
||||
ALUOp::Lsl64 => ("lsl", OperandSize::Size64),
|
||||
ALUOp::Adc32 => ("adc", OperandSize::Size32),
|
||||
ALUOp::Adc64 => ("adc", OperandSize::Size64),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user