Skip to content

Shaders: the v_mad_u64_u32 carry on its dwords (AMD answers the i64 compare wrong when the addend shares a register) - #205

Open
murillojndem wants to merge 1 commit into
DexNom:mainfrom
murillojndem:fix/amd-mad-u64-carry-dwords
Open

murillojndem wants to merge 1 commit into
DexNom:mainfrom
murillojndem:fix/amd-mad-u64-carry-dwords

Conversation

@murillojndem

Copy link
Copy Markdown

The carry out of v_mad_u64_u32 is r < c (unsigned), with r the low 64 bits of a * b + c. It is lowered as one i64 icmp. When the addend shares a register with the second factor (v_mad_u64_u32 v[5:6], s20, v1, v2, v[2:3]), AMD's D3D12 compiler gives the wrong carry. On main (4ad8692) and an RX 7900 XT (driver 32.0.32015.7029), the carry is wrong in 124 of 324 cases in that form, for example v_mad_u64_u32(0, 1, 1) gives carry 1. With the addend in its own pair, the carry is right in every case, both result dwords are right in both forms, and WARP is right throughout.

The carry is now computed on the dwords of r and c: the high dword of r below c's, or equal high dwords and the low dword of r below c's. The result dwords do not change.

Test v_mad_u64_u32_matches_its_definition checks the carry and both result dwords for 6 x 6 factors and 9 addends, with the addend in v[3:4] and sharing v2 in v[2:3]. It counts every mismatch by device, form and output before it fails.

Marvisak/VIctory@cc7ec2a (Marvisak#1599) changed the compares but not this carry. Marvisak#3082 (RVZO6, open) splits the same carry compare, together with other changes. The same test gave the same count with the same lowering in fxceless/victory-fork#1507. This PR does not depend on #204 (the 64-bit compares); the two apply together and their tests pass together.

Results on 4ad8692:

Not run on NVIDIA hardware; on a device that compares correctly, the dword form gives the same carry as the single compare.

Claude (Anthropic) wrote the change and the test and ran the verification.

Generated with Claude Code

The carry is r < c (unsigned), with r the low 64 bits of a * b + c. As
one i64 icmp, AMD's D3D12 compiler answers it wrong where c shares a
register with the second factor: 124 of 324 cases on an RX 7900 XT;
WARP is right. It is now computed on the dwords of r and c.

Co-Authored-By: Claude Opus 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.

1 participant