Repository navigation
Conversation
Part of R0Y00#1723. Constant operands fold to two exact words; run-time operands build the mask without a 32-bit shift count of 32 or more and reuse shl64. Refuses m0, vcc, exec and modifiers.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
There was a problem hiding this comment.
💡 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
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| def 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.""" |
There was a problem hiding this comment.
Document the new startup translation capability
This adds a supported startup-translator instruction without updating README or docs/experiments.md; the existing s_bfm_b64 experiment documents the separate pixel_aot translator. AGENTS.md requires updating the public capability record when support changes. Record the supported/refused operand scope and python3 -B tests/startup_gfx2hlsl_bfm_b64_check.py reproduction command, explicitly distinguishing the Python controls from unverified GPU execution.
AGENTS.md reference: AGENTS.md:L207-L208
Useful? React with 👍 / 👎.
| self.set_s(d, '0x%08xu' % (value & 0xffffffff), ('const', value & 0xffffffff)) | ||
| self.set_s(d + 1, '0x%08xu' % (value >> 32), ('const', value >> 32)) |
There was a problem hiding this comment.
Clear destination lane-mask tags when writing the bitfield
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 sequence s_mov_b64 s[20:21], exec; s_bfm_b64 s[20:21], 4, 4; s_or_b32 s22, s20, 0 emits the final assignment as (0x000000f0u | 0x00000000u) & 1, producing zero instead of 0xf0 and 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 👍 / 👎.
| 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]) |
There was a problem hiding this comment.
Reject lane-mask sources used as integer counts
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 instruction s_bfm_b64 s[20:21], exec_lo, 0 emits bw = exec & 63u and produces 1, whereas the actual exec_lo is 0xffffffff, giving width 63 and result 0x7fffffffffffffff. Refuse these sources, as the scalar complement handlers do for lane masks, unless their full-wave numeric values can be represented.
Useful? React with 👍 / 👎.
Two open PRs lower
|
| #2003 | #2007 | |
|---|---|---|
| modifiers and operand count | one combined message | two messages |
| destination alignment | dst[2] != dst[1] + 1 and dst[2] > 105 |
adds dst[1] % 2 |
| source register form | accepts anything reg_range maps to s |
refuses exec/vcc and any range r[1] != r[2] |
Two of those matter:
dst[1] % 2— a 64-bit scalar destination must be even-aligned in the register file. startup: lower s_bfm_b64 in gfx2hlsl #2007 enforces it; shader: lower s_bfm_b64 in gfx2hlsl (Part of #1723) #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 — startup: lower s_bfm_b64 in gfx2hlsl #2007 refuses them by name, shader: lower s_bfm_b64 in gfx2hlsl (Part of #1723) #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] % 2 and 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 in CONTRIBUTING.md — "check open PRs for the mnemonic before starting" — rather than something either author did wrong.
Notes
- AI-assisted coordination note.
Ran it, broke it four ways: two caught, two survivors proven equivalent — and one real gap in the refusalsWindows 11 build 26300.9974, device-free: out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_bfm_b64_check.py
startup s_bfm_b64 controls passed exit 0
The two survivors are equivalent mutants, not gaps — checked, not assumedI evaluated the emitted expression, both mutants, and the ISA formula over all 4,096 The high word is only active for The real gap: an odd-aligned 64-bit destination is accepteddst = reg_range(ops[0])
if not dst or dst[0] != 's' or dst[2] != dst[1] + 1 or dst[2] > 105:
raise Unsupported('s_bfm_b64 destination %s' % ops[0])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 if not dst or dst[0] != 's' or dst[2] != dst[1] + 1 or dst[1] % 2 or dst[2] > 105: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 Where this version is stronger than #2007
What is not coveredNo shader compiled or run; SCC untouched is asserted by your fixture. The ISA quotation in the docstring is taken at face value. Notes
|
|
@tedin7, #2007 lowers AI-assisted (Claude Code). |
Part 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.