more tests

This commit is contained in:
Richard Patel 2022-04-07 02:36:49 +02:00
parent b6ad3f4f2c
commit 8a57bd9eb2
5 changed files with 90 additions and 80 deletions

View File

@ -7,14 +7,17 @@ pub struct FormattedIns(pub Ins);
impl Display for FormattedIns {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let simple = self.0.clone().simplified();
write!(f, "{}{} ", simple.mnemonic, simple.modifiers)?;
write!(f, "{}{}", simple.mnemonic, simple.modifiers)?;
let mut writing_offset = false;
for (i, arg) in simple.args.iter().enumerate() {
if i > 0 {
if i == 0 {
write!(f, " ")?;
}
if i > 0 && !writing_offset {
write!(f, ", ")?;
}
if let Argument::Offset(_) = arg {
write!(f, "(")?;
if let Argument::Offset(val) = arg {
write!(f, "{}(", val)?;
writing_offset = true;
continue;
} else {

View File

@ -1836,7 +1836,6 @@ impl Ins {
],
Opcode::PsAbs => vec![
Field::frD(FPR(((self.code >> 21u8) & 0x1f) as _)),
Field::frA(FPR(((self.code >> 16u8) & 0x1f) as _)),
Field::frB(FPR(((self.code >> 11u8) & 0x1f) as _)),
],
Opcode::PsAdd => vec![
@ -2048,12 +2047,12 @@ impl Ins {
Field::rB(GPR(((self.code >> 11u8) & 0x1f) as _)),
],
Opcode::Stfd => vec![
Field::rS(GPR(((self.code >> 21u8) & 0x1f) as _)),
Field::frS(FPR(((self.code >> 21u8) & 0x1f) as _)),
Field::offset(Offset(((self.code >> 0u8) & 0xffff) as _)),
Field::rA(GPR(((self.code >> 16u8) & 0x1f) as _)),
],
Opcode::Stfdu => vec![
Field::rS(GPR(((self.code >> 21u8) & 0x1f) as _)),
Field::frS(FPR(((self.code >> 21u8) & 0x1f) as _)),
Field::offset(Offset(((self.code >> 0u8) & 0xffff) as _)),
Field::rA(GPR(((self.code >> 16u8) & 0x1f) as _)),
],
@ -2073,12 +2072,12 @@ impl Ins {
Field::rB(GPR(((self.code >> 11u8) & 0x1f) as _)),
],
Opcode::Stfs => vec![
Field::rS(GPR(((self.code >> 21u8) & 0x1f) as _)),
Field::frS(FPR(((self.code >> 21u8) & 0x1f) as _)),
Field::offset(Offset(((self.code >> 0u8) & 0xffff) as _)),
Field::rA(GPR(((self.code >> 16u8) & 0x1f) as _)),
],
Opcode::Stfsu => vec![
Field::rS(GPR(((self.code >> 21u8) & 0x1f) as _)),
Field::frS(FPR(((self.code >> 21u8) & 0x1f) as _)),
Field::offset(Offset(((self.code >> 0u8) & 0xffff) as _)),
Field::rA(GPR(((self.code >> 16u8) & 0x1f) as _)),
],
@ -3368,10 +3367,7 @@ impl Ins {
uses
}
Opcode::PsAbs => {
let mut uses = vec![
Field::frA(FPR(((self.code >> 16u8) & 0x1f) as _)),
Field::frB(FPR(((self.code >> 11u8) & 0x1f) as _)),
];
let mut uses = vec![Field::frB(FPR(((self.code >> 11u8) & 0x1f) as _))];
uses
}
Opcode::PsAdd => {
@ -3652,7 +3648,7 @@ impl Ins {
uses
}
Opcode::Stfd => {
let mut uses = vec![Field::rS(GPR(((self.code >> 21u8) & 0x1f) as _))];
let mut uses = vec![Field::frS(FPR(((self.code >> 21u8) & 0x1f) as _))];
if ((self.code >> 16u8) & 0x1f) != 0 {
uses.push(Field::rA(GPR(((self.code >> 16u8) & 0x1f) as _)));
}
@ -3660,7 +3656,7 @@ impl Ins {
}
Opcode::Stfdu => {
let mut uses = vec![
Field::rS(GPR(((self.code >> 21u8) & 0x1f) as _)),
Field::frS(FPR(((self.code >> 21u8) & 0x1f) as _)),
Field::rA(GPR(((self.code >> 16u8) & 0x1f) as _)),
];
uses
@ -3694,7 +3690,7 @@ impl Ins {
uses
}
Opcode::Stfs => {
let mut uses = vec![Field::rS(GPR(((self.code >> 21u8) & 0x1f) as _))];
let mut uses = vec![Field::frS(FPR(((self.code >> 21u8) & 0x1f) as _))];
if ((self.code >> 16u8) & 0x1f) != 0 {
uses.push(Field::rA(GPR(((self.code >> 16u8) & 0x1f) as _)));
}
@ -3702,7 +3698,7 @@ impl Ins {
}
Opcode::Stfsu => {
let mut uses = vec![
Field::rS(GPR(((self.code >> 21u8) & 0x1f) as _)),
Field::frS(FPR(((self.code >> 21u8) & 0x1f) as _)),
Field::rA(GPR(((self.code >> 16u8) & 0x1f) as _)),
];
uses

View File

@ -101,7 +101,7 @@ impl<N: PrimInt> UpperHex for ReallySigned<N> {
// General-purpose register.
field_arg!(GPR, u8, "r{}");
// Floating-point register (direct or paired-singles mode).
field_arg!(FPR, u8, "fr{}");
field_arg!(FPR, u8, "f{}");
// Segment register.
field_arg!(SR, u8);
// Special-purpose register.
@ -109,15 +109,15 @@ field_arg!(SPR, u16);
// Condition register field.
field_arg!(CRField, u8, "crb{}");
// Condition register bit (index + condition case).
field_arg!(CRBit, u8, "crf{}");
field_arg!(CRBit, u8, "cr{}");
// Paired-single graphics quantization register
field_arg!(GQR, u8);
field_arg!(GQR, u8, "qr{}");
// Unsigned immediate.
field_arg!(Uimm, u16, "{:#x}");
// Signed immediate.
field_arg!(Simm, i16, "{:#x}", ReallySigned);
// Offset for indirect memory reference.
field_arg!(Offset, i32, "{:#x}", ReallySigned);
field_arg!(Offset, i16, "{:#x}", ReallySigned);
// Branch destination.
field_arg!(BranchDest, i32, "{:#x}", ReallySigned);
// Opaque zero or one argument.

View File

@ -35,25 +35,7 @@ fn test_ins_addi() {
assert_asm!(0x38010018, "addi r0, r1, 0x18");
assert_asm!(0x38010140, "addi r0, r1, 0x140");
assert_asm!(0x38049000, "addi r0, r4, -0x7000");
//assert_asm!(0x38a00000, "li r5, 0");
}
#[test]
fn test_ins_psq_lx() {
let ins = Ins::new(0x1000000C, 0x8000_0000u32);
assert_eq!(ins.op, PsqLx);
assert_eq!(
ins.fields(),
vec![
frD(FPR(0)),
rA(GPR(0)),
rB(GPR(0)),
ps_W(OpaqueU(0)),
ps_l(GQR(0))
]
);
assert_eq!(ins.defs(), vec![frD(FPR(0))]);
assert_eq!(ins.uses(), vec![rB(GPR(0))]);
assert_asm!(0x38a00000, "li r5, 0x0");
}
#[test]
@ -75,7 +57,7 @@ fn test_ins_addic() {
fn test_ins_addis() {
assert_asm!(0x3C030000, "addis r0, r3, 0x0");
assert_asm!(0x3C038000, "addis r0, r3, 0x8000");
//assert_asm!(0x3D00EFCE, "lis r8, 0xefce");
assert_asm!(0x3D00EFCE, "lis r8, 0xefce");
}
#[test]
@ -89,8 +71,6 @@ fn test_ins_and() {
assert_asm!(0x7C001839, "and. r0, r0, r3");
}
/*
#[test]
fn test_ins_andc() {
assert_asm!(0x7C001878, "andc r0, r0, r3");
@ -98,14 +78,14 @@ fn test_ins_andc() {
#[test]
fn test_ins_andi_() {
assert_asm!(0x70000009, "andi. r0, r0, 9");
assert_asm!(0x70000009, "andi. r0, r0, 0x9");
}
#[test]
fn test_ins_andis_() {
assert_asm!(0x77c802ff, "andis. r8, r30, 0x2ff");
}
/*
#[test]
fn test_ins_b() {
assert_asm!(0x48000000, "b 0x0");
@ -143,13 +123,17 @@ fn test_ins_bc() {
assert_asm!(0x419C0008, "blt cr7, 0x8");
assert_asm!(0x4200F560, "bdnz -0xaa0");
}
*/
/*
#[test]
fn test_ins_bcctr() {
assert_asm!(0x4E800420, "bctr");
assert_asm!(0x4E800421, "bctrl");
}
*/
/*
#[test]
fn test_ins_bclr() {
assert_asm!(0x4C800020, "bgelr");
@ -163,12 +147,14 @@ fn test_ins_bclr() {
assert_asm!(0x4E800020, "blr");
assert_asm!(0x4E800021, "blrl");
}
*/
#[test]
fn test_ins_cmp() {
assert_asm!(0x7C030000, "cmpw r3, r0");
}
/*
#[test]
fn test_ins_cmpi() {
assert_asm!(0x2C050D00, "cmpwi r5, 0xd00");
@ -185,40 +171,43 @@ fn test_ins_cmpli() {
assert_asm!(0x2803FFF3, "cmplwi r3, 0xfff3");
assert_asm!(0x2884F8F0, "cmplwi cr1, r4, 0xf8f0");
}
*/
#[test]
fn test_ins_cntlzw() {
assert_asm!(0x7C030034, "cntlzw r3, r0");
}
/*
#[test]
fn test_ins_cror() {
assert_asm!(0x4C411382, "cror cr2, cr1, cr2");
}
*/
#[test]
fn test_ins_dcbf() {
assert_asm!(0x7C0028AC, "dcbf 0, r5");
assert_asm!(0x7C0028AC, "dcbf r0, r5");
}
#[test]
fn test_ins_dcbi() {
assert_asm!(0x7C001BAC, "dcbi 0, r3");
assert_asm!(0x7C001BAC, "dcbi r0, r3");
}
#[test]
fn test_ins_dcbst() {
assert_asm!(0x7C00286C, "dcbst 0, r5");
assert_asm!(0x7C00286C, "dcbst r0, r5");
}
#[test]
fn test_ins_dcbt() {
assert_asm!(0x7C001A2C, "dcbt 0, r3");
assert_asm!(0x7C001A2C, "dcbt r0, r3");
}
#[test]
fn test_ins_dcbz() {
assert_asm!(0x7C001FEC, "dcbz 0, r3");
assert_asm!(0x7C001FEC, "dcbz r0, r3");
}
#[test]
@ -361,7 +350,7 @@ fn test_ins_fsubs() {
#[test]
fn test_ins_icbi() {
assert_asm!(0x7C001FAC, "icbi 0, r3");
assert_asm!(0x7C001FAC, "icbi r0, r3");
}
#[test]
@ -437,8 +426,8 @@ fn test_ins_lha() {
#[test]
fn test_ins_lhau() {
assert_asm!(0xAC060006, "lhau r0, 6(r6)");
assert_asm!(0xAC06FFFA, "lhau r0, -6(r6)");
assert_asm!(0xAC060006, "lhau r0, 0x6(r6)");
assert_asm!(0xAC06FFFA, "lhau r0, -0x6(r6)");
}
#[test]
@ -454,7 +443,7 @@ fn test_ins_lhz() {
#[test]
fn test_ins_lhzu() {
assert_asm!(0xA40A0004, "lhzu r0, 4(r10)");
assert_asm!(0xA40A0004, "lhzu r0, 0x4(r10)");
}
#[test]
@ -474,7 +463,7 @@ fn test_ins_lmw() {
#[test]
fn test_ins_lwbrx() {
assert_asm!(0x7D80242C, "lwbrx r12, 0, r4");
assert_asm!(0x7D80242C, "lwbrx r12, r0, r4");
}
#[test]
@ -501,13 +490,15 @@ fn test_ins_lwzx() {
#[test]
fn test_ins_mfcr() {
assert_asm!(0x7C000026, "mfcr r0");
assert_asm!(0x7C000026, "mfcr cr0");
}
/*
#[test]
fn test_ins_mffs() {
assert_asm!(0xFC00048E, "mffs f0");
}
*/
#[test]
fn test_ins_mfmsr() {
@ -516,7 +507,7 @@ fn test_ins_mfmsr() {
#[test]
fn test_ins_mfspr() {
assert_asm!(0x7E1A02A6, "mfspr r16, 0x1a");
assert_asm!(0x7E1A02A6, "mfspr r16, 832");
}
#[test]
@ -526,7 +517,7 @@ fn test_ins_mfsr() {
#[test]
fn test_ins_mftb() {
assert_asm!(0x7C8C42E6, "mftb r4, 0x10c");
assert_asm!(0x7C8C42E6, "mftb r4, 392");
}
#[test]
@ -557,7 +548,7 @@ fn test_ins_mtmsr() {
#[test]
fn test_ins_mtspr() {
assert_asm!(0x7E75FBA6, "mtspr 0x3f5, r19");
assert_asm!(0x7E75FBA6, "mtspr 703, r19");
}
#[test]
@ -626,21 +617,40 @@ fn test_ins_psq_l() {
assert_asm!(0xE02500AC, "psq_l f1, 0xac(r5), 0, qr0");
}
/*
#[test]
fn test_ins_psq_lu() {
assert_asm!(0xE5435010, "psq_lu f10, 0x10(r3), 0, qr5");
}
*/
#[test]
fn test_ins_psq_lx() {
let ins = Ins::new(0x1000000C, 0x8000_0000u32);
assert_eq!(ins.op, PsqLx);
assert_eq!(
ins.fields(),
vec![
frD(FPR(0)),
rA(GPR(0)),
rB(GPR(0)),
ps_W(OpaqueU(0)),
ps_l(GQR(0))
]
);
assert_eq!(ins.defs(), vec![frD(FPR(0))]);
assert_eq!(ins.uses(), vec![rB(GPR(0))]);
assert_asm!(0x1000000C, "psq_lx f0, r0, r0, 0, qr0");
}
/*
#[test]
fn test_ins_psq_st() {
assert_asm!(0xF1230210, "psq_st f9, 0x210(r3), 0, qr0");
assert_asm!(0xF1238008, "psq_st f9, 8(r3), 1, qr0");
}
*/
#[test]
fn test_ins_psq_stu() {
@ -779,20 +789,20 @@ fn test_ins_rfi() {
#[test]
fn test_ins_rlwimi() {
assert_asm!(0x500306FE, "rlwimi r3, r0, 0, 0x1b, 0x1f");
assert_asm!(0x50032D74, "rlwimi r3, r0, 5, 0x15, 0x1a");
assert_asm!(0x500306FE, "rlwimi r3, r0, 0, 27, 31");
assert_asm!(0x50032D74, "rlwimi r3, r0, 5, 21, 26");
}
#[test]
fn test_ins_rlwinm() {
assert_asm!(0x54000423, "rlwinm. r0, r0, 0, 0x10, 0x11");
assert_asm!(0x54000432, "rlwinm r0, r0, 0, 0x10, 0x19");
assert_asm!(0x54000423, "rlwinm. r0, r0, 0, 16, 17");
assert_asm!(0x54000432, "rlwinm r0, r0, 0, 16, 25");
}
#[test]
fn test_ins_rlwnm() {
assert_asm!(0x5D6A67FE, "rlwnm r10, r11, r12, 0x1f, 0x1f");
assert_asm!(0x5FC52EFE, "rlwnm r5, r30, r5, 0x1b, 0x1f");
assert_asm!(0x5D6A67FE, "rlwnm r10, r11, r12, 31, 31");
assert_asm!(0x5FC52EFE, "rlwnm r5, r30, r5, 27, 31");
}
#[test]
@ -824,13 +834,13 @@ fn test_ins_srw() {
#[test]
fn test_ins_stb() {
assert_asm!(0x980105EC, "stb r0, 0x5ec(r1)");
assert_asm!(0x98030000, "stb r0, 0(r3)");
assert_asm!(0x98030000, "stb r0, 0x0(r3)");
}
#[test]
fn test_ins_stbu() {
assert_asm!(0x9D2A7428, "stbu r9, 0x7428(r10)");
assert_asm!(0x9D66FFFF, "stbu r11, -1(r6)");
assert_asm!(0x9D66FFFF, "stbu r11, -0x1(r6)");
}
#[test]
@ -854,10 +864,12 @@ fn test_ins_stfdu() {
assert_asm!(0xDC24FFC0, "stfdu f1, -0x40(r4)");
}
/*
#[test]
fn test_ins_stfdx() {
assert_asm!(0x7C4405AE, "stfdx f2, r4, r0");
}
*/
#[test]
fn test_ins_stfs() {
@ -878,7 +890,7 @@ fn test_ins_sth() {
#[test]
fn test_ins_sthbrx() {
assert_asm!(0x7C60072C, "sthbrx r3, 0, r0");
assert_asm!(0x7C60072C, "sthbrx r3, r0, r0");
}
#[test]
@ -909,7 +921,7 @@ fn test_ins_stw() {
#[test]
fn test_ins_stwbrx() {
assert_asm!(0x7C00FD2C, "stwbrx r0, 0, r31");
assert_asm!(0x7C00FD2C, "stwbrx r0, r0, r31");
}
#[test]
@ -972,4 +984,3 @@ fn test_ins_xori() {
fn test_ins_xoris() {
assert_asm!(0x6E3D8000, "xoris r29, r17, 0x8000");
}
*/

View File

@ -1319,9 +1319,9 @@ opcodes:
bitmask: 0xfc1f07fe
pattern: 0x10000210
modifiers: [ Rc ]
args: [ frD, frA, frB ]
args: [ frD, frB ]
defs: [ frD ]
uses: [ frA, frB ]
uses: [ frB ]
- name: ps_add
desc: Paired Single Add
@ -1678,16 +1678,16 @@ opcodes:
desc: Store Floating-Point Double
bitmask: 0xfc000000
pattern: 0xd8000000
args: [ rS, offset, rA ]
uses: [ rS, rA.nz ]
args: [ frS, offset, rA ]
uses: [ frS, rA.nz ]
- name: stfdu
desc: Store Floating-Point Double with Update
bitmask: 0xfc000000
pattern: 0xdc000000
args: [ rS, offset, rA ]
args: [ frS, offset, rA ]
defs: [ rA ]
uses: [ rS, rA ]
uses: [ frS, rA ]
- name: stfdux
desc: Store Floating-Point Double with Update Indexed
@ -1715,16 +1715,16 @@ opcodes:
desc: Store Floating-Point Single
bitmask: 0xfc000000
pattern: 0xd0000000
args: [ rS, offset, rA ]
uses: [ rS, rA.nz ]
args: [ frS, offset, rA ]
uses: [ frS, rA.nz ]
- name: stfsu
desc: Store Floating-Point Single with Update
bitmask: 0xfc000000
pattern: 0xd4000000
args: [ rS, offset, rA ]
args: [ frS, offset, rA ]
defs: [ rA ]
uses: [ rS, rA ]
uses: [ frS, rA ]
- name: stfsux
desc: Store Floating-Point Single with Update Indexed