From b0609b1b20851cf33eb03a8f9491502121c4f127 Mon Sep 17 00:00:00 2001 From: iximeow Date: Mon, 7 Apr 2025 03:32:29 -0700 Subject: it is done (not all system, duplex, extender tho) --- notes/encoding_table | 10 +- notes/grouped_encodings | 8 +- notes/reordered_encodings | 10 +- notes/todo | 381 +++++++++++++++++++++++----------------------- src/display.rs | 11 ++ src/lib.rs | 42 +++-- tests/from_brain.rs | 79 ++++++++++ 7 files changed, 319 insertions(+), 222 deletions(-) diff --git a/notes/encoding_table b/notes/encoding_table index e2c2fba..65a17de 100644 --- a/notes/encoding_table +++ b/notes/encoding_table @@ -1228,10 +1228,10 @@ A L I A S A L I A S A L I A S A L I A S A L I A S | Rd=zxtb(Rs) |1 1 1 0|1 0 0 1|1 1 0|s s s s s| P P |0 t t t t t|0 0 0|d d d d d| Rd=cmpyrw(Rss,Rtt):<<1:rnd:sat - XTYPE COMPLEX/slot 3 |1 1 1 0|1 0 0 1|1 1 1|s s s s s| P P |0 t t t t t|0 0 0|d d d d d| Rd=cmpyrw(Rss,Rtt*):<<1:rnd:sat - XTYPE COMPLEX/slot 3 -|1 1 1 0|1 0 1 0|0 1 0|s s s s s| P P |0 t t t t t|1 1 0|x x x x x| Rxx+cmpyiw(Rss,Rtt*) - XTYPE COMPLEX/slot 3 -|1 1 1 0|1 0 1 0|0 1 1|s s s s s| P P |0 t t t t t|0 1 0|x x x x x| Rxx+cmpyiw(Rss,Rtt) - XTYPE COMPLEX/slot 3 -|1 1 1 0|1 0 1 0|1 0 0|s s s s s| P P |0 t t t t t|0 1 0|x x x x x| Rxx+cmpyrw(Rss,Rtt) - XTYPE COMPLEX/slot 3 -|1 1 1 0|1 0 1 0|1 1 0|s s s s s| P P |0 t t t t t|0 1 0|x x x x x| Rxx+cmpyrw(Rss,Rtt*) - XTYPE COMPLEX/slot 3 +|1 1 1 0|1 0 1 0|0 1 0|s s s s s| P P |0 t t t t t|1 1 0|x x x x x| Rxx+=cmpyiw(Rss,Rtt*) - XTYPE COMPLEX/slot 3 +|1 1 1 0|1 0 1 0|0 1 1|s s s s s| P P |0 t t t t t|0 1 0|x x x x x| Rxx+=cmpyiw(Rss,Rtt) - XTYPE COMPLEX/slot 3 +|1 1 1 0|1 0 1 0|1 0 0|s s s s s| P P |0 t t t t t|0 1 0|x x x x x| Rxx+=cmpyrw(Rss,Rtt) - XTYPE COMPLEX/slot 3 +|1 1 1 0|1 0 1 0|1 1 0|s s s s s| P P |0 t t t t t|0 1 0|x x x x x| Rxx+=cmpyrw(Rss,Rtt*) - XTYPE COMPLEX/slot 3 |ICLASS |RegType|MajOp|s5 |Parse| |MinOp|d5 | |1 1 1 0|1 0 0 0|N 0 1|s s s s s| P P |0 t t t t t|1 1 0|d d d d d| Rdd=vcmpyr(Rss,Rtt)[:< { + return write!(f, "{}, {} = {}({}, {})", + self.dest.as_ref().unwrap(), self.alt_dest.as_ref().unwrap(), + self.opcode, self.sources[0], self.sources[1]); + } + Opcode::Vminub => { + return write!(f, "{}, {} = {}({}, {})", + self.dest.as_ref().unwrap(), self.alt_dest.as_ref().unwrap(), + self.opcode, self.sources[0], self.sources[1]); + } Opcode::SfRecipa => { return write!(f, "{}, {} = {}({}, {})", self.dest.as_ref().unwrap(), self.alt_dest.as_ref().unwrap(), @@ -871,6 +881,7 @@ impl fmt::Display for Opcode { Opcode::Vmpyeh => { f.write_str("vmpyeh") }, Opcode::Vmpyweh => { f.write_str("vmpyweh") }, Opcode::Vmpywoh => { f.write_str("vmpywoh") }, + Opcode::Vrmpyweh => { f.write_str("vrmpyweh") }, Opcode::Vrmpywoh => { f.write_str("vrmpywoh") }, Opcode::Vrmpyu => { f.write_str("vrmpyu") }, Opcode::Vrmpysu => { f.write_str("vrmpysu") }, diff --git a/src/lib.rs b/src/lib.rs index 2e1aa74..0b94231 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -281,8 +281,6 @@ enum RoundingMode { Round, Cround, Raw, - Hi, - Lo, Pos, Neg, } @@ -293,8 +291,6 @@ impl RoundingMode { RoundingMode::Round => ":rnd", RoundingMode::Cround => ":crnd", RoundingMode::Raw => ":raw", - RoundingMode::Lo => ":lo", - RoundingMode::Hi => ":hi", RoundingMode::Pos => ":pos", RoundingMode::Neg => ":neg", } @@ -600,7 +596,6 @@ pub enum Opcode { Cmpyrwh, Cmpyi, Cmpyr, - Vacsh, Vcmpyi, Vcmpyr, Vmpybu, @@ -706,7 +701,6 @@ pub enum Opcode { Vmaxb, Vmaxub, Vminb, - Vminub, Vminuw, Vminh, Vminuh, @@ -820,6 +814,7 @@ pub enum Opcode { Vmpywoh, Vmpyweuh, Vmpywouh, + Vrmpyweh, Vrmpywoh, Vrmpyu, Vrmpysu, @@ -850,6 +845,8 @@ pub enum Opcode { AddClb, AddAdd, AddSub, + Vacsh, + Vminub, SfRecipa, SfInvsqrta, Any8VcmpbEq, @@ -6102,15 +6099,13 @@ fn decode_instruction< handler.on_source_decoded(Operand::gprpair(sssss)?)?; match opc { - o if o & 0b100011 == 0b100001 => { + o if o & 0b100011 == 0b000001 => { handler.on_opcode_decoded(Opcode::Vradduh)?; - rtt_star = true; saturate = false; shift_amt = 0; } o if o & 0b101111 == 0b001111 => { handler.on_opcode_decoded(Opcode::Vraddh)?; - rtt_star = true; saturate = false; shift_amt = 0; } @@ -6162,7 +6157,6 @@ fn decode_instruction< if o & 0b100000 == 0 { shift_amt = 0; } - rtt_star = true; } _other => { return Err(DecodeError::InvalidOpcode); @@ -6176,7 +6170,7 @@ fn decode_instruction< handler.shift_left(shift_amt)?; } if rtt_star { - handler.on_source_decoded(Operand::gpr_conjugate(ttttt))?; + handler.on_source_decoded(Operand::gprpair_conjugate(ttttt)?)?; } else { handler.on_source_decoded(Operand::gprpair(ttttt)?)?; } @@ -6190,6 +6184,7 @@ fn decode_instruction< handler.on_dest_decoded(Operand::gprpair(ddddd)?)?; handler.on_source_decoded(Operand::gprpair(sssss)?)?; let mut rtt_star = false; + let mut add_assign = true; match opc { 0b000010 => { @@ -6207,6 +6202,7 @@ fn decode_instruction< } 0b001100 => { handler.on_opcode_decoded(Opcode::Vcmpyr)?; + handler.saturate()?; } 0b010001 => { handler.on_opcode_decoded(Opcode::Vraddub)?; @@ -6242,7 +6238,7 @@ fn decode_instruction< handler.on_opcode_decoded(Opcode::Vrcmpys)?; handler.shift_left(1)?; handler.saturate()?; - handler.rounded(RoundingMode::Hi)?; + handler.raw_mode(RawMode::Hi)?; } 0b110001 => { handler.on_opcode_decoded(Opcode::Vrmpybsu)?; @@ -6254,12 +6250,13 @@ fn decode_instruction< o if o & 0b111100 == 0b111000 => { handler.on_opcode_decoded(Opcode::Vminub)?; handler.on_dest_decoded(Operand::pred(o & 0b11))?; + add_assign = false; } 0b111100 => { handler.on_opcode_decoded(Opcode::Vrcmpys)?; handler.shift_left(1)?; handler.saturate()?; - handler.rounded(RoundingMode::Lo)?; + handler.raw_mode(RawMode::Lo)?; } 0b000_100 | 0b100_100 => { handler.on_opcode_decoded(Opcode::Vdmpy)?; @@ -6288,7 +6285,7 @@ fn decode_instruction< handler.shift_left((opc >> 5) as u8)?; } 0b001_110 | 0b101_110 => { - handler.on_opcode_decoded(Opcode::Vrmpywoh)?; + handler.on_opcode_decoded(Opcode::Vrmpyweh)?; handler.shift_left((opc >> 5) as u8)?; } 0b001_111 | 0b101_111 => { @@ -6297,6 +6294,16 @@ fn decode_instruction< handler.rounded(RoundingMode::Round)?; handler.shift_left((opc >> 5) as u8)?; } + 0b010_101 | 0b110_101 => { + handler.on_opcode_decoded(Opcode::Vmpyweuh)?; + handler.saturate()?; + handler.shift_left((opc >> 5) as u8)?; + } + 0b010_111 | 0b110_111 => { + handler.on_opcode_decoded(Opcode::Vmpywouh)?; + handler.saturate()?; + handler.shift_left((opc >> 5) as u8)?; + } 0b011_101 | 0b111_101 => { handler.on_opcode_decoded(Opcode::Vmpyweuh)?; handler.saturate()?; @@ -6308,7 +6315,7 @@ fn decode_instruction< handler.shift_left((opc >> 5) as u8)?; } 0b011_111 | 0b111_111 => { - handler.on_opcode_decoded(Opcode::Vmpywoh)?; + handler.on_opcode_decoded(Opcode::Vmpywouh)?; handler.saturate()?; handler.rounded(RoundingMode::Round)?; handler.shift_left((opc >> 5) as u8)?; @@ -6319,10 +6326,13 @@ fn decode_instruction< } if rtt_star { - handler.on_source_decoded(Operand::gpr_conjugate(ttttt))?; + handler.on_source_decoded(Operand::gprpair_conjugate(ttttt)?)?; } else { handler.on_source_decoded(Operand::gprpair(ttttt)?)?; } + if add_assign { + handler.assign_mode(AssignMode::AddAssign)?; + } } 0b1011 => { // 1110|1011 diff --git a/tests/from_brain.rs b/tests/from_brain.rs index 3f26ad6..047db47 100644 --- a/tests/from_brain.rs +++ b/tests/from_brain.rs @@ -1578,6 +1578,85 @@ fn inst_1110() { test_display(&0b1110_1000_011_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 = vmpyweuh(R21:20, R7:6):rnd:sat }"); test_display(&0b1110_1000_011_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 = vmpywouh(R21:20, R7:6):rnd:sat }"); + test_display(&0b1110_1000_100_10100_11_000110_100_10110u32.to_le_bytes(), "{ R23:22 = vdmpy(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1000_100_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 = vmpyweh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1000_100_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 = vmpyeh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1000_100_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 = vmpywoh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1000_101_10100_11_000110_010_10110u32.to_le_bytes(), "{ R23:22 = vrmpywoh(R21:20, R7:6):<<1 }"); + test_display(&0b1110_1000_101_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 = vmpyweh(R21:20, R7:6):<<1:rnd:sat }"); + test_display(&0b1110_1000_101_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 = vcmpyr(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1000_101_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 = vmpywoh(R21:20, R7:6):<<1:rnd:sat }"); + test_display(&0b1110_1000_110_10100_11_000110_100_10110u32.to_le_bytes(), "{ R23:22 = vrmpywoh(R21:20, R7:6):<<1 }"); + test_display(&0b1110_1000_110_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 = vmpyweuh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1000_110_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 = vcmpyi(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1000_110_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 = vmpywouh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1000_111_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 = vmpyweuh(R21:20, R7:6):<<1:rnd:sat }"); + test_display(&0b1110_1000_111_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 = vmpywouh(R21:20, R7:6):<<1:rnd:sat }"); + + test_display(&0b1110_1001_000_10100_11_000110_001_10110u32.to_le_bytes(), "{ R22 = vradduh(R21:20, R7:6) }"); + test_display(&0b1110_1001_001_10100_11_000110_111_10110u32.to_le_bytes(), "{ R22 = vraddh(R21:20, R7:6) }"); + test_display(&0b1110_1001_000_10100_11_000110_100_10110u32.to_le_bytes(), "{ R22 = cmpyiw(R21:20, R7:6*):<<1:sat }"); + test_display(&0b1110_1001_001_10100_11_000110_000_10110u32.to_le_bytes(), "{ R22 = cmpyiw(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1001_010_10100_11_000110_000_10110u32.to_le_bytes(), "{ R22 = cmpyrw(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1001_011_10100_11_000110_000_10110u32.to_le_bytes(), "{ R22 = cmpyrw(R21:20, R7:6*):<<1:sat }"); + test_display(&0b1110_1001_101_10100_11_000110_110_10110u32.to_le_bytes(), "{ R22 = vrcmpys(R21:20, R7:6):<<1:rnd:sat:raw:hi }"); + test_display(&0b1110_1001_101_10100_11_000110_111_10110u32.to_le_bytes(), "{ R22 = vrcmpys(R21:20, R7:6):<<1:rnd:sat:raw:lo }"); + test_display(&0b1110_1001_100_10100_11_000110_100_10110u32.to_le_bytes(), "{ R22 = cmpyiw(R21:20, R7:6*):<<1:rnd:sat }"); + test_display(&0b1110_1001_101_10100_11_000110_000_10110u32.to_le_bytes(), "{ R22 = cmpyiw(R21:20, R7:6):<<1:rnd:sat }"); + test_display(&0b1110_1001_110_10100_11_000110_000_10110u32.to_le_bytes(), "{ R22 = cmpyrw(R21:20, R7:6):<<1:rnd:sat }"); + test_display(&0b1110_1001_111_10100_11_000110_000_10110u32.to_le_bytes(), "{ R22 = cmpyrw(R21:20, R7:6*):<<1:rnd:sat }"); + + test_display(&0b1110_1001_000_10100_11_000110_000_10110u32.to_le_bytes(), "{ R22 = vdmpy(R21:20, R7:6):rnd:sat }"); + test_display(&0b1110_1001_100_10100_11_000110_000_10110u32.to_le_bytes(), "{ R22 = vdmpy(R21:20, R7:6):<<1:rnd:sat }"); + + test_display(&0b1110_1010_000_10100_11_000110_010_10110u32.to_le_bytes(), "{ R23:22 += vrmpyh(R21:20, R7:6) }"); + test_display(&0b1110_1010_000_10100_11_000110_011_10110u32.to_le_bytes(), "{ R23:22 += dfmpylh(R21:20, R7:6) }"); + test_display(&0b1110_1010_001_10100_11_000110_001_10110u32.to_le_bytes(), "{ R23:22 += vdmpybsu(R21:20, R7:6):sat }"); + test_display(&0b1110_1010_001_10100_11_000110_010_10110u32.to_le_bytes(), "{ R23:22 += vmpyeh(R21:20, R7:6) }"); + test_display(&0b1110_1010_001_10100_11_000110_100_10110u32.to_le_bytes(), "{ R23:22 += vcmpyr(R21:20, R7:6):sat }"); + test_display(&0b1110_1010_010_10100_11_000110_001_10110u32.to_le_bytes(), "{ R23:22 += vraddub(R21:20, R7:6) }"); + test_display(&0b1110_1010_010_10100_11_000110_010_10110u32.to_le_bytes(), "{ R23:22 += vrsadub(R21:20, R7:6) }"); + test_display(&0b1110_1010_010_10100_11_000110_100_10110u32.to_le_bytes(), "{ R23:22 += vcmpyi(R21:20, R7:6):sat }"); + test_display(&0b1110_1010_010_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 += cmpyiw(R21:20, R7:6*) }"); + test_display(&0b1110_1010_011_10100_11_000110_010_10110u32.to_le_bytes(), "{ R23:22 += cmpyiw(R21:20, R7:6) }"); + + test_display(&0b1110_1010_100_10100_11_000110_001_10110u32.to_le_bytes(), "{ R23:22 += vrmpybu(R21:20, R7:6) }"); + test_display(&0b1110_1010_100_10100_11_000110_010_10110u32.to_le_bytes(), "{ R23:22 += cmpyrw(R21:20, R7:6) }"); + test_display(&0b1110_1010_100_10100_11_000110_011_10110u32.to_le_bytes(), "{ R23:22 += dfmpyhh(R21:20, R7:6) }"); + test_display(&0b1110_1010_101_10100_11_000110_001_10110u32.to_le_bytes(), "{ R23:22, P1 = vacsh(R21:20, R7:6) }"); + test_display(&0b1110_1010_101_10100_11_000110_100_10110u32.to_le_bytes(), "{ R23:22 += vrcmpys(R21:20, R7:6):<<1:sat:raw:hi }"); + + test_display(&0b1110_1010_110_10100_11_000110_001_10110u32.to_le_bytes(), "{ R23:22 += vrmpybsu(R21:20, R7:6) }"); + test_display(&0b1110_1010_110_10100_11_000110_010_10110u32.to_le_bytes(), "{ R23:22 += cmpyrw(R21:20, R7:6*) }"); + test_display(&0b1110_1010_111_10100_11_000110_001_10110u32.to_le_bytes(), "{ R23:22, P1 = vminub(R21:20, R7:6) }"); + test_display(&0b1110_1010_111_10100_11_000110_100_10110u32.to_le_bytes(), "{ R23:22 += vrcmpys(R21:20, R7:6):<<1:sat:raw:lo }"); + + test_display(&0b1110_1010_000_10100_11_000110_100_10110u32.to_le_bytes(), "{ R23:22 += vdmpy(R21:20, R7:6):sat }"); + test_display(&0b1110_1010_000_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 += vmpyweh(R21:20, R7:6):sat }"); + test_display(&0b1110_1010_000_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 += vmpyeh(R21:20, R7:6):sat }"); + test_display(&0b1110_1010_000_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 += vmpywoh(R21:20, R7:6):sat }"); + test_display(&0b1110_1010_001_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 += vmpyweh(R21:20, R7:6):rnd:sat }"); + test_display(&0b1110_1010_001_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 += vrmpyweh(R21:20, R7:6) }"); + test_display(&0b1110_1010_001_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 += vmpywoh(R21:20, R7:6):rnd:sat }"); + test_display(&0b1110_1010_010_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 += vmpyweuh(R21:20, R7:6):sat }"); + test_display(&0b1110_1010_010_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 += vmpywouh(R21:20, R7:6):sat }"); + test_display(&0b1110_1010_011_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 += vmpyweuh(R21:20, R7:6):rnd:sat }"); + test_display(&0b1110_1010_011_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 += vrmpywoh(R21:20, R7:6) }"); + test_display(&0b1110_1010_011_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 += vmpywouh(R21:20, R7:6):rnd:sat }"); + + test_display(&0b1110_1010_100_10100_11_000110_100_10110u32.to_le_bytes(), "{ R23:22 += vdmpy(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1010_100_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 += vmpyweh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1010_100_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 += vmpyeh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1010_100_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 += vmpywoh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1010_101_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 += vmpyweh(R21:20, R7:6):<<1:rnd:sat }"); + test_display(&0b1110_1010_101_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 += vrmpyweh(R21:20, R7:6):<<1 }"); + test_display(&0b1110_1010_101_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 += vmpywoh(R21:20, R7:6):<<1:rnd:sat }"); + test_display(&0b1110_1010_110_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 += vmpyweuh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1010_110_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 += vmpywouh(R21:20, R7:6):<<1:sat }"); + test_display(&0b1110_1010_111_10100_11_000110_101_10110u32.to_le_bytes(), "{ R23:22 += vmpyweuh(R21:20, R7:6):<<1:rnd:sat }"); + test_display(&0b1110_1010_111_10100_11_000110_110_10110u32.to_le_bytes(), "{ R23:22 += vrmpywoh(R21:20, R7:6):<<1 }"); + test_display(&0b1110_1010_111_10100_11_000110_111_10110u32.to_le_bytes(), "{ R23:22 += vmpywouh(R21:20, R7:6):<<1:rnd:sat }"); + test_invalid(&0b1110_1011_000_10100_11_000110_000_10110u32.to_le_bytes(), DecodeError::InvalidOpcode); test_display(&0b1110_1011_000_10100_11_000110_001_10110u32.to_le_bytes(), "{ R22 = sfsub(R20, R6) }"); test_display(&0b1110_1011_000_10100_11_000110_011_10110u32.to_le_bytes(), "{ R22 = sfadd(R20, R6) }"); -- cgit v1.1