s_lshl<n>_add_u32 sets SCC to its carry #1972
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!1972
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1972"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Melow-code on GitHub · 2026-11-29 04:59 UTC · original
fix/lshl-add-carry→main· +68 −3 · 3 files · 1 commits · closed without mergingFound by reading the scalar lowering against the RDNA 2 ISA. I found no issue or pull request for it here. It is a known defect elsewhere, with the same formula proposed: Marvisak/VIctory#168 and fxceless/victory-fork#350 (both open; their
s_min/s_maxhalf is already here through #1891). Marvisak/VIctory#2813 refuses such reads instead.What it changes
s_lshl1_add_u32tos_lshl4_add_u32left "the result is not zero" in SCC. The RDNA 2 ISA (12.1) gives the unsigned overflow of the whole sum, shifted-out bits included:An
s_addc_u32behind one, the high dword of a 64-bit address, therefore added 1 whenever the low dword was not zero. A branch or ans_cselectbehind one could take the wrong side.SCC is now the carry: the shift loses a set bit, or the addition wraps. Lyrnc measured this rule, lost bits included, on RDNA 2 hardware (gfx1036) in Marvisak/VIctory#168: 141 of 141 operand pairs for each of the four opcodes.
The change is in
sopinemit/lower.rs. The test evaluator inbitcode.rs(test code) learnsor, zero extension and three integer compares.How it was tested
shift_and_add_leave_their_carry_in_scclowers the four opcodes, each followed bys_addc_u32 s7, 0, 0, and evaluates what the module stores for 13 operand pairs (no carry, each lost bit, wraps, both). It runs on any host, without a device.(0x1 << 1) + 0x2: 1 where 0 is right.s_addc_u32twice, against 64-bit arithmetic, and 5,000 per opcode with a literal, an inline -1 and the destination over a source, read bys_cselect_b32. 400,000 values, no mismatch; both fail with the change reverted.s_add/s_addc,s_sub/s_subb,s_add_i32ands_lshl_b32give the right values before and after.e1f2eb60:cargo test -p victory-formats -p victory-shader --lib: 57 and 274 passed, 0 failed (5 and 2 ignored).CARGO_FEATURE_PURE=1 cargo clippy -p victory-gpu -p victory-shader --tests --target x86_64-pc-windows-msvc: exit 0, no warning on the changed lines. The existing one invictory-shader(manual_checked_ops) is still there.lower.rsis past thecargo xtask policysize limit on main already.Checked for overlap
🤖 Generated with Claude Code
@dyshay on GitHub · 2026-11-29 13:05 UTC · original
Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch
janus-prs, on top of829188e9plus a couple of local fixes). Read the full diff first: no network, process spawning, binaries, build/CI/dependency changes or game data. Builds with--profile diag --features diagnostics; one conflict only: on our branch the lower.rs tests live inlower/tests.rs, so the new test moved there unchanged. Targeted shader tests pass. In-game runs on an RTX 4090 are queued; results will follow here.github-bot referenced this pull request2026-11-29 22:46:14 +00:00
@Lyrnc on GitHub · 2026-11-30 06:11 UTC · original
Checked this against a Radeon gfx1036 (RDNA 2) running the same kernels natively, and ran the translator's output for main and for this PR on an RTX 5080 and on that Radeon through D3D12.
Setup
mainat41adb551with this PR's head (c4848d8) merged locally. The lowering change merged without a conflict; your testshift_and_add_leave_their_carry_in_sccsits in the oldmod testsoflower.rs, which main has moved, so it is not part of this build. The victory-shader test binary was built from that merged tree (own tree and target directory).super::emit(32-lane host),dxil.dllvalidation, dispatched on the 5080 and on the Radeon (VICTORY_ADAPTER=radeon).Cases
For each of
s_lshl1_add_u32..s_lshl4_add_u32, 8 operand pairs, with SCC set to the opposite of the expected carry by ans_cmp_eq_u32right before:lshl_add/<n>: the result and SCC throughs_cselect_b32 s43, 1, 0.lshl_addc/<n>: the high dword of an address,s_addc_u32 s44, 0x100, 0right after.Pairs: (0x80000000, 0) only lost bits, (1, 2) no carry, (0x40000000, 0xC0000000), (0x7FFFFFFF, 1), (0x7FFFFFFF, 2), (0x10000000, 0) lost bits only for n = 4, (0, 0xFFFFFFFF), (0xFFFFFFFF, 0xFFFFFFFF).
The gfx1036 follows the ISA formula exactly, lost bits included: SCC = ((S0 << n) + S1) >= 2^32 in all 32 pair/opcode combinations. "Only the 32-bit addition's carry" is wrong in 1 to 5 of the 8 pairs per opcode, and "result is not zero" in 4 to 6.
Results (values that differ from the gfx1036, out of 64 lanes x 16 outputs)
lshl_add/1lshl_addc/1lshl_add/2,/3,/4lshl_addc/2,/3,/4On main every differing value is SCC or the
s_addc_u32after it; the shifted sums themselves were already right. Examples of main against the hardware, all 64 lanes alike:s_lshl1_add_u32of (0x80000000, 0) gives 0 with SCC 1 on the gfx1036 (the lost bit), main SCC 0; (1, 2) gives SCC 0, main 1, so the high dword after it is 0x101 instead of 0x100.s_lshl4_add_u32of (0x10000000, 0) gives 0 with SCC 1, main 0.Verdict: correct. With this PR all 16 cases are exact on both cards: 2,048 SCC values and 2,048 address high dwords, the lost-bit-only pairs and the wrapping ones alike. The other 8 wave32 cases in the same run (other opcodes) give the same values as main.
AI use: Claude Code (Claude Opus 5.5) ran the oracle and host cases and wrote this comment.
c4848d81d3toe2f5692b58@Melow-code on GitHub · 2026-11-30 06:16 UTC · original
Thank you, that is the check I could not make: 2,048 SCC values and as many high dwords against the real chip, the lost-bit-only pairs included.
Rebased onto
41adb551, asmainhad moved the tests: the lowering is the same, the test is inemit/lower/tests.rsnow. Linux, Rust 1.98.1:cargo test -p victory-shader --lib296 passed, 0 failed, 2 ignored. (victory-formatshas threebcpack::tests::oracle_parity_*failures here, the same three onmain.) Not run on a card again since the rebase.For information: the same change was merged in VIctory-Neo (KyleS98/VIctory-Neo#12), where it went through a full preload and play without a visible difference.
AI-assisted (Claude Code).
Pull request closed