fix(libc): preserve frexp decomposition and exception behavior #11077

Merged
JJenkx merged 1 commit from upstream-pr/11077 into main 2026-11-02 10:26:47 +00:00
JJenkx commented 2026-10-25 17:11:07 +00:00 (Migrated from github.com)

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


What

The host std::frexp(double) quiets signaling NaNs and does not reproduce the bundled implementation's subnormal scaling/DAZ behavior. frexp now decomposes exponent bits directly, scales only subnormal inputs by2^54, and returns zeros/infinities/NaNs unchanged with exponent0. This follows both supplied PPSA03766/PPSA07923 functions. Existing ABI and export identity are unchanged.

Tested

Main conflict refresh, 2026-10-27 10:18 UTC pass: exact head fa653e8c08153c828419adfa1c029ad3488917b3 on tested main 3fea2a937ba9fbab2f06c51691fe0c5763659aa3. The topic implementations and fixtures are retained alongside current main's newer math functions and coverage.

Linux Release focused rebuild: guest_math and guest_math_exact each pass three repetitions: 6 passes, zero skips. Conventions, whitespace and merge checks pass. Every refreshed head's submodule pointers match the pinned main; the private dependency checkouts used for the gates are aligned. No new negative-control, Windows, console, title, GPU, full-suite or performance run is claimed. Earlier measurements below retain their original exact pins. Fulfilled merge-order dependencies have been cleared from the checklist; open prerequisites remain.

Exact source/dependency pins, patch-preservation and gitlink proofs, builds, verbose tests, JUnit and lease-push receipts. SHA-256: 702c4110ee9dde421c2dd5e057ed53a2df05e0cf7b01f67e8fb9cb779e332f7c; downloaded copy verified.

Current-main refresh: head f3f75dade024d94529c6d51f9071a518e4f70264 is one linear commit on main a7a2eece499ef8925c93765dbbcc9f4d9461a2f0. The only rebase conflict was additive docs/dev/debt/libc.md; all upstream rows and this gap entry are retained. Production and960-call regression function bodies are byte-identical to61a9072bbb. All three focused suites pass3 repeats on the refreshed head; the parent host-call negative fails at the first subnormal's flags, and restoration passes3 repeats with a byte-identical library. Conventions/whitespace pass. The #11074-first merge-order dependency is unchanged.

Refresh logs, negative/restored runs, patch and preservation proof — SHA-256 f4741a30cb14e0c1b36c9be7fe301445e39b593cfdce9a683a098853f640f5ba, downloaded/hash-verified. The earlier broad numeric matrix below remains pinned to61a9072bbb; no new broad matrix or platform/title result is claimed.

Original qualification:

Linux / GCC16.2.1 / Release, exact head 61a9072bbbc19780adadc7d7b339ab04a50f8e63 on main 4718dedcf8415e462bd2bb6dc218142d81edd8f1.

  • guest_math, guest_math_exact and guest_dinkumware_internals: each passes3 repeats before and after the selective negative control.
  • New960-call regression:20 boundary/special inputs ×4 rounding modes ×4 DAZ/FTZ combinations ×3 sticky-flag seeds. It checks exact fraction bits, exponent, MXCSR flags/control and guest errno, including both signs of zero, subnormals, normal boundaries, maximum finite values, infinity and signaling/quiet NaNs.
  • Broader16,385-input differential: 786,480 calls per arm, loading both supplied bundled modules, the candidate and a current-main-function control. Inputs include all2048 exponent boundaries and deterministic random64-bit patterns. Both original copies and the candidate agree on every recorded result/exponent/errno/SSE/x87-flag/control field. The old function differs in336 rows, including168 result-bit and120 exponent observations.
  • Restoring only main's host call makes the committed guest_math regression fail at the first subnormal's flags. Restoring the change passes the suites and reproduces the libc SHA exactly.

Related #11074 changes float frexpf, independently of this double implementation. They have an adjacent Math.cpp conflict. I resolved that in private integration f014a32788fdd53cb4dac543006d9fbfb8178fdc, retaining both exact function bodies, both fixtures/calls and both debt entries; all three groups pass3 repeats. The archive includes the integration delta and proof. I then restored this standalone head, repeated all three groups3 times and verified its library byte-identical. I will preserve both functions when refreshing after either lands. Merge order is #11074 first, then this PR. I will recheck/rebase the combined tree after #11074 lands; this is a merge-order dependency, not a functional one. #9613's reported overlap is an independent additive debt entry; retain both rows. The other shared-file patches introduce no competing frexp implementation; their combinations were not runtime-tested.

Conventions/whitespace pass. Clean local merge-tree against newer main 4da123784ed160db849f1c72ec61dd0484708952; exact built/tested base remains4718.

Source patch, full numeric matrices, reference fingerprints, negative/restored test logs and float-combination evidence — SHA-256 2580e06d06628077746e7dd4bbad28e1b3aeda886994ee6dc954eb849cf045aa. Original module binaries, extracted instruction bytes and game assets are excluded.

Windows/macOS, unmasked traps and native games were not tested. No FPS, title-unblock or newly implemented export 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 (#11074 merged at d090e628413c; present in audited main 3fea2a937ba)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (CPU libc only)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5006851861 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11077). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-25T17:11:07Z. --- ### What The host `std::frexp(double)` quiets signaling NaNs and does not reproduce the bundled implementation's subnormal scaling/DAZ behavior. `frexp` now decomposes exponent bits directly, scales only subnormal inputs by2^54, and returns zeros/infinities/NaNs unchanged with exponent0. This follows both supplied PPSA03766/PPSA07923 functions. Existing ABI and export identity are unchanged. ### Tested <!-- codex-main-refresh-20261027-1018-pr11077 --> **Main conflict refresh, 2026-10-27 10:18 UTC pass:** exact head `fa653e8c08153c828419adfa1c029ad3488917b3` on tested main `3fea2a937ba9fbab2f06c51691fe0c5763659aa3`. The topic implementations and fixtures are retained alongside current main's newer math functions and coverage. Linux Release focused rebuild: `guest_math` and `guest_math_exact` each pass three repetitions: 6 passes, zero skips. Conventions, whitespace and merge checks pass. Every refreshed head's submodule pointers match the pinned main; the private dependency checkouts used for the gates are aligned. No new negative-control, Windows, console, title, GPU, full-suite or performance run is claimed. Earlier measurements below retain their original exact pins. Fulfilled merge-order dependencies have been cleared from the checklist; open prerequisites remain. [Exact source/dependency pins, patch-preservation and gitlink proofs, builds, verbose tests, JUnit and lease-push receipts](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-cpu11-main3fea-linux-20261027-1018.tar.gz). SHA-256: `702c4110ee9dde421c2dd5e057ed53a2df05e0cf7b01f67e8fb9cb779e332f7c`; downloaded copy verified. <!-- 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. --> **Current-main refresh:** head `f3f75dade024d94529c6d51f9071a518e4f70264` is one linear commit on main `a7a2eece499ef8925c93765dbbcc9f4d9461a2f0`. The only rebase conflict was additive `docs/dev/debt/libc.md`; all upstream rows and this gap entry are retained. Production and960-call regression function bodies are byte-identical to61a9072bbb. All three focused suites pass3 repeats on the refreshed head; the parent host-call negative fails at the first subnormal's flags, and restoration passes3 repeats with a byte-identical library. Conventions/whitespace pass. The #11074-first merge-order dependency is unchanged. [Refresh logs, negative/restored runs, patch and preservation proof](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr11077-headf3f75dad-maina7a2-linux-refresh.tar.gz) — SHA-256 `f4741a30cb14e0c1b36c9be7fe301445e39b593cfdce9a683a098853f640f5ba`, downloaded/hash-verified. The earlier broad numeric matrix below remains pinned to61a9072bbb; no new broad matrix or platform/title result is claimed. Original qualification: Linux / GCC16.2.1 / Release, exact head `61a9072bbbc19780adadc7d7b339ab04a50f8e63` on main `4718dedcf8415e462bd2bb6dc218142d81edd8f1`. - `guest_math`, `guest_math_exact` and `guest_dinkumware_internals`: each passes3 repeats before and after the selective negative control. - New960-call regression:20 boundary/special inputs ×4 rounding modes ×4 DAZ/FTZ combinations ×3 sticky-flag seeds. It checks exact fraction bits, exponent, MXCSR flags/control and guest errno, including both signs of zero, subnormals, normal boundaries, maximum finite values, infinity and signaling/quiet NaNs. - Broader16,385-input differential: **786,480 calls per arm**, loading both supplied bundled modules, the candidate and a current-main-function control. Inputs include all2048 exponent boundaries and deterministic random64-bit patterns. Both original copies and the candidate agree on every recorded result/exponent/errno/SSE/x87-flag/control field. The old function differs in336 rows, including168 result-bit and120 exponent observations. - Restoring only main's host call makes the committed `guest_math` regression fail at the first subnormal's flags. Restoring the change passes the suites and reproduces the libc SHA exactly. Related #11074 changes **float `frexpf`**, independently of this double implementation. They have an adjacent `Math.cpp` conflict. I resolved that in private integration `f014a32788fdd53cb4dac543006d9fbfb8178fdc`, retaining both exact function bodies, both fixtures/calls and both debt entries; all three groups pass3 repeats. The archive includes the integration delta and proof. I then restored this standalone head, repeated all three groups3 times and verified its library byte-identical. I will preserve both functions when refreshing after either lands. Merge order is #11074 first, then this PR. I will recheck/rebase the combined tree after #11074 lands; this is a merge-order dependency, not a functional one. #9613's reported overlap is an independent additive debt entry; retain both rows. The other shared-file patches introduce no competing `frexp` implementation; their combinations were not runtime-tested. Conventions/whitespace pass. Clean local merge-tree against newer main `4da123784ed160db849f1c72ec61dd0484708952`; exact built/tested base remains4718. [Source patch, full numeric matrices, reference fingerprints, negative/restored test logs and float-combination evidence](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/libc-frexp-head61a9072bbb-complete-validation.tar.gz) — SHA-256 `2580e06d06628077746e7dd4bbad28e1b3aeda886994ee6dc954eb849cf045aa`. Original module binaries, extracted instruction bytes and game assets are excluded. Windows/macOS, unmasked traps and native games were not tested. No FPS, title-unblock or newly implemented export 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 (#11074 merged at `d090e628413c`; present in audited main `3fea2a937ba`) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (CPU libc only) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 19:23:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:23:40Z.

Review: APPROVED


Reviewed the exact frexp bit decomposition and the environment regression matrix. The subnormal path is deliberately exposed to DAZ, while the result/exponent construction and unchanged special-value return avoid host frexp behavior; the tests check rounding, DAZ/FTZ, sticky flags, errno, signed zeros and signaling/quiet NaNs. GCC 12.2 syntax compilation passed for Math.cpp and GuestMath.cpp; conventions and git diff --check pass locally. The author reports repeated focused runtime suites, a negative control and the broader differential matrix. The current main has no changes to these three touched paths since the tested base, and the merge tree is clean. Merge order remains after #11074 as declared.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644862756 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11077#pullrequestreview-5644862756). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T19:23:40Z. **Review:** APPROVED --- Reviewed the exact `frexp` bit decomposition and the environment regression matrix. The subnormal path is deliberately exposed to DAZ, while the result/exponent construction and unchanged special-value return avoid host `frexp` behavior; the tests check rounding, DAZ/FTZ, sticky flags, errno, signed zeros and signaling/quiet NaNs. GCC 12.2 syntax compilation passed for `Math.cpp` and `GuestMath.cpp`; conventions and `git diff --check` pass locally. The author reports repeated focused runtime suites, a negative control and the broader differential matrix. The current main has no changes to these three touched paths since the tested base, and the merge tree is clean. Merge order remains after #11074 as declared.
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!11077
No description provided.