startup: draw the gfx2hlsl reciprocal, root, exp2 and log2 operations #1738

Merged
Asimmimx merged 2 commits from upstream-pr/1745 into main 2026-11-26 02:17:51 +00:00
Asimmimx commented 2026-11-24 18:03:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T18:03:18Z.


Refs #1149.

Change

The VEC_F table of tools/startup/gfx2hlsl.py lowers six operations to HLSL, and no check ran any of them:

Operation Lowering
v_rcp_f32, v_rcp_iflag_f32 1.0 / x
v_sqrt_f32 sqrt(x)
v_rsq_f32 rsqrt(x)
v_exp_f32 exp2(x)
v_log_f32 log2(x)

This PR adds a check only. The translator does not change.

tests/startup_gfx2hlsl_float_transcendental_check.py draws them with the per-lane runner tests/startup_gfx2hlsl_lane_alu.py. The runner is byte-identical to the copies in #1703, #1706, #1708, #1712 and #1741. Each draw runs one operation per lane on flat inputs, alternating _e32 and _e64, and compares the four result words exactly.

Exact inputs only. Every input is a power of two, or 0 and 9 for the square root, so every result is exact:

  • reciprocals: 4, -0.5, 2^20, 2^-10;
  • roots: 16, 0.25, 4096, 2^-20;
  • exponents: -10..20;
  • logarithms: 2^-20..2^30.

The draw therefore checks which function and which base each operation is lowered to. v_exp_f32 and v_log_f32 are base 2 in the AMD RDNA 2 ISA reference. The draw does not check the precision of an adapter's approximation.

Mutations, one per operation. The first draw with the mutated lowering must read the mutation's own reference words:

  • 2.0 / x for the reciprocals;
  • sqrt and rsqrt exchanged;
  • exp2(x) * 2;
  • log2(x) + 1.

v_sin_f32 and v_cos_f32 are not covered. Their results at the few exact points depend on the approximation.

Results

Commit 627d66e8 on origin/main. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on.

Adapter Driver Draws (FXC ps_5_1 + DXC ps_6_0) Mutated draws
WARP 10.0.26100.9818 24/24 match 12/12 read the mutated words
AMD Radeon RX 6600 (RDNA 2) 32.0.21045.29003 24/24 match 12/12 read the mutated words

There were no skips. binary with llvm-mc 19.1.1 gives fixture words match llvm-mc. docs_links_check.py passes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588222887 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1745). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T18:03:18Z. --- Refs #1149. ## Change The `VEC_F` table of `tools/startup/gfx2hlsl.py` lowers six operations to HLSL, and no check ran any of them: | Operation | Lowering | |---|---| | `v_rcp_f32`, `v_rcp_iflag_f32` | `1.0 / x` | | `v_sqrt_f32` | `sqrt(x)` | | `v_rsq_f32` | `rsqrt(x)` | | `v_exp_f32` | `exp2(x)` | | `v_log_f32` | `log2(x)` | This PR adds a check only. The translator does not change. `tests/startup_gfx2hlsl_float_transcendental_check.py` draws them with the per-lane runner `tests/startup_gfx2hlsl_lane_alu.py`. The runner is byte-identical to the copies in #1703, #1706, #1708, #1712 and #1741. Each draw runs one operation per lane on flat inputs, alternating `_e32` and `_e64`, and compares the four result words exactly. **Exact inputs only.** Every input is a power of two, or 0 and 9 for the square root, so every result is exact: - reciprocals: 4, -0.5, 2^20, 2^-10; - roots: 16, 0.25, 4096, 2^-20; - exponents: -10..20; - logarithms: 2^-20..2^30. The draw therefore checks which function and which base each operation is lowered to. `v_exp_f32` and `v_log_f32` are base 2 in the AMD RDNA 2 ISA reference. The draw does not check the precision of an adapter's approximation. **Mutations**, one per operation. The first draw with the mutated lowering must read the mutation's own reference words: - `2.0 / x` for the reciprocals; - sqrt and rsqrt exchanged; - `exp2(x) * 2`; - `log2(x) + 1`. `v_sin_f32` and `v_cos_f32` are not covered. Their results at the few exact points depend on the approximation. ## Results Commit `627d66e8` on `origin/main`. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on. | Adapter | Driver | Draws (FXC ps_5_1 + DXC ps_6_0) | Mutated draws | |---|---|---|---| | WARP | 10.0.26100.9818 | 24/24 match | 12/12 read the mutated words | | AMD Radeon RX 6600 (RDNA 2) | 32.0.21045.29003 | 24/24 match | 12/12 read the mutated words | There were no skips. `binary` with llvm-mc 19.1.1 gives `fixture words match llvm-mc`. `docs_links_check.py` passes. AI-assisted (Claude Code).
tedin7 commented 2026-11-24 19:01:15 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 627d66e8d5c45b176e88ee53bb6037021b0d9fbe. Tests, CMake, CI list and docs only; tools/startup/gfx2hlsl.py is unchanged. Verdict: 0 P1, 0 P2, with coverage nits.

Linux limits. Linux x86_64, llvm-mc-19 (the new CI entry pins llvm-mc-15), Python 3.14. No Windows, no DXC/FXC, no WARP or GPU: I could NOT run the draw mode, so the claimed 24 matching and 12 mutated draws on WARP and RX 6600 are not verified by me.

What I ran

  • python3 -B tests/startup_gfx2hlsl_float_transcendental_check.py (controls): passes. ... binary llvm-mc-19: fixture words match llvm-mc.
  • git diff --check origin/main...HEAD, docs_links_check.py, bidi_controls_check.py: clean; no non-ASCII bytes in the diff.
  • Semantics: the lowerings are 1.0 / x (rcp and rcp_iflag), rsqrt, sqrt, exp2, log2; v_exp_f32 and v_log_f32 are base 2 in the ISA, and every draw input is a power of two (or 0 and 9 for sqrt), so every reference is exact and the test checks which function is used, not the approximation error (the docs say so). Reference values recomputed by hand for a few lanes (rcp 4 = 0.25, rsq 16 = 0.25, exp2(10) = 1024, log2(2^-20) = -20): consistent.
  • Mutations (restored with git checkout -- .):
    • v_rcp_iflag_f32 1.0 / {0} -> 2.0 / {0}: controls FAILED (('v_rcp_iflag_f32', 0), the mutation regex no longer matches).
    • v_exp_f32 exp2 -> exp: controls FAILED (('v_exp_f32', 0), same mechanism).
    • v_rsq_f32 rsqrt({0}) -> 1.0 / sqrt({0}): controls FAILED (same mechanism; the value is the same, the shape is not).
    • test body word of v_rsq_f32 0x5d -> 0x5c: FAILED in binary (assembled words differ).
    • v_sqrt_f32 sqrt({0}) -> sqrt(abs({0})): controls and binary PASSED. This one also survives the draws: every v_sqrt_f32 draw input is 0 or positive, so the negative-domain behavior is not observed anywhere.

Coverage nits (not blocking)

  • Specials are untested for all six operations: rcp(+/-0), rsq(0), sqrt(-x) and sqrt(-0), log2(0), log2(-x), exp2 overflow and underflow, NaN and infinity, and denormal inputs. These are where RDNA 2 and HLSL may differ (flush, sign of zero, NaN payload), so the "which function is lowered" check does not protect them.
  • v_rcp_f32 and v_rcp_iflag_f32 share one lowering and one input set; the flag behavior of _iflag is not (and cannot be) observed.
  • As on the sibling PR #1741, a wrong value that keeps the shape of the translated text is only caught by the Windows draws.

Not approving (comment only).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044762711 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1745#pullrequestreview-6044762711). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:08:35Z. **Review:** COMMENTED --- Review of head `627d66e8d5c45b176e88ee53bb6037021b0d9fbe`. Tests, CMake, CI list and docs only; `tools/startup/gfx2hlsl.py` is unchanged. **Verdict: 0 P1, 0 P2**, with coverage nits. **Linux limits.** Linux x86_64, `llvm-mc-19` (the new CI entry pins `llvm-mc-15`), Python 3.14. No Windows, no DXC/FXC, no WARP or GPU: I could NOT run the `draw` mode, so the claimed 24 matching and 12 mutated draws on WARP and RX 6600 are not verified by me. **What I ran** - `python3 -B tests/startup_gfx2hlsl_float_transcendental_check.py` (controls): passes. `... binary llvm-mc-19`: `fixture words match llvm-mc`. - `git diff --check origin/main...HEAD`, `docs_links_check.py`, `bidi_controls_check.py`: clean; no non-ASCII bytes in the diff. - Semantics: the lowerings are `1.0 / x` (rcp and rcp_iflag), `rsqrt`, `sqrt`, `exp2`, `log2`; `v_exp_f32` and `v_log_f32` are base 2 in the ISA, and every draw input is a power of two (or 0 and 9 for sqrt), so every reference is exact and the test checks which function is used, not the approximation error (the docs say so). Reference values recomputed by hand for a few lanes (rcp 4 = 0.25, rsq 16 = 0.25, exp2(10) = 1024, log2(2^-20) = -20): consistent. - Mutations (restored with `git checkout -- .`): - `v_rcp_iflag_f32` `1.0 / {0}` -> `2.0 / {0}`: controls FAILED (`('v_rcp_iflag_f32', 0)`, the mutation regex no longer matches). - `v_exp_f32` `exp2` -> `exp`: controls FAILED (`('v_exp_f32', 0)`, same mechanism). - `v_rsq_f32` `rsqrt({0})` -> `1.0 / sqrt({0})`: controls FAILED (same mechanism; the value is the same, the shape is not). - test body word of `v_rsq_f32` 0x5d -> 0x5c: FAILED in `binary` (assembled words differ). - `v_sqrt_f32` `sqrt({0})` -> `sqrt(abs({0}))`: controls and `binary` PASSED. This one also survives the draws: every `v_sqrt_f32` draw input is 0 or positive, so the negative-domain behavior is not observed anywhere. **Coverage nits (not blocking)** - Specials are untested for all six operations: `rcp(+/-0)`, `rsq(0)`, `sqrt(-x)` and `sqrt(-0)`, `log2(0)`, `log2(-x)`, `exp2` overflow and underflow, NaN and infinity, and denormal inputs. These are where RDNA 2 and HLSL may differ (flush, sign of zero, NaN payload), so the "which function is lowered" check does not protect them. - `v_rcp_f32` and `v_rcp_iflag_f32` share one lowering and one input set; the flag behavior of `_iflag` is not (and cannot be) observed. - As on the sibling PR #1741, a wrong value that keeps the shape of the translated text is only caught by the Windows draws. Not approving (comment only). AI-assisted; commands listed were executed locally.
thepatrickworld commented 2026-11-24 19:01:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T18:59:52Z.


Draw mode, run on Windows

tedin7's review says it plainly: I could NOT run the draw mode, so no draw-mode result was on record outside the author's machine. They run here.

2026-11-24, head 627d66e8 merged onto main (my merge 3939c6a3, tree a2b5369f, 1101 tests), ctest --preset dev -R "^startup_gfx2hlsl_float_transcendental" --no-tests=error --output-on-failure -V, three consecutive runs, identical each time:

377: warp: 24 draws matched, 12 mutated draws read their mutated words
378: hardware: 24 draws matched, 12 mutated draws read their mutated words
100% tests passed out of 3

Same totals as the table in the PR body. What differs, row by row: the hardware row is a different AMD architecture, AMD Radeon RX 9070 XT 1002:7550 driver 32.0.32029.2010 (RDNA 4, gfx1201) instead of the RX 6600 (RDNA 2); the WARP row is the same Microsoft software adapter, with a newer compiler build. Both rows run DXC 1.9.2602.17 rather than 1.8.2502.11.

One line of detail on the mutations, because it separates "reads a different number" from "reads the mutation's own reference": for v_rcp_f32 the mutated draw reads 3f000000,c0800000,40000000,41800000, which is 0.5, -4.0, 2.0, 16.0 — exactly 2.0 / x for the four inputs 4.0, -0.5, 1.0, 0.125, and not a rounding difference. I decoded the words by hand for that operation only; the log reports 12 mutated draws per adapter (six operations × fxc and dxc), each reading its own mutated words.

Environment: Windows 11 25H2 26200.9974, DXC 1.9.2602.17, FXC 10.0.26100, dev preset, debug_layer=unavailable.

Limits: one adapter, one driver, no debug layer. As the test says, the inputs are exact powers of two, plus the two sqrt cases (0 and 9) whose roots are integers, so this checks which function and base each operation is lowered to, not the precision of any adapter's approximation. Nothing here covers v_sin_f32 or v_cos_f32, which the PR leaves out.

AI-assisted; runs executed on the machine above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141445427 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1745#issuecomment-7141445427). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-24T18:59:52Z. --- ### Draw mode, run on Windows tedin7's review says it plainly: `I could NOT run the draw mode`, so no draw-mode result was on record outside the author's machine. They run here. 2026-11-24, head `627d66e8` merged onto main (my merge `3939c6a3`, tree `a2b5369f`, 1101 tests), `ctest --preset dev -R "^startup_gfx2hlsl_float_transcendental" --no-tests=error --output-on-failure -V`, three consecutive runs, identical each time: ``` 377: warp: 24 draws matched, 12 mutated draws read their mutated words 378: hardware: 24 draws matched, 12 mutated draws read their mutated words 100% tests passed out of 3 ``` Same totals as the table in the PR body. What differs, row by row: the hardware row is a different AMD architecture, `AMD Radeon RX 9070 XT` `1002:7550` driver `32.0.32029.2010` (RDNA 4, `gfx1201`) instead of the RX 6600 (RDNA 2); the WARP row is the same Microsoft software adapter, with a newer compiler build. Both rows run DXC `1.9.2602.17` rather than `1.8.2502.11`. One line of detail on the mutations, because it separates "reads a different number" from "reads the mutation's own reference": for `v_rcp_f32` the mutated draw reads `3f000000,c0800000,40000000,41800000`, which is `0.5, -4.0, 2.0, 16.0` — exactly `2.0 / x` for the four inputs `4.0, -0.5, 1.0, 0.125`, and not a rounding difference. I decoded the words by hand for that operation only; the log reports 12 mutated draws per adapter (six operations × `fxc` and `dxc`), each reading its own mutated words. Environment: Windows 11 25H2 `26200.9974`, DXC `1.9.2602.17`, FXC `10.0.26100`, `dev` preset, `debug_layer=unavailable`. Limits: one adapter, one driver, no debug layer. As the test says, the inputs are exact powers of two, plus the two `sqrt` cases (`0` and `9`) whose roots are integers, so this checks which function and base each operation is lowered to, not the precision of any adapter's approximation. Nothing here covers `v_sin_f32` or `v_cos_f32`, which the PR leaves out. _AI-assisted; runs executed on the machine above._
legacy-code-archaeologist commented 2026-11-24 23:03:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T22:28:07Z.


Hardware run of head 627d66e8. Windows 11 Pro 26100.9168, DXC/FXC from Windows SDK 10.0.26100, dev preset, debug layer unavailable here. Adapter selected with XBOX2WINDOWS_ADAPTER: WARP 10.0.26100.8972, NVIDIA Quadro M1000M (Maxwell, 10de:13b1) 32.0.15.7371, Intel HD Graphics 530 (Gen9, 8086:191b) 31.0.101.2111.

Test Result
startup_gfx2hlsl_float_transcendental_controls Passed
startup_gfx2hlsl_float_transcendental_warp Passed
startup_gfx2hlsl_float_transcendental_hardware on the HD 530 Passed
startup_gfx2hlsl_float_transcendental_hardware on the Quadro M1000M Failed at v_sqrt_f32 (FXC)

The rcp, rcp_iflag and rsq rows pass on the Quadro too. The failing draw:

AssertionError: fxc v_sqrt_f32 inputs [(897581056, 0, 0), (1115684864, 0, 0), (0, 0, 0), (1091567616, 0, 0)]
startup_flat_param mismatch expected=3a800000,41000000,00000000,40400000 actual=3a800000,41000000,00000000,40400001

sqrt(9.0) (0x41100000) returns 0x40400001 on Maxwell, one ulp above the exact 0x40400000; the other lanes are exact. D3D's sqrt is not required to be correctly rounded, so this looks like an adapter tolerance rather than a lowering error. Whether the fixture should accept one ulp here, or the lowering should be made exact, is your call; I have not tested either.

No changes made.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146265827 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1745#issuecomment-7146265827). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T22:28:07Z. --- Hardware run of head 627d66e8. Windows 11 Pro 26100.9168, DXC/FXC from Windows SDK 10.0.26100, `dev` preset, debug layer unavailable here. Adapter selected with `XBOX2WINDOWS_ADAPTER`: WARP 10.0.26100.8972, NVIDIA Quadro M1000M (Maxwell, 10de:13b1) 32.0.15.7371, Intel HD Graphics 530 (Gen9, 8086:191b) 31.0.101.2111. | Test | Result | |---|---| | `startup_gfx2hlsl_float_transcendental_controls` | Passed | | `startup_gfx2hlsl_float_transcendental_warp` | Passed | | `startup_gfx2hlsl_float_transcendental_hardware` on the HD 530 | Passed | | `startup_gfx2hlsl_float_transcendental_hardware` on the **Quadro M1000M** | **Failed** at `v_sqrt_f32` (FXC) | The rcp, rcp_iflag and rsq rows pass on the Quadro too. The failing draw: ``` AssertionError: fxc v_sqrt_f32 inputs [(897581056, 0, 0), (1115684864, 0, 0), (0, 0, 0), (1091567616, 0, 0)] startup_flat_param mismatch expected=3a800000,41000000,00000000,40400000 actual=3a800000,41000000,00000000,40400001 ``` `sqrt(9.0)` (`0x41100000`) returns `0x40400001` on Maxwell, one ulp above the exact `0x40400000`; the other lanes are exact. D3D's `sqrt` is not required to be correctly rounded, so this looks like an adapter tolerance rather than a lowering error. Whether the fixture should accept one ulp here, or the lowering should be made exact, is your call; I have not tested either. No changes made.
tedin7 commented 2026-11-25 13:01:02 +00:00 (Migrated from github.com)

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


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

GitHub reports head 627d66e8 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
  • tests/startup_gfx2hlsl_lane_alu.py

Commands run locally:

git fetch origin main pull/1745/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1745 --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:7162997501 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1745#issuecomment-7162997501). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:53:24Z. --- @Asimmimx could you rebase this branch onto current `main` and force-push? GitHub reports head `627d66e8` 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` - `tests/startup_gfx2hlsl_lane_alu.py` Commands run locally: ``` git fetch origin main pull/1745/head git merge-tree --write-tree --name-only origin/main FETCH_HEAD gh pr view 1745 --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:49 +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:15:14Z.


Pushed b66ece187: merged current main into this branch (no rebase, no force) so it no longer conflicts.

Conflicts resolved:

  • tests/startup_gfx2hlsl_lane_alu.py (added on both sides): took main's version. It is a superset of this branch's file (it only adds the optional pipeline fixture keyword), so the transcendental check runs unchanged on it.
  • CMakeLists.txt, docs/experiments.md, .github/workflows/windows.yml: kept both sides.

Verification:

  • Linux: python3 tests/startup_gfx2hlsl_float_transcendental_check.py, ... binary llvm-mc-19, and the other lane_alu users startup_gfx2hlsl_cvt_pk_u8_check.py, startup_gfx2hlsl_pack_b32_f16_check.py, startup_gfx2hlsl_cvt_alu_check.py: pass.
  • Win2025 (dev + release): x2w_pipe.py win2025 1745 --patch <merge diff> --regex 'startup_gfx2hlsl_(float_transcendental|cvt_pk_u8|pack_b32_f16|cvt_alu)': 12/12 passed.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7180614743 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1745#issuecomment-7180614743). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:15:14Z. --- Pushed b66ece187: merged current `main` into this branch (no rebase, no force) so it no longer conflicts. Conflicts resolved: - `tests/startup_gfx2hlsl_lane_alu.py` (added on both sides): took main's version. It is a superset of this branch's file (it only adds the optional `pipeline` fixture keyword), so the transcendental check runs unchanged on it. - `CMakeLists.txt`, `docs/experiments.md`, `.github/workflows/windows.yml`: kept both sides. Verification: - Linux: `python3 tests/startup_gfx2hlsl_float_transcendental_check.py`, `... binary llvm-mc-19`, and the other lane_alu users `startup_gfx2hlsl_cvt_pk_u8_check.py`, `startup_gfx2hlsl_pack_b32_f16_check.py`, `startup_gfx2hlsl_cvt_alu_check.py`: pass. - Win2025 (dev + release): `x2w_pipe.py win2025 1745 --patch <merge diff> --regex 'startup_gfx2hlsl_(float_transcendental|cvt_pk_u8|pack_b32_f16|cvt_alu)'`: 12/12 passed. 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!1738
No description provided.