fix(libc): follow msun for asinhf #10002

Merged
MarcZX10 merged 4 commits from upstream-pr/10002 into main 2026-11-07 20:15:19 +00:00
MarcZX10 commented 2026-10-23 03:43:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T03:43:02Z.


What

asinhf currently forwards to the Windows host library. The #9707 survey reports 1,871,981 and 1,870,953 result-bit differences from the two bundled libc.prx builds over 20 million inputs. This ports FreeBSD msun's s_asinhf.c range handling and reuses the existing log1pf path for the small and moderate range.

The survey establishes host-versus-title differences, not the exact implementation used by every console library. The exact system libSceLibcInternal behavior and FMA-contracted libc.prx results remain unverified, as recorded in the debt entry.

Tested

  • Linux, GCC 12.2: compiled Math.cpp and GuestMath.cpp.
  • A focused Linux harness passed the boundary and special-value cases and 1,000,000 random finite inputs, comparing with double-precision std::asinh rounded to float (maximum difference 1 ULP).
  • MinGW GCC: GuestMath.cpp compiled.
  • The complete guest_math target was not run.
  • check_conventions.py, pr_overlap.py and git diff --check passed.

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:4977473395 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10002). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T03:43:02Z. --- ### What `asinhf` currently forwards to the Windows host library. The #9707 survey reports 1,871,981 and 1,870,953 result-bit differences from the two bundled `libc.prx` builds over 20 million inputs. This ports FreeBSD msun's `s_asinhf.c` range handling and reuses the existing `log1pf` path for the small and moderate range. The survey establishes host-versus-title differences, not the exact implementation used by every console library. The exact system `libSceLibcInternal` behavior and FMA-contracted `libc.prx` results remain unverified, as recorded in the debt entry. ### Tested - Linux, GCC 12.2: compiled `Math.cpp` and `GuestMath.cpp`. - A focused Linux harness passed the boundary and special-value cases and 1,000,000 random finite inputs, comparing with double-precision `std::asinh` rounded to float (maximum difference 1 ULP). - MinGW GCC: `GuestMath.cpp` compiled. - The complete `guest_math` target was not run. - `check_conventions.py`, `pr_overlap.py` and `git diff --check` passed. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 12:30:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:30:01Z.

Review: COMMENTED


Checked against main 87666fc5d6 and FreeBSD msun s_asinhf.c at release/9.0.0, 10.0.0, 11.4.0 and 12.0.0 (all identical to the pinned 5aa554c7 copy):

  • The thresholds (0x31800000, 0x4d800000, 0x40000000), ln2, huge and the three expressions match msun line by line, and the |x| <= 2 branch correctly goes through the existing msun log1pf path (AtanhfLog1p).
  • The two upper ranges still call the host's logf through std::log(float), while msun calls __ieee754_logf. Main already has msun's e_logf.c as logf_nid_postfix (Math.cpp:1025), which the debt entry records as bit-identical to the titles' libc.prx for all 2^32 arguments. Could those two calls use it, with a declaration as in DinkumwareInternals.cpp:23? In a Python float32 emulation of the msun chain, msun's logf and a correctly rounded logf give different asinhf results on about 1.4% of inputs in (2, 2^28] (e.g. 0x419999e4: 0x406984fe vs 0x406984ff) and about 0.2% above 2^28 (e.g. 0x55c5129d: 0x41fcfc3f vs 0x41fcfc3e). I couldn't run UCRT's logf, so I can't say which side it lands on at those points, but using the port removes the question.
  • The Near(..., 1e-6) checks wouldn't notice that difference; one or two exact-bit checks in those ranges would pin it.
  • git merge-tree against current main shows a conflict in core/libs/tests/GuestMath.cpp with the merged acoshf change (#10003). Keeping both check functions and both calls resolves it.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638239977 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10002#pullrequestreview-5638239977). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T12:30:01Z. **Review:** COMMENTED --- Checked against main 87666fc5d6 and FreeBSD msun `s_asinhf.c` at release/9.0.0, 10.0.0, 11.4.0 and 12.0.0 (all identical to the pinned 5aa554c7 copy): - The thresholds (`0x31800000`, `0x4d800000`, `0x40000000`), `ln2`, `huge` and the three expressions match msun line by line, and the `|x| <= 2` branch correctly goes through the existing msun `log1pf` path (`AtanhfLog1p`). - The two upper ranges still call the host's `logf` through `std::log(float)`, while msun calls `__ieee754_logf`. Main already has msun's `e_logf.c` as `logf_nid_postfix` (`Math.cpp:1025`), which the debt entry records as bit-identical to the titles' `libc.prx` for all 2^32 arguments. Could those two calls use it, with a declaration as in `DinkumwareInternals.cpp:23`? In a Python float32 emulation of the msun chain, msun's `logf` and a correctly rounded `logf` give different `asinhf` results on about 1.4% of inputs in (2, 2^28] (e.g. `0x419999e4`: `0x406984fe` vs `0x406984ff`) and about 0.2% above 2^28 (e.g. `0x55c5129d`: `0x41fcfc3f` vs `0x41fcfc3e`). I couldn't run UCRT's `logf`, so I can't say which side it lands on at those points, but using the port removes the question. - The `Near(..., 1e-6)` checks wouldn't notice that difference; one or two exact-bit checks in those ranges would pin it. - `git merge-tree` against current main shows a conflict in `core/libs/tests/GuestMath.cpp` with the merged acoshf change (#10003). Keeping both check functions and both calls resolves it. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!10002
No description provided.