SHADER-F64-OMODS: the binary64 VALU ops take clamp and nothing else from their omod #475

Closed
github-bot wants to merge 3 commits from gh-pr/475/head into gh-pr/475/base
Owner

@⁠fiestorra on GitHub · 2026-11-24 06:01 UTC · original
fiestorra:carry/f64-omod-clamp → main · +108 −67 · 11 files · 3 commits · closed without merging

Claimed in the coordination issue as: SHADER-F64-OMODS (claim comment).

What this changes

The VOP3 profiles for the binary64 VALU ops carry both HasClamp and HasOMod (binary64 is a modifier type), so a v_add_f64 / v_rcp_f64 / v_rsq_f64 / v_sqrt_f64 / v_trunc_f64 / v_ceil_f64 / v_rndne_f64 / v_floor_f64 encoding can name mul:2, mul:4 or div:2 in its omod field. On a gfx1036 iGPU those omods do nothing for these ops while binary64 denormals are kept, which is the mode this translator assumes: they only take effect with MODE.IEEE off and f64 denormals flushed. clamp is the one that applies in the mode we model. Measured on the device with runtime/test/shaders/ps_f64_mods.asm and cs_f64_add.asm, written up in the "v_add_f64 output modifiers" row and named in the v_rcp_f64, v_rsq_f64, v_sqrt_f64 and v_trunc_f64, v_ceil_f64, v_rndne_f64, v_floor_f64 rows of docs/design.md.

So the translator must not model them. tools/rdna2spirv.py now passes only the clamp part of the modifier list to clamp_mods_f64 and dst_f64 for the binary64 arithmetic and rounding ops ([m for m in mods if m == "clamp"]), with a comment naming the measurement and the row that records it, and a caller whose own row measured an omod still gets its own behaviour. A listing that names mul:2 on a v_add_f64 now compiles to the same value as the same listing without the omod, instead of a scaled one.

About the rebase

This is the content of the branch the private tracker carried as #4371, rebased onto ece4ba5b3 as three commits (9948f1f2f, e3a5bea41, e983b38f6). Both conflicts were in one file, tests/test_f64_output_modifiers.py: main writes the VGPR word of the destination directly, and my first version of the test read it through an OpAccessChain-style register load, so I kept main's side of both hunks. My fourth commit, 382366e5d ("tests: read the f64 destination write the way a VGPR word is written now"), existed only to adapt that test to the older shape and models nothing, so it is not in this branch: I dropped it with git rebase --skip. Nothing else was dropped, and the diff over main is the same 11 files:

docs/design.md                       |  6 ++---
runtime/test/shaders/check.py        |  2 +-
runtime/test/shaders/cs_f64_add.asm  |  3 ++-
runtime/test/shaders/ps_f64_mods.asm | 11 +++++----
scripts/run_gpu_tests.py             |  4 ++--
tests/semantic/test_f64_round.py     | 23 ++++++++++++++++++-
tests/semantic/test_valu_add_f64.py  | 18 ++++++++-------
tests/test_f64_diff.py               | 11 ++++++---
tests/test_f64_output_modifiers.py   | 43 ++++++++++++++++++------------------
tests/test_f64_transcendentals.py    | 28 +++++++++++------------
tools/rdna2spirv.py                  | 26 ++++++++++++++++------
11 files changed, 108 insertions(+), 67 deletions(-)

Evidence on ece4ba5b3

Head e983b38f6. Tools: CPython 3.13.14, pytest 9.2.0, llvm-mc 21.1.8 built by scripts/build_llvm_mc.ps1, spirv-as/spirv-val from Vulkan SDK 1.4.363.0, Windows build 26300. LEONIDA_HW_ARCH=gfx1036 was set for the device measurement described above, which was made on this machine's gfx1036 iGPU on 2026-11-22 and 2026-11-23 on the previous base; nothing in today's re-measurement needed a GPU.

  • py -3.13 -m pytest tests/test_f64_output_modifiers.py tests/test_f64_diff.py tests/test_f64_transcendentals.py -q — clean ece4ba5b3: 35 passed, 591 subtests passed in 2.83s. This branch: 35 passed, 591 subtests passed in 2.83s. Nothing that passes today stops passing.
  • py -3.13 -I -m unittest discover -s tests/semantic -p "test_f64_round.py" — clean ece4ba5b3: Ran 6 tests / OK. This branch: Ran 7 tests / OK. test_valu_add_f64.py: Ran 8 tests / OK both sides.
  • Negative control (same tests, tools/rdna2spirv.py from ece4ba5b3): py -3.13 -m pytest tests/test_f64_output_modifiers.py tests/test_f64_diff.py tests/test_f64_transcendentals.py -q → 9 failed, 34 passed, 583 subtests, including SUBFAILED(op='v_rsq_f64_e64', mods='clamp div:2') and SUBFAILED(op='v_sqrt_f64_e64', mods='clamp mul:4'), and the semantic files fail as test_f64_round FAILED (failures=4) and test_valu_add_f64 FAILED (failures=5). So every new assertion fails against main's translator and passes with this change.
  • Full semantic suite (py -3.13 -I scripts/run_semantic_tests.py tests/semantic), with llvm-mc on PATH and LLVM_MC unset: clean ece4ba5b3 465 files, 6103 tests, 0 files failed in 440 s with 16 jobs. This branch: 465 files, 6104 tests, 0 files failed in 458 s with 16 jobs. Same 465 files, nothing red either side, and the one extra test is the added rounding case.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 06:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/475) `fiestorra:carry/f64-omod-clamp` → `main` · +108 −67 · 11 files · 3 commits · closed without merging Claimed in the coordination issue as: `SHADER-F64-OMODS` ([claim comment](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). ### What this changes The VOP3 profiles for the binary64 VALU ops carry both `HasClamp` and `HasOMod` (binary64 is a modifier type), so a `v_add_f64` / `v_rcp_f64` / `v_rsq_f64` / `v_sqrt_f64` / `v_trunc_f64` / `v_ceil_f64` / `v_rndne_f64` / `v_floor_f64` encoding can name `mul:2`, `mul:4` or `div:2` in its omod field. On a gfx1036 iGPU those omods do nothing for these ops while binary64 denormals are kept, which is the mode this translator assumes: they only take effect with `MODE.IEEE` off and f64 denormals flushed. `clamp` is the one that applies in the mode we model. Measured on the device with `runtime/test/shaders/ps_f64_mods.asm` and `cs_f64_add.asm`, written up in the "v_add_f64 output modifiers" row and named in the `v_rcp_f64, v_rsq_f64, v_sqrt_f64` and `v_trunc_f64, v_ceil_f64, v_rndne_f64, v_floor_f64` rows of `docs/design.md`. So the translator must not model them. `tools/rdna2spirv.py` now passes only the clamp part of the modifier list to `clamp_mods_f64` and `dst_f64` for the binary64 arithmetic and rounding ops (`[m for m in mods if m == "clamp"]`), with a comment naming the measurement and the row that records it, and a caller whose own row measured an omod still gets its own behaviour. A listing that names `mul:2` on a `v_add_f64` now compiles to the same value as the same listing without the omod, instead of a scaled one. ### About the rebase This is the content of the branch the private tracker carried as #4371, rebased onto `ece4ba5b3` as three commits (`9948f1f2f`, `e3a5bea41`, `e983b38f6`). Both conflicts were in one file, `tests/test_f64_output_modifiers.py`: `main` writes the VGPR word of the destination directly, and my first version of the test read it through an `OpAccessChain`-style register load, so I kept `main`'s side of both hunks. My fourth commit, `382366e5d` ("tests: read the f64 destination write the way a VGPR word is written now"), existed only to adapt that test to the older shape and models nothing, so it is not in this branch: I dropped it with `git rebase --skip`. Nothing else was dropped, and the diff over `main` is the same 11 files: ``` docs/design.md | 6 ++--- runtime/test/shaders/check.py | 2 +- runtime/test/shaders/cs_f64_add.asm | 3 ++- runtime/test/shaders/ps_f64_mods.asm | 11 +++++---- scripts/run_gpu_tests.py | 4 ++-- tests/semantic/test_f64_round.py | 23 ++++++++++++++++++- tests/semantic/test_valu_add_f64.py | 18 ++++++++------- tests/test_f64_diff.py | 11 ++++++--- tests/test_f64_output_modifiers.py | 43 ++++++++++++++++++------------------ tests/test_f64_transcendentals.py | 28 +++++++++++------------ tools/rdna2spirv.py | 26 ++++++++++++++++------ 11 files changed, 108 insertions(+), 67 deletions(-) ``` ### Evidence on `ece4ba5b3` Head `e983b38f6`. Tools: CPython 3.13.14, `pytest 9.2.0`, `llvm-mc` 21.1.8 built by `scripts/build_llvm_mc.ps1`, `spirv-as`/`spirv-val` from Vulkan SDK 1.4.363.0, Windows build 26300. `LEONIDA_HW_ARCH=gfx1036` was set for the device measurement described above, which was made on this machine's gfx1036 iGPU on 2026-11-22 and 2026-11-23 on the previous base; nothing in today's re-measurement needed a GPU. * `py -3.13 -m pytest tests/test_f64_output_modifiers.py tests/test_f64_diff.py tests/test_f64_transcendentals.py -q` — clean `ece4ba5b3`: `35 passed, 591 subtests passed in 2.83s`. This branch: `35 passed, 591 subtests passed in 2.83s`. Nothing that passes today stops passing. * `py -3.13 -I -m unittest discover -s tests/semantic -p "test_f64_round.py"` — clean `ece4ba5b3`: `Ran 6 tests / OK`. This branch: `Ran 7 tests / OK`. `test_valu_add_f64.py`: `Ran 8 tests / OK` both sides. * Negative control (same tests, `tools/rdna2spirv.py` from `ece4ba5b3`): `py -3.13 -m pytest tests/test_f64_output_modifiers.py tests/test_f64_diff.py tests/test_f64_transcendentals.py -q` → `9 failed, 34 passed, 583 subtests`, including `SUBFAILED(op='v_rsq_f64_e64', mods='clamp div:2')` and `SUBFAILED(op='v_sqrt_f64_e64', mods='clamp mul:4')`, and the semantic files fail as `test_f64_round` `FAILED (failures=4)` and `test_valu_add_f64` `FAILED (failures=5)`. So every new assertion fails against `main`'s translator and passes with this change. * Full semantic suite (`py -3.13 -I scripts/run_semantic_tests.py tests/semantic`), with `llvm-mc` on `PATH` and `LLVM_MC` unset: clean `ece4ba5b3` `465 files, 6103 tests, 0 files failed in 440 s with 16 jobs`. This branch: `465 files, 6104 tests, 0 files failed in 458 s with 16 jobs`. Same 465 files, nothing red either side, and the one extra test is the added rounding case. Written with an AI assistant.
RDNA2 ignores the VOP3 output modifier of the f64 VALU arithmetic and rounding
ops while f64 denormals are kept, which is the MODE this translator models. I
measured it with tools/hw_oracle raw kernels on a gfx1036 iGPU (the Radeon
iGPU of a Ryzen 7 7800X3D, Windows driver 31.0.24002.92, code object v5),
wave32 and wave64 identical, over the four combinations of MODE.IEEE and
denorm_mode_16_64. mul:2 / mul:4 / div:2 changed nothing for v_add_f64,
v_rcp_f64, v_rsq_f64, v_sqrt_f64, v_trunc_f64, v_ceil_f64, v_floor_f64 and
v_rndne_f64 while f64 denormals were kept, applied only with MODE.IEEE off and
the denormals flushed, and clamp applied in every one of those runs. The two
f64 call sites that still forwarded a full modifier list now hand
clamp_mods_f64 only the clamp they act on, and the rows that described the
scaling for those ops are corrected to what the hardware does.

This is SHADER-721, the binary64 counterpart of the f16 omod row (#4542,
"an f16 destination ignores omod"). The row for v_add_f64 records the sweep and
how it was confirmed and keeps the LLVM VOP3 citation main already had; the
rcp/rsq/sqrt and rounding rows keep the measurements others contributed (the
v_sqrt_f64 ulp errors, @timelery's sweep of the four rounding ops) and only
change the sentence about the omod. One contradiction is removed on the way:
main's rounding row said the translator applies the modifiers "as those rows
do" while the code applied them to ops whose own row says they are ignored.

Ops with their own rows are left exactly as they are - v_cvt_f64_i32/u32,
v_cvt_f32_f64, v_frexp_mant_f64, v_div_fixup_f64 and v_ldexp_f64 keep what
their rows measure. The same rule probably reaches the first three as well, and
tests/semantic/test_alu_ldexp_f64.py already knows it for ldexp; I raised that
in #5256 as a finding instead of folding unmeasured ops into this change.

Counted over the whole corpus, not a sample: 216 v_add_f64 in 5 of the 26,503
listings, none carrying an omod or a clamp, and no f64 mnemonic in the corpus
carries one, so no game shader changes behaviour here. The two translated
fixtures that do carry a modifier move to the unmodified result, which is what
the sweep predicts: cs_f64_add now reads 0x0 0x3ff40000.

Expectations follow the rule in tests/semantic/test_valu_add_f64.py,
tests/semantic/test_f64_round.py, tests/test_f64_output_modifiers.py,
tests/test_f64_transcendentals.py and the two fixtures with their runners.
tools/f64_diff.py keeps its f64-omod case as a known divergence and
tests/test_f64_diff.py now expects it to mismatch the ISA reference rather than
match it: the reference applies the omod the ISA text describes, the translator
no longer emits it, and that case is the one MODE in which the hardware does
apply it. ps_f64_mods, cs_f64_add and ps_f64_round pass on an NVIDIA RTX 4090
(driver 32.0.16.2124) and on the gfx1036 iGPU above, 3/3 on both; cs_f64_add
reads the same words on Intel UHD 630 / Mesa ANV at this head (@gertify).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:02:46 +00:00
github-bot closed this pull request 2026-11-26 09:02:47 +00:00
Author
Owner

@⁠moffington on GitHub · 2026-11-24 06:14 UTC · original

Tested e983b38f6 on Linux with an RTX 3060 (driver 615.78.08). I translated the same fixtures with the PR and merge-base (ece4ba5b3) translators and ran both with Vulkan validation enabled.

  • cs_f64_add returned 1.25 with the PR, up against 2.5 on the merge base.
  • ps_f64_mods matched all four expected words in 4096/4096 pixels with the PR. The clamp div:2 lane returned 1.0 with the PR and 0.625 on the merge base.
    The filtered f64 GPU suite passed 4/4, with zero Vulkan validation errors. This verifies the translated SPIR-V behavior on NVIDIA.
**@⁠moffington** on GitHub · 2026-11-24 06:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/475#issuecomment-7123736564) Tested e983b38f6 on Linux with an RTX 3060 (driver 615.78.08). I translated the same fixtures with the PR and merge-base (ece4ba5b3) translators and ran both with Vulkan validation enabled. - cs_f64_add returned 1.25 with the PR, up against 2.5 on the merge base. - ps_f64_mods matched all four expected words in 4096/4096 pixels with the PR. The clamp div:2 lane returned 1.0 with the PR and 0.625 on the merge base. The filtered f64 GPU suite passed 4/4, with zero Vulkan validation errors. This verifies the translated SPIR-V behavior on NVIDIA.
Author
Owner

@⁠fiestorra on GitHub · 2026-11-24 07:23 UTC · original

Thank you — that closes the gap I left open in this pull request, which is that my own measurement was on an AMD card and predated a lot of the current main. I have now run the same head on this machine, and your two numbers reproduce exactly, word for word, on a third device class.

Machine: AMD Radeon 780M integrated GPU (gfx1036), Windows build 26300, CPython 3.13.14, llvm-mc 21.1.8, Vulkan SDK 1.4.363, LEONIDA_VK_DEVICE=radeon. Same head you tested (e983b38f6), applied on today's main d42773d07: the three commits come across in order with no conflicts and give the same 11 files, +108/−67 the pull request shows.

py -3.13 -I scripts/run_gpu_tests.py --build <build of d42773d07> --filter f64

with the change applied:

  PASS  cs_div_fmas_f64       0x0 0x3c300000
  PASS  cs_f64_add            0x0 0x3ff40000
  PASS  ps_f64_mods           4096/4096 pixels exact
  PASS  ps_f64_round          4096/4096 pixels exact
4/4 passed

and the same command in a second worktree at plain d42773d07 (only the fixture and the translator differ; the Vulkan test programs are the same binaries in both runs, so nothing about the harness moved between the two columns):

  PASS  cs_div_fmas_f64       0x0 0x3c300000
  PASS  cs_f64_add            0x0 0x40040000
  PASS  ps_f64_mods           4096/4096 pixels exact
  PASS  ps_f64_round          4096/4096 pixels exact

0x40040000 with the high word first is the double 2.5 you saw on the merge base, and 0x3ff40000 is the 1.25 you saw with the pull request. The ps_f64_mods column is the same pair: the fixture on main expects 0x40040000, 0x3ff00000, 0x3fe40000, 0x3ff00000 (2.5, 1.0, 0.625, 1.0) and passes against it, the fixture as this pull request writes it expects 0x3ff40000, 0x3ff00000, 0x3ff00000, 0x3fd00000 (1.25, 1.0, 1.0, 0.25) and passes against that. So your 1.0-versus-0.625 for the clamp div:2 lane is the same difference seen from here. The two neighbours, cs_div_fmas_f64 and ps_f64_round, come out identical in both columns, which is what I wanted to see on this card since they share the code path.

One thing I would keep visible in the record: on a PC the fixture passes in both columns because each one expects what the translator in that tree emits — the GPU is checking the translator against the fixture, not against an RDNA2 part. The part that carries the actual claim of correctness is still the tools/hw_oracle raw-kernel measurement quoted in the fixture comment on gfx1036, wave32 and wave64, which is why the pull request should be read as "the omod of these binary64 ops does nothing while f64 denormals are kept" with that measurement behind it, and these GPU runs as the confirmation that the change is consistent on a second vendor's hardware and on current main.

One housekeeping note, since I have four other items open: all five branches of mine apply cleanly onto d42773d07 (checked by cherry-picking each one into a scratch worktree at that commit; each gives the same file list and line counts the pull request shows). Nothing here needs a rebase to be reviewed.

**@⁠fiestorra** on GitHub · 2026-11-24 07:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/475#issuecomment-7124930361) Thank you — that closes the gap I left open in this pull request, which is that my own measurement was on an AMD card and predated a lot of the current `main`. I have now run the same head on this machine, and your two numbers reproduce exactly, word for word, on a third device class. Machine: AMD Radeon 780M integrated GPU (gfx1036), Windows build 26300, CPython 3.13.14, `llvm-mc` 21.1.8, Vulkan SDK 1.4.363, `LEONIDA_VK_DEVICE=radeon`. Same head you tested (`e983b38f6`), applied on today's `main` `d42773d07`: the three commits come across in order with no conflicts and give the same 11 files, +108/−67 the pull request shows. ``` py -3.13 -I scripts/run_gpu_tests.py --build <build of d42773d07> --filter f64 ``` with the change applied: ``` PASS cs_div_fmas_f64 0x0 0x3c300000 PASS cs_f64_add 0x0 0x3ff40000 PASS ps_f64_mods 4096/4096 pixels exact PASS ps_f64_round 4096/4096 pixels exact 4/4 passed ``` and the same command in a second worktree at plain `d42773d07` (only the fixture and the translator differ; the Vulkan test programs are the same binaries in both runs, so nothing about the harness moved between the two columns): ``` PASS cs_div_fmas_f64 0x0 0x3c300000 PASS cs_f64_add 0x0 0x40040000 PASS ps_f64_mods 4096/4096 pixels exact PASS ps_f64_round 4096/4096 pixels exact ``` `0x40040000` with the high word first is the double 2.5 you saw on the merge base, and `0x3ff40000` is the 1.25 you saw with the pull request. The `ps_f64_mods` column is the same pair: the fixture on `main` expects `0x40040000, 0x3ff00000, 0x3fe40000, 0x3ff00000` (2.5, 1.0, 0.625, 1.0) and passes against it, the fixture as this pull request writes it expects `0x3ff40000, 0x3ff00000, 0x3ff00000, 0x3fd00000` (1.25, 1.0, 1.0, 0.25) and passes against that. So your 1.0-versus-0.625 for the clamp div:2 lane is the same difference seen from here. The two neighbours, `cs_div_fmas_f64` and `ps_f64_round`, come out identical in both columns, which is what I wanted to see on this card since they share the code path. One thing I would keep visible in the record: on a PC the fixture passes in both columns because each one expects what the translator in that tree emits — the GPU is checking the translator against the fixture, not against an RDNA2 part. The part that carries the actual claim of correctness is still the `tools/hw_oracle` raw-kernel measurement quoted in the fixture comment on gfx1036, wave32 and wave64, which is why the pull request should be read as "the omod of these binary64 ops does nothing while f64 denormals are kept" with that measurement behind it, and these GPU runs as the confirmation that the change is consistent on a second vendor's hardware and on current `main`. One housekeeping note, since I have four other items open: all five branches of mine apply cleanly onto `d42773d07` (checked by cherry-picking each one into a scratch worktree at that commit; each gives the same file list and line counts the pull request shows). Nothing here needs a rebase to be reviewed.
Author
Owner

@⁠fiestorra on GitHub · 2026-11-24 12:19 UTC · original

Closing this. I am moving my work to a different project and will not continue here. Keeping the measurement on the record: moffington tested e983b38f6 on an RTX 3060, and that test closed the gap I had on the f64 fixtures. The omod clamp question itself remains open as a follow-up for whoever picks it up; my part will not be finished here. The branch will be deleted shortly.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 12:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/475#issuecomment-7131274972) Closing this. I am moving my work to a different project and will not continue here. Keeping the measurement on the record: moffington tested e983b38f6 on an RTX 3060, and that test closed the gap I had on the f64 fixtures. The omod clamp question itself remains open as a follow-up for whoever picks it up; my part will not be finished here. The branch will be deleted shortly. Written with an AI assistant.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.