use super::{AddrMode, Insn, Mem, Operand, Operands, Reg, Width};
const RANGE_LO: u16 = 0xC000;
const RANGE_HI: u16 = 0xCFFF;
const FRAME_BASE: Reg = Reg(9);
const POOL_BASE: Reg = Reg(10);
fn insn(
mnemonic: &'static str,
encoding: &'static str,
addr: u32,
operands: Operands,
) -> Option<Insn> {
Some(Insn {
mnemonic,
encoding,
addr,
width: Width::Narrow,
cond: None,
sets_flags: false,
explicit_width: false,
operands,
})
}
fn mem(base: Reg, add: bool, offset: u32) -> Operand {
Operand::Mem(Mem {
base,
index: None,
offset,
add,
align: 0,
mode: AddrMode::Offset,
})
}
pub(crate) fn owns(hw1: u16) -> bool {
(RANGE_LO..=RANGE_HI).contains(&hw1)
}
pub(crate) fn decode(hw1: u16, _hw2: u16, addr: u32) -> Option<Insn> {
if !owns(hw1) {
return None;
}
match (hw1 >> 8) & 0xF {
0b0000 => decode_hbp(hw1, addr),
0b0001 => None,
0b0010..=0b0011 => decode_hb(hw1, addr),
0b0100..=0b0111 => decode_hblp(hw1, addr),
0b1000..=0b1001 => decode_ldr_array(hw1, addr),
0b1010 => decode_chka(hw1, addr),
0b1011 => decode_ldr_pool(hw1, addr),
0b1100..=0b1101 => decode_frame(hw1, addr, "ldr"),
_ => decode_frame(hw1, addr, "str"),
}
}
fn decode_hbp(hw1: u16, addr: u32) -> Option<Insn> {
let imm3 = ((hw1 >> 5) & 0b111) as i64;
let handler = (hw1 & 0b1_1111) as i64;
let mut ops = Operands::new();
ops.push(Operand::Imm(imm3));
ops.push(Operand::Imm(handler));
insn("hbp", "E1", addr, ops)
}
fn decode_hb(hw1: u16, addr: u32) -> Option<Insn> {
let link = (hw1 >> 8) & 1 == 1;
let handler = (hw1 & 0xFF) as i64;
let mut ops = Operands::new();
ops.push(Operand::Imm(handler));
insn(if link { "hbl" } else { "hb" }, "E1", addr, ops)
}
fn decode_hblp(hw1: u16, addr: u32) -> Option<Insn> {
let imm5 = ((hw1 >> 5) & 0b1_1111) as i64;
let handler = (hw1 & 0b1_1111) as i64;
let mut ops = Operands::new();
ops.push(Operand::Imm(imm5));
ops.push(Operand::Imm(handler));
insn("hblp", "E1", addr, ops)
}
fn decode_chka(hw1: u16, addr: u32) -> Option<Insn> {
let n = (((hw1 >> 4) & 0b1000) | (hw1 & 0b111)) as u8;
let m = ((hw1 >> 3) & 0xF) as u8;
let mut ops = Operands::new();
ops.push(Operand::Reg(Reg(n)));
ops.push(Operand::Reg(Reg(m)));
insn("chka", "E1", addr, ops)
}
fn decode_ldr_array(hw1: u16, addr: u32) -> Option<Insn> {
let imm3 = u32::from((hw1 >> 6) & 0b111);
let rn = ((hw1 >> 3) & 0b111) as u8;
let rt = (hw1 & 0b111) as u8;
let mut ops = Operands::new();
ops.push(Operand::Reg(Reg(rt)));
ops.push(mem(Reg(rn), imm3 == 0, imm3 * 4));
insn("ldr", "E3", addr, ops)
}
fn decode_ldr_pool(hw1: u16, addr: u32) -> Option<Insn> {
let imm5 = u32::from((hw1 >> 3) & 0b1_1111);
let rt = (hw1 & 0b111) as u8;
let mut ops = Operands::new();
ops.push(Operand::Reg(Reg(rt)));
ops.push(mem(POOL_BASE, true, imm5 * 4));
insn("ldr", "E2", addr, ops)
}
fn decode_frame(hw1: u16, addr: u32, mnemonic: &'static str) -> Option<Insn> {
let imm6 = u32::from((hw1 >> 3) & 0b11_1111);
let rt = (hw1 & 0b111) as u8;
let mut ops = Operands::new();
ops.push(Operand::Reg(Reg(rt)));
ops.push(mem(FRAME_BASE, true, imm6 * 4));
insn(mnemonic, "E1", addr, ops)
}
pub(crate) fn encode(insn: &Insn) -> Option<u16> {
if insn.width != Width::Narrow || insn.sets_flags || insn.explicit_width {
return None;
}
match (insn.mnemonic, insn.encoding) {
("hbp", "E1") => {
let imm3 = imm_field(insn, 0, 2, 0b111)?;
let handler = imm_field(insn, 1, 2, 0b1_1111)?;
Some(0xC000 | (imm3 << 5) | handler)
}
("hb", "E1") => Some(0xC200 | imm_field(insn, 0, 1, 0xFF)?),
("hbl", "E1") => Some(0xC300 | imm_field(insn, 0, 1, 0xFF)?),
("hblp", "E1") => {
let imm5 = imm_field(insn, 0, 2, 0b1_1111)?;
let handler = imm_field(insn, 1, 2, 0b1_1111)?;
Some(0xC400 | (imm5 << 5) | handler)
}
("chka", "E1") => {
if insn.operands.len() != 2 {
return None;
}
let n = any_reg(insn.operands.get(0))?;
let m = any_reg(insn.operands.get(1))?;
Some(0xCA00 | ((n & 0b1000) << 4) | (m << 3) | (n & 0b111))
}
("ldr", "E1") => {
let (rt, imm) = mem_field(insn, FRAME_BASE, 0, 252)?;
Some(0xCC00 | (imm << 3) | rt)
}
("ldr", "E2") => {
let (rt, imm) = mem_field(insn, POOL_BASE, 0, 124)?;
Some(0xCB00 | (imm << 3) | rt)
}
("ldr", "E3") => {
if insn.operands.len() != 2 {
return None;
}
let rt = low_reg(insn.operands.get(0))?;
let m = plain_mem(insn.operands.get(1))?;
if !m.base.is_low() {
return None;
}
let imm3 = neg_scaled_offset(&m, 28)?;
Some(0xC800 | (imm3 << 6) | ((m.base.num() as u16) << 3) | rt)
}
("str", "E1") => {
let (rt, imm) = mem_field(insn, FRAME_BASE, 0, 252)?;
Some(0xCE00 | (imm << 3) | rt)
}
_ => None,
}
}
fn imm_field(insn: &Insn, i: usize, len: usize, max: i64) -> Option<u16> {
if insn.operands.len() != len {
return None;
}
match insn.operands.get(i) {
Some(Operand::Imm(v)) if (0..=max).contains(&v) => Some(v as u16),
_ => None,
}
}
fn any_reg(op: Option<Operand>) -> Option<u16> {
match op {
Some(Operand::Reg(r)) => Some(r.num() as u16),
_ => None,
}
}
fn low_reg(op: Option<Operand>) -> Option<u16> {
match op {
Some(Operand::Reg(r)) if r.is_low() => Some(r.num() as u16),
_ => None,
}
}
fn plain_mem(op: Option<Operand>) -> Option<Mem> {
match op {
Some(Operand::Mem(m)) if m.index.is_none() && m.mode == AddrMode::Offset => Some(m),
_ => None,
}
}
fn mem_field(insn: &Insn, base: Reg, lo: u32, hi: u32) -> Option<(u16, u16)> {
if insn.operands.len() != 2 {
return None;
}
let rt = low_reg(insn.operands.get(0))?;
let m = plain_mem(insn.operands.get(1))?;
if m.base != base {
return None;
}
Some((rt, scaled_offset(&m, lo, hi)?))
}
fn scaled_offset(mem: &Mem, lo: u32, hi: u32) -> Option<u16> {
if !mem.add || mem.offset < lo || mem.offset > hi || mem.offset % 4 != 0 {
return None;
}
Some((mem.offset / 4) as u16)
}
fn neg_scaled_offset(mem: &Mem, hi: u32) -> Option<u16> {
if mem.add != (mem.offset == 0) || mem.offset > hi || mem.offset % 4 != 0 {
return None;
}
Some((mem.offset / 4) as u16)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::isa::Target;
use crate::isa::{decode_halfwords, Decoder};
fn dec(hw1: u16) -> Option<Insn> {
decode(hw1, 0, 0x1000)
}
const UNDEFINED_LO: u16 = 0xC100;
const UNDEFINED_HI: u16 = 0xC1FF;
#[test]
fn exhaustive_round_trip() {
for addr in [0u32, 2, 0x8000, 0xFFFF_FFFC] {
let mut decoded = 0usize;
let mut rejected = Vec::new();
for hw in RANGE_LO..=RANGE_HI {
match decode(hw, 0, addr) {
Some(i) => {
decoded += 1;
assert_eq!(encode(&i), Some(hw), "{hw:#06x} at {addr:#x} -> {i}");
assert_eq!(i.len(), 2, "{hw:#06x} must be narrow");
assert!(!i.sets_flags, "{hw:#06x} must not set flags");
assert!(!i.explicit_width, "{hw:#06x} needs no width suffix");
assert_eq!(i.cond, None, "{hw:#06x} has no condition field");
assert_eq!(i.addr, addr);
}
None => rejected.push(hw),
}
}
assert_eq!(rejected.len(), 256);
assert_eq!(decoded, 4096 - 256);
assert_eq!(decoded, 3840);
let expected: Vec<u16> = (UNDEFINED_LO..=UNDEFINED_HI).collect();
assert_eq!(rejected, expected);
}
}
#[test]
fn non_interference() {
let mut claimed = 0usize;
for hw in 0..=u16::MAX {
let owned =
(RANGE_LO..=RANGE_HI).contains(&hw) && !(UNDEFINED_LO..=UNDEFINED_HI).contains(&hw);
match dec(hw) {
Some(i) => {
assert!(owned, "{hw:#06x} is not ThumbEE's, decoded as {i}");
claimed += 1;
}
None => assert!(!owned, "{hw:#06x} is ThumbEE's and was refused"),
}
}
assert_eq!(claimed, 3840);
}
#[test]
fn table_a9_2_partition() {
for hw in RANGE_LO..=RANGE_HI {
let expect = match hw {
0xC000..=0xC0FF => Some(("hbp", "E1")),
0xC100..=0xC1FF => None,
0xC200..=0xC2FF => Some(("hb", "E1")),
0xC300..=0xC3FF => Some(("hbl", "E1")),
0xC400..=0xC7FF => Some(("hblp", "E1")),
0xC800..=0xC9FF => Some(("ldr", "E3")),
0xCA00..=0xCAFF => Some(("chka", "E1")),
0xCB00..=0xCBFF => Some(("ldr", "E2")),
0xCC00..=0xCDFF => Some(("ldr", "E1")),
_ => Some(("str", "E1")),
};
let got = dec(hw).map(|i| (i.mnemonic, i.encoding));
assert_eq!(got, expect, "{hw:#06x}");
}
}
#[test]
fn encode_refuses_ordinary_thumb() {
let mut seen = 0usize;
let mut seen_ldm_stm = 0usize;
for hw in 0..=u16::MAX {
if let Some(i) = decode_halfwords(hw, 0, 0x1000, Target::Union) {
seen += 1;
assert_eq!(encode(&i), None, "{hw:#06x} ({i}) is not ThumbEE's");
if (RANGE_LO..=RANGE_HI).contains(&hw) {
seen_ldm_stm += 1;
}
}
}
assert_eq!(seen_ldm_stm, 4096 - 16);
assert!(seen >= 10_224, "sweep decoded only {seen} instructions");
}
#[test]
fn encode_refuses_operands_no_field_can_hold() {
let ops = |items: &[Operand]| items.iter().copied().collect::<Operands>();
let r0 = Operand::Reg(Reg(0));
let imm = |v| Operand::Imm(v);
let frame = |base: Reg, offset, add| {
Operand::Mem(Mem {
base,
index: None,
offset,
add,
align: 0,
mode: AddrMode::Offset,
})
};
let cases: &[(u16, &[Operand], &str)] = &[
(0xC0E1, &[imm(7)], "HBP takes two operands"),
(0xC0E1, &[imm(7), imm(1), imm(0)], "HBP takes two operands"),
(0xC0E1, &[imm(8), imm(1)], "imm3 holds 0..=7"),
(0xC0E1, &[imm(7), imm(32)], "handler is five bits"),
(0xC0E1, &[r0, imm(1)], "the fields are immediates"),
(0xC0E1, &[imm(7), r0], "the fields are immediates"),
(0xC207, &[], "HB takes one operand"),
(0xC207, &[imm(7), imm(0)], "HB takes one operand"),
(0xC207, &[imm(256)], "handler is eight bits"),
(0xC207, &[imm(-1)], "handler is unsigned"),
(0xC307, &[imm(256)], "HBL's handler is eight bits"),
(0xC7E0, &[imm(31)], "HBLP takes two operands"),
(0xC7E0, &[imm(32), imm(0)], "imm5 holds 0..=31"),
(0xC7E0, &[imm(31), imm(32)], "handler is five bits"),
(0xCAFE, &[r0], "CHKA takes two operands"),
(0xCAFE, &[r0, r0, r0], "CHKA takes two operands"),
(0xCAFE, &[imm(0), r0], "Rn is a register"),
(0xCAFE, &[r0, imm(0)], "Rm is a register"),
(0xCC10, &[r0], "the frame forms take two operands"),
(
0xCC10,
&[imm(0), frame(Reg(9), 8, true)],
"Rt is a register",
),
(
0xCC10,
&[Operand::Reg(Reg(8)), frame(Reg(9), 8, true)],
"Rt is three bits",
),
(0xCC10, &[r0, imm(8)], "the second operand is memory"),
(0xCC10, &[r0, frame(Reg(1), 8, true)], "the base is r9"),
(
0xCC10,
&[r0, frame(Reg(9), 256, true)],
"imm6:'00' reaches 252",
),
(
0xCC10,
&[r0, frame(Reg(9), 6, true)],
"imm6:'00' is a multiple of four",
),
(
0xCC10,
&[r0, frame(Reg(9), 8, false)],
"no U bit to subtract with",
),
(
0xCE13,
&[r0, frame(Reg(1), 8, true)],
"STR's base is r9 too",
),
(
0xCB08,
&[r0, frame(Reg(9), 8, true)],
"the pool base is r10",
),
(
0xCB08,
&[r0, frame(Reg(10), 128, true)],
"imm5:'00' reaches 124",
),
(0xC9D1, &[r0], "the array form takes two operands"),
(0xC9D1, &[r0, r0], "the second operand is memory"),
(
0xC9D1,
&[Operand::Reg(Reg(9)), frame(Reg(2), 28, false)],
"Rt is three bits",
),
(0xC9D1, &[r0, frame(Reg(9), 28, false)], "Rn is three bits"),
(
0xC9D1,
&[r0, frame(Reg(2), 32, false)],
"imm3:'00' reaches 28",
),
(
0xC9D1,
&[r0, frame(Reg(2), 6, false)],
"imm3:'00' is a multiple of four",
),
(
0xC9D1,
&[r0, frame(Reg(2), 28, true)],
"the array offset subtracts",
),
(
0xC9D1,
&[r0, frame(Reg(2), 0, false)],
"there is no #-0 here",
),
];
for &(hw, operands, why) in cases {
let base = dec(hw).expect("the base halfword decodes");
let bad = Insn {
operands: ops(operands),
..base
};
assert_eq!(encode(&bad), None, "`{bad}` from {hw:#06x}: {why}");
}
for mode in [
AddrMode::PreIndex,
AddrMode::PostIndex,
AddrMode::PostIncrement,
] {
let bad = Insn {
operands: ops(&[
r0,
Operand::Mem(Mem {
base: Reg(9),
index: None,
offset: 8,
add: true,
align: 0,
mode,
}),
]),
..dec(0xCC10).unwrap()
};
assert_eq!(encode(&bad), None, "`{bad}` writes its base back");
}
let indexed = Insn {
operands: ops(&[
r0,
Operand::Mem(Mem {
base: Reg(9),
index: Some((Reg(1), None)),
offset: 0,
add: true,
align: 0,
mode: AddrMode::Offset,
}),
]),
..dec(0xCC10).unwrap()
};
assert_eq!(encode(&indexed), None, "no register index in chapter A9");
}
#[test]
fn ual_text() {
assert_eq!(dec(0xCA08).unwrap().to_string(), "chka r0, r1");
assert_eq!(dec(0xCA9D).unwrap().to_string(), "chka sp, r3");
assert_eq!(dec(0xC207).unwrap().to_string(), "hb #7");
assert_eq!(dec(0xC2FF).unwrap().to_string(), "hb #0xff");
assert_eq!(dec(0xC31F).unwrap().to_string(), "hbl #0x1f");
assert_eq!(dec(0xC443).unwrap().to_string(), "hblp #2, #3");
assert_eq!(dec(0xC0FF).unwrap().to_string(), "hbp #7, #0x1f");
assert_eq!(dec(0xCC00).unwrap().to_string(), "ldr r0, [r9]");
assert_eq!(dec(0xCDF8).unwrap().to_string(), "ldr r0, [r9, #252]");
assert_eq!(dec(0xCB00).unwrap().to_string(), "ldr r0, [r10]");
assert_eq!(dec(0xCBFF).unwrap().to_string(), "ldr r7, [r10, #124]");
assert_eq!(dec(0xC811).unwrap().to_string(), "ldr r1, [r2]");
assert_eq!(dec(0xC9D1).unwrap().to_string(), "ldr r1, [r2, #-28]");
assert_eq!(dec(0xCE13).unwrap().to_string(), "str r3, [r9, #8]");
assert_eq!(dec(0xCFF8).unwrap().to_string(), "str r0, [r9, #252]");
}
#[test]
fn field_extents() {
let hbp = dec(0xC0E1).unwrap();
assert_eq!(hbp.operands.get(0), Some(Operand::Imm(7)));
assert_eq!(hbp.operands.get(1), Some(Operand::Imm(1)));
let hblp = dec(0xC7E0).unwrap();
assert_eq!(hblp.operands.get(0), Some(Operand::Imm(31)));
assert_eq!(hblp.operands.get(1), Some(Operand::Imm(0)));
let chka = dec(0xCAFE).unwrap();
assert_eq!(chka.operands.get(0), Some(Operand::Reg(Reg::LR)));
assert_eq!(chka.operands.get(1), Some(Operand::Reg(Reg::PC)));
assert_eq!(encode(&chka), Some(0xCAFE));
let chka_pc = dec(0xCA87).unwrap();
assert_eq!(chka_pc.operands.get(0), Some(Operand::Reg(Reg::PC)));
assert_eq!(encode(&chka_pc), Some(0xCA87));
for imm3 in 0..8u16 {
let i = dec(0xC800 | (imm3 << 6)).unwrap();
let m = i
.operands
.as_slice()
.find_map(|o| match o {
Operand::Mem(m) => Some(m),
_ => None,
})
.expect("the array form carries a memory operand");
assert_eq!(m.offset, 4 * u32::from(imm3));
assert_eq!(m.displacement(), -4 * i64::from(imm3));
assert_eq!(m.add, imm3 == 0);
assert_eq!(m.base, Reg(0));
assert_eq!(m.mode, AddrMode::Offset);
assert!(m.index.is_none());
}
}
#[test]
fn handler_branches_have_no_target() {
for hw in 0xC000..=0xC7FFu16 {
if let Some(i) = dec(hw) {
assert_eq!(i.branch_target(), None, "{hw:#06x} ({i})");
assert!(
!i.operands
.as_slice()
.any(|o| matches!(o, Operand::Target(_))),
"{hw:#06x} emitted a target"
);
}
}
for hw in 0xCA00..=0xCAFFu16 {
assert_eq!(dec(hw).unwrap().branch_target(), None, "{hw:#06x}");
}
}
#[test]
fn encode_rejects_unencodable() {
let mut frame = dec(0xCC00).unwrap();
frame.operands = [Operand::Reg(Reg(0)), mem(FRAME_BASE, true, 252)]
.into_iter()
.collect();
assert_eq!(encode(&frame), Some(0xCDF8));
frame.operands = [Operand::Reg(Reg(0)), mem(FRAME_BASE, true, 256)]
.into_iter()
.collect();
assert_eq!(encode(&frame), None);
frame.operands = [Operand::Reg(Reg(0)), mem(FRAME_BASE, true, 2)]
.into_iter()
.collect();
assert_eq!(encode(&frame), None);
frame.operands = [Operand::Reg(Reg(0)), mem(FRAME_BASE, false, 4)]
.into_iter()
.collect();
assert_eq!(encode(&frame), None);
frame.operands = [Operand::Reg(Reg(0)), mem(FRAME_BASE, false, 0)]
.into_iter()
.collect();
assert_eq!(encode(&frame), None);
frame.operands = [Operand::Reg(Reg(0)), mem(Reg(8), true, 4)]
.into_iter()
.collect();
assert_eq!(encode(&frame), None);
let mut array = dec(0xC811).unwrap();
array.operands = [Operand::Reg(Reg(1)), mem(Reg(2), false, 0)]
.into_iter()
.collect();
assert_eq!(encode(&array), None);
let mut hb = dec(0xC200).unwrap();
hb.operands = core::iter::once(Operand::Imm(255)).collect();
assert_eq!(encode(&hb), Some(0xC2FF));
hb.operands = core::iter::once(Operand::Imm(256)).collect();
assert_eq!(encode(&hb), None);
hb.operands = core::iter::once(Operand::Imm(-1)).collect();
assert_eq!(encode(&hb), None);
let mut wide = dec(0xCA08).unwrap();
wide.width = Width::Wide;
assert_eq!(encode(&wide), None);
let mut flags = dec(0xCA08).unwrap();
flags.sets_flags = true;
assert_eq!(encode(&flags), None);
let mut t1 = dec(0xCC00).unwrap();
t1.encoding = "T1";
assert_eq!(encode(&t1), None);
}
#[test]
fn decoder_flag_switches_the_map() {
let image = [0x24, 0xCC];
let plain = Decoder::new(&image).next().unwrap();
assert_eq!(plain.mnemonic, "ldmia");
assert_eq!(plain.to_string(), "ldmia r4!, {r2, r5}");
let ee = Decoder::new(&image)
.target(crate::isa::Target::ThumbEE)
.next()
.unwrap();
assert_eq!(ee.mnemonic, "ldr");
assert_eq!(ee.encoding, "E1");
assert_eq!(ee.to_string(), "ldr r4, [r9, #16]");
let hb_image = [0x07, 0xC2];
assert_eq!(
Decoder::new(&hb_image).next().unwrap().mnemonic,
"stmia",
"0xC207 is STM T1 in Thumb state"
);
let hb = Decoder::new(&hb_image)
.target(crate::isa::Target::ThumbEE)
.next()
.unwrap();
assert_eq!(hb.to_string(), "hb #7");
let bx = [0x70, 0x47];
assert_eq!(
Decoder::new(&bx).next().unwrap(),
Decoder::new(&bx)
.target(crate::isa::Target::ThumbEE)
.next()
.unwrap()
);
let undef = [0xC0, 0xC1];
assert!(dec(0xC1C0).is_none(), "0xC1C0 is not a ThumbEE encoding");
assert!(owns(0xC1C0), "…but it is in the range ThumbEE re-assigns");
assert_eq!(Decoder::new(&undef).next().unwrap().mnemonic, "stmia");
assert_eq!(
Decoder::new(&undef)
.target(crate::isa::Target::ThumbEE)
.next(),
None,
"A9.2.1's UNDEFINED row must not reappear as the Thumb encoding \
ThumbEE replaced"
);
}
#[test]
fn owns_agrees_with_decode() {
let mut owned = 0usize;
for hw in 0..=u16::MAX {
if dec(hw).is_some() {
assert!(owns(hw), "{hw:#06x} decoded but is not owned");
}
if owns(hw) {
owned += 1;
assert!(
(RANGE_LO..=RANGE_HI).contains(&hw),
"{hw:#06x} is owned but outside A9.2.1's range"
);
}
}
assert_eq!(owned, 4096);
let undefined: Vec<u16> = (0..=u16::MAX)
.filter(|&hw| owns(hw) && dec(hw).is_none())
.collect();
assert_eq!(undefined, (UNDEFINED_LO..=UNDEFINED_HI).collect::<Vec<_>>());
}
#[test]
fn dispatch_matches_state_over_the_whole_range() {
for hw in RANGE_LO..=RANGE_HI {
let ee = decode_halfwords(hw, 0, 0x1000, Target::ThumbEE);
assert_eq!(ee, dec(hw), "{hw:#06x} in ThumbEE state");
let plain = decode_halfwords(hw, 0, 0x1000, Target::Union);
if let Some(i) = plain {
assert!(
matches!(i.mnemonic, "stmia" | "ldmia"),
"{hw:#06x} is A5.2's STM/LDM in Thumb state, got {i}"
);
}
}
}
#[test]
fn round_trips_through_public_encode() {
for hw in [
0xC0FFu16, 0xC207, 0xC31F, 0xC443, 0xC811, 0xC9D1, 0xCA08, 0xCA9D, 0xCB7F, 0xCC00,
0xCDF8, 0xCE13, 0xCFF8,
] {
let i = decode_halfwords(hw, 0, 0x1000, Target::ThumbEE).unwrap();
assert_eq!(crate::isa::encode(&i), Some((hw, 0)), "{hw:#06x} ({i})");
}
}
}