fix(libc): preserve frexpf decomposition and exception behavior #11074

Merged
JJenkx merged 1 commit from upstream-pr/11074 into main 2026-10-27 08:18:34 +00:00
JJenkx commented 2026-10-25 17:00:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-25T17:00:57Z.


What

The host std::frexp(float) changes signaling-NaN payloads and flags, and ignores the bundled implementation's subnormal scaling and DAZ behavior. frexpf now decomposes the exponent bits, scales only subnormal inputs by2^25, and returns zeros/infinities/NaNs unchanged with exponent0. Normal inputs stay independent of the rounding mode. The implementation is derived from the bundled PPSA03766 function; there is no new export or dependency.

Tested

Linux / GCC16.2.1 / Release, head 7cfbb837c43378e5b2138b1a2cbaee16bdd0d1c5 on main 5949d8bf924b0f3b01c1c4e5e82b2e8ddabd9b97.

  • Three focused CTest groups (guest_math, guest_math_exact, guest_dinkumware_internals), each passing3 repeats before and after the negative control.
  • New960-call regression:20 boundary/special inputs ×4 rounding modes ×4 DAZ/FTZ combinations ×3 sticky-flag seeds. Checks exact result bits, exponent, MXCSR flags/control and guest errno. This includes both signs of zero, subnormals, normal boundaries, maximum finite values, infinity and signaling/quiet NaNs.
  • Broader5633-input differential: 270,384 calls per arm, independently loading the two supplied bundled modules, the candidate, and current-main's function. The candidate matches PPSA03766 in every captured field (result/exponent, SSE and x87 flags/control, errno). Current-main differs in1248 rows, including792 result-bit and408 exponent observations. Inputs combine deterministic random32-bit patterns and every exponent boundary.
  • Both bundled copies agree on all result bits and exponents. PPSA07923's compiler unconditionally scales finite inputs, adding overflow/inexact flags on26,112 large-value rows. The change deliberately follows PPSA03766's conditional scaling; this SDK flag variant and unmasked traps are recorded as debt.
  • Replacing only the new function with current-main's std::frexp fails the committed guest_math regression at the first subnormal's flags. Restoring the implementation passes all repeated groups and produces a byte-identical libc library.

Conventions and whitespace pass. Clean local merge-tree against newer main 6b1f419fefbde12c0fdad3299a294487dc427e44; exact built/tested base remains5949. The overlap scan's45 shared-file cases have no changed frexp/frexpf implementation or callers; #8937 and #10953 have independent additive debt entries at the same location. Retain both rows when reconciling; no functional dependency. Combined branches were not runtime-tested.

Source patch, numeric reference observations, full matrices, regression/negative-control logs and restoration proof — SHA-256 7a75885add6e2691d06ad91fc4d2784fbf54b7a185c1050ce0c2856b634de5e6. The downloaded asset was hash-verified. No proprietary module binaries, extracted instructions or game assets are included.

Windows/macOS, unmasked exceptions and native titles were not tested. No game-unblock, FPS or new-function-count claim.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (CPU libc only)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5006774327 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11074). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-25T17:00:57Z. --- ### What The host `std::frexp(float)` changes signaling-NaN payloads and flags, and ignores the bundled implementation's subnormal scaling and DAZ behavior. `frexpf` now decomposes the exponent bits, scales only subnormal inputs by2^25, and returns zeros/infinities/NaNs unchanged with exponent0. Normal inputs stay independent of the rounding mode. The implementation is derived from the bundled PPSA03766 function; there is no new export or dependency. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux / GCC16.2.1 / Release, head `7cfbb837c43378e5b2138b1a2cbaee16bdd0d1c5` on main `5949d8bf924b0f3b01c1c4e5e82b2e8ddabd9b97`. - Three focused CTest groups (`guest_math`, `guest_math_exact`, `guest_dinkumware_internals`), each passing3 repeats before and after the negative control. - New960-call regression:20 boundary/special inputs ×4 rounding modes ×4 DAZ/FTZ combinations ×3 sticky-flag seeds. Checks exact result bits, exponent, MXCSR flags/control and guest errno. This includes both signs of zero, subnormals, normal boundaries, maximum finite values, infinity and signaling/quiet NaNs. - Broader5633-input differential: **270,384 calls per arm**, independently loading the two supplied bundled modules, the candidate, and current-main's function. The candidate matches PPSA03766 in every captured field (result/exponent, SSE and x87 flags/control, errno). Current-main differs in1248 rows, including792 result-bit and408 exponent observations. Inputs combine deterministic random32-bit patterns and every exponent boundary. - Both bundled copies agree on all result bits and exponents. PPSA07923's compiler unconditionally scales finite inputs, adding overflow/inexact flags on26,112 large-value rows. The change deliberately follows PPSA03766's conditional scaling; this SDK flag variant and unmasked traps are recorded as debt. - Replacing only the new function with current-main's `std::frexp` fails the committed `guest_math` regression at the first subnormal's flags. Restoring the implementation passes all repeated groups and produces a byte-identical libc library. Conventions and whitespace pass. Clean local merge-tree against newer main `6b1f419fefbde12c0fdad3299a294487dc427e44`; exact built/tested base remains5949. The overlap scan's45 shared-file cases have no changed `frexp`/`frexpf` implementation or callers; #8937 and #10953 have independent additive debt entries at the same location. Retain both rows when reconciling; no functional dependency. Combined branches were not runtime-tested. [Source patch, numeric reference observations, full matrices, regression/negative-control logs and restoration proof](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/libc-frexpf-head7cfbb837-linux-validation.tar.gz) — SHA-256 `7a75885add6e2691d06ad91fc4d2784fbf54b7a185c1050ce0c2856b634de5e6`. The downloaded asset was hash-verified. No proprietary module binaries, extracted instructions or game assets are included. Windows/macOS, unmasked exceptions and native titles were not tested. No game-unblock, FPS or new-function-count claim. ### 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (CPU libc only) - [x] AI-assisted: yes
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!11074
No description provided.