decomp(savedata): hasChannel in C (asm placeholder removed) #1350

Merged
coah80 merged 1 commits from agent/w0929/a2c-hasch-land into main 2026-10-09 17:54:44 +00:00
3 changed files with 118 additions and 88 deletions

View File

@@ -1,7 +1,7 @@
# Assembly inventory
4.3U, 2026-10-08. 166 functions contain 168 assembly
bodies/blocks: 162 ORIGINAL functions and 4 PLACEHOLDER functions.
4.3U, 2026-10-09. 165 functions contain 167 assembly
bodies/blocks: 162 ORIGINAL functions and 3 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,
@@ -186,7 +186,6 @@ found. Historical logs absent from this branch have commit IDs and excerpts in
| `src/BS2/BS2Start.c` | `__start` | ORIGINAL | Runs before the C stack and ABI registers exist; constructs the initial stack. |
| `src/BS2/BS2Start.c` | `__init_registers` | ORIGINAL | Initializes GPRs, r1, r2, and r13 for the C runtime. |
| `src/scene/nakamuraTest/gamespy/common/gsPlatformUtil.c` | `GetTicks` | ORIGINAL | Inactive PS2 branch reads the CP0 Count register with mfc0 $9. |
| `src/system/iplSaveDataManager.cpp` | `Manager::hasChannel` | PLACEHOLDER | Title-slot search; best C 71/71 instructions, 12 mask/base register differences, [sol-ph1](../tools/decomp-assist/sol-ph1.attempts.md). |
| `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. |
| `src/system/rvl_dec.c` | `Rvl_decode_szs` | ORIGINAL | Original SZS decoder convention: nofralloc, r0 retains output length, fixed r3..r10/CTR byte-copy pipeline. |

View File

@@ -15,9 +15,6 @@
#include "config.h"
extern "C" void _savegpr_22();
extern "C" void _restgpr_22();
namespace ipl {
// clang-format off
#define DISK_CHANNEL CHANNEL_INFO(channel::PRIMARY_TYPE_DISK, channel::SECONARY_TYPE_SYSTEM, SCENE_DISK_CHANNEL, 0)
@@ -136,90 +133,40 @@ namespace ipl {
return file->isFinished();
}
asm ESTitleId Manager::hasChannel(register ESTitleId titleId, register int* outIndex, register int* outPage) const {
nofralloc
stwu r1, -0x30(r1)
mflr r0
stw r0, 0x34(r1)
addi r11, r1, 0x30
bl _savegpr_22
li r0, -1
and. r0, r5, r0
beq hasChannel_L1
li r10, -1
li r9, -1
b hasChannel_L2
hasChannel_L1:
li r10, -1
li r9, 0
hasChannel_L2:
li r4, -0x100
li r0, -1
and r12, r10, r4
li r31, 0
and r11, r9, r0
li r27, 0
li r28, 0xc
hasChannel_L3:
add r0, r3, r27
li r30, 0
li r26, 0
mtctr r28
hasChannel_L4:
add r22, r0, r26
lbz r4, 0x30(r22)
cmplwi r4, 3
bne hasChannel_L5
lwz r4, 0x3c(r22)
lwz r29, 0x38(r22)
and r23, r4, r10
and r22, r29, r9
xor r23, r6, r23
xor r22, r5, r22
or. r22, r23, r22
beq hasChannel_L6
and r22, r4, r12
and r24, r6, r12
and r23, r29, r11
and r25, r5, r11
xor r24, r22, r24
xor r25, r23, r25
or. r25, r24, r25
bne hasChannel_L5
clrlwi r25, r6, 0x18
xori r25, r25, 0x41
cmpwi r25, 0
bne hasChannel_L5
hasChannel_L6:
cmpwi r7, 0
beq hasChannel_L7
stw r31, 0(r7)
hasChannel_L7:
cmpwi r8, 0
beq hasChannel_L8
stw r30, 0(r8)
hasChannel_L8:
mr r3, r29
b hasChannel_L9
hasChannel_L5:
addi r30, r30, 1
addi r26, r26, 0x10
bdnz hasChannel_L4
addi r31, r31, 1
addi r27, r27, 0xc0
cmpwi r31, 4
blt hasChannel_L3
li r4, 0
li r3, 0
hasChannel_L9:
addi r11, r1, 0x30
bl _restgpr_22
lwz r0, 0x34(r1)
mtlr r0
addi r1, r1, 0x30
blr
#pragma push
#pragma opt_loop_invariants off
ESTitleId Manager::hasChannel(ESTitleId titleId, int* outIndex, int* outPage) const {
ESTitleId mask;
if (ES_TITLE_TYPE(titleId) != 0) {
mask = 0xFFFFFFFFFFFFFFFFULL;
} else {
mask = 0x00000000FFFFFFFFULL;
}
ESTitleId regionMask = mask & TITLE_NOREGION_MASK;
int page = 0;
do {
for (int index = 0; index < MAX_CHANNEL_INDEX; index++) {
if (mData.chanInfo[page][index].primaryType == channel::PRIMARY_TYPE_CHANNEL) {
ESTitleId stored = ES_TITLE_ID(mData.chanInfo[page][index].titleType, mData.chanInfo[page][index].titleCode);
if ((stored & mask) == titleId ||
((stored & regionMask) == (titleId & regionMask) && (ESTitleId)(u8)titleId == TITLE_REGION_ALL)) {
if (outIndex) {
*outIndex = page;
}
if (outPage) {
*outPage = index;
}
return stored;
}
}
}
page++;
} while (page < MAX_CHANNEL_PAGE);
return 0;
}
#pragma pop
int Manager::getNumValidChannel() const {
// MWCC needs this page view to preserve the original channel-base calculation.
const ChannelSlot* channelSlot;

View File

@@ -0,0 +1,84 @@
# a2c-hasch attempts
Worktree data-d9; branch agent/w1009/a2c-hasch; base 85d653b0.
Full initial 43U build passed. DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d.
Owned function: hasChannel__Q33ipl8savedata7ManagerCFUxPiPi.
Read opus-common.md, AGENTS.md, opus-sdm, opus-iro, sol-ph1, and o3-idct evidence.
Prior best C: 12 differences, 71/71 instructions, 284/284 bytes.
Prior failures covered mask spelling, helpers, parameter copies, loop forms, and eight declaration orders.
Avoid repeating those sweeps. New method: full target-register map and declaration-order simulation
restricted to implementable locals, then restructure only if captured compiler temporaries require it.
The older simulated exact allocation moved compiler temporaries, so it was diagnostic only.
## Capture and legal declaration search
Corrected a missing closing brace during seed extraction; the failed compile was not measured as C.
Fresh seed build: 12/71 differences, 284/284 bytes; pool identical 3/3.
Baseline completion checker: DECOMPLETE_OK.
Two initial --args captures failed with WRITE_UNMAPPED at 40495a because --args disables automatic
sjiswrap detection. README identifies this exact failure. Recaptured through Ninja flags with sjiswrap.
Fresh capture: /mnt/drive2/projects/wii-ipl-workers/_mwdbg/runs/a2c-hasch-03.
regsim reproduces 53/53 virtual registers. The supplied vmap.py cannot align this function's
save/restore pseudo-instructions: 1 mapped register, 39 unmatched definitions. Used the existing
vmap2.py alignment fallback; it maps 29 registers across 60 instructions with unambiguous wants.
Exhaustive permutations of legal named locals stored/index/page leave all five allocation misses.
The supplied declsearch2.py confirms cost 5. The row-base virtual r45 is @17360; full-mask halves
r46/r47 are @17357. Diagnostic relabel r45 -> 48 alone gives all 29/29 target assignments,
including the two mask-constant registers. This is a required creation-order change, not a
declaration recipe. New hypothesis: preserve a real page view or mask locals so their source
creation order becomes controllable.
Moving the full-mask conditional inside the page loop: 53/71; inside the channel block: 50/71.
Plain SInfo row pointers add a base adjustment: 60/72, 70/72, 67/72.
Explicit nonzero if/else gives 12/71 but moves the row base to the desired r0 and swaps full/region
mask registers; capture this form to distinguish real locals from hoisted temporaries.
Scoped opt_lifetimes, opt_propagation, opt_strength_reduction off: each 12/71.
Scoped opt_loop_invariants off: 29/71. Scoped optimization_level 3: 35/71. Restored seed.
## Exact source
Explicit mask branches preserve mask as a named local; the region-mask expression remains an
IRO temporary when declared in the channel block. Legal declaration search stays at 4 mismatches.
A ChannelPage view makes the row pointer named, but leaves the region temporary ahead of both
row and full mask; legal search stays at 4 mismatches. Restored the experimental header fields.
All row-view candidates were rejected: 14-20 differing instructions, no lasting header edit.
Computing regionMask once outside the loops preserves a real invariant, but default IRO also
hoists titleId & regionMask and changes the instruction stream, 45/71 differences.
A scoped opt_loop_invariants off with this source prevents that extra hoist and produces
0/71 differing instructions, 284/284 bytes, on the first compile. Scoped ppc_iro_level 1 is
also exact, but the narrower loop-invariant switch is retained. Adding opt_common_subs off
is unnecessary. The earlier declaration-only proof identified the temporary-creation blocker;
the accepted source expresses the invariant directly and uses the owner-authorized scoped pragma.
Removed the hasChannel inventory row and decremented function/block/placeholder counts.
Removed the two external save/restore declarations that only the former assembly body used.
## Final validation
Final formatted source rebuilt successfully after removing assembly-only declarations.
Exact-name objdiff: hasChannel fuzzy_match_percent 100.0, size 284.
odiff: 0/71 differing; ctxdiff: 71/71 instructions, diffs 0.
Pool identical 3/3; the complete .data bytes are identical, 184/184.
Unit: 35/35 objdiff and instruction-exact functions; code 7172/7172; data 968/968;
linked code 7172. .data, .rodata, .sdata, and .text all 100.0.
Full 43U build passed. main.dol SHA1 26116613f624061ba99c8d1a299aaa6efa85670d.
Fresh build/43U/report.json passed check_decomp_complete.py: DECOMPLETE_OK.
Gate command: gate.py src/system/iplSaveDataManager --base 85d653b0 --quick.
GATE PASS: zero regressions, zero forbidden additions, zero readability warnings.
The gate reports the scoped optimization pragma for parent review. Target comparison instructions
37 and 39 mask the input title inside the loop; default IRO with an explicit regionMask hoists
those two computations to the preheader. The scoped switch preserves those target lifetimes.
Evidence: /tmp/a2c-hasch-gate.log and /tmp/a2c-hasch-final-build.log.
check_asm_inventory.py still returns 1 solely for the three other owned placeholders:
TMCJPEGDEC_err_restart, CNTCACHEClear, and System::warning_run. There are no missing/stale rows
or coverage failures. Counts match the updated header: 165 functions, 167 bodies/blocks,
162 ORIGINAL, 3 PLACEHOLDER. hasChannel no longer contains assembly.
Experimental header changes and generated dependency files were removed. Only the function,
its inventory removal/counts, and this log are retained. No push, PR, merge, or rebase.