shader: lower s_absdiff_i32 #94
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!94
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-94"
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?
@lcg007xd-c on GitHub · 2026-11-25 22:27 UTC · original
lcg007xd-c:shader-s-absdiff→main· +70 −0 · 2 files · 1 commits · openWhat is broken
s_absdiff_i32(SOP2 0x2C) decodes, but a program using it fails to translate withs_absdiff_i32 is not supported. I found it in the scalar sweep through the CPU harness of #62, the same sweep as #89, #91 and #92.Semantics
AMD's RDNA2 ISA (§12.1, opcode 44):
D.i = S0.i - S1.i; if (D.i < 0) D.i = -D.i, andSCC = (D != 0). The difference is a 32-bit one and wraps. So, for example,|0x80000000 - 0|stays0x80000000, as the hardware's two's-complement negation leaves it.The change (
emit/lower.rs, insop)SCC = (D != 0)is whatsop's shared SCC path already sets, and the IR already listsabsdiffamong the SCC writers.Tests
emit::lower::tests::scalar_absolute_difference_translates(every host): the encoding decodes. Two programs translate: one that stores the value, and one that stores SCC throughs_cselect_b32. Without thelower.rschange it fails:s_absdiff_i32 [960c0100, 7e00020c]: GFX10 code at 0x24: s_absdiff_i32 is not supported.valu_tests::scalar_absolute_difference_matches_rdna2(Windows/GPU): the value and SCC for five pairs, covering both orders, a negative operand, equal values (SCC 0), andINT_MIN − 0.lli. I compared the value and SCC against Rust'swrapping_sub(..).wrapping_abs()on all 81 pairs of 9 edge values. All match.Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine.
🤖 Generated with Claude Code
SOP2 0x2C decoded but failed to translate ("s_absdiff_i32 is not supported"). AMD's RDNA2 ISA: D.i = S0.i - S1.i, negated if negative (the 32-bit difference wraps, so |INT_MIN| stays 0x80000000), and SCC = (D != 0), which the shared SCC path already gives. Co-Authored-By: Claude Opus 5.5 <[email protected]>View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.