fix(shader): quiet f64 signaling NaNs only in IEEE mode #2035

Merged
CouchRiv merged 1 commit from upstream-pr/2035 into main 2026-10-10 07:49:39 +00:00
CouchRiv commented 2026-10-09 05:35:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T05:35:16Z.


What

Part of #981, follow-up to #1867. The f64 unary instructions always set the quiet bit on a signaling NaN input:

v_fract_f64 0x7ff00000_00000001, IEEE=0: hardware 0x7ff00000_00000001, recompiler 0x7ff80000_00000001

The SPIR-V lowering quiets every f64 NaN, but the hardware does that only with IEEE_MODE=1, the same rule #1867 measured for f32 and f16. Translation now follows GuestContext::floatMode.ieeeMode through a third helper, quietNan64, next to quietNan32 and quietNan16.

  • Changed here: v_sqrt/rcp/rsq/fract/floor/ceil/trunc/rndne/frexp_mant_f64, v_ldexp_f64, v_div_fixup_f64 and v_cvt_f64_f32 return a signaling NaN unchanged with IEEE=0 and quieted with IEEE=1. A shader without a known float mode follows IEEE=0.
  • Recorded, not changed: v_add/mul/fma_f64 follow the same rule on hardware, but their NaN bits stay with the driver, as for f16 (#2083 now chooses them for f32). v_cvt_f32_f64 always quiets, like v_cvt_f16_f32, and the code already does that.

TechnicalDebt: the "Signaling NaN inputs" line now names the f64 forms and the two conversions.

Which title needs it

No single title. This applies #1867's measured rule to the f64 forms of the same instructions. Most titles run with IEEE=0, where the f64 forms were still quieting.

Measured on RDNA2 (gfx1036, Radeon 610M) with the HW oracle. #1867 was measured on gfx1035, which is the same family. Settings: f32 denormals flushed, f16/f64 denormals kept, round to nearest even, DX10 clamp on.

Instruction, input IEEE=0 IEEE=1
v_floor_f64 0xfff00000_12345678 0xfff00000_12345678 0xfff80000_12345678
v_ldexp_f64 0x7ff40000_00000000, 0 0x7ff40000_00000000 0x7ffc0000_00000000
v_rcp_f64 0x7ff00000_00000001 0x7ff00000_00000001 0x7ff80000_00000001
v_div_fixup_f64 1.0, 0x7ff00000_00000001, 1.0 0x7ff00000_00000001 0x7ff80000_00000001
v_cvt_f64_f32 0xff812345 0xfff02468_a0000000 0xfff82468_a0000000
v_cvt_f32_f64 0x7ff00000_00000001 0x7fc00000 0x7fc00000

Tested

CachyOS Linux, GCC 16.2, RTX 4070 Ti (NVIDIA 615.71) and Radeon 610M (RADV, Mesa 26.2.4).

  • agc_driver_nan_quieting runs two more kernels, 13 f64 instructions × 8 rows captured on hardware, with no mode, IEEE=0 and IEEE=1, bit for bit. For v_rcp/rsq/sqrt_f64 only the NaN cells are compared, because their finite results are approximations. The f64 part runs only when the device has Float64, like the other f64 tests; otherwise it prints that it was skipped and the f32/f16 checks still run. Checked with a copy of the test that removes Float64 from the target: it skips the f64 part and passes on both drivers.
  • agc_driver_f64_arithmetic, _conversions, _division, _division_modifiers, _nan_conversions and _transcendental expected quieted NaNs. Their tables predate the oracle's explicit modes, so they now pin FLOAT_MODE 0xf0, IEEE=1, as #1867 did for its tests. The tables are unchanged.
  • Negative checks, each fails: quieting always (the old behaviour) and quieting never.
  • A hardware-vs-recompiler comparison of these instructions at IEEE=0 and IEEE=1, with DX10 clamp and f32 denormals each on and off: no NaN row differs on either driver.
  • Full ctest 498/498 on NVIDIA and on RADV. check_conventions.py and git diff --check pass.
  • Not tested: gfx1035, lavapipe.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796444576 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2035). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-09T05:35:16Z. --- ### What Part of #981, follow-up to #1867. The f64 unary instructions always set the quiet bit on a signaling NaN input: ``` v_fract_f64 0x7ff00000_00000001, IEEE=0: hardware 0x7ff00000_00000001, recompiler 0x7ff80000_00000001 ``` The SPIR-V lowering quiets every f64 NaN, but the hardware does that only with `IEEE_MODE`=1, the same rule #1867 measured for f32 and f16. Translation now follows `GuestContext::floatMode.ieeeMode` through a third helper, `quietNan64`, next to `quietNan32` and `quietNan16`. - **Changed here:** `v_sqrt/rcp/rsq/fract/floor/ceil/trunc/rndne/frexp_mant_f64`, `v_ldexp_f64`, `v_div_fixup_f64` and `v_cvt_f64_f32` return a signaling NaN unchanged with IEEE=0 and quieted with IEEE=1. A shader without a known float mode follows IEEE=0. - **Recorded, not changed:** `v_add/mul/fma_f64` follow the same rule on hardware, but their NaN bits stay with the driver, as for f16 (#2083 now chooses them for f32). `v_cvt_f32_f64` always quiets, like `v_cvt_f16_f32`, and the code already does that. TechnicalDebt: the "Signaling NaN inputs" line now names the f64 forms and the two conversions. ### Which title needs it No single title. This applies #1867's measured rule to the f64 forms of the same instructions. Most titles run with IEEE=0, where the f64 forms were still quieting. Measured on RDNA2 (gfx1036, Radeon 610M) with the HW oracle. #1867 was measured on gfx1035, which is the same family. Settings: f32 denormals flushed, f16/f64 denormals kept, round to nearest even, DX10 clamp on. | Instruction, input | IEEE=0 | IEEE=1 | |---|---|---| | `v_floor_f64 0xfff00000_12345678` | `0xfff00000_12345678` | `0xfff80000_12345678` | | `v_ldexp_f64 0x7ff40000_00000000, 0` | `0x7ff40000_00000000` | `0x7ffc0000_00000000` | | `v_rcp_f64 0x7ff00000_00000001` | `0x7ff00000_00000001` | `0x7ff80000_00000001` | | `v_div_fixup_f64 1.0, 0x7ff00000_00000001, 1.0` | `0x7ff00000_00000001` | `0x7ff80000_00000001` | | `v_cvt_f64_f32 0xff812345` | `0xfff02468_a0000000` | `0xfff82468_a0000000` | | `v_cvt_f32_f64 0x7ff00000_00000001` | `0x7fc00000` | `0x7fc00000` | ### Tested CachyOS Linux, GCC 16.2, RTX 4070 Ti (NVIDIA 615.71) and Radeon 610M (RADV, Mesa 26.2.4). - `agc_driver_nan_quieting` runs two more kernels, 13 f64 instructions × 8 rows captured on hardware, with no mode, IEEE=0 and IEEE=1, bit for bit. For `v_rcp/rsq/sqrt_f64` only the NaN cells are compared, because their finite results are approximations. The f64 part runs only when the device has Float64, like the other f64 tests; otherwise it prints that it was skipped and the f32/f16 checks still run. Checked with a copy of the test that removes Float64 from the target: it skips the f64 part and passes on both drivers. - `agc_driver_f64_arithmetic`, `_conversions`, `_division`, `_division_modifiers`, `_nan_conversions` and `_transcendental` expected quieted NaNs. Their tables predate the oracle's explicit modes, so they now pin `FLOAT_MODE` 0xf0, IEEE=1, as #1867 did for its tests. The tables are unchanged. - Negative checks, each fails: quieting always (the old behaviour) and quieting never. - A hardware-vs-recompiler comparison of these instructions at IEEE=0 and IEEE=1, with DX10 clamp and f32 denormals each on and off: no NaN row differs on either driver. - Full ctest 498/498 on NVIDIA and on RADV. `check_conventions.py` and `git diff --check` pass. - Not tested: gfx1035, lavapipe. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-09 06:00:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T06:00:00Z.


I reviewed the full diff and the hardware evidence in the PR description. The current Build, Conventions, and Progress workflows for this head are all marked action_required, so those upstream checks have not run. CONTRIBUTING says a maintainer must approve held fork workflows; please have that done before merge. I am holding approval until the required checks are visible.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6075262527 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2035#issuecomment-6075262527). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T06:00:00Z. --- I reviewed the full diff and the hardware evidence in the PR description. The current Build, Conventions, and Progress workflows for this head are all marked action_required, so those upstream checks have not run. CONTRIBUTING says a maintainer must approve held fork workflows; please have that done before merge. I am holding approval until the required checks are visible.
popcoder565 commented 2026-10-09 15:24:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:24:07Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 3b3f77bb, merged onto main d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run.

  • This PR's tests pass: agc_driver_f64_arithmetic, agc_driver_f64_conversions, agc_driver_f64_division, agc_driver_f64_division_modifiers, agc_driver_f64_nan_conversions, agc_driver_f64_transcendental, agc_driver_nan_quieting. None of them reported skipping a case.
  • Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows PATH setup.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083901317 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2035#issuecomment-6083901317). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:24:07Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `3b3f77bb`, merged onto `main` d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run. - This PR's tests pass: `agc_driver_f64_arithmetic`, `agc_driver_f64_conversions`, `agc_driver_f64_division`, `agc_driver_f64_division_modifiers`, `agc_driver_f64_nan_conversions`, `agc_driver_f64_transcendental`, `agc_driver_nan_quieting`. None of them reported skipping a case. - Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows `PATH` setup. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-10 06:56:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:56:54Z.


The red linux/windows jobs were not caused by this PR: both stop building agc_shader_fusion_tests on spirv/unified1/spirv.hpp: No such file or directory (via VulkanTestDevice.hpp), a break on main at the time that 37bc6f2e7 fixed.

The PR also conflicted with main after #2083, in TranslationContext.hpp (nanResultF32) and in the Signaling NaN inputs TechnicalDebt line. I rebased it: kept main's declaration plus quietNan64, and merged the f64 forms, v_cvt_f64_f32 and v_cvt_f32_f64 into main's version of that line.

After the rebase the 7 tests of this PR, agc_driver_f64_rounding and vector_fma_nan_result pass on RADV. The HW-oracle comparison from the earlier review is unchanged (the rebase touches only a declaration and docs). Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094877111 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2035#issuecomment-6094877111). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:56:54Z. --- The red linux/windows jobs were not caused by this PR: both stop building `agc_shader_fusion_tests` on `spirv/unified1/spirv.hpp: No such file or directory` (via `VulkanTestDevice.hpp`), a break on `main` at the time that 37bc6f2e7 fixed. The PR also conflicted with `main` after #2083, in `TranslationContext.hpp` (`nanResultF32`) and in the `Signaling NaN inputs` TechnicalDebt line. I rebased it: kept `main`'s declaration plus `quietNan64`, and merged the f64 forms, `v_cvt_f64_f32` and `v_cvt_f32_f64` into `main`'s version of that line. After the rebase the 7 tests of this PR, `agc_driver_f64_rounding` and `vector_fma_nan_result` pass on RADV. The HW-oracle comparison from the earlier review is unchanged (the rebase touches only a declaration and docs). Merging once CI is green.
adriadam10 commented 2026-10-10 07:18:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:18:35Z.


main moved again and the Signaling NaN inputs TechnicalDebt line conflicted a second time (v_pack_b32_f16 was added to it). I rebased: main's line plus the f64 forms, v_cvt_f64_f32 and v_cvt_f32_f64 clauses from this PR. The code had no conflict.

After the rebase the scoped ctest (327 tests, including the 7 of this PR) passes on RADV. The HW-oracle comparison from the earlier review is unchanged (the rebase only touches that docs line). Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095047609 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2035#issuecomment-6095047609). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:18:35Z. --- `main` moved again and the `Signaling NaN inputs` TechnicalDebt line conflicted a second time (`v_pack_b32_f16` was added to it). I rebased: `main`'s line plus the f64 forms, `v_cvt_f64_f32` and `v_cvt_f32_f64` clauses from this PR. The code had no conflict. After the rebase the scoped ctest (327 tests, including the 7 of this PR) passes on RADV. The HW-oracle comparison from the earlier review is unchanged (the rebase only touches that docs line). Merging once CI is green.
adriadam10 commented 2026-10-10 07:32:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:32:18Z.


main moved again: a change on main added invalidProductF32 next to nanResultF32 in TranslationContext.hpp, which conflicted with the quietNan64 declaration. I rebased, keeping main's lines plus quietNan64. No other change.

After the rebase the scoped ctest (324 tests, including the 7 of this PR) passes on RADV. The HW-oracle comparison from the earlier review is unchanged. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095149425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2035#issuecomment-6095149425). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:32:18Z. --- `main` moved again: a change on `main` added `invalidProductF32` next to `nanResultF32` in `TranslationContext.hpp`, which conflicted with the `quietNan64` declaration. I rebased, keeping `main`'s lines plus `quietNan64`. No other change. After the rebase the scoped ctest (324 tests, including the 7 of this PR) passes on RADV. The HW-oracle comparison from the earlier review is unchanged. Merging once CI is green.
adriadam10 commented 2026-10-10 07:44:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:44:13Z.


main moved again (#2521 plus earlier changes), and this time the conflicts were real: main added nonIeeeMinMaxF64 next to float64Operation and made F64Arithmetic.cpp run in both IEEE modes. I rebased:

  • TranslationContext.hpp / Float64Instructions.cpp: kept main's nonIeeeMinMaxF64 plus float64Unary, vCvtF64F32 and quietNan64.
  • F64Arithmetic.cpp: kept main's Ieee switch instead of pinning IEEE=1, and in the IEEE=0 pass ldexp of the signaling NaN in lane 13 now expects the input unchanged (0xfff7c837), per the hardware rows in the description.
  • TechnicalDebt.md: main's Signaling NaN inputs line plus the f64 forms, v_cvt_f64_f32 and v_cvt_f32_f64 clauses.

After the rebase the scoped ctest (328 tests, including the 7 of this PR and agc_driver_f16_min_max_nan) passes on RADV. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095243445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2035#issuecomment-6095243445). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:44:13Z. --- `main` moved again (#2521 plus earlier changes), and this time the conflicts were real: `main` added `nonIeeeMinMaxF64` next to `float64Operation` and made `F64Arithmetic.cpp` run in both IEEE modes. I rebased: - `TranslationContext.hpp` / `Float64Instructions.cpp`: kept `main`'s `nonIeeeMinMaxF64` plus `float64Unary`, `vCvtF64F32` and `quietNan64`. - `F64Arithmetic.cpp`: kept `main`'s `Ieee` switch instead of pinning IEEE=1, and in the IEEE=0 pass `ldexp` of the signaling NaN in lane 13 now expects the input unchanged (`0xfff7c837`), per the hardware rows in the description. - `TechnicalDebt.md`: `main`'s `Signaling NaN inputs` line plus the f64 forms, `v_cvt_f64_f32` and `v_cvt_f32_f64` clauses. After the rebase the scoped ctest (328 tests, including the 7 of this PR and `agc_driver_f16_min_max_nan`) passes on RADV. Merging once CI is green.
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
boykopovar/AnyPS5!2035
No description provided.