fix(shader): translate f32 compares in f32 denormal modes 1 and 2 #6007

Merged
zmeizy merged 1 commit from upstream-pr/6007 into main 2026-10-17 01:10:57 +00:00
zmeizy commented 2026-10-14 19:11:24 +00:00 (Migrated from github.com)

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


What

v_cmp_X_f32 and v_cmpx_X_f32 (X = eq, ge, gt, le, lg, lt, neq, nge, ngt, nle, nlg, nlt) 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 they flush their denormal inputs only when bit 0 of that field is clear: mode 1 keeps denormal inputs, as mode 3 does, and mode 2 flushes them, as mode 0 does. f32DenormalFlushFor now returns that input flush for the compares, and the existing paths do the rest: the sign-magnitude integer compare for kept denormals, and the flush before the compare otherwise. No driver denormal behaviour is involved.

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: 484 operand pairs over 22 values: ±0, ±2^-149, ±2^-148, ±0x00400000, ±0x007fffff, ±2^-126, 0x00800001, ±1, 0x7f7fffff, ±infinity, the quiet NaNs 0x7fc00000 and 0xffc00000, and the signaling NaNs 0x7f800001 and 0xff800001.
  • Instructions: all 12 conditions, in VOPC form, writing VCC (v_cmp) and EXEC (v_cmpx).
  • Float modes: ieee 0 and 1, each with denorm32 0, 1, 2 and 3; dx10_clamp 1, denorm16 3, round32 0, round16 0, fp16_overflow 0.
  • Model: inputs are flushed exactly when bit 0 of denorm32 is clear. It matches all 5,808 results in each mode and form; "never flush" and "always flush" each miss 704 results per mode.

The measured masks for modes 1 and 2 are the "kept" and "flushed" masks that VCmpF32Denormals already pins for modes 3 and 0 (measured on gfx1036).

A new entry in docs/dev/debt/shader.md records the measurement. The general "f32 denormals" entry, which says denormal modes 1 and 2 throw for the other instructions, is left unchanged because #5782 edits that line.

Tested

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

  • agc_driver_vcmp_f32_denormal_modes (new) pins the measured results for the 16 x 16 operand pairs of VCmpF32Denormals, for v_cmp and v_cmpx in denormal modes 1 and 2 at IEEE 0 and 1. It compiles 8 programs.
    • On main it fails (mode 1 throws). With the change it passes in 0.1 s.
  • All measured rows (484 pairs x 12 conditions x 2 forms) match the recompiler output with the change in all 8 modes. Before the change, modes 0 and 3 already matched and modes 1 and 2 threw.
  • agc_driver_vcmp_f32_denormals, agc_driver_f32_compare_constant, agc_driver_f32_denormal_flush, agc_driver_vopc_compare, agc_driver_vopc_compare_table, agc_driver_vopc_compare_f64 and agc_driver_vop3_compare_modifiers pass.
  • Measurement data attached: anyps5-gpu-probes-v2-gfx1030.json.gz (probe cmp_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:4863128411 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6007). Originally posted by [zmeizy](https://github.com/zmeizy) on 2026-10-14T19:11:24Z. --- ### What `v_cmp_X_f32` and `v_cmpx_X_f32` (X = eq, ge, gt, le, lg, lt, neq, nge, ngt, nle, nlg, nlt) 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 they flush their denormal inputs only when bit 0 of that field is clear: mode 1 keeps denormal inputs, as mode 3 does, and mode 2 flushes them, as mode 0 does. `f32DenormalFlushFor` now returns that input flush for the compares, and the existing paths do the rest: the sign-magnitude integer compare for kept denormals, and the flush before the compare otherwise. No driver denormal behaviour is involved. 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: 484 operand pairs over 22 values: ±0, ±2^-149, ±2^-148, ±0x00400000, ±0x007fffff, ±2^-126, 0x00800001, ±1, 0x7f7fffff, ±infinity, the quiet NaNs 0x7fc00000 and 0xffc00000, and the signaling NaNs 0x7f800001 and 0xff800001. - Instructions: all 12 conditions, in VOPC form, writing VCC (`v_cmp`) and EXEC (`v_cmpx`). - Float modes: ieee 0 and 1, each with denorm32 0, 1, 2 and 3; dx10_clamp 1, denorm16 3, round32 0, round16 0, fp16_overflow 0. - Model: inputs are flushed exactly when bit 0 of denorm32 is clear. It matches all 5,808 results in each mode and form; "never flush" and "always flush" each miss 704 results per mode. The measured masks for modes 1 and 2 are the "kept" and "flushed" masks that `VCmpF32Denormals` already pins for modes 3 and 0 (measured on gfx1036). A new entry in `docs/dev/debt/shader.md` records the measurement. The general "f32 denormals" entry, which says denormal modes 1 and 2 throw for the other instructions, is left unchanged because #5782 edits that line. ### Tested Ubuntu 24.04 (WSL2), GCC 13.3, lavapipe, on `main` `73efd940`. - `agc_driver_vcmp_f32_denormal_modes` (new) pins the measured results for the 16 x 16 operand pairs of `VCmpF32Denormals`, for `v_cmp` and `v_cmpx` in denormal modes 1 and 2 at IEEE 0 and 1. It compiles 8 programs. - On `main` it fails (mode 1 throws). With the change it passes in 0.1 s. - All measured rows (484 pairs x 12 conditions x 2 forms) match the recompiler output with the change in all 8 modes. Before the change, modes 0 and 3 already matched and modes 1 and 2 threw. - `agc_driver_vcmp_f32_denormals`, `agc_driver_f32_compare_constant`, `agc_driver_f32_denormal_flush`, `agc_driver_vopc_compare`, `agc_driver_vopc_compare_table`, `agc_driver_vopc_compare_f64` and `agc_driver_vop3_compare_modifiers` pass. - Measurement data attached: `anyps5-gpu-probes-v2-gfx1030.json.gz` (probe `cmp_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/33452781/anyps5-gpu-probes-v2-gfx1030.json.gz)
Dextroid17 commented 2026-10-15 01:02:51 +00:00 (Migrated from github.com)

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


Ran this on PR head 659eddb10 (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_vcmp_f32_denormal_modes_tests on the PR: 3 of 3 passed ("v_cmp and v_cmpx f32 denormal mode 1 and 2 tests passed").
  • Mutation check: kept the PR's test, put back the merge-base Translation/src/VectorInstructions.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.

Overlap: #6009, #6010 and #5782 edit the same switch in f32DenormalFlushFor, and #5941 edits the same function just after it. git merge-tree of this PR with #6009 is clean, so this may only need a re-check, not a rebase.

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

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6181960766 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6007#issuecomment-6181960766). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-15T01:02:51Z. --- Ran this on PR head 659eddb10 (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_vcmp_f32_denormal_modes_tests on the PR: 3 of 3 passed ("v_cmp and v_cmpx f32 denormal mode 1 and 2 tests passed"). - Mutation check: kept the PR's test, put back the merge-base Translation/src/VectorInstructions.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. Overlap: #6009, #6010 and #5782 edit the same switch in f32DenormalFlushFor, and #5941 edits the same function just after it. git merge-tree of this PR with #6009 is clean, so this may only need a re-check, not a rebase. Not checked: other GPUs, Windows, or any title. AI-assisted: yes
github-actions[bot] commented 2026-10-15 12:13:08 +00:00 (Migrated from github.com)

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


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 4048 docs/dev/debt/shader.md
PR 5021 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 6503 core/shader/recompiler/Translation/src/VectorInstructions.cpp
PR 6612 docs/dev/debt/shader.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191766726 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6007#issuecomment-6191766726). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:13:08Z. --- <!-- 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 4048](https://www.github.com/boykopovar/AnyPS5/pull/4048) | `docs/dev/debt/shader.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `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 6503](https://www.github.com/boykopovar/AnyPS5/pull/6503) | `core/shader/recompiler/Translation/src/VectorInstructions.cpp` | | [PR 6612](https://www.github.com/boykopovar/AnyPS5/pull/6612) | `docs/dev/debt/shader.md` |
adriadam10 commented 2026-10-16 20:55:18 +00:00 (Migrated from github.com)

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


Measured v_cmp_X_f32 and v_cmpx_X_f32 on our RDNA2 oracle (gfx1035) over 576 operand pairs (the test's 16 values plus 8 more denormal, minimum-normal, largest-finite and NaN edges), all 12 conditions, IEEE 0/1 and f32 denormal modes 0-3: inputs are flushed exactly when bit 0 of the field is clear, and the test's tables match the hardware bit for bit. Build, the agc tests on RADV and lavapipe, and the negative check (the new test fails without the change) are green; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224522987 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6007#issuecomment-6224522987). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T20:55:18Z. --- Measured `v_cmp_X_f32` and `v_cmpx_X_f32` on our RDNA2 oracle (gfx1035) over 576 operand pairs (the test's 16 values plus 8 more denormal, minimum-normal, largest-finite and NaN edges), all 12 conditions, IEEE 0/1 and f32 denormal modes 0-3: inputs are flushed exactly when bit 0 of the field is clear, and the test's tables match the hardware bit for bit. Build, the agc tests on RADV and lavapipe, and the negative check (the new test fails without the change) are green; 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!6007
No description provided.