From 634d8ab6a1719e96e6025a55ffaaef3b7421497c Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:29:22 -0500 Subject: [PATCH 1/2] decomp(ezitext): pair current and best phonetic restoration (#1024) --- .../RVLMiddleware/eZiText/src/clib/zprepare.c | 6 +- .../zprepare-phonetic-restore-20261003.md | 92 +++++++++++++++++++ 2 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 tools/decomp-assist/zprepare-phonetic-restore-20261003.md diff --git a/libs/RVLMiddleware/eZiText/src/clib/zprepare.c b/libs/RVLMiddleware/eZiText/src/clib/zprepare.c index f337ec92..a67eb13b 100644 --- a/libs/RVLMiddleware/eZiText/src/clib/zprepare.c +++ b/libs/RVLMiddleware/eZiText/src/clib/zprepare.c @@ -280,10 +280,8 @@ savePhonetic: } if (buffers.phoneticInput[phoneticLength - 1] == 0xF360) { match->nCand--; - bestInitial = previousInitial; - bestFinal = previousFinal; - final = bestFinal; - initial = bestInitial; + bestInitial = initial = previousInitial; + bestFinal = final = previousFinal; goto savePhonetic; } if (match->nCand == 1) { diff --git a/tools/decomp-assist/zprepare-phonetic-restore-20261003.md b/tools/decomp-assist/zprepare-phonetic-restore-20261003.md new file mode 100644 index 00000000..42c5608c --- /dev/null +++ b/tools/decomp-assist/zprepare-phonetic-restore-20261003.md @@ -0,0 +1,92 @@ +# Zi8PrepareMatch paired phonetic restoration + +Base: `5d7760d341938a55e7613de85a3e1e5a3ba6bcb7`. +Leaf: `agent/bittle/prepare-phonetic-restore`. +Only `libs/RVLMiddleware/eZiText/src/clib/zprepare.c` and this log change. +The separate CHANSVm candidate and the one-key/PUD sources are untouched. + +## Retained source reconstruction + +On a failed Bopomofo parse ending in the separator, the previous initial and +final phonetics restore both the current and best outputs. The original loads +each previous halfword once and writes its two destinations immediately. +The source instead assigned the best outputs, then reloaded them to assign the +current outputs. + +Express the two paired restores directly: + +```c +bestInitial = initial = previousInitial; +bestFinal = final = previousFinal; +``` + +The original six instructions at `0x81485D24` through `0x81485D38` are now +byte-identical to the candidate's corresponding restore block. Those words +were checked against the original DOL, independently of relocation matching. +No new behavioral bug is claimed: this reconstructs the target's data flow. + +All six variables are distinct `ziWChar` halfword locals. There is no call, +volatile access, or other intervening operation between these assignments. +The two snapshots and all existing initialization remain present. Pairing the +stores introduces no alias-dependent result or new evaluation dependency. + +## Caller/callee audit + +- The original Pinyin call at `0x81485B68` resolves to `0x8147DDE8`, and the + Bopomofo call at `0x81485BEC` resolves to `0x8147E9F4`. Raw DOL branches agree + with extracted relocations. +- Pinyin receives the request's UTF-16 input, byte count, the two halfword + output arrays at match offsets `0x26`/`0x46`, byte completion at request + offset `0x22`, and halfword best outputs at match offsets `0x66`/`0x68`. +- Bopomofo receives the same four distinct halfword output locals whose + pointers and snapshots are traced in the restore block. Its count and + consumed-count result are bytes; the caller's halfword running length is + narrowed to a byte at the call exactly as in the target. +- No phonetic output-pointer, request-field width, or return-width correction + is warranted. The target's unconsumed component flag stores remain omitted; + no dummy state is introduced. +- Prior `ezi3.round2/3/4` and `fz15` logs were read. Earlier restore-order trials + did not express the paired assignments. Prior register, helper, and dummy-flag + investigations were not repeated. + +## Separate bounded trials + +| Trial | Function fuzzy | Source/target instructions | Matched data | Decision | +| --- | ---: | ---: | ---: | --- | +| Fresh baseline | 96.319145% | 939/940 | 8/68 | baseline | +| Paired restore | 96.802124% | 936/940 | 8/68 | retain | +| Joint index/phonetic-length loop increment | 96.313830% | 941/940 | 8/68 | reject | +| Both changes | 96.748940% | 937/940 | 8/68 | reject | + +The retained source removes two restore reloads and one redundant move elsewhere +in the function. Its 22 ordered call identities are unchanged. Register choices +and code layout still differ elsewhere; no exact match or linking gain is claimed. + +## Validation + +- Fresh configured 43U baseline and final `all_source`, report, and `ok` gates + pass with the assigned wibo wrapper and WIBO_SJIS_MISSING_IMPORTS=1. +- Full 1,027-unit report comparison: only zprepare changes, zero per-function + fuzzy/exact/code/data regressions. The unit still has 0/1 exact functions. +- Source-extracted baseline/candidate restore harness: 165,536 cases pass under + UBSan, covering every previous-initial halfword plus deterministic generated + states. All four outputs, both snapshots and adjacent guard halfwords agree + with an independent paired-output reference. This is a focused block test, + not a complete dictionary-engine or Wii runtime test. +- Pool before/after: identical, no strings. +- Literal advisory: no candidates/errors; its one function is skipped because + source and target extents differ. No literal coverage is claimed from that skip. +- `git diff --check`: PASS. +- DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d`. +- Final source SHA256: + `0df8e9d97309fe5aef8336de71b3ec7aebf549ddd024cb927fa3f93a3d3e8333`. +- Final object SHA256: + `bdd28374efdc511ad35278dbf1b2f88f553d36f0cba901af13a3105b41281b34`. + +Private local evidence: `/tmp/zprepare-contract-audit/` contains the fresh +baseline, separate trial sources/objects/reports, trials.py, test_restore.py, +focused test output, raw-address audit, pool/literal results and build logs. +No original binary/disassembly, header change, metadata, linking flags, assembly, +volatile forcing, register search, dummy storage or other-region build is included. + +GATE: validated partial source-data-flow gain; frozen for independent review. -- 2.49.1 From d79822629d1692febdd45fb100337412a6f0ca24 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:30:45 -0500 Subject: [PATCH 2/2] fix(odh): represent Huffman trees as halfword nodes --- src/system/odh.cpp | 16 ++-- .../allhands-odh-node-types.attempts.md | 79 +++++++++++++++++++ 2 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 tools/decomp-assist/allhands-odh-node-types.attempts.md diff --git a/src/system/odh.cpp b/src/system/odh.cpp index d1e303f0..d907c9e1 100644 --- a/src/system/odh.cpp +++ b/src/system/odh.cpp @@ -466,19 +466,21 @@ static const u8 gArDeconvPlttTbl[3072] = { 0x00, 0xD5, 0x00, 0xD6, 0x00, 0xD8, 0x00, 0xDA, 0x00, 0xDC, 0x00, 0xDE, 0x00, 0xDF, 0x00, 0xE1 }; -static const u32 gArDc_luminance_huffTable[] = { - 0x00018002, 0x00030000, 0xC003C004, 0x80050001, 0x00020003, 0x00040005, - 0x80010006, 0x80010007, 0x80010008, 0x80010009, 0x8001000A, 0x8001000B, +static const u16 gArDc_luminance_huffTable[] = { + 0x0001, 0x8002, 0x0003, 0x0000, 0xC003, 0xC004, 0x8005, 0x0001, + 0x0002, 0x0003, 0x0004, 0x0005, 0x8001, 0x0006, 0x8001, 0x0007, + 0x8001, 0x0008, 0x8001, 0x0009, 0x8001, 0x000A, 0x8001, 0x000B, }; -static const u32 gArDc_chrominance_huffTable[] = { - 0x0001C002, 0x80030000, 0x00010002, 0x80010003, 0x80010004, 0x80010005, - 0x80010006, 0x80010007, 0x80010008, 0x80010009, 0x8001000A, 0x8001000B, +static const u16 gArDc_chrominance_huffTable[] = { + 0x0001, 0xC002, 0x8003, 0x0000, 0x0001, 0x0002, 0x8001, 0x0003, + 0x8001, 0x0004, 0x8001, 0x0005, 0x8001, 0x0006, 0x8001, 0x0007, + 0x8001, 0x0008, 0x8001, 0x0009, 0x8001, 0x000A, 0x8001, 0x000B, }; #pragma pack(1) struct HufftreeData { - const u32* tables[4]; + const u16* tables[4]; char messages[0x1BB]; }; #pragma pack() diff --git a/tools/decomp-assist/allhands-odh-node-types.attempts.md b/tools/decomp-assist/allhands-odh-node-types.attempts.md new file mode 100644 index 00000000..dc4e56a0 --- /dev/null +++ b/tools/decomp-assist/allhands-odh-node-types.attempts.md @@ -0,0 +1,79 @@ +# ODH Huffman node-type reconstruction, 2026-10-03 UTC + +Base `a894ff5c`, branch `agent/bittle/odh-huffman-node-types`, 43U only. +Changed only the two tree declarations/initializers and their local pointer +record in `src/system/odh.cpp`, plus this log. No headers, public signatures, +metadata, linking flags, forced alignment or padding changed. + +## Evidence and source correction + +The decoder reads its tree entries and leaf categories with zero-extending +16-bit loads. Edges use the low 14 bits as relative halfword indices, while the +top two bits indicate terminal left/right branches. Leaves hold categories0..11. +The earlier source represented each pair of entries as one packed const u32 and +then accessed it through u16 pointers. HufftreeData likewise described the trees +as const u32 pointers, although every decoder use expects halfword entries. + +Both tables are now explicit const u16 arrays, each with 24 actual entries. +HufftreeData::tables holds const u16 pointers. This removes the mismatched u32 +object/u16 access representation, rather than changing the Huffman algorithm. +Every original word was split into its high and low halfwords in the target's +big-endian order; no value, tree edge or byte was added, removed or reordered. + +The decoder's existing u16** parameter, its exact mangled public symbol, the C +ODH entry points and every caller are unchanged. The existing caller casts retain +the established ABI; no decoder writes a tree entry. Component0 uses the luma +value tree, components1/2 the chroma value tree, and all use the existing luma +prefix tree for zero-run categories. Request initialization starts at byte16, +bit offset0; successful decoding commits normalized offsets0..7. + +## Read-only decoder audit + +Prior sol-low, sol-high and fz10 attempts were reviewed. The existing decoder is +306/306 instructions with register allocation differences. Four-byte lookahead, +big-endian word assembly, unsigned bit-buffer operations, predictor selection, +DC/AC sign reconstruction, zero-run writes, EOB, success-only cursor/bit-count +commit, and error-path partial coefficient/predictor writes agree with target. +No additional algorithmic or stream-boundary behavior was invented. + +Malformed overlong zero runs can exceed a nominal64-coefficient block in both +the source and original target; changing that behavior is outside this focused +type correction. Arbitrary table contents or invalid request states are likewise +not claimed to have acquired validation. + +## Verification + +- Each tree remains exactly48 bytes. Fresh source bytes, old packed-u32 bytes, + and original split-object payloads agree byte-for-byte. +- Exhaustive tree-path validation: all512 nine-bit luma prefixes and all2048 + eleven-bit chroma prefixes agree with independent canonical Huffman codes, + including each valid leaf and the depth-limit invalid path. +- Fresh baseline/candidate builds: all28 reported function instruction streams + are unchanged. Entire .text14964, .data459, .rodata5856 and .sdata2 40 bytes + are identical, with the same section alignments. Defined function/object + symbol names, bindings, types and sizes are unchanged. +- Decoder remains95.57189%,306/306; unit remains99.55462%; exact26/28 and code + 12876/14684; data6360/6360 (100%) and linking unchanged. No matching gain claimed. +- Pool: all10 strings identical to target. +- Literal audit:14 arguments across28 functions, no candidates, skips or errors. +- Full1027-unit report: zero exact-function/code/data/fuzzy regressions. +- Full43U build and build/43U/ok passed. DOL SHA1: + `26116613f624061ba99c8d1a299aaa6efa85670d`. + +A host harness compiles the actual production decoder body and the new u16 table +initializers with fixed-width types and strict aliasing enabled. It passes24000 +cases against an independent canonical-code bit reader:6657 successes and17343 +truncation/malformed-code failures. Coverage includes components0/1/2, starting +bit offsets0..7, positive/negative DC and AC values, zero runs, EOB, full blocks, +4-byte-lookahead boundaries, invalid tree codes and run signs, output canaries, +predictors and request-state commit. Malformed overlong zero runs are excluded; +whole-image/Wii runtime execution is not claimed. + +Private evidence: `/tmp/odh-node-types/` contains baseline/final reports and +source objects, tree-proof.log, pool/literal audits, full-build.log, +validate_decoder.py and decoder-tests.log. The earlier read-only decoder audit +is in `/tmp/odh-decoder-audit/`. No retail assembly or binary is committed or +uploaded. + +GATE: real halfword node types reconstructed, ABI and all compiled bytes/metrics +preserved, tree and decoder behavior verified. Frozen for parent validation. -- 2.49.1