fix(shader): flush f16 min/max denormal inputs #2876

Merged
CouchRiv merged 2 commits from upstream-pr/2876 into main 2026-10-10 23:10:52 +00:00
CouchRiv commented 2026-10-10 17:16:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-10T17:16:59Z.


What

v_min_f16 and v_max_f16 keep denormal inputs when the shader asks to flush them, so their selected result differs from RDNA2. #2036 fixed their IEEE NaN handling but left this gap in TechnicalDebt.

The binary forms now flush each half input to its signed zero when denorm16 bit 0 is clear. Output flushing alone preserves the selected input. This applies to the comparison value and the bits returned for a NaN fallback. The second commit applies the same rule to v_min3_f16, v_max3_f16 and v_med3_f16, which share minMaxF16: on gfx1036 they flush the same way (8,024 operand triples in each of the eight IEEE 0/1 x denorm16 0-3 modes, every row matching the rule, changes only at denorm16 0 and 2). The debt entry retains the f64 gap.

Measured with the hardware oracle on gfx1036 (Radeon 610M), at IEEE=0/1 and denorm16=0/1/2/3. Other controls: DX10 clamp enabled, f32 denormals flushed, both rounding fields nearest even, FP16_OVFL=0. These example half results are at IEEE=1:

Instruction / operands denorm16 Hardware and fix main
min 0x3c01, 0x03ff 0 0x0000 0x03ff
max 0xbc01, 0x03ff 2 0x0000 0x03ff
min 0x3c01, 0x03ff 1 0x03ff 0x03ff

Tested

CachyOS Linux, Release build; RTX 4070 Ti (NVIDIA), Radeon 610M (RADV), and lavapipe, including the pinned CI driver.

  • Extended agc_driver_f16_min_max_nan: 32 measured operand pairs, eight IEEE/denormal modes, plain and neg/abs forms, and SDWA WORD_0/WORD_1 sources. Includes signed zeros, NaNs, denormals and minimum normals. Main fails with 0x03ff instead of 0x0000; the fix passes on all three drivers. Original NaN/ternary tables still pass. The ternary rows fail on the first commit (v_min3_f16 v12, v4, v5, v6 is 0x000003ff, expected 0x00000000) and pass with the second. Runtime below 1.2 s.
  • Build, the execution test plus shader checks (22/22 per driver), check_conventions.py, and git diff --check pass.
  • Not tested: gfx1013 hardware, Windows, titles, or a replay of every sweep row. Packed f16 and f64 lowering are unchanged; backend half conversion is unchanged.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813044705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2876). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-10T17:16:59Z. --- ### What `v_min_f16` and `v_max_f16` keep denormal inputs when the shader asks to flush them, so their selected result differs from RDNA2. #2036 fixed their IEEE NaN handling but left this gap in TechnicalDebt. The binary forms now flush each half input to its signed zero when denorm16 bit 0 is clear. Output flushing alone preserves the selected input. This applies to the comparison value and the bits returned for a NaN fallback. The second commit applies the same rule to `v_min3_f16`, `v_max3_f16` and `v_med3_f16`, which share `minMaxF16`: on gfx1036 they flush the same way (8,024 operand triples in each of the eight IEEE 0/1 x denorm16 0-3 modes, every row matching the rule, changes only at denorm16 0 and 2). The debt entry retains the f64 gap. Measured with the [hardware oracle](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/HW_ORACLE.md) on gfx1036 (Radeon 610M), at IEEE=0/1 and denorm16=0/1/2/3. Other controls: DX10 clamp enabled, f32 denormals flushed, both rounding fields nearest even, FP16_OVFL=0. These example half results are at IEEE=1: | Instruction / operands | denorm16 | Hardware and fix | `main` | |---|---:|---|---| | min `0x3c01, 0x03ff` | 0 | `0x0000` | `0x03ff` | | max `0xbc01, 0x03ff` | 2 | `0x0000` | `0x03ff` | | min `0x3c01, 0x03ff` | 1 | `0x03ff` | `0x03ff` | ### Tested CachyOS Linux, Release build; RTX 4070 Ti (NVIDIA), Radeon 610M (RADV), and lavapipe, including the pinned CI driver. - Extended `agc_driver_f16_min_max_nan`: 32 measured operand pairs, eight IEEE/denormal modes, plain and neg/abs forms, and SDWA WORD_0/WORD_1 sources. Includes signed zeros, NaNs, denormals and minimum normals. Main fails with `0x03ff` instead of `0x0000`; the fix passes on all three drivers. Original NaN/ternary tables still pass. The ternary rows fail on the first commit (`v_min3_f16 v12, v4, v5, v6 is 0x000003ff, expected 0x00000000`) and pass with the second. Runtime below 1.2 s. - Build, the execution test plus shader checks (22/22 per driver), `check_conventions.py`, and `git diff --check` pass. - Not tested: gfx1013 hardware, Windows, titles, or a replay of every sweep row. Packed f16 and f64 lowering are unchanged; backend half conversion is unchanged. ### 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
adriadam10 commented 2026-10-10 23:10:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:10:50Z.


Checked on the HW oracle (gfx1035): 2048 operand triples (signed zeros, denormals, min normals, ±1, ±inf, quiet/signaling NaNs) at IEEE=0/1 × denorm16 0–3 for v_min/max/min3/max3/med3_f16, neg/abs, SDWA and clamp all match "flush inputs when denorm16 bit 0 is clear". Also ran the AGC driver ctest scope (agc_driver_f16_min_max_nan fails without the change). Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103184133 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2876#issuecomment-6103184133). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:10:50Z. --- Checked on the HW oracle (gfx1035): 2048 operand triples (signed zeros, denormals, min normals, ±1, ±inf, quiet/signaling NaNs) at IEEE=0/1 × denorm16 0–3 for `v_min/max/min3/max3/med3_f16`, neg/abs, SDWA and clamp all match "flush inputs when denorm16 bit 0 is clear". Also ran the AGC driver ctest scope (`agc_driver_f16_min_max_nan` 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!2876
No description provided.