Skip to content

Translator: v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32, v_msad_u8 - #544

Merged
ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
LouisRiverstone:valu-sad
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
LouisRiverstone:valu-sad

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

tools/rdna2spirv.py raises Unsupported on the sum-of-absolute-differences ops: v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8. They aren't in the translated corpus, so this is future-proofing. Claimed in #374.

Change

  • tools/rdna2spirv.py follows the RDNA ISA pseudocode. Everything is unsigned and wraps at 32 bits:
    • v_sad_u8: S2 + Σ over the 4 bytes of |S0.b − S1.b|
    • v_sad_hi_u8: S2 + (that byte sum << 16)
    • v_sad_u16: S2 + Σ over the 2 halves of |S0.h − S1.h|
    • v_sad_u32: S2 + |S0 − S1|
    • v_msad_u8: like v_sad_u8, but a byte is skipped where S1's byte is 0 (masked SAD)
    • Each |a − b| is UMax − UMin of the extracted fields.
    • clamp raises Unsupported instead of being guessed. The pseudocode doesn't define what clamp does to these ops.
  • tests/semantic/test_alu_sad.py (new, stdlib unittest) checks against a plain-Python reference:
  • tests/test_translate.py and tests/test_f16_op_sel.py used v_sad_u8 as their example of an unsupported instruction. They now use v_mqsad_u32_u8, which stays unsupported. The destination doesn't overlap the sources, because LLVM marks that op's vdst early-clobber.

Tested

  • python -I -m unittest discover -s tests/semantic: all pass. Without the translator change, the new file has 446 errors (Unsupported). It also passes with the interpreter forced to quiet signalling NaNs.
  • tests/test_f16_op_sel.py: 34/34 pass through a local pytest stand-in, because I can't install pytest here. That includes the changed test_other_unsupported_instructions_are_still_rejected. I couldn't run tests/test_translate.py, because it needs llvm-mc; CI runs it.
  • An ad-hoc differential run: 300 cases per op, 0 mismatches.
  • 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.

All five raised Unsupported. They add the sum of absolute differences of the
sources' bytes / halves / words to S2 (unsigned, wrapping at 32 bits), as in
the RDNA ISA pseudocode; v_sad_hi_u8 shifts the byte sum left by 16 and
v_msad_u8 skips the bytes where S1's byte is 0. clamp is rejected, not
guessed.

tests/semantic/test_alu_sad.py checks all five against a plain-Python
reference. test_translate.py and test_f16_op_sel.py used v_sad_u8 as their
example of an unsupported instruction; they now use v_mqsad_u32_u8.
@ItsNotRexed
ItsNotRexed merged commit e4375b4 into ProjectLeonida:main Nov 22, 2026
5 of 9 checks passed
@kacper-serewis

Copy link
Copy Markdown
Contributor

Tested 7a86a2e on RTX 5070 (Blackwell, subgroup 32..32), NVIDIA 616.56, Windows 11 Pro 26200: pass.

No GPU shader in the suite uses the v_sad/v_msad ops yet, so the GPU run is a regression check only.

Tools: llvm-mc 21.1.8 (WSL), Vulkan SDK 1.4.363.0, MSVC 19.50, Python 3.13.

ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
…ROC-20)

#544, #549 and #577 merged without a row in the contract table, which
AGENTS.md asks for. One row per group, each with the semantics (checked
against the RDNA2 ISA pseudocode), what is not handled (clamp on the SAD and
lerp ops) and how it was confirmed (the CPU tests added by the PR); none is
GPU-checked.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

3 participants