Skip to content

Translator: v_mqsad_u32_u8 - #796

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:valu-mqsad-u32
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:valu-mqsad-u32

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

tools/rdna2spirv.py raises Unsupported on v_mqsad_u32_u8. It's the last of the GFX10 SAD family, after v_sad* / v_msad_u8 (#544) and v_qsad_pk_u16_u8 / v_mqsad_pk_u16_u8 (#623). It isn't in the translated corpus, so this is future-proofing. Claimed in #374.

Change

  • tools/rdna2spirv.py follows the RDNA ISA pseudocode. S0 is 64 bits, S1 is 32 bits, and S2 and D are 128 bits (four VGPRs):
    • D[k] = S2[k] + v_msad_u8(S0[8k+31 : 8k], S1), wrapping at 32 bits.
    • The four windows slide over S0 one byte at a time, as in v_qsad_pk_u16_u8, but each result is a whole dword with its own 32-bit accumulator. A byte where S1's byte is 0 adds nothing.
    • S0 can be a VGPR or SGPR pair, or a 64-bit inline constant. All four sources are read before D is written. clamp raises Unsupported instead of being guessed.
    • The code sits after the v_sad* block, so it doesn't overlap Translator: v_qsad_pk_u16_u8 and v_mqsad_pk_u16_u8 #623, which goes before it.
  • tests/test_translate.py and tests/test_f16_op_sel.py used v_mqsad_u32_u8 as their example of an unsupported instruction. They now use v_sat_pk_u8_i16, which exists on GFX10 and stays unsupported.
  • tests/semantic/test_alu_mqsad_u32.py (new, stdlib unittest) checks D against a plain-Python reference:
    • a 5×5 edge grid with accumulators that wrap
    • 25 seeded cases, including masked bytes
    • an SGPR source pair
    • clamp rejected
    • D leaves exp as eight 16-bit halves ORed into 0x40000000, so no export channel can be a NaN pattern

Tested

  • python -I -m unittest discover -s tests/semantic: all pass. Without the translator change, the new file has 51 errors (Unsupported).
  • tests/test_f16_op_sel.py: 34/34 through a local stand-in for pytest, because I can't install pytest here. tests/test_translate.py needs llvm-mc, so CI runs it.
  • python -m compileall -q tools tests passes. Not run on a GPU, and no game files used.

AI-assisted (Claude Code): it wrote the change and the tests, and ran the checks listed above.

v_mqsad_u32_u8 raised Unsupported. Four masked byte-SADs with full 32-bit
accumulators (RDNA ISA pseudocode): D[k] = S2[k] + v_msad_u8 of S0's 32-bit
window at byte k against S1. S0 is a 64-bit pair, S2 and D four VGPRs.
clamp is rejected.

tests/semantic/test_alu_mqsad_u32.py checks it against a plain-Python
reference. test_translate.py and test_f16_op_sel.py used it as their example
of an unsupported instruction; they now use v_sat_pk_u8_i16.

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

matches the pseudocode: masked byte-SAD per window, 32-bit wrapping accumulators, every source read before the first write (good for overlapping regs), and clamp is refused. tests pass merged with main o7 AI-assisted review (Claude Code).

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026

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

Tested 4a8d410 on NVIDIA GeForce RTX 5070 (subgroup 32), driver 621.24, Windows 11 Pro (26300), Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (built with scripts/build_llvm_mc.ps1), scripts/run_gpu_tests.py:

  • native: 70/97 passed, 27 skipped (main 8df277f here: 64/91 passed, 27 skipped, all wave64 tests needing a 64-wide subgroup)
  • LEONIDA_W64_EMULATE=1: 97/97 passed (main here: 91/91)
  • python -m unittest discover -s tests/semantic: Ran 977 tests in 201.525s OK

@ItsNotRexed
ItsNotRexed merged commit 5dd199f into ItsNotRexed:main Nov 22, 2026
10 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.

4 participants