Skip to content

thp: improve THPInit to 89% - #3014

Draft
MarkMcCaskey wants to merge 3 commits into
doldecomp:masterfrom
MarkMcCaskey:match-thpinit
Draft

thp: improve THPInit to 89%#3014
MarkMcCaskey wants to merge 3 commits into
doldecomp:masterfrom
MarkMcCaskey:match-thpinit

Conversation

@MarkMcCaskey

@MarkMcCaskey MarkMcCaskey commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

From Claude:

Reconstructs the missing LC (locked-cache) offset-table setup and its two backing size-descriptor tables, both recovered byte-exact from the target .data. Fixes __THPLCWork672 being wrongly declared extern instead of static. .data and .bss layout now match target exactly; remaining gap is an MWCC address-anchoring difference in the generated code, not a data/logic difference.

This is system code so happy to not use AI here if there are any concerns (feel free to close this PR). Saw this as the lowest matched function on Discord and gave it to Claude Sonnet. Never used Sonnet for this but it looks pretty reasonable.

Reconstructs the missing LC (locked-cache) offset-table setup and its
two backing size-descriptor tables, both recovered byte-exact from the
target .data. Fixes __THPLCWork672 being wrongly declared extern
instead of static. .data and .bss layout now match target exactly;
remaining gap is an MWCC address-anchoring difference in the generated
code, not a data/logic difference.
@MarkMcCaskey MarkMcCaskey added the ai-assisted Utilizes a LLM to do the heavy lifting label Aug 6, 2026
@decomp-dev

decomp-dev Bot commented Aug 6, 2026

Copy link
Copy Markdown

Report for GALE01 (b5530e1 - ab15336)

📈 Matched data: 87.65% (+0.02%, +200 bytes)

✅ 1 new match
Unit Item Bytes Before After
main/dolphin/thp/THPDec .data +81 59.65% 100.00%
📈 2 improvements in unmatched items
Unit Item Bytes Before After
main/dolphin/thp/THPDec THPInit +406 10.60% 89.16%
main/dolphin/thp/THPDec .bss +206 33.33% 85.71%
📉 2 regressions in unmatched items
Unit Item Bytes Before After
main/dolphin/thp/THPDec __THPDecompressiMCURow640x480 -54 97.75% 96.94%
main/dolphin/thp/THPDec __THPDecompressiMCURowNxN -54 98.32% 97.50%

These were dead in the original placeholder source too, but got
dropped while restructuring THPInit; restoring them (unused, but
harmless to keep) also happens to shift MWCC's codegen for the
LC table setup closer to target.
Several fixes to the LC offset-table setup, verified against the target
disassembly:

- Second unrolled loop reads __THPLCSizeTableA, not ...B (target reuses
  table A across the first two loops and table B across the last two).
- Walk the size tables through a pointer (`sizes = __THPLCSizeTableA`
  then `...B`) instead of indexing the statics directly. This matches
  the target's on-demand address materialization and stops MWCC from
  pooling the two tables under one .data base — the single largest gain.
- Build work512/work672 with a running `base` pointer rather than
  reading each prior slot back from memory.
- Correct the work672[1] stride: 0x2800, not 0x2A00 (the sibling
  decompress functions already store 0x2800 there).

Also fold __THPLCTableBase[28] + __THPLCWork512[3] into one struct, so
the object matches the target's single 0x7C .bss symbol (THPDec_804A7400).

Scores measured with GC/1.2.5 (the thp lib's configured compiler) and
cross-checked on 1.2.5n; identical either way.
@MarkMcCaskey MarkMcCaskey changed the title thp: improve THPInit to 78.33% thp: improve THPInit to 89% Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Utilizes a LLM to do the heavy lifting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant