From 9f39cd84cadbd9cfdf02651d248c1f51e0f9af12 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 04:21:12 -0500 Subject: [PATCH 1/2] decomp(jpeg): refine RGBA422 edge declaration order (#1087) --- .../src/texturecvtr/Texture_MCUtoRGBA8.c | 16 +-- ...gba422edge-declaration-context.attempts.md | 116 ++++++++++++++++++ 2 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 tools/decomp-assist/rgba422edge-declaration-context.attempts.md diff --git a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c index eb171016..a04ee309 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c @@ -441,21 +441,21 @@ static void TMCJPEGDEC_converterYUV422toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 } static void TMCJPEGDEC_converterYUV422toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { - s32 blue; + s32 chromaSkip; u16* output; - s32 xEnd; - u8* cr; + s32 lumaSkip; + s32 tileRow; TMCCJPEGDecState* state; - s32 tileWidth; + u8* texture; u8* luminance; s32 width; s32 height; u8* cb; - u8* texture; + u8* cr; s32 column; - s32 chromaSkip; + s32 xEnd; s32 yEnd; - s32 tileRow; + s32 tileWidth; s32 cbValue; s32 crValue; s32 redOffset; @@ -463,8 +463,8 @@ static void TMCJPEGDEC_converterYUV422toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 blueOffset; s32 value; s32 red; - s32 lumaSkip; s32 green; + s32 blue; luminance = work->convBuf + 4; cb = &work->convBuf[132]; diff --git a/tools/decomp-assist/rgba422edge-declaration-context.attempts.md b/tools/decomp-assist/rgba422edge-declaration-context.attempts.md new file mode 100644 index 00000000..7ee43875 --- /dev/null +++ b/tools/decomp-assist/rgba422edge-declaration-context.attempts.md @@ -0,0 +1,116 @@ +# RGBA422 edge final-expression declaration search + +Base `a2c008c4`; branch `agent/bittle/rgba422edge-declaration-context`; 43U only. +All previous RGBA branches/evidence remain frozen. Target: +`TMCJPEGDEC_converterYUV422toRGBA8edge` in +`libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c`. + +## Verified context + +Only lines 444..467 were eligible: 24 existing, used, uninitialized scalar or +pointer declarations. Every type, initializer, body expression, statement, +scope, helper, compilation flag, and source byte outside the block is unchanged. + +The earlier official search (`fz20.attempts.md:886..950`) capped at 250 +evaluations, ending `(6,68)` after starting `(12,84)`; its retained fuzzy was +90.04425%. The search-end function at `c7896c38` differs from the current +baseline only by the overflow test changed in `786a2dd3` from +`(blue | green | red)` to `(red | green | blue)`, producing 90.08849% +(`fz20.attempts.md:1692..1701`). Exact function comparison was repeated before +this run. No current-context official fixed point was recorded before it. + +Pinned SHA256 values: + +- Earlier search-end function: `ab286761736afb0a3b812b5f19878fea2fd47189126132af9342f52a2b7a0ed8` +- Baseline function: `65979211dfeff0f56a50370b739b3694c57a386f9f52a21b0d3eb780a764dbe2` +- Baseline declarations: `5d7f99140080df5b3f1d760f49b3b97259c613f08155b57c40c99af0a00557ce` +- Baseline source: `c35b810dd4c60332563f54f424cf3887ebdee99698cd51e8909d5bf5c298b490` +- Retained function: `ed89120c68826826bdf016e86abfdd149158f3df7b265d9cc85acb5767f3e622` +- Retained source: `d4651ae1f7dd68082c84008ecce8b12c8f9d1053bc09ec1c0694acbb114b9cba` + +## One authorized run + +Fresh baseline object/full build/report reproduced 90.08849%, 113/113 +instructions, and score `(6,68)`. The unchanged official tool was run once, +with ordinary compilation at every evaluation: + +```sh +WIBO_SJIS_MISSING_IMPORTS=1 NINJA=../.venv/bin/ninja \ + PYTHONPATH=../local-tools ../.venv/bin/python -u \ + tools/decomp-assist/declsearch.py \ + libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8 \ + TMCJPEGDEC_converterYUV422toRGBA8edge --lines 444 467 --max-evals 1600 +``` + +- Actual evaluations: 1,392 distinct orders within this invocation +- Trajectory: `(6,68) -> (6,65) -> (6,64) -> (6,61) -> (6,60) -> (6,59) + -> (6,55) -> (6,51)` +- Stop: natural local fixed point, before the 1,600-evaluation cap +- Final immediate neighborhood: 276 pair swaps + 529 distinct moves minus + 23 shared neighbors = 782 unique neighbors, all scored without improvement +- No restart, continuation, other-converter run, or modified search tool + +The fixed point is relative to the structural/positional lexicographic score, +not an exhaustive search of 24! permutations, plateau paths, combined moves, +other source forms, or the official fuzzy objective considered independently. + +## Strict retained gain and gates + +- Official function fuzzy: `90.08849% -> 91.9469%` +- Unit fuzzy: `90.45967% -> 90.58702%` +- Global fuzzy: `99.72663% -> 99.72691%` +- Instructions `113/113`; ctxdiff differences `68 -> 51` +- Exact functions unchanged `2/13`; matched code unchanged `660/6596` +- All 1,027-unit exact/link/data totals unchanged; zero report regressions +- All twelve sibling object bodies byte-identical to the saved baseline +- Both YUV400 siblings remain objdiff 100%, retail-byte exact, ctxdiff zero + (`76/76` and `89/89` instructions) +- The source block is exactly a permutation; all other source bytes identical +- Candidate object deleted and freshly rebuilt; identical to search-end object +- Baseline/candidate/original contain no allocated non-code sections +- Empty/identical pools; literal audit has zero candidates/errors, twelve + functions analyzed, unchanged unequal-size setter skipped +- Full default 43U build, explicit progress/report/`build/43U/ok` targets, + and `git diff --check` pass +- DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d` + +This is partial fuzzy progress, with no new exact function or linking gain. +The global completion checker remains `DECOMPLETE_FAIL`, exit 1, reflecting +existing repository-wide incomplete code/data/link totals, unchanged here. + +## Independent 4:2:2 edge and alias audit + +The repository JPEG differential audit passes all 9,456 paired cases. +A separate scalar 4:2:2 edge model passes 11,420 vectors against candidate, +original, and saved baseline: 34,260 object executions. Physical planes are +Y[8][16], Cb[8][8], Cr[8][8], at conversion-buffer offsets 4/132/196. Each chroma +sample serves two horizontal pixels, with fresh chroma every row. Scaled MCU +dimensions are 16/scale by 8/scale. All x origins satisfy the existing even-x +assertion; tiled x residue 2 is exercised. + +- 657 edge-size cases: every width 0..16/scale and height 0..8/scale for + scales 1, 2, 4, 8 at three origins, including empty blocks and odd widths +- 256 cases independently exercise both dimension-selection branches, + four row/tile origins, and constant/random planes +- 6,400 saturation cases cross all luminance bytes with signed Cb/Cr pairs + from `{-128,-1,0,1,127}`, using partial pairs and multiple rows +- 4,107 halfword-aligned overlaps lie wholly within the actual 0x184-byte + conversion allocation, with descriptors and state kept separate + +All 113 instructions are covered in each object. Every byte below the reserved +stack region, including guards, agrees with the scalar model. The interpreter +checks GPR14..31, stack pointer, and LR restoration. The alias oracle preserves +sequential reads/stores and pair-local chroma caching. Aliasing and additional +row residues are machine-level checks, not claims of public API validity. +These finite integer-interpreter tests are not formal equivalence or Wii +hardware validation. + +## Reproduction artifacts + +`build/43U/rgba422edge-declaration-context/` retains baseline hashes/source/ +object/report, `prior-search.txt`, `search.log`, search-end/candidate objects, +candidate/final reports, `candidate.ctx`, exact-sibling/pool/literal/build/ +status/completion results, `verify.py`, `verification.log`, `audit.py`, +`audit-output.txt`, `audit-results.json`, and `differential.log`. Run either +verification script from this root with `PYTHONPATH=../local-tools +../.venv/bin/python`. No remote writes or linking changes. -- 2.49.1 From dbb261192b5aa1b61042e4ab41278a83c002fc92 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 04:21:19 -0500 Subject: [PATCH 2/2] decomp(aes): select best exhaustive state declaration order --- libs/RevoEX/src/net/aes.c | 4 +- ...nds-aes-state-order-exhaustive.attempts.md | 149 ++++++++++++++++++ 2 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 tools/decomp-assist/allhands-aes-state-order-exhaustive.attempts.md diff --git a/libs/RevoEX/src/net/aes.c b/libs/RevoEX/src/net/aes.c index 8419b217..52aff7f0 100644 --- a/libs/RevoEX/src/net/aes.c +++ b/libs/RevoEX/src/net/aes.c @@ -198,10 +198,10 @@ void AESiEncryptBlock(AESContext* context, u32* output, const u32* input) { void AESiDecryptBlock(AESContext* context, u32* output, const u32* input) { u32 rounds=context->rounds; u32* key=context->keys; - u32 d; u32 b; - u32 c; u32 a; + u32 c; + u32 d; key += rounds*4; if (context->needsTransform) { u32 round; diff --git a/tools/decomp-assist/allhands-aes-state-order-exhaustive.attempts.md b/tools/decomp-assist/allhands-aes-state-order-exhaustive.attempts.md new file mode 100644 index 00000000..66ab7996 --- /dev/null +++ b/tools/decomp-assist/allhands-aes-state-order-exhaustive.attempts.md @@ -0,0 +1,149 @@ +# AES four-state declaration order: exhaustive official-fuzzy comparison + +Base `a2c008c4`; leaf `agent/bittle/aes-state-order-exhaustive`. The accepted +`ce3cbf5f` source is the baseline: decrypt76.70518%, existing state declaration +order d,b,c,a. The previous frozen candidate remains preserved. + +Only four existing uninitialized `u32` declarations are reordered to b,a,c,d. +All other source bytes, initializers, expressions, assignments, scopes, types, +helpers, tables, public APIs, configuration and linking status are unchanged. +This is a declaration-order matching gain, not new algorithmic behavior. + +## Why a complete comparison was needed + +The prior official search reached a local fixed point after17 evaluated orders, +optimizing `(structural difference, positional difference)` rather than official +objdiff fuzzy. Its saved log did not record intermediate orders. Before this +experiment, a read-only traversal reconstruction admitted three possible +17-order histories, so the original complete visited set was not recoverable +uniquely from saved artifacts alone. The remaining seven could not be reliably +named, and the prior intermediate orders had no official-fuzzy measurements. + +The authorized experiment therefore deliberately rebuilt all24 permutations. +The official search tool, compiler, options and cache behavior were untouched. +A separate private driver changed only lines201-204, invoked ordinary Ninja +compilation and the official objdiff report tool for every order, and saved +source/object/report snapshots plus a manifest. No compilation was skipped, +no surrogate score replaced objdiff, and no restart or extra dimension occurred. + +The fresh dbca baseline was rebuilt and measured first. The other23 orders were +then compiled once each. There are12 distinct whole-object hashes across the24 +orders. After selection, one additional ordinary object rebuild restored the +best source. Ninja independently records25 successful object rebuilds after the +saved baseline, matching24 evaluations plus the final selection rebuild. + +## Complete results + +Every row passed all preservation gates: every other unit's full report is +identical; all eight sibling functions retain their instruction streams and +resolved relocations; every existing exact function/code/data measure is +preserved; all allocated non-code bytes, extents and alignments are identical; +and source text outside the four declarations is unchanged. Each row has a +fresh official report, source snapshot/hash and object snapshot/hash in the +private manifest. Object hashes below are SHA256 of the entire compiled AES +object, not instruction-score hashes. + +| Order | Official decrypt fuzzy | Structural/raw | Preservation gates | Object SHA256 | +|---|---:|---:|---|---| +| dbca | 76.70518 | 60/205 | PASS | `9eaf814a28a1585d780efa84a36f8981711b95c64566f67cf99469154eefc970` | +| abcd | 72.30677 | 93/217 | PASS | `426958cfec4e8d48869177e56a9f9d8afed12af28934980d88918c8bd6d05177` | +| abdc | 70.972115 | 72/216 | PASS | `5adf70c02ada68e520d1c533339eb830e4c86227c99dba537113e4ea1d47bf1c` | +| acbd | 72.30677 | 93/217 | PASS | `426958cfec4e8d48869177e56a9f9d8afed12af28934980d88918c8bd6d05177` | +| acdb | 72.123505 | 93/217 | PASS | `f7779c0547ac63397ed0f8631cbcafeed598ca9f734e271eadb68568a396bb69` | +| adbc | 70.972115 | 72/216 | PASS | `5adf70c02ada68e520d1c533339eb830e4c86227c99dba537113e4ea1d47bf1c` | +| adcb | 76.525894 | 68/216 | PASS | `44f7dd4aea84e4d62c9bca2ba6c034c368ca48c1e8bb7497924124641f34c558` | +| bacd | 78.95618 | 68/215 | PASS | `1a37fcb561221b6b60fb66feaf06411cc02fafef101d705b60ce2c69a4379569` | +| badc | 74.99602 | 71/213 | PASS | `427ae222f6c756f3a525e53f7aba7cf232c9d509c80d37c0c87b3ad5ffe5e9e1` | +| bcad | 78.95618 | 68/215 | PASS | `1a37fcb561221b6b60fb66feaf06411cc02fafef101d705b60ce2c69a4379569` | +| bcda | 76.525894 | 78/211 | PASS | `57052da319d896c187a83017e6e31d69e7bc4fd0bda1f1cf8f4795aa8d838e3b` | +| bdac | 74.99602 | 71/213 | PASS | `427ae222f6c756f3a525e53f7aba7cf232c9d509c80d37c0c87b3ad5ffe5e9e1` | +| bdca | 78.876495 | 65/213 | PASS | `8398c78fc241ecfb72a89ad0b14fc9b71118dd9f64cca7bc071ee5730f2001ec` | +| cabd | 73.32271 | 70/214 | PASS | `79f077cea200aefb8fb66ae2d108fbd2ef2985e4977d0b5fd63b108b9cde5114` | +| cadb | 73.32271 | 70/214 | PASS | `79f077cea200aefb8fb66ae2d108fbd2ef2985e4977d0b5fd63b108b9cde5114` | +| cbad | 73.836655 | 63/216 | PASS | `7651aa61c79c62ebe0af0b750639552ba00079357cd9865b4dedf7b884271f9b` | +| cbda | 73.836655 | 63/216 | PASS | `7651aa61c79c62ebe0af0b750639552ba00079357cd9865b4dedf7b884271f9b` | +| cdab | 73.32271 | 70/214 | PASS | `79f077cea200aefb8fb66ae2d108fbd2ef2985e4977d0b5fd63b108b9cde5114` | +| cdba | 73.836655 | 63/216 | PASS | `7651aa61c79c62ebe0af0b750639552ba00079357cd9865b4dedf7b884271f9b` | +| dabc | 75.76892 | 61/214 | PASS | `e0190031dca922706310bbe3d26ffff12e9224a7f13442fd1ecad4f83a0cf416` | +| dacb | 75.76892 | 61/214 | PASS | `e0190031dca922706310bbe3d26ffff12e9224a7f13442fd1ecad4f83a0cf416` | +| dbac | 76.70518 | 60/205 | PASS | `9eaf814a28a1585d780efa84a36f8981711b95c64566f67cf99469154eefc970` | +| dcab | 75.76892 | 61/214 | PASS | `e0190031dca922706310bbe3d26ffff12e9224a7f13442fd1ecad4f83a0cf416` | +| dcba | 76.70518 | 60/205 | PASS | `9eaf814a28a1585d780efa84a36f8981711b95c64566f67cf99469154eefc970` | + +The maximum official fuzzy is **78.95618%**, shared by bacd and bcad, which +produce byte-identical objects. The first strictly improving maximum, bacd, +is retained. All24 orders are covered; this four-declaration space is now +exhausted for this exact expression/compiler context. + +Using the newly measured score table, a read-only replay of the unchanged +hill-climbing traversal reproduces the original trajectory and17-order count: +`abcd (93,217) -> bacd (68,215) -> dacb (61,214) -> dbca (60,205)`. +Thus the best official-fuzzy form had been the first improvement in the old +run, then was displaced by its structural-first objective. This replay uses +new exhaustive measurements; it is not claimed as recovery from old logs alone. + +## Final measures and gates + +- AESiDecryptBlock: **76.70518 ->78.95618%**,251/251 instructions. +- AESiEncryptBlock: **65.81013% unchanged**,158/158; entire function unchanged. +- AES unit fuzzy: **83.64971 ->84.47093%**. +- Exact functions **7/9**, exact code **1116/2752**, data **2800/2800**, unchanged. +- Full1027-unit baseline/final comparison: only AES changes, no existing exact, + code, data or per-function fuzzy regression in the retained result. +- Pool4/4 identical; literal audit covers nine functions/five arguments, with + no candidates, skips or errors. +- Fresh full43U baseline and final full43U builds pass using + `../toolchain/wibo-build/wibo` and `WIBO_SJIS_MISSING_IMPORTS=1`. +- Default `progress build/43U/report.json` and `build/43U/ok` pass. +- DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d`. +- `git diff --check` passes. No remote action or linking change. + +## Behavior and alias validation + +The production C is compiled unchanged for native tests with minimal PPC-type/ +OS shims and target-endian numeric words. Candidate and actual baseline each +pass2406 independent AES-128/192/256 known-answer/randomized CBC comparisons, +including in-place/separate buffers and incremental calls. The candidate also +passes2688 direct-block input/output overlaps at offsets-3..+3 words. Both +native validation paths run under UBSan with no recovery and no runtime error. + +An interpreter of actual source and original final-round instructions passes +4608 cases for both, against an independent packing/publication oracle. These +include separate output and eight placements overlapping/adjoining final key +words. The interleaved K0-load/O0-store through K3-load/O3-store event sequence +is preserved. Candidate decrypt's incoming state registers are r6/r0/r5/r10, +verified from actual input/key XORs and round-result assignments; its key cursor +is r9. Only that map was adapted from the existing independent interpreter. + +Immutable S-box load scheduling remains nonexact: source has5/13/16/16 table +loads before successive stores, versus target5/11/16/16. This does not change +the key-load/store alias order and is not hidden by the fuzzy gain. Key-overlap +cases remain diagnostics, not a new supported public API promise. No live Wii +runtime execution is claimed. + +## Reproduction and frozen evidence + +Private evidence directory: `/tmp/aes-state-order-exhaustive/`. It contains +`manifest.json` with every order/hash/score/gate,24 corresponding source/object/ +report snapshots, compiler logs, baseline/final reports, the enumeration driver, +known-answer/overlap/publication scripts and results, and full/default-progress/ +pool/ctxdiff/literal gates. Retail objects and disassembly remain private. +Do not rerun the exhausted enumeration. Read-only reproduction checks and tests: + +```sh +PYTHONPATH=../local-tools ../.venv/bin/python /tmp/aes-state-order-exhaustive/verify_exhaustive.py +python3 /tmp/aes-state-order-exhaustive/validate_aes.py +python3 /tmp/aes-state-order-exhaustive/test_input_overlap.py +PYTHONPATH=../local-tools ../.venv/bin/python /tmp/aes-state-order-exhaustive/final_publication_audit.py +``` + +Baseline source SHA256: +`29f201a50b18799eea47820c52ebdb26254e5ccdc2904c858ffffe71cea9f109`. +Final source SHA256: +`af7e472e1d862675b353679af97ff4f90115891d14eb9b327941995e56dae48c`. +Final whole-object SHA256: +`1a37fcb561221b6b60fb66feaf06411cc02fafef101d705b60ce2c69a4379569`. + +GATE PASS: strict official fuzzy gain, complete24-order coverage, all exact/ +code/data/source/alias/default-progress/43U/DOL gates preserved. Source frozen; +no further order experiment running or needed in this context. -- 2.49.1