//! Cross-check our decoder against xenia-canary's authoritative encoding table. //! //! Canary's `ppc_opcode_table_gen.cc` lists, for every opcode it knows, a //! representative instruction word with the operand fields zeroed. Feeding each //! word to our decoder must yield the matching opcode — anything else is a hole //! or a mis-decode in our tables. //! //! ```text //! cargo run --release -p sylpheed-ppc --example decode_table_check -- //! ``` //! where each line is `0xWORD name`. use std::io::BufRead; fn main() -> Result<(), Box> { let path = std::env::args() .nth(1) .ok_or("usage: decode_table_check ")?; let f = std::io::BufReader::new(std::fs::File::open(path)?); let (mut ok, mut bad, mut invalid) = (0u32, 0u32, 0u32); for line in f.lines() { let line = line?; let mut it = line.split_whitespace(); let (Some(w), Some(name)) = (it.next(), it.next()) else { continue; }; let word = u32::from_str_radix(w.trim_start_matches("0x"), 16)?; let d = sylpheed_ppc::decoder::decode(word, 0x8200_0000); let got = format!("{:?}", d.opcode); if got == name { ok += 1; } else if got == "Invalid" { invalid += 1; println!("MISSING {w} {name:<14} -> Invalid"); } else { bad += 1; println!("MISMATCH {w} {name:<14} -> {got}"); } } println!("\nmatched {ok}, mismatched {bad}, missing {invalid}"); Ok(()) }