shader: lower s_bfe_u64, s_bfe_i64 and s_bfm_b64 #97
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!97
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-97"
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:34 UTC · original
lcg007xd-c:shader-s-bfe64→main· +154 −0 · 2 files · 1 commits · openWhat is broken
The 64-bit scalar bitfield instructions decode, but a program using one fails to translate with
s_bfe_u64 is not supported(or the matching name). Their 32-bit forms (s_bfe_u32,s_bfe_i32,s_bfm_b32) already lower.s_bfe_u64s_bfe_i64s_bfm_b64They are part of the scalar gap the sweep through the CPU harness of #62 turned up (see #89).
Semantics (AMD's RDNA2 ISA, §12.1, opcodes 37, 41, 42)
s_bfe_u64:D.u64 = (S0.u64 >> S1[5:0]) & ((1 << S1[22:16]) - 1)andSCC = (D != 0).s_bfe_i64sign-extends the field from its top bit.s_bfm_b64:D.u64 = ((1 << S0[5:0]) - 1) << S1[5:0]. It writes no SCC.bfehelper already treats a width of 32 or more fors_bfe_u32.The change (
emit/lower.rs, insop's 64-bit section)INT64flag), mirroring the 32-bitbfehelper: a full-width mask, then a sign extension skipped for widths 0 and ≥ 64.Tests
emit::lower::tests::scalar_64_bit_bitfields_translate(every host): all three decode, and a program that stores the result translates. Without thelower.rschange it fails:s_bfe_u64 [948c0200, 7e00020c]: GFX10 code at 0x24: s_bfe_u64 is not supported.valu_tests::scalar_64_bit_bitfields_match_rdna2(Windows/GPU): both dwords of each result for four cases: a field across the dword boundary, a sign-set top nibble, width 64, and width 0.lli. I compared both dwords against a Rustu64/i64reference on 38 cases. They include widths 1, 32, 63+, 127 and junk in S1's other bits, plus SCC for both extracts. 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. I could not check widths above 64 on RDNA2 hardware, so they follow the 32-bit lowering's rule.
🤖 Generated with Claude Code
SOP2 0x29, 0x2A and 0x25 decoded but failed to translate ("s_bfe_u64 is not supported"): the 64-bit forms of s_bfe_u32/s_bfe_i32/s_bfm_b32. AMD's RDNA2 ISA: s_bfe extracts a field of width S1[22:16] at offset S1[5:0] (sign-extended for _i64; a width of 64 or more takes every remaining bit, as the 32-bit lowering does for 32), SCC = (D != 0); s_bfm_b64 builds ((1 << S0[5:0]) - 1) << S1[5:0] with no SCC. Computed in 64-bit integers. Co-Authored-By: Claude Opus 5.5 <[email protected]>@lmouz823-lang on GitHub · 2026-11-28 04:40 UTC · original
I can take Windows GPU and SCC validation at exact head
7fceac4d9604c1bca5148e4b9e14b9315e715081. I will execute the existing translation/result tests and add fixed-expectation coverage for BFE updating SCC from the complete 64-bit result and BFM preserving incoming SCC 0/1. New cases will use widths 0–63, including a high-dword-only nonzero result. I will report the existing width-64 case as consistency with the current PR expectations, with its native semantic uncertainty retained. A temporary low-dword-only SCC check will provide a negative control, followed by restoration and fresh runs on RTX 4060 Laptop and WARP with the SDK validator. AI-assisted with Codex.@lmouz823-lang on GitHub · 2026-11-28 04:52 UTC · original
Native Windows validation completed for exact head
7fceac4d9604c1bca5148e4b9e14b9315e715081on RTX 4060 Laptop and WARP. The existing translation and GPU tests each execute exactly one test and pass. The existing GPU test includes width 64, so its success records agreement with this PR's chosen expectations. Native RDNA2 behavior at width 64 or above remains unverified.I added one fixed-table GPU regression restricted to width 0–63 and offset + width <= 64. It separately reads the low dword, high dword and SCC for all three operations, with incoming SCC both 0 and 1. Six input vectors per operation × two incoming flags × three readbacks × two backends gives 216 passing dispatches. It checks BFE setting SCC from the full 64-bit result, signed extraction, and BFM preserving SCC for zero and nonzero masks. One BFE case produces low=0, high=1, which specifically checks the high dword contributes to SCC. Expectations follow AMD's RDNA2 ISA, SOP2 opcodes 37, 41 and 42, printed page 105.
A negative control temporarily changes this branch's
nonzero(self, rl, rh)tononzero(self, rl, rl). The original result-only GPU test still passes. The new test fails on hardware for source0x0000000100000000, offset 0, width 63 and incoming SCC 0, reporting SCC 0 where the fixed table expects 1. After restoring the implementation and removing diagnostics, a fresh compilation and final runs of both GPU tests and the translation test each pass. There are no skips or ignored tests. The additional patch contains one 94-line synthetic test function.The explicit SDK
dxil.dll1.8.2502.11 createdIDxcValidator. Temporary success markers after DXIL validation and the container-hash assertion confirmed all nine new modules and all six original modules passed both checks. Those markers were removed before the final runs. Independent review checked the fixed values, encodings, bounds, SCC producer/readback, counts and final source restoration.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 (195 files),git diff --checkand rustfmt on the added function pass. Native AMD execution, game behavior and the full workspace suite remain unverified.Reproduction uses an installed SDK validator and the Windows build prerequisites.
AI assistance from Codex covered the test, execution, independent review and this report.
94-line synthetic test patch against this PR head
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.