thumb2c tune: learn the HImode literal-pool respellings - #11
Open
wowwheaties wants to merge 2 commits into
Open
Conversation
GCC 2.96 places a Thumb literal pool by the tightest pending fix, and each fix takes its range from the pattern alternative recog chose rather than from the printed text (push_minipool_fix, arm.c:5367; the entries stay sorted by max_address in add_minipool_forward_ref, arm.c:4829). A symbol address spelled through SImode files a 1020-byte fix (*thumb_movsi_insn alt 6, arm.md:3838); held in HImode it files a 64-byte one (*thumb_movhi_insn alt 1, arm.md:4318) and the pool lands where the reference put it. tune now proposes both HImode spellings one site at a time - a one-element u16 array for a symbol-valued local, and the bare halfword constant for a store of a symbol-derived constant - guarded by that early-pool signature in the alignment report and kept only on a strict differing_halfwords improvement. Fixtures: resource_3c9:0200423c 114 -> 0, resource_3a4:02001838 531 -> 111, resource_371:020039fc 513 -> 98. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Two drafts where the HImode respelling is the fix drew no proposal at all: a symbol-valued local written as `s32 data = (s32)Sym;` on one line, which himode_local knew only in its split form, and a symbol value stored straight into a narrow target with no local at all. himode_local now takes the declaration-with-initializer, moving the value to the first statement of the block the declaration opens; himode_store takes a direct halfword-or-narrower store through a one-element u16 temporary declared beside the other locals. Either way the fix files a 64-byte pool range (*thumb_movhi_insn alt 1, arm.md:4318) instead of 1020 (*thumb_movsi_insn alt 6, arm.md:3838), which is what push_minipool_fix records (arm.c:5367). The early-pool guard needed no change: it fires on both reports, only the rewrites were missing. Fixtures at span 192: resource_3ba:02002aec 69 -> 45, resource_3bb:02002d84 67 -> 42; resource_3c9:0200423c still 114 -> 0. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Summary
thumb2c tunelearns the two HImode literal-pool respellings, so drafts whose only residue is an early literal pool can reach exact without hand editing. One site at a time, kept only on a strictdiffering_halfwordsimprovement, and only while the aligned report still shows the candidate's pool behind the reference's. Ordinary C89 source alternatives; no flags, no register or scheduling forcing; nothing outsidetools/thumb2c/.Mechanism (read from the compiler)
GCC 2.96 places a Thumb literal pool by the tightest pending fix, and each fix takes its range from the pattern alternative recog chose, not from the printed text (
push_minipool_fix, arm.c:5367; entries sorted bymax_addressinadd_minipool_forward_ref, arm.c:4829; the barrier chosen increate_fix_barrier, arm.c:5240). A symbol address spelled through SImode files a 1020-byte fix (*thumb_movsi_insnalt 6, arm.md:3838). Held in HImode it files a 64-byte one (*thumb_movhi_insnalt 1, arm.md:4318), which is where the ROM's pool sits in these functions. A plainu16local does not help:PROMOTE_MODE(arm.h:618) widens it back to SImode.s32 p8; p8 = (s32)Sym;(or the one-lines32 p8 = (s32)Sym;) →u16 p8[1]; p8[0] = (u16)(s32)Sym;with every read respelledp8[0]. Refused unless the local is declared once, assigned once from a symbol the unit declaresextern, and read only into halfword-or-narrower stores.rec7[34] = (s32)Sym;): a one-elementu16temporary is declared beside the other locals and the store goes through it.*p = (u16)(s32)Data_00000e00;→*p = 0xe00;(the lifter names such a word by the value the image holds; only values in 1..0xffff qualify).pool_is_late(report): an aligned row where both columns load a pool word and the candidate's is at the higher address.Fixtures (
overlay score <file> --owner <owner> --span <span>)thumb2c tunefrom the draftresource_3c9:0200423c114 -> 0 himode p8[1])resource_3a4:02001838531 -> 111 himode p10[1], then two call respellings)resource_371:020039fchimode *shown = 0x…;steps; the guard turns false after the fifth site, so it stops short of the hand file by design)resource_3ba:02002aechimode data[1], the one-line initializer form); the rest of the hand file is a shared zero and store orderresource_3bb:02002d84himode store, the direct-store form); the residue is allocation-shapedSweep over the 20 remaining near-miss overlay drafts on 7d8a720 (
thumb2c tunefrom each lane's best draft):resource_3af:02002618312 → 43 in onehimode storestep,resource_3b9:02001298346 → 218 andresource_3b7:02000e5c838 → 729 through the existing call respellings; the other owners moved by 0–4.The remaining residue on 3a4 and 371 is allocation and scheduling shaped and goes to the smart queue.
Gates
cargo test(thumb2c): 16 passed; five new unit tests besiderespells_calls_both_ways.make test,make lint(forbidden=0),make tooling-index-check(87 tools),make verify: green.make tooling-size: 46,996 / 50,000.Review notes
scratch/himode/REPORT.md(ignored path, not part of the commit) and was published earlier on ☀️ 73% – adopt seventy-eight exact owners on 2338f8f0a: ten main-image functions and sixty-eight scene sequences #10.🤖 Generated with Claude Code