shader: lower s_bfm_b64 in gfx2hlsl (Part of #1723) #1996

Closed
tedin7 wants to merge 2 commits from upstream-pr/2003 into main
tedin7 commented 2026-11-24 22:57:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:57:43Z.


Part of #1723

What this unblocks: startup shaders that build 64-bit bitfield masks with s_bfm_b64 now translate instead of being refused.

Adds op_s_bfm_b64 to tools/startup/gfx2hlsl.py, the 64-bit twin of op_s_bfm_b32: D = ((1 << S0[5:0]) - 1) << S1[5:0].

  • Constant operands fold to two exact 32-bit words (width 32 and 33..63 included).
  • Run-time operands build the mask words without a 32-bit shift count of 32 or more, then reuse shl64. Both sources are read before either destination register is written, so overlapping registers are safe.
  • SCC is untouched. m0, vcc, exec, odd destinations above s105 and modifiers are refused.
  • New tests/startup_gfx2hlsl_bfm_b64_check.py (13 hand-written constant cases, run-time block shape, refusals), registered in CMake as startup_gfx2hlsl_bfm_b64_controls.

Verification:

  • python3 -B tests/startup_gfx2hlsl_bfm_b64_check.py -> startup s_bfm_b64 controls passed (with the fix).
  • Same test with the fix reverted -> 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.
  • Not run: Win2025 GPU draw (this change is pure-Python controls only; no GPU readback of the dynamic path yet).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593093929 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T22:57:43Z. --- Part of #1723 What this unblocks: startup shaders that build 64-bit bitfield masks with `s_bfm_b64` now translate instead of being refused. Adds `op_s_bfm_b64` to `tools/startup/gfx2hlsl.py`, the 64-bit twin of `op_s_bfm_b32`: `D = ((1 << S0[5:0]) - 1) << S1[5:0]`. - Constant operands fold to two exact 32-bit words (width 32 and 33..63 included). - Run-time operands build the mask words without a 32-bit shift count of 32 or more, then reuse `shl64`. Both sources are read before either destination register is written, so overlapping registers are safe. - SCC is untouched. `m0`, `vcc`, `exec`, odd destinations above s105 and modifiers are refused. - New `tests/startup_gfx2hlsl_bfm_b64_check.py` (13 hand-written constant cases, run-time block shape, refusals), registered in CMake as `startup_gfx2hlsl_bfm_b64_controls`. Verification: - `python3 -B tests/startup_gfx2hlsl_bfm_b64_check.py` -> `startup s_bfm_b64 controls passed` (with the fix). - Same test with the fix reverted -> `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. - Not run: Win2025 GPU draw (this change is pure-Python controls only; no GPU readback of the dynamic path yet). AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 23:03:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T22:57:55Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T23:05:07.344042Z ce590a3 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146852541 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003#issuecomment-7146852541). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T22:57:55Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"ce590a3a5001c24d44bbed080866fefc320fa8e4","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T23:05:07.344042Z">2026-11-24T23:05:07.344042Z</relative-time> | `ce590a3` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-25 00:04:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:05:04Z.

Review: COMMENTED


💡 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048818113 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003#pullrequestreview-6048818113). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:05:04Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `ce590a3a50` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). 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". </details>
upstream-sync closed this pull request 2026-11-25 01:01:01 +00:00
ChazY11 commented 2026-11-25 01:01:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:12:41Z.


Two open PRs lower s_bfm_b64 — #2003 and #2007 — and they conflict on three files

Not a problem with your patch; a coordination note so the effort is not spent twice. Checked against main 7f149ac9:

#2003  contains op_s_bfm_b64: True   merge-base 36a9a06f, 22 commits behind
#2007  contains op_s_bfm_b64: True   merge-base 1ebfe511, 27 commits behind

git checkout -B bfm-both origin/main
git merge pr-2003 && git merge pr-2007
    UU AGENTS.md
    AA tests/startup_gfx2hlsl_bfm_b64_check.py
    UU tools/startup/gfx2hlsl.py

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:

#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. #2007 enforces it; #2003 does not, so s_bfm_b64 s[3:4], … would be accepted. That is the one substantive difference I would not want to lose.
  • exec/vcc as sources — #2007 refuses them by name, #2003 accepts them through the generic s path. 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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147141562 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003#issuecomment-7147141562). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T23:12:41Z. --- ## Two open PRs lower `s_bfm_b64` — #2003 and #2007 — and they conflict on three files Not a problem with your patch; a coordination note so the effort is not spent twice. Checked against `main` `7f149ac9`: ```text #2003 contains op_s_bfm_b64: True merge-base 36a9a06f, 22 commits behind #2007 contains op_s_bfm_b64: True merge-base 1ebfe511, 27 commits behind git checkout -B bfm-both origin/main git merge pr-2003 && git merge pr-2007 UU AGENTS.md AA tests/startup_gfx2hlsl_bfm_b64_check.py UU tools/startup/gfx2hlsl.py ``` 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*: | | #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. #2007 enforces it; #2003 does not, so `s_bfm_b64 s[3:4], …` would be accepted. That is the one substantive difference I would not want to lose. - **`exec`/`vcc` as sources** — #2007 refuses them by name, #2003 accepts them through the generic `s` path. 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.
ChazY11 commented 2026-11-25 01:01:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:23:23Z.


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:

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_bfm_b64_check.py
startup s_bfm_b64 controls passed      exit 0
mutation result
constant fold loses its & 63 masks caught
the run-time path stops clearing sym for the destination pair caught
high-word condition bw > 32u → bw >= 32u survived
high-word shift (bw - 32u) & 31u → bw & 31u survived

The 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:

as written (bw>32, bw-32)   mismatches over 4096 pairs: 0
mutant 1   (bw>=32, bw-32)  mismatches over 4096 pairs: 0
mutant 2   (bw>32,  bw&31)  mismatches over 4096 pairs: 0

widths where (bw-32)&31 != bw&31 : []
widths where the high word is active : 33..63 (31 values)

The high word is only active for bw in 33..63, and on exactly that range (bw-32)&31 == bw&31, while at bw == 32 the 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

dst = 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:

s[2:3]      reg_range=('s', 2, 3)      accepted
s[3:4]      reg_range=('s', 3, 4)      accepted      <- odd
s[104:105]  reg_range=('s', 104, 105)  accepted

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:

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
is the one line I would take from the other one.

Where this version is stronger than #2007

bw - 32u instead of bw & 31u in the high word reads as the intent (they are equal, as shown above), and the folding path writes two exact 32-bit
words 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

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147342844 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003#issuecomment-7147342844). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T23:23:23Z. --- ## 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: ```powershell out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_bfm_b64_check.py startup s_bfm_b64 controls passed exit 0 ``` | mutation | result | |---|---| | constant fold loses its `& 63` masks | **caught** | | the run-time path stops clearing `sym` for the destination pair | **caught** | | high-word condition `bw > 32u` → `bw >= 32u` | survived | | high-word shift `(bw - 32u) & 31u` → `bw & 31u` | survived | ## The 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: ```text as written (bw>32, bw-32) mismatches over 4096 pairs: 0 mutant 1 (bw>=32, bw-32) mismatches over 4096 pairs: 0 mutant 2 (bw>32, bw&31) mismatches over 4096 pairs: 0 widths where (bw-32)&31 != bw&31 : [] widths where the high word is active : 33..63 (31 values) ``` The high word is only active for `bw` in 33..63, and on exactly that range `(bw-32)&31 == bw&31`, while at `bw == 32` the 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 ```python dst = 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: ```text s[2:3] reg_range=('s', 2, 3) accepted s[3:4] reg_range=('s', 3, 4) accepted <- odd s[104:105] reg_range=('s', 104, 105) accepted ``` 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: ```python 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 is the one line I would take from the other one. ## Where this version is stronger than #2007 `bw - 32u` instead of `bw & 31u` in the high word reads as the intent (they are equal, as shown above), and the folding path writes two exact 32-bit words 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 - AI-assisted review.
JB2WIN commented 2026-11-25 01:02:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T00:05:14Z.


@tedin7, #2007 lowers s_bfm_b64 too. 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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148123339 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003#issuecomment-7148123339). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-25T00:05:14Z. --- @tedin7, #2007 lowers `s_bfm_b64` too. 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 commented 2026-11-25 01:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:40:44Z.


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!

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148762497 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003#issuecomment-7148762497). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:40:44Z. --- 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 commented 2026-11-25 01:02:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:05:04Z.

Code review location: tools/startup/gfx2hlsl.py; line 924

@@ -920,6 +920,39 @@ def op_s_bfm_b32(self, ops, mods):
         self.set_s(d, '(((1u << (%s & 31)) - 1) << (%s & 31))' % (self.u(ops[1]), self.u(ops[2])))
         return None
 
+    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."""

P1 Badge 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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4687753583 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003#discussion_r4687753583). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:05:04Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 924 ~~~~diff @@ -920,6 +920,39 @@ def op_s_bfm_b32(self, ops, mods): self.set_s(d, '(((1u << (%s & 31)) - 1) << (%s & 31))' % (self.u(ops[1]), self.u(ops[2]))) return None + 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.""" ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> 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](https://github.com/R0Y00/Xbox2Windows/blob/ce590a3a5001c24d44bbed080866fefc320fa8e4/AGENTS.md#L207-L208) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:05:04Z.

Code review location: tools/startup/gfx2hlsl.py; line 944

@@ -920,6 +920,39 @@ def op_s_bfm_b32(self, ops, mods):
         self.set_s(d, '(((1u << (%s & 31)) - 1) << (%s & 31))' % (self.u(ops[1]), self.u(ops[2])))
         return None
 
+    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."""
+        if mods or len(ops) != 3:
+            raise Unsupported('s_bfm_b64 with %d operands and modifiers %s' % (len(ops), mods))
+        dst = 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])
+        vals = []
+        for o in ops[1:3]:
+            r = reg_range(o)
+            if r and r[0] == 's':
+                vals.append(self.is_const(r[1]))
+            else:
+                try:
+                    vals.append(int(o, 0))
+                except ValueError:
+                    vals.append(None)
+        d = dst[1]
+        if None not in vals:
+            value = (((1 << (vals[0] & 63)) - 1) << (vals[1] & 63)) & 0xffffffffffffffff
+            self.set_s(d, '0x%08xu' % (value & 0xffffffff), ('const', value & 0xffffffff))
+            self.set_s(d + 1, '0x%08xu' % (value >> 32), ('const', value >> 32))

P2 Badge 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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4687753594 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003#discussion_r4687753594). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:05:04Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 944 ~~~~diff @@ -920,6 +920,39 @@ def op_s_bfm_b32(self, ops, mods): self.set_s(d, '(((1u << (%s & 31)) - 1) << (%s & 31))' % (self.u(ops[1]), self.u(ops[2]))) return None + 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.""" + if mods or len(ops) != 3: + raise Unsupported('s_bfm_b64 with %d operands and modifiers %s' % (len(ops), mods)) + dst = 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]) + vals = [] + for o in ops[1:3]: + r = reg_range(o) + if r and r[0] == 's': + vals.append(self.is_const(r[1])) + else: + try: + vals.append(int(o, 0)) + except ValueError: + vals.append(None) + d = dst[1] + if None not in vals: + value = (((1 << (vals[0] & 63)) - 1) << (vals[1] & 63)) & 0xffffffffffffffff + self.set_s(d, '0x%08xu' % (value & 0xffffffff), ('const', value & 0xffffffff)) + self.set_s(d + 1, '0x%08xu' % (value >> 32), ('const', value >> 32)) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> 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 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:05:04Z.

Code review location: tools/startup/gfx2hlsl.py; line 948

@@ -920,6 +920,39 @@ def op_s_bfm_b32(self, ops, mods):
         self.set_s(d, '(((1u << (%s & 31)) - 1) << (%s & 31))' % (self.u(ops[1]), self.u(ops[2])))
         return None
 
+    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."""
+        if mods or len(ops) != 3:
+            raise Unsupported('s_bfm_b64 with %d operands and modifiers %s' % (len(ops), mods))
+        dst = 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])
+        vals = []
+        for o in ops[1:3]:
+            r = reg_range(o)
+            if r and r[0] == 's':
+                vals.append(self.is_const(r[1]))
+            else:
+                try:
+                    vals.append(int(o, 0))
+                except ValueError:
+                    vals.append(None)
+        d = dst[1]
+        if None not in vals:
+            value = (((1 << (vals[0] & 63)) - 1) << (vals[1] & 63)) & 0xffffffffffffffff
+            self.set_s(d, '0x%08xu' % (value & 0xffffffff), ('const', value & 0xffffffff))
+            self.set_s(d + 1, '0x%08xu' % (value >> 32), ('const', value >> 32))
+            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])

P2 Badge 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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4687753602 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2003#discussion_r4687753602). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:05:04Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 948 ~~~~diff @@ -920,6 +920,39 @@ def op_s_bfm_b32(self, ops, mods): self.set_s(d, '(((1u << (%s & 31)) - 1) << (%s & 31))' % (self.u(ops[1]), self.u(ops[2]))) return None + 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.""" + if mods or len(ops) != 3: + raise Unsupported('s_bfm_b64 with %d operands and modifiers %s' % (len(ops), mods)) + dst = 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]) + vals = [] + for o in ops[1:3]: + r = reg_range(o) + if r and r[0] == 's': + vals.append(self.is_const(r[1])) + else: + try: + vals.append(int(o, 0)) + except ValueError: + vals.append(None) + d = dst[1] + if None not in vals: + value = (((1 << (vals[0] & 63)) - 1) << (vals[1] & 63)) & 0xffffffffffffffff + self.set_s(d, '0x%08xu' % (value & 0xffffffff), ('const', value & 0xffffffff)) + self.set_s(d + 1, '0x%08xu' % (value >> 32), ('const', value >> 32)) + 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]) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> 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 👍 / 👎. <!-- codex-code-review-finding:v1 -->

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1996
No description provided.