fix(shader): translate v_ldexp_f32 in f32 denormal modes 1 and 2 #6008

Merged
zmeizy merged 1 commit from upstream-pr/6008 into main 2026-10-17 02:14:46 +00:00
zmeizy commented 2026-10-14 19:12:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zmeizy on 2026-10-14T19:12:05Z.


What

v_ldexp_f32 threw f32 denormal mode N ... is not implemented in shaders whose FLOAT_MODE f32 denormal field (bits 5:4) is 1 or 2. On RDNA2 it follows the field like the kept and flushed modes do:

  • Mode 1 (keep inputs, flush outputs) keeps a subnormal input and flushes a result below 2^-126 to a zero of its sign, in every f32 round mode. That includes a result that would round up to 2^-126 at subnormal precision: 0x3fffffff scaled by 2^-127 gives +0.
  • Mode 2 (flush inputs, keep outputs) flushes a subnormal input to a zero of its sign, and rounds a subnormal result in the f32 round mode of FLOAT_MODE, as mode 3 does.

vLdexpF32 now takes the subnormal-aware path of mode 3 for modes 1 and 2 too. Mode 1 selects the signed zero instead of the rounded subnormal result, and mode 2 treats a subnormal input as zero. Modes 0 and 3 are unchanged.

Source of semantics: measured with the hardware oracle's kernel template on gfx1030 (AMD Radeon RX 6800, AMD Windows driver 32.0.21045.5002 through its HIP runtime amdhip64_6.dll):

  • Rows: 10,260 rows, 54 inputs scaled by 190 exponents.
    • Inputs, both signs: zeros, subnormals from 2^-149 to 0x007fffff, normals near 2^-126 and 1.0, 0x7f000000, 0x7f7fffff, infinities, a quiet and a signaling NaN.
    • Exponents: -280 to -241, -160 to -101, -40 to 40, 200, 254 to 256, 300, ±1000, -2^31 and 2^31-1.
  • Instructions: v_ldexp_f32, and v_ldexp_f32 ... clamp.
  • Float modes: ieee 0 and 1, each with denorm32 0 to 3 and round32 0 to 3 (32 modes); dx10_clamp 1, denorm16 3, round16 0, fp16_overflow 0.
  • Model: the exact product rounded to f32, with the flushes above. It matches every row in all 32 modes. A result's exact value is already a 24-bit significand, so tininess before and after rounding are the same here. The clamp results are the clamped plain results.

A new entry in docs/dev/debt/shader.md records it. The general "f32 denormals" entry is left unchanged because #5782 edits that line.

Tested

Ubuntu 24.04 (WSL2), GCC 13.3, lavapipe, on main 73efd940.

  • agc_driver_ldexp_f32_denormal_modes (new) pins 39 measured rows, with an expected value for each of the 16 combinations of mode (1, 2), round mode (0 to 3) and IEEE (0, 1). The rows cover denormal inputs with exponent 0, denormal to normal and back, the ties at 2^-150, the 0x3fffffff * 2^-127 case, overflow, the extreme exponents, zeros, infinities and a quiet NaN.
    • On main it fails (mode 1 throws). With the change it passes in 0.1 s.
  • All 328,320 measured rows (10,260 x 32 modes, plain and clamp) match the recompiler output with the change. Before the change, modes 0 and 3 already matched and modes 1 and 2 threw.
  • agc_driver_ldexp_f32_denormal, agc_driver_f32_denormal_flush, agc_driver_nan_quieting and agc_driver_vop3_pack_ldexp pass.
  • Measurement data attached: anyps5-gpu-probes-v2-gfx1030.json.gz (probe ldexp_f32_denormal_modes).

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 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
  • Unblocks: none
  • GPUs tested: lavapipe (Mesa 25.2.8, LLVM 20.1.2) on Ubuntu 24.04 under WSL2; semantics measured on AMD Radeon RX 6800 (gfx1030, Windows driver 32.0.21045.5002)
  • AI-assisted: yes

🤖 Generated with Claude Code
anyps5-gpu-probes-v2-gfx1030.json.gz

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4863138109 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6008). Originally posted by [zmeizy](https://github.com/zmeizy) on 2026-10-14T19:12:05Z. --- ### What `v_ldexp_f32` threw `f32 denormal mode N ... is not implemented` in shaders whose `FLOAT_MODE` f32 denormal field (bits 5:4) is 1 or 2. On RDNA2 it follows the field like the kept and flushed modes do: - **Mode 1** (keep inputs, flush outputs) keeps a subnormal input and flushes a result below 2^-126 to a zero of its sign, in every f32 round mode. That includes a result that would round up to 2^-126 at subnormal precision: `0x3fffffff` scaled by 2^-127 gives +0. - **Mode 2** (flush inputs, keep outputs) flushes a subnormal input to a zero of its sign, and rounds a subnormal result in the f32 round mode of `FLOAT_MODE`, as mode 3 does. `vLdexpF32` now takes the subnormal-aware path of mode 3 for modes 1 and 2 too. Mode 1 selects the signed zero instead of the rounded subnormal result, and mode 2 treats a subnormal input as zero. Modes 0 and 3 are unchanged. Source of semantics: measured with the hardware oracle's kernel template on gfx1030 (AMD Radeon RX 6800, AMD Windows driver 32.0.21045.5002 through its HIP runtime `amdhip64_6.dll`): - Rows: 10,260 rows, 54 inputs scaled by 190 exponents. - Inputs, both signs: zeros, subnormals from 2^-149 to 0x007fffff, normals near 2^-126 and 1.0, 0x7f000000, 0x7f7fffff, infinities, a quiet and a signaling NaN. - Exponents: -280 to -241, -160 to -101, -40 to 40, 200, 254 to 256, 300, ±1000, -2^31 and 2^31-1. - Instructions: `v_ldexp_f32`, and `v_ldexp_f32 ... clamp`. - Float modes: ieee 0 and 1, each with denorm32 0 to 3 and round32 0 to 3 (32 modes); dx10_clamp 1, denorm16 3, round16 0, fp16_overflow 0. - Model: the exact product rounded to f32, with the flushes above. It matches every row in all 32 modes. A result's exact value is already a 24-bit significand, so tininess before and after rounding are the same here. The clamp results are the clamped plain results. A new entry in `docs/dev/debt/shader.md` records it. The general "f32 denormals" entry is left unchanged because #5782 edits that line. ### Tested Ubuntu 24.04 (WSL2), GCC 13.3, lavapipe, on `main` `73efd940`. - `agc_driver_ldexp_f32_denormal_modes` (new) pins 39 measured rows, with an expected value for each of the 16 combinations of mode (1, 2), round mode (0 to 3) and IEEE (0, 1). The rows cover denormal inputs with exponent 0, denormal to normal and back, the ties at 2^-150, the 0x3fffffff * 2^-127 case, overflow, the extreme exponents, zeros, infinities and a quiet NaN. - On `main` it fails (mode 1 throws). With the change it passes in 0.1 s. - All 328,320 measured rows (10,260 x 32 modes, plain and `clamp`) match the recompiler output with the change. Before the change, modes 0 and 3 already matched and modes 1 and 2 threw. - `agc_driver_ldexp_f32_denormal`, `agc_driver_f32_denormal_flush`, `agc_driver_nan_quieting` and `agc_driver_vop3_pack_ldexp` pass. - Measurement data attached: `anyps5-gpu-probes-v2-gfx1030.json.gz` (probe `ldexp_f32_denormal_modes`). ### 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 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] Unblocks: none - [x] GPUs tested: lavapipe (Mesa 25.2.8, LLVM 20.1.2) on Ubuntu 24.04 under WSL2; semantics measured on AMD Radeon RX 6800 (gfx1030, Windows driver 32.0.21045.5002) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) [anyps5-gpu-probes-v2-gfx1030.json.gz](https://github.com/user-attachments/files/33452950/anyps5-gpu-probes-v2-gfx1030.json.gz)
Dextroid17 commented 2026-10-15 01:02:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-15T01:02:53Z.


Ran this on PR head f11382faf (merge base 73efd9407, 290 commits behind main ab9a47684).

Setup: PR head checked out as-is (not rebased), default CMake build (CMAKE_BUILD_TYPE empty, unoptimized), Linux, ANYPS5_NO_SHADER_CACHE=1, GPU test run on lavapipe (Mesa 26.2.4 llvmpipe, LLVM 23.1.1).

  • agc_driver_ldexp_f32_denormal_modes_tests on the PR: 3 of 3 passed ("ldexp f32 denormal mode 1 and 2 tests passed").
  • Mutation check: kept the PR's test, put back the merge-base Translation/src/FloatInstructions.cpp, rebuilt, ran 3 times: 3 of 3 failed. The recompiler stopped with "ShaderRecompiler::Recompile: f32 denormal mode 1 at pc 20 is not implemented".

So the test does reach modes 1 and 2. Without the change the recompiler refuses mode 1 outright, so this check does not show whether the asserted values would catch a wrong translation. The expected values come from the PR's RDNA2 measurements; llvmpipe does not confirm hardware behaviour.

Not checked: other GPUs, Windows, or any title.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6181961063 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6008#issuecomment-6181961063). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-15T01:02:53Z. --- Ran this on PR head f11382faf (merge base 73efd9407, 290 commits behind main ab9a47684). Setup: PR head checked out as-is (not rebased), default CMake build (CMAKE_BUILD_TYPE empty, unoptimized), Linux, ANYPS5_NO_SHADER_CACHE=1, GPU test run on lavapipe (Mesa 26.2.4 llvmpipe, LLVM 23.1.1). - agc_driver_ldexp_f32_denormal_modes_tests on the PR: 3 of 3 passed ("ldexp f32 denormal mode 1 and 2 tests passed"). - Mutation check: kept the PR's test, put back the merge-base Translation/src/FloatInstructions.cpp, rebuilt, ran 3 times: 3 of 3 failed. The recompiler stopped with "ShaderRecompiler::Recompile: f32 denormal mode 1 at pc 20 is not implemented". So the test does reach modes 1 and 2. Without the change the recompiler refuses mode 1 outright, so this check does not show whether the asserted values would catch a wrong translation. The expected values come from the PR's RDNA2 measurements; llvmpipe does not confirm hardware behaviour. Not checked: other GPUs, Windows, or any title. AI-assisted: yes
github-actions[bot] commented 2026-10-15 12:13:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:13:10Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4072 core/shader/recompiler/Translation/src/FloatInstructions.cpp
PR 5021 core/shader/recompiler/Translation/src/FloatInstructions.cpp
docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5500 docs/dev/debt/shader.md
PR 6222 docs/dev/debt/shader.md
PR 6235 docs/dev/debt/shader.md
PR 6412 docs/dev/debt/shader.md
PR 6612 docs/dev/debt/shader.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191767303 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6008#issuecomment-6191767303). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:13:10Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 4072](https://www.github.com/boykopovar/AnyPS5/pull/4072) | `core/shader/recompiler/Translation/src/FloatInstructions.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/shader/recompiler/Translation/src/FloatInstructions.cpp`<br>`docs/dev/debt/shader.md` | | [PR 5371](https://www.github.com/boykopovar/AnyPS5/pull/5371) | `docs/dev/debt/shader.md` | | [PR 5426](https://www.github.com/boykopovar/AnyPS5/pull/5426) | `docs/dev/debt/shader.md` | | [PR 5500](https://www.github.com/boykopovar/AnyPS5/pull/5500) | `docs/dev/debt/shader.md` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `docs/dev/debt/shader.md` | | [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) | `docs/dev/debt/shader.md` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `docs/dev/debt/shader.md` | | [PR 6612](https://www.github.com/boykopovar/AnyPS5/pull/6612) | `docs/dev/debt/shader.md` |
adriadam10 commented 2026-10-16 20:58:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T20:58:44Z.


Measured v_ldexp_f32 (plain and clamp) on gfx1035 over 2679 value/exponent rows, including the test's 39, in all 32 modes: f32 denormal modes 0 to 3, IEEE 0 and 1, f32 round modes 0 to 3. The recompiler output with this change matches the hardware bit for bit in all 171,456 cells, the test's expected values match the hardware, and the test fails without the change. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224575554 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6008#issuecomment-6224575554). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T20:58:44Z. --- Measured `v_ldexp_f32` (plain and `clamp`) on gfx1035 over 2679 value/exponent rows, including the test's 39, in all 32 modes: f32 denormal modes 0 to 3, IEEE 0 and 1, f32 round modes 0 to 3. The recompiler output with this change matches the hardware bit for bit in all 171,456 cells, the test's expected values match the hardware, and the test fails without the change. Merging.
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!6008
No description provided.