A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
aarch64: remove `MInst::Extend` (#14793)
Alexander Rafferty66165fe5f399
diff --git a/cranelift/codegen/meta/src/pulley.rs b/cranelift/codegen/meta/src/pulley.rsindex 4af01ae3ce..fb9c06382d 100644--- a/cranelift/codegen/meta/src/pulley.rs+++ b/cranelift/codegen/meta/src/pulley.rs@@ -105,8 +105,8 @@ impl Inst<'_> {/// Generates a pretty-printing method for debugging.pub fn generate_raw_inst_display(rust: &mut String) -> Result<(), Error> {- rust.push_str("impl<'a> std::fmt::Display for RawInstDisplay<'a> {\n");- rust.push_str("fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n");+ rust.push_str("impl<'a> core::fmt::Display for RawInstDisplay<'a> {\n");+ rust.push_str("fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {\n");rust.push_str("let inst = self.0;\n");rust.push_str("match inst {\n");for inst @ Inst { name, .. } in OPS.iter().chain(EXTENDED_OPS) {diff --git a/cranelift/codegen/src/isa/aarch64/abi.rs b/cranelift/codegen/src/isa/aarch64/abi.rsindex 3556efef15..e0ce6370fd 100644--- a/cranelift/codegen/src/isa/aarch64/abi.rs+++ b/cranelift/codegen/src/isa/aarch64/abi.rs@@ -474,14 +474,20 @@ impl ABIMachineSpec for AArch64MachineDeps {from_bits: u8,to_bits: u8,) -> Inst {- assert!(from_bits < to_bits);- Inst::Extend {- rd: to_reg,- rn: from_reg,- signed,- from_bits,- to_bits,- }+ let (op, to) = match (signed, from_bits, to_bits) {+ (false, 8, 32) => (ExtendOp::UXTB, OperandSize::Size32),+ (false, 8, 64) => (ExtendOp::UXTB, OperandSize::Size64),+ (false, 16, 32) => (ExtendOp::UXTH, OperandSize::Size32),+ (false, 16, 64) => (ExtendOp::UXTH, OperandSize::Size64),+ (false, 32, 64) => (ExtendOp::UXTW, OperandSize::Size64),+ (true, 8, 32) => (ExtendOp::SXTB, OperandSize::Size32),+ (true, 8, 64) => (ExtendOp::SXTB, OperandSize::Size64),+ (true, 16, 32) => (ExtendOp::SXTH, OperandSize::Size32),+ (true, 16, 64) => (ExtendOp::SXTH, OperandSize::Size64),+ (true, 32, 64) => (ExtendOp::SXTW, OperandSize::Size64),+ _ => unimplemented!("cannot extend {from_bits} to {to_bits} as signed? {signed}"),+ };+ Inst::gen_extend(to_reg, from_reg, op, to)}fn gen_args(args: Vec<ArgPair>) -> Inst {diff --git a/cranelift/codegen/src/isa/aarch64/inst.isle b/cranelift/codegen/src/isa/aarch64/inst.isleindex 22d8765ce1..a9b0058a1c 100644--- a/cranelift/codegen/src/isa/aarch64/inst.isle+++ b/cranelift/codegen/src/isa/aarch64/inst.isle@@ -201,14 +201,6 @@(imm MoveWideConst)(size OperandSize))- ;; A sign- or zero-extend operation.- (Extend- (rd WritableReg)- (rn Reg)- (signed bool)- (from_bits u8)- (to_bits u8))-;; A bitfield move instruction, either UBFM or SBFM.;; The BFM instruction is instead encoded as BitfieldMoveMod.(BitfieldMove@@ -1306,7 +1298,6 @@;; Leaves currently without specs: excluded from verification via todo.(attr MInst.Udf (tag TODO))-(attr MInst.BitfieldMove (tag TODO));; An ALU operation. This can be paired with several instruction formats;; below (see `Inst`) in any combination.@@ -2333,6 +2324,13 @@(decl u8_into_uimm5 (u8) UImm5)(extern constructor u8_into_uimm5 u8_into_uimm5)+(spec (u8_into_uimm6 n)+ (provide (= result (extract 5 0 n)))+ (require (bvult n #x40))+)+(decl u8_into_uimm6 (u8) UImm6)+(extern constructor u8_into_uimm6 u8_into_uimm6)+(spec (u8_into_imm12 n)(provide(not (:shift12 result))@@ -3072,18 +3070,42 @@(_ Unit (emit (MInst.FpuMoveFromVec dst rn idx size))))dst))-;; Helper for emitting `MInst.Extend` instructions.+;; Helper for emitting instructions that perform zero-/sign-extension.(attr extend (veri chain))(decl extend (Reg bool u8 u8) Reg)-(rule (extend rn signed from_bits to_bits)+(rule extend_mov 1 (extend rn false 32 64)+ (let ((dst WritableReg (temp_writable_reg $I64))+ (_ Unit (emit (MInst.Mov (OperandSize.Size32) dst rn))))+ dst))+(rule extend_bfm 0 (extend rn signed from_bits to_bits)(let ((dst WritableReg (temp_writable_reg $I64))- (_ Unit (emit (MInst.Extend dst rn signed from_bits to_bits))))+ (size OperandSize (extend_bfm_size signed to_bits))+ (bfm_op BfmOp (extend_bfm_op signed))+ (immr UImm6 (u8_into_uimm6 0))+ (imms UImm6 (u8_into_uimm6 (u8_sub from_bits 1)))+ (_ Unit (emit (MInst.BitfieldMove size bfm_op dst rn immr imms))))dst))+;; Helper for `extend` to select the BFM operation+(attr extend_bfm_op (veri chain))+(decl extend_bfm_op (bool) BfmOp)+(rule (extend_bfm_op true) (BfmOp.SBfm))+(rule (extend_bfm_op false) (BfmOp.UBfm))++;; Helper for `extend` to select the operand size+(attr extend_bfm_size (veri chain))+(decl extend_bfm_size (bool u8) OperandSize)+(attr rule extend_bfm_size_64 (veri priority))+(rule extend_bfm_size_64 1 (extend_bfm_size true 64) (OperandSize.Size64))+(rule 0 (extend_bfm_size _ _) (OperandSize.Size32))+;; Helper for emitting `MInst.BitfieldMove` instructions.(attr bitfield_move (veri chain))(decl bitfield_move (Type BfmOp Reg UImm6 UImm6) Reg)-(rule (bitfield_move ty bfm_op rn immr imms)+;; TODO: `MInst.BitfieldMove`'s generated spec only covers the extend+;; immediates, so the general `sbfm`/`ubfm` rules can't verify yet.+(attr rule bitfield_move_inst (tag TODO))+(rule bitfield_move_inst (bitfield_move ty bfm_op rn immr imms)(let ((dst WritableReg (temp_writable_reg ty))(_ Unit (emit (MInst.BitfieldMove (operand_size ty) bfm_op dst rn immr imms))))dst))diff --git a/cranelift/codegen/src/isa/aarch64/inst/args.rs b/cranelift/codegen/src/isa/aarch64/inst/args.rsindex c85e29966e..dbcf63e292 100644--- a/cranelift/codegen/src/isa/aarch64/inst/args.rs+++ b/cranelift/codegen/src/isa/aarch64/inst/args.rs@@ -108,6 +108,16 @@ impl ExtendOp {pub fn bits(self) -> u8 {self as u8}++ /// The width in bits of the value being extended.+ pub fn from_bits(self) -> u8 {+ match self {+ Self::UXTB | Self::SXTB => 8,+ Self::UXTH | Self::SXTH => 16,+ Self::UXTW | Self::SXTW => 32,+ Self::UXTX | Self::SXTX => 64,+ }+ }}//=============================================================================diff --git a/cranelift/codegen/src/isa/aarch64/inst/emit.rs b/cranelift/codegen/src/isa/aarch64/inst/emit.rsindex a7f7ea7aaa..fc6dec68dc 100644--- a/cranelift/codegen/src/isa/aarch64/inst/emit.rs+++ b/cranelift/codegen/src/isa/aarch64/inst/emit.rs@@ -1575,8 +1575,8 @@ impl MachInstEmit for Inst {let size = OperandSize::from_ty(ty);let sign_ext = match op {AtomicRMWLoopOp::Smin | AtomicRMWLoopOp::Smax => match ty {- I16 => Some((ExtendOp::SXTH, 16)),- I8 => Some((ExtendOp::SXTB, 8)),+ I16 => Some(ExtendOp::SXTH),+ I8 => Some(ExtendOp::SXTB),_ => None,},_ => None,@@ -1590,16 +1590,8 @@ impl MachInstEmit for Inst {_ => None,};// sxt{b|h} the loaded result if necessary.- if sign_ext.is_some() {- let (_, from_bits) = sign_ext.unwrap();- Inst::Extend {- rd: x27wr,- rn: x27,- signed: true,- from_bits,- to_bits: size.bits(),- }- .emit(sink, emit_info, state);+ if let Some(op) = sign_ext {+ Inst::gen_extend(x27wr, x27, op, size).emit(sink, emit_info, state);}match op {@@ -1641,7 +1633,7 @@ impl MachInstEmit for Inst {_ => unreachable!(),};- if let Some(extendop) = sign_ext.map(|(op, _)| op).or(zero_ext) {+ if let Some(extendop) = sign_ext.or(zero_ext) {Inst::AluRRRExtend {alu_op: ALUOp::SubS,size,@@ -3360,57 +3352,6 @@ impl MachInstEmit for Inst {&Inst::MovFromNZCV { rd } => {sink.put4(0xd53b4200 | machreg_to_gpr(rd.to_reg()));}- &Inst::Extend {- rd,- rn,- signed: false,- from_bits: 1,- to_bits,- } => {- assert!(to_bits <= 64);- // Reduce zero-extend-from-1-bit to:- // - and rd, rn, #1- // Note: This is special cased as UBFX may take more cycles- // than AND on smaller cores.- let imml = ImmLogic::maybe_from_u64(1, I32).unwrap();- Inst::AluRRImmLogic {- alu_op: ALUOp::And,- size: OperandSize::Size32,- rd,- rn,- imml,- }- .emit(sink, emit_info, state);- }- &Inst::Extend {- rd,- rn,- signed: false,- from_bits: 32,- to_bits: 64,- } => {- let mov = Inst::Mov {- size: OperandSize::Size32,- rd,- rm: rn,- };- mov.emit(sink, emit_info, state);- }- &Inst::Extend {- rd,- rn,- signed,- from_bits,- to_bits,- } => {- let (bfm_op, size) = if signed {- (BfmOp::SBfm, OperandSize::from_bits(to_bits))- } else {- (BfmOp::UBfm, OperandSize::Size32)- };- let opc = bfm_op.opc();- sink.put4(enc_bfm(opc, size, rd, rn, 0, from_bits - 1));- }&Inst::BitfieldMove {size,bfm_op,diff --git a/cranelift/codegen/src/isa/aarch64/inst/emit_tests.rs b/cranelift/codegen/src/isa/aarch64/inst/emit_tests.rsindex 5efc306cd0..5839c81b92 100644--- a/cranelift/codegen/src/isa/aarch64/inst/emit_tests.rs+++ b/cranelift/codegen/src/isa/aarch64/inst/emit_tests.rs@@ -5738,158 +5738,160 @@ fn test_aarch64_binemit() {));insns.push((- Inst::Extend {- rd: writable_xreg(3),- rn: xreg(5),- signed: false,- from_bits: 1,- to_bits: 32,- },- "A3000012",- "and w3, w5, #1",- ));- insns.push((- Inst::Extend {- rd: writable_xreg(3),- rn: xreg(5),- signed: false,- from_bits: 1,- to_bits: 64,- },- "A3000012",- "and w3, w5, #1",- ));- insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size32,+ bfm_op: BfmOp::SBfm,rd: writable_xreg(10),rn: xreg(21),- signed: true,- from_bits: 1,- to_bits: 32,+ immr: UImm6 { imm: 0 },+ imms: UImm6 { imm: 0 },},"AA020013","sbfx w10, w21, #0, #1",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size64,+ bfm_op: BfmOp::SBfm,rd: writable_xreg(1),rn: xreg(2),- signed: true,- from_bits: 1,- to_bits: 64,+ immr: UImm6 { imm: 0 },+ imms: UImm6 { imm: 0 },},"41004093","sbfx x1, x2, #0, #1",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size32,+ bfm_op: BfmOp::UBfm,rd: writable_xreg(1),rn: xreg(2),- signed: false,- from_bits: 8,- to_bits: 32,+ immr: UImm6 { imm: 0 },+ imms: UImm6 { imm: 7 },},"411C0053","uxtb w1, w2",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size32,+ bfm_op: BfmOp::SBfm,rd: writable_xreg(1),rn: xreg(2),- signed: true,- from_bits: 8,- to_bits: 32,+ immr: UImm6 { imm: 0 },+ imms: UImm6 { imm: 7 },},"411C0013","sxtb w1, w2",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size32,+ bfm_op: BfmOp::UBfm,rd: writable_xreg(1),rn: xreg(2),- signed: false,- from_bits: 16,- to_bits: 32,+ immr: UImm6 { imm: 0 },+ imms: UImm6 { imm: 15 },},"413C0053","uxth w1, w2",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size32,+ bfm_op: BfmOp::SBfm,rd: writable_xreg(1),rn: xreg(2),- signed: true,- from_bits: 16,- to_bits: 32,+ immr: UImm6 { imm: 0 },+ imms: UImm6 { imm: 15 },},"413C0013","sxth w1, w2",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size64,+ bfm_op: BfmOp::SBfm,rd: writable_xreg(1),rn: xreg(2),- signed: false,- from_bits: 8,- to_bits: 64,+ immr: UImm6 { imm: 0 },+ imms: UImm6 { imm: 7 },},- "411C0053",- "uxtb w1, w2",+ "411C4093",+ "sxtb x1, w2",+ ));+ insns.push((+ Inst::BitfieldMove {+ size: OperandSize::Size64,+ bfm_op: BfmOp::SBfm,+ rd: writable_xreg(1),+ rn: xreg(2),+ immr: UImm6 { imm: 0 },+ imms: UImm6 { imm: 15 },+ },+ "413C4093",+ "sxth x1, w2",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size64,+ bfm_op: BfmOp::SBfm,rd: writable_xreg(1),rn: xreg(2),- signed: true,- from_bits: 8,- to_bits: 64,+ immr: UImm6 { imm: 0 },+ imms: UImm6 { imm: 31 },},- "411C4093",- "sxtb x1, w2",+ "417C4093",+ "sxtw x1, w2",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size32,+ bfm_op: BfmOp::UBfm,rd: writable_xreg(1),rn: xreg(2),- signed: false,- from_bits: 16,- to_bits: 64,+ immr: UImm6 { imm: 20 },+ imms: UImm6 { imm: 15 },},- "413C0053",- "uxth w1, w2",+ "413C1453",+ "ubfm w1, w2, #20, #15",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size32,+ bfm_op: BfmOp::SBfm,rd: writable_xreg(1),rn: xreg(2),- signed: true,- from_bits: 16,- to_bits: 64,+ immr: UImm6 { imm: 20 },+ imms: UImm6 { imm: 15 },},- "413C4093",- "sxth x1, w2",+ "413C1413",+ "sbfm w1, w2, #20, #15",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size64,+ bfm_op: BfmOp::UBfm,rd: writable_xreg(1),rn: xreg(2),- signed: false,- from_bits: 32,- to_bits: 64,+ immr: UImm6 { imm: 20 },+ imms: UImm6 { imm: 31 },},- "E103022A",- "mov w1, w2",+ "417C54D3",+ "ubfm x1, x2, #20, #31",));insns.push((- Inst::Extend {+ Inst::BitfieldMove {+ size: OperandSize::Size64,+ bfm_op: BfmOp::SBfm,rd: writable_xreg(1),rn: xreg(2),- signed: true,- from_bits: 32,- to_bits: 64,+ immr: UImm6 { imm: 20 },+ imms: UImm6 { imm: 31 },},- "417C4093",- "sxtw x1, w2",+ "417C5493",+ "sbfm x1, x2, #20, #31",));insns.push((diff --git a/cranelift/codegen/src/isa/aarch64/inst/mod.rs b/cranelift/codegen/src/isa/aarch64/inst/mod.rsindex 1eb4552539..333896deb4 100644--- a/cranelift/codegen/src/isa/aarch64/inst/mod.rs+++ b/cranelift/codegen/src/isa/aarch64/inst/mod.rs@@ -299,6 +299,36 @@ impl Inst {}}+ /// Zero- or sign-extend `from_reg` as described by `op` into a `to`-sized result.+ pub fn gen_extend(to_reg: Writable<Reg>, from_reg: Reg, op: ExtendOp, to: OperandSize) -> Inst {+ assert!(op.from_bits() < to.bits());++ let bfm = |size, bfm_op| Inst::BitfieldMove {+ size,+ bfm_op,+ rd: to_reg,+ rn: from_reg,+ immr: UImm6::maybe_from_u8(0).unwrap(),+ imms: UImm6::maybe_from_u8(op.from_bits() - 1).unwrap(),+ };++ match op {+ // A 32-bit move zeroes the upper half of the destination.+ ExtendOp::UXTW => Inst::Mov {+ size: OperandSize::Size32,+ rd: to_reg,+ rm: from_reg,+ },+ // 32-bit UBFM already zeroes the upper half, so it's equivalent to the+ // 64-bit form; using it preserves the encoding emitted previously.+ ExtendOp::UXTB | ExtendOp::UXTH => bfm(OperandSize::Size32, BfmOp::UBfm),+ // SBFM must run at the destination width to sign-fill it.+ ExtendOp::SXTB | ExtendOp::SXTH | ExtendOp::SXTW => bfm(to, BfmOp::SBfm),+ // These cases are excluded by the assertion above.+ ExtendOp::UXTX | ExtendOp::SXTX => unreachable!(),+ }+ }+/// What type does this load or store instruction access in memory? When/// uimm12 encoding is used, the size of this type is the amount that/// immediate offsets are scaled by.@@ -887,10 +917,6 @@ fn aarch64_get_operands(inst: &mut Inst, collector: &mut impl OperandVisitor) {Inst::MovFromNZCV { rd } => {collector.reg_def(rd);}- Inst::Extend { rd, rn, .. } => {- collector.reg_def(rd);- collector.reg_use(rn);- }Inst::BitfieldMove { rd, rn, .. } => {// The UBFM and SBFM instructions overwrite all bits in `rd`,// unlike BFM which is represented as `BitfieldMoveMod` instead.@@ -2781,61 +2807,34 @@ impl Inst {let rd = pretty_print_reg(rd.to_reg());format!("mrs {rd}, nzcv")}- &Inst::Extend {- rd,- rn,- signed: false,- from_bits: 1,- ..- } => {- let rd = pretty_print_ireg(rd.to_reg(), OperandSize::Size32);- let rn = pretty_print_ireg(rn, OperandSize::Size32);- format!("and {rd}, {rn}, #1")- }- &Inst::Extend {- rd,- rn,- signed: false,- from_bits: 32,- to_bits: 64,- } => {- // The case of a zero extension from 32 to 64 bits, is implemented- // with a "mov" to a 32-bit (W-reg) dest, because this zeroes- // the top 32 bits.- let rd = pretty_print_ireg(rd.to_reg(), OperandSize::Size32);- let rn = pretty_print_ireg(rn, OperandSize::Size32);- format!("mov {rd}, {rn}")- }- &Inst::Extend {+ // Special case when `immr == 0` so that zero- and sign-extending+ // operations use the appropriate aliases, preserving the behavior+ // of the old `Inst::Extend` instruction.+ &Inst::BitfieldMove {+ size,+ bfm_op,rd,rn,- signed,- from_bits,- to_bits,+ immr: UImm6 { imm: 0 },+ imms,} => {- assert!(from_bits <= to_bits);- let op = match (signed, from_bits) {- (false, 8) => "uxtb",- (true, 8) => "sxtb",- (false, 16) => "uxth",- (true, 16) => "sxth",- (true, 32) => "sxtw",- (true, _) => "sbfx",- (false, _) => "ubfx",+ let from_bits = imms.value() + 1;+ let op = match (bfm_op, size, from_bits) {+ (BfmOp::UBfm, OperandSize::Size32, 8) => "uxtb",+ (BfmOp::UBfm, OperandSize::Size32, 16) => "uxth",+ (BfmOp::SBfm, _, 8) => "sxtb",+ (BfmOp::SBfm, _, 16) => "sxth",+ (BfmOp::SBfm, OperandSize::Size64, 32) => "sxtw",+ (BfmOp::UBfm, _, _) => "ubfx",+ (BfmOp::SBfm, _, _) => "sbfx",};if op == "sbfx" || op == "ubfx" {- let dest_size = OperandSize::from_bits(to_bits);- let rd = pretty_print_ireg(rd.to_reg(), dest_size);- let rn = pretty_print_ireg(rn, dest_size);+ let rd = pretty_print_ireg(rd.to_reg(), size);+ let rn = pretty_print_ireg(rn, size);format!("{op} {rd}, {rn}, #0, #{from_bits}")} else {- let dest_size = if signed {- OperandSize::from_bits(to_bits)- } else {- OperandSize::Size32- };- let rd = pretty_print_ireg(rd.to_reg(), dest_size);- let rn = pretty_print_ireg(rn, OperandSize::from_bits(from_bits));+ let rd = pretty_print_ireg(rd.to_reg(), size);+ let rn = pretty_print_ireg(rn, OperandSize::Size32);format!("{op} {rd}, {rn}")}}diff --git a/cranelift/codegen/src/isa/aarch64/lower/isle.rs b/cranelift/codegen/src/isa/aarch64/lower/isle.rsindex 4d482fe6bf..a289b06acf 100644--- a/cranelift/codegen/src/isa/aarch64/lower/isle.rs+++ b/cranelift/codegen/src/isa/aarch64/lower/isle.rs@@ -524,6 +524,10 @@ impl Context for IsleContext<'_, '_, MInst, AArch64Backend> {UImm5::maybe_from_u8(x).unwrap()}+ fn u8_into_uimm6(&mut self, x: u8) -> UImm6 {+ UImm6::maybe_from_u8(x).unwrap()+ }+fn u8_into_imm12(&mut self, x: u8) -> Imm12 {Imm12::maybe_from_u64(x.into()).unwrap()}diff --git a/cranelift/codegen/src/isa/aarch64/spec/bitfield_move.isle b/cranelift/codegen/src/isa/aarch64/spec/bitfield_move.islenew file mode 100644index 0000000000..8fc84f65a2--- /dev/null+++ b/cranelift/codegen/src/isa/aarch64/spec/bitfield_move.isle@@ -0,0 +1,93 @@+;; GENERATED BY `isaspec`. DO NOT EDIT!!!++(attr MInst.BitfieldMove (tag isaspec_generated))++(spec+ (MInst.BitfieldMove size bfm_op rd rn immr imms)+ (provide+ (match+ size+ ((Size32)+ (match+ bfm_op+ ((UBfm)+ (and+ (=> (and (= immr #b000000) (= imms #b000111)) (= rd (zero_ext 64 (extract 7 0 (as rn (bv 64))))))+ (=> (and (= immr #b000000) (= imms #b001111)) (= rd (zero_ext 64 (extract 15 0 (as rn (bv 64))))))+ (=> (and (= immr #b000000) (= imms #b011111)) (= rd (zero_ext 64 (extract 31 0 (as rn (bv 64))))))+ )+ )+ ((SBfm)+ (and+ (=> (and (= immr #b000000) (= imms #b000111)) (= rd (zero_ext 64 (sign_ext 32 (extract 7 0 (as rn (bv 64)))))))+ (=> (and (= immr #b000000) (= imms #b001111)) (= rd (zero_ext 64 (sign_ext 32 (extract 15 0 (as rn (bv 64)))))))+ (=> (and (= immr #b000000) (= imms #b011111)) (= rd (zero_ext 64 (extract 31 0 (as rn (bv 64))))))+ )+ )+ )+ )+ ((Size64)+ (match+ bfm_op+ ((UBfm)+ (and+ (=> (and (= immr #b000000) (= imms #b000111)) (= rd (zero_ext 64 (extract 7 0 (as rn (bv 64))))))+ (=> (and (= immr #b000000) (= imms #b001111)) (= rd (zero_ext 64 (extract 15 0 (as rn (bv 64))))))+ (=> (and (= immr #b000000) (= imms #b011111)) (= rd (zero_ext 64 (extract 31 0 (as rn (bv 64))))))+ )+ )+ ((SBfm)+ (and+ (=> (and (= immr #b000000) (= imms #b000111)) (= rd (sign_ext 64 (extract 7 0 (as rn (bv 64))))))+ (=> (and (= immr #b000000) (= imms #b001111)) (= rd (sign_ext 64 (extract 15 0 (as rn (bv 64))))))+ (=> (and (= immr #b000000) (= imms #b011111)) (= rd (sign_ext 64 (extract 31 0 (as rn (bv 64))))))+ )+ )+ )+ )+ )+ )+ (require+ (match+ size+ ((Size32)+ (match+ bfm_op+ ((UBfm)+ (or+ (and (= immr #b000000) (= imms #b000111))+ (and (= immr #b000000) (= imms #b001111))+ (and (= immr #b000000) (= imms #b011111))+ )+ )+ ((SBfm)+ (or+ (and (= immr #b000000) (= imms #b000111))+ (and (= immr #b000000) (= imms #b001111))+ (and (= immr #b000000) (= imms #b011111))+ )+ )+ )+ )+ ((Size64)+ (match+ bfm_op+ ((UBfm)+ (or+ (and (= immr #b000000) (= imms #b000111))+ (and (= immr #b000000) (= imms #b001111))+ (and (= immr #b000000) (= imms #b011111))+ )+ )+ ((SBfm)+ (or+ (and (= immr #b000000) (= imms #b000111))+ (and (= immr #b000000) (= imms #b001111))+ (and (= immr #b000000) (= imms #b011111))+ )+ )+ )+ )+ )+ )+)diff --git a/cranelift/codegen/src/isa/aarch64/spec/extend.isle b/cranelift/codegen/src/isa/aarch64/spec/extend.isledeleted file mode 100644index 8dab27244f..0000000000--- a/cranelift/codegen/src/isa/aarch64/spec/extend.isle+++ /dev/null@@ -1,49 +0,0 @@-;; GENERATED BY `isaspec`. DO NOT EDIT!!!--(attr MInst.Extend (tag isaspec_generated))--(spec- (MInst.Extend rd rn signed from_bits to_bits)- (provide- (=> (and (not signed) (= from_bits #x08) (= to_bits #x08)) (= rd (zero_ext 64 (extract 7 0 (as rn (bv 64))))))- (=> (and signed (= from_bits #x08) (= to_bits #x08)) (= rd (zero_ext 64 (sign_ext 32 (extract 7 0 (as rn (bv 64)))))))- (=> (and (not signed) (= from_bits #x08) (= to_bits #x10)) (= rd (zero_ext 64 (extract 7 0 (as rn (bv 64))))))- (=> (and signed (= from_bits #x08) (= to_bits #x10)) (= rd (zero_ext 64 (sign_ext 32 (extract 7 0 (as rn (bv 64)))))))- (=> (and (not signed) (= from_bits #x08) (= to_bits #x20)) (= rd (zero_ext 64 (extract 7 0 (as rn (bv 64))))))- (=> (and signed (= from_bits #x08) (= to_bits #x20)) (= rd (zero_ext 64 (sign_ext 32 (extract 7 0 (as rn (bv 64)))))))- (=> (and (not signed) (= from_bits #x08) (= to_bits #x40)) (= rd (zero_ext 64 (extract 7 0 (as rn (bv 64))))))- (=> (and signed (= from_bits #x08) (= to_bits #x40)) (= rd (sign_ext 64 (extract 7 0 (as rn (bv 64))))))- (=> (and (not signed) (= from_bits #x10) (= to_bits #x10)) (= rd (zero_ext 64 (extract 15 0 (as rn (bv 64))))))- (=> (and signed (= from_bits #x10) (= to_bits #x10)) (= rd (zero_ext 64 (sign_ext 32 (extract 15 0 (as rn (bv 64)))))))- (=> (and (not signed) (= from_bits #x10) (= to_bits #x20)) (= rd (zero_ext 64 (extract 15 0 (as rn (bv 64))))))- (=> (and signed (= from_bits #x10) (= to_bits #x20)) (= rd (zero_ext 64 (sign_ext 32 (extract 15 0 (as rn (bv 64)))))))- (=> (and (not signed) (= from_bits #x10) (= to_bits #x40)) (= rd (zero_ext 64 (extract 15 0 (as rn (bv 64))))))- (=> (and signed (= from_bits #x10) (= to_bits #x40)) (= rd (sign_ext 64 (extract 15 0 (as rn (bv 64))))))- (=> (and (not signed) (= from_bits #x20) (= to_bits #x20)) (= rd (zero_ext 64 (extract 31 0 (as rn (bv 64))))))- (=> (and signed (= from_bits #x20) (= to_bits #x20)) (= rd (zero_ext 64 (extract 31 0 (as rn (bv 64))))))- (=> (and (not signed) (= from_bits #x20) (= to_bits #x40)) (= rd (zero_ext 64 (extract 31 0 (as rn (bv 64))))))- (=> (and signed (= from_bits #x20) (= to_bits #x40)) (= rd (sign_ext 64 (extract 31 0 (as rn (bv 64))))))- )- (require- (or- (and (not signed) (= from_bits #x08) (= to_bits #x08))- (and signed (= from_bits #x08) (= to_bits #x08))- (and (not signed) (= from_bits #x08) (= to_bits #x10))- (and signed (= from_bits #x08) (= to_bits #x10))- (and (not signed) (= from_bits #x08) (= to_bits #x20))- (and signed (= from_bits #x08) (= to_bits #x20))- (and (not signed) (= from_bits #x08) (= to_bits #x40))- (and signed (= from_bits #x08) (= to_bits #x40))- (and (not signed) (= from_bits #x10) (= to_bits #x10))- (and signed (= from_bits #x10) (= to_bits #x10))- (and (not signed) (= from_bits #x10) (= to_bits #x20))- (and signed (= from_bits #x10) (= to_bits #x20))- (and (not signed) (= from_bits #x10) (= to_bits #x40))- (and signed (= from_bits #x10) (= to_bits #x40))- (and (not signed) (= from_bits #x20) (= to_bits #x20))- (and signed (= from_bits #x20) (= to_bits #x20))- (and (not signed) (= from_bits #x20) (= to_bits #x40))- (and signed (= from_bits #x20) (= to_bits #x40))- )- )-)diff --git a/cranelift/codegen/src/isa/aarch64/spec/mov.isle b/cranelift/codegen/src/isa/aarch64/spec/mov.islenew file mode 100644index 0000000000..11fe41c903--- /dev/null+++ b/cranelift/codegen/src/isa/aarch64/spec/mov.isle@@ -0,0 +1,9 @@+;; GENERATED BY `isaspec`. DO NOT EDIT!!!++(attr MInst.Mov (tag isaspec_generated))++(spec+ (MInst.Mov size rd rm)+ (provide (match size ((Size64) (= rd rm)) ((Size32) (= rd (zero_ext 64 (extract 31 0 rm))))))+ (require (match size ((Size64) true) ((Size32) true)))+)diff --git a/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs b/cranelift/codegen/src/isa/pulley_shared/inst/mod.rsindex 2a41543be2..34c55f52be 100644--- a/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs+++ b/cranelift/codegen/src/isa/pulley_shared/inst/mod.rs@@ -623,8 +623,8 @@ fn test_trap_encoding() {pub struct RegNameDisplay(Reg);-impl std::fmt::Display for RegNameDisplay {- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+impl core::fmt::Display for RegNameDisplay {+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {let reg = self.0;match reg.to_real_reg() {Some(real) => {diff --git a/cranelift/codegen/src/prelude.isle b/cranelift/codegen/src/prelude.isleindex 5c7b744b7b..c3867c1fc4 100644--- a/cranelift/codegen/src/prelude.isle+++ b/cranelift/codegen/src/prelude.isle@@ -776,6 +776,7 @@(model I8X16 (const (struct (bits 128) (lanes 16))))(spec (i64_neg x) (provide (= result (bvneg x))))+(spec (u8_sub x y) (provide (= result (bvsub x y))))(spec (u64_sub x y) (provide (= result (bvsub x y))))(spec (u64_shl x y)(match (bvult y #x00000040))diff --git a/cranelift/isle/veri/isaspec/src/instructions.rs b/cranelift/isle/veri/isaspec/src/instructions.rsindex 311ce50e1d..b372091eb8 100644--- a/cranelift/isle/veri/isaspec/src/instructions.rs+++ b/cranelift/isle/veri/isaspec/src/instructions.rs@@ -19,15 +19,14 @@ use cranelift_codegen::{Reg, Writable,ir::{MemFlagsData, types::I8},isa::aarch64::inst::{- ALUOp, ALUOp3, AMode, ASIMDFPModImm, ASIMDMovModImm, BitOp, Cond, ExtendOp,+ ALUOp, ALUOp3, AMode, ASIMDFPModImm, ASIMDMovModImm, BfmOp, BitOp, Cond, ExtendOp,FPULeftShiftImm, FPUOp1, FPUOp2, FPUOpRI, FPUOpRIMod, FPURightShiftImm, FpuRoundMode,FpuToIntOp, Imm12, Inst, IntToFpuOp, MoveWideConst, MoveWideOp, NZCV, OperandSize, SImm9,- ScalarSize, ShiftOp, ShiftOpAndAmt, ShiftOpShiftImm, UImm5, UImm12Scaled, VecALUOp,+ ScalarSize, ShiftOp, ShiftOpAndAmt, ShiftOpShiftImm, UImm5, UImm6, UImm12Scaled, VecALUOp,VecLanesOp, VecMisc2, VectorSize, vreg, writable_vreg, writable_xreg, xreg,},};use cranelift_isle::ast::{SpecExpr, SpecOp};-use itertools::Itertools;use std::collections::HashMap;use std::path::PathBuf;use std::vec;@@ -73,13 +72,17 @@ pub fn define() -> Result<Vec<FileConfig>> {name: "stores.isle".into(),specs: define_stores()?,},+ FileConfig {+ name: "mov.isle".into(),+ specs: vec![define_mov()],+ },FileConfig {name: "mov_wide.isle".into(),specs: vec![define_mov_wide()?],},FileConfig {- name: "extend.isle".into(),- specs: vec![define_extend()],+ name: "bitfield_move.isle".into(),+ specs: vec![define_bitfield_move()],},FileConfig {name: "conds.isle".into(),@@ -658,6 +661,20 @@ fn is_bit_op_size_supported(bit_op: BitOp, size: OperandSize) -> bool {}}+// MInst.Mov specification configuration.+fn define_mov() -> SpecConfig {+ let sizes = [OperandSize::Size64, OperandSize::Size32];+ spec_config! {+ (Mov size rd rm)+ {+ enumerate (size, sizes);+ register (rd, write, gp, 4);+ register (rm, read, gp, 5);+ instruction ();+ }+ }+}+// MInst.MovWide specification configuration.fn define_mov_wide() -> Result<SpecConfig> {// MovWideOps@@ -776,10 +793,16 @@ fn mov_wide_template(Ok(template)}-fn define_extend() -> SpecConfig {- // Extend- let signed = [false, true];- let bits = [8u8, 16u8, 32u8, 64u8];+// MInst.BitfieldMove specification configuration.+//+// Only the immediates used for zero- and sign-extension (`immr == 0`,+// `imms` of 7, 15 or 31) are covered, matching the coverage of the former+// `MInst.Extend` spec. Other immediates fall outside the generated `require`.+fn define_bitfield_move() -> SpecConfig {+ let sizes = [OperandSize::Size32, OperandSize::Size64];+ let bfm_ops = [BfmOp::UBfm, BfmOp::SBfm];+ let immr: u8 = 0;+ let imms_values: [u8; 3] = [7, 15, 31];let mut mappings = Mappings::default();mappings.writes.insert(@@ -792,43 +815,59 @@ fn define_extend() -> SpecConfig {);SpecConfig {- // Spec signature.- term: "MInst.Extend".to_string(),- args: ["rd", "rn", "signed", "from_bits", "to_bits"]+ term: "MInst.BitfieldMove".to_string(),+ args: ["size", "bfm_op", "rd", "rn", "immr", "imms"].map(String::from).to_vec(),- cases: Cases::Cases(- bits.iter()- .cartesian_product(&bits)- .filter(|(from_bits, to_bits)| from_bits <= to_bits && **from_bits < 64)- .cartesian_product(&signed)- .map(|((from_bits, to_bits), signed)| Case {- conds: vec![- spec_eq_bool(spec_var("signed".to_string()), *signed),- spec_eq(- spec_var("from_bits".to_string()),- spec_const_bit_vector((*from_bits).into(), 8),- ),- spec_eq(- spec_var("to_bits".to_string()),- spec_const_bit_vector((*to_bits).into(), 8),- ),- ],- cases: Cases::Instruction(InstConfig {- // Instruction to generate specification from.- opcodes: Opcodes::Instruction(Inst::Extend {- rd: writable_xreg(4),- rn: xreg(5),- signed: *signed,- from_bits: *from_bits,- to_bits: *to_bits,- }),- scope: aarch64::state(),- mappings: mappings.clone(),+ cases: Cases::Match(Match {+ on: spec_var("size".to_string()),+ arms: sizes+ .iter()+ .map(|&size| Arm {+ variant: format!("{size:?}"),+ args: Vec::new(),+ body: Cases::Match(Match {+ on: spec_var("bfm_op".to_string()),+ arms: bfm_ops+ .iter()+ .map(|&bfm_op| Arm {+ variant: format!("{bfm_op:?}"),+ args: Vec::new(),+ body: Cases::Cases(+ imms_values+ .iter()+ .map(|&imms| Case {+ conds: vec![+ spec_eq(+ spec_var("immr".to_string()),+ spec_const_bit_vector(immr.into(), 6),+ ),+ spec_eq(+ spec_var("imms".to_string()),+ spec_const_bit_vector(imms.into(), 6),+ ),+ ],+ cases: Cases::Instruction(InstConfig {+ opcodes: Opcodes::Instruction(Inst::BitfieldMove {+ size,+ bfm_op,+ rd: writable_xreg(4),+ rn: xreg(5),+ immr: UImm6::maybe_from_u8(immr).unwrap(),+ imms: UImm6::maybe_from_u8(imms).unwrap(),+ }),+ scope: aarch64::state(),+ mappings: mappings.clone(),+ }),+ })+ .collect(),+ ),+ })+ .collect(),}),}).collect(),- ),+ }),}}diff --git a/winch/codegen/src/isa/aarch64/asm.rs b/winch/codegen/src/isa/aarch64/asm.rsindex 88d5d402a5..0d3ffaa659 100644--- a/winch/codegen/src/isa/aarch64/asm.rs+++ b/winch/codegen/src/isa/aarch64/asm.rs@@ -1273,13 +1273,22 @@ impl Assembler {}pub fn extend(&mut self, rn: Reg, rd: WritableReg, kind: ExtendKind) {- self.emit(Inst::Extend {- rd: rd.map(Into::into),- rn: rn.into(),- signed: kind.signed(),- from_bits: kind.from_bits(),- to_bits: kind.to_bits(),- })+ use inst::args::OperandSize;++ let (op, to) = match kind {+ ExtendKind::Unsigned(Extend::I32Extend8) => (ExtendOp::UXTB, OperandSize::Size32),+ ExtendKind::Unsigned(Extend::I32Extend16) => (ExtendOp::UXTH, OperandSize::Size32),+ ExtendKind::Unsigned(Extend::I64Extend8) => (ExtendOp::UXTB, OperandSize::Size64),+ ExtendKind::Unsigned(Extend::I64Extend16) => (ExtendOp::UXTH, OperandSize::Size64),+ ExtendKind::Unsigned(Extend::I64Extend32) => (ExtendOp::UXTW, OperandSize::Size64),+ ExtendKind::Signed(Extend::I32Extend8) => (ExtendOp::SXTB, OperandSize::Size32),+ ExtendKind::Signed(Extend::I32Extend16) => (ExtendOp::SXTH, OperandSize::Size32),+ ExtendKind::Signed(Extend::I64Extend8) => (ExtendOp::SXTB, OperandSize::Size64),+ ExtendKind::Signed(Extend::I64Extend16) => (ExtendOp::SXTH, OperandSize::Size64),+ ExtendKind::Signed(Extend::I64Extend32) => (ExtendOp::SXTW, OperandSize::Size64),+ };++ self.emit(Inst::gen_extend(rd.map(Into::into), rn.into(), op, to))}/// Bitwise AND (shifted register), setting flags.diff --git a/winch/codegen/src/masm.rs b/winch/codegen/src/masm.rsindex 01cb207196..d22279a9fb 100644--- a/winch/codegen/src/masm.rs+++ b/winch/codegen/src/masm.rs@@ -410,20 +410,6 @@ impl ExtendKind {_ => false,}}-- pub fn from_bits(&self) -> u8 {- match self {- Self::Signed(s) => s.from_bits(),- Self::Unsigned(u) => u.from_bits(),- }- }-- pub fn to_bits(&self) -> u8 {- match self {- Self::Signed(s) => s.to_bits(),- Self::Unsigned(u) => u.to_bits(),- }- }}/// Kinds of vector load and extends in WebAssembly. Each MacroAssembler