Skip to content

Translator: v_mad_u64_u32 and v_mad_i64_i32 (carry-out lane mask in sdst) - #546

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

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
LouisRiverstone:valu-mad64

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

tools/rdna2spirv.py raises Unsupported on v_mad_u64_u32 and v_mad_i64_i32. These are the 32 × 32 + 64 multiply-adds that compilers use for 64-bit address and index arithmetic. They aren't in the translated corpus, so this is future-proofing. Claimed in #374.

Change

  • tools/rdna2spirv.py: {sdst, D} = S0 × S1 + S2 as a 65-bit result, as the RDNA ISA pseudocode writes it ({ D1.u1, D0.u64 } = 65'B(65'U(S0.u32) * 65'U(S1.u32) + 65'U(S2.u64)), and the same with 65'I for the signed op).
    • The product comes from OpUMulExtended / OpSMulExtended, and S2 is added with an OpIAddCarry chain. No Int64 is needed.
    • S2 can be a VGPR or SGPR pair, or a 64-bit inline constant, sign-extended as for v_lshlrev_b64.
    • sdst is a lane mask written through mask_dst, like the carry of v_add_co_u32, and null is skipped. It gets bit 64:
      • for v_mad_u64_u32, the carry out
      • for v_mad_i64_i32, the sign of the exact sum. That is bit 64 of a 65-bit two's-complement value, which isn't the same as a signed-overflow flag.
    • clamp raises Unsupported.
  • tests/semantic/test_alu_mad64.py (new, stdlib unittest) checks D and lane 0's sdst bit against a plain-Python 65-bit reference:
  • docs/design.md: a contract row for the sdst rule.

Tested

  • python -I -m unittest discover -s tests/semantic: all pass. Without the translator change, the new file has 234 errors (Unsupported).
  • python -m compileall -q tools tests passes. Not run on a GPU, and no game files used.

The sdst of v_mad_i64_i32 follows the pseudocode literally, and that hasn't been measured on hardware. The contract row says so. A test that would settle it is 0 × 0 + (−1): the pseudocode gives sdst = 1, while a signed-overflow reading would give 0.

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

Both raised Unsupported. {sdst, D} = S0 * S1 + S2 as a 65-bit result (RDNA ISA
pseudocode): a 32 x 32 -> 64-bit product, unsigned or signed, plus the 64-bit
S2, built from OpUMulExtended/OpSMulExtended and an OpIAddCarry chain. sdst
gets bit 64 as a lane mask: the carry out for u64, the sign of the exact sum
for i64. clamp is rejected.

tests/semantic/test_alu_mad64.py checks D and the sdst bit against a
plain-Python reference, a null sdst, an inline accumulator, and the carry
feeding v_add_co_ci_u32; docs/design.md gets a contract row.
@ItsNotRexed
ItsNotRexed merged commit 3dee137 into ItsNotRexed:main Nov 22, 2026
5 of 9 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.

2 participants