feat(libc): implement log1p, log1pf and expm1 #3259

Merged
reyani-dev merged 1 commit from upstream-pr/3259 into main 2026-10-11 07:17:08 +00:00
reyani-dev commented 2026-10-11 03:43:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T03:43:46Z.


Resubmission of #2173, which was closed because no title was shown stopping on these functions.

OpenRCT2 (PPSA99728) stops at cosh on main 961b25fe (implemented by #3190). With #3190 applied, it stops next at expm1 (gqKfOiJaCOo), per @babyhuey's run on #3190 (comment). So this becomes OpenRCT2's next stop as soon as #3190 lands, the same stacking as #2933 (llroundf) before #2932 (atol).

log1p, log1pf and expm1 are still absent on current main, and no open PR implements them. There is no code dependency on #3190: the branch is rebased onto current main and merges cleanly with #3190. Windows 11 (WinLibs GCC 15.2.0), Release: guest_math passes 3/3, and check_conventions.py and pr_overlap.py --branch pass.


What

Exports log1p, log1pf and expm1. Each one forwards to the C++ standard library, like log and exp. Only the variants that titles import are added.

Titles: open-source homebrew from the #1578 catalog audit imports them from libSceLibcInternal (resolved through libc.prx):

  • log1p: PPSA68091 Ruffle, PPSA99169 RetroArch
  • log1pf: PPSA68091 Ruffle
  • expm1: PPSA99169 RetroArch, PPSA99764 Porpoise

I haven't run any of these titles.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, -DBUILD_TESTING=ON:

  • New checks in guest_math_tests, next to log10f:
    • signed zero (log1p(-0) and expm1(-0) are -0);
    • limits: log1p(-1) == -inf, log1p(inf) == inf, expm1(-inf) == expm1(-1000) == -1;
    • NaN below the domain: log1p(-2), log1pf(-2);
    • reference values at 1;
    • small arguments that need the dedicated functions: log1p(1e-300), log1pf(1e-30f) and expm1(1e-300) return their argument, and log1p(1e-10)/expm1(1e-10) are within 1e-25 of the exact values. log(1 + x) and exp(x) - 1 give 0 or lose most digits there.
  • Mutation check: replacing any of the three with log(1 + x) or exp(x) - 1 makes guest_math fail.
  • cmake --build build --target libs: the patched libc.prx exports all 3 NIDs.
  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no overlap. This branch also merges cleanly with my #2158, #2166 and #2167.

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: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4816349225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3259). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T03:43:46Z. --- Resubmission of #2173, which was closed because no title was shown stopping on these functions. OpenRCT2 (PPSA99728) stops at `cosh` on `main` 961b25fe (implemented by #3190). With #3190 applied, it stops next at `expm1` (`gqKfOiJaCOo`), per @babyhuey's run on #3190 ([comment](https://github.com/boykopovar/AnyPS5/pull/3190#issuecomment-6105046281)). So this becomes OpenRCT2's next stop as soon as #3190 lands, the same stacking as #2933 (`llroundf`) before #2932 (`atol`). `log1p`, `log1pf` and `expm1` are still absent on current `main`, and no open PR implements them. There is no code dependency on #3190: the branch is rebased onto current `main` and merges cleanly with #3190. Windows 11 (WinLibs GCC 15.2.0), Release: `guest_math` passes 3/3, and `check_conventions.py` and `pr_overlap.py --branch` pass. --- ### What Exports `log1p`, `log1pf` and `expm1`. Each one forwards to the C++ standard library, like `log` and `exp`. Only the variants that titles import are added. Titles: open-source homebrew from the #1578 catalog audit imports them from `libSceLibcInternal` (resolved through `libc.prx`): - `log1p`: PPSA68091 Ruffle, PPSA99169 RetroArch - `log1pf`: PPSA68091 Ruffle - `expm1`: PPSA99169 RetroArch, PPSA99764 Porpoise I haven't run any of these titles. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - New checks in `guest_math_tests`, next to `log10f`: - signed zero (`log1p(-0)` and `expm1(-0)` are `-0`); - limits: `log1p(-1) == -inf`, `log1p(inf) == inf`, `expm1(-inf) == expm1(-1000) == -1`; - NaN below the domain: `log1p(-2)`, `log1pf(-2)`; - reference values at 1; - small arguments that need the dedicated functions: `log1p(1e-300)`, `log1pf(1e-30f)` and `expm1(1e-300)` return their argument, and `log1p(1e-10)`/`expm1(1e-10)` are within 1e-25 of the exact values. `log(1 + x)` and `exp(x) - 1` give 0 or lose most digits there. - Mutation check: replacing any of the three with `log(1 + x)` or `exp(x) - 1` makes `guest_math` fail. - `cmake --build build --target libs`: the patched `libc.prx` exports all 3 NIDs. - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no overlap. This branch also merges cleanly with my #2158, #2166 and #2167. ### 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: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-11 03:44:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T03:44:09Z.


Progress report (961b25f → 1f94d93)

📈 System libraries: 86.02% (+0.02%, +3 implemented functions)

✅ 3 implemented
Library Name
libc expm1_nid_postfix
libc log1p_nid_postfix
libc log1pf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105130730 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3259#issuecomment-6105130730). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T03:44:09Z. --- <!-- progress-report --> ### Progress report (961b25f → 1f94d93) 📈 **System libraries**: 86.02% (+0.02%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libc | `expm1_nid_postfix` | | libc | `log1p_nid_postfix` | | libc | `log1pf_nid_postfix` | </details>
reyani-dev commented 2026-10-11 04:10:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T04:10:22Z.


Full Linux and Windows builds and tests for this head (1f94d93d), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (e28fbc27):

Job Result
linux failure; full build, ctest: 760/761 passed
windows success; full build, ctest: 765/765 passed
relinker (Linux, Windows, macOS) success

The one Linux failure, agc_unit_shadow, also fails on main itself (push run 38098335801); this PR only touches libc math and its tests.

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/38109323513

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105309558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3259#issuecomment-6105309558). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T04:10:22Z. --- Full Linux and Windows builds and tests for this head (`1f94d93d`), using the project's Build workflow. I can't start the upstream manual run, so I ran the same `build.yml` in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current `main` (`e28fbc27`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/38109323513/job/114381415276) | failure; full build, `ctest`: 760/761 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/38109323513/job/114381415285) | success; full build, `ctest`: 765/765 passed | | relinker (Linux, Windows, macOS) | success | The one Linux failure, `agc_unit_shadow`, also fails on `main` itself (push run [38098335801](https://github.com/boykopovar/AnyPS5/actions/runs/38098335801)); this PR only touches libc math and its tests. Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/38109323513
babyhuey commented 2026-10-11 04:32:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T04:32:44Z.


Checked with #3190 under this head (1f94d93d) on main 961b25fe, both merge cleanly. Linux (Ubuntu 24.04, GCC 13) and Windows 11 (WinLibs GCC 15.2), Release: guest_math passes 5/5 (--repeat until-fail:5) on both, with no warnings in Math.cpp or GuestMath.cpp.

OpenRCT2 (PPSA99728), Linux, catalog build with sce_module/libc.prx unwrapped:

  • with #3190: app.elf: symbol lookup error: app.elf: undefined symbol: gqKfOiJaCOo (expm1)
  • with #3190 and this PR: app.elf: symbol lookup error: app.elf: undefined symbol: 0hlfW1O4Aa4 (localeconv, #545)

On Windows the loader reports FAIL: unresolved ELF import oxMp8uPqa+U (pthread_set_name_np) from libkernel.prx (#3031) first for OpenRCT2, with and without these PRs, so the expm1 step only shows on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105463989 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3259#issuecomment-6105463989). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T04:32:44Z. --- Checked with #3190 under this head (1f94d93d) on `main` 961b25fe, both merge cleanly. Linux (Ubuntu 24.04, GCC 13) and Windows 11 (WinLibs GCC 15.2), Release: `guest_math` passes 5/5 (`--repeat until-fail:5`) on both, with no warnings in `Math.cpp` or `GuestMath.cpp`. OpenRCT2 (PPSA99728), Linux, catalog build with `sce_module/libc.prx` unwrapped: - with #3190: `app.elf: symbol lookup error: app.elf: undefined symbol: gqKfOiJaCOo` (`expm1`) - with #3190 and this PR: `app.elf: symbol lookup error: app.elf: undefined symbol: 0hlfW1O4Aa4` (`localeconv`, #545) On Windows the loader reports `FAIL: unresolved ELF import oxMp8uPqa+U (pthread_set_name_np) from libkernel.prx` (#3031) first for OpenRCT2, with and without these PRs, so the `expm1` step only shows on Linux.
adriadam10 commented 2026-10-11 07:17:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:17:05Z.


Checked log1p, log1pf and expm1 forward to std:: with the right float/double overloads, and guest_math passes on Linux. Without the change the new checks fail to link, so they exercise the new exports. OpenRCT2 stopping at expm1 after #3190 is confirmed in @babyhuey's run; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106593395 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3259#issuecomment-6106593395). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:17:05Z. --- Checked `log1p`, `log1pf` and `expm1` forward to `std::` with the right float/double overloads, and `guest_math` passes on Linux. Without the change the new checks fail to link, so they exercise the new exports. OpenRCT2 stopping at `expm1` after #3190 is confirmed in @babyhuey's run; merging.
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!3259
No description provided.