Repository navigation
Carry .b128 registers as UInt128 on the NVPTX q constraint - #173
Merged
Merged
Conversation
LLVM's NVPTX backend allocates a PTX .b128 register for an i128 inline-asm operand under the `q` constraint (sm_70+, the floor of every .b128 form). The ledger had assumed no such constraint existed and bridged each value as two UInt64 words through block-local .b128 registers with mov.b128 pack/unpack inside the asm text. B128 is now an alias for UInt128, and the emitter names .b128 operands directly (`ld.global.b128 $0, [$1];` with `=q,l`). LLVM does the register packing itself, so the emitted PTX keeps the same shape while the asm strings lose their bridge. b128(lo, hi) and b128(x0, x1, x2, x3) pack words low-first into the UInt128, and the transpiler emits b128(...) for both mov.b128 pack widths. Below sm_70 the backend reports "Inline asm with 128 bit operands is only supported for sm_70 and higher!" as a compile diagnostic. Breaking: code that destructured a B128 as a tuple or built one as (lo, hi) needs b128(lo, hi) and integer shifts instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
The scalar
.b128ledger assumed LLVM's NVPTX inline asm has no 128-bit register constraint. So each value crossed the asm boundary as twoUInt64words, bridged through block-local.b128registers withmov.b128pack/unpack written into the asm text. The constraint does exist:qallocates a PTX.b128register for ani128operand on sm_70+, the floor of every.b128form. It's in the pinned backend (checked on LLVM 22 and on libnvptx 23.1.1).Changes
B128is now an alias forUInt128(previouslyNTuple{2,UInt64}), andconstraint_letter(UInt128) = "q".b128(lo, hi)andb128(x0, x1, x2, x3)pack words low-first into theUInt128, the lane order ofmov.b128 d, {lo, hi}.b128(::UInt128)is the identity.B128Ledgeremitter names.b128operands directly and drops the declaration/setup/teardown bridge. For example,ld.global.b128goes from=l,=l,lwith a wrapped asm block told.global.b128 $0, [$1];with=q,l.b128(...)for bothmov.b128pack widths (previously a bare tuple for the two-.b64form).dsl.md.b128section and themovnote inSURFACE.toml.Emitted PTX
The instruction sequence is unchanged; the pack/unpack moves out of the asm string into LLVM's own code:
Values do not stay in
%rqregisters between asm blocks.i128is still legalized into twoi64in between, so a load feeding a store round-trips through%rdpairs as it did before. This change simplifies the representation; it isn't a codegen win.Below sm_70, libnvptx reports
Inline asm with 128 bit operands is only supported for sm_70 and higher!as a compile diagnostic, not a process abort.Breaking
Code that built a
B128as(lo, hi)or destructured one as a tuple now usesb128(lo, hi)and integer ops (x % UInt64,(x >> 64) % UInt64).Verification
Full local suite on the GB10 (CC 12.1, CUDA 13.4): 237,975 passed, 0 failed. That includes
gpu/b128_load_store(runtime round-trip of both words) andptxas/b128_forms(sm_75/80/90/100 partitions).Independent of #172; the two touch disjoint lines.
🤖 Generated with Claude Code