Repository navigation
Translator: track v_mad_u64_u32 and v_mad_i64_i32 sdst as lane masks - #958
Merged
ItsNotRexed merged 1 commit intoNov 22, 2026
Merged
Conversation
v_mad_u64_u32 and v_mad_i64_i32 write their 64-bit carry/sign output sdst (a[1]) via mask_dst in rdna2spirv.py, matching *_co_* vector carry ops, and shader_meta.py already groups them together. lane_masks.step() only checked '_co_' in op, causing whole-wave mask consumers (s_bcnt1_i32_b64, s_ff1_i32_b64, v_mbcnt) to treat sdst as plain per-lane data and produce divergent SGPR results (e.g. 64 in carrying lanes and 0 in non-carrying lanes). Verified on CPU with tests/test_lane_masks.py, tests/semantic/test_alu_mad64.py (including 64-lane wave64 s_bcnt1_i32_b64/s_ff1_i32_b64 tests) and tests/semantic/test_wave64_scmp_masks.py.
Contributor
|
Tested 060dded on Windows 11 (Python 3.12, llvm-mc 23.1.6 with AMDGPU, spirv-tools): pass
|
IAmNotSiob
approved these changes
Nov 22, 2026
IAmNotSiob
left a comment
Contributor
There was a problem hiding this comment.
right, the sdst of v_mad_u64_u32/i64_i32 is a per-lane carry mask like the co ops. tests pass with main o7 AI-assisted review (Claude Code).
|
GPU check of
|
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.
Claimed in the coordination issue as: #634 (comment)
What and why
tools/rdna2spirv.pywrites the scalar carry/sign outputsdst(a[1]) ofv_mad_u64_u32andv_mad_i64_i32viaself.mask_dst(sd, m)(per-lane0xFFFFFFFF/0), andtools/shader_meta.py::_split_operandsalready groups them with*_co_*. However,tools/lane_masks.py::step()only checked_co_ in op:python if op.startswith(v_) and _co_ in op and len(a) > 1: put(state, a[1], MASK)As a result, when a wave64 shader feeds the
sdstofv_mad_u64_u32/v_mad_i64_i32into a whole-wave mask consumer such ass_bcnt1_i32_b64,s_ff1_i32_b64orv_mbcnt_*, the translator treated the SGPR pair as plain 64-bit data and produced divergent per-lane garbage (e.g.s_bcnt1_i32_b64returned64in lanes that carried and0in all other lanes instead of the uniform wave count).Fix:
op in (v_mad_u64_u32, v_mad_i64_i32)alongside_co_ in opintools/lane_masks.py::step().tests/test_lane_masks.py(SGPR pair,vcc, andnull) and 64-lane compute tests intests/semantic/test_alu_mad64.py(s_bcnt1_i32_b64ands_ff1_i32_b64over bothv_mad_u64_u32andv_mad_i64_i32).v_mad_u64_u32/v_mad_i64_i32row indocs/design.md.Note on overlap: touches line 158 of
tools/lane_masks.py(clean againstmain067d3e8; open PR #293 also editstools/lane_masks.pynearby).Tested
CPU-only on Windows 11, Python 3.11.9 (no GPU run, no
spirv-val/llvm-mc, no game files):python -m compileall -q make_game.py tools tests— exit 0python -I -W error::ResourceWarning tests/test_lane_masks.py—okpython -I -W error::ResourceWarning tests/semantic/test_alu_mad64.py -q— 7/7 OK (including 64-lanerun_workgroupballot tests)python -I tests/semantic/test_wave64_scmp_masks.py -q— 6/6 OKAI-assisted.
Checklist
docs/design.md, with how it was confirmed.