pixel_aot: read v_fma_mix op_sel_hi as the binary16 flag and op_sel as the high half #2093

Merged
Leyukaka merged 3 commits from upstream-pr/2100 into main 2026-11-25 00:21:03 +00:00
Leyukaka commented 2026-11-25 00:14:12 +00:00 (Migrated from github.com)

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


pixel_aot read the two VOP3P selector fields of v_fma_mix_f32, v_fma_mixlo_f16 and v_fma_mixhi_f16 the wrong way round: op_sel[i] as "source i is binary16" and op_sel_hi[i] as "high half". LLVM, whose syntax disasm_rdna2.py prints, defines the opposite in SelectVOP3PMadMixModsImpl (llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp):

// If the source's op_sel_hi is set, it indicates to do a conversion from fp16.
// If the sources's op_sel is set, it picks the high half of the source register.

LLVM's tests print v_fma_mix_f32 v0, v0, v1, v2 op_sel_hi:[1,1,1] for three low binary16 halves. For three high halves they print op_sel:[1,1,1] op_sel_hi:[1,1,1] (llvm/test/CodeGen/AMDGPU/mad-mix.ll, GFX1100 checks). The old parser refused the first form.

The selector roles already match LLVM in two other places. tools/ffx_dispatch_aot.py requires op_sel_hi:[0,1,0] for its binary16 source and uses op_sel:[0,1,0] for the high half. tools/startup/gfx2hlsl.py uses op_sel_hi as the binary16 flag for mixlo/mixhi and refuses op_sel.

Changes

  • Selectors. parse_fma_mix and the v_fma_mix* handler use op_sel_hi as the binary16 flag and op_sel as the half select. op_sel[i] = 1 on a binary32 source (op_sel_hi[i] = 0) is refused. SelectVOP3PMadMixModsImpl never sets it, and I found no description of its hardware effect.
  • fma_mix_operand:
    • -0 (NEG on inline 0) lowers to asfloat(0x80000000u); it used to lower to +0.0.
    • -1 .. -16 are refused. The disassembler prints the same text for the inline negative integer and for NEG on inline 1..16. This also refuses genuine inline -1..-16, which used to lower to their integer words, and |-N|.
  • Tests: fixtures re-spelled in LLVM's reading, same arithmetic.
    • pixel_aot_check.py: the draw program and its op_sel mutation.
    • rdna2_tools_check.py: the combined-modifier encodings, the end-to-end shader, the bad_tail and bad_shader_asm negative cases, and one line of the llvm-mc comparison fixture. That fixture is skipped without LLVM_LIB and was skipped in the run below.
    • pso_readiness_check.py: the readiness example, which only checks opcode support.
    • Lines with op_sel:[1,0,0] op_sel_hi:[1,0,0] mean the same in both readings and are unchanged.
  • Tests: new checks. LLVM's all-low and all-high forms, -0, and the ambiguous -N.
  • Repro bytes. 0c1920cc2c26524c from #745 still decodes to the same text. The bytes were built in #745 to reproduce the existing fixture text, which used the old reading. That text sets op_sel on binary32 source 1, so it is now refused; the test asserts the refusal.
  • Docs. The mixed-precision paragraph in docs/experiments.md states the field roles and cites LLVM.
  • Scanner. A comment in scan_unsupported_shaders.py notes that its pattern matches opcode and destination only, while lower() validates the selectors.

Tests

Windows 11, MSVC, cmake --preset dev, WARP:

python -B tests/rdna2_tools_check.py      # OK (skipped=19, including test_llvm_comparison: no LLVM_LIB)
python -B tests/pso_readiness_check.py    # passed
ctest --preset dev --no-tests=error -R '^pixel_aot_core_vector_warp$'   # 100% tests passed (1)

Negative control: I ran the updated tests against the previous tools/pixel_aot.py.

  • pixel_aot_core_vector_warp fails in check_fma_mix_draw, because parse_fma_mix raises on op_sel_hi:[1,1,0].
  • rdna2_tools_check.py fails test_vop3p_fma_mix_inline_abs_neg_modifiers.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594124014 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2100). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-25T00:14:12Z. --- `pixel_aot` read the two VOP3P selector fields of `v_fma_mix_f32`, `v_fma_mixlo_f16` and `v_fma_mixhi_f16` the wrong way round: `op_sel[i]` as "source i is binary16" and `op_sel_hi[i]` as "high half". LLVM, whose syntax `disasm_rdna2.py` prints, defines the opposite in `SelectVOP3PMadMixModsImpl` (`llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp`): > // If the source's op_sel_hi is set, it indicates to do a conversion from fp16. > // If the sources's op_sel is set, it picks the high half of the source register. LLVM's tests print `v_fma_mix_f32 v0, v0, v1, v2 op_sel_hi:[1,1,1]` for three low binary16 halves. For three high halves they print `op_sel:[1,1,1] op_sel_hi:[1,1,1]` (`llvm/test/CodeGen/AMDGPU/mad-mix.ll`, GFX1100 checks). The old parser refused the first form. The selector roles already match LLVM in two other places. `tools/ffx_dispatch_aot.py` requires `op_sel_hi:[0,1,0]` for its binary16 source and uses `op_sel:[0,1,0]` for the high half. `tools/startup/gfx2hlsl.py` uses `op_sel_hi` as the binary16 flag for `mixlo`/`mixhi` and refuses `op_sel`. ## Changes - **Selectors.** `parse_fma_mix` and the `v_fma_mix*` handler use `op_sel_hi` as the binary16 flag and `op_sel` as the half select. `op_sel[i] = 1` on a binary32 source (`op_sel_hi[i] = 0`) is refused. `SelectVOP3PMadMixModsImpl` never sets it, and I found no description of its hardware effect. - **`fma_mix_operand`:** - `-0` (NEG on inline 0) lowers to `asfloat(0x80000000u)`; it used to lower to +0.0. - `-1` .. `-16` are refused. The disassembler prints the same text for the inline negative integer and for NEG on inline `1`..`16`. This also refuses genuine inline `-1`..`-16`, which used to lower to their integer words, and `|-N|`. - **Tests: fixtures re-spelled in LLVM's reading, same arithmetic.** - `pixel_aot_check.py`: the draw program and its `op_sel` mutation. - `rdna2_tools_check.py`: the combined-modifier encodings, the end-to-end shader, the `bad_tail` and `bad_shader_asm` negative cases, and one line of the `llvm-mc` comparison fixture. That fixture is skipped without `LLVM_LIB` and was skipped in the run below. - `pso_readiness_check.py`: the readiness example, which only checks opcode support. - Lines with `op_sel:[1,0,0] op_sel_hi:[1,0,0]` mean the same in both readings and are unchanged. - **Tests: new checks.** LLVM's all-low and all-high forms, `-0`, and the ambiguous `-N`. - **Repro bytes.** `0c1920cc2c26524c` from #745 still decodes to the same text. The bytes were built in #745 to reproduce the existing fixture text, which used the old reading. That text sets `op_sel` on binary32 source 1, so it is now refused; the test asserts the refusal. - **Docs.** The mixed-precision paragraph in `docs/experiments.md` states the field roles and cites LLVM. - **Scanner.** A comment in `scan_unsupported_shaders.py` notes that its pattern matches opcode and destination only, while `lower()` validates the selectors. ## Tests Windows 11, MSVC, `cmake --preset dev`, WARP: ``` python -B tests/rdna2_tools_check.py # OK (skipped=19, including test_llvm_comparison: no LLVM_LIB) python -B tests/pso_readiness_check.py # passed ctest --preset dev --no-tests=error -R '^pixel_aot_core_vector_warp$' # 100% tests passed (1) ``` Negative control: I ran the updated tests against the previous `tools/pixel_aot.py`. - `pixel_aot_core_vector_warp` fails in `check_fma_mix_draw`, because `parse_fma_mix` raises on `op_sel_hi:[1,1,0]`. - `rdna2_tools_check.py` fails `test_vop3p_fma_mix_inline_abs_neg_modifiers`. AI-assisted.
upstream-sync closed this pull request 2026-11-25 01:01:40 +00:00
tedin7 commented 2026-11-25 01:01:41 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 5cdecfe8786d53449c8d78aebf41f72a18ac5d31.

Semantics: op_sel_hi[i] now means binary16 and op_sel[i] picks the high half, which matches LLVM's printed form. The parser check, the lowerer zip, the -0 handling and the ambiguous negative inline constants are all consistent with that. Tests and docs follow. Only Python, docs and test files changed, with no CMake changes. The change is clean-room, with LLVM cited only as a reference.

Commands executed:

  • git merge-tree --write-tree --name-only origin/main HEAD: no conflicts
  • python3 tests/pixel_aot_check.py, tests/pso_readiness_check.py, tests/rdna2_tools_check.py (154 tests, OK), tests/docs_links_check.py, tests/bidi_controls_check.py: all PASS
  • git diff --check origin/main...HEAD: clean
  • Win2025 (Debug and Release /O2), ctest -R '^(pixel_aot_core_vector_|rdna2_tools_check|pso_readiness_check)': 4/4 passed in each config. The Windows Python checks for the three touched tests also passed.
  • CI: Windows build/test, Linux checks and gfx1013 fixtures all pass.

Mutations killed (both reported by tests/rdna2_tools_check.py, then reverted):

  • parse_fma_mix validation zip swapped back to (op_sel, op_sel_hi): 1 failure.
  • lower operand zip swapped back to (op_sel, op_sel_hi): 1 failure.

P1: 0. P2: 0.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049598311 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2100#pullrequestreview-6049598311). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:20:19Z. **Review:** COMMENTED --- Review of head `5cdecfe8786d53449c8d78aebf41f72a18ac5d31`. Semantics: `op_sel_hi[i]` now means binary16 and `op_sel[i]` picks the high half, which matches LLVM's printed form. The parser check, the lowerer zip, the `-0` handling and the ambiguous negative inline constants are all consistent with that. Tests and docs follow. Only Python, docs and test files changed, with no CMake changes. The change is clean-room, with LLVM cited only as a reference. Commands executed: - `git merge-tree --write-tree --name-only origin/main HEAD`: no conflicts - `python3 tests/pixel_aot_check.py`, `tests/pso_readiness_check.py`, `tests/rdna2_tools_check.py` (154 tests, OK), `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: all PASS - `git diff --check origin/main...HEAD`: clean - Win2025 (Debug and Release /O2), `ctest -R '^(pixel_aot_core_vector_|rdna2_tools_check|pso_readiness_check)'`: 4/4 passed in each config. The Windows Python checks for the three touched tests also passed. - CI: Windows build/test, Linux checks and gfx1013 fixtures all pass. Mutations killed (both reported by `tests/rdna2_tools_check.py`, then reverted): - `parse_fma_mix` validation zip swapped back to `(op_sel, op_sel_hi)`: 1 failure. - `lower` operand zip swapped back to `(op_sel, op_sel_hi)`: 1 failure. P1: 0. P2: 0. AI-assisted; commands listed were executed locally.
ChazY11 commented 2026-11-25 01:02:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:20:16Z.


Ran the pure-Python half here, mutated the swap both ways — caught by rdna2_tools_check.py

I cannot run the draw half (no llvm-mc on this machine), so this is the part I could execute:

out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py         exit 0
out/pe-env/Scripts/python.exe -B tests/pso_readiness_check.py       exit 0
out/pe-env/Scripts/python.exe -B tests/docs_links_check.py          exit 0

Two mutations, each reverted:

mutation rdna2_tools_check
the zip back to zip(tokens, op_sel, op_sel_hi) (the old reading) exit 1
the guard unpacked back to for f16, hi in zip(op_sel, op_sel_hi) exit 1

The second one matters more than it looks: if any(hi and not f16 ...) reads the same under either unpacking, so a reviewer skimming the diff sees no
change — the swap is only visible in the tuple order. It is caught, which means one of the fixtures actually distinguishes the two.

The guard's new naming is right — I checked it against LLVM's rule rather than by reading the diff

if any(hi and not f16 for hi, f16 in zip(op_sel, op_sel_hi)):
    raise ValueError("High-half selection requires an f16 operand")

zip yields (op_sel_i, op_sel_hi_i), unpacked as (hi, f16), so hi is the high-half selector and f16 is the conversion flag — the assignment
LLVM uses and the one this PR is adopting. Under the old reading that guard would have refused a different set of forms, which is exactly the kind of
thing that silently changes meaning in a swap commit.

Two things I would ask before this merges

1. The PR carries a second behaviour that the title does not mention. Besides the swap, it adds a refusal and a special case:

if re.fullmatch(r"-\d+", token) and -16 <= int(token) <= -1:
    raise ValueError(f"Ambiguous mixed-precision inline constant {token}")
if token == "-0":
    expr = "asfloat(0x80000000u)"

That is defensible on its own — a negative inline constant is ambiguous with the neg-modifier syntax, and -0 needs its sign kept — but it is a
different change from "read op_sel_hi as the binary16 flag", and it is the part a reviewer of this PR is least likely to be looking at. Either say so
in the description, or split it; both are cheaper than discovering it later.

2. One assertion was replaced rather than moved. In rdna2_tools_check.py this block used to assert the lowered operand strings for the
reproduction form:

self.assertEqual(lowered, ["abs(widen16(asuint(params[0].x) >> 16))", "(-widen16(asuint(alu_19)))", "alu_20"])

and is now

with self.assertRaisesRegex(ValueError, "High-half selection requires an f16 operand"):
    parse_fma_mix(...)

The new expectation is correct under the new reading — that encoding now has op_sel set on a non-f16 source — but the mixed-operand lowering lost its
only direct string assertion. If another fixture covers fma_mix_operand for an f16 source, ignore this; I could not find one in
rdna2_tools_check.py (fma_mix_operand is imported at line 21 and used at the old site only).

What is still not established here, and cannot be by this PR

Which assignment the gfx1013 encoding actually has. This PR makes pixel_aot follow LLVM, which is the stronger position — gfx2hlsl already
reads it that way and refuses op_sel outright — but it is a consistency argument, not hardware evidence. I said the same on #2054: settled only on
RDNA 2 hardware, or by a second LLVM version printing the same fields.

AI-assisted; the three commands and both mutations above were executed locally on Windows 11 build 26300.9974.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148403634 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2100#issuecomment-7148403634). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T00:20:16Z. --- ## Ran the pure-Python half here, mutated the swap both ways — caught by `rdna2_tools_check.py` I cannot run the draw half (no `llvm-mc` on this machine), so this is the part I could execute: ```powershell out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py exit 0 out/pe-env/Scripts/python.exe -B tests/pso_readiness_check.py exit 0 out/pe-env/Scripts/python.exe -B tests/docs_links_check.py exit 0 ``` Two mutations, each reverted: | mutation | rdna2_tools_check | |---|---| | the zip back to `zip(tokens, op_sel, op_sel_hi)` (the old reading) | **exit 1** | | the guard unpacked back to `for f16, hi in zip(op_sel, op_sel_hi)` | **exit 1** | The second one matters more than it looks: `if any(hi and not f16 ...)` reads the same under either unpacking, so a reviewer skimming the diff sees no change — the swap is only visible in the tuple order. It is caught, which means one of the fixtures actually distinguishes the two. ## The guard's new naming is right — I checked it against LLVM's rule rather than by reading the diff ```python if any(hi and not f16 for hi, f16 in zip(op_sel, op_sel_hi)): raise ValueError("High-half selection requires an f16 operand") ``` `zip` yields `(op_sel_i, op_sel_hi_i)`, unpacked as `(hi, f16)`, so `hi` is the high-half selector and `f16` is the conversion flag — the assignment LLVM uses and the one this PR is adopting. Under the old reading that guard would have refused a different set of forms, which is exactly the kind of thing that silently changes meaning in a swap commit. ## Two things I would ask before this merges **1. The PR carries a second behaviour that the title does not mention.** Besides the swap, it adds a refusal and a special case: ```python if re.fullmatch(r"-\d+", token) and -16 <= int(token) <= -1: raise ValueError(f"Ambiguous mixed-precision inline constant {token}") if token == "-0": expr = "asfloat(0x80000000u)" ``` That is defensible on its own — a negative inline constant is ambiguous with the neg-modifier syntax, and `-0` needs its sign kept — but it is a different change from "read `op_sel_hi` as the binary16 flag", and it is the part a reviewer of this PR is least likely to be looking at. Either say so in the description, or split it; both are cheaper than discovering it later. **2. One assertion was replaced rather than moved.** In `rdna2_tools_check.py` this block used to assert the *lowered operand strings* for the reproduction form: ```python self.assertEqual(lowered, ["abs(widen16(asuint(params[0].x) >> 16))", "(-widen16(asuint(alu_19)))", "alu_20"]) ``` and is now ```python with self.assertRaisesRegex(ValueError, "High-half selection requires an f16 operand"): parse_fma_mix(...) ``` The new expectation is correct under the new reading — that encoding now has `op_sel` set on a non-f16 source — but the mixed-operand lowering lost its only direct string assertion. If another fixture covers `fma_mix_operand` for an f16 source, ignore this; I could not find one in `rdna2_tools_check.py` (`fma_mix_operand` is imported at line 21 and used at the old site only). ## What is still not established here, and cannot be by this PR Which assignment the **gfx1013 encoding** actually has. This PR makes `pixel_aot` follow LLVM, which is the stronger position — `gfx2hlsl` already reads it that way and refuses `op_sel` outright — but it is a consistency argument, not hardware evidence. I said the same on #2054: settled only on RDNA 2 hardware, or by a second LLVM version printing the same fields. AI-assisted; the three commands and both mutations above were executed locally on Windows 11 build 26300.9974.
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!2093
No description provided.