fix: v_bfe_i32 reads copies of the sign bit when the field runs past bit 31 #271
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/271"
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?
Imported from LooperSalty/AnyXboxX. Originally posted by lcg007xd-c on 2026-11-25T22:55:43Z.
Change
v_bfe_i32(interpreter_bitfieldand HLSLBfeI32) shifted S0 as an unsigned value before masking and sign-extending the field. When the field runs past bit 31 (offset + width > 32), the bits above bit 31 came in as zeros instead of copies of the sign bit:main(e921268)939108F500009391FFFF9391D992A38200000001FFFFFFFF8000000000000008FFFFFFF8EC3B1D4F0000EC3BFFFFEC3BThe ISA pseudo-code shifts the signed S0: V_BFE_I32,
D.i = (S0.i >> S1.u[4:0]) & ((1 << S2.u[4:0]) - 1)(section 12.12, p. 169), and the field is then sign-extended, as for S_BFE_I32,D.i = signext((S0.i >> S1.u[4:0]) & ...)(section 12.1, p. 105). The interpreter'ss_bfe_i32(rdna2_exec_bits.bfe) and the HLSLSBfeI32already shift arithmetically, so only the vector form was wrong. Both the interpreter andBfeI32now shift arithmetically. Fields that fit inside S0 (offset + width ≤ 32) and width 0 give the same results as before.Linked issue: none.
Verification
Linux, Python 3.14, no C++ runtime, no GPU (the runtime and GPU tests skip):
Not run here:
test_bfe_i32_matches_interpreter_on_gpu(no dxc or GPU on this machine). It runs in the Windows CI job on WARP. The HLSL text was checked offline:rdna2_hlsl.translateof the parity program succeeds, and a Python model of the newBfeI32(32-bitshlandashrwith 5-bit shift amounts, as in DXIL) equals the interpreter on 200,000 random (S0, offset, width), with 0 differences.Oracle and test data
How it was found: differential testing of the interpreter against LLVM's constant folding of
llvm.amdgcn.sbfe.i32(opt -passes=instcombine -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1030, LLVM 23.1.5, which turns a field past bit 31 intoashr S0, offset). Onmain, 23 of 256 random triples differed. With the fix, 0 differ.v_bfe_u32matched before and still does.New
tests/test_rdna2_exec_bfe.py:S1[4:0],S2[4:0]), fields inside S0, and width 0;The expected values are worked out from the ISA pseudo-code and agree with LLVM's folding. The data is built in the test.
Failure case: without the fix, the two interpreter tests fail.
Checklist
E_NOTIMPL), never a fake success.AI assistance: written with Claude Code (Claude Opus 5.5).
🤖 Generated with Claude Code
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-25T23:42:42Z.
Setup: Windows 11 26200, dxc 1.8.2502.11 (Windows SDK 10.0.26100.0), Python 3.12.10, C++ runtime built from
main3e258c8. Adapters: RTX 4060 Laptop (driver 32.0.16.1047, i.e. 610.47; default adapter), Intel UHD 8086:a78b (31.0.101.5445,ANYXBOXX_GPU=Intel, 16 lanes, no FP64), WARP 10.0.26100.9818 (ANYXBOXX_GPU=warp). This PR was merged ontomain3e258c8(clean merge).mainpython -m pytesttests/test_rdna2*.pytests/test_rdna2*.pytests/test_rdna2_exec_bfe.pyonmaincode, each adaptertest_bfe_i32_matches_interpreter_on_gpu(the item you couldn't run) passes with this PR on the RTX 4060, Intel UHD (16 lanes) and WARP. Onmainit also passes on all three, because the interpreter andBfeI32shared the bug. It guards parity, and the two interpreter tests guard the fix.BfeI32now compute the same thing: an arithmetic shift byS1[4:0], then sign extension from bitw - 1. Width 0 still gives 0, andv_bfe_u32is unchanged. No rule-3 or rule-4 issue: there is no refusal change, and both sides change together.AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.