shader: lower s_bfm_b64 in gfx2hlsl (Part of #1723) #2003
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2003
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2003/head"
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?
@tedin7 on GitHub · 2026-11-24 22:57 UTC · original
tedin7:x2w-pipe-s-bfm-b64→main· +124 −0 · 3 files · 2 commits · closed without mergingPart of #1723
What this unblocks: startup shaders that build 64-bit bitfield masks with
s_bfm_b64now translate instead of being refused.Adds
op_s_bfm_b64totools/startup/gfx2hlsl.py, the 64-bit twin ofop_s_bfm_b32:D = ((1 << S0[5:0]) - 1) << S1[5:0].shl64. Both sources are read before either destination register is written, so overlapping registers are safe.m0,vcc,exec, odd destinations above s105 and modifiers are refused.tests/startup_gfx2hlsl_bfm_b64_check.py(13 hand-written constant cases, run-time block shape, refusals), registered in CMake asstartup_gfx2hlsl_bfm_b64_controls.Verification:
python3 -B tests/startup_gfx2hlsl_bfm_b64_check.py->startup s_bfm_b64 controls passed(with the fix).Unsupported: s_bfm_b64(fails before, passes after).python3 -B tests/startup_gfx2hlsl_scalar_m0_check.py,..._shift64_check.py,..._bit_alu_check.py-> all pass.AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 22:57 UTC · original · edited 2026-11-24 23:05 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
ce590a3ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
@ -921,2 +921,4 @@return Nonedef op_s_bfm_b64(self, ops, mods):"""64-bit bitfield mask: D = ((1 << S0[5:0]) - 1) << S1[5:0]; both sources are 32-bit, SCC is untouched."""@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:05 UTC · original
This adds a supported startup-translator instruction without updating README or
docs/experiments.md; the existings_bfm_b64experiment documents the separatepixel_aottranslator.AGENTS.mdrequires updating the public capability record when support changes. Record the supported/refused operand scope andpython3 -B tests/startup_gfx2hlsl_bfm_b64_check.pyreproduction command, explicitly distinguishing the Python controls from unverified GPU execution.AGENTS.md reference: AGENTS.md:L207-L208
Useful? React with 👍 / 👎.
@ -923,0 +941,4 @@if None not in vals:value = (((1 << (vals[0] & 63)) - 1) << (vals[1] & 63)) & 0xffffffffffffffffself.set_s(d, '0x%08xu' % (value & 0xffffffff), ('const', value & 0xffffffff))self.set_s(d + 1, '0x%08xu' % (value >> 32), ('const', value >> 32))@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:05 UTC · original
If a destination SGPR previously held a lane mask, this handler overwrites its numeric value without removing its entry from
self.masks. For example, the decoded sequences_mov_b64 s[20:21], exec; s_bfm_b64 s[20:21], 4, 4; s_or_b32 s22, s20, 0emits the final assignment as(0x000000f0u | 0x00000000u) & 1, producing zero instead of0xf0and consequently setting SCC incorrectly. Clear both destination mask tags in the constant and runtime paths so subsequent scalar operations do not truncate the numeric result to one bit.Useful? React with 👍 / 👎.
@ -923,0 +945,4 @@return None# The mask words are built so no 32-bit shift sees a count of 32 or more, then shl64 moves them;# both sources are read before either destination register is written (D may overlap S0/S1).width, offset = self.u(ops[1]), self.u(ops[2])@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:05 UTC · original
When a source is
exec_lo,vcc_lo, or a mask-tagged SGPR,self.u()supplies the per-lane 0/1 projection rather than the wave's 32-bit mask. For example, on an all-active wave, the accepted instructions_bfm_b64 s[20:21], exec_lo, 0emitsbw = exec & 63uand produces 1, whereas the actualexec_lois0xffffffff, giving width 63 and result0x7fffffffffffffff. Refuse these sources, as the scalar complement handlers do for lane masks, unless their full-wave numeric values can be represented.Useful? React with 👍 / 👎.
@ChazY11 on GitHub · 2026-11-24 23:12 UTC · original
Two open PRs lower
s_bfm_b64— #2003 and #2007 — and they conflict on three filesNot a problem with your patch; a coordination note so the effort is not spent twice. Checked against
main7f149ac9:Both add a fixture with the same filename, so whichever lands second has to be rewritten rather than rebased.
Where the two implementations differ
The semantics agree (
D.u64 = ((1ULL << S0[5:0]) - 1) << S1[5:0], SCC untouched, both words written). The differences are in what is refused:dst[2] != dst[1] + 1anddst[2] > 105dst[1] % 2reg_rangemaps tosexec/vccand any ranger[1] != r[2]Two of those matter:
dst[1] % 2— a 64-bit scalar destination must be even-aligned in the register file. #2007 enforces it; #2003 does not, sos_bfm_b64 s[3:4], …would be accepted. That is the one substantive difference I would not want to lose.exec/vccas sources — #2007 refuses them by name, #2003 accepts them through the genericspath. Whether that is right depends on whether the ISA allows a 64-bit pair spelling here; worth agreeing on rather than leaving to merge order.What I would suggest
Keep #2007's
dst[1] % 2and its explicit source refusal, and take #2003's split modifier/operand messages if you prefer them — then close the other, since neither check can be reused as is.I have already reviewed #2007 at the behaviour level (five mutations, all caught, plus an exhaustive check of the emitted expression against the ISA formula over all 4,096
(width, offset)pairs). I have not reviewed #2003.The same duplication exists for
v_swap_b32(#1995 and #2012), so this looks like a pattern worth a one-line note inCONTRIBUTING.md— "check open PRs for the mnemonic before starting" — rather than something either author did wrong.Notes
@ChazY11 on GitHub · 2026-11-24 23:23 UTC · original
Ran it, broke it four ways: two caught, two survivors proven equivalent — and one real gap in the refusals
Windows 11 build 26300.9974, device-free:
& 63maskssymfor the destination pairbw > 32u→bw >= 32u(bw - 32u) & 31u→bw & 31uThe two survivors are equivalent mutants, not gaps — checked, not assumed
I evaluated the emitted expression, both mutants, and the ISA formula over all 4,096
(width, offset)pairs:The high word is only active for
bwin 33..63, and on exactly that range(bw-32)&31 == bw&31, while atbw == 32the shift is 0 so>=and>agree. So no fixture can distinguish them, and asking for one would be asking for a test that cannot fail. Your expression is correct as written.
The real gap: an odd-aligned 64-bit destination is accepted
There is no alignment term, so every one of these passes the condition:
A 64-bit scalar operand must be even-aligned in the register file, so
s_bfm_b64 s[3:4], …should be refused. One clause closes it:The other PR for this mnemonic (#2007) has that term, which is why I raised the duplicate on both — see my earlier note. If you keep #2003 instead, this
is the one line I would take from the other one.
Where this version is stronger than #2007
bw - 32uinstead ofbw & 31uin the high word reads as the intent (they are equal, as shown above), and the folding path writes two exact 32-bitwords with
('const', …)symbols, which the other version also does. Nothing to change.What is not covered
No shader compiled or run; SCC untouched is asserted by your fixture. The ISA quotation in the docstring is taken at face value.
Notes
@JB2WIN on GitHub · 2026-11-25 00:05 UTC · original
@tedin7, #2007 lowers
s_bfm_b64too. I claimed it in #1723 at 22:20 UTC and hadn't seen your PR when I did. R0Y00 asked on #2007 to keep a single implementation there, and I'm now adding his requested mask-alias refusal and the uniformity check on top of #1931. If your branch has controls #2007 lacks, tell me and I'll bring them over with attribution. Sorry for the overlap.AI-assisted (Claude Code).
@tedin7 on GitHub · 2026-11-25 00:40 UTC · original
Closing in favor of #2007 (@JB2WIN had already claimed s_bfm_b64 in #1723) so there is a single clean implementation as requested by @R0Y00. Thanks @ChazY11 for the thorough review!
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:05 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
ce590a3a50ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Pull request closed