Repository navigation
[pr-fix] Shaders: s_lshl<n>_add_u32 sets SCC to its carry - #12
Conversation
s_lshl1_add_u32 to s_lshl4_add_u32 left whether the result is not zero in SCC. The RDNA 2 ISA gives the unsigned overflow of the whole sum, shifted bits included, so an s_addc_u32 behind one added 1 to the high dword of nearly every address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Read against the instruction set: (a << n) + b reaches 2^32 exactly when bits are shifted out of It changes the shader cache key, so I will take it together with #14 under one full preload and a play of the opening, the cell and the first house before merging, and report here. The red check is AI-assisted (Claude Code, Claude Fable 5.2). |
|
Merged ( AI-assisted (Claude Code, Claude Fable 5.2). |
Found by reading the scalar lowering against the RDNA 2 ISA. No issue or pull request here mentions it. The same fix is open in trustno1-coder/VIctory-NVIDIA#1972 (also mine). Credit: the defect and the formula were reported before in Marvisak/VIctory#168 and fxceless/victory-fork#350 (both open).
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 fix is in
sop(emit/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.cargo testpassed for the crates it touches: yes. Linux, Rust 1.98.1, on 1675e22:cargo test -p victory-formats -p victory-shader --lib: 57 and 246 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 (main's own are still there; run on e4c123c, two README commits earlier).cargo xtask policy: ok (331 files; also on e4c123c).cargo fmt --checkalready lists 614 places in this crate on main; this adds one, in the test.Checked for overlap
s_min/s_maxhad the same kind of mistake (Shaders: s_min and s_max set SCC to their comparison #8, merged).🤖 Generated with Claude Code