Repository navigation
Translator: v_mad_u64_u32 and v_mad_i64_i32 (carry-out lane mask in sdst) - #546
Merged
Merged
Conversation
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.
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.
tools/rdna2spirv.pyraisesUnsupportedonv_mad_u64_u32andv_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 + S2as 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 with65'Ifor the signed op).OpUMulExtended/OpSMulExtended, and S2 is added with anOpIAddCarrychain. No Int64 is needed.v_lshlrev_b64.mask_dst, like the carry ofv_add_co_u32, andnullis skipped. It gets bit 64:v_mad_u64_u32, the carry outv_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.clampraisesUnsupported.tests/semantic/test_alu_mad64.py(new, stdlibunittest) checks D and lane 0's sdst bit against a plain-Python 65-bit reference:nullsdst and with a real onev_add_co_ci_u32expas 16-bit halves ORed into0x40000000, so no export channel can be a NaN pattern (see the review on tests/semantic: export test_alu_shift_b64 results in 16-bit halves (fixes CI on Python < 3.14) #454).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 testspasses. Not run on a GPU, and no game files used.The sdst of
v_mad_i64_i32follows the pseudocode literally, and that hasn't been measured on hardware. The contract row says so. A test that would settle it is0 × 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.