From 3aa9daf94af1cc73396ededb99c9536eef8467b4 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 2 Oct 2026 17:22:10 -0500 Subject: [PATCH 1/4] decomp: emission gates for iplSDChannelTitle + MemoryCardManager decodes (#972) IPL_SD_CHANNEL_TITLE_CPP gates move inline members to declarations so the TU emits non-inlined calls like retail (same dedup-loss pattern as #834's vtable restoration): iplInterporation::get, math::VEC3 ctor, FaderSceneBase::initCalcNormal/calcCommonAfter, SceneBase::isReady/ isResetProcessDone/getParent/getChild/getNext/getPrev, NANDTask:: isFinished/checkData, Graphics::setOrthoTrans/setOrthoScale, ut::Rect/RuntimeTypeInfo. Verified vs main: iplSDChannelTitle 68/69 fns byte-exact (152B tail residual in iplSDChannelTitle_flushSaveBeforeExit), iplMemoryCardManager 18/26. Units stay NonMatching; documented walls in revisit.attempts.md. Co-authored-by: devin Co-authored-by: coah80 --- include/math/iplInterporation.h | 4 + include/math/iplMathTypes.h | 2 +- include/scene/iplFaderSceneBase.h | 8 ++ include/scene/iplSceneBase.h | 15 ++ include/system/iplNand.h | 5 + include/utility/iplGraphics.h | 5 + libs/NW4R/include/nw4r/ut/Rect.h | 4 +- libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h | 2 +- src/scene/memoryCard/iplMemoryCardManager.cpp | 5 +- .../sdChannelTitle/iplSDChannelTitle.cpp | 14 +- tools/decomp-assist/revisit.attempts.md | 130 ++++++++++++++++++ 11 files changed, 176 insertions(+), 18 deletions(-) create mode 100644 tools/decomp-assist/revisit.attempts.md diff --git a/include/math/iplInterporation.h b/include/math/iplInterporation.h index f19128bd..558a0a3f 100644 --- a/include/math/iplInterporation.h +++ b/include/math/iplInterporation.h @@ -163,6 +163,9 @@ namespace ipl { void init(const f32& start, const f32& end, f32 maxFrame, f32 startTangent, f32 endTangent, int playback = ANIM_TYPE_FORWARD, f32 speed = 1.0f); +#ifdef IPL_SD_CHANNEL_TITLE_CPP + f32 get() const; +#else f32 get() const { f32 var_f27 = mFrame; f32 var_f28 = 1.0f / mMaxFrame; @@ -181,6 +184,7 @@ namespace ipl { return r; } +#endif protected: f32 mStart; diff --git a/include/math/iplMathTypes.h b/include/math/iplMathTypes.h index fe2ea912..a9dadb38 100644 --- a/include/math/iplMathTypes.h +++ b/include/math/iplMathTypes.h @@ -103,7 +103,7 @@ namespace ipl { y = r.y; z = 0.0f; } -#if defined(IPL_ADDRESS_EDIT_CPP) || defined(IPL_SD_CHANNEL_SELECT_CPP) || defined(IPL_GC_WINDOW_CPP) +#if defined(IPL_ADDRESS_EDIT_CPP) || defined(IPL_SD_CHANNEL_SELECT_CPP) || defined(IPL_GC_WINDOW_CPP) || defined(IPL_SD_CHANNEL_TITLE_CPP) VEC3(f32 fx, f32 fy, f32 fz); #else VEC3(f32 fx, f32 fy, f32 fz) { diff --git a/include/scene/iplFaderSceneBase.h b/include/scene/iplFaderSceneBase.h index d841c0a7..65fc9338 100644 --- a/include/scene/iplFaderSceneBase.h +++ b/include/scene/iplFaderSceneBase.h @@ -31,8 +31,12 @@ namespace ipl { virtual void calc(); +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual void initCalcNormal(); +#else virtual void initCalcNormal() { } // 0x4C +#endif virtual void initCalcFadeout() { } // 0x50 @@ -49,8 +53,12 @@ namespace ipl { return FADER_SCN_NEXT; } // 0x60 +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual void calcCommonAfter(); +#else virtual void calcCommonAfter() { } // 0x64 +#endif int getSceneFadeState() { return mScnFadeState; diff --git a/include/scene/iplSceneBase.h b/include/scene/iplSceneBase.h index 05ca1e5e..37cd9919 100644 --- a/include/scene/iplSceneBase.h +++ b/include/scene/iplSceneBase.h @@ -62,7 +62,11 @@ namespace ipl { virtual ~Base(); /** @brief If the scene is ready */ +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual BOOL isReady() const; +#else virtual BOOL isReady() const { return FALSE; } +#endif /** @brief If the user can power off/reset the system */ #ifdef IPL_SD_CHANNEL_TITLE_CPP @@ -73,7 +77,11 @@ namespace ipl { /** @brief The scene running code when powering off/resetting the system */ virtual void startResetting() {} /** @brief If the scene has finished its powering off/resetting task */ +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual BOOL isResetProcessDone(); +#else virtual BOOL isResetProcessDone() { return TRUE; } +#endif /** @brief Prepare to create scene */ virtual void prepare() {} @@ -86,10 +94,17 @@ namespace ipl { /** @brief Destroy the scene and clear from memory */ virtual void destroy() {} +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual Base* getParent(); + virtual Base* getChild(); + virtual Base* getNext(); + virtual Base* getPrev(); +#else virtual Base* getParent() { return (Base*)mpParent; } virtual Base* getChild() { return (Base*)mpChild; } virtual Base* getNext() { return (Base*)mpNext; } virtual Base* getPrev() { return (Base*)mpPrev; } +#endif /** @brief Check if scene has been created.*/ bool isSceneCreated() const { return (mScnState & SCN_STATE_CREATED); } diff --git a/include/system/iplNand.h b/include/system/iplNand.h index ea0dc137..d18ce526 100644 --- a/include/system/iplNand.h +++ b/include/system/iplNand.h @@ -65,8 +65,13 @@ namespace ipl { /** @brief Writes the file contents. */ virtual void write(); // 0x10 +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual bool isFinished(); + virtual int checkData(); +#else virtual bool isFinished() { return mbDoneTask; } // 0x14 virtual int checkData() { return mResult; } // 0x18 +#endif virtual bool isFatalError(); // 0x1C u8* getBuffer() const { return mpBuffer; } diff --git a/include/utility/iplGraphics.h b/include/utility/iplGraphics.h index d2d26131..9cadb0d8 100644 --- a/include/utility/iplGraphics.h +++ b/include/utility/iplGraphics.h @@ -51,12 +51,17 @@ namespace ipl { mArg.mOrthoScale = scale; } +#ifdef IPL_SD_CHANNEL_TITLE_CPP + static void setOrthoTrans(const math::VEC3& translate); + static void setOrthoScale(const math::VEC2& scale); +#else static void setOrthoTrans(const math::VEC3& translate) { mArg.mOrthoTrans = translate; } static void setOrthoScale(const math::VEC2& scale) NO_INLINE { mArg.mOrthoScale.x = scale.x; mArg.mOrthoScale.y = scale.y; } +#endif private: static Arg mArg; diff --git a/libs/NW4R/include/nw4r/ut/Rect.h b/libs/NW4R/include/nw4r/ut/Rect.h index cf3c7b66..5332a4e1 100644 --- a/libs/NW4R/include/nw4r/ut/Rect.h +++ b/libs/NW4R/include/nw4r/ut/Rect.h @@ -9,7 +9,7 @@ namespace nw4r { namespace ut { class Rect { public: -#ifdef IPL_SOUND_RECT_OUT_OF_LINE +#if defined(IPL_SOUND_RECT_OUT_OF_LINE) || defined(IPL_SD_CHANNEL_TITLE_CPP) Rect(); #else Rect() : left(), top(), right(), bottom() {} @@ -20,7 +20,7 @@ namespace nw4r { Rect(f32 l, f32 t, f32 r, f32 b) : left(l), top(t), right(r), bottom(b) {} #endif -#if !defined(IPL_CONTROLLER_TRIVIAL_RECT_DTOR) && !defined(IPL_MEMORYCARD_BASE_CPP) +#if !defined(IPL_CONTROLLER_TRIVIAL_RECT_DTOR) && !defined(IPL_MEMORYCARD_BASE_CPP) && !defined(IPL_SD_CHANNEL_TITLE_CPP) ~Rect() {} #endif diff --git a/libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h b/libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h index 74b85650..25e83a47 100644 --- a/libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h +++ b/libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h @@ -37,7 +37,7 @@ namespace nw4r { } // namespace detail template -#if defined(IPL_BOARD_OBJECT_EXTERNAL_DYNAMIC_CAST) || defined(IPL_MEMORYCARD_BASE_CPP) +#if defined(IPL_BOARD_OBJECT_EXTERNAL_DYNAMIC_CAST) || defined(IPL_MEMORYCARD_BASE_CPP) || defined(IPL_SD_CHANNEL_TITLE_CPP) TDerived DynamicCast(TBase* pPtr); #else inline TDerived DynamicCast(TBase* pPtr) { diff --git a/src/scene/memoryCard/iplMemoryCardManager.cpp b/src/scene/memoryCard/iplMemoryCardManager.cpp index 5b74505d..f07c4fa7 100644 --- a/src/scene/memoryCard/iplMemoryCardManager.cpp +++ b/src/scene/memoryCard/iplMemoryCardManager.cpp @@ -237,10 +237,7 @@ bool MemoryCardManager::isIconValidate(u8 slot, s16 index) { bool MemoryCardManager::isBannerEnable(u8 slot, s16 index) { CardIcons* icons = reinterpret_cast(memorycard::getIconStateArray()); - u32 file = mFile[slot][index].fileNo; - memorycard::IconState* icon = &icons[slot][file]; - u8 enabled = icon->bannerEnable; - return enabled != 0; + return icons[slot][mFile[slot][index].fileNo].bannerEnable != 0; } void MemoryCardManager::update_icon_anm() { diff --git a/src/scene/sdChannelTitle/iplSDChannelTitle.cpp b/src/scene/sdChannelTitle/iplSDChannelTitle.cpp index 1a7dc893..12e54e22 100644 --- a/src/scene/sdChannelTitle/iplSDChannelTitle.cpp +++ b/src/scene/sdChannelTitle/iplSDChannelTitle.cpp @@ -3,6 +3,10 @@ #define IPL_SDMEMORY_DIALOG_STATE_ACCESSOR #define IPL_SDMEMORY_COMPLETION_PCT_ACCESSOR +#define IPL_CHANNEL_TITLE_NOVTABLE +#include "math/iplInterporation.h" +#undef IPL_CHANNEL_TITLE_NOVTABLE + #include "scene/sdChannelTitle/iplSDChannelTitle.h" #include "scene/sdChannelSelect/iplSDChannelSelect.h" #include "system/iplSystem.h" @@ -1554,15 +1558,5 @@ void SDChannelTitle::startResetting() { snd::getSystem()->resetAllSound(); } -extern "C" void iplSDChannelTitle_onTitleButtonEvent(SDTitleButtonEventHandler* handler, u32 component, - u32 event, const controller::Interface* controller) { - handler->onEventDerived(component, event, controller); -} - -extern "C" void iplSDChannelTitle_onTitlePaneEvent(SDTitlePaneEventHandler* handler, u32 component, - u32 event, const controller::Interface* controller) { - handler->onEvent(component, event, const_cast(controller)); -} - } } diff --git a/tools/decomp-assist/revisit.attempts.md b/tools/decomp-assist/revisit.attempts.md new file mode 100644 index 00000000..e30e4701 --- /dev/null +++ b/tools/decomp-assist/revisit.attempts.md @@ -0,0 +1,130 @@ +# revisit leaf — second-pass evidence (agent/w1007/revisit @ origin/main 29fe1efa) + +Scope: iplSDChannelTitle (99.98883), ut_ArchiveFontBase (98.52), lyt_window (99.76), +iplMemoryCardManager (97.88). Post-#834 (linkgap emit gates + .data object names). + +## iplSDChannelTitle — all gates landed + +Per-TU `IPL_SD_CHANNEL_TITLE_CPP` declared-only gates applied to: +RuntimeTypeInfo.h DynamicCast, iplMathTypes.h VEC3 3-arg ctor, GUIManager.h +(EventHandler setManager/setLatestEventCtrlNo/getLatestEventCtrlNo, +Component setTriggerTarget, PaneComponent setPane/getPane), iplGraphics.h +setOrthoTrans/setOrthoScale, iplSceneBase.h isReady/isResetProcessDone/getParent/ +getChild/getNext/getPrev, iplFaderSceneBase.h initCalcNormal/calcCommonAfter, +iplNand.h File::isFinished/checkData, iplInterporation.h HermiteIntp::get +(nested under IPL_CHANNEL_TITLE_NOVTABLE spec), Rect.h 0-arg ctor +(IPL_SOUND_RECT_OUT_OF_LINE gate), iplGuiManager.h ~PaneManager. +Deleted 2 unreferenced extern "C" trampolines (onTitleButtonEvent/onTitlePaneEvent) +orig lacks. Result: all data sections 100%; .text 99.98883. + +### VERIFIED WALL — dtor emission policy (decl-immune) +Residual .text gap = 2 unreferenced weak deleting-dtor bodies +(~FaderSceneBase 88B + ~FrameController 64B) + ~5 dangling no-reloc UNDs +(__vt__LangFile, __vt__SDButtonEventHandlerBase, __vt__FrameController, +mArg/typeInfo syms — symtab noise, no relocs). Orig's TU had these dtors +trivial/implicit: ~SDChannelTitle calls ~Base directly (28 insns), Rect +temporaries carry no dtor calls, so correct forms are `virtual ~X() {}` +inline or NO decl at all. Declaring them out-of-line adds real `bl` calls → +fuzzy dropped 99.98883→99.55799. Implicit/non-virtual variants still emit the +weak bodies AND slightly regress — front-end-level MWCC instantiation drag, +no decl form eliminates it. Remaining fn wall: flushSaveBeforeExit 98.59 — +&smArg materialization register choice (orig r3→scratch r4, mine r4/r5→recv-first); +8+ source forms all shift the home, never to r3. + +## ut_ArchiveFontBase — ConstructOpAnalyzeGLGR 92.09 (956B) + +20 normalized diffs, insns 116-147 of 239 — issue-order inside the +ready-set around the CalcOffsetSheetFlags/CalcSizeFlagSet scratch math. +Orig hoists lhz 0x1c (sheetGlyphCount) / lhz 0x24 (sheetCount) / lhz 0xe +(dataBlockCount) + lwz 0x4c(r20) into the marshal block. +FAILED variants: decl-order swap of the three u16s (identical 20 diffs — +scheduler ignores decl order); moving ctx->m* tail stores adjacent to the +u16 loads (regressed 20→108, whole-web rotation). Conclusion: pure list- +scheduling tie, same family as before. + +## lyt_window — DrawFrame 98.18 (1504B) + +376=376 insns. One callee-window permutation: orig numbers the static +flipInfos[] array base early (r21, first materialized at insn 36) pushing +arg webs to r27-r31; mine puts it deepest (r31), args r26-r30. Same web +count (12 callee webs r20-r31 both), identical prologue/epilogue; only the +allocator's numbering differs. Plus a repeated stfsx/fadds store-weave in +the 4 DRAW_QUAD_FOR_FRAME_1 corner blocks. +FAILED variants: scoping polPt/polSize inside the macro (385 insns, +worse); moving texSize decl after polPt/polSize (372 insns, worse). +NOTE: paired-single ops — capstone can't decode psq_*/ps_* insns, so +ndiff.py/disasm_fn.py truncate at the first one; use raw-word diffs. + +## iplMemoryCardManager — 8 sub-100 fns all decomposed + +- isMoveEnable/isCopyEnable (99.83), update_file_array (99.72), + getComment (98.94): 0 normalized diffs — pure regname webs. +- isBannerEnable (92.31, 26 insns, 7 diffs) + getBlocks (92.0, 25 insns, + 6 diffs): single diff = `addi r11,r1,0x20` restgpr-setup placement — + orig emits it at tail (after the full member-chain load), mine hoists + to slot 11. Folded-return variant (`return icons[slot][mFile..]` no + locals) emits identical code — scheduler-internal, decl-form insensitive. + Folded form kept (same output, terser). +- _create_icon (87.55) + create_banner (90.42): `(base+const)+var` + member-chain regroup — orig computes (&mFileCell + memberOffs) + + (slot*row + file*0x15C combined index) with `this+0x10EC`/`this+0x110C` + bases cached in callee regs reused across both GX_TF branches, and + rematerializes &cell.icon per call (`add r3,...` then `add r24,...` + post-bl) while mine pins it; marshal order `li r4,0` before `mr r3` + in orig. FAILED variants: `MCFileCell* cell = &mFileCell[slot][file]` + (90 insns — MWCC folded the pointer, worse); `mFileCell[0] + + slot*0x7F + file` flat-index (89 insns — aggressive CSE, worse). + Same documented mcard2 wall. + +All units stay NonMatching — no shims, no flips. Every residual is a +verified allocator/scheduler/emission-policy tie with source-form evidence. + +## Round 2 (post-#834 rebase @11c75ddb) — sdChannelTitle emit-parity probe + +Investigated per orchestrator hint whether the 152B weak-dtor + dangling-UND +residual was the same dedup-loss family as channelTitle's symbols.txt fix. +VERDICT: NOT a naming issue and NOT a flip blocker. + +- orig iplSDChannelTitle.o: ZERO weak FUNC syms. Mine emits 2 unreferenced + weak deleting-dtor bodies: `__dt__FaderSceneBase` (88B @0x1f4) + + `__dt__FrameController` (64B @0xb30), plus 3 zero-reloc UND vtable refs + (`__vt__FrameController`, `__vt__SDButtonEventHandlerBase`, `__vt__LangFile`). +- orig iplFaderSceneBase.o's own view: `~FaderSceneBase` is DECLARED-ONLY + (its `__dt__` is UND there, defined in another TU). +- Tried `__declspec(novtable)` on all 4 classes under + IPL_SD_CHANNEL_TITLE_CPP: removed the 3 dangling `__vt__` UNDs (correct + mechanism — orig stores only most-derived vt) but weak bodies persisted. +- Tried implicit-trivial dtor (removing decl): `__dt__FrameController` emit + STOPPED (64B gone), but `calc()` vtable slot shifted 0x0c→0x08 → + calcFadein/calcFadeout single-word diffs (`lwz r12,0x0c(r12)` vs 0x08) + → REVERTED everything. +- CRITICAL PROOF these bodies are harmless: main's iplChannelTitle.o + (unit fuzzy 100.0 post-#834) emits the IDENTICAL `__dt__FaderSceneBase` + 88B + `__dt__FrameController` 64B weak bodies that orig's .o lacks. + They are linker-stripped dead emission; objdiff fn-pairing ignores them. + => The 152B was never the blocker. Real residual = flushSaveBeforeExit + 98.59 only. + +## flushSaveBeforeExit — 6-diff → 2-diff minimum + +Window is the `sm` (System globals) base web: orig binds &sm to r3 and +loads +0x94→r4 (store), +0x28→r4 (heap arg), +0x94→r3 (recv); mine binds +r4 and marshals recv before arg. Variants: +- saveHeap decl hoisted above getSDPrevPage store: 2 diffs (base→r5, + +0x28 load moved early) — closer but not orig's order. +- `flushAsync(System::getMem2App())` inline: same 2 diffs, base→r4. +Residual = base-web home + marshal eval order — allocator tie. + +## GLGR — ready-set issue-order re-probes + +- def-move (sheetGlyphCount/dataBlockCount to tail): 20→99 diffs, REGRESSION. +- `u32 remWorkSpace = ctx->remWorkSpace()` hoist: 20→25, REGRESSION. +- stepSheetFlags after flagsSheetsOff (dependency-chain reorder): identical + 20 diffs — MWCC issue-order insensitive to stmt order here. Wall stands. + +## DrawFrame / MCManager re-verified + +DrawFrame 376=376: flipInfos base pinned r21(orig)/r31(mine) + stfsx weave +— callee-numbering tie unchanged. create_banner/_create_icon: `(base+const) ++var` regroup + recompute-vs-CSE (`add r3,r29,r25` remat per call in orig) +— same documented wall. -- 2.49.1 From f9358f6e466d66427c08a982e52e988e4e92613f Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 2 Oct 2026 17:26:43 -0500 Subject: [PATCH 2/4] Decode BS2Mach Run asm + nup dead-static fossil (stays NonMatching) (#973) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * decomp: BS2Mach Run asm + CoverBlock/state decodes; nup dead-static fossil - BS2Mach::Run: retail zeroes r0-r31 and installs a custom stack (__pformatter+640) before the dcbz/dcbf flush loop and tail jump — inexpressible in C, so asm with the exact retail sequence. - BS2StartGCGame: CoverBlock.state direct member read (orig inlined DVDGetCommandBlockStatus accessor). - BS2StateMachine: GamePartition!=0 polarity fold. - nup.cpp __nupOp: 'static u32 lo' dead static reproduces orig's second .sbss word (orig .sbss=8: rvThread$2389 + 4B dead static). Verified vs main: BS2Mach 25/29 fns byte-exact, nup 20/23 + .sbss 8=8. Units stay NonMatching. Full build + DOL sha1 verified. Co-authored-by: coah80 Co-Authored-By: wch * decomp: drop dead 'static u32 lo' padding from __nupOp Per review: the extra .sbss word is a padding object — no relocation references it, and nup data is already exact without it. Left unowned for the linking pass. Co-Authored-By: wch --------- Co-authored-by: devin Co-authored-by: coah80 --- src/BS2/BS2Mach.c | 73 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/src/BS2/BS2Mach.c b/src/BS2/BS2Mach.c index 23832473..3fb4a619 100644 --- a/src/BS2/BS2Mach.c +++ b/src/BS2/BS2Mach.c @@ -242,14 +242,64 @@ BOOL BS2IsDiagDisc() { return (u8)(*(u8 *)OSPhysicalToCached(OS_ADDR_BOOT_INFO) extern vu32 BS2VideoMode; extern vu32 __DVDLayoutFormat; -void Run(u32 entryPoint, void *start, u32 blockCount, u32 argument) { - u8 *block = start; - for (; blockCount != 0; --blockCount) { - __dcbz(block, 0); - __dcbf(block, 0); - block += 32; - } - ((void (*)(u32))entryPoint)(argument); +extern void __pformatter(void); + +asm void Run(u32 entryPoint, void *start, u32 blockCount, u32 argument) { + // clang-format off +#ifdef __MWERKS__ + nofralloc + + mtctr r5 + mtlr r3 + + li r0, 0 + li r2, 0 + li r3, 0 + li r5, 0 + li r7, 0 + li r8, 0 + li r9, 0 + li r10, 0 + li r11, 0 + li r12, 0 + li r13, 0 + li r14, 0 + li r15, 0 + li r16, 0 + li r17, 0 + li r18, 0 + li r19, 0 + li r20, 0 + li r21, 0 + li r22, 0 + li r23, 0 + li r24, 0 + li r25, 0 + li r26, 0 + li r27, 0 + li r28, 0 + li r29, 0 + li r30, 0 + li r31, 0 + + lis r1, __pformatter+640@h + ori r1, r1, (__pformatter+640)@l + li r6, 0 + + b Run_loop_entry +Run_loop: + dcbz r4, r0 + dcbf r4, r0 + addi r4, r4, 0x20 + bdnz Run_loop + b Run_done +Run_done: + li r4, 0 + blr +Run_loop_entry: + b Run_loop +#endif + // clang-format on } BOOL BS2GetLockedTitles(ESTitleId *pTitleIds, u32 *count) { @@ -803,7 +853,7 @@ void BS2StartGCGame() { OSTime time; StartingGame = TRUE; - while (DVDGetCommandBlockStatus(&CoverBlock) != DVD_STATE_IDLE) { + while (CoverBlock.state != DVD_STATE_IDLE) { } soundMode = SCGetSoundMode(); @@ -1796,11 +1846,12 @@ invalidRvlRegion: State = BS2_STT_RESET_SYSTEM; break; } - if (GamePartition == 0) { + if (GamePartition != 0) + State = BS2_STT_37; + else { State = BS2_STT_54; break; } - State = BS2_STT_37; case 0x25: if (BS2BootFromCache != 0) { BS2Report("Open partition from cache.dat\n"); -- 2.49.1 From d1c364269a2fc84dcc9efc349cc55e7d6122a547 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 2 Oct 2026 17:27:03 -0500 Subject: [PATCH 3/4] decomp: refine JPEG butterfly and color source structure --- .../TMC_JPEG/src/buffer/idct_block_var.c | 12 +- .../src/texturecvtr/Texture_MCUtoRGB565.c | 11 +- .../src/texturecvtr/Texture_MCUtoRGBA8.c | 8 +- .../decomp-assist/jpeg-remainder-attempts.md | 276 +++++++++++++++ .../jpeg-remainder-differential-results.txt | 29 ++ .../decomp-assist/jpeg_differential_audit.py | 319 ++++++++++++++++++ 6 files changed, 640 insertions(+), 15 deletions(-) create mode 100644 tools/decomp-assist/jpeg-remainder-attempts.md create mode 100644 tools/decomp-assist/jpeg-remainder-differential-results.txt create mode 100644 tools/decomp-assist/jpeg_differential_audit.py 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 02d0e046..e808fa22 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var.c @@ -92,18 +92,20 @@ void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigz dst[0] = val; } else { s32 oddLowSum; + s32 oddLowDifference; s32 oddHighSum; + s32 oddHighDifference; s32 dcValue; t = b2 - b6; oddLowSum = b5 + b3; - b5 = b5 - b3; + oddLowDifference = b5 - b3; oddHighSum = b1 + b7; - b1 = b1 - b7; + oddHighDifference = b1 - b7; u = b6 + b2; t = t * 0xB5 >> 8; x_factor = oddHighSum - oddLowSum; - z_factor = b5 + b1; + z_factor = oddLowDifference + oddHighDifference; dcValue = block[0]; a = dcValue - b4; x = x_factor * 0xB5 >> 8; @@ -113,14 +115,14 @@ void TMCJPEGDEC_IdctBlock_Lumi(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigz z = z_factor * 0x62 >> 8; w = d + u; y = d - u; - m_part = b1 * 0x14E >> 8; + m_part = oddHighDifference * 0x14E >> 8; e = a - t; m = m_part - z; oddLowSum += m; n = oddHighSum + oddLowSum; o = x + m; dst[0] = w + n; - p_part = b5 * 0x8B; + p_part = oddLowDifference * 0x8B; dst[7] = w - n; p_part >>= 8; dst[1] = v + o; diff --git a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c index c27f82e0..2d0a8e61 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c @@ -816,7 +816,6 @@ static void TMCJPEGDEC_converterYUV444toRGB565(TMCCJPEGDecWork* work, s32 x, s32 u8* luminance; u8* cb; u8* cr; - s32 value; s32 column; s32 xEnd; s32 cbValue; @@ -844,17 +843,17 @@ static void TMCJPEGDEC_converterYUV444toRGB565(TMCCJPEGDecWork* work, s32 x, s32 for (column = x; column < xEnd; column++) { cbValue = (s8)*cb++; crValue = (s8)*cr++; - value = *luminance++; - green = value + (-(cbValue * 88 + crValue * 183) >> 8); - red = value + ((crValue * 359) >> 8); - blue = value + ((cbValue * 454) >> 8); + red = *luminance++; + green = red + (-(cbValue * 88 + crValue * 183) >> 8); + blue = red + ((cbValue * 454) >> 8); + red = red + ((crValue * 359) >> 8); if ((blue | green | red) >> 8) { blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; green = green > 255 ? 255 : green < 0 ? 0 : green; red = red > 255 ? 255 : red < 0 ? 0 : red; } output[(column & 3) + (((column >> 2) + tileRow) << 4)] = - ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); + ((blue & 0xF8) >> 3) + (((red & 0xF8) << 8) + ((green & 0xFC) << 3)); } luminance += rowSkip; cb += rowSkip; diff --git a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c index 69d38cb7..993d7389 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8.c @@ -656,10 +656,10 @@ static void TMCJPEGDEC_converterYUV420toRGBA8edge(TMCCJPEGDecWork* work, s32 x, blueOffset = (cbValue * 454) >> 8; } { - s32 value = *luminance++; - s32 green = value + greenOffset; - s32 red = value + redOffset; - s32 blue = value + blueOffset; + s32 red = *luminance++; + s32 green = red + greenOffset; + s32 blue = red + blueOffset; + red = red + redOffset; if ((green | red | blue) >> 8) { blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; green = green > 255 ? 255 : green < 0 ? 0 : green; diff --git a/tools/decomp-assist/jpeg-remainder-attempts.md b/tools/decomp-assist/jpeg-remainder-attempts.md new file mode 100644 index 00000000..acc9c0c6 --- /dev/null +++ b/tools/decomp-assist/jpeg-remainder-attempts.md @@ -0,0 +1,276 @@ +# JPEG remainder: semantic audit and source-shape reconstruction + +Baseline: `449529d9`, branch `agent/bittle/allhands-jpeg-decompile`, 4.3U only. +No remote writes, header changes, configuration changes, linking changes, assembly, +volatile forcing, padding, or edits to the separately owned entropy decoder. + +## Result + +All 28 owned functions were already implemented. No semantic mismatch was found +in a bounded differential comparison of their current compiled PPC against their +original ELF function bodies. This is additional test evidence, not a formal +proof of equivalence and not a Wii runtime test. + +Three natural source-shape changes improved the report without a function-score +regression: + +- Luminance IDCT now uses explicit odd-coefficient sum/difference temporaries, + matching the existing chroma first-pass butterfly. Function fuzzy + 82.31518 -> 83.05058; 257/257 instructions, 187 ctxdiff differences remain +- RGB444 consumes the luminance temporary as the red channel and uses the + existing exact edge sibling's red/green packing association. Function fuzzy + 97.96703 -> 98.71429; 91/91 instructions, 13 ctxdiff differences remain +- RGBA420 edge consumes the luminance temporary as red after calculating the + other channels. Function fuzzy 87.4 -> 87.458336; 120/120 instructions, + 77 ctxdiff differences remain + +No new exact matches. This candidate is not an exact-matching or linking result. + +| Unit | Exact before -> after | Fuzzy before -> after | Allocated data | +| --- | --- | --- | --- | +| Texture_MCUtoRGBA8 | 2/13 -> 2/13 | 90.318985 -> 90.32323 | 0 bytes; 100% | +| Texture_MCUtoRGB565 | 6/13 -> 6/13 | 96.40103 -> 96.44502 | 0 bytes; 100% | +| idct_block_var | 0/2 -> 0/2 | 88.80309 -> 89.06892 | 0 bytes; 100% | + +All eight previously exact functions still have exact-name objdiff 100% and +ctxdiff zero differences. Each setter remains 169/170 instructions, with one +folded buffer-base address operation; the other 26 functions retain their +original instruction counts. Every owned function and both input objects were +checked for allocated non-code sections: none. Pool checks were run before tuning and after the final build; all three were +identical, with zero strings. + +The baseline comparison was regenerated by rebuilding saved unmodified versions +of the three owned sources, reporting them, then restoring/rebuilding the final +sources. All 28 function scores were compared; zero regressions. + +Full build: PASS. `git diff --check`: PASS. +DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d`. + +Commands used: + +```sh +python3 configure.py --version 43U --wrapper ../toolchain/wibo-build/wibo +WIBO_SJIS_MISSING_IMPORTS=1 ../.venv/bin/ninja +build/tools/objdiff-cli report generate -p . -o build/43U/report.json -f json +PYTHONPATH=../local-tools ../.venv/bin/python tools/decomp-assist/pool_diff.py +PYTHONPATH=../local-tools ../.venv/bin/python tools/decomp-assist/ctxdiff.py +../.venv/bin/python tools/decomp-assist/jpeg_differential_audit.py +sha1sum build/43U/main.dol +``` + +## Differential test scope and limitations + +The committed `jpeg_differential_audit.py` is a bounded integer PPC interpreter +and deterministic test generator. It reads the locally available source/original +ELF objects and does not distribute original executable bytes. Capstone and +pyelftools are required. Run it from the repository root after building the +three objects; do not run Python with assertions disabled. + +- 9,456 paired calls across all 28 functions, seed 449529 +- Normal and edge converters: scales 1, 2, 4, 8; multiple MCU origins; both + edge-dimension branches; zero, partial and full extents; constant and random + luminance/chroma bytes, including negative signed chroma and clipping +- Setters: all 256 component selectors and four supported IDCT sizes; + randomized 16-bit image dimensions; return values, converter identities and + non-stack side effects compared +- IDCT: all row extents 1..8 and column-mode representatives 1, 2, 3, 8; + DC-only, sparse and dense coefficients; positive/negative coefficients and + clipping-boundary DC values; pitches 8, 16, 32 +- Every non-stack byte is compared, including guard regions, along with setter + return values. Stack pointer, LR and GPR14..GPR31 restoration are checked +- Full instruction-address coverage was reached for all 20 non-grayscale + converter bodies and both IDCT functions. This does not mean exhaustive + branch/path/input coverage. Four grayscale bodies retain 19 unvisited + instructions each in saturation paths that follow an unsigned byte load; + each setter has one unvisited negative-selector branch instruction +- Function address relocations are normalized to deterministic symbol tokens, + with collision checks. Real linked addresses and integration are not tested +- Only the observed integer instruction subset is implemented. Unsupported + instructions/relocations/callees fail closed. No FPU, exceptions, cache/MMIO, + timing, alignment faults, XER behavior or complete condition-register model +- `memset` is modeled by its memory effects and ABI-permitted volatile-register + clobbers; its actual library machine code is not executed +- Inputs are bounded samples. Invalid pointers, zero scale, arbitrary invalid + IDCT descriptors, all 32-bit coefficient patterns, concurrency, real JPEG + streams and other units are not covered +- This custom interpreter is itself test tooling rather than a formally verified + CPU implementation. Official objdiff, ctxdiff and full-DOL checks remain the + matching/integration authority + +Exact run output is preserved in `jpeg-remainder-differential-results.txt`. + +## Attempts + +Only strictly improved candidates without other function regressions were kept. +No declaration-order permutation search was performed. Failed/equal candidates +were restored. The one temporary compile error in the luminance-consumption +script was a duplicate local declaration; it was corrected and no broken +candidate was retained. + +### type-trials + +```text +TMCJPEGDEC_converterYUV411toRGBA8 signed-chroma-pointers: 82.603300 -> 82.500000; restore +TMCJPEGDEC_converterYUV411toRGBA8 signed-chroma-coefficients: 82.603300 -> 82.603300; restore +TMCJPEGDEC_converterYUV411toRGBA8 signed-chroma-domain: 82.603300 -> 81.570250; restore +TMCJPEGDEC_converterYUV411toRGBA8edge signed-chroma-pointers: 93.883930 -> 91.964290; restore +TMCJPEGDEC_converterYUV411toRGBA8edge signed-chroma-coefficients: 93.883930 -> 93.750000; restore +TMCJPEGDEC_converterYUV411toRGBA8edge signed-chroma-domain: 93.883930 -> 92.187500; restore +TMCJPEGDEC_converterYUV422toRGBA8 signed-chroma-pointers: 87.722980 -> 87.722980; restore +TMCJPEGDEC_converterYUV422toRGBA8 signed-chroma-coefficients: 87.722980 -> 87.722980; restore +TMCJPEGDEC_converterYUV422toRGBA8 signed-chroma-domain: 87.722980 -> 87.722980; restore +TMCJPEGDEC_converterYUV422toRGBA8 byte-luminance: 87.722980 -> 87.689186; restore +TMCJPEGDEC_converterYUV422toRGBA8edge signed-chroma-pointers: 90.088490 -> 90.088490; restore +TMCJPEGDEC_converterYUV422toRGBA8edge signed-chroma-coefficients: 90.088490 -> 90.088490; restore +TMCJPEGDEC_converterYUV422toRGBA8edge signed-chroma-domain: 90.088490 -> 88.628320; restore +TMCJPEGDEC_converterYUV422toRGBA8edge byte-luminance: 90.088490 -> 90.088490; restore +TMCJPEGDEC_converterYUV420toRGBA8 signed-chroma-pointers: 89.405230 -> 89.176470; restore +TMCJPEGDEC_converterYUV420toRGBA8 signed-chroma-coefficients: 89.405230 -> 89.307190; restore +TMCJPEGDEC_converterYUV420toRGBA8 signed-chroma-domain: 89.405230 -> 86.464050; restore +TMCJPEGDEC_converterYUV420toRGBA8 byte-luminance: 89.405230 -> 87.379080; restore +TMCJPEGDEC_converterYUV420toRGBA8edge signed-chroma-pointers: 87.400000 -> 80.666664; restore +TMCJPEGDEC_converterYUV420toRGBA8edge signed-chroma-domain: 87.400000 -> 80.666664; restore +TMCJPEGDEC_converterYUV211toRGBA8 signed-chroma-pointers: 91.153850 -> 91.153850; restore +TMCJPEGDEC_converterYUV211toRGBA8 signed-chroma-coefficients: 91.153850 -> 91.153850; restore +TMCJPEGDEC_converterYUV211toRGBA8 signed-chroma-domain: 91.153850 -> 91.153850; restore +TMCJPEGDEC_converterYUV211toRGBA8 byte-luminance: 91.153850 -> 91.153850; restore +TMCJPEGDEC_converterYUV211toRGBA8edge signed-chroma-pointers: 92.000000 -> 91.869570; restore +TMCJPEGDEC_converterYUV211toRGBA8edge signed-chroma-coefficients: 92.000000 -> 91.869570; restore +TMCJPEGDEC_converterYUV211toRGBA8edge signed-chroma-domain: 92.000000 -> 91.869570; restore +TMCJPEGDEC_converterYUV444toRGBA8 signed-chroma-pointers: 90.670105 -> 90.515465; restore +TMCJPEGDEC_converterYUV444toRGBA8 signed-chroma-coefficients: 90.670105 -> 90.515465; restore +TMCJPEGDEC_converterYUV444toRGBA8 signed-chroma-domain: 90.670105 -> 90.618550; restore +TMCJPEGDEC_converterYUV444toRGBA8 byte-luminance: 90.670105 -> 90.670105; restore +TMCJPEGDEC_converterYUV444toRGBA8edge signed-chroma-pointers: 88.909090 -> 88.909090; restore +TMCJPEGDEC_converterYUV444toRGBA8edge signed-chroma-coefficients: 88.909090 -> 88.909090; restore +TMCJPEGDEC_converterYUV444toRGBA8edge signed-chroma-domain: 88.909090 -> 87.645454; restore +TMCJPEGDEC_converterYUV444toRGBA8edge byte-luminance: 88.909090 -> 88.909090; restore +TMCJPEGDEC_converterYUV411toRGB565 signed-chroma-pointers: 90.599075 -> 90.599075; restore +TMCJPEGDEC_converterYUV411toRGB565 signed-chroma-coefficients: 90.599075 -> 90.599075; restore +TMCJPEGDEC_converterYUV411toRGB565 signed-chroma-domain: 90.599075 -> 90.599075; restore +TMCJPEGDEC_converterYUV422toRGB565 signed-chroma-pointers: 96.691180 -> 96.691180; restore +TMCJPEGDEC_converterYUV422toRGB565 signed-chroma-coefficients: 96.691180 -> 96.691180; restore +TMCJPEGDEC_converterYUV422toRGB565 signed-chroma-domain: 96.691180 -> 96.691180; restore +TMCJPEGDEC_converterYUV420toRGB565 signed-chroma-pointers: 94.609930 -> 94.609930; restore +TMCJPEGDEC_converterYUV420toRGB565 signed-chroma-coefficients: 94.609930 -> 94.609930; restore +TMCJPEGDEC_converterYUV420toRGB565 signed-chroma-domain: 94.609930 -> 94.609930; restore +TMCJPEGDEC_converterYUV420toRGB565 byte-luminance: 94.609930 -> 92.907800; restore +TMCJPEGDEC_converterYUV444toRGB565 signed-chroma-pointers: 97.967030 -> 97.362640; restore +TMCJPEGDEC_converterYUV444toRGB565 signed-chroma-coefficients: 97.967030 -> 97.802200; restore +TMCJPEGDEC_converterYUV444toRGB565 signed-chroma-domain: 97.967030 -> 97.340660; restore +TMCJPEGDEC_converterYUV444toRGB565 byte-luminance: 97.967030 -> 91.373630; restore +``` + +### idct-trials + +```text +TMCJPEGDEC_IdctBlock_Lumi nested-odd-output-sum: 82.315180 -> 79.708170; restore +TMCJPEGDEC_IdctBlock_Lumi explicit-ac-or-tree: 82.315180 -> 74.984436; restore +TMCJPEGDEC_IdctBlock_Lumi ac-coefficients-direct-condition: 82.315180 -> 74.984436; restore +TMCJPEGDEC_IdctBlock_Lumi nested-even-output-sum: 82.315180 -> 82.315180; restore +TMCJPEGDEC_IdctBlock_Lumi direct-product-shifts: 82.315180 -> 82.315180; restore +TMCJPEGDEC_IdctBlock_Col nested-odd-output-sum: 92.475770 -> 87.907486; restore +TMCJPEGDEC_IdctBlock_Col explicit-ac-or-tree: 92.475770 -> 90.651985; restore +TMCJPEGDEC_IdctBlock_Col ac-coefficients-direct-condition: 92.475770 -> 90.651985; restore +TMCJPEGDEC_IdctBlock_Col nested-even-output-sum: 92.475770 -> 92.475770; restore +TMCJPEGDEC_IdctBlock_Col direct-product-shifts: 92.475770 -> 92.475770; restore +``` + +### packing-trials + +```text +TMCJPEGDEC_converterYUV411toRGBA8 explicit-channel-clamp-branches: 82.603300 -> 61.962810; restore +TMCJPEGDEC_converterYUV411toRGBA8 structured-nonnegative-clamp: 82.603300 -> 68.442150; restore +TMCJPEGDEC_converterYUV411toRGBA8edge explicit-channel-clamp-branches: 93.883930 -> 80.008930; restore +TMCJPEGDEC_converterYUV411toRGBA8edge structured-nonnegative-clamp: 93.883930 -> 85.714290; restore +TMCJPEGDEC_converterYUV422toRGBA8 explicit-channel-clamp-branches: 87.722980 -> 71.222980; restore +TMCJPEGDEC_converterYUV422toRGBA8 structured-nonnegative-clamp: 87.722980 -> 75.533780; restore +TMCJPEGDEC_converterYUV422toRGBA8edge explicit-channel-clamp-branches: 90.088490 -> 76.097340; restore +TMCJPEGDEC_converterYUV422toRGBA8edge structured-nonnegative-clamp: 90.088490 -> 82.123890; restore +TMCJPEGDEC_converterYUV420toRGBA8 explicit-channel-clamp-branches: 89.405230 -> 73.372550; restore +TMCJPEGDEC_converterYUV420toRGBA8 structured-nonnegative-clamp: 89.405230 -> 76.797386; restore +TMCJPEGDEC_converterYUV420toRGBA8edge explicit-channel-clamp-branches: 87.400000 -> 77.841670; restore +TMCJPEGDEC_converterYUV420toRGBA8edge structured-nonnegative-clamp: 87.400000 -> 82.400000; restore +TMCJPEGDEC_converterYUV211toRGBA8 explicit-channel-clamp-branches: 91.153850 -> 74.701920; restore +TMCJPEGDEC_converterYUV211toRGBA8 structured-nonnegative-clamp: 91.153850 -> 82.211540; restore +TMCJPEGDEC_converterYUV211toRGBA8edge explicit-channel-clamp-branches: 92.000000 -> 77.730440; restore +TMCJPEGDEC_converterYUV211toRGBA8edge structured-nonnegative-clamp: 92.000000 -> 84.043480; restore +TMCJPEGDEC_converterYUV444toRGBA8 explicit-channel-clamp-branches: 90.670105 -> 73.030930; restore +TMCJPEGDEC_converterYUV444toRGBA8 structured-nonnegative-clamp: 90.670105 -> 81.082470; restore +TMCJPEGDEC_converterYUV444toRGBA8edge explicit-channel-clamp-branches: 88.909090 -> 75.463640; restore +TMCJPEGDEC_converterYUV444toRGBA8edge structured-nonnegative-clamp: 88.909090 -> 81.000000; restore +TMCJPEGDEC_converterYUV411toRGB565 normalize-packed-channels: 90.599075 -> 87.004610; restore +TMCJPEGDEC_converterYUV411toRGB565 group-red-green-packing: 90.599075 -> 88.755760; restore +TMCJPEGDEC_converterYUV411toRGB565 pack-before-output-address: 90.599075 -> 90.599075; restore +TMCJPEGDEC_converterYUV411toRGB565 explicit-channel-clamp-branches: 90.599075 -> 59.511520; restore +TMCJPEGDEC_converterYUV411toRGB565 structured-nonnegative-clamp: 90.599075 -> 71.640560; restore +TMCJPEGDEC_converterYUV411toRGB565edge normalize-packed-channels: 95.377360 -> 93.820755; restore +TMCJPEGDEC_converterYUV411toRGB565edge group-red-green-packing: 95.377360 -> 93.613205; restore +TMCJPEGDEC_converterYUV411toRGB565edge pack-before-output-address: 95.377360 -> 95.377360; restore +TMCJPEGDEC_converterYUV411toRGB565edge explicit-channel-clamp-branches: 95.377360 -> 79.801890; restore +TMCJPEGDEC_converterYUV411toRGB565edge structured-nonnegative-clamp: 95.377360 -> 86.179245; restore +TMCJPEGDEC_converterYUV422toRGB565 explicit-channel-clamp-branches: 96.691180 -> 78.507355; restore +TMCJPEGDEC_converterYUV422toRGB565 structured-nonnegative-clamp: 96.691180 -> 79.044120; restore +TMCJPEGDEC_converterYUV420toRGB565 normalize-packed-channels: 94.609930 -> 90.248230; restore +TMCJPEGDEC_converterYUV420toRGB565 group-red-green-packing: 94.609930 -> 91.560290; restore +TMCJPEGDEC_converterYUV420toRGB565 pack-before-output-address: 94.609930 -> 94.609930; restore +TMCJPEGDEC_converterYUV420toRGB565 explicit-channel-clamp-branches: 94.609930 -> 73.127660; restore +TMCJPEGDEC_converterYUV420toRGB565 structured-nonnegative-clamp: 94.609930 -> 76.751770; restore +TMCJPEGDEC_converterYUV420toRGB565edge normalize-packed-channels: 94.692986 -> 89.912280; restore +TMCJPEGDEC_converterYUV420toRGB565edge group-red-green-packing: 94.692986 -> 91.798250; restore +TMCJPEGDEC_converterYUV420toRGB565edge pack-before-output-address: 94.692986 -> 94.692986; restore +TMCJPEGDEC_converterYUV420toRGB565edge explicit-channel-clamp-branches: 94.692986 -> 81.894740; restore +TMCJPEGDEC_converterYUV420toRGB565edge structured-nonnegative-clamp: 94.692986 -> 86.315790; restore +TMCJPEGDEC_converterYUV444toRGB565 normalize-packed-channels: 97.967030 -> 96.648350; restore +TMCJPEGDEC_converterYUV444toRGB565 group-red-green-packing: 97.967030 -> 98.681320; RETAIN +TMCJPEGDEC_converterYUV444toRGB565 explicit-channel-clamp-branches: 98.681320 -> 85.120880; restore +TMCJPEGDEC_converterYUV444toRGB565 structured-nonnegative-clamp: 98.681320 -> 82.802200; restore +``` + +### control-trials + +```text +structured-col-low-mode-first: {'TMCJPEGDEC_IdctBlock_Lumi': 82.31518, 'TMCJPEGDEC_IdctBlock_Col': 92.47577} -> {'TMCJPEGDEC_IdctBlock_Lumi': 82.31518, 'TMCJPEGDEC_IdctBlock_Col': 92.47577}; restore +structured-col-high-mode-first: {'TMCJPEGDEC_IdctBlock_Lumi': 82.31518, 'TMCJPEGDEC_IdctBlock_Col': 92.47577} -> {'TMCJPEGDEC_IdctBlock_Lumi': 82.31518, 'TMCJPEGDEC_IdctBlock_Col': 50.55066}; restore +shared-full-row-butterfly: {'TMCJPEGDEC_IdctBlock_Lumi': 82.31518, 'TMCJPEGDEC_IdctBlock_Col': 92.47577} -> {'TMCJPEGDEC_IdctBlock_Lumi': 83.05058, 'TMCJPEGDEC_IdctBlock_Col': 92.47577}; RETAIN +``` + +### luma-reuse-trials + +```text +TMCJPEGDEC_converterYUV422toRGBA8edge consume-luminance-as-blue: 90.088490 -> 90.088490; restore +TMCJPEGDEC_converterYUV422toRGBA8edge consume-luminance-as-red: 90.088490 -> 89.955750; restore +TMCJPEGDEC_converterYUV422toRGBA8edge consume-luminance-as-green: 90.088490 -> 90.088490; restore +TMCJPEGDEC_converterYUV420toRGBA8edge consume-luminance-as-blue: 87.400000 -> 87.400000; restore +TMCJPEGDEC_converterYUV420toRGBA8edge consume-luminance-as-red: 87.400000 -> 87.458336; RETAIN +TMCJPEGDEC_converterYUV211toRGBA8 consume-luminance-as-blue: 91.153850 -> 91.153850; restore +TMCJPEGDEC_converterYUV211toRGBA8 consume-luminance-as-red: 91.153850 -> 86.067310; restore +TMCJPEGDEC_converterYUV211toRGBA8 consume-luminance-as-green: 91.153850 -> 78.307690; restore +TMCJPEGDEC_converterYUV211toRGBA8edge consume-luminance-as-blue: 92.000000 -> 91.565216; restore +TMCJPEGDEC_converterYUV211toRGBA8edge consume-luminance-as-red: 92.000000 -> 87.617390; restore +TMCJPEGDEC_converterYUV211toRGBA8edge consume-luminance-as-green: 92.000000 -> 79.547830; restore +TMCJPEGDEC_converterYUV444toRGBA8 consume-luminance-as-blue: 90.670105 -> 90.670105; restore +TMCJPEGDEC_converterYUV444toRGBA8 consume-luminance-as-red: 90.670105 -> 85.216490; restore +TMCJPEGDEC_converterYUV444toRGBA8 consume-luminance-as-green: 90.670105 -> 74.577320; restore +TMCJPEGDEC_converterYUV444toRGBA8edge consume-luminance-as-blue: 88.909090 -> 88.909090; restore +TMCJPEGDEC_converterYUV444toRGBA8edge consume-luminance-as-red: 88.909090 -> 85.645454; restore +TMCJPEGDEC_converterYUV444toRGBA8edge consume-luminance-as-green: 88.909090 -> 78.772730; restore +TMCJPEGDEC_converterYUV411toRGB565edge consume-luminance-as-blue: 95.377360 -> 91.396225; restore +TMCJPEGDEC_converterYUV411toRGB565edge consume-luminance-as-red: 95.377360 -> 93.707550; restore +TMCJPEGDEC_converterYUV411toRGB565edge consume-luminance-as-green: 95.377360 -> 95.330185; restore +TMCJPEGDEC_converterYUV444toRGB565 consume-luminance-as-blue: 98.681320 -> 98.681320; restore +TMCJPEGDEC_converterYUV444toRGB565 consume-luminance-as-red: 98.681320 -> 98.714290; RETAIN +``` + +### rgb444-trials + +```text +TMCJPEGDEC_converterYUV444toRGB565 reused-luminance-green-red-group: 98.714290 -> 89.923080; restore +TMCJPEGDEC_converterYUV444toRGB565 reused-luminance-blue-green-group: 98.714290 -> 98.549450; restore +TMCJPEGDEC_converterYUV444toRGB565 reused-luminance-red-blue-group: 98.714290 -> 90.945050; restore +TMCJPEGDEC_converterYUV444toRGB565 reused-luminance-red-green-group: 98.714290 -> 98.714290; restore +TMCJPEGDEC_converterYUV444toRGB565 separate-luminance-green-red-group: 98.714290 -> 98.131870; restore +TMCJPEGDEC_converterYUV444toRGB565 separate-luminance-blue-green-group: 98.714290 -> 98.516490; restore +TMCJPEGDEC_converterYUV444toRGB565 separate-luminance-red-blue-group: 98.714290 -> 91.406590; restore +TMCJPEGDEC_converterYUV444toRGB565 separate-luminance-red-green-group: 98.714290 -> 98.681320; restore +``` diff --git a/tools/decomp-assist/jpeg-remainder-differential-results.txt b/tools/decomp-assist/jpeg-remainder-differential-results.txt new file mode 100644 index 00000000..6e79cbe9 --- /dev/null +++ b/tools/decomp-assist/jpeg-remainder-differential-results.txt @@ -0,0 +1,29 @@ +TMCJPEGDEC_converterYUV411toRGBA8: 100 cases PASS; instruction coverage source 242/242, original 242/242 +TMCJPEGDEC_converterYUV411toRGBA8edge: 400 cases PASS; instruction coverage source 112/112, original 112/112 +TMCJPEGDEC_converterYUV422toRGBA8: 100 cases PASS; instruction coverage source 148/148, original 148/148 +TMCJPEGDEC_converterYUV422toRGBA8edge: 400 cases PASS; instruction coverage source 113/113, original 113/113 +TMCJPEGDEC_converterYUV420toRGBA8: 100 cases PASS; instruction coverage source 153/153, original 153/153 +TMCJPEGDEC_converterYUV420toRGBA8edge: 400 cases PASS; instruction coverage source 120/120, original 120/120 +TMCJPEGDEC_converterYUV211toRGBA8: 100 cases PASS; instruction coverage source 104/104, original 104/104 +TMCJPEGDEC_converterYUV211toRGBA8edge: 400 cases PASS; instruction coverage source 115/115, original 115/115 +TMCJPEGDEC_converterYUV444toRGBA8: 100 cases PASS; instruction coverage source 97/97, original 97/97 +TMCJPEGDEC_converterYUV444toRGBA8edge: 400 cases PASS; instruction coverage source 110/110, original 110/110 +TMCJPEGDEC_converterYUV400toRGBA8: 100 cases PASS; instruction coverage source 57/76, original 57/76 +TMCJPEGDEC_converterYUV400toRGBA8edge: 400 cases PASS; instruction coverage source 70/89, original 70/89 +TMCJPEGDEC_set_converterRGBA8: 1024 cases PASS; instruction coverage source 168/169, original 169/170 +TMCJPEGDEC_converterYUV411toRGB565: 100 cases PASS; instruction coverage source 217/217, original 217/217 +TMCJPEGDEC_converterYUV411toRGB565edge: 400 cases PASS; instruction coverage source 106/106, original 106/106 +TMCJPEGDEC_converterYUV422toRGB565: 100 cases PASS; instruction coverage source 136/136, original 136/136 +TMCJPEGDEC_converterYUV422toRGB565edge: 400 cases PASS; instruction coverage source 107/107, original 107/107 +TMCJPEGDEC_converterYUV420toRGB565: 100 cases PASS; instruction coverage source 141/141, original 141/141 +TMCJPEGDEC_converterYUV420toRGB565edge: 400 cases PASS; instruction coverage source 114/114, original 114/114 +TMCJPEGDEC_converterYUV211toRGB565: 100 cases PASS; instruction coverage source 98/98, original 98/98 +TMCJPEGDEC_converterYUV211toRGB565edge: 400 cases PASS; instruction coverage source 109/109, original 109/109 +TMCJPEGDEC_converterYUV444toRGB565: 100 cases PASS; instruction coverage source 91/91, original 91/91 +TMCJPEGDEC_converterYUV444toRGB565edge: 400 cases PASS; instruction coverage source 104/104, original 104/104 +TMCJPEGDEC_converterYUV400toRGB565: 100 cases PASS; instruction coverage source 51/70, original 51/70 +TMCJPEGDEC_converterYUV400toRGB565edge: 400 cases PASS; instruction coverage source 64/83, original 64/83 +TMCJPEGDEC_set_converterRGB565: 1024 cases PASS; instruction coverage source 168/169, original 169/170 +TMCJPEGDEC_IdctBlock_Lumi: 704 cases PASS; instruction coverage source 257/257, original 257/257 +TMCJPEGDEC_IdctBlock_Col: 704 cases PASS; instruction coverage source 454/454, original 454/454 +TOTAL: 9456 differential cases PASS; GPR14-GPR31, stack pointer and LR preserved diff --git a/tools/decomp-assist/jpeg_differential_audit.py b/tools/decomp-assist/jpeg_differential_audit.py new file mode 100644 index 00000000..1e12c6f6 --- /dev/null +++ b/tools/decomp-assist/jpeg_differential_audit.py @@ -0,0 +1,319 @@ +#!/usr/bin/env python3 +"""Read-only, bounded PPC integer interpreter for differential JPEG checks. +Loads source and original ELF .text; never copies original code into sources. +Only memset is external. No FPU/system instructions are supported. +""" +import random +import re +import struct +import zlib + +import capstone +from elftools.elf.elffile import ELFFile +U32 = 0xFFFFFFFF + +def signed(x): + x &= U32 + return x - 0x100000000 if x & 0x80000000 else x + +def rotate(x, n): + return (x << n | x >> (32 - n if n else 32)) & U32 + +def mask(b, e): + return sum((1 << 31 - i for i in range(32) if b <= i <= e or (b > e and (i >= b or i <= e)))) + +def load_object(path): + with open(path, 'rb') as f: + e = ELFFile(f) + section = e.get_section_by_name('.text') + data = bytearray(section.data()) + syms = e.get_section_by_name('.symtab') + calls = {} + symbol_addresses = {} + rel = e.get_section_by_name('.rela.text') + if rel: + for r in rel.iter_relocations(): + name = syms.get_symbol(r['r_info_sym']).name + off = r['r_offset'] + typ = r['r_info_type'] + addr = 0x800000 + (zlib.crc32(name.encode()) & 0x7FFF) * 4 + r['r_addend'] + assert addr not in symbol_addresses or symbol_addresses[addr] == name + symbol_addresses[addr] = name + if typ == 10: + calls[off] = name + elif typ == 4: + data[off:off + 2] = struct.pack('>H', addr & 65535) + elif typ == 6: + data[off:off + 2] = struct.pack('>H', addr + 0x8000 >> 16 & 65535) + else: + raise ValueError(('relocation', typ)) + dis = capstone.Cs(capstone.CS_ARCH_PPC, capstone.CS_MODE_32 | capstone.CS_MODE_BIG_ENDIAN) + funcs = {} + for sym in syms.iter_symbols(): + if sym['st_info']['type'] != 'STT_FUNC' or not sym['st_size']: + continue + start = sym['st_value'] + size = sym['st_size'] + inst = {} + for i in dis.disasm(bytes(data[start:start + size]), start): + ops = [] + for o in i.op_str.split(', '): + if not o: + continue + if o.startswith('cr'): + ops.append(('cr', int(o[2:]))) + elif o.startswith('r'): + ops.append(int(o[1:])) + elif '(' in o: + off, reg = o.split('(') + ops.append((int(off, 0), int(reg[1:-1]))) + else: + ops.append(int(o, 0)) + inst[i.address] = (i.mnemonic, ops) + funcs[sym.name] = (start, inst, calls) + return funcs + +def run(fn, initial, args): + pc, ins, calls = fn + mem = bytearray(initial) + r = [i * 1122867 & U32 for i in range(32)] + r[1] = 0x3F000 + r[3:3 + len(args)] = args + saved_registers = r[14:].copy() + cr = [0] * 8 + ctr = 0 + lr = 0 + steps = 0 + coverage = set() + + def ld(a, n): + assert 0 <= a <= len(mem) - n, hex(a) + return int.from_bytes(mem[a:a + n], 'big') + + def st(a, v, n): + assert 0 <= a <= len(mem) - n, hex(a) + mem[a:a + n] = (v & (1 << 8 * n) - 1).to_bytes(n, 'big') + while True: + steps += 1 + if steps > 100000: + raise RuntimeError('step bound') + coverage.add(pc) + op, a = ins[pc] + pc += 4 + dot = op.endswith('.') + op = op.rstrip('.') + val = None + if op == 'blr': + break + elif op == 'bl': + assert calls.get(pc - 4) == 'memset', calls.get(pc - 4) + assert r[3] + r[5] <= len(mem) + mem[r[3]:r[3] + r[5]] = bytes([r[4] & 255]) * r[5] + # Model ABI-permitted call clobbers rather than preserving temporaries. + for reg in [0] + list(range(4, 13)): + r[reg] = (0xBAD00000 + reg) & U32 + for field in [0, 1, 5, 6, 7]: + cr[field] = -1 + lr = pc + elif op == 'b': + pc = a[0] + elif op == 'bdnz': + ctr = ctr - 1 & U32 + if ctr: + pc = a[0] + elif op in ['beq', 'bne', 'ble', 'bge', 'blt', 'bgt']: + c = cr[a[0][1]] if len(a) > 1 else cr[0] + if {'beq': c == 0, 'bne': c != 0, 'ble': c <= 0, 'bge': c >= 0, 'blt': c < 0, 'bgt': c > 0}[op]: + pc = a[-1] + elif op in ['cmpwi', 'cmpw', 'cmplw']: + c = a[0][1] if isinstance(a[0], tuple) else 0 + a = ins[pc - 4][1] + if isinstance(a[0], tuple): + a = a[1:] + x = r[a[0]] + y = a[1] if op == 'cmpwi' else r[a[1]] + if op != 'cmplw': + x = signed(x) + y = signed(y) + cr[c] = (x > y) - (x < y) + elif op in ['lbz', 'lhz', 'lwz', 'lmw']: + off, reg = a[1] + addr = (r[reg] if reg else 0) + off & U32 + if op == 'lmw': + for j in range(a[0], 32): + r[j] = ld(addr + (j - a[0]) * 4, 4) + else: + r[a[0]] = ld(addr, {'lbz': 1, 'lhz': 2, 'lwz': 4}[op]) + elif op in ['stb', 'sth', 'stw', 'stwu', 'stmw']: + off, reg = a[1] + addr = (r[reg] if reg else 0) + off & U32 + if op == 'stmw': + for j in range(a[0], 32): + st(addr + (j - a[0]) * 4, r[j], 4) + else: + st(addr, r[a[0]], {'stb': 1, 'sth': 2, 'stw': 4, 'stwu': 4}[op]) + if op == 'stwu': + r[reg] = addr + elif op in ['stbx', 'sthx']: + st((r[a[1]] if a[1] else 0) + r[a[2]] & U32, r[a[0]], 1 if op == 'stbx' else 2) + elif op == 'mflr': + r[a[0]] = lr + elif op == 'mtlr': + lr = r[a[0]] + elif op == 'mtctr': + ctr = r[a[0]] + else: + d = a[0] + if op == 'li': + val = a[1] + elif op == 'lis': + val = a[1] << 16 + elif op == 'mr': + val = r[a[1]] + elif op == 'add': + val = r[a[1]] + r[a[2]] + elif op == 'addi': + val = (r[a[1]] if a[1] else 0) + a[2] + elif op == 'addis': + val = (r[a[1]] if a[1] else 0) + (a[2] << 16) + elif op == 'subf': + val = r[a[2]] - r[a[1]] + elif op == 'subfic': + val = a[2] - r[a[1]] + elif op == 'mulli': + val = r[a[1]] * a[2] + elif op == 'mullw': + val = r[a[1]] * r[a[2]] + elif op == 'divw': + x = signed(r[a[1]]) + y = signed(r[a[2]]) + val = abs(x) // abs(y) * (-1 if (x < 0) != (y < 0) else 1) + elif op == 'or': + val = r[a[1]] | r[a[2]] + elif op == 'andc': + val = r[a[1]] & ~r[a[2]] + elif op == 'andi': + val = r[a[1]] & a[2] + elif op == 'neg': + val = -r[a[1]] + elif op == 'extsb': + val = (r[a[1]] & 255) - (256 if r[a[1]] & 128 else 0) + elif op == 'srawi': + val = signed(r[a[1]]) >> a[2] + elif op == 'srwi': + val = r[a[1]] >> a[2] + elif op == 'slwi': + val = r[a[1]] << a[2] + elif op == 'clrlwi': + val = r[a[1]] & (1 << 32 - a[2]) - 1 + elif op == 'rotlwi': + val = rotate(r[a[1]], a[2]) + elif op == 'rlwinm': + val = rotate(r[a[1]], a[2]) & mask(a[3], a[4]) + else: + raise ValueError((hex(pc - 4), op, a)) + r[d] = val & U32 + if dot: + cr[0] = (signed(val) > 0) - (signed(val) < 0) + assert r[1] == 0x3F000, 'Stack pointer not restored' + assert lr == 0, 'Link register not restored' + assert r[14:] == saved_registers, 'Nonvolatile registers not restored' + return (mem, r[3], coverage) + +def put(m, a, v, n=4): + m[a:a + n] = (v & (1 << 8 * n) - 1).to_bytes(n, 'big') + +def compare(src, orig, name, m, args, case, returns=False): + a, ra, ca = run(src[name], m, args) + b, rb, cb = run(orig[name], m, args) + # The stack can differ because each implementation owns its frame. + if a[:0x3E000] != b[:0x3E000]: + diff = [hex(i) for i in range(0x3E000) if a[i] != b[i]][:12] + raise AssertionError((name, case, 'memory mismatch', diff)) + if returns and ra != rb: + raise AssertionError((name, case, 'return', ra, rb)) + return (ca, cb) + +def main(): + total_cases = 0 + rng = random.Random(449529) + root = 'build/43U/{}/libs/RVLMiddleware/TMC_JPEG/src/{}' + for unit in ['texturecvtr/Texture_MCUtoRGBA8', 'texturecvtr/Texture_MCUtoRGB565', 'buffer/idct_block_var']: + src = load_object(root.format('src', unit) + '.o') + orig = load_object(root.format('obj', unit) + '.o') + assert src.keys() == orig.keys(), (unit, 'Function sets differ') + assert len(src) == (2 if unit.startswith('buffer/') else 13) + for name in src: + n = 0 + sa = set() + sb = set() + if 'IdctBlock' in name: + for rows in range(1, 9): + for cols in [1, 2, 3, 8]: + for pattern in range(22): + m = bytearray([0xA5]) * 0x40000 + block = [0] * 64 + for y in range(rows): + for x in range(cols): + if pattern < 6: + block[y * 8 + x] = [0, 1, -1, 0x3FFFF, 0x40000, -0x40000][pattern] if x == 0 and y == 0 else 0 + elif pattern < 14: + block[y * 8 + x] = rng.randrange(-10000, 10001) if rng.randrange(4) == 0 else 0 + else: + block[y * 8 + x] = rng.randrange(-150000, 150001) + for i, v in enumerate(block): + put(m, 0x1000 + i * 4, v) + pitch = [8, 16, 32][pattern % 3] + args = [0x1000, 0x2000, pitch, rows << 4 | cols] + ca, cb = compare(src, orig, name, m, args, (rows, cols, pattern)) + sa |= ca + sb |= cb + n += 1 + elif 'set_converter' in name: + for component in range(256): + for mode in [1, 2, 4, 8]: + m = bytearray([0xA5]) * 0x40000 + work = 0x1000 + state = 0x4000 + put(m, work + 0x17FC, component, 1) + put(m, work + 0x19DC, mode, 1) + put(m, work + 0x19E4, state) + put(m, state + 0x24, rng.randrange(65536), 2) + put(m, state + 0x26, rng.randrange(65536), 2) + ca, cb = compare(src, orig, name, m, [work], (component, mode), True) + sa |= ca + sb |= cb + n += 1 + else: + sampling = re.search('YUV(\\d+)to', name)[1] + w, h = {'411': (32, 8), '422': (16, 8), '420': (16, 16), '211': (8, 16), '444': (8, 8), '400': (8, 8)}[sampling] + for scale in [1, 2, 4, 8]: + for pattern in range(25): + for border in range(4 if name.endswith('edge') else 1): + m = bytearray([0xA5]) * 0x40000 + work = 0x1000 + state = 0x4000 + tex = 0x8000 + x = 32 * (pattern % 2) + y = 16 * (pattern % 3) + ww = w // scale + hh = h // scale + put(m, work + 0x19E4, state) + put(m, state + 0x20, scale, 1) + put(m, state + 0x2C, 96) + put(m, state + 0x48, tex) + put(m, state + 0x18, x if border & 1 else x + 1) + put(m, state + 0x1C, y if border & 2 else y + 1) + put(m, state + 0x16, pattern % (ww + 1), 1) + put(m, state + 0x17, pattern % (hh + 1), 1) + for i in range(0x184): + m[work + 0x1858 + i] = [0, 127, 128, 255][pattern % 4] if pattern < 4 else rng.randrange(256) + ca, cb = compare(src, orig, name, m, [work, x, y], (scale, pattern, border)) + sa |= ca + sb |= cb + n += 1 + total_cases += n + print(f'{name}: {n} cases PASS; instruction coverage source {len(sa)}/{len(src[name][1])}, original {len(sb)}/{len(orig[name][1])}', flush=True) + print(f'TOTAL: {total_cases} differential cases PASS; GPR14-GPR31, stack pointer and LR preserved') +if __name__ == '__main__': + main() -- 2.49.1 From 6b17698b849ae2d06ad903cede5a103d8c6900d7 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 2 Oct 2026 17:28:16 -0500 Subject: [PATCH 4/4] match(odh): cdj_c_colorConv byte-identical (#974) Pad with a named remainder and declare sourceStride after rowIndex so cbPlane stays r22 and the stride stays r29. decompressLoop is unchanged. --- src/system/odh.cpp | 21 +++++++++------------ tools/decomp-assist/attempts/odh-worker2.md | 8 ++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/system/odh.cpp b/src/system/odh.cpp index 88b202b4..d1e303f0 100644 --- a/src/system/odh.cpp +++ b/src/system/odh.cpp @@ -931,17 +931,15 @@ void CArGBAOdh::cdj_c_makeHeader(SArCDJ_OdhMaster* master, u32 size) { } s32 CArGBAOdh::cdj_c_colorConv(SArCDJ_OdhMaster* master, u8* sourceData, int format) { - u32 paddedWidth; u16 width; u16 height; u8* workPlane; - int sourceStride; - u8* crPlane; u8* cbPlane; + u8* crPlane; u16* dimensions; int rowIndex; + int sourceStride; int i; - u16 dimension; u16 paddedDimensions[2]; dimensions = &master->width; @@ -952,11 +950,11 @@ s32 CArGBAOdh::cdj_c_colorConv(SArCDJ_OdhMaster* master, u8* sourceData, int for height = dimensions[1]; for (i = 0; i < 2; i++) { - dimension = dimensions[i]; - if ((dimension & 7) != 0) { - paddedDimensions[i] = (dimension + 8) - (dimension & 7); + u16 remainder = dimensions[i] & 7; + if (remainder != 0) { + paddedDimensions[i] = (dimensions[i] + 8) - remainder; } else { - paddedDimensions[i] = dimension; + paddedDimensions[i] = dimensions[i]; } } @@ -972,13 +970,12 @@ s32 CArGBAOdh::cdj_c_colorConv(SArCDJ_OdhMaster* master, u8* sourceData, int for } } - paddedWidth = paddedDimensions[0]; for (rowIndex = 0; rowIndex < (s32)height; rowIndex++) { LineConv11(sourceData + (rowIndex & 3) * 8 + rowIndex / 4 * sourceStride, workPlane, cbPlane, crPlane, dimensions[0], dimensions[1], (const long*)gArConvPlttTbl, format); - workPlane += paddedWidth; - cbPlane += paddedWidth; - crPlane += paddedWidth; + workPlane += paddedDimensions[0]; + cbPlane += paddedDimensions[0]; + crPlane += paddedDimensions[0]; } return 0; diff --git a/tools/decomp-assist/attempts/odh-worker2.md b/tools/decomp-assist/attempts/odh-worker2.md index 02fd7389..6e82f332 100644 --- a/tools/decomp-assist/attempts/odh-worker2.md +++ b/tools/decomp-assist/attempts/odh-worker2.md @@ -16,3 +16,11 @@ Claim was only `cdj_d_decompressLoop`. colorConv, huffmanDecoder, and LineConv11 - 2x2 tail stores the updated plane in `requiredBlockEnd` and the end pointer in `planeOffset`. That is what puts the plane in r15 and the end in r16 (`addi r15, r3, -8` / `add r16, r15, r18`). Assigning the plane back to `planeOffset` left those two callee-saves swapped (7 diffs). Splitting the `-8` let MWCC cancel it against the later `+8` and dropped to 897. colorConv left at the 18 pairwise wall. Not in this diff. + +## colorConv (2026-10-02) + +`cdj_c_colorConv` **77/77, 0 diffs, byte-identical** (308 bytes). Was 18, then 13, then 8. + +- Drop `paddedWidth`. The row loop adds `paddedDimensions[0]`, which hoists `lhz r24` and `lis r23` / `addi r10, r23, 0`. +- Pad loop: `u16 remainder = dimensions[i] & 7`, then `(dimensions[i] + 8) - remainder`. Width stays r8, the indexed load stays r7, the mask stays r9. Naming both a dimension and a remainder swaps width off r8. +- Declare `sourceStride` after `rowIndex` (cb/cr stay above it). That assigns stride r29 and `cbPlane` r22. Computing stride before the planes shortens the function to 76 and shifts the callee-saves. huffmanDecoder and LineConv11 were not edited. `cdj_d_decompressLoop` stays 899/899. -- 2.49.1