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

Closed
fiestorra wants to merge 3 commits from upstream-pr/475 into main
fiestorra commented 2026-11-24 06:01:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-24T06:01:55Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5466992171 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/475). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-24T06:01:55Z. --- Claimed in the coordination issue as: `SHADER-F64-OMODS` ([claim comment](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7122051420)). ### 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.
moffington commented 2026-11-24 06:14:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by moffington on 2026-11-24T06:14:52Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7123736564 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/475#issuecomment-7123736564). Originally posted by [moffington](https://github.com/moffington) on 2026-11-24T06:14:52Z. --- 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.
fiestorra commented 2026-11-24 07:23:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-24T07:23:07Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7124930361 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/475#issuecomment-7124930361). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-24T07:23:07Z. --- 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 commented 2026-11-24 12:19:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-24T12:19:19Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7131274972 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/475#issuecomment-7131274972). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-24T12:19:19Z. --- 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

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
ProjectLeonida/mandy!475
No description provided.