Skip to content

eZ80: retire NarrowADLPointerTypes — emitter widths from value representations (ADR 0056 Stage C, part 2) - #379

Merged
oisee merged 6 commits into
mainfrom
feat/ez80-retire-narrowing
Dec 1, 2026
Merged

oisee merged 6 commits into
mainfrom
feat/ez80-retire-narrowing

Conversation

@oisee

@oisee oisee commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Stage C part 2 of ADR 0056. NarrowADLPointerTypes and SnapshotADLPointerTypes are deleted. The eZ80 emitter now reads pointer widths from value representations instead of relabelled types.

Changes

  1. Emitter widths.
    • New regWidth(ty) returns 16 for any pointer (one pair) and Ty.Width() otherwise. z80ValueWidth gets the same pointer case. 118 emitter lines use it.
    • Six helpers shared by the allocator and the emitter take the width test as a parameter, so each side behaves exactly as before:
      • computeDeadConsts
      • directStoreAddressValues
      • callArgumentAddressConstants
      • cmpOperandIsWord
      • byteComparison
      • verifySignedWordOperands
    • Byte-loop codegen tests IsPointer.
    • In the z80cg files, .Width() calls drop from 154 to 8. The 8 left are storage widths or MIR passes.
  2. Assert judging. With 24-bit contract types, AssertValueMatches masks a pointer result to 24 bits. eZ80 verdicts are unchanged.
  3. Deletion.
  4. adl_upper widths. adlCallUses and adlReturnUses take parameter and return narrowness from Func.Reprs/ReprOf (adlSignatures). Header type names are now only a fallback.
  5. ADR 0056 gets a "Status after part 2" section.

Gates (full set, against main 8b6d96c with #376 and #378; then #377 merged and spot-checked)

Z80

  • compile_sweep: 0 output changes.
  • C bench: 1.0000 T and 1.0000 bytes.
  • Fast profile: PASS.
  • assert_matrix and test_judges: OK.
  • Fuzz: direct-call 0–19999 20000/20000, --signed 4000/4000, folded 3000/3000, byte-shifts 3000/3000.
  • go test -short (ci.yml list): 18 ok.

Z80N

  • Corpus and bench: byte-identical.
  • fuzz_diff --target z80n: 1000 + 1000.

eZ80

  • Sweep: failures identical to main.
  • fuzz_diff: 2000 + 2000.
  • fuzz_ptr: 2000.
  • fuzz_nowrap: 2000, with 6498 folds as on main.
  • Bench geomean: 1.0000.
  • Large eZ80 benchmark program: identical (v4 1,785,616, v0 2,728,746).
  • Player: byte-exact, 11180 frames.

Left (recorded in the ADR)

  • The allocator still measures widths through types, with mixed results when switched.
  • Explicit MIR widening conversions.
  • Representations recorded at HIR→MIR lowering.
  • pairs24() copies as value queries.
  • The inliner and splitter asking the target.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS

oisee and others added 6 commits December 1, 2026 09:11
…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
…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
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

PR tests: 🟢 pass

Commit: 959e670f · Full test log

Check Result
Complete fresh Ruby/Crystal native pipeline 🟢 pass
Inherited compiler and complete frozen native gates 🟢 pass
Build mz, mza, mze, mzv 🟢 pass
Fast compiler regressions (deep suites run separately) 🟢 pass
Fibonacci compile + assemble 🟢 pass
Nanz language regressions 🟢 pass
Z3 West of House demo 🟢 pass
Z3 small conformance fixtures 🟢 pass

Deep pipeline domains and the full assertion corpus run on release tags, nightly and manual audits.
The external CZECH and full Zork I stories are not part of this PR gate.

@oisee
oisee merged commit b6132f8 into main Dec 1, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant