rustfmt, then clippy -D warnings across the three new crates. Mechanical,
except three decisions that are stated rather than silently allowed:
* lzx.rs gets file-scoped needless_range_loop/explicit_counter_loop allows.
Index arithmetic IS the algorithm -- LZX is defined over symbol indices,
Huffman slots and window positions, and a decompressor that is merely
idiomatic is worth nothing if it is not bit-exact.
* sylpheed-xexdb gets crate-scoped allows for needless_range_loop (nine
sites index reg[r] where r is the PowerPC register number -- the index is
the meaning), too_many_arguments and type_complexity. This code arrived
whole from a retired repository; a refactor here would be an unreviewed
edit dressed as a lint fix.
* Everything else clippy asked for is FIXED, including all 14 doc-indent
sites, the let-else, and a Prepared type alias in the binary.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
42 lines
1.5 KiB
Rust
42 lines
1.5 KiB
Rust
//! 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 xenia-cpu --example decode_table_check -- <table.txt>
|
|
//! ```
|
|
//! where each line is `0xWORD name`.
|
|
use std::io::BufRead;
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let path = std::env::args()
|
|
.nth(1)
|
|
.ok_or("usage: decode_table_check <table>")?;
|
|
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(())
|
|
}
|