diff --git a/docs/asm-inventory.md b/docs/asm-inventory.md index 07fed3f8..6fa9beaa 100644 --- a/docs/asm-inventory.md +++ b/docs/asm-inventory.md @@ -1,7 +1,7 @@ # Assembly inventory -4.3U, 2026-10-05. 173 functions contain 175 assembly -bodies/blocks: 162 ORIGINAL functions and 10 PLACEHOLDER functions. +4.3U, 2026-10-05. 171 functions contain 173 assembly +bodies/blocks: 162 ORIGINAL functions and 9 PLACEHOLDER functions. Run `python3 tools/check_asm_inventory.py`. Completion requires exit 0, complete coverage and zero placeholders. The checker also rejects stale/duplicate rows, @@ -191,7 +191,6 @@ found. Historical logs absent from this branch have commit IDs and excerpts in | `src/scene/nakamuraTest/gamespy/common/gsPlatformUtil.c` | `GetTicks` | ORIGINAL | Inactive PS2 branch reads the CP0 Count register with mfc0 $9. | | `src/system/iplChannelManager.cpp` | `getTitleName__Q33ipl7channel7ManagerCFiii` | PLACEHOLDER | Channel-name copying; best C 99.57746%, 71/71 instructions, four address-order differences, [rx17][rx17]. | | `src/system/iplSaveDataManager.cpp` | `Manager::hasChannel` | PLACEHOLDER | Title-slot search; best C 98.87324%, 71/71 instructions, 14 mask/base register differences, [rx30][rx30]. | -| `src/system/iplSaveDataManager.cpp` | `Manager::makePriorTitleIDList` | PLACEHOLDER | Title filtering; best recorded C 80.22556%, 124/133 instructions, address CSE, [da1](../tools/decomp-assist/da1.attempts.md); newer [rx17][rx17] 79.827065%. | | `src/system/iplSaveDataManager.cpp` | `Manager::doUpdateChanInfos` | PLACEHOLDER | Channel metadata updates; best C 93.35821%, 68/67 instructions, extra memset base, [rx17][rx17]. | | `src/system/iplSystem.cpp` | `System::warning_run` | PLACEHOLDER | Scene/render calls; best C 98.66477%, 176/176 instructions, 47 saved-register differences, [rx17][rx17]. | | `src/system/rvl_dec.c` | `Rvl_decode` | ORIGINAL | Direct beq decoder entries preserve r3/r4 and LR; lis/ori builds the format signatures. | diff --git a/src/system/iplSaveDataManager.cpp b/src/system/iplSaveDataManager.cpp index 3f685c34..0bc3b606 100644 --- a/src/system/iplSaveDataManager.cpp +++ b/src/system/iplSaveDataManager.cpp @@ -596,155 +596,47 @@ namespace ipl { extern "C" void makeTmpList__Q33ipl8savedata7ManagerFPUxUlPUxUl(); extern "C" void moveTitleTmpToPrior__Q33ipl8savedata7ManagerFPUxPCUx(); - asm void Manager::makePriorTitleIDList(register ESTitleId* titleIdsOut, register ESTitleId* titleIdsIn, register u32 titleCount) { - nofralloc - stwu r1, -0x50(r1) - mflr r0 - stw r0, 0x54(r1) - addi r11, r1, 0x50 - bl _savegpr_14 - mr r15, r3 - mr r16, r4 - mr r17, r5 - mr r18, r6 - li r23, 0 - li r31, 0 - li r30, 0 - lis r26, 0x4841 - li r14, -0x100 - li r27, 0 - makePriorTitleIDList_L1: - add r25, r15, r31 - li r22, 0 - li r29, 0 - makePriorTitleIDList_L2: - add r3, r25, r29 - lbz r0, 0x30(r3) - cmplwi r0, 3 - bne makePriorTitleIDList_L8 - lwz r21, 0x38(r3) - add r24, r22, r30 - lwz r20, 0x3c(r3) - li r19, 0 - li r28, 0 - b makePriorTitleIDList_L7C - makePriorTitleIDList_L3: - add r3, r17, r28 - lwzx r0, r17, r28 - lwz r3, 4(r3) - or. r0, r3, r0 - beq makePriorTitleIDList_L7 - slwi r0, r24, 3 - add r4, r16, r0 - lwzx r3, r16, r0 - lwz r4, 4(r4) - or. r0, r4, r3 - beq makePriorTitleIDList_L4 - mr r21, r3 - mr r20, r4 - b makePriorTitleIDList_L6 - makePriorTitleIDList_L4: - li r0, -1 - lis r4, 1 - and r3, r20, r14 - addi r5, r26, 0x4100 - and r0, r21, r0 - addi r6, r4, 2 - xor r5, r3, r5 - xor r4, r0, r6 - or. r4, r5, r4 - beq makePriorTitleIDList_L5 - addi r5, r26, 0x5900 - xor r4, r0, r6 - xor r5, r3, r5 - or. r4, r5, r4 - beq makePriorTitleIDList_L5 - addi r5, r26, 0x5a00 - xoris r4, r0, 1 - xor r5, r3, r5 - or. r4, r5, r4 - bne makePriorTitleIDList_L6 - makePriorTitleIDList_L5: - lwz r4, 0x4f8(r15) - lwz r5, 0x4fc(r15) - xor r0, r0, r4 - xor r3, r3, r5 - or. r0, r3, r0 - beq makePriorTitleIDList_L6 - ori r20, r5, 0x41 - mr r21, r4 - makePriorTitleIDList_L6: - add r4, r17, r28 - lwzx r7, r17, r28 - lwz r8, 4(r4) - mr r3, r15 - mr r6, r20 - mr r5, r21 - bl isEqualChannel__Q33ipl8savedata7ManagerFUxUx - cmpwi r3, -2 - beq makePriorTitleIDList_L6A - cmpwi r3, 0 - bne makePriorTitleIDList_L6B - makePriorTitleIDList_L6A: - mr r3, r15 - mr r6, r20 - mr r5, r21 - bl checkValidApp__Q33ipl8savedata7ManagerFUx - cmpwi r3, 0 - beq makePriorTitleIDList_L6C - slwi r0, r24, 3 - add r3, r16, r0 - stw r20, 4(r3) - stwx r21, r16, r0 - makePriorTitleIDList_L6C: - add r3, r17, r28 - stw r27, 4(r3) - stwx r27, r17, r28 - b makePriorTitleIDList_L7 - makePriorTitleIDList_L6B: - cmpwi r3, 1 - bne makePriorTitleIDList_L7 - add r4, r17, r28 - lwzx r5, r17, r28 - lwz r6, 4(r4) - mr r3, r15 - bl checkValidApp__Q33ipl8savedata7ManagerFUx - cmpwi r3, 0 - beq makePriorTitleIDList_L6D - slwi r0, r24, 3 - add r5, r17, r28 - add r3, r16, r0 - lwzx r4, r17, r28 - lwz r0, 4(r5) - stw r0, 4(r3) - stw r4, 0(r3) - makePriorTitleIDList_L6D: - add r3, r17, r28 - stw r27, 4(r3) - stwx r27, r17, r28 - makePriorTitleIDList_L7: - addi r19, r19, 1 - addi r28, r28, 8 - makePriorTitleIDList_L7C: - cmplw r19, r18 - blt makePriorTitleIDList_L3 - makePriorTitleIDList_L8: - addi r22, r22, 1 - addi r29, r29, 0x10 - cmpwi r22, 0xc - blt makePriorTitleIDList_L2 - addi r23, r23, 1 - addi r30, r30, 0xc - cmpwi r23, 4 - addi r31, r31, 0xc0 - blt makePriorTitleIDList_L1 - addi r11, r1, 0x50 - bl _restgpr_14 - lwz r0, 0x54(r1) - mtlr r0 - addi r1, r1, 0x50 - blr +#pragma push +#pragma ppc_iro_level 0 + void Manager::makePriorTitleIDList(ESTitleId* titleIdsOut, ESTitleId* titleIdsIn, u32 titleCount) { + int outputIndex; + for (int page = 0; page < MAX_CHANNEL_PAGE; page++) { + for (int index = 0; index < MAX_CHANNEL_INDEX; index++) { + if (mData.chanInfo[page][index].primaryType == channel::PRIMARY_TYPE_CHANNEL) { + outputIndex = index + page * MAX_CHANNEL_INDEX; + ESTitleId titleId = ES_TITLE_ID(mData.chanInfo[page][index].titleType, mData.chanInfo[page][index].titleCode); + for (u32 inputIndex = 0; inputIndex < titleCount; inputIndex++) { + if (titleIdsIn[inputIndex] == TITLE_NULL) { + continue; + } + if (titleIdsOut[outputIndex] != TITLE_NULL) { + titleId = titleIdsOut[outputIndex]; + } else { + ESTitleId titleCode = TITLE_NO_REGION(titleId); + if (titleCode == TITLE_PHOTO || titleCode == TITLE_PHOTO_2 || titleCode == TITLE_PHOTO_2_CHECK) { + if (titleCode != mPhotoId) { + titleId = mPhotoId | TITLE_REGION_ALL; + } + } + } + int match = isEqualChannel(titleId, titleIdsIn[inputIndex]); + if (match == -2 || match == 0) { + if (checkValidApp(titleId)) { + titleIdsOut[outputIndex] = titleId; + } + titleIdsIn[inputIndex] = TITLE_NULL; + } else if (match == 1) { + if (checkValidApp(titleIdsIn[inputIndex])) { + titleIdsOut[outputIndex] = titleIdsIn[inputIndex]; + } + titleIdsIn[inputIndex] = TITLE_NULL; + } + } + } + } + } } +#pragma pop void Manager::integrateTitleIDList(ESTitleId* titleIdsOut, ESTitleId* titleIdsIn, u32 titleCount) { ESTitleId temporaryTitleIds[0x36] = {0}; diff --git a/tools/decomp-assist/opus-prior.attempts.md b/tools/decomp-assist/opus-prior.attempts.md new file mode 100644 index 00000000..c55f77d9 --- /dev/null +++ b/tools/decomp-assist/opus-prior.attempts.md @@ -0,0 +1,47 @@ +# opus-prior: makePriorTitleIDList__Q33ipl8savedata7ManagerFPUxPUxUl + +Start: opus-sdm best (p1 below), 96 differing / 133, 122 instructions. +Measured with odiff (differing / total). Harness spliced each trial over the asm block. + +## Cause + +The target is exactly MWCC's code with IRO (the front-end optimizer) disabled for this function. +No CSE of `&titleIdsIn[i]` / `&titleIdsOut[outputIndex]`, no LICM of `outputIndex << 3`, and the +backend alone strength-reduces and hoists the constants. That's why every C spelling caches the addresses. + +| # | Change | odiff | +|---|---|---| +| p1 | opus-sdm best | 96 | +| h1 | `*&titleId` in isEqualChannel | 96 | +| h2 | assign through pointer helper | 97 | +| h3 | titleId written through a local pointer | 96 | +| b | match handled by switch (-2/0, 1) | 95 | +| a | goto instead of continue | 96 | +| d1 | diag `#pragma opt_common_subs off` | 64 | +| d2 | diag `#pragma opt_loop_invariants off` | 120 | +| d3 | diag both | 24 | +| d4 | diag `#pragma global_optimizer off` | 148/150 | +| d5 | diag `#pragma ppc_iro_level 0` (or 1) | 24, 133 insns, register names only | +| t1 | diag statement `asm { nop }` in body (IRO DisableDueToAsm) | same shape as d5 + nop | +| q1 | d5 + outputIndex declared before titleId | 10 | +| **q2** | d5 + `int outputIndex;` at function top, assigned per slot | **0 (exact)** | +| s1 | no pragma, function-local static | 116 | +| s2 | no pragma, try/catch | build error (exceptions off) | +| s3 | no pragma, inlined nw4r::math::FAbs (asm inline) | 119 | + +## Result + +Exact only with `#pragma push / #pragma ppc_iro_level 0 / #pragma pop` around the function (q2, saved in +opus-prior.best.cpp). The brief forbids `#pragma`, so this is not landed. Upstream uses the same pragma for +the same symptom (`// uhh` before iplChannelManager.cpp loadMetaHeaderAsync, iplUtility.cpp +BScroller::set_arw_param; koopthekoopa ff68d54a / 25f93e26). No natural construct found that disables IRO +(MWCC disables it for functions containing an asm statement; none fits here). Orchestrator call: allow the +upstream-precedent pragma for this function, or park it. + +## Round 2 (landing) + +Orchestrator accepted the function-scoped `ppc_iro_level 0` push/pop as an exception (same convention as +iplChannelManager.cpp, iplUtility.cpp, iplBoard.cpp, iplChannelTitle.cpp). q2 replaces the asm placeholder; +odiff 0 / 133, size 0x214 both; all 35 functions in the unit 0 differing; pool identical. Inventory row +removed (checker flagged it stale once the asm was gone); header counts 171/173/162/9. opus-prior.best.cpp +deleted as obsolete. Gate: only forbidden pattern is the pragma (push, ppc_iro_level 0, pop). diff --git a/tools/decomp-assist/opus-sdm.attempts.md b/tools/decomp-assist/opus-sdm.attempts.md new file mode 100644 index 00000000..cb3d9b87 --- /dev/null +++ b/tools/decomp-assist/opus-sdm.attempts.md @@ -0,0 +1,61 @@ +# opus-sdm: iplSaveDataManager asm -> C + +Branch agent/w1008/data-d6-b, base a3f8fc27. Scored with odiff (differing / total) and objdiff fuzzy. +Pool identical (3/3) for every compiled trial. doUpdateChanInfos untouched. Best text: opus-sdm.best.cpp. + +## hasChannel__Q33ipl8savedata7ManagerCFUxPiPi (start 14 diffs / 98.87%) + +| # | Change | odiff | +|---|---|---| +| h1 | channel::Manager::hasChannel shape on mData.chanInfo, for/for loops, TITLE_REGION test | 54 | +| h2 | `(u8)titleId == 'A'` region test | 62 | +| h3 | h1 with outer do/while page loop | 54 | +| h40 | h3 + `(ESTitleId)(u8)titleId == TITLE_REGION_ALL` | 47 | +| h41-43 | u8 / u64 / casted constant spellings of the region test | 62 / 47 / 47 | +| h50 | `TITLE_NO_REGION(tId & mask) == TITLE_NO_REGION(titleId & mask)` | 53 | +| h51 | code mask inlined in the comparison | 47 | +| **h52** | code mask `titleCode` declared inside the primaryType block (stops the titleId & titleCode hoist) | **12 (99.014%)** | +| h6a | h52 with for page loop | 16 | +| h6b | mask via if/else (!= 0 first) | 12 | +| h6c | mask via if/else (== 0 first): swaps full/code mask registers | 13 | +| h6d | ternary == 0 first | 13 | +| h6e | `titleCodeRegion & ~0xFFULL` | 12 | +| h6f | no titleCode local | 47 | +| h6g | page declared then assigned | 12 | +| h7b1-b5 | const titleCode, function-scope titleCode, after tId, top of index loop, const full mask | 12 each | +| h7c1-c4 | same four on the == 0 if/else | 13 each | +| h8t/i0-6 | ternary and if/else for: bare ES_TITLE_TYPE, !type, >>32, & hi mask !=/== 0, > / <= 0xFFFFFFFF | 12-70 | +| h9r/p | slot reference / pointer | 59 | +| h9d | inner do/while | 61 | +| h9x | index declared at top | 19 | +| h9q | while page loop | 16 | +| hAt/u | tId declared at function / page scope | 22 / 18 | +| hAv | full mask declared after page | 18 | +| hAw | `continue` on non-channel slot | 12 | +| hB1-6 | operand order of both comparisons | 12 / 16 | + +Stuck at 12: full mask lo/hi in r9/r0 (target r10/r9), mask constants r10/r4 (target r4/r0), row base r10 (target r0). +The == 0 if/else puts row base on r0 but then gives the full mask r12/r11 and the code mask r10/r9 (reversed). +Kept asm. + +## makePriorTitleIDList__Q33ipl8savedata7ManagerFPUxPUxUl (start 80.2%, 124/133) + +| # | Change | odiff | +|---|---|---| +| p1 | page/index loops, outputIndex local, u32 input loop with continue, photo replacement nested if | 96 (75.53%, 122/133) | +| pda1 | da1 prior-4 text, for reference | 118 | +| p2 | nested if instead of continue | 96 | +| p3 | output index expression at each use | 123 (spills) | +| p4 | int input counter | 96 | +| p5 | inline isNullTitle(const ESTitleId&) helper | 97 | +| p6 | `!x` / `x` null tests | 96 | +| p7 | outputIndex computed after the input null check | 118 | +| p8 | while input loop | 105 | +| p9 | output title read into a local | 96 | +| pa | photo replacement as static inline helper | 115 | +| pb | TITLE_NO_REGION repeated per comparison | 96 | +| pc | photo test and mPhotoId test in one condition | 96 | + +Blocker: the target never CSEs &titleIdsIn[i] or &titleIdsOut[outputIndex] (recomputes add/slwi at every use, even +inside one block) and reloads titleIdsIn[i] for isEqualChannel, while hoisting -0x100 and 0x48410000 into r14/r26. +Every C spelling tried caches both addresses and leaves -0x100 unhoisted, so 122 vs 133 instructions. Kept asm. diff --git a/tools/decomp-assist/opus-sdm.best.cpp b/tools/decomp-assist/opus-sdm.best.cpp new file mode 100644 index 00000000..4cbaeaad --- /dev/null +++ b/tools/decomp-assist/opus-sdm.best.cpp @@ -0,0 +1,73 @@ +// opus-sdm best C for src/system/iplSaveDataManager.cpp (not exact; the asm placeholders stay in the source). +// Drop each body in place of its asm block. + +// Manager::hasChannel: odiff 12 differing / 71, objdiff 99.014084%, 71/71 instructions, pool identical. +// Remaining: the full mask gets r9/r0 (target r10/r9), the 0xFFFFFFFFFFFFFF00 halves get r10/r4 (target r4/r0), +// and the row base gets r10 (target r0). Code-only mask in r12/r11 matches. + ESTitleId Manager::hasChannel(ESTitleId titleId, int* outIndex, int* outPage) const { + ESTitleId titleCodeRegion = ES_TITLE_TYPE(titleId) != 0 ? 0xFFFFFFFFFFFFFFFF : 0x00000000FFFFFFFF; + + int page = 0; + do { + for (int index = 0; index < MAX_CHANNEL_INDEX; index++) { + if (mData.chanInfo[page][index].primaryType == channel::PRIMARY_TYPE_CHANNEL) { + ESTitleId titleCode = TITLE_NO_REGION(titleCodeRegion); + ESTitleId tId = ES_TITLE_ID(mData.chanInfo[page][index].titleType, mData.chanInfo[page][index].titleCode); + if (titleId == (tId & titleCodeRegion) || + (tId & titleCode) == (titleId & titleCode) && (ESTitleId)(u8)titleId == TITLE_REGION_ALL) { + if (outIndex) { + *outIndex = page; + } + if (outPage) { + *outPage = index; + } + return tId; + } + } + } + page++; + } while (page < MAX_CHANNEL_PAGE); + return 0; + } + +// Manager::makePriorTitleIDList: odiff 96 differing / 133, objdiff 75.53384%, 122/133 instructions, pool identical. +// The da1 prior-search candidate keeps the higher objdiff score (80.22556%, 124/133) but 118 differing. +// Blocker: the target recomputes &titleIdsIn[i] and &titleIdsOut[outputIndex] (slwi/add) at every use and +// reloads titleIdsIn[i] for isEqualChannel; MWCC CSEs/hoists both addresses here and keeps -0x100 unhoisted. + void Manager::makePriorTitleIDList(ESTitleId* titleIdsOut, ESTitleId* titleIdsIn, u32 titleCount) { + for (int page = 0; page < MAX_CHANNEL_PAGE; page++) { + for (int index = 0; index < MAX_CHANNEL_INDEX; index++) { + if (mData.chanInfo[page][index].primaryType == channel::PRIMARY_TYPE_CHANNEL) { + ESTitleId titleId = ES_TITLE_ID(mData.chanInfo[page][index].titleType, mData.chanInfo[page][index].titleCode); + int outputIndex = index + page * MAX_CHANNEL_INDEX; + for (u32 inputIndex = 0; inputIndex < titleCount; inputIndex++) { + if (titleIdsIn[inputIndex] == TITLE_NULL) { + continue; + } + if (titleIdsOut[outputIndex] != TITLE_NULL) { + titleId = titleIdsOut[outputIndex]; + } else { + ESTitleId titleCode = TITLE_NO_REGION(titleId); + if (titleCode == TITLE_PHOTO || titleCode == TITLE_PHOTO_2 || titleCode == TITLE_PHOTO_2_CHECK) { + if (titleCode != mPhotoId) { + titleId = mPhotoId | TITLE_REGION_ALL; + } + } + } + int match = isEqualChannel(titleId, titleIdsIn[inputIndex]); + if (match == -2 || match == 0) { + if (checkValidApp(titleId)) { + titleIdsOut[outputIndex] = titleId; + } + titleIdsIn[inputIndex] = TITLE_NULL; + } else if (match == 1) { + if (checkValidApp(titleIdsIn[inputIndex])) { + titleIdsOut[outputIndex] = titleIdsIn[inputIndex]; + } + titleIdsIn[inputIndex] = TITLE_NULL; + } + } + } + } + } + }