Repository navigation
eZ80: retire NarrowADLPointerTypes — emitter widths from value representations (ADR 0056 Stage C, part 2) - #379
Merged
Merged
Conversation
…ge C part 2, steps 1-2) The emitter picks a value's path by width: 8 = byte register, 16 = one pair, wider = main+alternate pair. A pointer is one pair on every target (ReprPtr16, or ReprPtr24 whose pair holds all 24 bits), so the width tests now ask regWidth(ty), which is 16 for every pointer, instead of Ty.Width(), which is 24 for an eZ80 pointer type. z80ValueWidth gets the same pointer case. Until now NarrowADLPointerTypes relabelled the types so that Ty.Width() said 16; with these tests the relabelling no longer decides anything (its removal is the next commit). - 118 Ty.Width() tests inside z80cg methods and those of the emitter-only helpers (adlNoWrapIncrements, scanTSMCSpillPairs, byteSmallStep, ptrAddConstantFolds) become regWidth. - Helpers shared by the allocator and the emitter (computeDeadConsts, directStoreAddressValues, callArgumentAddressConstants, cmpOperandIsWord, byteComparison, verifySignedWordOperands) take the width test: the allocator keeps type widths (typeWidth), the emitter and the codegen-time remat repair use regWidth. That is what each side saw before (the allocator ran on 24-bit types, the emitter on relabelled ones), so output does not change; making the allocator agree is a measured follow-up. - Byte-loop codegen tests "the result is a pointer" with IsPointer instead of identity with TyPtr (a relabelled ^u8 was TyPtr; a 24-bit one is not). The sites were found by tracing every Width() call on a 24-bit pointer type during emission over the corpus, the player, both large-program versions, the C benchmark, the eZ80 assert sweep and 300+300 fuzz seeds: the remaining ones are storage (global data, struct layout) or already pointer-aware. Verified: eZ80 products (corpus text, player, large program, C benchmark asm both profiles) identical to main; Z80 compile_sweep 0 changes; Z80N corpus and C benchmark products identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
…056 Stage C part 2, step 3) The emitter now reads value widths from representations (previous commit), so the relabelling of 24-bit pointer types as 16-bit before emission and the snapshot that undid it after the call-write prediction are gone. The module keeps its 24-bit pointer types from HIR lowering to the assembly. LowerADLConversions (pointer->pointer and pointer->u16 conversions become moves) moves from emission to just before allocation, after the last MIR rewrite: the snapshot existed to undo its op changes after the trial emission, and the allocator now sees the same moves as the emitter. eZ80 assert judging reads the contract types after emission, which are now 24-bit for pointers: readEZ80Return already reads 24 bits of a pointer, and AssertValueMatches now masks a pointer result to 24 bits instead of 16 (a result with a non-zero bank could only fail before). The eZ80 assert sweep gives the same verdicts as main (1065 pass, same failure list). Products: one eZ80 product changes, examples/c89/func_ptr.c: in a caller of two indirect calls the function-pointer copy is a move before allocation and coalesces, 34 -> 29 bytes for that call sequence (image 171 -> 166) (LD DE,sub / LD BC,10 / LD IX,5 instead of PUSH HL / POP IX / ... / LD D,IXH / LD E,IXL); its asserts pass. Corpus otherwise, player, both large-program versions and the C benchmark (both profiles) are identical to main. Z80 compile_sweep 0 changes; Z80N products identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
…s (ADR 0056 Stage C part 2, step 6) adlCallUses and adlReturnUses decided from the type names in the function headers whether a parameter's or return value's pair keeps a live upper byte across a call or a RET (narrow set u8/i8/bool/u16/i16; return "ptr"). For module functions they now take the decision from the value representations (adlSignatures: ReprByte/ReprWord parameter = narrow; a single return is narrow, or a 24-bit pointer whose upper byte stays live). Homes and clobbers are still read from the header text; a header of a function the module does not have (unit tests, hand-written text), or one whose parameter count differs from the signature, falls back to the type names. verifyADLHeaderWidths stays for that fallback. Differences from the text decision: a 16-bit or byte value whose type prints under another name (an alias) is narrow, and a typed pointer return (^T) keeps its pair with the upper byte instead of keeping every register. Neither occurs in the measured products: eZ80 corpus, player, both large-program versions and the C benchmark are identical to the previous commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
…rowing The no-wrap proofs are taken first, on the same MIR #376 measured; the ADL conversion lowering follows, before PreallocCoalesce. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
PR tests: 🟢 passCommit:
Deep pipeline domains and the full assertion corpus run on release tags, nightly and manual audits. |
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.
Stage C part 2 of ADR 0056.
NarrowADLPointerTypesandSnapshotADLPointerTypesare deleted. The eZ80 emitter now reads pointer widths from value representations instead of relabelled types.Changes
regWidth(ty)returns 16 for any pointer (one pair) andTy.Width()otherwise.z80ValueWidthgets the same pointer case. 118 emitter lines use it.computeDeadConstsdirectStoreAddressValuescallArgumentAddressConstantscmpOperandIsWordbyteComparisonverifySignedWordOperandsIsPointer.z80cgfiles,.Width()calls drop from 154 to 8. The 8 left are storage widths or MIR passes.AssertValueMatchesmasks a pointer result to 24 bits. eZ80 verdicts are unchanged.LowerADLConversionsnow runs once before allocation, after the no-wrap proofs (eZ80: no-wrap range facts restore the index fold (fusion_window_sum 2× faster) + widening byte-add wrong-code fix #376), so the allocator and the emitter see the same moves.examples/c89/func_ptr.c: a function-pointer copy now coalesces, so the image goes from 171 to 166 bytes. Its asserts pass.adl_upperwidths.adlCallUsesandadlReturnUsestake parameter and return narrowness fromFunc.Reprs/ReprOf(adlSignatures). Header type names are now only a fallback.Gates (full set, against main 8b6d96c with #376 and #378; then #377 merged and spot-checked)
Z80
--signed4000/4000, folded 3000/3000, byte-shifts 3000/3000.go test -short(ci.yml list): 18 ok.Z80N
fuzz_diff --target z80n: 1000 + 1000.eZ80
fuzz_diff: 2000 + 2000.fuzz_ptr: 2000.fuzz_nowrap: 2000, with 6498 folds as on main.Left (recorded in the ADR)
pairs24()copies as value queries.🤖 Generated with Claude Code
https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS