startup: flip the sign bit for a negated source on the vector select #1703

Merged
triggered02 merged 6 commits from upstream-pr/1710 into main 2026-11-24 18:18:47 +00:00
triggered02 commented 2026-11-24 17:35:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T17:35:04Z.


Fixes #1709. Fourth group from the loading-screen refusal census (#870): 2 of 29 shaders.

Note on authorship: the branch now carries R0Y00's dfc73a1b ("Preserve unmodified negative select immediates"), which replaces my first attempt with a better design, plus his merge of main (ab586947). The description below reflects the final tree.

Change

In an integer instruction the - source modifier is that source's sign bit flipped — the bit pattern a float negation produces. The vector select passed the printed operand straight to the uint helper, so v_cndmask_b32_e64 v31, v30, -v30 did not translate:

v_cndmask_b32_e64 v31, v30, v30      -> v31 = (s0 & 1) ? v30 : v30;
v_cndmask_b32_e64 v31, v30, -v30     -> v31 = (s0 & 1) ? (v30 ^ 0x80000000u) : v30;

The helper is used only where the modifier is modelled. Another integer instruction carrying the same - operand still refuses rather than silently flipping a bit, so this does not quietly widen the accepted set.

Immediate operands (R0Y00's refinement)

The printed -1 is ambiguous: it can be the plain inline constant -1 (0xffffffff) or inline 1 with NEG set (0x80000001). Rather than guess from the text, the ambiguity is resolved in the decoder: decode() inspects the encoded source field and refuses NEG on immediate and literal data operands, while plain immediates keep translating:

v_cndmask_b32_e64 v31, -1, v30      -> v31 = (s0 & 1) ? v30 : 0xffffffffu;      (plain inline -1)
v_cndmask_b32_e64 v31, -1.0, v30    -> v31 = (s0 & 1) ? v30 : 0xbf800000u;      (plain inline -1.0)
NEG on an inline constant           -> REFUSED (decode)
NEG on a literal dword              -> REFUSED (decode)

Test

startup_gfx2hlsl_cndmask_neg builds VOP2-as-VOP3 encodings from the checked-in decoder's layout (0b110101 prefix, opcode 0x100 + n, neg bits w1[31:29]), decodes them, then translates — no game-derived bytes. Eleven checks: negation on either source and on both, the unchanged no-negation form, another integer op still refusing, plain -1 / -1.0 immediates translating, and NEG on an inline integer, an inline float and a literal all refused.

dev: startup_gfx2hlsl_cndmask_neg Passed 0.14 s; startup_translator Passed 0.18 s

Verified at the merged head ab586947.

Census A/B (local, aggregates only)

With the change, refusals grouped as operand '-v…' go 2 → 0, and those shaders progress to the next form (v_cvt_pknorm_u16_f32, v_cmp_class_f32).

What this does not establish

  • That the loading screen gets further — needs a run that visibly reaches it; counts are local aggregates.
  • |vN| (absolute) on an integer source and negations on other integer instructions stay refused.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587731145 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1710). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T17:35:04Z. --- Fixes #1709. Fourth group from the loading-screen refusal census (#870): 2 of 29 shaders. **Note on authorship:** the branch now carries R0Y00's `dfc73a1b` ("Preserve unmodified negative select immediates"), which replaces my first attempt with a better design, plus his merge of main (`ab586947`). The description below reflects the final tree. ## Change In an integer instruction the `-` source modifier is that source's **sign bit flipped** — the bit pattern a float negation produces. The vector select passed the printed operand straight to the uint helper, so `v_cndmask_b32_e64 v31, v30, -v30` did not translate: ``` v_cndmask_b32_e64 v31, v30, v30 -> v31 = (s0 & 1) ? v30 : v30; v_cndmask_b32_e64 v31, v30, -v30 -> v31 = (s0 & 1) ? (v30 ^ 0x80000000u) : v30; ``` The helper is used **only** where the modifier is modelled. Another integer instruction carrying the same `-` operand still refuses rather than silently flipping a bit, so this does not quietly widen the accepted set. ### Immediate operands (R0Y00's refinement) The printed `-1` is ambiguous: it can be the plain inline constant `-1` (0xffffffff) or inline `1` with NEG set (0x80000001). Rather than guess from the text, the ambiguity is resolved in the **decoder**: `decode()` inspects the encoded source field and refuses NEG on immediate and literal data operands, while plain immediates keep translating: ``` v_cndmask_b32_e64 v31, -1, v30 -> v31 = (s0 & 1) ? v30 : 0xffffffffu; (plain inline -1) v_cndmask_b32_e64 v31, -1.0, v30 -> v31 = (s0 & 1) ? v30 : 0xbf800000u; (plain inline -1.0) NEG on an inline constant -> REFUSED (decode) NEG on a literal dword -> REFUSED (decode) ``` ## Test `startup_gfx2hlsl_cndmask_neg` builds VOP2-as-VOP3 encodings from the checked-in decoder's layout (`0b110101` prefix, opcode `0x100 + n`, neg bits `w1[31:29]`), decodes them, then translates — no game-derived bytes. Eleven checks: negation on either source and on both, the unchanged no-negation form, another integer op still refusing, plain `-1` / `-1.0` immediates translating, and NEG on an inline integer, an inline float and a literal all refused. ``` dev: startup_gfx2hlsl_cndmask_neg Passed 0.14 s; startup_translator Passed 0.18 s ``` Verified at the merged head `ab586947`. ## Census A/B (local, aggregates only) With the change, refusals grouped as `operand '-v…'` go **2 → 0**, and those shaders progress to the next form (`v_cvt_pknorm_u16_f32`, `v_cmp_class_f32`). ## What this does not establish - That the loading screen gets further — needs a run that visibly reaches it; counts are local aggregates. - `|vN|` (absolute) on an integer source and negations on other integer instructions stay refused. AI-assisted (Claude Code).
tedin7 commented 2026-11-24 18:02:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:42:04Z.

Review: COMMENTED


Review of head efd7a2f86f93af91c0a11f749aaf9dac39788fb7 (Linux only; no Windows or RDNA2 hardware here).

Verdict: 0 P1, 1 P2, 1 P3. The change itself is correct for register and SGPR sources; the P2 is a neighbouring gap the new helper makes visible.

Semantics

  • RDNA2 v_cndmask_b32 (VOP3) accepts the NEG source modifier, and it flips bit 31 of that source. u_src emits (x ^ 0x80000000u), which is that behaviour. The select order is unchanged (mask ? src1 : src0).
  • The handler is the only caller, so v_and_b32_e64 ... -v30 still raises Unsupported. The widening claim in the PR text holds.
  • |v| and -|v| still reach u() and are refused.

P2: negated integer inline constant is read as a negative constant

The VOP3 decoder prints NEG on an inline constant as a plain -. llvm-mc prints neg(1) for that encoding and -1 for the different encoding src 193.

  • Encoding v_cndmask_b32_e64 v31, <src 129 (=1)>, v30, s0 with neg0 decodes to -1.
  • It translates to 0xffffffffu. Hardware gives 0x80000001.
  • The same happened before this PR (u('-1')), so it is not a regression. But u_src now claims to model the modifier and its re.match(r'-[\d.]', tok) guard cannot tell the two cases apart.
  • Suggestion: make the decoder print neg(c) for a constant (as _format_sdwa_float_modifiers already does), or refuse a negated integer constant, and add a control.

P3: the numeric guard is untested

Dropping not re.match(r'-[\d.]', tok) makes u_src('-1') return (0x00000001u ^ 0x80000000u), and the test still passes. A control with a plain -1 or -4.0 source would pin it.

Commands executed locally

  • python3 -B tests/startup_gfx2hlsl_cndmask_neg_check.py: 6 ok, PASS.
  • llvm-mc-19 -triple=amdgcn -mcpu=gfx1030 -show-encoding on the four select spellings (no neg, neg on src1, neg on src0, both). The bytes equal the ones the test builds (..., 0x00/0x40/0x20/0x60 in the last byte).
  • Local mutations of tools/startup/gfx2hlsl.py, each run against the test and then reverted:
    • sign flip removed: FAIL
    • source order swapped: FAIL
    • 0x8000000u (one zero short): FAIL
    • | instead of ^: FAIL
    • negation applied to both operands: FAIL
    • numeric guard removed: PASS (the P3 gap)
  • Probe: src 129 and 193 with neg bits, and sgpr, vcc and float-constant sources. This found the P2.

Limits: CMake registration and the ctest presets were not run; the Windows build and the loading-screen census claim (2 to 0) were not reproduced.

AI-assisted review.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044379866 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1710#pullrequestreview-6044379866). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:42:04Z. **Review:** COMMENTED --- Review of head `efd7a2f86f93af91c0a11f749aaf9dac39788fb7` (Linux only; no Windows or RDNA2 hardware here). **Verdict: 0 P1, 1 P2, 1 P3. The change itself is correct for register and SGPR sources; the P2 is a neighbouring gap the new helper makes visible.** ### Semantics - RDNA2 `v_cndmask_b32` (VOP3) accepts the NEG source modifier, and it flips bit 31 of that source. `u_src` emits `(x ^ 0x80000000u)`, which is that behaviour. The select order is unchanged (`mask ? src1 : src0`). - The handler is the only caller, so `v_and_b32_e64 ... -v30` still raises Unsupported. The widening claim in the PR text holds. - `|v|` and `-|v|` still reach `u()` and are refused. ### P2: negated integer inline constant is read as a negative constant The VOP3 decoder prints NEG on an inline constant as a plain `-`. llvm-mc prints `neg(1)` for that encoding and `-1` for the different encoding src 193. - Encoding `v_cndmask_b32_e64 v31, <src 129 (=1)>, v30, s0` with neg0 decodes to `-1`. - It translates to `0xffffffffu`. Hardware gives `0x80000001`. - The same happened before this PR (`u('-1')`), so it is not a regression. But `u_src` now claims to model the modifier and its `re.match(r'-[\d.]', tok)` guard cannot tell the two cases apart. - Suggestion: make the decoder print `neg(c)` for a constant (as `_format_sdwa_float_modifiers` already does), or refuse a negated integer constant, and add a control. ### P3: the numeric guard is untested Dropping `not re.match(r'-[\d.]', tok)` makes `u_src('-1')` return `(0x00000001u ^ 0x80000000u)`, and the test still passes. A control with a plain `-1` or `-4.0` source would pin it. ### Commands executed locally - `python3 -B tests/startup_gfx2hlsl_cndmask_neg_check.py`: 6 ok, PASS. - `llvm-mc-19 -triple=amdgcn -mcpu=gfx1030 -show-encoding` on the four select spellings (no neg, neg on src1, neg on src0, both). The bytes equal the ones the test builds (`..., 0x00/0x40/0x20/0x60` in the last byte). - Local mutations of `tools/startup/gfx2hlsl.py`, each run against the test and then reverted: - sign flip removed: FAIL - source order swapped: FAIL - `0x8000000u` (one zero short): FAIL - `|` instead of `^`: FAIL - negation applied to both operands: FAIL - numeric guard removed: PASS (the P3 gap) - Probe: src 129 and 193 with neg bits, and sgpr, vcc and float-constant sources. This found the P2. Limits: CMake registration and the `ctest` presets were not run; the Windows build and the loading-screen census claim (2 to 0) were not reproduced. AI-assisted review.
tedin7 commented 2026-11-24 18:02:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:58:53Z.

Review: COMMENTED


Review of head ab586947d920895a98d5b6601d11dd6daa9396a2 (4 commits: the original select change, b019275d and dfc73a1b which refuse NEG on an immediate and keep plain negative immediates, and a merge of main; tools/startup/gfx2hlsl.py +21/-1, new tests/startup_gfx2hlsl_cndmask_neg_check.py +126, CMakeLists.txt +3, docs/experiments.md +10). I reviewed the whole diff again; my earlier review was of efd7a2f8.

Linux limits. Linux x86_64, llvm-mc-19, Python 3.14. No CMake configure and no ctest (the startup_gfx2hlsl_cndmask_neg registration is unexercised), no Windows, no DXC, no WARP or GPU. The emitted HLSL is compared as text and was never compiled or run.

What I ran

  • python3 -B tests/startup_gfx2hlsl_cndmask_neg_check.py: PASS. Also exit 0: startup_gfx2hlsl_sdwa_check.py, startup_gfx2hlsl_vcvt_omod_check.py, startup_translator_check.py, startup_gfx2hlsl_bit_alu_check.py, startup_gfx2hlsl_smem_offset_check.py.
  • git diff --check origin/main...HEAD: clean; no non-ASCII added; no existing test line removed. tests/docs_links_check.py and tests/bidi_controls_check.py: pass. git merge-tree against current main: no conflicts.
  • Binary check: I assembled the instructions the test builds with encode_vop2_e64() using llvm-mc-19 -show-encoding for gfx1030 and gfx1013: v30, -v30, -v30, v30, -v30, -v30, plain -1 (src 193), plain -1.0 (src 243) and neg(1) (src 129 with NEG) are byte-identical to the encoder on both. The NEG bits (29 for src0, 30 for src1) and the 9-bit source fields in decode() therefore match the assembler.
  • Probes with the same encoder: |v30|, -|v30| and -s0 on the mask are refused (operand '|v30|', operand '-s0'), so abs and a negated mask do not slip through.
  • Nine mutations of the production code, each run against the new test and restored (git status clean):
    • no sign flip, and flipping bit 30 instead of 31: FAIL.
    • negation applied to the wrong source, and the two sources swapped: FAIL.
    • NEG on an immediate not refused: FAIL (NEG on literal remains refused).
    • NEG bit read from position 28+i: FAIL.
    • literal source (255) no longer refused: FAIL.
    • plain negative constants also flipped: FAIL (plain inline -1.0 still translates).
    • lower edge of the float inline range moved from 240 to 241: PASSED, not caught (see nit 1).

Semantics

  • A negated VOP3 source on v_cndmask_b32 flips bit 31 exactly: (v ^ 0x80000000u) keeps NaN payloads and turns -0.0 into +0.0, which is what a sign-bit flip does, without any canonicalisation. It applies to the source it is printed on, and the select order is unchanged ((mask & 1) ? src1 : src0).
  • The ambiguity of the printed -1 (plain inline -1, or inline 1 with NEG) is resolved from the encoded fields: NEG on 128..208, 240..248 and 255 is refused, plain negative immediates keep their bit pattern. I found no case where NEG is silently dropped.

Findings: 0 P1, 0 P2, 3 nits

  1. Nit, coverage. The refusal range edges (128, 208, 240, 248) are not each exercised: the mutation above moving 240 to 241 survives, because the tests only use 129, 242 and 255 with NEG.
  2. Nit. op_v_cndmask_b32 ignores mods, so clamp and mul:2 on v_cndmask_b32_e64 translate to the same text with the modifier dropped (I checked with the encoder). This is not introduced by the PR (the handler ignored them before), and I did not verify whether the hardware applies them to this instruction, so I only flag it.
  3. Nit. startup_gfx2hlsl_cndmask_neg_check.py uses encode_vop2_e64(AND_B32, ... neg1=1) for "another integer op stays refused"; llvm-mc-19 rejects v_and_b32_e64 ..., -v30, so that bytes pattern is not one an assembler produces. It still checks the intended property (the decoder's text is refused).
  • Not verified: the "2 of 29" census (local cache), DXC or FXC compilation, any draw.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044621127 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1710#pullrequestreview-6044621127). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:58:53Z. **Review:** COMMENTED --- Review of head `ab586947d920895a98d5b6601d11dd6daa9396a2` (4 commits: the original select change, `b019275d` and `dfc73a1b` which refuse NEG on an immediate and keep plain negative immediates, and a merge of main; `tools/startup/gfx2hlsl.py` +21/-1, new `tests/startup_gfx2hlsl_cndmask_neg_check.py` +126, `CMakeLists.txt` +3, `docs/experiments.md` +10). I reviewed the whole diff again; my earlier review was of `efd7a2f8`. **Linux limits.** Linux x86_64, `llvm-mc-19`, Python 3.14. No CMake configure and no `ctest` (the `startup_gfx2hlsl_cndmask_neg` registration is unexercised), no Windows, no DXC, no WARP or GPU. The emitted HLSL is compared as text and was never compiled or run. **What I ran** - `python3 -B tests/startup_gfx2hlsl_cndmask_neg_check.py`: PASS. Also exit 0: `startup_gfx2hlsl_sdwa_check.py`, `startup_gfx2hlsl_vcvt_omod_check.py`, `startup_translator_check.py`, `startup_gfx2hlsl_bit_alu_check.py`, `startup_gfx2hlsl_smem_offset_check.py`. - `git diff --check origin/main...HEAD`: clean; no non-ASCII added; no existing test line removed. `tests/docs_links_check.py` and `tests/bidi_controls_check.py`: pass. `git merge-tree` against current main: no conflicts. - Binary check: I assembled the instructions the test builds with `encode_vop2_e64()` using `llvm-mc-19 -show-encoding` for `gfx1030` and `gfx1013`: `v30, -v30`, `-v30, v30`, `-v30, -v30`, plain `-1` (src 193), plain `-1.0` (src 243) and `neg(1)` (src 129 with NEG) are byte-identical to the encoder on both. The NEG bits (29 for src0, 30 for src1) and the 9-bit source fields in `decode()` therefore match the assembler. - Probes with the same encoder: `|v30|`, `-|v30|` and `-s0` on the mask are refused (`operand '|v30|'`, `operand '-s0'`), so abs and a negated mask do not slip through. - Nine mutations of the production code, each run against the new test and restored (`git status` clean): - no sign flip, and flipping bit 30 instead of 31: FAIL. - negation applied to the wrong source, and the two sources swapped: FAIL. - NEG on an immediate not refused: FAIL (`NEG on literal remains refused`). - NEG bit read from position 28+i: FAIL. - literal source (255) no longer refused: FAIL. - plain negative constants also flipped: FAIL (`plain inline -1.0 still translates`). - lower edge of the float inline range moved from 240 to 241: PASSED, not caught (see nit 1). **Semantics** - A negated VOP3 source on `v_cndmask_b32` flips bit 31 exactly: `(v ^ 0x80000000u)` keeps NaN payloads and turns -0.0 into +0.0, which is what a sign-bit flip does, without any canonicalisation. It applies to the source it is printed on, and the select order is unchanged (`(mask & 1) ? src1 : src0`). - The ambiguity of the printed `-1` (plain inline -1, or inline 1 with NEG) is resolved from the encoded fields: NEG on 128..208, 240..248 and 255 is refused, plain negative immediates keep their bit pattern. I found no case where NEG is silently dropped. **Findings: 0 P1, 0 P2, 3 nits** 1. Nit, coverage. The refusal range edges (128, 208, 240, 248) are not each exercised: the mutation above moving 240 to 241 survives, because the tests only use 129, 242 and 255 with NEG. 2. Nit. `op_v_cndmask_b32` ignores `mods`, so `clamp` and `mul:2` on `v_cndmask_b32_e64` translate to the same text with the modifier dropped (I checked with the encoder). This is not introduced by the PR (the handler ignored them before), and I did not verify whether the hardware applies them to this instruction, so I only flag it. 3. Nit. `startup_gfx2hlsl_cndmask_neg_check.py` uses `encode_vop2_e64(AND_B32, ... neg1=1)` for "another integer op stays refused"; `llvm-mc-19` rejects `v_and_b32_e64 ..., -v30`, so that bytes pattern is not one an assembler produces. It still checks the intended property (the decoder's text is refused). - Not verified: the "2 of 29" census (local cache), DXC or FXC compilation, any draw. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 18:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T17:35:19Z.


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-24T17:37:54.986419Z efd7a2f 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:7139416679 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1710#issuecomment-7139416679). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:35:19Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"efd7a2f86f93af91c0a11f749aaf9dac39788fb7","has_any_findings":false,"has_unresolved_findings":false,"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-24T17:37:54.986419Z">2026-11-24T17:37:54.986419Z</relative-time> | `efd7a2f` | 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>
triggered02 commented 2026-11-24 18:02:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T17:43:17Z.


Both addressed in b019275d (rebased onto current main).

P2 — the ambiguous spelling is now refused, not guessed. You are right that the printed operand does not identify the value: src 193 is the literal -1 (0xffffffff) and src 129 with NEG is inline 1 with its sign bit flipped (0x80000001), and both print as -1. u_src now raises for that exact spelling instead of picking one reading, so the select no longer translates to 0xffffffff for a case that may be 0x80000001:

v_cndmask_b32_e64 v31, -1, v30      -> REFUSED: negated integer constant '-1' is ambiguous
v_cndmask_b32_e64 v31, --1, v30     -> v31 = (s0 & 1) ? v30 : (0xffffffffu ^ 0x80000000u);   (src 193 with NEG, unambiguous)

I did not change the decoder to print neg(1): that is a disassembly-wide output change and belongs in its own slice, not inside a select fix. Refusing keeps this PR's claim honest — it models the modifier only where the printed operand identifies the source.

P3 — the guard is pinned. Two controls, one per encoding, plus a check that both decode to the same text (which is why refusal is the right answer):

a negated inline constant is refused as ambiguous: ok
a negative literal source is refused as ambiguous too: ok
both spellings decode identically: ok
a double negation still translates: ok

Your mutation now fails: dropping the guard gives fail-first exit: 1 | a negative literal source is refused as ambiguous too.

Verified after rebase on 107a0466: test passes in dev (0.16 s) and release (0.14 s). Re-running the CMake configure per preset first, since your review correctly noted the presets were not exercised.

Thanks for probing the constant sources — that is precisely the class of thing a register-only fixture hides.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7139607807 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1710#issuecomment-7139607807). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T17:43:17Z. --- Both addressed in `b019275d` (rebased onto current main). **P2 — the ambiguous spelling is now refused, not guessed.** You are right that the printed operand does not identify the value: `src 193` is the literal `-1` (0xffffffff) and `src 129` with NEG is inline `1` with its sign bit flipped (0x80000001), and both print as `-1`. `u_src` now raises for that exact spelling instead of picking one reading, so the select no longer translates to 0xffffffff for a case that may be 0x80000001: ``` v_cndmask_b32_e64 v31, -1, v30 -> REFUSED: negated integer constant '-1' is ambiguous v_cndmask_b32_e64 v31, --1, v30 -> v31 = (s0 & 1) ? v30 : (0xffffffffu ^ 0x80000000u); (src 193 with NEG, unambiguous) ``` I did not change the decoder to print `neg(1)`: that is a disassembly-wide output change and belongs in its own slice, not inside a select fix. Refusing keeps this PR's claim honest — it models the modifier only where the printed operand identifies the source. **P3 — the guard is pinned.** Two controls, one per encoding, plus a check that both decode to the same text (which is *why* refusal is the right answer): ``` a negated inline constant is refused as ambiguous: ok a negative literal source is refused as ambiguous too: ok both spellings decode identically: ok a double negation still translates: ok ``` Your mutation now fails: dropping the guard gives `fail-first exit: 1 | a negative literal source is refused as ambiguous too`. Verified after rebase on `107a0466`: test passes in dev (0.16 s) and release (0.14 s). Re-running the CMake configure per preset first, since your review correctly noted the presets were not exercised. Thanks for probing the constant sources — that is precisely the class of thing a register-only fixture hides. AI-assisted (Claude Code).
R0Y00 commented 2026-11-24 18:03:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T17:51:27Z.


I pushed dfc73a1b to fix the Linux regression. Plain negative inline constants keep their existing value in both encodings. Encoded NEG on an immediate is still refused, even when it disassembles with the same spelling as a plain constant. The new select fixture and both failing Linux cases (startup_flat_param_check.py and startup_gfx2hlsl_bit_alu_check.py) passed locally. Waiting on the checks for this new head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7139804320 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1710#issuecomment-7139804320). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T17:51:27Z. --- I pushed dfc73a1b to fix the Linux regression. Plain negative inline constants keep their existing value in both encodings. Encoded NEG on an immediate is still refused, even when it disassembles with the same spelling as a plain constant. The new select fixture and both failing Linux cases (startup_flat_param_check.py and startup_gfx2hlsl_bit_alu_check.py) passed locally. Waiting on the checks for this new head.
upstream-sync closed this pull request 2026-11-24 19:01:03 +00:00
tedin7 commented 2026-11-24 19:01:04 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Re-review of head f9e815d5f6 (comment only, not an approval). My earlier review was at ab586947.

Verdict: 0 P1 / 0 P2, three nits. Update: while I was reviewing, the head moved from 9bed7ffc to f9e815d5, which is a merge of main. The PR's own changes are identical (the added and removed lines of gfx2hlsl.py, the test, docs/experiments.md and CMakeLists.txt compare equal to the 9bed7ffc diff against main). At the new head the cndmask test (PASS), the sdwa and vcvt_omod checks, docs_links_check (17 files, 366 links), bidi_controls_check (1303 files) and git diff --check origin/main...HEAD pass again. The mutation results below were run at 9bed7ffc and not repeated.

Earlier points, all fixed: the NEG range edges are now tried on 128, 208, 240 and 248 plus a plain 0.5 (240 -> 241 and 208 -> 207 both fail); clamp and mul:2 are no longer dropped silently (op_v_cndmask_b32 raises on any mods, two tests pin it); the v_and_b32_e64 fixture is kept with a comment. The only commit since is 9bed7ffc (+3 lines in gfx2hlsl.py and the test).

Semantics

  • (x ^ 0x80000000u) is an exact sign-bit flip: NaN payloads are kept and -0.0 becomes +0.0, with no canonicalisation. It applies to the source it is printed on and the select order is unchanged.
  • The mask is never negated; v_cndmask_b32_e64 ..., -s0 does not assemble in llvm-mc. |v30| and -|v30| (assembled for gfx1030) are refused with operand '|v30|'. The e32 form has no modifiers; the SDWA form with -v30 is refused as a whole.
  • A constant source such as -0x3f800000 assembles to inline -4.0 and translates to 0xc0800000u; NEG on a constant source is refused by encoded field in decode() (128..208, 240..248, 255).
  • No assertion is weakened (the test diff is additive) and no test searches source text. Doc claims match the tests; no title content.

Run

  • python3 -B tests/startup_gfx2hlsl_cndmask_neg_check.py: PASS. sdwa, vcvt_omod, translator, bit_alu, smem_offset and flat_param checks: pass. docs_links_check (17 files, 365 links), bidi_controls_check (1296 files), git diff --check origin/main...HEAD: clean. llvm-mc-19 -mcpu=gfx1030 was used on the probe forms and its bytes fed through G.decode and Stage.one.
  • 13 production mutations in tools/startup/gfx2hlsl.py (each restored with git checkout --). Caught: bit 30 instead of 31; swapped sources; dropped mods refusal; neg check only on src0; literal 255 no longer refused; NEG bit read from position 28+i; range 208 -> 207; range 240 -> 241.
  • NOT caught: the mask routed through u_src (no test pins "a negated mask is refused"; no assembler can emit it); stripping | in u_src (self.u(tok[1:].strip('|'))), which would turn -|v30| into a plain negation, although production refuses both today; and 248 -> 247, which is equivalent because source 248 is not a decodable inline constant.

Nits

  1. Add a decoder-produced -s0 mask control, or document why it cannot be encoded.
  2. Add |v30| and -|v30| refusal controls; the PR text says abs stays refused but nothing pins it.
  3. A decoded v_cndmask_b32_e64 ... vcc_lo emits (vcc & 1); pre-existing and out of scope.

Overlap: no cndmask or u_src hits in #1755, #1747, #1703, #1706, #1712, #1708, #1745 and #1741 (only those eight were grepped). Main has moved; I did not check whether a rebase conflicts.

Not run: CMake/ctest (so the startup_gfx2hlsl_cndmask_neg add_test is unexercised), DXC or WARP (the emitted HLSL is compared as text, never compiled), the census claim (2 of 29 shaders, 2 -> 0), mingw (no C++ in the diff).

Linux limits: no Windows, WARP, DXC or GPU here; LLVM 19 only (CI pins LLVM 15). Anything that needs them was not run.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044902730 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1710#pullrequestreview-6044902730). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:17:57Z. **Review:** COMMENTED --- Re-review of head f9e815d5f6f2edd6c6058b2cc867b5404501c18c (comment only, not an approval). My earlier review was at ab586947. Verdict: 0 P1 / 0 P2, three nits. Update: while I was reviewing, the head moved from 9bed7ffc to f9e815d5, which is a merge of main. The PR's own changes are identical (the added and removed lines of gfx2hlsl.py, the test, docs/experiments.md and CMakeLists.txt compare equal to the 9bed7ffc diff against main). At the new head the cndmask test (PASS), the sdwa and vcvt_omod checks, docs_links_check (17 files, 366 links), bidi_controls_check (1303 files) and `git diff --check origin/main...HEAD` pass again. The mutation results below were run at 9bed7ffc and not repeated. Earlier points, all fixed: the NEG range edges are now tried on 128, 208, 240 and 248 plus a plain 0.5 (240 -> 241 and 208 -> 207 both fail); `clamp` and `mul:2` are no longer dropped silently (`op_v_cndmask_b32` raises on any `mods`, two tests pin it); the `v_and_b32_e64` fixture is kept with a comment. The only commit since is 9bed7ffc (+3 lines in gfx2hlsl.py and the test). Semantics - `(x ^ 0x80000000u)` is an exact sign-bit flip: NaN payloads are kept and -0.0 becomes +0.0, with no canonicalisation. It applies to the source it is printed on and the select order is unchanged. - The mask is never negated; `v_cndmask_b32_e64 ..., -s0` does not assemble in llvm-mc. `|v30|` and `-|v30|` (assembled for gfx1030) are refused with `operand '|v30|'`. The e32 form has no modifiers; the SDWA form with `-v30` is refused as a whole. - A constant source such as `-0x3f800000` assembles to inline -4.0 and translates to `0xc0800000u`; NEG on a constant source is refused by encoded field in `decode()` (128..208, 240..248, 255). - No assertion is weakened (the test diff is additive) and no test searches source text. Doc claims match the tests; no title content. Run - `python3 -B tests/startup_gfx2hlsl_cndmask_neg_check.py`: PASS. sdwa, vcvt_omod, translator, bit_alu, smem_offset and flat_param checks: pass. docs_links_check (17 files, 365 links), bidi_controls_check (1296 files), `git diff --check origin/main...HEAD`: clean. llvm-mc-19 `-mcpu=gfx1030` was used on the probe forms and its bytes fed through `G.decode` and `Stage.one`. - 13 production mutations in tools/startup/gfx2hlsl.py (each restored with `git checkout --`). Caught: bit 30 instead of 31; swapped sources; dropped `mods` refusal; neg check only on src0; literal 255 no longer refused; NEG bit read from position 28+i; range 208 -> 207; range 240 -> 241. - NOT caught: the mask routed through `u_src` (no test pins "a negated mask is refused"; no assembler can emit it); stripping `|` in `u_src` (`self.u(tok[1:].strip('|'))`), which would turn `-|v30|` into a plain negation, although production refuses both today; and 248 -> 247, which is equivalent because source 248 is not a decodable inline constant. Nits 1. Add a decoder-produced `-s0` mask control, or document why it cannot be encoded. 2. Add `|v30|` and `-|v30|` refusal controls; the PR text says abs stays refused but nothing pins it. 3. A decoded `v_cndmask_b32_e64 ... vcc_lo` emits `(vcc & 1)`; pre-existing and out of scope. Overlap: no `cndmask` or `u_src` hits in #1755, #1747, #1703, #1706, #1712, #1708, #1745 and #1741 (only those eight were grepped). Main has moved; I did not check whether a rebase conflicts. Not run: CMake/ctest (so the `startup_gfx2hlsl_cndmask_neg` add_test is unexercised), DXC or WARP (the emitted HLSL is compared as text, never compiled), the census claim (2 of 29 shaders, 2 -> 0), mingw (no C++ in the diff). Linux limits: no Windows, WARP, DXC or GPU here; LLVM 19 only (CI pins LLVM 15). Anything that needs them was not run. AI-assisted; commands listed were executed locally.
triggered02 commented 2026-11-24 19:01:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:05:24Z.


All three nits addressed in 9bed7ffc (on top of your ab586947).

1 — range edges. The test now tries NEG on each boundary the decoder refuses (128, 208, 240, 248) and a plain 0.5 that must keep translating, so your surviving mutation no longer passes:

NEG on the immediate at 128/208/240/248: refused
plain 0.5 still translates -> v31 = (s0 & 1) ? v30 : 0x3f000000u;
fail-first: 240 -> 241  =>  "NEG on the immediate at 240 is refused" FAIL

2 — modifiers silently dropped. You are right that this predates the PR, and the same reasoning as the PR itself applies: a modifier the text drops changes the value. op_v_cndmask_b32 now refuses any modifier instead of ignoring it, and both cases are pinned:

a clamp on the select is refused
a mul:2 on the select is refused
fail-first: removing the refusal  =>  "a mul:2 on the select is refused" FAIL

I did not try to establish what the hardware does with those bits on this instruction — same limit you noted, so refusal is the safe side.

3 — non-assembler encoding. Kept, with a comment stating that llvm-mc rejects -v30 on v_and_b32_e64 and that the property under test is only that a handler which does not model the modifier refuses the decoder's text.

Verification: the Python-level tests that reach gfx2hlsl pass in dev (startup_image_sample_l, startup_image_sample_c, the image control tests, startup_translator) and startup_gfx2hlsl_cndmask_neg passes in release. The dev tree here has no built executables (5 files in out/build/dev), so the whole startup_* family returned 142 failures for missing binaries — not a signal about this change. Flagging that plainly rather than quoting a green family I did not get.

Thanks for the byte-level assembler cross-check against both gfx1030 and gfx1013; that is the part of the encoder I could not verify locally.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7140140460 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1710#issuecomment-7140140460). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T18:05:24Z. --- All three nits addressed in `9bed7ffc` (on top of your `ab586947`). **1 — range edges.** The test now tries NEG on each boundary the decoder refuses (128, 208, 240, 248) and a plain `0.5` that must keep translating, so your surviving mutation no longer passes: ``` NEG on the immediate at 128/208/240/248: refused plain 0.5 still translates -> v31 = (s0 & 1) ? v30 : 0x3f000000u; fail-first: 240 -> 241 => "NEG on the immediate at 240 is refused" FAIL ``` **2 — modifiers silently dropped.** You are right that this predates the PR, and the same reasoning as the PR itself applies: a modifier the text drops changes the value. `op_v_cndmask_b32` now refuses any modifier instead of ignoring it, and both cases are pinned: ``` a clamp on the select is refused a mul:2 on the select is refused fail-first: removing the refusal => "a mul:2 on the select is refused" FAIL ``` I did not try to establish what the hardware does with those bits on this instruction — same limit you noted, so refusal is the safe side. **3 — non-assembler encoding.** Kept, with a comment stating that `llvm-mc` rejects `-v30` on `v_and_b32_e64` and that the property under test is only that a handler which does not model the modifier refuses the decoder's text. Verification: the Python-level tests that reach `gfx2hlsl` pass in dev (`startup_image_sample_l`, `startup_image_sample_c`, the image control tests, `startup_translator`) and `startup_gfx2hlsl_cndmask_neg` passes in release. The dev tree here has no built executables (5 files in `out/build/dev`), so the whole `startup_*` family returned 142 failures for missing binaries — not a signal about this change. Flagging that plainly rather than quoting a green family I did not get. Thanks for the byte-level assembler cross-check against both `gfx1030` and `gfx1013`; that is the part of the encoder I could not verify locally. AI-assisted (Claude Code).
triggered02 commented 2026-11-24 19:01:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:23:47Z.


Both coverage nits are closed in #+ (($pr -split '/')[-1].Trim()) +.

  • Negated mask: it can be decoded — setting w1[31] makes the decoder print -s0 (LLVM just refuses to assemble it, which is why no fixture existed). The test now asserts REFUSED: operand '-s0' with a comment saying the word is decoder-produced only. So the answer to your nit 1 is "encodable from the word, only refused before by accident" rather than "cannot be encoded".
  • Absolute values: the encoder gained the abs bits; |v30| on the first source, the second source and both are pinned as refused (operand '|v30|').

Fail-first: routing the mask through u_src fails a negated mask is refused; stripping the abs bars in u_src fails absolute values on both sources are refused. 22 checks; dev startup_gfx2hlsl* 10/10 and the release test pass; docs/bidi checks pass.

Your nit 3 (vcc_lo emitting (vcc & 1)) stays out of scope, as you flagged.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7140585677 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1710#issuecomment-7140585677). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T18:23:47Z. --- Both coverage nits are closed in **#` + (($pr -split '/')[-1].Trim()) + `**. - **Negated mask:** it *can* be decoded — setting `w1[31]` makes the decoder print `-s0` (LLVM just refuses to assemble it, which is why no fixture existed). The test now asserts `REFUSED: operand '-s0'` with a comment saying the word is decoder-produced only. So the answer to your nit 1 is "encodable from the word, only refused before by accident" rather than "cannot be encoded". - **Absolute values:** the encoder gained the abs bits; `|v30|` on the first source, the second source and both are pinned as refused (`operand '|v30|'`). Fail-first: routing the mask through `u_src` fails *a negated mask is refused*; stripping the abs bars in `u_src` fails *absolute values on both sources are refused*. 22 checks; dev `startup_gfx2hlsl*` 10/10 and the release test pass; docs/bidi checks pass. Your nit 3 (`vcc_lo` emitting `(vcc & 1)`) stays out of scope, as you flagged. AI-assisted (Claude Code).
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!1703
No description provided.