Skip to content

Translator: track v_mad_u64_u32 and v_mad_i64_i32 sdst as lane masks - #958

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
edwin042331-hue:fix/lane-masks-mad64
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
edwin042331-hue:fix/lane-masks-mad64

Conversation

@edwin042331-hue

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #634 (comment)

What and why

tools/rdna2spirv.py writes the scalar carry/sign output sdst (a[1]) of v_mad_u64_u32 and v_mad_i64_i32 via self.mask_dst(sd, m) (per-lane 0xFFFFFFFF / 0), and tools/shader_meta.py::_split_operands already 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 sdst of v_mad_u64_u32 / v_mad_i64_i32 into a whole-wave mask consumer such as s_bcnt1_i32_b64, s_ff1_i32_b64 or v_mbcnt_*, the translator treated the SGPR pair as plain 64-bit data and produced divergent per-lane garbage (e.g. s_bcnt1_i32_b64 returned 64 in lanes that carried and 0 in all other lanes instead of the uniform wave count).

Fix:

  • Match op in (v_mad_u64_u32, v_mad_i64_i32) alongside _co_ in op in tools/lane_masks.py::step().
  • Add unit tests in tests/test_lane_masks.py (SGPR pair, vcc, and null) and 64-lane compute tests in tests/semantic/test_alu_mad64.py (s_bcnt1_i32_b64 and s_ff1_i32_b64 over both v_mad_u64_u32 and v_mad_i64_i32).
  • Update the v_mad_u64_u32/v_mad_i64_i32 row in docs/design.md.

Note on overlap: touches line 158 of tools/lane_masks.py (clean against main 067d3e8; open PR #293 also edits tools/lane_masks.py nearby).

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 0
  • python -I -W error::ResourceWarning tests/test_lane_masks.py — ok
  • python -I -W error::ResourceWarning tests/semantic/test_alu_mad64.py -q — 7/7 OK (including 64-lane run_workgroup ballot tests)
  • python -I tests/semantic/test_wave64_scmp_masks.py -q — 6/6 OK

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

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.
@kapitche

Copy link
Copy Markdown
Contributor

Tested 060dded on Windows 11 (Python 3.12, llvm-mc 23.1.6 with AMDGPU, spirv-tools): pass

  • pytest tests/test_translate.py tests/semantic/test_alu_mad64.py tests/test_lane_masks.py: 284 passed, 232 subtests
  • Negative control: with tools/lane_masks.py from main, 3 fail. The change is in the mask analysis, so rdna2spirv.py itself is untouched.

@IAmNotSiob IAmNotSiob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@poststructural

Copy link
Copy Markdown

GPU check of 060dded on Linux: NVIDIA GeForce RTX 2080 (Turing, subgroup 32), driver 610.57.04, llvm-mc 21.1.8, GCC build of runtime/. AI-assisted.

  • scripts/run_gpu_tests.py: 74/101 passed, 27 skipped (skips = wave64, no 64-wide subgroup); LEONIDA_W64_EMULATE=1: 101/101 passed.
  • python -m unittest discover -s tests/semantic: Ran 1022 tests, OK.

main (067d3e8) on the same machine: 74/101 native, 101/101 emulated.

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.

5 participants