shader: lower compute VOP1 bfrev and ffbh_i32 #1584
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1591"
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 R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T14:39:47Z.
Change
Refs #1546. This lowers the VOP1 forms
v_bfrev_b32_e32andv_ffbh_i32_e32in the compute translator (tools/compute_store_aot.py).The change adds a
VOP1_ALUtable afterALUand a newelifbranch before thev_mad_u32_u24row-pitch branch. The branch reads its source operand throughALU_SOURCE/alu_wordand reuses the existing "Unverified ALU operand" andALU_EXPRESSION_LIMITchecks.Semantics
v_bfrev_b32lowers toreversebits(x).v_ffbh_i32follows the RDNA 2 ISA pseudocode: D = -1, then D is the first i from 1 to 31 for which S0[31-i] differs from S0[31]. For example:This matches
gfx2hlsl.pyandpixel_aot.py.The
v_ffbh_i32HLSL isfirstbitlow(reversebits(x ^ asuint(asint(x) >> 31u))). It gives the same result as thegfx2hlslexpression but names x twice instead of five times, which keeps inline chains short.Fixture
The fixture is in a new
tests/compute_alu_vop1_check.py, which imports the helpers oftests/compute_store_check.py(that file is unchanged). It isREAD_COMPUTEwith the ALU lines replaced. With w the source word and cap =params[0].y= 0xfffffffe, each lane stores 16 bytes:bfrev(0x12345678) = 0x1e6a2c48.Wrong references and templates
Controls
These are refused with the existing messages:
_e64(including-v3), SDWA and DPP forms, and-v1,|v1|,clampandv[1:2];v_ffbh_u32,v_ffbl_b32,v_not_b32,s_brev_b32ands_flbit_i32;Registration and docs
compute_store_aot_alu_vop1_${adapter}, registered aftercompute_store_aot_mubuf_subword. It setsFORM_COVERAGE_RECORD, so the dashboard counts both forms.docs/experiments.mdsubsection, "VOP1 bit reverse and signed leading-bit count".Verification
Commit
6c0e5380(main) plus this change,devpreset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11.1002:73ff), driver 32.0.21045.29003, debug layer enabledThese also pass:
compute_store_checktranslator controls, run through itscompile-mimg-atomic-*modes;draw-guard-readon WARP;tests/docs_links_check.py,tests/bidi_controls_check.py,tests/form_coverage_check.pyandgit diff --check.I did not run the LLVM 15
binarymode.Notes
_e64without modifiers is refused, as in the binary32 subset. Accepting it would be a separate decision.llvm-mc19 unchanged, apart from a blank line.Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:01:31Z.
Review: COMMENTED
Reviewed
dd929728(tools/compute_store_aot.py,tests/compute_alu_vop1_check.py,CMakeLists.txt,docs/experiments.md).Findings
v_bfrev_b32_e32lowers toreversebits({0})andv_ffbh_i32_e32lowers tofirstbitlow(reversebits({0} ^ asuint(asint({0}) >> 31u))). Folding the sign bit via arithmetic right shift clears bit 31 and sets bit31 - iiffS0[31 - i] != S0[31], sofirstbitlow(reversebits(m))returns the RDNA 2V_FFBH_I32index1..31(or0xffffffffwhenS0is0or0xffffffff), while substituting{0}only twice._e64,_sdwa,_dpp, modifiers, register ranges, neighbouring opcodes (v_ffbh_u32_e32,v_ffbl_b32_e32,v_not_b32_e32,s_brev_b32,s_flbit_i32), unverified operands, and data-only address/guard/post-exec-restore misuse are all rejected.tests/compute_alu_vop1_check.pycovers both wrong reference models and mutated HLSL templates on WARP.Verification
python3 tests/compute_alu_vop1_check.py controls: passed.llvm-mc-19 -arch=amdgcn -mcpu=gfx1013 -show-encodingon the fixture'sv_bfrev_b32_e32/v_ffbh_i32_e32forms: passed.python3 tests/docs_links_check.py: passed (16 Markdown files, 344 links).python3 tests/bidi_controls_check.py: passed (1253 tracked files)./O2):ctest --preset devon the 41offscreen_check/compute_*_warptests (includingcompute_store_aot_alu_vop1_warp): 41/41 passed.ctest --preset releaseon the same 41 tests: 41/41 passed (58.43s,compute_store_aot_alu_vop1_warp4.19s).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T16:46:14Z.
Review: COMMENTED
Hardware check on NVIDIA, which adds a data point to the RX 6600 and WARP runs above. Nothing below is a code change.
Tested:
dd929728merged onto mainc864f138.docs/experiments.mdconflicts with main (see the end of this review). For the build I kept this PR's version of that file; no code conflicted.Environment:
10de:1c03), driver 32.0.15.6094 (Pascal).1414:008c.Ran:
python -B tests/compute_alu_vop1_check.py controls: passed.ctest --preset {dev,release} --no-tests=error -R '^compute_store_aot_(alu_vop1_(warp|hardware)|warp|hardware)$' -V: 4/4 in Debug and 4/4 in Release. Every dispatch readcompared_words=320 mismatches=0withdebug_errors=0 debug_warnings=0, on the 1060 and on WARP.Controls on the 1060:
ffbh_u32 for ffbh_i32at word 2,counting after the sign bitat word 1, and so on).logical sign fold. So DXC emits theasint(x) >> 31ufold as an arithmetic shift on this driver too, and the negative inputs in the fixture, plus 0 and0xffffffff, read back as the ISA model gives.Reading of the lowering:
firstbitlow(reversebits(x ^ asuint(asint(x) >> 31u)))agrees with V_FFBH_I32 for every word. After the fold, bit 31 is always clear, so the result is 1–31 for mixed words and0xfffffffffor 0 and −1.reversebitsmatches V_BFREV_B32. No defects found.Merge conflict:
docs/experiments.mdcurrently conflicts with main, next to the new "VOP1 bit reverse and signed leading-bit count" section. It needs a rebase or merge before this can land.AI-assisted (Claude Code); the commands listed were run locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:18:11Z.
Review: COMMENTED
Re-review at
head_sha:6d5586490575dd64259647f557946eb388fcf8f9(previously reviewed atdd929728).Findings
No P1/P2. No defect found.
main.git range-diffand a diff of the added/removed lines of the two patches show the PR's own content is unchanged; only context lines differ.git merge-treeagainst currentmain(bc65bb1b) reports no conflicts (tree32a58dc1).firstbitlow(reversebits(x ^ (x >>s 31)))against a direct "first bit that differs from the sign bit, counted from the MSB" over 75 words (0, 0xffffffff, 0x80000000, 0x7fffffff, every single-bit word and its complement, and a few mixed patterns). 0 mismatches, including the0xffffffffresult for0and0xffffffff.Verified
Limits: Linux x86-64 only. I did not rerun the Windows WARP/hardware
ctestfor this head, sodrawmode rests on the unchanged patch and the earlier Windows results on the previous head.python3 -B tests/compute_alu_vop1_check.py controls-> exit 0.llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding:v_bfrev_b32_e32 v1, v2->02 71 02 7e;v_ffbh_i32_e32 v1, v2->02 77 02 7e; the literal and SGPR forms assemble too.python3 -B tests/docs_links_check.py-> 16 files, 351 links OK.git diff --check HEAD^ HEADclean.asint({0}) >> 31uto>> 30uin thev_ffbh_i32_e32template;controlsfails with anAssertionErroron the exact-text check (exit 1). Restored withgit checkout -- .;git status --shortclean.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:41:28Z.
Review: COMMENTED
Verified at
head_sha:6d5586490575dd64259647f557946eb388fcf8f9(0 P1, 0 P2).Scope & Semantics
tools/compute_store_aot.py,tests/compute_alu_vop1_check.py,CMakeLists.txt(test-onlycompute_store_aot_alu_vop1_{hardware,warp}), anddocs/experiments.md.v_bfrev_b32_e32(reversebits(a)) andv_ffbh_i32_e32(firstbitlow(reversebits(a ^ asuint(asint(a) >> 31u)))) match the AMD RDNA 2 ISA definitions (VOP1 opcodes 56 and 59, returning0xfffffffffor0and-1, and1..31for the first bit differing from bit 31);_e64, SDWA, DPP, modifiers, register ranges, and unknown/pending/descriptor operands are refused.Verified
git diff --check origin/main...HEAD-> cleanpython3 tests/docs_links_check.py-> passed (16 Markdown files, 351 links)python3 tests/bidi_controls_check.py-> passed (1280 tracked files)python3 tests/compute_alu_vop1_check.py controls-> passedllvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding:v_bfrev_b32_e32 v1, v2(02 71 02 7e),v_ffbh_i32_e32 v3, v4(04 77 06 7e)--preset dev):offscreen_checkbuilt (10.49s),ctest --preset dev -R 'compute_store_aot_alu_vop1'2/2 passed (4.51s:compute_store_aot_alu_vop1_hardware,compute_store_aot_alu_vop1_warp)/O2(--preset release):offscreen_checkbuilt (8.13s),ctest --preset release -R 'compute_store_aot_alu_vop1'2/2 passed (4.48s)v_bfrev_b32_e32template with identity({0})intools/compute_store_aot.py->compute_alu_vop1_check.py controlsfailed as expected.v_ffbh_i32_e32template intools/compute_store_aot.py->compute_alu_vop1_check.py controlsfailed as expected.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:35:03Z.
This PR currently has merge conflicts with
main. Could you please rebase it onto the latestmainso it can be checked for merge?AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:58:07Z.
Pushed
1614dc918: merged currentmaininto this branch (no rebase, no force) so it no longer conflicts.Conflicts resolved, keeping both sides:
tools/compute_store_aot.py(the new VOP1bfrev/ffbh_i32branch sits next to main's new borrow/carry branches in the sameelifchain) anddocs/experiments.md.CMakeLists.txtmerged cleanly.Verification:
python3 tests/compute_alu_vop1_check.py controlsand the siblingcompute_alu_*_check.py controls(bcnt, med3, xor3, mad_i24): pass.x2w_pipe.py win2025 1591 --patch <merge diff> --regex 'compute_alu_(vop1|bcnt|med3|xor3|mad_i24|minmax3|cmp_ne|cvt_pk_u8|lane_gaps)|compute_store': 212/213 pass.compute_store_aot_mac_f32_hardwarefails the same way on a tree without this PR (Basic Render Driver, "fused mad() escaped detection"); its warp variant passes, and this PR does not touch that test or thev_mac_f32lowering.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T04:51:26Z.
Review: APPROVED
The current branch includes the mainline fix for duplicate Pass fields that broke the older Windows build. Its diff against main is the VOP1 code and fixture only. Release offscreen readbacks for v_bfrev_b32 and v_ffbh_i32 matched on WARP and RTX 4060 Laptop, and the guards and wrong-model mutations failed as intended. The Python translation controls passed as well.