rdna2spirv: the binary64 VALU ops take clamp and nothing else from their omod (SHADER-F64-OMODS-CARRY) #1112

Open
github-bot wants to merge 4 commits from github-bot/gh-1112 into main AGit
Owner

@⁠klikso on GitHub · 2026-11-24 18:43 UTC · original
klikso:carry/shader-f64-omods → main · +116 −71 · 11 files · 4 commits · open

Claimed in the coordination issue as: SHADER-F64-OMODS-CARRY

What and why

This carries #475 by @⁠fiestorra onto current main: its three commits (9948f1f2f, e3a5bea41, e983b38f6), cherry-picked in order with their author kept and no change of mine. #475 was verified by @⁠Len1k (tests guard the change) and by @⁠moffington on an RTX 3060, reproduced by the author on a Radeon 780M (gfx1036), and then closed by its author on 24 November when he left the project. main still models the omods, and no open pull request carries the change.

The binary64 VALU ops (v_add_f64, v_rcp_f64, v_rsq_f64, v_sqrt_f64, v_trunc_f64, v_ceil_f64, v_rndne_f64, v_floor_f64) can name mul:2, mul:4 or div:2 in their omod field. The author measured on gfx1036 hardware that those omods do nothing for these ops in the mode the translator assumes (binary64 denormals kept); only clamp applies. The translator now passes only the clamp part of the modifier list for these ops, and the fixtures, tests and the docs/design.md rows say so.

@⁠fiestorra: this is your work. If you want it back, say so and I will close this.

Tested

Windows 11 26200.9974, Python 3.13.14 (pytest 9.2.0), llvm-mc 23.1.6 (conda-forge, AMDGPU target), SPIRV-Tools v2026.4. Runtime test programs built from main 3aa975421 with MSVC 19.44; this change does not touch runtime/src or the shims.

The five changed test files, run against main's translator and against this branch's:

main translator this branch
tests/semantic/test_f64_round.py 4 fail pass
tests/semantic/test_valu_add_f64.py 5 fail pass
tests/test_f64_diff.py 1 fail pass
tests/test_f64_output_modifiers.py 5 fail pass
tests/test_f64_transcendentals.py 3 fail pass

run_gpu_tests.py --filter f64, each tree judged by its own check.py, native and with LEONIDA_W64_EMULATE=1 (the two modes give the same words):

Fixture main this branch
cs_f64_add (high word of the mul:2 result) 0x40040000 (2.5) 0x3ff40000 (1.25)
ps_f64_mods 4096/4096 pixels exact 4096/4096 pixels exact, against the new expectations
ps_f64_round, cs_div_fmas_f64, cs_div_fmas_f64_rt pass pass, same words
Total 5/5 passed 5/5 passed

The cs_f64_add pair is the one @⁠moffington reported on the RTX 3060 (1.25 with the change, 2.5 on the merge base). Note what this does and does not show: an NVIDIA device runs the translated SPIR-V, so it confirms the translator emits what the new rule says; the rule itself rests on the author's gfx1036 measurement.

  • python -I scripts/check_no_game_data.py on the eleven changed files: no hits. git diff --check: clean. python -I tests/test_text_write_line_endings.py: pass.

GPUs tested: NVIDIA GeForce RTX 3060 Ti (Ampere), driver 621.14, Vulkan 1.4.357, Windows 11 26200

AI-assisted: yes (Claude Code; run and measured on the machine above)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed: the commits update the three f64 rows there, confirmed by the author's GPU measurement on gfx1036.

🤖 Generated with Claude Code

**@⁠klikso** on GitHub · 2026-11-24 18:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1112) `klikso:carry/shader-f64-omods` → `main` · +116 −71 · 11 files · 4 commits · open Claimed in the coordination issue as: SHADER-F64-OMODS-CARRY ### What and why This carries #475 by @⁠fiestorra onto current `main`: its three commits (`9948f1f2f`, `e3a5bea41`, `e983b38f6`), cherry-picked in order with their author kept and no change of mine. #475 was verified by @⁠Len1k (tests guard the change) and by @⁠moffington on an RTX 3060, reproduced by the author on a Radeon 780M (gfx1036), and then closed by its author on 24 November when he left the project. `main` still models the omods, and no open pull request carries the change. The binary64 VALU ops (`v_add_f64`, `v_rcp_f64`, `v_rsq_f64`, `v_sqrt_f64`, `v_trunc_f64`, `v_ceil_f64`, `v_rndne_f64`, `v_floor_f64`) can name `mul:2`, `mul:4` or `div:2` in their omod field. The author measured on gfx1036 hardware that those omods do nothing for these ops in the mode the translator assumes (binary64 denormals kept); only `clamp` applies. The translator now passes only the clamp part of the modifier list for these ops, and the fixtures, tests and the `docs/design.md` rows say so. @⁠fiestorra: this is your work. If you want it back, say so and I will close this. ### Tested Windows 11 26200.9974, Python 3.13.14 (pytest 9.2.0), `llvm-mc` 23.1.6 (conda-forge, AMDGPU target), SPIRV-Tools v2026.4. Runtime test programs built from `main` `3aa975421` with MSVC 19.44; this change does not touch `runtime/src` or the shims. The five changed test files, run against `main`'s translator and against this branch's: | | `main` translator | this branch | |---|---|---| | `tests/semantic/test_f64_round.py` | 4 fail | pass | | `tests/semantic/test_valu_add_f64.py` | 5 fail | pass | | `tests/test_f64_diff.py` | 1 fail | pass | | `tests/test_f64_output_modifiers.py` | 5 fail | pass | | `tests/test_f64_transcendentals.py` | 3 fail | pass | `run_gpu_tests.py --filter f64`, each tree judged by its own `check.py`, native and with `LEONIDA_W64_EMULATE=1` (the two modes give the same words): | Fixture | `main` | this branch | |---|---|---| | `cs_f64_add` (high word of the `mul:2` result) | `0x40040000` (2.5) | `0x3ff40000` (1.25) | | `ps_f64_mods` | 4096/4096 pixels exact | 4096/4096 pixels exact, against the new expectations | | `ps_f64_round`, `cs_div_fmas_f64`, `cs_div_fmas_f64_rt` | pass | pass, same words | | Total | 5/5 passed | 5/5 passed | The `cs_f64_add` pair is the one @⁠moffington reported on the RTX 3060 (1.25 with the change, 2.5 on the merge base). Note what this does and does not show: an NVIDIA device runs the translated SPIR-V, so it confirms the translator emits what the new rule says; the rule itself rests on the author's gfx1036 measurement. - `python -I scripts/check_no_game_data.py` on the eleven changed files: no hits. `git diff --check`: clean. `python -I tests/test_text_write_line_endings.py`: pass. GPUs tested: NVIDIA GeForce RTX 3060 Ti (Ampere), driver 621.14, Vulkan 1.4.357, Windows 11 26200 AI-assisted: yes (Claude Code; run and measured on the machine above) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed: the commits update the three f64 rows there, confirmed by the author's GPU measurement on gfx1036. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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).
main added a check that mul:2 doubles the result of v_ceil_f64 on a subnormal
(SHADER-ROUND-F64-SPECIALS). With the omod dropped for the binary64 rounding
ops, the result stays 1; the check now says so and adds the clamp case.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:38:46 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 18:48 UTC · original · approved these changes

Reviewed and verified. Accurately reflects measured RDNA2 hardware semantics (gfx1036 oracle): when 64-bit denormals are preserved (denorm_mode_16_64 == 3), mul:2, mul:4, and div:2 omods are ignored by hardware on binary64 VALU ops, while clamp is respected. Emitting only clamp fixes spurious double-scaling in SPIR-V output. Accompanied by comprehensive updates to semantic test suites and docs/design.md. 100% clean-room compliant.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1112#pullrequestreview-6045324617) · **approved these changes** Reviewed and verified. Accurately reflects measured RDNA2 hardware semantics (gfx1036 oracle): when 64-bit denormals are preserved (denorm_mode_16_64 == 3), mul:2, mul:4, and div:2 omods are ignored by hardware on binary64 VALU ops, while clamp is respected. Emitting only clamp fixes spurious double-scaling in SPIR-V output. Accompanied by comprehensive updates to semantic test suites and docs/design.md. 100% clean-room compliant.
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 19:30 UTC · original

Tested b30c72899 on Arch Linux + NVIDIA RTX 3060 Ti (595.58.03 / Vulkan, Python 3.14):

  • PYTHONPATH=tests/semantic python3 -m unittest discover -s tests/semantic -p "test_*f64*.py": 814 tests ran, OK (skipped=2)
  • python3 -m unittest tests/test_f64_output_modifiers.py tests/test_f64_diff.py tests/test_f64_transcendentals.py: 35 tests passed
  • python3 scripts/run_gpu_tests.py --build runtime/build/linux --filter f64 --require-pass (native): 5/5 passed (cs_div_fmas_f64, cs_div_fmas_f64_rt, cs_f64_add, ps_f64_mods, ps_f64_round)
  • LEONIDA_W64_EMULATE=1 ... --filter f64 --require-pass: 5/5 passed

AI-assisted: yes

**@⁠madhyn** on GitHub · 2026-11-24 19:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1112#issuecomment-7142202892) Tested `b30c72899` on Arch Linux + NVIDIA RTX 3060 Ti (595.58.03 / Vulkan, Python 3.14): - `PYTHONPATH=tests/semantic python3 -m unittest discover -s tests/semantic -p "test_*f64*.py"`: **814 tests ran, OK** (skipped=2) - `python3 -m unittest tests/test_f64_output_modifiers.py tests/test_f64_diff.py tests/test_f64_transcendentals.py`: **35 tests passed** - `python3 scripts/run_gpu_tests.py --build runtime/build/linux --filter f64 --require-pass` (native): **5/5 passed** (`cs_div_fmas_f64`, `cs_div_fmas_f64_rt`, `cs_f64_add`, `ps_f64_mods`, `ps_f64_round`) - `LEONIDA_W64_EMULATE=1 ... --filter f64 --require-pass`: **5/5 passed** AI-assisted: yes
Author
Owner

@⁠Deedlyy on GitHub · 2026-11-24 20:16 UTC · original

Recommendation: [MERGE]

Reasoning: Carries #475: the binary64 VALU ops honour only clamp from their omod field, matching hardware, with fixture/test updates across nine files. Behaviour change for f64 shaders, but it was verified on the original PR (RTX 3060, Radeon 780M) and again here by madhyn (814 f64 tests OK on RTX 3060 Ti). CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 5/10

**@⁠Deedlyy** on GitHub · 2026-11-24 20:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1112#issuecomment-7143292586) **Recommendation:** [MERGE] **Reasoning:** Carries #475: the binary64 VALU ops honour only clamp from their omod field, matching hardware, with fixture/test updates across nine files. Behaviour change for f64 shaders, but it was verified on the original PR (RTX 3060, Radeon 780M) and again here by madhyn (814 f64 tests OK on RTX 3060 Ti). CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 5/10
Author
Owner

@⁠klikso on GitHub · 2026-11-25 01:04 UTC · original

Rebased onto main b4b7756e8; the head moved from b30c72899 to 1a3a65e0d. Two things differ from before, both because of commit 26d010b41 (SHADER-ROUND-F64-SPECIALS), which rewrote the binary64 rounding ops on main:

  • Conflict in tools/rdna2spirv.py and the rounding row of docs/design.md. main now selects NaN and subnormal sources by hand and then applies the output modifiers to the selected value. The carried change is applied at that new place: only clamp is handed to clamp_mods_f64 there. The row keeps main's new text about NaNs and subnormals and takes the two sentences this pull request changed. The three commits by @⁠fiestorra keep their author.
  • One new commit of mine, 1a3a65e0d: main's new test_a_subnormal_is_rounded_as_the_hardware_does checked that mul:2 doubles v_ceil_f64 of a subnormal to 2. With the omod dropped the result stays 1, so the check says that and gains a clamp case (v_floor_f64 of the smallest negative subnormal, -1, clamps to 0).

Measured again on the rebased head (Windows 11, RTX 3060 Ti 621.14, test programs built from b4b7756e8 with MSVC 19.44):

main's translator this branch
the five test files this pull request changes 19 failures (tests and subtests) 54 tests and 673 subtests pass, 0 failures
the 22 test files that touch the f64 ops not rerun 586 passed, 2 skipped
run_gpu_tests.py --filter f64, native and LEONIDA_W64_EMULATE=1 not rerun 7/7 passed in both (cs_f64_add reads 0x0 0x3ff40000, ps_f64_mods and ps_f64_round 4096/4096 pixels)

check_no_game_data.py on the changed files: no hits. git diff --check: clean. AI-assisted (Claude Code).

**@⁠klikso** on GitHub · 2026-11-25 01:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1112#issuecomment-7149182385) Rebased onto `main` `b4b7756e8`; the head moved from `b30c72899` to `1a3a65e0d`. Two things differ from before, both because of commit `26d010b41` (`SHADER-ROUND-F64-SPECIALS`), which rewrote the binary64 rounding ops on `main`: - **Conflict in `tools/rdna2spirv.py` and the rounding row of `docs/design.md`.** `main` now selects NaN and subnormal sources by hand and then applies the output modifiers to the selected value. The carried change is applied at that new place: only `clamp` is handed to `clamp_mods_f64` there. The row keeps `main`'s new text about NaNs and subnormals and takes the two sentences this pull request changed. The three commits by @⁠fiestorra keep their author. - **One new commit of mine**, `1a3a65e0d`: `main`'s new `test_a_subnormal_is_rounded_as_the_hardware_does` checked that `mul:2` doubles `v_ceil_f64` of a subnormal to 2. With the omod dropped the result stays 1, so the check says that and gains a `clamp` case (`v_floor_f64` of the smallest negative subnormal, -1, clamps to 0). Measured again on the rebased head (Windows 11, RTX 3060 Ti 621.14, test programs built from `b4b7756e8` with MSVC 19.44): | | `main`'s translator | this branch | |---|---|---| | the five test files this pull request changes | 19 failures (tests and subtests) | 54 tests and 673 subtests pass, 0 failures | | the 22 test files that touch the f64 ops | not rerun | 586 passed, 2 skipped | | `run_gpu_tests.py --filter f64`, native and `LEONIDA_W64_EMULATE=1` | not rerun | 7/7 passed in both (`cs_f64_add` reads `0x0 0x3ff40000`, `ps_f64_mods` and `ps_f64_round` 4096/4096 pixels) | `check_no_game_data.py` on the changed files: no hits. `git diff --check`: clean. AI-assisted (Claude Code).
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 18:36 UTC · original · approved these changes

Approving. Merged into current main (b9320a1) with no conflicts. The updated tests/test_f64_output_modifiers.py, tests/test_f64_transcendentals.py and tests/test_f64_diff.py pass (36 tests), and the full translator suite gives 490 files / 6,293 tests with only test_int32_to_f64 failing, the same baseline failure as main here (Linux, Python 3.13).

The change is consistent at every site. v_add_f64, the rcp/rsq/sqrt ops and the four rounding ops now pass only clamp to clamp_mods_f64, and callers whose own design row measured an omod keep passing it. That matches RDNA2 ignoring f64 omod while denormals are kept. I can't repeat the hw_oracle runs here; the code does what the design row records.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 18:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1112#pullrequestreview-6062996699) · **approved these changes** Approving. Merged into current main (b9320a1) with no conflicts. The updated `tests/test_f64_output_modifiers.py`, `tests/test_f64_transcendentals.py` and `tests/test_f64_diff.py` pass (36 tests), and the full translator suite gives 490 files / 6,293 tests with only `test_int32_to_f64` failing, the same baseline failure as main here (Linux, Python 3.13). The change is consistent at every site. `v_add_f64`, the rcp/rsq/sqrt ops and the four rounding ops now pass only `clamp` to `clamp_mods_f64`, and callers whose own design row measured an omod keep passing it. That matches RDNA2 ignoring f64 omod while denormals are kept. I can't repeat the hw_oracle runs here; the code does what the design row records. AI-assisted (Claude).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1112/head:github-bot/gh-1112'
git switch 'github-bot/gh-1112'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1112'
git switch 'github-bot/gh-1112'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1112'
git switch 'github-bot/gh-1112'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1112'
git switch 'main'
git merge --squash 'github-bot/gh-1112'
git switch 'main'
git merge --ff-only 'github-bot/gh-1112'
git switch 'main'
git merge 'github-bot/gh-1112'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.