From ca5ac04a65a4be2dd91d75dbf803e8abd14e9369 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 06:18:23 -0500 Subject: [PATCH 1/2] fix(ezitext): align Chinese table-address return contract (#1092) --- .../RVLMiddleware/eZiText/src/clib/zi8cgetc.c | 30 ++++---- ...chinese-table-address-contract-20261003.md | 73 +++++++++++++++++++ 2 files changed, 88 insertions(+), 15 deletions(-) create mode 100644 tools/decomp-assist/chinese-table-address-contract-20261003.md diff --git a/libs/RVLMiddleware/eZiText/src/clib/zi8cgetc.c b/libs/RVLMiddleware/eZiText/src/clib/zi8cgetc.c index 321eae0c..364a3ad4 100644 --- a/libs/RVLMiddleware/eZiText/src/clib/zi8cgetc.c +++ b/libs/RVLMiddleware/eZiText/src/clib/zi8cgetc.c @@ -133,7 +133,7 @@ typedef struct { ziU8 phonetics[11]; } ZiChineseRecord; -extern ziPtr Zi8GetTableAddress(ziU8 language, ziU8 table, ziPtr work); +extern ziU32 Zi8GetTableAddress(ziU8 language, ziU8 table, ziPtr work); extern ziU16 Zi8GetTableCount(ziU8 language, ziU8 table, ziPtr work); extern ziU8 Zi8IsDupWChar(ziWChar character, ziPtr work); extern ziU8 Zi8IsDupWordW(ziWChar* word, ziU8 length, ziPtr work); @@ -1336,7 +1336,7 @@ dictionary_search: Zi8GetFormatVersion(1, work) >= 8) { lastCharHigh = (request->currentWord[request->wordCharCount - 1] >> 8) & 0xFF; lastCharLow = request->currentWord[request->wordCharCount - 1]; - phoneticGroups = Zi8GetTableAddress(1, 28, work); + phoneticGroups = (ziU8*)Zi8GetTableAddress(1, 28, work); rangeCount = Zi8GetTableCount(1, 28, work); rangeIndex = 0; while (rangeIndex < rangeCount) { @@ -1384,7 +1384,7 @@ numeric_setup: default: ordinalCount = 0; break; } } - if (ordinalCount) ordinalTable = Zi8GetTableAddress(1, 29, work); + if (ordinalCount) ordinalTable = (ziU8*)Zi8GetTableAddress(1, 29, work); } if (!request->elementCount && (getMode == 7 || getMode == 8 || getMode == 9)) { resultFallback = 0; @@ -1451,7 +1451,7 @@ character_range_start: firstOrdinal = 0; rangeIndex = Zi8GetTableCount(1, 16, work); if (Zi8GetFormatVersion(1, work) >= 4 && rangeIndex && elements[0] != 0xEF00) { - phoneticGroups = Zi8GetTableAddress(1, 16, work); + phoneticGroups = (ziU8*)Zi8GetTableAddress(1, 16, work); rangeIndex = 0; rangeCount = 0; switch (phase) { @@ -1912,7 +1912,7 @@ cangjie_components: Zi8GetTableCount(1, 16, work) && elements[0] != 0xEF00 && getMode != 5) { rangeIndex = 0; rangeCount = 0; - phoneticGroups = Zi8GetTableAddress(1, 16, work); + phoneticGroups = (ziU8*)Zi8GetTableAddress(1, 16, work); switch (phase) { case 0: rangeIndex = 0; rangeCount = 2; phase = 1; break; case 1: @@ -2199,7 +2199,7 @@ phonetic_main: if (Zi8GetFormatVersion(1, work) >= 4) rangeCount = Zi8GetTableCount(1, 23, work); else rangeCount = 0; if (rangeCount && match.nCand == 2 && emitWords) { - frequencyCursor = Zi8GetTableAddress(1, 24, work); + frequencyCursor = (ziU8*)Zi8GetTableAddress(1, 24, work); frequencyEntry = frequencyCursor; duplicateIndex = Zi8GetTableCount(1, 24, work); if (!duplicateIndex) isFirstCandidate = 1; @@ -2446,7 +2446,7 @@ engine_finish: return totalResults; filtered_search: userIndex = Zi8GetTableCount(1, 31, work); - frequencyTable = Zi8GetTableAddress(1, 31, work); + frequencyTable = (ziU8*)Zi8GetTableAddress(1, 31, work); for (; userIndex; --userIndex) { index = frequencyTable[0] & 15; if (!(*frequencyTable++ & charset)) goto filtered_next; @@ -2645,20 +2645,20 @@ static int Zi8NewMatchPhonetic(ziGetParam* request, ZiChineseRecord* records, if ((mask & 7) == 7) { stopAfterTone = match & 7; } - phoneticOffsets = Zi8GetTableAddress(1, 13, work); - ordinalTable = Zi8GetTableAddress(1, 14, work); + phoneticOffsets = (ziU16*)Zi8GetTableAddress(1, 13, work); + ordinalTable = (ziU16*)Zi8GetTableAddress(1, 14, work); if (pinyin) { - phonetics = Zi8GetTableAddress(1, 3, work); + phonetics = (ziU8*)Zi8GetTableAddress(1, 3, work); phoneticCount = Zi8GetTableCount(1, 3, work); - phoneticGroups = Zi8GetTableAddress(1, 17, work); + phoneticGroups = (ziU8*)Zi8GetTableAddress(1, 17, work); groupCount = Zi8GetTableCount(1, 17, work); - candidateGroups = Zi8GetTableAddress(1, 18, work); + candidateGroups = (ziU8*)Zi8GetTableAddress(1, 18, work); } else { - phonetics = Zi8GetTableAddress(1, 4, work); + phonetics = (ziU8*)Zi8GetTableAddress(1, 4, work); phoneticCount = Zi8GetTableCount(1, 4, work); - phoneticGroups = Zi8GetTableAddress(1, 19, work); + phoneticGroups = (ziU8*)Zi8GetTableAddress(1, 19, work); groupCount = Zi8GetTableCount(1, 19, work); - candidateGroups = Zi8GetTableAddress(1, 20, work); + candidateGroups = (ziU8*)Zi8GetTableAddress(1, 20, work); } if (groupCount) { diff --git a/tools/decomp-assist/chinese-table-address-contract-20261003.md b/tools/decomp-assist/chinese-table-address-contract-20261003.md new file mode 100644 index 00000000..5596dbbe --- /dev/null +++ b/tools/decomp-assist/chinese-table-address-contract-20261003.md @@ -0,0 +1,73 @@ +# Chinese table-address contract, 2026-10-03 + +Base: `3dd12f63`, 43U. This is a source-contract consistency correction. +It has no exact, fuzzy, data or linking percentage gain. + +## Definition and caller evidence + +`zi8cgetc.c` locally declared `Zi8GetTableAddress` as returning `ziPtr`. +The exact definition in `zaddress.c:91` returns `ziU32`, forwarding +`Zi8GetTableData`. That helper's address selector explicitly converts the +computed dictionary pointer to `ziU32`. The local declaration therefore had +an incompatible cross-translation-unit function type, despite using the same +machine return register. + +The change corrects that one return declaration and adds fourteen explicit +conversions at previously implicit assignments: twelve `ziU8*` conversions +and two `ziU16*` conversions. The latter preserve the exact phonetic helper's +halfword `phoneticOffsets` and `ordinalTable`. Its halfword ordinal table is +distinct from the giant engine's byte ordinal table. The fourteen existing +byte-pointer conversions remain unchanged. These are exactly fifteen changed +source lines; no argument, condition, statement order, initializer, local type, +scope, header, callee, symbol metadata or linking flag changes. + +The project's typedefs make `ziU32` unsigned long and `ziPtr` void pointer. +A standalone compile-time assertion check using this unit's actual target +compiler and flags verifies `sizeof(ziU32) == sizeof(ziPtr) == 4`, +`sizeof(ziU16) == 2` and `sizeof(ziU8) == 1`. No host-width assumption is used. + +## Original ABI verification + +The original DOL SHA1 was verified independently. The wrapper at +`0x8145F3B0` calls `Zi8GetTableData` at `0x8145F1E0`, then leaves the full r3 +return unchanged through its epilogue. + +All 28 call relocations in this unit were checked against raw DOL branches: +20 in `zi8InternalGetZH` and eight in exact `Zi8NewMatchPhonetic`. Each first +return consumer stores or copies the entire address-sized r3 value. Those +consumer words also agree with the extracted original object. No byte or +halfword narrowing is introduced at the API boundary. + +This establishes return-width and flow compatibility, not a uniquely proven +original pointer-versus-integer return spelling. The correction follows the +existing exact definition and the already corrected one-key/zconvert caller +contracts. No missing machine operation or new dictionary behavior is claimed. + +## Prior-attempt distinction + +`fz21.attempts.md:605` records MAX gM17, a byte-pointer return experiment that +failed to compile at a legitimate halfword-table consumer. It did not try the +callee's integer-address contract with per-consumer typed conversions. +The earlier zconvert and one-key contract corrections did not touch this unit. + +## Fresh verification + +- Rebuilt the unchanged baseline in a fresh leaf using the approved + `wibo-release64/wibo` wrapper and `WIBO_SJIS_MISSING_IMPORTS=1` +- Corrected entire `zi8cgetc.o` is byte-identical to baseline, including all + code/data sections, symbols and relocations +- After the full default build, all 1,027 source-object SHA256 hashes and the + complete generated report remain equal to pinned main +- All five exact functions retain zero normalized instruction differences: + SetFindCand 50/50, GetNextPhonetic 31/31, PartialMatch 51/51, + NewMatchPhonetic 755/755, GetChineseCandidates 155/155 +- Unit unchanged: 5/8 exact, 4168/47816 exact code, 144/536 data, + 96.65468% fuzzy; the giant engine remains 96.27482% +- Pool 0/0, identical; literal audit analyzes all eight functions with no + candidates, errors or skips, and zero narrow-string arguments to compare +- Full default, explicit progress/report and `build/43U/ok` targets pass +- DOL SHA1 remains `26116613f624061ba99c8d1a299aaa6efa85670d` +- `git diff --check` passes + +No complete dictionary-engine or Wii runtime execution is claimed. Entire +object identity is the emitted-code neutrality evidence. -- 2.49.1 From ebf7e15d1fd9ae75c8fd40058c4bae605968e16f Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 06:18:48 -0500 Subject: [PATCH 2/2] decomp(jpeg): retain observed Lumi outer declaration order --- .../TMC_JPEG/src/buffer/idct_block_var.c | 24 +-- ...llhands-jpeg-lumi-outer-orders.attempts.md | 193 ++++++++++++++++++ 2 files changed, 205 insertions(+), 12 deletions(-) create mode 100644 tools/decomp-assist/allhands-jpeg-lumi-outer-orders.attempts.md diff --git a/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c b/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c index 5f0cddab..af7e8d29 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c @@ -28,36 +28,36 @@ static s32 scalingClampU8(s32 value) { void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigzag) { s32 tmp[64]; s32* dst; - s32 done; - s32 iter; + s32 d; + s32 t; s32 i; - s32 e; + s32 y; s32 b2; - s32 b3; + s32 b1; s32 b4; s32 b5; s32 b6; s32 b7; - s32 v; + s32 o; s32 m; s32 a; - s32 d; + s32 done; s32 z; - s32 o; + s32 v; s32 p; s32 p_part; - s32 t; + s32 m_part; s32 u; s32 r; s32 n; - s32 y; + s32 x; s32 x_factor; s32 z_factor; - s32 m_part; + s32 iter; s32 q; s32 w; - s32 x; - s32 b1; + s32 e; + s32 b3; r = (zigzag >> 4) * 8; dst = tmp; diff --git a/tools/decomp-assist/allhands-jpeg-lumi-outer-orders.attempts.md b/tools/decomp-assist/allhands-jpeg-lumi-outer-orders.attempts.md new file mode 100644 index 00000000..1e3f4be8 --- /dev/null +++ b/tools/decomp-assist/allhands-jpeg-lumi-outer-orders.attempts.md @@ -0,0 +1,193 @@ +# Lumi outer declarations after the retained inner order + +Base: `3dd12f63` (merged #1091), 43U only. +Leaf: `wii-jpeg-lumi-outer-orders`. +Branch: `agent/bittle/jpeg-lumi-outer-orders`. + +## Scope and new allocator context + +One authorized invocation of unchanged official `declsearch.py` permutes only +`TMCJPEGDEC_IdctBlock_Lumi` lines **31-60**, the 30 existing uninitialized `s32` +scalars from `done` through `b1`. The scratch array at line 29 and `dst` pointer +at line 30 remain fixed. The retained inner order from #1091 and every source +byte outside lines 31-60 remain fixed. There are no changes to initializers, +assignments, expressions, types, scopes, helpers, compiler flags or data. + +The outer declaration block is contiguous and contains no initializer. All +variables retain their original uses and assignments. This is a contextual +register-allocation search, not a claim of a semantic defect. The earlier +outer searches in round4/four-leaves-r9/r11 predate the retained #1091 inner +order. The 120-order #1091 experiment kept all outer declarations fixed. + +Baseline Lumi function text SHA256: +`8d3eca6f5cf34ade61942232c855dac36920db522111cbf40df15f9402819d2f`. +Baseline whole source SHA256: +`8e55f74add4f4da8bfab7a69dc1c5e6a13e467e58a8c3ba6a8bd23e93e5946f3`. +Authorized 30-line block SHA256, including newlines: +`f1ac9e00d55cd1d240a370083c6181f6673f43f52e46e91e05aacc0d8ced5469`. + +The fresh unchanged baseline was rebuilt using ordinary default Ninja and +explicit 43U `ok`; fresh official report confirms Lumi **83.657585%**, Col +**92.47577%**. The approved wrapper is `../toolchain/wibo-release64/wibo`, with +`WIBO_SJIS_MISSING_IMPORTS=1` and the existing cached-tool configure overrides. + +## Single bounded run and recording + +```sh +WIBO_SJIS_MISSING_IMPORTS=1 \ +NINJA=/tmp/jpeg-lumi-outer-orders/ninja-record.py \ +PYTHONPATH=../local-tools ../.venv/bin/python -u \ + tools/decomp-assist/declsearch.py \ + libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var \ + TMCJPEGDEC_IdctBlock_Lumi --lines 31 60 --max-evals 1250 +``` + +Official tool SHA256, unchanged before and after: +`9642fe689ee3a4d80236b5f790fdda83397214cd209c62ce07088b3f2b3726bb`. + +The recorder always invokes the real `.venv/bin/ninja` with the exact supplied +arguments and inherited environment. It saves the exact source before each +call, checks the authorized range, verifies source stability after compilation, +and saves the successful object. It records declaration order, source/object +hashes, timestamps, object mtime, compiler stdout/stderr and return status. +It does not replace, suppress, accelerate or alter compilation. + +There were **1,250 distinct evaluated orders**, plus the tool's separate final +restoration call: **1,251 actual MWCC object compilations**. Every call succeeded, +updated the object mtime and had stable source. There were zero failed, no-work +or unstable-source calls. The evaluated orders produced **542 distinct whole +objects**. The original baseline build and final chosen-source validation build +are separate from these recorded calls. + +The official internal trajectory was: + +```text +(40,187) -> (33,187) -> (32,187) -> (32,186) + -> (28,186) -> (28,185) -> (22,185) +``` + +The invocation **hit the 1,250-evaluation cap**. It did not establish a local +fixed point. There was no restart, continuation or second invocation. + +## Official scoring of frozen snapshots + +A private copy of actual `objdiff.json` preserves all diff settings, unit +metadata and mappings. Its units are copies of the real IDCT unit, with unique +names, frozen original-object `target_path` and each saved-object `base_path`. +Official `objdiff-cli report generate -p PRIVATE_DIR -o REPORT -f json` scores +all 1,251 snapshots without `--deduplicate` or swapping live source/objects. +First, a one-unit private baseline report was verified identical to the real +full-project baseline's functions, sections and unit measures. + +Only each candidate's raw function/unit scores are used; the artificial batch +aggregate is ignored. Every snapshot preserved Col's raw body and 92.47577% +fuzzy score, the same function set, exact-code/completion metrics, and empty +allocated non-code sections. All source snapshots preserve the exact authorized +block multiset and all other bytes. There are no non-fuzzy gate failures. + +Of the 1,250 evaluations, 632 were admissible (including baseline ties), and +618 strictly improved Lumi. The other 618 were rejected for unit fuzzy loss. +The unique official-fuzzy best is **call 1033**, at **86.15953%**. The tool-final +order scores **86.08171%**. Both have internal tool score `(22,185)`, illustrating +why the internal comparator alone cannot select the best official fuzzy result. +Call 1033 is retained, not the tool-final order. + +Retained order (all existing `s32` declarations): + +```text +d, t, i, y, b2, b1, b4, b5, b6, b7, o, m, a, done, z, +v, p, p_part, m_part, u, r, n, x, x_factor, z_factor, +iter, q, w, e, b3 +``` + +## Recorded neighborhood coverage + +For 30 distinct declaration lines, the official swap/move generators produce +435 distinct swaps and 841 distinct moves, with 29 overlapping adjacent swaps: +**1,247 distinct immediate neighbors**. Baseline plus that neighborhood is 1,248 +orders, but accepted improvements restart around new centers, so the cap does +not imply full coverage of the final neighborhood. + +Coverage below is computed by comparing the exact recorded evaluated orders +with those generators, rather than inferred from the evaluation count: + +- Tool-final order: **467/1,247** neighbors compiled; **780** uncompiled +- Retained official-fuzzy best: **2/1,247** neighbors compiled; **1,245** uncompiled + +These are coverage facts for this invocation, not claims about all historical +orders or a global optimum. Neither neighborhood is exhausted. No additional +search was run. + +## Fresh retained-source gates + +After choosing call 1033, rebuild its saved source with ordinary default Ninja, +then explicit `build/43U/ok`, and generate a fresh full official report. + +- Lumi: **83.657585% -> 86.15953%**, 1028/1028 bytes, 257/257 instructions +- Normalized positional ctxdiff: **187 -> 185** +- Col: **92.47577%**, 454/454 instructions; raw body unchanged +- Unit fuzzy: **89.28833% -> 90.19269%** +- Global fuzzy: **99.72798% -> 99.728836%** +- Unit exact functions/code remain **0/2, 0/2844**; this is a fuzzy gain +- All 1027 units and every function checked: zero regressions; only Lumi changes +- Fresh retained whole object equals saved snapshot 1033 byte-for-byte +- Fresh full-report IDCT functions/sections/measures equal the saved raw snapshot +- Original/baseline/candidate have zero allocated non-code bytes; pool identical +- Literal audit: two functions, zero candidates, errors or skips +- Ordinary default build/progress and explicit 43U `ok` pass +- DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d` +- `git diff --check` passes + +## Integer, dependency and alias validation + +Only scalar declaration order changes; all actual integer operation dependencies, +read/write ordering, fixed-point multiply/shift expressions and scopes are +unchanged. No addresses of these scalar locals escape. The scratch array, +pointer declarations and retained inner butterfly declarations are untouched. +The baseline, selected and original IDCT objects contain no FPU instructions. + +The existing independent scalar Lumi model was rerun against selected, +original and this run's freshly saved baseline objects: + +- **6,569 vectors / 19,707 object executions**, all exact-byte comparisons pass +- 1,280 row/column-mode, pitch and coefficient-pattern combinations +- 2,304 single-coefficient position/scaling cases +- 777 DC clipping threshold and adjacent-value cases +- 2,208 input/output overlap cases, every output byte inside the actual + 64-s32 input allocation; no stack alias or outside-object pointer +- All scalar intermediates checked within signed-32-bit range +- All non-stack memory and guards agree; **257/257** instruction coverage for + selected, original and saved baseline + +The repository JPEG differential suite also passes **9,456 paired cases** across +28 functions, including 704 Lumi and 704 Col cases with full own-body coverage; +GPR14-GPR31, stack pointer and LR are preserved. These are bounded integer +interpreter/model checks, not a formal proof or Wii hardware execution. The +alias cases are additional machine-level diagnostics, not an expanded API +contract. No tolerance-based arithmetic comparison is used. + +## Evidence and retained hashes + +`/tmp/jpeg-lumi-outer-orders/` contains `baseline.c/.o`, `original.o`, baseline +and final full reports, actual/private objdiff configs, `calls.jsonl`, all +`snapshots/0000.*` through `snapshots/1250.*`, `ninja-record.py`, +`search-output.txt`, `score_snapshots.py`, `all-snapshot-reports.json`, +`manifest.json`, `selection.json`, configure/default build logs, `verify.py`, +`verification.txt`, `candidate.ctx`, literal audit, `audit.py`, +`audit-results.json`, audit output and the 9,456-case differential log. + +Run the model and validation from the leaf with the shared Python environment: + +```sh +PYTHONPATH=../local-tools ../.venv/bin/python /tmp/jpeg-lumi-outer-orders/audit.py +PYTHONPATH=../local-tools ../.venv/bin/python /tmp/jpeg-lumi-outer-orders/verify.py +``` + +Baseline whole object: +`a2434d346c31d526b66073460fceb08924db12ce3eca7fef9847dc2285b0d2a8`. +Retained whole object: +`fe1ea30df17ae6263527744a5478eebfac008de2799226b312b80d8dc01e68ed`. +Retained whole source: +`65930a8c92d8acfd1cb6ee35715a0ff475b46b1abf649ba6ee3a3216cb51e087`. +Retained Lumi function text: +`250a74ae5b9b7f901bfe79dda1ae0dd0ae4ce29e1383d3e636c19ac00f7e4606`. -- 2.49.1