From ca92a309204a58647251a42a9ba0545356339f75 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 9 Oct 2022 21:41:34 -0400 Subject: [PATCH] Improve CRBit display --- disasm/src/lib.rs | 13 ++++++++++++- disasm/tests/test_disasm.rs | 14 ++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/disasm/src/lib.rs b/disasm/src/lib.rs index 1fd538b..802cfb7 100644 --- a/disasm/src/lib.rs +++ b/disasm/src/lib.rs @@ -108,7 +108,18 @@ field_arg!(SPR, u16); // Condition register field. field_arg!(CRField, u8, "cr{}"); // Condition register bit (index + condition case). -field_arg!(CRBit, u8, "{}"); +field_arg_no_display!(CRBit, u8); +impl Display for CRBit { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let cr = self.0 >> 2; + let cc = self.0 & 3; + if cr != 0 { + write!(f, "4*{}+", CRField(cr))?; + } + const CR_NAMES: [&str; 4] = ["lt", "gt", "eq", "so"]; + f.write_str(CR_NAMES[cc as usize]) + } +} // Paired-single graphics quantization register field_arg!(GQR, u8, "qr{}"); // Unsigned immediate. diff --git a/disasm/tests/test_disasm.rs b/disasm/tests/test_disasm.rs index 210cd81..052ee86 100644 --- a/disasm/tests/test_disasm.rs +++ b/disasm/tests/test_disasm.rs @@ -149,11 +149,10 @@ fn test_ins_cmp() { assert_asm!(0x7C030000, "cmpw r3, r0"); } -/* #[test] fn test_ins_cmpi() { assert_asm!(0x2C050D00, "cmpwi r5, 0xd00"); - assert_asm!(0x2F1F0000, "cmpwi cr6, r31, 0"); + assert_asm!(0x2F1F0000, "cmpwi cr6, r31, 0x0"); } #[test] @@ -166,7 +165,6 @@ fn test_ins_cmpli() { assert_asm!(0x2803FFF3, "cmplwi r3, 0xfff3"); assert_asm!(0x2884F8F0, "cmplwi cr1, r4, 0xf8f0"); } -*/ #[test] fn test_ins_cntlzw() { @@ -175,7 +173,7 @@ fn test_ins_cntlzw() { #[test] fn test_ins_cror() { - assert_asm!(0x4C411382, "cror 2, 1, 2"); + assert_asm!(0x4C411382, "cror eq, gt, eq"); } #[test] @@ -516,14 +514,14 @@ fn test_ins_mtcrf() { assert_asm!(0x7C6FF120, "mtcrf 255, r3"); } -/* #[test] -fn test_ins_mtfsb0() {} - */ +fn test_ins_mtfsb0() { + assert_asm!(0xFFA0008C, "mtfsb0 4*cr7+gt") +} #[test] fn test_ins_mtfsb1() { - assert_asm!(0xFFA0004C, "mtfsb1 29"); + assert_asm!(0xFFA0004C, "mtfsb1 4*cr7+gt"); } #[test]