shader: lower negated and absolute f32 source operands in compute #1666

Merged
RenzoWit35 merged 2 commits from upstream-pr/1673 into main 2026-11-26 02:19:33 +00:00
RenzoWit35 commented 2026-11-24 16:49:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T16:49:32Z.


Change

Issue #1546 lists "the -|v| operand form" among the single-instruction gaps of the measured compute programs, without naming an instruction; the per-family PRs for that issue do not cover it. The only binary32 ALU forms tools/compute_store_aot.py lowers are v_add_f32, v_sub_f32, v_subrev_f32 and v_mul_f32 (_e32 only), so this PR adds their VOP3 _e64 spelling with source modifiers. No opcode is added.

  • An _e64 form is accepted when at least one source carries -v, |v| or -|v| on a VGPR or SGPR, as LLVM 15 prints them. The other source may be any binary32 source the _e32 forms accept (VGPR, known SGPR, literal, integer zero, inline float constant).
  • The modifiers are sign-bit operations on the word, abs first and then neg, the same as pixel_aot.py does for v_cvt_f64_f32_e64 and the binary64 compare sources: |v| becomes (w & 0x7fffffffu), -v becomes (w ^ 0x80000000u), and -|v| becomes ((w & 0x7fffffffu) ^ 0x80000000u). A signed zero or NaN payload keeps its other bits, and the output contains no float abs() or unary minus.
  • These stay refused:
    • the unmodified _e64 spelling (the existing control in compute_store_check.py is unchanged);
    • modifiers on _e32;
    • clamp, mul:2, mul:4 and div:2, refused with Unsupported float output modifier;
    • the abs() and neg() spellings, unbalanced or nested bars, and modifiers on constants (|1.0|, neg(0x3f800000), -0x3f800000), refused with Unsupported float source modifier;
    • unknown, NaN, infinite or denormal sources, refused with Unverified float operand.
  • The code change is local. It adds one helper, float_e64_source(), after float_word(), and one new elif branch placed before the existing _e32 float branch in lower(). It reuses the FALU templates and does not change the shared opcode alternations.
  • New check tests/compute_alu_negabs_check.py (modes controls, draw, binary), registered as compute_store_aot_f32_negabs_{warp,hardware}. The binary mode is added to the Ubuntu LLVM 15 list in .github/workflows/windows.yml. docs/experiments.md gets a new subsection, and one sentence of the binary32 section is corrected.

Verification

Environment: Windows 11 Enterprise 10.0.26300, MSVC 19.51 (14.51), DXC 1.8.2502.11, WARP 10.0.26100.9818. The D3D12 debug layer was unavailable. Parent commit c864f138.

Before the change, origin/main refuses the form: v_add_f32_e64 v4, -|v2|, v3 gives Unsupported compute instruction: v_add_f32_e64 v4, -|v2|, v3. The same happens for -v2 and |v2|.

The fixture is the read-compute-write kernel with cap = params[0].y = -0.75:

d = x - 1.75
z = 0 * d
a = |d| + y
b = -d * a
c = b - (-|d|)
e = (-c) - (-|cap|)
f = |z| * y
out = e ^ f

d takes both signs, and z is +0.0 or -0.0 depending on the lane. Each modifier appears on two operations, including one SGPR source.

. .\tools\dev.ps1
cmake --preset dev -DINTAKE_PYTHON=<pe-env python>
cmake --build --preset dev --target offscreen_check --parallel 4
ctest --preset dev --no-tests=error -R '^compute_store_aot_f32_negabs_warp$' -V
  • WARP passes. All three dispatches (groups=1, groups=1, groups=5) report compared_words=320 mismatches=0, followed by read_f32_negabs: 3 dispatches, 12 wrong references and 12 mutated sources checked.
  • Wrong references (12, all detected at their first differing word): for each modified source, the negation dropped, the abs dropped, or abs and negation exchanged.
  • HLSL mutations (12, all Compute readback differs): each of the four abs masks dropped, and each of the four sign flips dropped or replaced by an abs.
  • Translation controls (python -B tests/compute_alu_negabs_check.py controls) pass. They pin the exact store and evaluate the three modifier expressions against the bit model on +0, -0, quiet and signalling NaN payloads, -inf, a negative value and a denormal word. They also check 37 refusals.
  • Each of six mutations of the translator makes the controls fail: abs dropped, neg dropped, neg emitted as float negation, an output modifier accepted, the bar check removed, and a modified constant accepted.
  • Regression in dev: ctest --preset dev --no-tests=error -R '^compute_(store_aot|mesh|to_pixel).*_warp$' passes 49 of 49. tests/docs_links_check.py also passes. compute_store_check.py has no controls mode; its translation controls run inside the compute_store_aot_* tests above.
  • Release: cmake --preset release, then cmake --build --preset release --target offscreen_check --parallel 4, then ctest --preset release --no-tests=error -R '^compute_store_aot_(f32|f32_negabs|alu_xor3|alu_minmax3|guard_read)_warp$'. This passes 5 of 5.

Not run locally:

  • LLVM 15 round trip. python -B tests/compute_alu_negabs_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 needs llvm-mc and libLLVM, and neither is installed on this PC. It runs in the Ubuntu job. Until then, the claim that LLVM 15 prints |v4|, -v4 and -|v4| exactly this way rests on the AMDGPU printer conventions that pixel_aot.py already relies on.
  • NaN on the GPU. NaN inputs are not dispatched, because the binary32 operation itself does not model NaN. This is an existing limit of the subset. The modifier is an integer operation by construction and is checked at the text level.
  • Hardware. No hardware result is reported.

Evidence and follow-up

Refs #1546

The open PRs that also edit tools/compute_store_aot.py are #1580, #1591, #1592 and #1596 for #1546, plus #1566 and #1655. The #1546 ones change the ALU table, the integer opcode alternations in lower(), add a VOP1 branch after the integer branch (#1591), and add a v_cvt_pk_u8_f32 branch and table after FLOAT_INLINE (#1592). #1579, #1582 and #1588 change the scalar ALU part. This PR touches none of those lines: its helper sits after float_word() and its branch before the _e32 float branch. git merge-tree against the current main reports no conflict. In CMakeLists.txt the new test follows the alu_xor3 entry, and in docs/experiments.md the new subsection follows "Three-input XOR". Those are the only places a rebase could need a trivial resolution against the open PRs.

Possible follow-ups, not in this PR:

  • modifiers on constants (neg(0x...));
  • the unmodified _e64 spelling;
  • clamp and omod;
  • modifiers on other compute float opcodes once those are lowered.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6586903260 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1673). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T16:49:32Z. --- ## Change Issue #1546 lists "the `-|v|` operand form" among the single-instruction gaps of the measured compute programs, without naming an instruction; the per-family PRs for that issue do not cover it. The only binary32 ALU forms `tools/compute_store_aot.py` lowers are `v_add_f32`, `v_sub_f32`, `v_subrev_f32` and `v_mul_f32` (`_e32` only), so this PR adds their VOP3 `_e64` spelling with source modifiers. No opcode is added. - An `_e64` form is accepted when at least one source carries `-v`, `|v|` or `-|v|` on a VGPR or SGPR, as LLVM 15 prints them. The other source may be any binary32 source the `_e32` forms accept (VGPR, known SGPR, literal, integer zero, inline float constant). - The modifiers are sign-bit operations on the word, abs first and then neg, the same as `pixel_aot.py` does for `v_cvt_f64_f32_e64` and the binary64 compare sources: `|v|` becomes `(w & 0x7fffffffu)`, `-v` becomes `(w ^ 0x80000000u)`, and `-|v|` becomes `((w & 0x7fffffffu) ^ 0x80000000u)`. A signed zero or NaN payload keeps its other bits, and the output contains no float `abs()` or unary minus. - These stay refused: - the unmodified `_e64` spelling (the existing control in `compute_store_check.py` is unchanged); - modifiers on `_e32`; - `clamp`, `mul:2`, `mul:4` and `div:2`, refused with `Unsupported float output modifier`; - the `abs()` and `neg()` spellings, unbalanced or nested bars, and modifiers on constants (`|1.0|`, `neg(0x3f800000)`, `-0x3f800000`), refused with `Unsupported float source modifier`; - unknown, NaN, infinite or denormal sources, refused with `Unverified float operand`. - The code change is local. It adds one helper, `float_e64_source()`, after `float_word()`, and one new `elif` branch placed before the existing `_e32` float branch in `lower()`. It reuses the `FALU` templates and does not change the shared opcode alternations. - New check `tests/compute_alu_negabs_check.py` (modes `controls`, `draw`, `binary`), registered as `compute_store_aot_f32_negabs_{warp,hardware}`. The `binary` mode is added to the Ubuntu LLVM 15 list in `.github/workflows/windows.yml`. `docs/experiments.md` gets a new subsection, and one sentence of the binary32 section is corrected. ## Verification Environment: Windows 11 Enterprise 10.0.26300, MSVC 19.51 (14.51), DXC 1.8.2502.11, WARP 10.0.26100.9818. The D3D12 debug layer was unavailable. Parent commit c864f138. Before the change, origin/main refuses the form: `v_add_f32_e64 v4, -|v2|, v3` gives `Unsupported compute instruction: v_add_f32_e64 v4, -|v2|, v3`. The same happens for `-v2` and `|v2|`. The fixture is the read-compute-write kernel with `cap = params[0].y = -0.75`: ``` d = x - 1.75 z = 0 * d a = |d| + y b = -d * a c = b - (-|d|) e = (-c) - (-|cap|) f = |z| * y out = e ^ f ``` `d` takes both signs, and `z` is +0.0 or -0.0 depending on the lane. Each modifier appears on two operations, including one SGPR source. ```powershell . .\tools\dev.ps1 cmake --preset dev -DINTAKE_PYTHON=<pe-env python> cmake --build --preset dev --target offscreen_check --parallel 4 ctest --preset dev --no-tests=error -R '^compute_store_aot_f32_negabs_warp$' -V ``` - WARP passes. All three dispatches (`groups=1`, `groups=1`, `groups=5`) report `compared_words=320 mismatches=0`, followed by `read_f32_negabs: 3 dispatches, 12 wrong references and 12 mutated sources checked`. - Wrong references (12, all detected at their first differing word): for each modified source, the negation dropped, the abs dropped, or abs and negation exchanged. - HLSL mutations (12, all `Compute readback differs`): each of the four abs masks dropped, and each of the four sign flips dropped or replaced by an abs. - Translation controls (`python -B tests/compute_alu_negabs_check.py controls`) pass. They pin the exact store and evaluate the three modifier expressions against the bit model on +0, -0, quiet and signalling NaN payloads, -inf, a negative value and a denormal word. They also check 37 refusals. - Each of six mutations of the translator makes the controls fail: abs dropped, neg dropped, neg emitted as float negation, an output modifier accepted, the bar check removed, and a modified constant accepted. - Regression in dev: `ctest --preset dev --no-tests=error -R '^compute_(store_aot|mesh|to_pixel).*_warp$'` passes 49 of 49. `tests/docs_links_check.py` also passes. `compute_store_check.py` has no `controls` mode; its translation controls run inside the `compute_store_aot_*` tests above. - Release: `cmake --preset release`, then `cmake --build --preset release --target offscreen_check --parallel 4`, then `ctest --preset release --no-tests=error -R '^compute_store_aot_(f32|f32_negabs|alu_xor3|alu_minmax3|guard_read)_warp$'`. This passes 5 of 5. Not run locally: - **LLVM 15 round trip.** `python -B tests/compute_alu_negabs_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1` needs llvm-mc and libLLVM, and neither is installed on this PC. It runs in the Ubuntu job. Until then, the claim that LLVM 15 prints `|v4|`, `-v4` and `-|v4|` exactly this way rests on the AMDGPU printer conventions that `pixel_aot.py` already relies on. - **NaN on the GPU.** NaN inputs are not dispatched, because the binary32 operation itself does not model NaN. This is an existing limit of the subset. The modifier is an integer operation by construction and is checked at the text level. - **Hardware.** No hardware result is reported. ## Evidence and follow-up Refs #1546 The open PRs that also edit `tools/compute_store_aot.py` are #1580, #1591, #1592 and #1596 for #1546, plus #1566 and #1655. The #1546 ones change the `ALU` table, the integer opcode alternations in `lower()`, add a VOP1 branch after the integer branch (#1591), and add a `v_cvt_pk_u8_f32` branch and table after `FLOAT_INLINE` (#1592). #1579, #1582 and #1588 change the scalar ALU part. This PR touches none of those lines: its helper sits after `float_word()` and its branch before the `_e32` float branch. `git merge-tree` against the current main reports no conflict. In `CMakeLists.txt` the new test follows the `alu_xor3` entry, and in `docs/experiments.md` the new subsection follows "Three-input XOR". Those are the only places a rebase could need a trivial resolution against the open PRs. Possible follow-ups, not in this PR: - modifiers on constants (`neg(0x...)`); - the unmodified `_e64` spelling; - `clamp` and omod; - modifiers on other compute float opcodes once those are lowered. AI-assisted.
tedin7 commented 2026-11-24 17:02:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:54:49Z.

Review: COMMENTED


Peer review of #1673 (a0b6d41baf687bdd4126af2b4feff2803ca76dbe): no defects found (0 P1, 0 P2).

Summary

  • tools/compute_store_aot.py (float_e64_source, lower): lowers v_{add,sub,subrev,mul}_f32_e64 when at least one source has -, |...|, or -|...| in LLVM 15 register spelling, applying bit-31 integer masks (& 0x7fffffffu then ^ 0x80000000u) while rejecting output modifiers (clamp, mul:2, mul:4, div:2), unbalanced bars, abs()/neg() spellings, modified constants, and unmodified _e64 forms.
  • tests/compute_alu_negabs_check.py, CMakeLists.txt, .github/workflows/windows.yml, docs/experiments.md: adds controls, LLVM round-trip (binary mode wired into windows.yml with *COMMON_LLVM), WARP/hardware CTest (compute_store_aot_f32_negabs_${adapter}), and 12 wrong-reference + 12 HLSL mutation checks. Title-neutral and git diff --check clean.

Verification

  • Linux:
    • python3 -B tests/compute_alu_negabs_check.py controls -> PASS
    • python3 -B tests/compute_alu_negabs_check.py binary /usr/bin/llvm-mc-19 /usr/bin/llvm-objcopy-19 /usr/lib/x86_64-linux-gnu/libLLVM-19.so -> PASS (read_f32_negabs: LLVM round trip prints the 5 modified forms and translates identically)
    • python3 -B tests/docs_links_check.py -> PASS (Checked 16 Markdown files and 351 links.)
    • git diff --check origin/main...HEAD -> PASS
  • Windows Server 2025 (x2w_pipe.py win2025 1673):
    • Debug (--preset dev): cmake --build --preset dev --target offscreen_check + ctest --preset dev -> 45/45 passed (compute_store_aot_f32_negabs_warp 4.90s; *_hardware excluded on VM).
    • Release /O2 (--preset release): cmake --build --preset release --target offscreen_check + ctest --preset release -> 45/45 passed (compute_store_aot_f32_negabs_warp 4.84s).
  • Local mutation check:
    • Mutated 0x7fffffffu -> 0xffffffffu in tools/compute_store_aot.py (float_e64_source); python3 -B tests/compute_alu_negabs_check.py controls failed as expected (AssertionError in controls(), exit code 1). Restored via git checkout -- ..

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043666021 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1673#pullrequestreview-6043666021). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T16:54:49Z. **Review:** COMMENTED --- Peer review of #1673 (`a0b6d41baf687bdd4126af2b4feff2803ca76dbe`): **no defects found** (0 P1, 0 P2). ### Summary - `tools/compute_store_aot.py` (`float_e64_source`, `lower`): lowers `v_{add,sub,subrev,mul}_f32_e64` when at least one source has `-`, `|...|`, or `-|...|` in LLVM 15 register spelling, applying bit-31 integer masks (`& 0x7fffffffu` then `^ 0x80000000u`) while rejecting output modifiers (`clamp`, `mul:2`, `mul:4`, `div:2`), unbalanced bars, `abs()`/`neg()` spellings, modified constants, and unmodified `_e64` forms. - `tests/compute_alu_negabs_check.py`, `CMakeLists.txt`, `.github/workflows/windows.yml`, `docs/experiments.md`: adds controls, LLVM round-trip (`binary` mode wired into `windows.yml` with `*COMMON_LLVM`), WARP/hardware CTest (`compute_store_aot_f32_negabs_${adapter}`), and 12 wrong-reference + 12 HLSL mutation checks. Title-neutral and `git diff --check` clean. ### Verification - **Linux**: - `python3 -B tests/compute_alu_negabs_check.py controls` -> PASS - `python3 -B tests/compute_alu_negabs_check.py binary /usr/bin/llvm-mc-19 /usr/bin/llvm-objcopy-19 /usr/lib/x86_64-linux-gnu/libLLVM-19.so` -> PASS (`read_f32_negabs: LLVM round trip prints the 5 modified forms and translates identically`) - `python3 -B tests/docs_links_check.py` -> PASS (`Checked 16 Markdown files and 351 links.`) - `git diff --check origin/main...HEAD` -> PASS - **Windows Server 2025** (`x2w_pipe.py win2025 1673`): - **Debug (`--preset dev`)**: `cmake --build --preset dev --target offscreen_check` + `ctest --preset dev` -> **45/45 passed** (`compute_store_aot_f32_negabs_warp` `4.90s`; `*_hardware` excluded on VM). - **Release `/O2` (`--preset release`)**: `cmake --build --preset release --target offscreen_check` + `ctest --preset release` -> **45/45 passed** (`compute_store_aot_f32_negabs_warp` `4.84s`). - **Local mutation check**: - Mutated `0x7fffffffu` -> `0xffffffffu` in `tools/compute_store_aot.py` (`float_e64_source`); `python3 -B tests/compute_alu_negabs_check.py controls` failed as expected (`AssertionError` in `controls()`, exit code 1). Restored via `git checkout -- .`. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 13:01:03 +00:00 (Migrated from github.com)

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


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

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

Files that conflict with current main (cf97bee1):

  • .github/workflows/windows.yml
  • CMakeLists.txt
  • docs/experiments.md

Commands run locally:

git fetch origin main pull/1673/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1673 --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:7163007041 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1673#issuecomment-7163007041). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:53:49Z. --- @RenzoWit35 could you rebase this branch onto current `main` and force-push? GitHub reports head `a0b6d41b` as conflicting with `main`, so it cannot be merged as is. Files that conflict with current `main` (`cf97bee1`): - `.github/workflows/windows.yml` - `CMakeLists.txt` - `docs/experiments.md` Commands run locally: ``` git fetch origin main pull/1673/head git merge-tree --write-tree --name-only origin/main FETCH_HEAD gh pr view 1673 --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:45 +00:00
tedin7 commented 2026-11-26 03:03:21 +00:00 (Migrated from github.com)

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


Merged origin/main into this branch (e85592ebd, fast-forward from a0b6d41ba) so the PR no longer conflicts. No author code was changed.

Conflicts, all mechanical, both sides kept: the Linux check list in .github/workflows/windows.yml, the xor3/bcnt test block in CMakeLists.txt (the compute_store_aot_f32_negabs_* tests now sit after main's xor3 entry), and docs/experiments.md (this PR's negabs section followed by the sections that landed on main). tools/compute_store_aot.py merged without conflicts.

Verification:

  • python3 -B tests/compute_alu_negabs_check.py controls: PASS (Linux)
  • x2w_pipe.py win2025 1673 --patch <merge diff> --targets offscreen_check --regex compute_store_aot_f32_negabs: dev 2/2 and release 2/2 passed (compute_store_aot_f32_negabs_warp and _hardware).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7180631565 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1673#issuecomment-7180631565). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:16:14Z. --- Merged `origin/main` into this branch (`e85592ebd`, fast-forward from `a0b6d41ba`) so the PR no longer conflicts. No author code was changed. Conflicts, all mechanical, both sides kept: the Linux check list in `.github/workflows/windows.yml`, the xor3/bcnt test block in `CMakeLists.txt` (the `compute_store_aot_f32_negabs_*` tests now sit after main's xor3 entry), and `docs/experiments.md` (this PR's negabs section followed by the sections that landed on main). `tools/compute_store_aot.py` merged without conflicts. Verification: - `python3 -B tests/compute_alu_negabs_check.py controls`: PASS (Linux) - `x2w_pipe.py win2025 1673 --patch <merge diff> --targets offscreen_check --regex compute_store_aot_f32_negabs`: dev 2/2 and release 2/2 passed (`compute_store_aot_f32_negabs_warp` and `_hardware`). AI-assisted; commands listed were executed locally.
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!1666
No description provided.