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--gone-20261201!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]>@lmouz823-lang on GitHub · 2026-11-28 05:31 UTC · original
I can take native Windows GPU validation at exact head
3a7b9d9c9da1e6bd47ba0917779380c4a8b854a3. I will run both existing exact tests and add focused fixed-expectation coverage for wrapped signed-difference boundaries and SCC with incoming flags 0/1. I will verify a temporary negative control and restored-source recompilation on RTX 4060 Laptop and WARP, with an explicitly loaded SDK validator. Exact counts, skipped cases and remaining native AMD/game scope will accompany the small patch. AI-assisted with Codex.@lmouz823-lang on GitHub · 2026-11-28 05:42 UTC · original
Native Windows GPU validation completed for exact head
3a7b9d9c9da1e6bd47ba0917779380c4a8b854a3. The existing translation and result regressions each execute exactly one test and pass. The original GPU test performs 20 dispatches across RTX 4060 Laptop and WARP.I added a fixed-expectation test with 12 pairs and incoming SCC both 0 and 1. It covers equal zero/INT_MIN/INT_MAX, both orders of INT_MIN versus INT_MAX, INT_MIN versus 1 and -1, INT_MAX versus -1, and zero versus INT_MIN. Value and outgoing SCC are read separately, giving 96 passing dispatches across the two backends. The table follows AMD's RDNA2 ISA, SOP2 opcode 44, printed page 105. Subtraction wraps at 32 bits before the conditional negation, and the resulting zero/nonzero value replaces SCC.
A temporary negative control changes the sign decision from
difference < 0tooperand0 < operand1. The original five-pair GPU test still passes. The new test fails on hardware for INT_MIN versus INT_MAX, returning0xffffffffwhere the fixed table expects1. Its exact selection runs one test and exits 101. I then restoredlower.rsbyte-for-byte, removed the temporary diagnostics and confirmed actual recompilation before the final three exact selections pass again. Those selections have zero failed or ignored tests and no skip diagnostics.The explicitly selected SDK
dxil.dll1.8.2502.11 successfully createdIDxcValidator. Temporary success markers after loading and after validation plus the container-hash assertion confirmed both new modules and both original modules passed those checks. Those markers are absent from the final patch and runs.The patch adds one 42-line test function. It also relocates the existing two-line negative-zero doc comment from the absolute-difference test to
max_and_min_order_negative_zero_below_positive_zero, which it describes. Removing the new test and reversing that comment move reproduces the head source text exactly. Independent review checked the fixed values, encodings, SCC registers, counts and restoration evidence.One initial unchanged-head release compilation ended with a
rustcaccess violation (0xc0000005) before any test executed. The failure log was retained. An immediate retry with identical source and configuration compiled successfully in 1m01s, and all subsequent diagnostic, mutation and restored-source builds completed. The cause of that first compiler failure remains undetermined.Environment was Windows 11 Pro build 26200, i9-14900HX, NVIDIA 610.88 and Rust 1.98.1 MSVC, release. Package Clippy with
--all-targets -- -D warnings, asset policy, new-function rustfmt andgit diff --checkpass. Whole-file rustfmt exits 1 on the original and patched files with the same 17 existing formatting hunks after file/line headers are removed. Native AMD execution, game behavior, other platforms and full shader/workspace suites remain unverified. Coverage is limited to the listed synthetic patterns and SCC/wrapping boundaries.Reproduction uses an installed SDK validator and the project's Windows build prerequisites.
AI assistance from Codex covered the test, execution, independent review and this report.
Focused test patch and doc-comment relocation
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.