fix(shader): keep v_exp_f32 at or above the smallest normal for inputs from -126 #1571

Merged
Zheorgyan merged 1 commit from upstream-pr/1571 into main 2026-10-10 01:11:42 +00:00
Zheorgyan commented 2026-10-08 12:59:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Zheorgyan on 2026-10-08T12:59:32Z.


What

agc_driver_vop1_float_unary fails on an Apple M1 with exp_f32 of -126 giving 0 where the test expects 0x00800000. the M1 GPU's exp2 comes out about 2 ULP low even for whole numbers (2^-120 gives 0x037ffffe), checked in plain Metal with fast math on and off. at -126 that lands just under the normal range, and Metal flushes it to 0

for x >= -126 the exact result is at least 2^-126, so the FPExp2 specials now take a UMax32 of the result bits with 0x00800000 before the existing underflow pick. x < -126, -inf and NaN keep their current results, since the underflow pick and the NaN handling come after it. on a host whose exp2 doesn't undershoot, the max changes nothing

Tested

  • macOS 15.6.1 on an M1 Pro, MoltenVK from Vulkan SDK 1.4.363.0, on top of mugurc's macos-port branch. agc_driver_vop1_float_unary fails before and passes after, and the rest of the suite is unchanged
  • Linux, Ubuntu 24.04 in Docker, GCC 14.2, lavapipe. builds, 452 tests, and the 26 that fail fail the same way on main in this container, which is x86-64 emulated on Apple Silicon. agc_driver_vop1_float_unary is one of them, so the changed path isn't exercised there
  • tools/check_conventions.py passes

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:4787166781 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1571). Originally posted by [Zheorgyan](https://github.com/Zheorgyan) on 2026-10-08T12:59:32Z. --- ### What `agc_driver_vop1_float_unary` fails on an Apple M1 with `exp_f32` of -126 giving 0 where the test expects `0x00800000`. the M1 GPU's `exp2` comes out about 2 ULP low even for whole numbers (2^-120 gives `0x037ffffe`), checked in plain Metal with fast math on and off. at -126 that lands just under the normal range, and Metal flushes it to 0 for x >= -126 the exact result is at least 2^-126, so the FPExp2 specials now take a `UMax32` of the result bits with `0x00800000` before the existing underflow pick. x < -126, -inf and NaN keep their current results, since the underflow pick and the NaN handling come after it. on a host whose `exp2` doesn't undershoot, the max changes nothing ### Tested - macOS 15.6.1 on an M1 Pro, MoltenVK from Vulkan SDK 1.4.363.0, on top of mugurc's `macos-port` branch. `agc_driver_vop1_float_unary` fails before and passes after, and the rest of the suite is unchanged - Linux, Ubuntu 24.04 in Docker, GCC 14.2, lavapipe. builds, 452 tests, and the 26 that fail fail the same way on main in this container, which is x86-64 emulated on Apple Silicon. `agc_driver_vop1_float_unary` is one of them, so the changed path isn't exercised there - `tools/check_conventions.py` passes ### 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) - [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
yahya308 commented 2026-10-08 15:28:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yahya308 on 2026-10-08T15:28:57Z.


Tested on top of main 9e2ffe0d, Windows 11, MinGW-w64 GCC 16.2.0, full ctest with ANYPS5_REQUIRE_VULKAN=1 --repeat until-fail:3, NVIDIA RTX 4070 Laptop (32.0.16.1074) and AMD Radeon 780M (32.0.31041.1004). vopc_compare_table fails on the 780M on main too (#825, #1473).

Head 847bd9f4: no change from main on either GPU. vop1_float_unary passes on both, so the max changes nothing on these hosts, as described.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6063311244 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1571#issuecomment-6063311244). Originally posted by [yahya308](https://github.com/yahya308) on 2026-10-08T15:28:57Z. --- Tested on top of main `9e2ffe0d`, Windows 11, MinGW-w64 GCC 16.2.0, full ctest with `ANYPS5_REQUIRE_VULKAN=1 --repeat until-fail:3`, NVIDIA RTX 4070 Laptop (32.0.16.1074) and AMD Radeon 780M (32.0.31041.1004). `vopc_compare_table` fails on the 780M on main too (#825, #1473). Head `847bd9f4`: no change from main on either GPU. `vop1_float_unary` passes on both, so the max changes nothing on these hosts, as described. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-10 01:11:39 +00:00 (Migrated from github.com)

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


Checked v_exp_f32 on the HW oracle (IEEE=0, DENORM=0): -126 gives 0x00800000, values just above stay ≥ that and are monotonic, -126.0000076 and -inf give 0, +inf/NaN unchanged. The UMax32 therefore changes nothing on real hardware and only fixes hosts whose exp2 undershoots; it sits before the existing underflow pick, so x < -126 still returns 0. agc_driver_vop1_float_unary passes here. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092032069 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1571#issuecomment-6092032069). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T01:11:39Z. --- Checked `v_exp_f32` on the HW oracle (IEEE=0, DENORM=0): -126 gives `0x00800000`, values just above stay ≥ that and are monotonic, -126.0000076 and -inf give 0, +inf/NaN unchanged. The `UMax32` therefore changes nothing on real hardware and only fixes hosts whose `exp2` undershoots; it sits before the existing underflow pick, so x < -126 still returns 0. `agc_driver_vop1_float_unary` passes here. Merging once CI is green.
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!1571
No description provided.