fix(shader): flush v_rcp_f64, v_rsq_f64 and v_sqrt_f64 denormals by the f64 field #22384

Merged
NWProgramming00 merged 2 commits from upstream-pr/22384 into main 2026-11-26 05:52:43 +00:00
NWProgramming00 commented 2026-11-17 13:39:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NWProgramming00 on 2026-11-17T13:39:06Z.


What

The technical debt lists v_rcp_f64, v_rsq_f64 and v_sqrt_f64 among the f64 instructions that do not model the FLOAT_MODE f16/f64 denormal field. On RDNA2 they follow it like the other f64 ops:

  • With bit 0 of the field clear (modes 0 and 2), a denormal input is read as a zero of its sign. v_rcp_f64(0x0008000000000000) is +inf on the hardware; the translation gave 0x7fe0000000000000.
  • With bit 1 clear (modes 0 and 1), a denormal result becomes a zero of its sign. v_rcp_f64(2^1023) is +0 on the hardware; the translation gave 0x0008000000000000.

This holds at IEEE=0 and IEEE=1. float64Unary now runs the three opcodes through the same flushF64Bits input flush (bit 0) as v_floor_f64 and v_fract_f64, and the same result flush (bit 1) as v_fract_f64. Without a known float mode, flushF64Bits keeps everything, as before. RoundingUseOf now lists the three opcodes as readers of both f16/f64 denormal bits, as it lists the other f64 ops that flush. A MODE value that differs between paths, or comes from an SGPR, now throws for them instead of being read from a stale field.

Measurement: hardware oracle on an AMD Radeon Graphics iGPU (Ryzen 7 9700X, gfx1036), AMD Windows driver 32.0.21042.62, HIP runtime, against agc_oracle_runner (lavapipe). The PS5's gfx1013 is not measured. Inputs: 27 values covering normals, ±0, ±inf, quiet and signaling NaNs, positive and negative denormals, 2^-1022, values above 2^1022 and ±DBL_MAX. Modes: all four f16/f64 denormal fields, at IEEE 0 and 1.

Before the change, every mode has rows where the hardware and the translation differ in class: zero against denormal, or inf against finite. Examples in mode 0:

input instruction hardware before
0x7fe0000000000000 (2^1023) v_rcp_f64 0x0000000000000000 0x0008000000000000
0xffe0000000000000 v_rcp_f64 0x8000000000000000 0x8008000000000000
0x0008000000000000 v_rcp_f64 0x7ff0000000000000 0x7fe0000000000000
0x000fffffffffffff v_rsq_f64 0x7ff0000000000000 0x5fe0000000000001

After the change, no row differs in sign or class, or by more than 2^-20 relative, in any mode or IEEE setting.

The hardware results of all three instructions are approximations, often only about 30 bits exact. For example, v_sqrt_f64(1.0) is 0x3ff0000004000000 and v_rsq_f64(2.0) is 0x3fe6a09e60000000. The translation keeps the driver's correctly rounded result there. This change does not try to reproduce the approximation.

The new execution test Float64TranscendentalDenormals runs v_rcp_f64, v_rsq_f64 and v_sqrt_f64 over 29 measured inputs in FLOAT_MODE 0x30, 0x70, 0xb0 and 0xf0, with IEEE off.

  • It compares the 244 cells where the hardware result matched the translation on both sides of the oracle run. The other 104 are hardware approximations and are marked Approximate, not compared.
  • The driver's f64 rcp, rsq and sqrt need not be correctly rounded. A finite result therefore passes within 4 ulp of the RDNA 2 value, as long as its class (normal or denormal) and sign match. Zeros, infinities and NaNs stay exact.
  • The two inputs whose exact result is the smallest normal (2^1022) or the overflow threshold (2^-1024) are dropped, since a device within that bound can land on either side.
  • Like F64RoundingDenormalModes, on a device without float64DenormPreserve it skips the cells whose kept input or expected result is a denormal. lavapipe reports no float64DenormPreserve, so it runs the test with 28 cells skipped.
  • I assembled the kernel words with AMD's comgr for gfx1036.

Debt:

  • A new shader entry records the measured behaviour and the approximation.
  • In the libSceAgcDriver float-mode entry, the three instructions move out of the "do not model these denormal controls" list. That entry was already over the 1000-character limit, so check_conventions reports a debt-length warning for this change (0 errors).

Tested

Linux (WSL2 Ubuntu 24.04), GCC, Release, lavapipe, on main 9c0d96916c:

  • agc_driver_float64_transcendental_denormals without the fix: v_rcp_f64 of 0x7fe0000000000000 with FLOAT_MODE 0x30 is 0x0008000000000000, expected the RDNA 2 value 0x0000000000000000. With the fix: passes, also with APS5_SPIRV_OPT=full and none.
  • Full ctest -j 14: 5999 of 6008 pass. All 9 failures also fail with the fix reverted on the same base:
    • agc_driver_image_table_packed_guards fails on main (#21255).
    • agc_hook_clear_access, agc_hook_clear_access_off and agc_driver_recorder fail on main on lavapipe (#21627).
    • patched_self_imports, guest_libressl3_ec_parameters and guest_libressl3_asn1 fail on this main in this environment.
    • guest_audio_in_status_reroute_shared_bounds and guest_audio_out_system_state_output_time_bounds are intermittent here.
  • python3 tools/pr_overlap.py --branch fix/shader-f64-transcendental-denormals: no overlap with open pull requests.
  • python3 tools/check_conventions.py --base origin/main: 0 errors, 1 debt-length warning as above.
  • python3 tools/debt_fold.py --check: the only error is test-libc-wcstombs.md and fix-libc-wcstombs-zero-capacity.md changing the same libc entry, which main reports without this change.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: lavapipe (llvmpipe, LLVM 20.1.2, Mesa) on Linux (WSL2) for the GPU tests; the measurement is from an AMD Radeon Graphics iGPU (gfx1036, Ryzen 7 9700X), AMD Windows driver 32.0.21042.62, Windows 11
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5357914845 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22384). Originally posted by [NWProgramming00](https://github.com/NWProgramming00) on 2026-11-17T13:39:06Z. --- ### What The [technical debt](docs/dev/debt/libSceAgcDriver.md) lists `v_rcp_f64`, `v_rsq_f64` and `v_sqrt_f64` among the f64 instructions that do not model the `FLOAT_MODE` f16/f64 denormal field. On RDNA2 they follow it like the other f64 ops: - With bit 0 of the field clear (modes 0 and 2), a denormal input is read as a zero of its sign. `v_rcp_f64(0x0008000000000000)` is `+inf` on the hardware; the translation gave `0x7fe0000000000000`. - With bit 1 clear (modes 0 and 1), a denormal result becomes a zero of its sign. `v_rcp_f64(2^1023)` is `+0` on the hardware; the translation gave `0x0008000000000000`. This holds at IEEE=0 and IEEE=1. `float64Unary` now runs the three opcodes through the same `flushF64Bits` input flush (bit 0) as `v_floor_f64` and `v_fract_f64`, and the same result flush (bit 1) as `v_fract_f64`. Without a known float mode, `flushF64Bits` keeps everything, as before. `RoundingUseOf` now lists the three opcodes as readers of both f16/f64 denormal bits, as it lists the other f64 ops that flush. A MODE value that differs between paths, or comes from an SGPR, now throws for them instead of being read from a stale field. Measurement: [hardware oracle](docs/dev/HW_ORACLE.md) on an AMD Radeon Graphics iGPU (Ryzen 7 9700X, gfx1036), AMD Windows driver 32.0.21042.62, HIP runtime, against `agc_oracle_runner` (lavapipe). The PS5's gfx1013 is not measured. Inputs: 27 values covering normals, ±0, ±inf, quiet and signaling NaNs, positive and negative denormals, 2^-1022, values above 2^1022 and ±DBL_MAX. Modes: all four f16/f64 denormal fields, at IEEE 0 and 1. Before the change, every mode has rows where the hardware and the translation differ in class: zero against denormal, or inf against finite. Examples in mode 0: | input | instruction | hardware | before | |---|---|---|---| | `0x7fe0000000000000` (2^1023) | `v_rcp_f64` | `0x0000000000000000` | `0x0008000000000000` | | `0xffe0000000000000` | `v_rcp_f64` | `0x8000000000000000` | `0x8008000000000000` | | `0x0008000000000000` | `v_rcp_f64` | `0x7ff0000000000000` | `0x7fe0000000000000` | | `0x000fffffffffffff` | `v_rsq_f64` | `0x7ff0000000000000` | `0x5fe0000000000001` | After the change, no row differs in sign or class, or by more than 2^-20 relative, in any mode or IEEE setting. The hardware results of all three instructions are approximations, often only about 30 bits exact. For example, `v_sqrt_f64(1.0)` is `0x3ff0000004000000` and `v_rsq_f64(2.0)` is `0x3fe6a09e60000000`. The translation keeps the driver's correctly rounded result there. This change does not try to reproduce the approximation. The new execution test `Float64TranscendentalDenormals` runs `v_rcp_f64`, `v_rsq_f64` and `v_sqrt_f64` over 29 measured inputs in FLOAT_MODE 0x30, 0x70, 0xb0 and 0xf0, with IEEE off. - It compares the 244 cells where the hardware result matched the translation on both sides of the oracle run. The other 104 are hardware approximations and are marked `Approximate`, not compared. - The driver's f64 rcp, rsq and sqrt need not be correctly rounded. A finite result therefore passes within 4 ulp of the RDNA 2 value, as long as its class (normal or denormal) and sign match. Zeros, infinities and NaNs stay exact. - The two inputs whose exact result is the smallest normal (`2^1022`) or the overflow threshold (`2^-1024`) are dropped, since a device within that bound can land on either side. - Like `F64RoundingDenormalModes`, on a device without `float64DenormPreserve` it skips the cells whose kept input or expected result is a denormal. lavapipe reports no `float64DenormPreserve`, so it runs the test with 28 cells skipped. - I assembled the kernel words with AMD's comgr for gfx1036. Debt: - A new shader entry records the measured behaviour and the approximation. - In the `libSceAgcDriver` float-mode entry, the three instructions move out of the "do not model these denormal controls" list. That entry was already over the 1000-character limit, so `check_conventions` reports a `debt-length` warning for this change (0 errors). ### Tested Linux (WSL2 Ubuntu 24.04), GCC, Release, lavapipe, on `main` `9c0d96916c`: - `agc_driver_float64_transcendental_denormals` without the fix: `v_rcp_f64 of 0x7fe0000000000000 with FLOAT_MODE 0x30 is 0x0008000000000000, expected the RDNA 2 value 0x0000000000000000`. With the fix: passes, also with `APS5_SPIRV_OPT=full` and `none`. - Full `ctest -j 14`: 5999 of 6008 pass. All 9 failures also fail with the fix reverted on the same base: - `agc_driver_image_table_packed_guards` fails on `main` (#21255). - `agc_hook_clear_access`, `agc_hook_clear_access_off` and `agc_driver_recorder` fail on `main` on lavapipe (#21627). - `patched_self_imports`, `guest_libressl3_ec_parameters` and `guest_libressl3_asn1` fail on this `main` in this environment. - `guest_audio_in_status_reroute_shared_bounds` and `guest_audio_out_system_state_output_time_bounds` are intermittent here. - `python3 tools/pr_overlap.py --branch fix/shader-f64-transcendental-denormals`: no overlap with open pull requests. - `python3 tools/check_conventions.py --base origin/main`: 0 errors, 1 `debt-length` warning as above. - `python3 tools/debt_fold.py --check`: the only error is `test-libc-wcstombs.md` and `fix-libc-wcstombs-zero-capacity.md` changing the same libc entry, which `main` reports without this change. ### Checklist - [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) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: lavapipe (llvmpipe, LLVM 20.1.2, Mesa) on Linux (WSL2) for the GPU tests; the measurement is from an AMD Radeon Graphics iGPU (gfx1036, Ryzen 7 9700X), AMD Windows driver 32.0.21042.62, Windows 11 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-22 22:17:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T22:17:25Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation applies the described f64 denormal input and result flushing, and the included execution test checks measured cases within its stated tolerance.

What I ran

Reviewed head 50d5e600ab95b53176ba83d56728d9abd30c5a76. Read the prepared description, commits, manifest, full diff, all four included changed files, the relevant execution-test registration in core/libs/prx/libSceAgcDriver/CMakeLists.txt, and F64RoundingDenormalModes.cpp for comparison. No build or test commands were run; author-reported test results are not independently verified.

Results

Check Result Note
Diff and changed source review passed Four changed files read
Execution-test registration passed CMake glob registers the new source
Build and runtime tests not run Results in the PR description only

Findings

Blocking

None.

Non-blocking

None.

Not verified

The hardware oracle measurements, reported lavapipe runs, and physical-console behavior were not independently confirmed. The excluded-file list was not available through the reader; the manifest shows all four changed files as included, and those files were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6014818627 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22384#pullrequestreview-6014818627). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T22:17:25Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation applies the described f64 denormal input and result flushing, and the included execution test checks measured cases within its stated tolerance. ## What I ran Reviewed head `50d5e600ab95b53176ba83d56728d9abd30c5a76`. Read the prepared description, commits, manifest, full diff, all four included changed files, the relevant execution-test registration in `core/libs/prx/libSceAgcDriver/CMakeLists.txt`, and `F64RoundingDenormalModes.cpp` for comparison. No build or test commands were run; author-reported test results are not independently verified. ## Results | Check | Result | Note | |---|---|---| | Diff and changed source review | passed | Four changed files read | | Execution-test registration | passed | CMake glob registers the new source | | Build and runtime tests | not run | Results in the PR description only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The hardware oracle measurements, reported lavapipe runs, and physical-console behavior were not independently confirmed. The excluded-file list was not available through the reader; the manifest shows all four changed files as included, and those files were read. ## To get this to a good state Nothing is required.
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!22384
No description provided.