feat(shader): follow IEEE_MODE in f16 and f64 min and max #2036

Merged
CouchRiv merged 1 commit from upstream-pr/2036 into main 2026-10-10 07:28:38 +00:00
CouchRiv commented 2026-10-09 05:35:48 +00:00 (Migrated from github.com)

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


What

The f16 and f64 min/max family ignored the shader's IEEE_MODE, so a NaN operand gave a different result than on the console:

v_min_f16(0x3c00, 0x7c01), IEEE=1:              hardware 0x7e01, main 0x3c00
v_min_f64(+0, 0x7ff0000000000001), IEEE=0:      hardware +0,     main 0x7ff8000000000001

#1826 and #1867 made the f32 forms and the unary instructions follow IEEE_MODE; TechnicalDebt still listed "the f16 and f64 min/max/med3" as following a single mode. This PR covers those forms: v_min_f16, v_max_f16, v_min3_f16, v_max3_f16, v_med3_f16, v_min_f64 and v_max_f64. RDNA2 has no f64 min3, max3 or med3.

The f16 forms now choose the NaN result on the f16 bits, like the packed f16 forms already do. The f64 forms keep their current lowering at IEEE=1 (it already matched) and get the IEEE=0 rule. The f32 path and ieeeMinMaxF32 are unchanged. Shaders with no known float mode follow IEEE=0, as elsewhere.

Measured with the hardware oracle on RDNA2. I used gfx1036 (Radeon 610M), not the gfx1035 of #1826; both are RDNA2. Every float control was set explicitly, at IEEE=0 and IEEE=1, with f32 denormals kept and flushed:

IEEE=0 IEEE=1
f16 a NaN operand returns the other operand unchanged, src0 when both are NaN as IEEE=0, but a signaling NaN operand returns that NaN quieted, src0 checked first; min3/max3 are two nested pairs, med3 is min3 when any operand is NaN (same rule as f32)
f64 src1 NaN: src0 unchanged, even a signaling NaN; otherwise src0 NaN: src1 a signaling NaN operand returns that NaN quieted (already the case on main)

Measured rows (gfx1036):

instruction operands IEEE hardware main
v_min_f16 0x0000, 0xfd23 1 0xff23 0x0000
v_med3_f16 0x0000, 0x0000, 0xfd23 1 0xff23 0x0000
v_min_f16 0x7c01, 0xfe55 0 0x7c01 0x7e01 RADV, 0x7fff NVIDIA
v_min_f64 0x7ff0000000000001, +0 0 +0 0x7ff8000000000001
v_max_f64 0x7ff0000000000001, 0x7ff8000000000000 0 0x7ff0000000000001 0x7ff8000000000001

The TechnicalDebt float mode line now lists these forms with their rule. It also records a separate gap: when f16/f64 denormals are flushed, the hardware flushes denormal inputs of these instructions (v_min_f16(0x0001, 0x8001) gives 0x8000), and this lowering does not, before or after this PR.

Which title needs it

No title yet. This completes the IEEE_MODE series (#1826, #1867) for the f16 and f64 min/max forms that TechnicalDebt still listed as following a single mode. Most titles use FLOAT_MODE 0xc0 with IEEE=0, where v_min_f64/v_max_f64 now return the non-NaN operand as the console does instead of a NaN, and f16 min/max keep src0's NaN bits when both operands are NaN. No title is known to hit either case.

Tested

CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV), Release build.

  • New agc_driver_f16_min_max_nan, laid out like agc_driver_f32_min_max_nan: 128 rows of ±0, ±1, ±inf, quiet and signaling NaNs with payloads and denormals, with garbage in the high halves, through the five f16 ops and -/|x| modifiers. Each row runs with no float mode and with IEEE=1, against tables captured on the oracle. It passes on both GPUs. On main it fails at row 94 v_min_f16 v10, v4, v5 is 0x00007e01, expected 0x00007c01.
  • agc_driver_f64_arithmetic held the IEEE=1 results (its table matches gfx1036 exactly at IEEE=1) but ran without a float mode. It now runs both ways, and its min/max columns at IEEE=0 come from the oracle.
  • Every row of the f16/f64 min/max cases from our oracle sweep (424 to 2,221 rows per op, with clamp and neg/abs variants) matches the hardware on both drivers in the four mode combinations (IEEE 0/1, DX10 clamp 0/1, f32 denormals kept/flushed).
  • The SDWA forms follow too: v_min/max_f16_sdwa with WORD_0/WORD_1 selects, clamp, mul:2 and neg/abs, 400 rows each in two IEEE=1 modes (DX10 clamp on and off), match the hardware on both drivers with this branch (main: 64 of 400 differ).
  • Full ctest on both GPUs, check_conventions.py, git diff --check.
  • With f16/f64 denormals flushed, these forms still differ from the hardware (measured, recorded in TechnicalDebt, see above).
  • Not tested: lavapipe, gfx1013 hardware, rounding other than to nearest even.

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. #2035 (mine) also edits F64Arithmetic.cpp and #2000 edits FloatInstructions.cpp; different functions, I'll rebase whichever lands second
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796448243 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2036). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-09T05:35:48Z. --- ### What The f16 and f64 min/max family ignored the shader's `IEEE_MODE`, so a NaN operand gave a different result than on the console: ``` v_min_f16(0x3c00, 0x7c01), IEEE=1: hardware 0x7e01, main 0x3c00 v_min_f64(+0, 0x7ff0000000000001), IEEE=0: hardware +0, main 0x7ff8000000000001 ``` #1826 and #1867 made the f32 forms and the unary instructions follow `IEEE_MODE`; TechnicalDebt still listed "the f16 and f64 min/max/med3" as following a single mode. This PR covers those forms: `v_min_f16`, `v_max_f16`, `v_min3_f16`, `v_max3_f16`, `v_med3_f16`, `v_min_f64` and `v_max_f64`. RDNA2 has no f64 min3, max3 or med3. The f16 forms now choose the NaN result on the f16 bits, like the packed f16 forms already do. The f64 forms keep their current lowering at IEEE=1 (it already matched) and get the IEEE=0 rule. The f32 path and `ieeeMinMaxF32` are unchanged. Shaders with no known float mode follow IEEE=0, as elsewhere. Measured with the [hardware oracle](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/HW_ORACLE.md) on RDNA2. I used gfx1036 (Radeon 610M), not the gfx1035 of #1826; both are RDNA2. Every float control was set explicitly, at IEEE=0 and IEEE=1, with f32 denormals kept and flushed: | | IEEE=0 | IEEE=1 | |---|---|---| | f16 | a NaN operand returns the other operand unchanged, src0 when both are NaN | as IEEE=0, but a signaling NaN operand returns that NaN quieted, src0 checked first; min3/max3 are two nested pairs, med3 is min3 when any operand is NaN (same rule as f32) | | f64 | src1 NaN: src0 unchanged, even a signaling NaN; otherwise src0 NaN: src1 | a signaling NaN operand returns that NaN quieted (already the case on `main`) | Measured rows (gfx1036): | instruction | operands | IEEE | hardware | `main` | |---|---|---|---|---| | `v_min_f16` | `0x0000`, `0xfd23` | 1 | `0xff23` | `0x0000` | | `v_med3_f16` | `0x0000`, `0x0000`, `0xfd23` | 1 | `0xff23` | `0x0000` | | `v_min_f16` | `0x7c01`, `0xfe55` | 0 | `0x7c01` | `0x7e01` RADV, `0x7fff` NVIDIA | | `v_min_f64` | `0x7ff0000000000001`, `+0` | 0 | `+0` | `0x7ff8000000000001` | | `v_max_f64` | `0x7ff0000000000001`, `0x7ff8000000000000` | 0 | `0x7ff0000000000001` | `0x7ff8000000000001` | The TechnicalDebt float mode line now lists these forms with their rule. It also records a separate gap: when f16/f64 denormals are flushed, the hardware flushes denormal inputs of these instructions (`v_min_f16(0x0001, 0x8001)` gives `0x8000`), and this lowering does not, before or after this PR. ### Which title needs it No title yet. This completes the `IEEE_MODE` series (#1826, #1867) for the f16 and f64 min/max forms that TechnicalDebt still listed as following a single mode. Most titles use `FLOAT_MODE` 0xc0 with IEEE=0, where `v_min_f64`/`v_max_f64` now return the non-NaN operand as the console does instead of a NaN, and f16 min/max keep src0's NaN bits when both operands are NaN. No title is known to hit either case. ### Tested CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV), Release build. - New `agc_driver_f16_min_max_nan`, laid out like `agc_driver_f32_min_max_nan`: 128 rows of ±0, ±1, ±inf, quiet and signaling NaNs with payloads and denormals, with garbage in the high halves, through the five f16 ops and `-`/`|x|` modifiers. Each row runs with no float mode and with IEEE=1, against tables captured on the oracle. It passes on both GPUs. On `main` it fails at `row 94 v_min_f16 v10, v4, v5 is 0x00007e01, expected 0x00007c01`. - `agc_driver_f64_arithmetic` held the IEEE=1 results (its table matches gfx1036 exactly at IEEE=1) but ran without a float mode. It now runs both ways, and its min/max columns at IEEE=0 come from the oracle. - Every row of the f16/f64 min/max cases from our oracle sweep (424 to 2,221 rows per op, with clamp and neg/abs variants) matches the hardware on both drivers in the four mode combinations (IEEE 0/1, DX10 clamp 0/1, f32 denormals kept/flushed). - The SDWA forms follow too: `v_min/max_f16_sdwa` with WORD_0/WORD_1 selects, clamp, `mul:2` and neg/abs, 400 rows each in two IEEE=1 modes (DX10 clamp on and off), match the hardware on both drivers with this branch (`main`: 64 of 400 differ). - Full ctest on both GPUs, `check_conventions.py`, `git diff --check`. - With f16/f64 denormals flushed, these forms still differ from the hardware (measured, recorded in TechnicalDebt, see above). - Not tested: lavapipe, gfx1013 hardware, rounding other than to nearest even. ### 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. #2035 (mine) also edits `F64Arithmetic.cpp` and #2000 edits `FloatInstructions.cpp`; different functions, I'll rebase whichever lands second - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-09 06:00:01 +00:00 (Migrated from github.com)

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


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:6075262822 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2036#issuecomment-6075262822). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T06:00:01Z. --- 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:46:20 +00:00 (Migrated from github.com)

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


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 b05a8048, merged onto main d70b8998 in one build with 38 other PRs that had no Windows run.

  • It conflicts with #2035, so it was tested on main without it.
  • This PR's tests pass: agc_driver_f16_min_max_nan, agc_driver_f64_arithmetic. None of them reported skipping a case.
  • Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084270153 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2036#issuecomment-6084270153). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:46:20Z. --- 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 `b05a8048`, merged onto `main` d70b8998 in one build with 38 other PRs that had no Windows run. - It conflicts with #2035, so it was tested on `main` without it. - This PR's tests pass: `agc_driver_f16_min_max_nan`, `agc_driver_f64_arithmetic`. None of them reported skipping a case. - Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-10 07:19:39 +00:00 (Migrated from github.com)

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


Rebased onto current main (only conflict: the shader float mode line in TechnicalDebt, merged with the lines that landed since; no code changes). agc_driver_f16_min_max_nan and agc_driver_f64_arithmetic pass on the rebased tree, and fail without the change. The earlier red linux/windows jobs were the agc_shader_fusion_tests missing spirv.hpp break on main, fixed by 37bc6f2e7. Merging once CI is green on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095056370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2036#issuecomment-6095056370). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:19:39Z. --- Rebased onto current `main` (only conflict: the shader float mode line in TechnicalDebt, merged with the lines that landed since; no code changes). `agc_driver_f16_min_max_nan` and `agc_driver_f64_arithmetic` pass on the rebased tree, and fail without the change. The earlier red `linux`/`windows` jobs were the `agc_shader_fusion_tests` missing `spirv.hpp` break on `main`, fixed by 37bc6f2e7. Merging once CI is green on the new head.
github-actions[bot] commented 2026-10-10 07:27:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T07:27:42Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2025 docs/dev/TechnicalDebt.md L338
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095116198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2036#issuecomment-6095116198). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T07:27:42Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2025 | `docs/dev/TechnicalDebt.md` [L338](https://github.com/boykopovar/AnyPS5/blob/51b8cef4f9e8129d7227ec08d5c714fc3868046b/docs/dev/TechnicalDebt.md#L338) | | |
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!2036
No description provided.