thp: improve THPInit to 89% - #3014
Draft
MarkMcCaskey wants to merge 3 commits into
Draft
Conversation
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.
Report for GALE01 (b5530e1 - ab15336)📈 Matched data: 87.65% (+0.02%, +200 bytes) ✅ 1 new match
📈 2 improvements in unmatched items
📉 2 regressions in unmatched items
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From Claude:
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.