shader: lower compute VOP3 binary32 add, sub and mul with neg and abs #1668

Closed
Asimmimx wants to merge 1 commit from upstream-pr/1675 into main
Asimmimx commented 2026-11-24 16:53:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T16:53:08Z.


Refs #1546. This covers the -|v| operand form from that list.

Change

tools/compute_store_aot.py now lowers the VOP3 spelling of the four binary32 operations the compute store profile already handles: v_add_f32_e64, v_sub_f32_e64, v_subrev_f32_e64 and v_mul_f32_e64.

  • Both slots take any known source: a VGPR, a ready SGPR, a 32-bit literal or an inline constant. The _e32 form only takes a VGPR as src1.
  • A VGPR or SGPR source can carry the modifiers LLVM prints as -r, |r| and -|r|. The RDNA ISA references define neg and abs on the sign bit of a floating-point input. They therefore lower to bit operations on the word: (w ^ 0x80000000u), (w & 0x7fffffffu) and (w | 0x80000000u). Unlike HLSL -x and abs(x), these keep NaN payloads and denormals unchanged.
  • The result goes into the existing precise f32_add, f32_sub and f32_mul helpers. Without modifiers, a program lowers to the same HLSL as its _e32 spelling. The controls check this.

These stay refused:

  • a modifier on a constant, the neg() and abs() spellings, and |-r|;
  • clamp, mul:2 and div:2;
  • a third source or a register range;
  • modifiers on _e32 forms;
  • other _e64 binary32 forms (v_max_f32_e64, v_mul_legacy_f32_e64, v_fma_f32).

The NaN, infinity and denormal rules of the existing binary32 section apply unchanged.

One existing control changes. compute_store_check.py expected a plain v_add_f32_e64 v4, v2, v3 to be refused, and that form is now accepted. The control now uses v_add_f32_e64 v4, v2, v3 clamp, which is still refused. The new file checks the accepted form.

Fixture

tests/compute_f32_e64_modifiers_check.py follows the read-compute-write fixture and reuses the operands of the binary32 fixture: x in [1.5, 2), y in [3, 4) and cap = 20.0 in s0. The chain is in LLVM 15 spelling:

v_add_f32_e64 v4, v2, -v3            ; a = x + -y        (always negative)
v_sub_f32_e64 v5, s0, |v4|           ; b = cap - |a|
v_sub_f32_e64 v7, v2, 0x3fe00000     ; t = x - 1.75      (negative in some lanes, positive in others)
v_mul_f32_e64 v8, -|v7|, v5          ; d = -|t| * b
v_subrev_f32_e64 v6, -s0, v8         ; e = d - (-cap)
v_add_f32_e64 v1, v6, |v7|           ; out = e + |t|
  • Every modifier changes the result: -|t| differs from t where t > 0 and from -t where t < 0.
  • The sub and subrev operand orders are observable.
  • The modifiers cover a VGPR and an SGPR, both slots and all three forms.
  • LLVM 19.1.1 llvm-mc -mcpu=gfx1013 assembles the six lines, and llvm-objdump prints them back unchanged.

The expected words come from a Python model that rounds each step to binary32 and shares no code with the lowering. All values are finite and normal, or zero where x is exactly 1.75. At least one multiply is inexact.

Negative controls:

  • 9 wrong references, each of which must fail at its first differing word: each of the five modifiers dropped, -|t| as -t and as |t|, and the sub and subrev operands exchanged.
  • 7 mutated translations, each of which must fail the readback: neg as abs on y, abs dropped on a, -|t| as -t and as |t|, neg dropped on the SGPR, abs as neg on the last t, and subrev as sub.
  • 25 refusals in the controls mode, for the forms and operands listed above.

The new tests are compute_store_aot_f32_e64_modifiers_{warp,hardware}, with a form-coverage record. docs/experiments.md gets a section after the binary32 one, and that section's list of refused forms is updated.

Results

Commit c5684e08 on top of c864f138. Windows 11 26300.9974, DXC 1.8.2502.11 (Windows SDK 10.0.26100), debug layer on.

python -B tests/compute_f32_e64_modifiers_check.py draw <dxc> out/build/dev/offscreen_check.exe warp
python -B tests/compute_f32_e64_modifiers_check.py draw <dxc> out/build/dev/offscreen_check.exe hardware
Adapter Driver Readback Wrong references Mutations
WARP 10.0.26100.9818 3 dispatches, 320 words, mismatches=0 9/9 fail 7/7 fail
AMD Radeon RX 6600 (RDNA 2) 32.0.21045.29003 3 dispatches, 320 words, mismatches=0 9/9 fail 7/7 fail

Both runs reported debug_errors=0 debug_warnings=0. There were no skips.

Also run on this commit, all passing:

  • python -B tests/compute_store_check.py draw-f32 <dxc> <renderer> warp, which includes compute_store_check controls with the changed refusal: mismatches=0.
  • The controls of compute_alu_xor3_check.py, compute_alu_med3_check.py and compute_alu_minmax3_check.py, plus compute_entry_layout_check.py.
  • tests/form_coverage_check.py, tests/docs_links_check.py and tests/bidi_controls_check.py.
  • ctest --preset dev -N -R f32_e64 lists both new tests.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6586970162 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1675). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T16:53:08Z. --- Refs #1546. This covers the `-|v|` operand form from that list. ## Change `tools/compute_store_aot.py` now lowers the VOP3 spelling of the four binary32 operations the compute store profile already handles: `v_add_f32_e64`, `v_sub_f32_e64`, `v_subrev_f32_e64` and `v_mul_f32_e64`. - Both slots take any known source: a VGPR, a ready SGPR, a 32-bit literal or an inline constant. The `_e32` form only takes a VGPR as src1. - A VGPR or SGPR source can carry the modifiers LLVM prints as `-r`, `|r|` and `-|r|`. The RDNA ISA references define neg and abs on the sign bit of a floating-point input. They therefore lower to bit operations on the word: `(w ^ 0x80000000u)`, `(w & 0x7fffffffu)` and `(w | 0x80000000u)`. Unlike HLSL `-x` and `abs(x)`, these keep NaN payloads and denormals unchanged. - The result goes into the existing `precise` `f32_add`, `f32_sub` and `f32_mul` helpers. Without modifiers, a program lowers to the same HLSL as its `_e32` spelling. The controls check this. These stay refused: - a modifier on a constant, the `neg()` and `abs()` spellings, and `|-r|`; - `clamp`, `mul:2` and `div:2`; - a third source or a register range; - modifiers on `_e32` forms; - other `_e64` binary32 forms (`v_max_f32_e64`, `v_mul_legacy_f32_e64`, `v_fma_f32`). The NaN, infinity and denormal rules of the existing binary32 section apply unchanged. One existing control changes. `compute_store_check.py` expected a plain `v_add_f32_e64 v4, v2, v3` to be refused, and that form is now accepted. The control now uses `v_add_f32_e64 v4, v2, v3 clamp`, which is still refused. The new file checks the accepted form. ## Fixture `tests/compute_f32_e64_modifiers_check.py` follows the read-compute-write fixture and reuses the operands of the binary32 fixture: `x` in [1.5, 2), `y` in [3, 4) and `cap = 20.0` in s0. The chain is in LLVM 15 spelling: ``` v_add_f32_e64 v4, v2, -v3 ; a = x + -y (always negative) v_sub_f32_e64 v5, s0, |v4| ; b = cap - |a| v_sub_f32_e64 v7, v2, 0x3fe00000 ; t = x - 1.75 (negative in some lanes, positive in others) v_mul_f32_e64 v8, -|v7|, v5 ; d = -|t| * b v_subrev_f32_e64 v6, -s0, v8 ; e = d - (-cap) v_add_f32_e64 v1, v6, |v7| ; out = e + |t| ``` - Every modifier changes the result: `-|t|` differs from `t` where `t > 0` and from `-t` where `t < 0`. - The `sub` and `subrev` operand orders are observable. - The modifiers cover a VGPR and an SGPR, both slots and all three forms. - LLVM 19.1.1 `llvm-mc -mcpu=gfx1013` assembles the six lines, and `llvm-objdump` prints them back unchanged. The expected words come from a Python model that rounds each step to binary32 and shares no code with the lowering. All values are finite and normal, or zero where `x` is exactly 1.75. At least one multiply is inexact. Negative controls: - **9 wrong references**, each of which must fail at its first differing word: each of the five modifiers dropped, `-|t|` as `-t` and as `|t|`, and the `sub` and `subrev` operands exchanged. - **7 mutated translations**, each of which must fail the readback: neg as abs on `y`, abs dropped on `a`, `-|t|` as `-t` and as `|t|`, neg dropped on the SGPR, abs as neg on the last `t`, and `subrev` as `sub`. - **25 refusals** in the controls mode, for the forms and operands listed above. The new tests are `compute_store_aot_f32_e64_modifiers_{warp,hardware}`, with a form-coverage record. `docs/experiments.md` gets a section after the binary32 one, and that section's list of refused forms is updated. ## Results Commit `c5684e08` on top of `c864f138`. Windows 11 26300.9974, DXC 1.8.2502.11 (Windows SDK 10.0.26100), debug layer on. ``` python -B tests/compute_f32_e64_modifiers_check.py draw <dxc> out/build/dev/offscreen_check.exe warp python -B tests/compute_f32_e64_modifiers_check.py draw <dxc> out/build/dev/offscreen_check.exe hardware ``` | Adapter | Driver | Readback | Wrong references | Mutations | |---|---|---|---|---| | WARP | 10.0.26100.9818 | 3 dispatches, 320 words, mismatches=0 | 9/9 fail | 7/7 fail | | AMD Radeon RX 6600 (RDNA 2) | 32.0.21045.29003 | 3 dispatches, 320 words, mismatches=0 | 9/9 fail | 7/7 fail | Both runs reported `debug_errors=0 debug_warnings=0`. There were no skips. Also run on this commit, all passing: - `python -B tests/compute_store_check.py draw-f32 <dxc> <renderer> warp`, which includes `compute_store_check` controls with the changed refusal: mismatches=0. - The controls of `compute_alu_xor3_check.py`, `compute_alu_med3_check.py` and `compute_alu_minmax3_check.py`, plus `compute_entry_layout_check.py`. - `tests/form_coverage_check.py`, `tests/docs_links_check.py` and `tests/bidi_controls_check.py`. - `ctest --preset dev -N -R f32_e64` lists both new tests. AI-assisted (Claude Code).
tedin7 commented 2026-11-24 18:02:26 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Peer review at head_sha: c5684e08dbbb517c8cdb4367d460a2390161d5b6

Findings

No P1/P2 on this PR taken alone. One nit, then the overlap with #1673, which matters more for what to merge.

  • nit (docs/experiments.md, "Binary32 VOP3 spelling and source modifiers"): the text says LLVM 19 llvm-mc assembles the six fixture lines and llvm-objdump prints them back unchanged. No test enforces that: tests/compute_f32_e64_modifiers_check.py has only controls and draw modes and no assemble/disassemble step. I ran it by hand and the claim is true today (below), but it can regress unnoticed. #1673 has a binary mode for this, wired into windows.yml.

Overlap with #1673 (head a0b6d41baf687bdd4126af2b4feff2803ca76dbe, no defects found there on my earlier review)

Both lower v_{add,sub,subrev,mul}_f32_e64 with neg/abs source modifiers to the same precise f32_* helpers. They cannot both land as they are: git merge-tree reports content conflicts in tools/compute_store_aot.py (both add a function named float_e64_source at the same spot plus a new branch in lower) and in docs/experiments.md (same paragraph and same new section position). CMakeLists.txt merges cleanly.

I compared the two translators directly: 1321 instruction lines (4 ops x 36 first-source spellings x 9 second-source spellings, plus clamp/omod suffixes and the neighbouring forms), same program, each worktree's own aot.lower.

#1675 #1673
-r, |r|, -|r| on a VGPR or SGPR, either slot accepted accepted
neg(...), abs(...), |-r|, --r, unbalanced bar, modifier on a constant (|1.0|, -0x3fc00000) refused refused
clamp, mul:2, mul:4, div:2 refused refused
unmodified _e64 (no modifier at all) accepted, lowers exactly like _e32 refused (deliberate, documented)
refusal text generic Unsupported compute instruction: <line> specific: Unsupported float output modifier / Unsupported float source modifier
-|r| expression (w | 0x80000000u) ((w & 0x7fffffffu) ^ 0x80000000u)
order of operations abs first, then neg abs first, then neg
NaN / signed zero sign-bit integer ops, payload kept same
fixture 6-line chain (a..out), 3 forms x VGPR/SGPR, both slots 8-step chain with an integer XOR so the -0.0 sign bit is observed
LLVM round trip test none (doc claim only) binary mode, added to windows.yml
form-coverage record (FORM_COVERAGE_RECORD) yes no
touches compute_store_check.py yes (the old "_e64 is refused" control becomes "_e64 clamp is refused") no

Result of the 1321-line comparison: all 160 accept/refuse differences are the unmodified _e64 row. Every line that carries a modifier is accepted or refused identically. The only different accepted output is the -|r| spelling; (x & 0x7fffffff) ^ 0x80000000 and x | 0x80000000 set bit 31 and keep the other 31 bits the same for every word, so the results are equal. Nothing was found where one translator accepts a modified form the other gets wrong.

Order of modifiers: LLVM itself only accepts -|v| (abs inside neg); llvm-mc-19 rejects |-v6| with "failed parsing operand", which both PRs also refuse. So neg(abs(x)) is the only legal nesting, and both lower it as abs then neg.

Suggestion for @R0Y00, as a choice and not a verdict: the two are semantically equal, so pick by scope. If only modified sources are wanted, #1673 is older and has the CI round trip. If unmodified _e64 should also be accepted, #1675 already does that and records form coverage. The cleanest path is to land one and have the other rebase down to its delta (for #1675: unmodified _e64, the form-coverage record, and the changed control; for #1673: the specific diagnostics and the round-trip test).

Verified

Linux only, x86-64 (no Windows, no D3D12, no dxc, so the draw ctests were not run):

  • python3 -B tests/compute_f32_e64_modifiers_check.py controls -> exit 0.
  • llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding on the fixture chain and on clamp -> assembles (e.g. v_mul_f32_e64 v8, -|v7|, v5 -> 08 01 08 d5 07 0b 02 20); -filetype=obj then llvm-objdump-19 -d prints the six lines back unchanged. |-v6| is rejected by the assembler.
  • python3 -B tests/docs_links_check.py -> 16 files, 350 links OK. git diff --check clean.
  • Differential run: python3 -B -I script calling each tree's compute_store_check.variant + compute_store_aot.lower over the 1321 lines, results compared as above.
  • Mutation 1: FLOAT_MODIFIERS[(True, True)] changed from | 0x80000000u to ^ 0x80000000u; controls fails with an AssertionError (exit 1). Restored; git status --short clean.
  • Mutation 2: abs mask 0x7fffffffu changed to 0xffffffffu; controls fails with an AssertionError (exit 1). Restored; clean.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043807015 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1675#pullrequestreview-6043807015). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:03:56Z. **Review:** COMMENTED --- Peer review at `head_sha`: `c5684e08dbbb517c8cdb4367d460a2390161d5b6` ### Findings No P1/P2 on this PR taken alone. One nit, then the overlap with #1673, which matters more for what to merge. - **nit** (`docs/experiments.md`, "Binary32 VOP3 spelling and source modifiers"): the text says LLVM 19 `llvm-mc` assembles the six fixture lines and `llvm-objdump` prints them back unchanged. No test enforces that: `tests/compute_f32_e64_modifiers_check.py` has only `controls` and `draw` modes and no assemble/disassemble step. I ran it by hand and the claim is true today (below), but it can regress unnoticed. #1673 has a `binary` mode for this, wired into `windows.yml`. ### Overlap with #1673 (head `a0b6d41baf687bdd4126af2b4feff2803ca76dbe`, no defects found there on my earlier review) Both lower `v_{add,sub,subrev,mul}_f32_e64` with neg/abs source modifiers to the same `precise` `f32_*` helpers. They cannot both land as they are: `git merge-tree` reports content conflicts in `tools/compute_store_aot.py` (both add a function named `float_e64_source` at the same spot plus a new branch in `lower`) and in `docs/experiments.md` (same paragraph and same new section position). `CMakeLists.txt` merges cleanly. I compared the two translators directly: 1321 instruction lines (4 ops x 36 first-source spellings x 9 second-source spellings, plus clamp/omod suffixes and the neighbouring forms), same program, each worktree's own `aot.lower`. | | #1675 | #1673 | |---|---|---| | `-r`, `\|r\|`, `-\|r\|` on a VGPR or SGPR, either slot | accepted | accepted | | `neg(...)`, `abs(...)`, `\|-r\|`, `--r`, unbalanced bar, modifier on a constant (`\|1.0\|`, `-0x3fc00000`) | refused | refused | | `clamp`, `mul:2`, `mul:4`, `div:2` | refused | refused | | unmodified `_e64` (no modifier at all) | **accepted**, lowers exactly like `_e32` | **refused** (deliberate, documented) | | refusal text | generic `Unsupported compute instruction: <line>` | specific: `Unsupported float output modifier` / `Unsupported float source modifier` | | `-\|r\|` expression | `(w \| 0x80000000u)` | `((w & 0x7fffffffu) ^ 0x80000000u)` | | order of operations | abs first, then neg | abs first, then neg | | NaN / signed zero | sign-bit integer ops, payload kept | same | | fixture | 6-line chain (a..out), 3 forms x VGPR/SGPR, both slots | 8-step chain with an integer XOR so the -0.0 sign bit is observed | | LLVM round trip test | none (doc claim only) | `binary` mode, added to `windows.yml` | | form-coverage record (`FORM_COVERAGE_RECORD`) | yes | no | | touches `compute_store_check.py` | yes (the old "`_e64` is refused" control becomes "`_e64 clamp` is refused") | no | Result of the 1321-line comparison: all 160 accept/refuse differences are the unmodified `_e64` row. Every line that carries a modifier is accepted or refused identically. The only different accepted output is the `-|r|` spelling; `(x & 0x7fffffff) ^ 0x80000000` and `x | 0x80000000` set bit 31 and keep the other 31 bits the same for every word, so the results are equal. Nothing was found where one translator accepts a modified form the other gets wrong. Order of modifiers: LLVM itself only accepts `-|v|` (abs inside neg); `llvm-mc-19` rejects `|-v6|` with "failed parsing operand", which both PRs also refuse. So `neg(abs(x))` is the only legal nesting, and both lower it as abs then neg. Suggestion for @R0Y00, as a choice and not a verdict: the two are semantically equal, so pick by scope. If only modified sources are wanted, #1673 is older and has the CI round trip. If unmodified `_e64` should also be accepted, #1675 already does that and records form coverage. The cleanest path is to land one and have the other rebase down to its delta (for #1675: unmodified `_e64`, the form-coverage record, and the changed control; for #1673: the specific diagnostics and the round-trip test). ### Verified Linux only, x86-64 (no Windows, no D3D12, no `dxc`, so the `draw` ctests were not run): - `python3 -B tests/compute_f32_e64_modifiers_check.py controls` -> exit 0. - `llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding` on the fixture chain and on `clamp` -> assembles (e.g. `v_mul_f32_e64 v8, -|v7|, v5` -> `08 01 08 d5 07 0b 02 20`); `-filetype=obj` then `llvm-objdump-19 -d` prints the six lines back unchanged. `|-v6|` is rejected by the assembler. - `python3 -B tests/docs_links_check.py` -> 16 files, 350 links OK. `git diff --check` clean. - Differential run: `python3 -B -I` script calling each tree's `compute_store_check.variant` + `compute_store_aot.lower` over the 1321 lines, results compared as above. - **Mutation 1:** `FLOAT_MODIFIERS[(True, True)]` changed from `| 0x80000000u` to `^ 0x80000000u`; `controls` fails with an `AssertionError` (exit 1). Restored; `git status --short` clean. - **Mutation 2:** abs mask `0x7fffffffu` changed to `0xffffffffu`; `controls` fails with an `AssertionError` (exit 1). Restored; clean. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 13:01:00 +00:00 (Migrated from github.com)

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


@Asimmimx could you rebase this branch onto current main and force-push?

GitHub reports head c5684e08 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (b1a644ae):

  • CMakeLists.txt
  • docs/experiments.md
  • tools/compute_store_aot.py

Commands run locally:

git fetch origin main pull/1675/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1675 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7162787311 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1675#issuecomment-7162787311). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:44:21Z. --- @Asimmimx could you rebase this branch onto current `main` and force-push? GitHub reports head `c5684e08` as conflicting with `main`, so it cannot be merged as is. Files that conflict with current `main` (`b1a644ae`): - `CMakeLists.txt` - `docs/experiments.md` - `tools/compute_store_aot.py` Commands run locally: ``` git fetch origin main pull/1675/head git merge-tree --write-tree --name-only origin/main FETCH_HEAD gh pr view 1675 --json mergeable # CONFLICTING ``` Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 03:02:46 +00:00
tedin7 commented 2026-11-26 03:03:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:21:39Z.


Closing this as a duplicate of #1673, which is now merged. Both PRs add the same slice (negated and absolute f32 source operands on compute VOP3 add/sub/mul through float_e64_source plus a new lowering branch), so only one of them can land, and the older one went in first.

Thank you for the work here. If this PR covers a form that #1673 does not (for example the unmodified _e64 case, which the two PRs treat differently), please reopen it or open a small follow-up on top of current main with just that case and its WARP readback, and we will review it right away.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7180730029 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1675#issuecomment-7180730029). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:21:39Z. --- Closing this as a duplicate of #1673, which is now merged. Both PRs add the same slice (negated and absolute f32 source operands on compute VOP3 add/sub/mul through `float_e64_source` plus a new lowering branch), so only one of them can land, and the older one went in first. Thank you for the work here. If this PR covers a form that #1673 does not (for example the unmodified `_e64` case, which the two PRs treat differently), please reopen it or open a small follow-up on top of current `main` with just that case and its WARP readback, and we will review it right away. AI-assisted; commands listed were executed locally.

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!1668
No description provided.