Repository navigation
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
Conversation
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>
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.
The carry out of
v_mad_u64_u32isr < c(unsigned), with r the low 64 bits of a * b + c. It is lowered as one i64icmp. 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. Onmain(4ad8692) and an RX 7900 XT (driver 32.0.32015.7029), the carry is wrong in 124 of 324 cases in that form, for examplev_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_definitionchecks the carry and both result dwords for 6 x 6 factors and 9 addends, with the addend inv[3:4]and sharingv2inv[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:maingiveshardware v[2:3] carry: 124 of 324 wrongand nothing else; with the change, no mismatch on the card or on WARP.main(PSV0 with the SDK 22621dxil.dll, and three pipelines WARP refuses).v[3:4], 69 inv[2:3]).cargo clippy -p victory-shader --all-targets --locked -- -D warningsis clean with and without--all-features,cargo xtask policypasses, and rustfmt reports nothing new.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