From 2c7fa341890d2e0cd08b74b003bb3150a2f04d33 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 03:40:44 -0500 Subject: [PATCH 1/2] decomp(jpeg): refine RGB565420 normal declaration order (#1081) --- .../src/texturecvtr/Texture_MCUtoRGB565.c | 8 +- ...hands-jpeg-rgb420-declarations.attempts.md | 183 ++++++++++++++++++ 2 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 tools/decomp-assist/allhands-jpeg-rgb420-declarations.attempts.md diff --git a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c index 9b66ad89..5f09b457 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c @@ -475,7 +475,7 @@ static void TMCJPEGDEC_converterYUV420toRGB565(TMCCJPEGDecWork* work, s32 x, s32 s32 width; s32 redOffset; s32 green; - u32 tileWidth; + s32 tileRow; u8* texture; s32 chromaSkip; s32 height; @@ -484,11 +484,11 @@ static void TMCJPEGDEC_converterYUV420toRGB565(TMCCJPEGDecWork* work, s32 x, s32 s32 crValue; s32 value; u8* cb; - s32 xEnd; - s32 column; u8* cr; + s32 column; + s32 xEnd; s32 greenOffset; - s32 tileRow; + u32 tileWidth; s32 cbValue; s32 lumaSkip; s32 blueOffset; diff --git a/tools/decomp-assist/allhands-jpeg-rgb420-declarations.attempts.md b/tools/decomp-assist/allhands-jpeg-rgb420-declarations.attempts.md new file mode 100644 index 00000000..44e54b37 --- /dev/null +++ b/tools/decomp-assist/allhands-jpeg-rgb420-declarations.attempts.md @@ -0,0 +1,183 @@ +# RGB565420 normal bounded declaration search + +Base: `f3f295c6`; branch: `agent/bittle/jpeg-rgb420-declarations`; 43U only. +The closed RGB565411, RGB565422 and RGB565420-edge contexts and all prior +branches remain preserved. No RGBA8 source was changed. + +## Context and eligibility + +Function: `TMCJPEGDEC_converterYUV420toRGB565` in +`libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c`. +The verified block at lines 474–497 contains exactly 24 existing, genuinely +used, uninitialized scalar/pointer declarations. The only retained change is +within this block. Every type, initializer, body expression, statement order, +scope, helper, clamp, packing operation and cursor step is unchanged. + +Entry function-text SHA256, definition through closing brace plus newline: +`cb8768325af825089c3ac634b533d972d902158c9481ccdee269ea08ccd80308`. +The full function is identical at `cdc22045`, `6ec48a1b`, `be7ded2f` and +`f3f295c6`. The baseline object was rebuilt and officially scored 94.60993. + +`jpeg-round4-attempts.md:749-762` records a 400-swap capped search with eleven +improvements ending at this score. That record does not establish exhaustion +of the final neighborhood. Later individual structural/template trials do not +establish an official fixed point. Only this normal converter was authorized +for the new run. + +## Single authorized run and stop + +The unchanged official tool was invoked exactly once: + +```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_MCUtoRGB565 \ + TMCJPEGDEC_converterYUV420toRGB565 --lines 474 497 --max-evals 1000 +``` + +Tool SHA256: +`9642fe689ee3a4d80236b5f790fdda83397214cd209c62ce07088b3f2b3726bb`. +Each evaluation used the ordinary Ninja/MWCC object build with the approved +wibo wrapper and `WIBO_SJIS_MISSING_IMPORTS=1`. + +Trajectory: `(6,86)` -> `(6,84)` -> `(6,81)`. +The tool stopped at 1,000 cached order evaluations, its authorized cap. +It did not establish a local fixed point. For 24 declarations, each fixed +order has 782 distinct immediate neighbors: 276 swaps + 529 distinct moves +minus 23 overlaps. The center changed twice and per-order coverage was not +logged, so exact coverage of the final neighborhood is unknown. No automatic +continuation, custom search or intermediate-order recovery was performed. + +## Fresh official result + +- Function fuzzy: 94.60993 -> 95.17731 +- Unit fuzzy: 96.753555 -> 96.805305 +- Instructions: 141/141; ctxdiff differences: 86 -> 81 +- Exact functions unchanged at 7/13; matched code unchanged at 2648/6184 bytes +- All twelve sibling function bodies byte-identical to the saved baseline +- All seven prior exact siblings retain exact-name objdiff 100, raw-byte + equality and ctxdiff zero +- No allocated non-code sections in baseline, candidate or original objects +- Global fuzzy on this base: 99.72492 -> 99.72503 +- All 1,027 units and every function score checked: no regression; only the + owned RGB565 unit changes + +This is partial fuzzy progress, not exact completion or a linking change. + +## Gates and differential behavior + +Full 43U build and `build/43U/ok` pass. DOL SHA1: +`26116613f624061ba99c8d1a299aaa6efa85670d`. +Pool checks before search and after the final build: identical and empty. +Literal audit: twelve functions analyzed, no candidates/errors; unchanged +setter skipped for unequal function sizes. `git diff --check` passes. + +The unchanged repository `jpeg_differential_audit.py` passes all 9,456 paired +calls. A separate scalar RGB565420 model passes 7,280 vectors against the +candidate, original and saved baseline, totaling 21,840 object executions: + +- 384 supported-scale/MCU-origin cases with random and constant samples +- 64 additional tiled-row and column-residue machine-level cases +- 6,400 saturation cases: every luminance byte crossed with signed Cb/Cr + values from {-128, -1, 0, 1, 127} +- 432 halfword-aligned input/output overlap cases whose stores remain entirely + within the actual 0x184-byte conversion buffer; descriptor/state stay separate + +The independent reference reads and writes the overlapping buffer sequentially. +Every non-stack byte, including guards, matches. The interpreter checks SP, LR +and GPR14–GPR31 restoration. All 141 instructions in each of the three objects +were exercised. Arithmetic is integer-only; there are no floating-point +operations or newly introduced overflow cases. Additional residue and overlap +cases are machine-level checks, not claims about permitted public API inputs. +These bounded tests are not formal equivalence proofs or Wii runtime tests; +the repository interpreter's existing unsupported-instruction/device limits +continue to apply. + +## Frozen evidence + +Final function SHA256: +`c8c40679d9d2fd3ce5841870fc4098c88a371a7e9082d41242ca6c8655507aee`. +Final entire source SHA256: +`4216dc6aa323936fe4cc747c05d37bdce37d9a7c3861021c47920d2cfc0e4b3d`. +Local evidence is preserved in `/tmp/jpeg-rgb420-declarations/`: baseline +source/object/report, candidate and final reports, search-output.txt, +candidate.ctx, full-build.log, literal-all.txt, verify.py, verification.txt, +differential.log, audit.py, audit-output.txt and audit-results.json. + +The focused scalar audit can be rerun from this worktree with: + +```sh +PYTHONPATH=../local-tools ../.venv/bin/python /tmp/jpeg-rgb420-declarations/audit.py +``` + +No remote writes, configuration/header changes or linking changes are retained. + +## Separately authorized continuation on latest base + +The initial candidate `b7e74104` was preserved on its original branch and +cherry-picked cleanly as `41f83f91` onto latest main `dc3eede8` in +`agent/bittle/jpeg-rgb420-fixedpoint`. The owned object and `build/43U/ok` target were rebuilt before +search. Both recorded source hashes and official function fuzzy 95.17731 were +reverified. The same 24 uninitialized declarations at lines 474–497 were used. + +Exactly one further unchanged official invocation used `--max-evals 1600`, +with all other command arguments and build settings as above. It reported: + +```text +start (6, 81) +best (6, 81) after 783 builds; source restored; best order was: +``` + +There were no improving steps. This run stopped at a local fixed point before +its cap: one baseline and all 782 distinct immediate single-swap/single-move +neighbors were evaluated. Because the center never changed, that coverage is +established directly by the tool's enumeration and 783-evaluation count. +The fixed point concerns the tool's structural/positional comparator; it does +not exhaust all 24! orders, plateau paths or the official fuzzy objective. +There were two separately authorized runs totaling 1,783 evaluations; overlap +between the runs was not logged, so this is not a unique-order total. + +The prior 95.17731 candidate remains the final source. Source and entire object +are byte-identical to the rebuilt continuation baseline. The initial regenerated report matched the entry report, but both contained a +stale unrelated NonMatching object; the corrected full-report comparison below +supersedes that interim result. All seven exact siblings retain raw +byte equality and ctxdiff zero; all twelve siblings remain unchanged. Pool +remains identical and empty, with zero allocated non-code bytes. Literal audit +again reports no candidates/errors. The DOL build target passes; DOL +SHA1 remains `26116613f624061ba99c8d1a299aaa6efa85670d`. +The source, compiler settings and converter instructions are unchanged from +the candidate that passed the 9,456-case paired audit and 7,280-vector pixel +model above; those behavior tests were not repeated for this neutral search. + +Continuation evidence is preserved in `/tmp/jpeg-rgb420-fixedpoint/`, including +baseline source/object/report, baseline-build.log, search-output.txt, +final-report.json, full-build.log, literal-all.txt, verify.py and +verification.txt. No third run, restart, further source change or remote write +was performed. The source gain and this evidence are frozen for parent review. + + +### Corrected full progress gate + +Before final handoff, the continuation report was found to retain the old +RGBA422 NonMatching object: its cached score was 87.72298 instead of the +merged 88.060814. `build/43U/ok` verifies the DOL but does not refresh every +NonMatching object. This did not affect the rebuilt owned RGB565 object, +source hashes, search scores, fixed-point count or pixel-model evidence. + +Ran the default `WIBO_SJIS_MISSING_IMPORTS=1 ../.venv/bin/ninja` progress build +and then `build/43U/ok`, and regenerated the official final report. All source +objects are now current. The RGB565 object is byte-identical to the committed +95.17731 continuation baseline, and the DOL hash still passes. Compared with +the freshly built main report at exact commit +`dc3eede8d3781762e566f72e2ae9aa0f49dbaf69`, only the RGB565 unit differs across +all 1,027 units; no function, exact/code/data or linking metric regresses. +RGBA422's merged 88.060814 result is preserved. The corrected latest-base +global fuzzy comparison is 99.72499 -> 99.72510. + +In the continuation evidence directory, `latest-main-report.json` is the +verified dc3eede8 comparison report, `final-report.json` is the corrected +full candidate report, and `full-progress-build.log` records the default +full build. `verify.py` and `verification.txt` use that current-main comparison. +The original `baseline-report.json`, `pre-progress-report.json` and +`pre-progress-verification.txt` are preserved as explicitly stale interim +evidence and must not be used for the latest-base aggregate comparison. -- 2.49.1 From e7114b8b34e40c43f840c02887c16cf256f4e0d8 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 03:40:55 -0500 Subject: [PATCH 2/2] decomp(jpeg): refine RGBA411 edge declaration order --- .../src/texturecvtr/Texture_MCUtoRGBA8.c | 10 +- ...gba411edge-declaration-context.attempts.md | 117 ++++++++++++++++++ 2 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 tools/decomp-assist/rgba411edge-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 16e6e319..e680c321 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c @@ -287,7 +287,7 @@ static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 static void TMCJPEGDEC_converterYUV411toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { s32 chromaSkip; s32 tileRow; - s32 xEnd; + s32 lumaSkip; u8* texture; TMCCJPEGDecState* state; u8* luminance; @@ -296,15 +296,15 @@ static void TMCJPEGDEC_converterYUV411toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 height; u8* cr; s32 column; - s32 lumaSkip; + s32 xEnd; s32 yEnd; s32 tileWidth; - u16* output; + s32 redOffset; s32 cbValue; s8 crValue; - s32 redOffset; - s32 greenOffset; + u16* output; s32 blueOffset; + s32 greenOffset; s32 blue; s32 red; s32 green; diff --git a/tools/decomp-assist/rgba411edge-declaration-context.attempts.md b/tools/decomp-assist/rgba411edge-declaration-context.attempts.md new file mode 100644 index 00000000..6422e90a --- /dev/null +++ b/tools/decomp-assist/rgba411edge-declaration-context.attempts.md @@ -0,0 +1,117 @@ +# RGBA411 edge final-expression declaration search + +Base `dc3eede8`; branch `agent/bittle/rgba411edge-declaration-context`; 43U only. +The previously validated RGBA422 branch and its artifacts remain frozen. +Target: `TMCJPEGDEC_converterYUV411toRGBA8edge` in +`libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c`. + +## Eligible context + +Only lines 288..310 were eligible: 23 existing, used, uninitialized scalar or +pointer declarations. The declaration `s8 crValue` and every other type were +preserved. No initializer, expression, scope, helper, statement, compilation +flag, or source byte outside the declaration block changed. + +The prior official search is logged in `fz20.attempts.md:759..820`: 250 +evaluations, capped after `(6,69) -> (4,56)`, fuzzy `90.80357% -> 93.83929%`. +Its retained source is `c7896c38`. Commit `786a2dd3` subsequently changed only +one overflow expression in this function: `(blue | red | green)` to +`(green | red | blue)`, yielding `93.88393%` (`fz20.attempts.md:1725..1730`). +Exact function comparison confirms no other change from that search-end body; +current function bytes are identical at `786a2dd3`, `e8241734`, and `dc3eede8`. +Later `tex1.attempts.md` records rejected structural trials and excludes +standalone declaration permutations. No final-context official fixed point +was recorded before this authorized run. + +Pinned SHA256 values: + +- Earlier search-end function: `3b0e7a0a09706d2d7654871dfb5d47d4d2c72d7c78a1801bcad4315932145a2b` +- Current baseline function: `f3f785894e5a5599289837cb775af58065dae32e8dd03cdcae0ccf38efa3cf8e` +- Baseline declaration block: `4ca4c6dbe945ee8cbba7c5d3c45ee13328ae89d2333df40d1314456cc759c09f` +- Baseline whole source: `c90f879594dac677d81bfc9524fc4653d847d2a4a9fc68f3999759f1ab440b12` +- Retained candidate function: `a47aed8fea3a4cafeb4a5128698b610323977fa3aaa476f372c71da51f3c5e56` +- Retained whole source: `ec53fd090e5d068e301192ad320ad471c1f933e9caf5c7f38233e813b1c380a4` + +## Single authorized run + +The unchanged official tool compiled every evaluated order normally: + +```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_converterYUV411toRGBA8edge --lines 288 310 --max-evals 1600 +``` + +- Actual evaluations: 1,227 distinct orders within this invocation +- Trajectory: `(4,56) -> (4,53) -> (4,52) -> (4,51)` +- Stop: natural local fixed point, before the 1,600-evaluation cap +- Final immediate neighborhood: 253 pair swaps + 484 distinct moves minus + 22 common neighbors = 715 unique neighboring orders, all scored without a + lexicographic structural/positional improvement +- No restart, continuation, source-body trial, or modified search tool + +The fixed point concerns this official tool's objective and immediate +neighborhood; it does not exhaust 23! permutations, plateau paths, combined +moves, other source forms, or the official fuzzy objective independently. + +## Retained result and gates + +- Official function fuzzy: `93.88393% -> 94.10714%` +- Unit fuzzy: `90.43238% -> 90.44754%` +- Global fuzzy: `99.72499% -> 99.725006%` +- Instructions `112/112`; ctxdiff differences `56 -> 51` +- Exact functions unchanged `2/13`; matched code unchanged `660/6596` +- All full-report exact/link/data totals unchanged; no 1,027-unit regressions +- All twelve sibling function bodies byte-identical to the saved baseline +- Both exact YUV400 siblings stay objdiff 100%, retail-byte-identical, and + ctxdiff zero (`76/76` and `89/89` instructions) +- Source block is precisely a permutation; all other source bytes identical +- Baseline and candidate objects freshly rebuilt; final object is identical + to the official tool's retained search-end object +- Baseline/candidate/original have no allocated non-code sections +- Pool identical and empty; all-functions literal audit has zero candidates + or errors, twelve functions analyzed, unchanged unequal-size setter skipped +- Full 43U build, `build/43U/ok`, 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, due to the +repository's existing incomplete code/data/link totals, unchanged here. + +## Independent edge-pixel and alias model + +The repository JPEG differential audit passes all 9,456 paired cases. +A separate scalar 4:1:1 edge model passes 11,828 vectors against candidate, +original, and saved baseline: 35,484 object executions. Input planes are +Y[8][32], Cb[8][8], Cr[8][8], at conversion-buffer offsets 4/260/324. Each +chroma sample serves four horizontal pixels, without chroma-row reuse. +All tested x origins satisfy the existing four-pixel alignment assertion. + +- 1,257 edge-size cases: every width 0..32/scale and height 0..8/scale for + scales 1, 2, 4, 8 at three output origins, including partial chroma groups +- 256 cases independently cover both dimension-selection branches, four + row/tile origins, and constant/random planes +- 6,400 saturation cases: every luminance byte crossed with Cb/Cr pairs from + `{-128,-1,0,1,127}`, with partial groups and multiple rows +- 3,915 halfword-aligned input/output overlaps wholly inside the actual + 0x184-byte conversion buffer; descriptors and state remain separate + +All 112 instructions are covered in each object. Every byte below the +interpreter's reserved stack region, including output guards, agrees with the +scalar model; GPR14..31, stack pointer, and LR are restored. The alias model +uses actual sequential reads/stores and group-local cached chroma. Aliasing +and additional row residues are machine-level checks, not a claim that the +public API permits them. Finite integer-interpreter tests are not formal +equivalence or Wii hardware validation. + +## Reproduction + +`build/43U/rgba411edge-declaration-context/` retains baseline hashes/source/ +object/report, `search.log`, rebuilt candidate/search-end objects, final report, +`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 worktree root using `PYTHONPATH=../local-tools ../.venv/bin/python`. +No remote writes, linking changes, or previously frozen branch edits. -- 2.49.1