fix(libc): preserve expm1 rounding during exponent scaling #10529

Merged
JJenkx merged 1 commit from upstream-pr/10529 into main 2026-10-28 04:49:49 +00:00
JJenkx commented 2026-10-24 08:19:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-24T08:19:38Z.


What

In the expm1 exponent-scaling branch, 1 - (e - x) introduces a rounding point with the opposite sign from 1 + (x - e). The two expressions agree under nearest and toward-zero rounding, but can differ by one ULP under upward/downward rounding. The bundled PPSA03766 and PPSA07923 libraries use the latter association.

Change that one expression to 1 + (x - e). Other production paths are unchanged. For example, input 0x407ff33f4d52628c under downward rounding should return 0x6e06c8c73526868f; main returns 0x6e06c8c735268690.

Contract source: PPSA03766 bundled libc.prx, expm1 NID gqKfOiJaCOo, scaling arithmetic at 0x49936/0x4993a, checked against the unchanged function in the converted module and numerically against both bundled copies. No SDK instruction dump is attached.

Tested

Main conflict refresh, 2026-10-27 10:18 UTC pass: exact head f89e32170ce3bc8fc785148b5236a1c81adaa6d2 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 conflict refresh, 2026-10-27 UTC: exact head 3013efe5bef79c6866d7e2fae1848b10789d2886 on tested main 74acfad65b3f0fd4eab653f3a3989d298fba1157. Resolved overlapping test/debt context while preserving this branch's authored production/test edits and main's nextafter environment implementation and coverage. Existing prerequisite commits remain in their original series order.

Linux focused rebuild of libc and selected test executables passes guest_math and guest_math_exact, each three times: 6 passes, zero skips. Conventions and whitespace checks pass. Final fetched main cb45ae2ddf6e113a4619e8fed91fe7b9333c5c0f merges cleanly; its later change is an unrelated Windows crash-test pattern, and the executed qualification remains pinned to the stated base. No new Windows, console, GPU, title, full-suite or negative-control run is claimed. Earlier reference/Windows evidence keeps its original pins.

Exact pins, branch patches, preservation proofs, build/test logs, JUnit and lease-push receipts for this refresh batch. SHA-256: e33f98cc467f038af662cc5fa491c3acc1806bb47171cf77b748f0d4d052c1f2; downloaded copy verified.

Current Linux rebase: 1f3b30246c95a935561c1f34c83a40607c4816de, one topic commit on main 16ff208dc32cf3927ba1bae492eee363a5ae7ae8, without merge commits. Production and regression function bodies are unchanged from af0905fd62bff6da32102e36dcbf7a7510594968; main's merged log1p implementation, regressions and calls remain intact. Additive regression insertions were retained on both sides.

Fresh Linux x86-64 Release: guest_math, guest_math_exact, guest_dinkumware_internals and public_headers each pass three repeats before and after the production-only main-Math negative control. The negative fails as expected while exact-math/Dinkumware controls pass; restored libc is byte-identical. Conventions and whitespace pass. The negative identifies the downward-rounding expm1 scaling case.

Fresh exact-head logs, negative/restoration evidence and preservation proof (SHA-256 fba4546fd2ffc5ea33459b5cc498adc8d2844b835d01d33e301b09d530c93087). No new Windows/macOS, title/module matrix or performance result is claimed. Earlier independent reports below retain their original measured revisions.

Previous qualification (historical source pins)

Historical main refresh: af0905fd62bff6da32102e36dcbf7a7510594968, one topic commit directly on main 8b426927d7d91c137e6f4704acc860f060a2798a, with no merge commits. The original Expm1 implementation and both expm1 regression functions are preserved; the entire production file equals main plus the original single-expression correction. Current public libc declarations are retained.

Fresh Linux x86-64 Release: rebuilt libc and the three math targets. guest_math, guest_math_exact, guest_dinkumware_internals and public_headers each pass three repeats. A production-only main-Math control fails the intended downward-rounding expm1 scaling: input=407ff33f4d52628c mode=1 case; exact-math and Dinkumware controls pass. Restored candidate passes all four groups three times and restores byte-identical libc. Conventions/whitespace pass. No original-library matrix, Windows/title or performance run was repeated for this refresh.

Exact-head logs, negative/restoration checks, source proof and patch, SHA-256 c718609d1f990bc2677789f2729d02799317405b61c28cbc8b7f57c484db6042.

Historical independent Windows evidence: ycbuzi’s report tests prior head b9e1b20e02 integrated with main fa515def85 as clean 73015c686e, Windows11 Home26200 / MinGW GCC15.2.0 Release. Math and Dinkumware pass twice; a main-Math negative aborts math while Dinkumware passes. No title was run. This is attributed historical integration evidence, not a new author-run Windows result.

Earlier qualification (historical source pins)

Linux x86-64, GNU C++ 16.2.1, Release. Exact candidate b9e1b20e0225a63d419ca01f7c9e231f0b3a8553 on main 1e20650e8458f4e8916a85576ae231b5e144b581; clean merge-tree check against current main e058b3284a1284449cafbf6423ce01bcd1153108.

  • Independent full libc/math target builds for main plus the identical new regression, the one-expression candidate, and a private combined-fix integration. Both math suites pass 3/3 for candidate and final integration. The same-test main control fails specifically at expm1 scaling; its Dinkumware suite passes 3/3.
  • The regression makes 96 calls over two independently measured inputs, four rounding modes, four DAZ/FTZ states and three sticky flag seeds. It checks exact result bits, errno, full MXCSR, x87 exception flags and unchanged x87 control. Both x87 and SSE sticky flags are explicitly seeded and checked; prior state is restored.
  • Fresh original-module matrices: 2,653 expm1 inputs × 48 environments = 127,344 calls per arm. Inputs include branch-boundary neighborhoods, raw random bits, positive/negative finite values and the previous corpus. Both original function bodies are byte-identical before/after conversion; both supplied libraries produce identical observations throughout this matrix. The CPU loader installs process metadata and rejects AGC/VideoOut/Vulkan mappings; it never calls a game entry point.
  • The candidate changes 2,820 one-ULP results: 2,700 positive-input and 120 negative-input rows. All now match the original modules. There are zero nearest/toward-zero changes, zero flag/errno/control changes, and zero remaining nonoverflow differences in this matrix.
  • The standalone candidate retains 12,528 positive-overflow environment differences (including 6,264 result/errno differences), which belong to the separate #10510 fix. The production paths are independent; test/debt insertion anchors overlap. Either merge order needs the ordinary additive conflict refresh, not a runtime dependency.
  • Private integration 88f292c4c693af736bac15aba4f5fadd1e4d681f combines this change with existing #10510/#10316/#10506. It has zero differences in all 127,344 expm1 and 79,104 tanh calls against both originals, including bits, errno, x87/SSE flags and controls. This also removes the previously documented sampled tanh discrepancy through the shared Expm1 helper. It is validation-only and is not part of this PR.
  • Conventions, diff checks and the open-PR overlap scan passed. Own patches, fixtures, complete Linux logs and numeric observations, SHA-256 04581076c482cf9788bbc79989b57d204b3f0618a85a274356d9d7ffd68812be. No SDK binaries, original code bytes or disassembly are included.
  • Not tested: physical console, other SDK release identities, unmasked exception traps, Windows/macOS or game/FPS behavior. Input coverage is sampled, not exhaustive.

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4993807235 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10529). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-24T08:19:38Z. --- ### What In the `expm1` exponent-scaling branch, `1 - (e - x)` introduces a rounding point with the opposite sign from `1 + (x - e)`. The two expressions agree under nearest and toward-zero rounding, but can differ by one ULP under upward/downward rounding. The bundled PPSA03766 and PPSA07923 libraries use the latter association. Change that one expression to `1 + (x - e)`. Other production paths are unchanged. For example, input `0x407ff33f4d52628c` under downward rounding should return `0x6e06c8c73526868f`; main returns `0x6e06c8c735268690`. Contract source: PPSA03766 bundled `libc.prx`, expm1 NID `gqKfOiJaCOo`, scaling arithmetic at `0x49936`/`0x4993a`, checked against the unchanged function in the converted module and numerically against both bundled copies. No SDK instruction dump is attached. ### Tested <!-- codex-main-refresh-20261027-1018-pr10529 --> **Main conflict refresh, 2026-10-27 10:18 UTC pass:** exact head `f89e32170ce3bc8fc785148b5236a1c81adaa6d2` 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. <!-- codex-main-refresh-20261027-pr10529 --> **Current-main conflict refresh, 2026-10-27 UTC:** exact head `3013efe5bef79c6866d7e2fae1848b10789d2886` on tested main `74acfad65b3f0fd4eab653f3a3989d298fba1157`. Resolved overlapping test/debt context while preserving this branch's authored production/test edits and main's nextafter environment implementation and coverage. Existing prerequisite commits remain in their original series order. Linux focused rebuild of `libc` and selected test executables passes `guest_math` and `guest_math_exact`, each three times: **6 passes, zero skips**. Conventions and whitespace checks pass. Final fetched main `cb45ae2ddf6e113a4619e8fed91fe7b9333c5c0f` merges cleanly; its later change is an unrelated Windows crash-test pattern, and the executed qualification remains pinned to the stated base. No new Windows, console, GPU, title, full-suite or negative-control run is claimed. Earlier reference/Windows evidence keeps its original pins. [Exact pins, branch patches, preservation proofs, build/test logs, JUnit and lease-push receipts for this refresh batch](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math14-main74acfad-linux-refresh-20261027.tar.gz). SHA-256: `e33f98cc467f038af662cc5fa491c3acc1806bb47171cf77b748f0d4d052c1f2`; downloaded copy verified. **Current Linux rebase:** `1f3b30246c95a935561c1f34c83a40607c4816de`, one topic commit on main `16ff208dc32cf3927ba1bae492eee363a5ae7ae8`, without merge commits. Production and regression function bodies are unchanged from `af0905fd62bff6da32102e36dcbf7a7510594968`; main's merged log1p implementation, regressions and calls remain intact. Additive regression insertions were retained on both sides. Fresh Linux x86-64 Release: `guest_math`, `guest_math_exact`, `guest_dinkumware_internals` and `public_headers` each pass three repeats before and after the production-only main-Math negative control. The negative fails as expected while exact-math/Dinkumware controls pass; restored libc is byte-identical. Conventions and whitespace pass. The negative identifies the downward-rounding expm1 scaling case. [Fresh exact-head logs, negative/restoration evidence and preservation proof](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr10345-7385e2d9-pr10529-1f3b3024-main16ff-linux-validation.tar.gz) (SHA-256 `fba4546fd2ffc5ea33459b5cc498adc8d2844b835d01d33e301b09d530c93087`). No new Windows/macOS, title/module matrix or performance result is claimed. Earlier independent reports below retain their original measured revisions. #### Previous qualification (historical source pins) Historical main refresh: `af0905fd62bff6da32102e36dcbf7a7510594968`, one topic commit directly on main `8b426927d7d91c137e6f4704acc860f060a2798a`, with no merge commits. The original Expm1 implementation and both expm1 regression functions are preserved; the entire production file equals main plus the original single-expression correction. Current public libc declarations are retained. Fresh Linux x86-64 Release: rebuilt libc and the three math targets. `guest_math`, `guest_math_exact`, `guest_dinkumware_internals` and `public_headers` each pass three repeats. A production-only main-Math control fails the intended downward-rounding `expm1 scaling: input=407ff33f4d52628c mode=1` case; exact-math and Dinkumware controls pass. Restored candidate passes all four groups three times and restores byte-identical libc. Conventions/whitespace pass. No original-library matrix, Windows/title or performance run was repeated for this refresh. [Exact-head logs, negative/restoration checks, source proof and patch](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr10529-headaf0905fd-main8b42-linux-validation.tar.gz), SHA-256 `c718609d1f990bc2677789f2729d02799317405b61c28cbc8b7f57c484db6042`. Historical independent Windows evidence: [ycbuzi’s report](https://github.com/boykopovar/AnyPS5/pull/10529#issuecomment-6386341683) tests prior head `b9e1b20e02` integrated with main `fa515def85` as clean `73015c686e`, Windows11 Home26200 / MinGW GCC15.2.0 Release. Math and Dinkumware pass twice; a main-Math negative aborts math while Dinkumware passes. No title was run. This is attributed historical integration evidence, not a new author-run Windows result. #### Earlier qualification (historical source pins) Linux x86-64, GNU C++ 16.2.1, Release. Exact candidate `b9e1b20e0225a63d419ca01f7c9e231f0b3a8553` on main `1e20650e8458f4e8916a85576ae231b5e144b581`; clean merge-tree check against current main `e058b3284a1284449cafbf6423ce01bcd1153108`. - Independent full libc/math target builds for main plus the identical new regression, the one-expression candidate, and a private combined-fix integration. Both math suites pass **3/3** for candidate and final integration. The same-test main control fails specifically at `expm1 scaling`; its Dinkumware suite passes 3/3. - The regression makes **96 calls** over two independently measured inputs, four rounding modes, four DAZ/FTZ states and three sticky flag seeds. It checks exact result bits, errno, full MXCSR, x87 exception flags and unchanged x87 control. Both x87 and SSE sticky flags are explicitly seeded and checked; prior state is restored. - Fresh original-module matrices: **2,653 expm1 inputs × 48 environments = 127,344 calls per arm**. Inputs include branch-boundary neighborhoods, raw random bits, positive/negative finite values and the previous corpus. Both original function bodies are byte-identical before/after conversion; both supplied libraries produce identical observations throughout this matrix. The CPU loader installs process metadata and rejects AGC/VideoOut/Vulkan mappings; it never calls a game entry point. - The candidate changes **2,820 one-ULP results**: 2,700 positive-input and 120 negative-input rows. All now match the original modules. There are **zero nearest/toward-zero changes**, **zero flag/errno/control changes**, and **zero remaining nonoverflow differences** in this matrix. - The standalone candidate retains **12,528 positive-overflow environment differences** (including 6,264 result/errno differences), which belong to the separate #10510 fix. The production paths are independent; test/debt insertion anchors overlap. Either merge order needs the ordinary additive conflict refresh, not a runtime dependency. - Private integration `88f292c4c693af736bac15aba4f5fadd1e4d681f` combines this change with existing #10510/#10316/#10506. It has **zero differences** in all **127,344 expm1** and **79,104 tanh** calls against both originals, including bits, errno, x87/SSE flags and controls. This also removes the previously documented sampled tanh discrepancy through the shared Expm1 helper. It is validation-only and is not part of this PR. - Conventions, diff checks and the open-PR overlap scan passed. [Own patches, fixtures, complete Linux logs and numeric observations](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/libc-expm1-scaling-association-headb9e1b20e-linux-validation.tar.gz), SHA-256 `04581076c482cf9788bbc79989b57d204b3f0618a85a274356d9d7ffd68812be`. No SDK binaries, original code bytes or disassembly are included. - Not tested: physical console, other SDK release identities, unmasked exception traps, Windows/macOS or game/FPS behavior. Input coverage is sampled, not exhaustive. <!-- 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. --> ### 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 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-24 11:10:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T11:10:18Z.

Review: APPROVED


Reviewed the exact one-expression change, its directed-rounding regression, and the reported comparison against both supplied modules. The changed association is isolated to the exponent-scaling branch; the regression exercises two exact inputs across all four rounding modes, DAZ/FTZ combinations, seeded sticky flags, errno and the saved floating-point control state. The reported original-module matrix is broad and its remaining overflow differences are explicitly separated as #10510. I attempted an exact-head local CMake configure, but it cannot proceed in this checkout because the SDL2 submodule content and XRandR development package are absent. The hosted relinker jobs pass; the full Linux/Windows jobs are skipped, so I rely on the detailed reported math-target builds rather than treating skipped CI as coverage.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638032105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10529#pullrequestreview-5638032105). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T11:10:18Z. **Review:** APPROVED --- Reviewed the exact one-expression change, its directed-rounding regression, and the reported comparison against both supplied modules. The changed association is isolated to the exponent-scaling branch; the regression exercises two exact inputs across all four rounding modes, DAZ/FTZ combinations, seeded sticky flags, errno and the saved floating-point control state. The reported original-module matrix is broad and its remaining overflow differences are explicitly separated as #10510. I attempted an exact-head local CMake configure, but it cannot proceed in this checkout because the SDL2 submodule content and XRandR development package are absent. The hosted relinker jobs pass; the full Linux/Windows jobs are skipped, so I rely on the detailed reported math-target builds rather than treating skipped CI as coverage.
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!10529
No description provided.