feat(libc): implement extended-precision math exports #2271

Closed
obojeoboje wants to merge 2 commits from upstream-pr/2271 into main
obojeoboje commented 2026-10-09 14:06:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by obojeoboje on 2026-10-09T14:06:04Z.


What

Add 43 missing libc long double math exports in a dedicated translation unit, preserving the guest x87 extended format rather than narrowing inputs, outputs or pointer results to double.

  • Trigonometric and hyperbolic: acosl, asinl, atanl, atan2l, tanl, acoshl, asinhl, atanhl, coshl, sinhl, tanhl.

  • Exponentials, logarithms and roots: expl, exp2l, expm1l, log10l, log1pl, log2l, logbl, sqrtl, cbrtl, hypotl.

  • Arithmetic and rounding: fabsl, copysignl, fdiml, fmaxl, fminl, fmal, ceill, floorl, roundl, lroundl, llroundl, nearbyintl.

  • Remainders, neighbors and decomposition: fmodl, remainderl, remquol, nextafterl, nexttowardl, frexpl, ldexpl, modfl, scalbnl, scalblnl.

Guest lroundl returns 64 bits on Windows through the host llround overload. scalblnl accepts a 64-bit guest exponent and bounds it before using the native int-exponent operation, avoiding Windows long truncation. Bounds exceed the entire representable x87 exponent range.

Normalize native runtime differences found by the tests: signed-zero fractional results for infinite modfl inputs; domain/pole exception flags and errno for acoshl, atanhl and sqrtl; and missing overflow/zero-underflow flags for finite exponential/hyperbolic inputs. Preserve FreeBSD signed-zero ordering for fmaxl/fminl, and normalize neighbor-operation underflow/overflow flags and ERANGE. Use -frounding-math only for the new implementation and test translation units.

Contracts and signatures follow FreeBSD fmax(3), math(3), modf(3), and ldexp(3). All 43 export names are present in the shadPS4 aerolib table. Transcendental results use native extended-precision math; bit-identical results across host runtimes are not claimed.

Checked open PR descriptions and the relevant libc patches in #2193, #2213, #2166, #2167, #2173, #2192 and #2037. This branch excludes their functions and the rounding exports in #2235. Shared CMake insertion points may need both independent source/test additions preserved when rebasing.

The progress scanner changes from 2578/3044 (84.69%) to 2621/3087 (84.90%). Both counts grow because these are newly declared exports.

Tested

  • Windows, WinLibs GCC 15.2, Release with testing enabled: full default build and libs target passed.

  • Full CTest run, four workers, 30-second per-test limit: 507 passed, one skipped (guest_video_out_wqhd_detection_no_vulkan), zero failures; 39.68 seconds total on the final head 91f4371b.

  • New runtime fixture exercises all 43 exports using fixed numerical expectations, extended precision beyond double, exponents beyond the double range, subnormal decomposition/scaling, all four rounding modes, signed zero, NaNs/infinities, exception flags, fused rounding, quotient bits and 64-bit integer boundaries/exponents.

  • Linux, Ubuntu 24.04 under WSL, GCC 13.3: built ExtendedMath.cpp as a separate optimized shared library and linked/ran the same complete fixture with UndefinedBehaviorSanitizer successfully on the final head 91f4371b. This was a focused runtime check, not a full Linux project build or NID-patched library run.

  • Test registration, conventions and whitespace checks passed. No game tested.

  • Full Linux/Windows Build and the relinker matrix still require a collaborator to dispatch the workflow for this PR head.

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: none added

  • Generic behaviour, not specific to one title

  • Depends on: none

  • AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4801532603 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2271). Originally posted by [obojeoboje](https://github.com/obojeoboje) on 2026-10-09T14:06:04Z. --- ### What Add 43 missing libc `long double` math exports in a dedicated translation unit, preserving the guest x87 extended format rather than narrowing inputs, outputs or pointer results to `double`. - Trigonometric and hyperbolic: `acosl`, `asinl`, `atanl`, `atan2l`, `tanl`, `acoshl`, `asinhl`, `atanhl`, `coshl`, `sinhl`, `tanhl`. - Exponentials, logarithms and roots: `expl`, `exp2l`, `expm1l`, `log10l`, `log1pl`, `log2l`, `logbl`, `sqrtl`, `cbrtl`, `hypotl`. - Arithmetic and rounding: `fabsl`, `copysignl`, `fdiml`, `fmaxl`, `fminl`, `fmal`, `ceill`, `floorl`, `roundl`, `lroundl`, `llroundl`, `nearbyintl`. - Remainders, neighbors and decomposition: `fmodl`, `remainderl`, `remquol`, `nextafterl`, `nexttowardl`, `frexpl`, `ldexpl`, `modfl`, `scalbnl`, `scalblnl`. Guest `lroundl` returns 64 bits on Windows through the host `llround` overload. `scalblnl` accepts a 64-bit guest exponent and bounds it before using the native int-exponent operation, avoiding Windows `long` truncation. Bounds exceed the entire representable x87 exponent range. Normalize native runtime differences found by the tests: signed-zero fractional results for infinite `modfl` inputs; domain/pole exception flags and errno for `acoshl`, `atanhl` and `sqrtl`; and missing overflow/zero-underflow flags for finite exponential/hyperbolic inputs. Preserve FreeBSD signed-zero ordering for `fmaxl`/`fminl`, and normalize neighbor-operation underflow/overflow flags and `ERANGE`. Use `-frounding-math` only for the new implementation and test translation units. Contracts and signatures follow FreeBSD [fmax(3)](https://man.freebsd.org/cgi/man.cgi?query=fmax&sektion=3&manpath=FreeBSD+14.0-RELEASE), [math(3)](https://man.freebsd.org/cgi/man.cgi?query=math&sektion=3&manpath=FreeBSD+15.0-RELEASE), [modf(3)](https://man.freebsd.org/cgi/man.cgi?query=modf&sektion=3&manpath=FreeBSD+14.0-RELEASE), and [ldexp(3)](https://man.freebsd.org/cgi/man.cgi?query=ldexp&sektion=3&manpath=FreeBSD+14.0-RELEASE). All 43 export names are present in the [shadPS4 aerolib table](https://github.com/shadps4-emu/shadPS4/blob/0fe263a4760dfbfa973366890061749b4af0de97/src/core/aerolib/aerolib.inl). Transcendental results use native extended-precision math; bit-identical results across host runtimes are not claimed. Checked open PR descriptions and the relevant libc patches in #2193, #2213, #2166, #2167, #2173, #2192 and #2037. This branch excludes their functions and the rounding exports in #2235. Shared CMake insertion points may need both independent source/test additions preserved when rebasing. The progress scanner changes from 2578/3044 (84.69%) to 2621/3087 (84.90%). Both counts grow because these are newly declared exports. ### Tested - Windows, WinLibs GCC 15.2, Release with testing enabled: full default build and `libs` target passed. - Full CTest run, four workers, 30-second per-test limit: 507 passed, one skipped (`guest_video_out_wqhd_detection_no_vulkan`), zero failures; 39.68 seconds total on the final head `91f4371b`. - New runtime fixture exercises all 43 exports using fixed numerical expectations, extended precision beyond double, exponents beyond the double range, subnormal decomposition/scaling, all four rounding modes, signed zero, NaNs/infinities, exception flags, fused rounding, quotient bits and 64-bit integer boundaries/exponents. - Linux, Ubuntu 24.04 under WSL, GCC 13.3: built `ExtendedMath.cpp` as a separate optimized shared library and linked/ran the same complete fixture with UndefinedBehaviorSanitizer successfully on the final head `91f4371b`. This was a focused runtime check, not a full Linux project build or NID-patched library run. - Test registration, conventions and whitespace checks passed. No game tested. - Full Linux/Windows Build and the relinker matrix still require a collaborator to dispatch the workflow for this PR head. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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: none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-09 14:34:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T14:34:47Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2170 core/libs/prx/libc/CMakeLists.txt L48
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083048474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2271#issuecomment-6083048474). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T14:34:47Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2170 | `core/libs/prx/libc/CMakeLists.txt` [L48](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/prx/libc/CMakeLists.txt#L48) | | |
oneandonlydean commented 2026-10-09 20:11:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:11:07Z.


Closing: none of these 43 functions is shown to be reached by a title on main; the list comes from the aerolib table, and library functions go in when a title needs them. Reopen with the title ID and the log line where it stops if you find one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088458913 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2271#issuecomment-6088458913). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:11:07Z. --- Closing: none of these 43 functions is shown to be reached by a title on main; the list comes from the aerolib table, and library functions go in when a title needs them. Reopen with the title ID and the log line where it stops if you find one.
babyhuey commented 2026-10-10 22:36:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T22:36:22Z.


@obojeoboje PokeMMO (PPSA98001) now stops at frexpl on main f38a036e (catalog build, sce_module/libc.prx unwrapped, with #1529 in): app.elf: symbol lookup error: app.elf: undefined symbol: YZk9sHO0yNg. The intake check needs 10 merged PRs; if you can't open PRs yet, would you like me to open the frexpl part of this from my fork with your commits and authorship kept, after a Linux and Windows run? The rest of the long double set has no title stopping on it yet, so it would likely need to wait.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102919629 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2271#issuecomment-6102919629). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T22:36:22Z. --- @obojeoboje PokeMMO (PPSA98001) now stops at `frexpl` on `main` f38a036e (catalog build, `sce_module/libc.prx` unwrapped, with #1529 in): `app.elf: symbol lookup error: app.elf: undefined symbol: YZk9sHO0yNg`. The intake check needs 10 merged PRs; if you can't open PRs yet, would you like me to open the `frexpl` part of this from my fork with your commits and authorship kept, after a Linux and Windows run? The rest of the long double set has no title stopping on it yet, so it would likely need to wait.

Pull request closed

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!2271
No description provided.