feat(libc): implement atanhf #5036

Merged
0xRickx merged 1 commit from upstream-pr/5036 into main 2026-10-13 09:23:00 +00:00
0xRickx commented 2026-10-13 09:07:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 0xRickx on 2026-10-13T09:07:15Z.


What

Dusklight (PPSA99305) imports atanhf (cPGyc5FGjy0) from libSceLibcInternal.prx. The libc.prx it bundles only has a zero-return stub for it, and no AnyPS5 library exports it. With #3651 (posix_spawn, its current stop on main) applied, Dusklight stops here:

FAIL: unresolved ELF import cPGyc5FGjy0 from libSceLibcInternal.prx

atanhf follows the one in the libc.prx bundled with PPSA28319, read from its disassembly, as sinhf and asinl already do. That is FreeBSD msun's e_atanhf.c calling msun's s_log1pf.c, both at 59bc2f09, the revision #3725 took expm1f and expf from. The log1pf paths for the positive arguments atanhf passes are inlined (AtanhfLog1p), because libc's exported log1pf is the host's; with the host's, 4.7% of the arguments in [0, 1) give different bits. For |x| > 1, the infinities and NaN, Sony's error helper raises FE_INVALID and sets errno to EDOM. For |x| = 1 it sets errno to ERANGE and returns ±inf. The technical-debt entry records that the system libSceLibcInternal is assumed to have the same code.

Tested

Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, on main 4bb2c7f3:

  • A scratch harness ran the atanhf code of the libc.prx bundled with PPSA28319 on the Windows host. For all 2^32 arguments it gives the same bits, errno and floating-point exceptions as this implementation. msun's own e_atanhf.c and s_log1pf.c built with the host compiler give the same bits.
  • guest_math gains CheckAtanhf: bit patterns for every branch reachable from atanhf, both signs, and the errno and exception behaviour. It fails with the host log1pf in place of the msun one, at input 3dcccccd.
  • Dusklight PPSA99305 0.2.0, catalog build, relinked with this main's relinker:
    • on main it stops at posix_spawnattr_init (44hlATrd47U, #3651);
    • with #3651 it stops at cPGyc5FGjy0 (atanhf);
    • with #3651 and this PR it loads, creates its swapchain and renders (about 210 GPU submissions per 10 s) for the whole 40 s run.
  • Full ctest: 1050/1051 passed (8 skipped on this machine). The one failure, patched_libraries, is main's libkernel_sys.prx load failure on Windows, fixed by #5025.
  • tools/check_conventions.py --base upstream/main passes.

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: #3651
  • Unblocks: PPSA99305 (no Game bring-up discussion yet)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4840942077 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5036). Originally posted by [0xRickx](https://github.com/0xRickx) on 2026-10-13T09:07:15Z. --- ### What Dusklight (PPSA99305) imports `atanhf` (`cPGyc5FGjy0`) from `libSceLibcInternal.prx`. The `libc.prx` it bundles only has a zero-return stub for it, and no AnyPS5 library exports it. With #3651 (`posix_spawn`, its current stop on `main`) applied, Dusklight stops here: ``` FAIL: unresolved ELF import cPGyc5FGjy0 from libSceLibcInternal.prx ``` `atanhf` follows the one in the `libc.prx` bundled with PPSA28319, read from its disassembly, as `sinhf` and `asinl` already do. That is FreeBSD msun's `e_atanhf.c` calling msun's `s_log1pf.c`, both at 59bc2f09, the revision #3725 took `expm1f` and `expf` from. The `log1pf` paths for the positive arguments `atanhf` passes are inlined (`AtanhfLog1p`), because libc's exported `log1pf` is the host's; with the host's, 4.7% of the arguments in [0, 1) give different bits. For |x| > 1, the infinities and NaN, Sony's error helper raises `FE_INVALID` and sets `errno` to `EDOM`. For |x| = 1 it sets `errno` to `ERANGE` and returns ±inf. The technical-debt entry records that the system `libSceLibcInternal` is assumed to have the same code. ### Tested Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, on `main` 4bb2c7f3: - A scratch harness ran the `atanhf` code of the `libc.prx` bundled with PPSA28319 on the Windows host. For all 2^32 arguments it gives the same bits, `errno` and floating-point exceptions as this implementation. msun's own `e_atanhf.c` and `s_log1pf.c` built with the host compiler give the same bits. - `guest_math` gains `CheckAtanhf`: bit patterns for every branch reachable from `atanhf`, both signs, and the `errno` and exception behaviour. It fails with the host `log1pf` in place of the msun one, at input `3dcccccd`. - Dusklight PPSA99305 0.2.0, catalog build, relinked with this `main`'s relinker: - on `main` it stops at `posix_spawnattr_init` (`44hlATrd47U`, #3651); - with #3651 it stops at `cPGyc5FGjy0` (`atanhf`); - with #3651 and this PR it loads, creates its swapchain and renders (about 210 GPU submissions per 10 s) for the whole 40 s run. - Full ctest: 1050/1051 passed (8 skipped on this machine). The one failure, `patched_libraries`, is `main`'s `libkernel_sys.prx` load failure on Windows, fixed by #5025. - `tools/check_conventions.py --base upstream/main` passes. ### 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 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: #3651 - [x] Unblocks: PPSA99305 (no Game bring-up discussion yet) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 09:07:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T09:07:45Z.


Progress report (2a2a3dc → 3fe04d4)

➖ System libraries: 88.38% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libc atanhf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142176272 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5036#issuecomment-6142176272). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T09:07:45Z. --- <!-- progress-report --> ### Progress report (2a2a3dc → 3fe04d4) ➖ **System libraries**: 88.38% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `atanhf_nid_postfix` | </details>
adriadam10 commented 2026-10-13 09:14:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T09:14:15Z.


Checked the atanhf + inlined log1pf paths against msun e_atanhf.c/s_log1pf.c at 59bc2f09 over all 2^32 float arguments on Linux (GCC, -ffp-contract=off): identical bits. guest_math passes with the new CheckAtanhf; conventions and the debt entry are fine. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142287730 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5036#issuecomment-6142287730). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T09:14:15Z. --- Checked the `atanhf` + inlined `log1pf` paths against msun `e_atanhf.c`/`s_log1pf.c` at 59bc2f09 over all 2^32 float arguments on Linux (GCC, `-ffp-contract=off`): identical bits. `guest_math` passes with the new `CheckAtanhf`; conventions and the debt entry are fine. Merging once the full Build is green.
LeandroLP23 commented 2026-10-13 09:24:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-13T09:24:44Z.


Windows check with both titles that stop here. Windows 11 (26300), Radeon 860M, WinLibs GCC 15.2.0, Release. Build: main 2a2a3dc65 + #3651 (7bb59f73b) + this PR (3fe04d4b7), titles relinked with --windows --trap-sdk-syscall-stubs.

  • guest_math: 3/3.
  • Dusklight (PPSA99305): gets past atanhf and runs the full 60 s (Dusklight | FPS: 23.18). With #3651 alone it stops at unresolved ELF import cPGyc5FGjy0.
  • Wind Waker (PPSA99309): gets past atanhf too, then faults after 2 s inside the title: 0xc0000005, rip PPSA99309.exe+0xddad12, read of 0x98. That's a separate stop, after this PR's point.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142466619 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5036#issuecomment-6142466619). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-13T09:24:44Z. --- Windows check with both titles that stop here. Windows 11 (26300), Radeon 860M, WinLibs GCC 15.2.0, Release. Build: `main` `2a2a3dc65` + #3651 (`7bb59f73b`) + this PR (`3fe04d4b7`), titles relinked with `--windows --trap-sdk-syscall-stubs`. - `guest_math`: 3/3. - **Dusklight (PPSA99305):** gets past `atanhf` and runs the full 60 s (`Dusklight | FPS: 23.18`). With #3651 alone it stops at `unresolved ELF import cPGyc5FGjy0`. - **Wind Waker (PPSA99309):** gets past `atanhf` too, then faults after 2 s inside the title: `0xc0000005`, rip `PPSA99309.exe+0xddad12`, read of `0x98`. That's a separate stop, after this PR's point. AI-assisted: yes (Claude Code)
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!5036
No description provided.