feat(libc): implement the remaining long double math functions RetroArch imports #3598

Merged
Recapi merged 2 commits from upstream-pr/3598 into main 2026-10-11 22:22:48 +00:00
Recapi commented 2026-10-11 14:06:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-11T14:06:16Z.


What

Implements the rest of the math functions that RetroArch (PPSA99169, catalog 1.0.0-beta.1) imports and main lacks (#1578): the long double functions atanl, sinl, cosl, tanl, sinhl, coshl, tanhl, expl, exp2l, logl, log10l, powl, ldexpl and truncl, plus logb and remainder. Each forwards to the host's std:: function, as acosl does. ldexpl, truncl, logb and remainder are exact operations, so they match the console. The transcendental ones can differ from the console's msun code in the last bit, and that is recorded in TechnicalDebt.md.

sinhf and asinl, RetroArch's other two math imports, are in #3725, which carries @screamm's ports from #3519. Those ports match the console bit for bit. Earlier versions of this PR and #3597 carried host one-liners for them instead. The relinked title is BIND_NOW, so it needs both PRs to get past its math imports. The two PRs touch separate lines and merge with each other without conflicts.

Tested

Linux (Ubuntu, GCC, Release) on main a11c8f7. The catalog ZIP was checked against its sha256, eboot.bin and sce_module/libc.prx were unwrapped as #2605 requires, and the title was relinked with --registry and run in a sandbox with no network:

  • main: ./app.elf: symbol lookup error: ./app.elf: undefined symbol: Nx-F5v0-qU8 (asinl)
  • #3725 alone: stops at KvOHPTz595Y (atanl)
  • #3725 merged with this PR: ./app.elf: symbol lookup error: ./app.elf: undefined symbol: EDyhWelj7UY (pause). Of RetroArch's 33 absent imports, 17 remain, and none of them is math
  • guest_math passes 3/3 (--repeat until-fail:3), both on this branch and merged with #3725. The new CheckExtendedMath covers:
    • exact x87 bits for atanl(inf) and the denormal edges of exp2l and ldexpl;
    • values against 21-digit bc -l references;
    • signed zeros, infinities, NaN domains, overflow thresholds, powl special cases, truncl near 2^63, and logb/remainder edge cases.
  • check_conventions.py passes. Fork CI for the previous version of this branch: guest_math passed on Linux and Windows (run 38145813373)

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: #3725 for RetroArch to start (builds and tests on its own)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819639558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3598). Originally posted by [Recapi](https://github.com/Recapi) on 2026-10-11T14:06:16Z. --- ### What Implements the rest of the math functions that RetroArch (PPSA99169, catalog 1.0.0-beta.1) imports and `main` lacks (#1578): the `long double` functions `atanl`, `sinl`, `cosl`, `tanl`, `sinhl`, `coshl`, `tanhl`, `expl`, `exp2l`, `logl`, `log10l`, `powl`, `ldexpl` and `truncl`, plus `logb` and `remainder`. Each forwards to the host's `std::` function, as `acosl` does. `ldexpl`, `truncl`, `logb` and `remainder` are exact operations, so they match the console. The transcendental ones can differ from the console's msun code in the last bit, and that is recorded in `TechnicalDebt.md`. `sinhf` and `asinl`, RetroArch's other two math imports, are in #3725, which carries @screamm's ports from #3519. Those ports match the console bit for bit. Earlier versions of this PR and #3597 carried host one-liners for them instead. The relinked title is `BIND_NOW`, so it needs both PRs to get past its math imports. The two PRs touch separate lines and merge with each other without conflicts. ### Tested Linux (Ubuntu, GCC, Release) on `main` a11c8f7. The catalog ZIP was checked against its sha256, `eboot.bin` and `sce_module/libc.prx` were unwrapped as #2605 requires, and the title was relinked with `--registry` and run in a sandbox with no network: - `main`: `./app.elf: symbol lookup error: ./app.elf: undefined symbol: Nx-F5v0-qU8` (`asinl`) - #3725 alone: stops at `KvOHPTz595Y` (`atanl`) - #3725 merged with this PR: `./app.elf: symbol lookup error: ./app.elf: undefined symbol: EDyhWelj7UY` (`pause`). Of RetroArch's 33 absent imports, 17 remain, and none of them is math - `guest_math` passes 3/3 (`--repeat until-fail:3`), both on this branch and merged with #3725. The new `CheckExtendedMath` covers: - exact x87 bits for `atanl(inf)` and the denormal edges of `exp2l` and `ldexpl`; - values against 21-digit `bc -l` references; - signed zeros, infinities, NaN domains, overflow thresholds, `powl` special cases, `truncl` near 2^63, and `logb`/`remainder` edge cases. - `check_conventions.py` passes. Fork CI for the previous version of this branch: `guest_math` passed on Linux and Windows ([run 38145813373](https://github.com/Recapi/AnyPS5/actions/runs/38145813373)) ### 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: #3725 for RetroArch to start (builds and tests on its own) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 14:06:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T14:06:45Z.


Progress report (1be2ca2 → 7663d84)

📈 System libraries: 85.91% (+0.07%, +16 implemented functions)

✅ 16 implemented
Library Name
libc atanl_nid_postfix
libc coshl_nid_postfix
libc cosl_nid_postfix
libc exp2l_nid_postfix
libc expl_nid_postfix
libc ldexpl_nid_postfix
libc log10l_nid_postfix
libc logb_nid_postfix
libc logl_nid_postfix
libc powl_nid_postfix
libc remainder_nid_postfix
libc sinhl_nid_postfix
libc sinl_nid_postfix
libc tanhl_nid_postfix
libc tanl_nid_postfix
libc truncl_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109861764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3598#issuecomment-6109861764). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T14:06:45Z. --- <!-- progress-report --> ### Progress report (1be2ca2 → 7663d84) 📈 **System libraries**: 85.91% (+0.07%, +16 implemented functions) <details> <summary>✅ 16 implemented</summary> | Library | Name | | - | - | | libc | `atanl_nid_postfix` | | libc | `coshl_nid_postfix` | | libc | `cosl_nid_postfix` | | libc | `exp2l_nid_postfix` | | libc | `expl_nid_postfix` | | libc | `ldexpl_nid_postfix` | | libc | `log10l_nid_postfix` | | libc | `logb_nid_postfix` | | libc | `logl_nid_postfix` | | libc | `powl_nid_postfix` | | libc | `remainder_nid_postfix` | | libc | `sinhl_nid_postfix` | | libc | `sinl_nid_postfix` | | libc | `tanhl_nid_postfix` | | libc | `tanl_nid_postfix` | | libc | `truncl_nid_postfix` | </details>
Recapi commented 2026-10-11 14:41:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-11T14:41:08Z.


Fork CI for this commit: run 38145813373. guest_math passes on Linux and Windows. The failures in that run are unrelated to this change, and the Windows ones are the same as in main's own run on a11c8f7 (38144471410):

  • Windows: guest_kernel_sys, windows_exceptions
  • Linux: agc_driver_emulated_color_compare, agc_driver_image_plane_address_on_li…, guest_kernel_stack_protect
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110167774 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3598#issuecomment-6110167774). Originally posted by [Recapi](https://github.com/Recapi) on 2026-10-11T14:41:08Z. --- Fork CI for this commit: [run 38145813373](https://github.com/Recapi/AnyPS5/actions/runs/38145813373). `guest_math` passes on Linux and Windows. The failures in that run are unrelated to this change, and the Windows ones are the same as in `main`'s own run on a11c8f7 ([38144471410](https://github.com/boykopovar/AnyPS5/actions/runs/38144471410)): - Windows: `guest_kernel_sys`, `windows_exceptions` - Linux: `agc_driver_emulated_color_compare`, `agc_driver_image_plane_address_on_li…`, `guest_kernel_stack_protect`
blawesom commented 2026-10-11 15:20:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T15:20:16Z.


Independent pre-review on Linux (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON.

  • Builds; tools/check_conventions.py --base origin/main passes.
  • Full suite: 832/832 passed (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110522092 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3598#issuecomment-6110522092). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T15:20:16Z. --- Independent pre-review on **Linux** (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`. - Builds; `tools/check_conventions.py --base origin/main` passes. - Full suite: **832/832 passed** (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).
Recapi commented 2026-10-11 16:01:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-11T16:01:27Z.


Updated: dropped asinl in favour of @screamm's console-exact port in #3725 (from #3519). This PR now has only the 16 functions that no other PR or branch implements. Thanks @blawesom for pointing out the overlap.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110898239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3598#issuecomment-6110898239). Originally posted by [Recapi](https://github.com/Recapi) on 2026-10-11T16:01:27Z. --- Updated: dropped `asinl` in favour of @screamm's console-exact port in #3725 (from #3519). This PR now has only the 16 functions that no other PR or branch implements. Thanks @blawesom for pointing out the overlap.
adriadam10 commented 2026-10-11 21:40:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:40:59Z.


Checked the build and guest_math on Linux (libs + libc scope, 74/74 pass); the new cases fail to link without the change. No open PR adds these functions (#3725 carries sinhf/asinl).

Added one commit:

  • TechnicalDebt.md: logb and remainder return the console's value, but glibc sets errno (ERANGE for logb(0), EDOM for remainder by zero or of an infinity) where msun only raises the exception. The entry said they matched the console fully.

Errno handling for the libm wrappers is tracked separately in #3690. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114089949 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3598#issuecomment-6114089949). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:40:59Z. --- Checked the build and `guest_math` on Linux (libs + libc scope, 74/74 pass); the new cases fail to link without the change. No open PR adds these functions (#3725 carries `sinhf`/`asinl`). Added one commit: - `TechnicalDebt.md`: `logb` and `remainder` return the console's value, but glibc sets `errno` (`ERANGE` for `logb(0)`, `EDOM` for `remainder` by zero or of an infinity) where msun only raises the exception. The entry said they matched the console fully. Errno handling for the libm wrappers is tracked separately in #3690. Merging once CI is green.
adriadam10 commented 2026-10-11 21:54:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:54:02Z.


Rebased onto current main: the only conflict was GuestMath.cpp, where CheckAsin and CheckExtendedMath were added at the same spot; both are kept. guest_math passes after the rebase. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114218847 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3598#issuecomment-6114218847). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:54:02Z. --- Rebased onto current `main`: the only conflict was `GuestMath.cpp`, where `CheckAsin` and `CheckExtendedMath` were added at the same spot; both are kept. `guest_math` passes after the rebase. Merging once CI is green.
github-actions[bot] commented 2026-10-11 21:56:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T21:56:52Z.


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
#2465 core/libs/tests/GuestMath.cpp L85
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114243863 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3598#issuecomment-6114243863). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T21:56:52Z. --- <!-- 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 | |---|---|---|---| | #2465 | `core/libs/tests/GuestMath.cpp` [L85](https://github.com/boykopovar/AnyPS5/blob/31bf997b5342b88ebd4fa8f5629b0ee7400fe176/core/libs/tests/GuestMath.cpp#L85) | | |
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!3598
No description provided.