fix(libc): compute j0f, j1f, y0f and y1f with the console's msun revision #21013

Merged
kali113 merged 3 commits from upstream-pr/21013 into main 2026-11-16 16:33:47 +00:00
kali113 commented 2026-11-15 19:14:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kali113 on 2026-11-15T19:14:23Z.


What

j0f, j1f, y0f and y1f were FreeBSD msun's e_j0f.c and e_j1f.c at release/10.0.0. The libc debt file said the console's revision was unknown and probably an untagged 2014–2015 snapshot. This measures it and moves both files to that snapshot, a737ef56ab (only inline hints over 8192c85cb3). The change ports those commits' cutoffs: the tiny-input limits, the large-input shortcut at 2^49 and the pzerof/qzerof/ponef/qonef table thresholds.

How the revision was found. A payload on a PS5 (firmware 13.590.001) called the four functions from the system libSceLibcInternal.sprx by NID, on 26 arguments each, under MXCSR 0x1f80. I then compiled FreeBSD's e_j0f.c and e_j1f.c at every commit that touched them from release/10.0.0 to 2018, with msun's own sinf, cosf and logf, and compared bit patterns:

revision built with FMA built without FMA
release/10.0.0 to d300dc2302 4 of 104 differ (all y1f) 14 differ
8192c85cb3, a737ef56ab 0 of 104 differ 14 differ
186f620727 and later 6 differ: negative y0f/y1f give 0xffc00000, the console 0x7fc00000 18+ differ

So the system module is this revision built with fused multiply-adds. This PR keeps the code unfused, as the lgamma entry records for the libc.prx most titles bundle. That means AnyPS5 now equals FreeBSD at a737ef56ab, not the fused system module's last bit.

What changes for titles. I scanned every 256th float from 2^-31 to 2^61 (3,014,656 arguments). Against main, this changes:

  • j1f on 13,946 arguments, all between 2.5 and 7.6;
  • y1f on 254,057, across its range;
  • j0f on 64 and y0f on 47.

On that scan the new j0f and j1f equal FreeBSD's a737ef56ab bit for bit. y0f and y1f differ on about 250 arguments both before and after this PR. The remaining gap is between this libc's sinf/cosf ports and the msun 11.4 copies used in the comparison, and this PR does not change it.

The console also gave the negative-argument results the debt entry called unmeasured: y0f and y1f of -1, -3.5 and -34.5 return 0x7fc00000 with errno unchanged and no flags, and -inf returns a NaN with invalid. That is what this code already did, so the entry now records the measurement.

Tested

  • PS5, firmware 13.590.001: payload results for j0f, j1f, y0f, y1f, 26 arguments each, as above.
  • macOS 27.3, Apple M5 Pro, x86_64 Release under Rosetta: guest_bessel_tests and guest_math_tests pass.
    • Six rows of the j1f/y1f table changed, at the old thresholds 2.5 and 2.857 and at 2^17.
    • Rows were added on both sides of each new threshold.
    • Every expected value is from FreeBSD's a737ef56ab compiled locally, and the build agrees on all of them.
    • With main's J0f.cpp and J1f.cpp, guest_bessel_tests aborts at j1f(2.5).
  • Conventions: python3 tools/check_conventions.py --base origin/main passes. tools/debt_fold.py --check passes.
  • Not run: Linux, Windows, and titles' bundled libc.prx.

Open #18792 (jnf/ynf) calls j0f and j1f. If its tests pin arguments in the changed ranges, one of the two will need its expected values updated after the other merges.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5326189553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21013). Originally posted by [kali113](https://github.com/kali113) on 2026-11-15T19:14:23Z. --- ### What `j0f`, `j1f`, `y0f` and `y1f` were FreeBSD msun's `e_j0f.c` and `e_j1f.c` at release/10.0.0. The libc debt file said the console's revision was unknown and probably an untagged 2014–2015 snapshot. This measures it and moves both files to that snapshot, `a737ef56ab` (only inline hints over `8192c85cb3`). The change ports those commits' cutoffs: the tiny-input limits, the large-input shortcut at 2^49 and the `pzerof`/`qzerof`/`ponef`/`qonef` table thresholds. **How the revision was found.** A payload on a PS5 (firmware 13.590.001) called the four functions from the system `libSceLibcInternal.sprx` by NID, on 26 arguments each, under MXCSR 0x1f80. I then compiled FreeBSD's `e_j0f.c` and `e_j1f.c` at every commit that touched them from release/10.0.0 to 2018, with msun's own `sinf`, `cosf` and `logf`, and compared bit patterns: | revision | built with FMA | built without FMA | |---|---|---| | release/10.0.0 to `d300dc2302` | 4 of 104 differ (all `y1f`) | 14 differ | | `8192c85cb3`, `a737ef56ab` | **0 of 104 differ** | 14 differ | | `186f620727` and later | 6 differ: negative `y0f`/`y1f` give 0xffc00000, the console 0x7fc00000 | 18+ differ | So the system module is this revision built with fused multiply-adds. This PR keeps the code unfused, as the `lgamma` entry records for the `libc.prx` most titles bundle. That means AnyPS5 now equals FreeBSD at `a737ef56ab`, not the fused system module's last bit. **What changes for titles.** I scanned every 256th float from 2^-31 to 2^61 (3,014,656 arguments). Against `main`, this changes: - `j1f` on 13,946 arguments, all between 2.5 and 7.6; - `y1f` on 254,057, across its range; - `j0f` on 64 and `y0f` on 47. On that scan the new `j0f` and `j1f` equal FreeBSD's `a737ef56ab` bit for bit. `y0f` and `y1f` differ on about 250 arguments both before and after this PR. The remaining gap is between this libc's `sinf`/`cosf` ports and the msun 11.4 copies used in the comparison, and this PR does not change it. The console also gave the negative-argument results the debt entry called unmeasured: `y0f` and `y1f` of -1, -3.5 and -34.5 return 0x7fc00000 with `errno` unchanged and no flags, and `-inf` returns a NaN with invalid. That is what this code already did, so the entry now records the measurement. ### Tested - **PS5, firmware 13.590.001:** payload results for `j0f`, `j1f`, `y0f`, `y1f`, 26 arguments each, as above. - **macOS 27.3, Apple M5 Pro, x86_64 Release under Rosetta:** `guest_bessel_tests` and `guest_math_tests` pass. - Six rows of the `j1f`/`y1f` table changed, at the old thresholds 2.5 and 2.857 and at 2^17. - Rows were added on both sides of each new threshold. - Every expected value is from FreeBSD's `a737ef56ab` compiled locally, and the build agrees on all of them. - With `main`'s `J0f.cpp` and `J1f.cpp`, `guest_bessel_tests` aborts at `j1f(2.5)`. - **Conventions:** `python3 tools/check_conventions.py --base origin/main` passes. `tools/debt_fold.py --check` passes. - **Not run:** Linux, Windows, and titles' bundled `libc.prx`. Open #18792 (jnf/ynf) calls `j0f` and `j1f`. If its tests pin arguments in the changed ranges, one of the two will need its expected values updated after the other merges. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.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 (Claude Code)
copilot-pull-request-reviewer[bot] commented 2026-11-15 19:14:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-15T19:14:31Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5912376035 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21013#pullrequestreview-5912376035). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-15T19:14:31Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
PrivacyOnion commented 2026-11-16 01:26:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T01:26:28Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b856c64419:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_bessel_tests built cleanly.
  • CTest (guest_bessel):
    1/1 Test #1162: guest_bessel .....................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/src/J0f.cpp, core/libs/prx/libc/src/J1f.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #1162: guest_bessel .....................Subprocess aborted***Exception:   1.47 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified threshold updates in core/libs/prx/libc/src/J0f.cpp (PZero, QZero, j0f_nid_postfix, y0f_nid_postfix) and core/libs/prx/libc/src/J1f.cpp (POne, QOne, j1f_nid_postfix, y1f_nid_postfix) match FreeBSD msun revision a737ef56ab.
    • Verified special-case handling for NaNs, infinities, signed zeros, and negative finite arguments in j0f_nid_postfix, y0f_nid_postfix, j1f_nid_postfix, and y1f_nid_postfix.
    • Checked boundary test cases in core/libs/tests/GuestBessel.cpp against the updated bit-pattern cutoffs (0x4036d917, 0x409173eb, 0x58000000, 0x3b000000, 0x39800000, 0x39000000, 0x33000000).
    • Checked docs/dev/debt/changes/fix-libc-float-bessel-revision.md against the modified functions and maintainer feedback.
  • Concerns:
    • docs/dev/debt/changes/fix-libc-float-bessel-revision.md:1-9: The debt fragment updates [j1f and y1f] and [j0f], but omits a ## change [y0f] section. Because core/libs/prx/libc/src/J0f.cpp also updates y0f_nid_postfix (lines 73, 76, 126, 129, 221, 230) to FreeBSD msun revision a737ef56ab and y0f was measured on the console, the existing y0f entry in docs/dev/debt/libc.md (which states y0f follows release/10.0.0 with unmeasured console provenance and 10.0.0 thresholds) is now stale, as noted by maintainer oneandonlydean.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5914044474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21013#pullrequestreview-5914044474). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-16T01:26:28Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b856c64419`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_bessel_tests` built cleanly. - **CTest** (`guest_bessel`): ``` 1/1 Test #1162: guest_bessel ..................... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libc/src/J0f.cpp`, `core/libs/prx/libc/src/J1f.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #1162: guest_bessel .....................Subprocess aborted***Exception: 1.47 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified threshold updates in core/libs/prx/libc/src/J0f.cpp (PZero, QZero, j0f_nid_postfix, y0f_nid_postfix) and core/libs/prx/libc/src/J1f.cpp (POne, QOne, j1f_nid_postfix, y1f_nid_postfix) match FreeBSD msun revision a737ef56ab. - Verified special-case handling for NaNs, infinities, signed zeros, and negative finite arguments in j0f_nid_postfix, y0f_nid_postfix, j1f_nid_postfix, and y1f_nid_postfix. - Checked boundary test cases in core/libs/tests/GuestBessel.cpp against the updated bit-pattern cutoffs (0x4036d917, 0x409173eb, 0x58000000, 0x3b000000, 0x39800000, 0x39000000, 0x33000000). - Checked docs/dev/debt/changes/fix-libc-float-bessel-revision.md against the modified functions and maintainer feedback. - **Concerns**: - docs/dev/debt/changes/fix-libc-float-bessel-revision.md:1-9: The debt fragment updates `[j1f and y1f]` and `[j0f]`, but omits a `## change [y0f]` section. Because `core/libs/prx/libc/src/J0f.cpp` also updates `y0f_nid_postfix` (lines 73, 76, 126, 129, 221, 230) to FreeBSD msun revision `a737ef56ab` and `y0f` was measured on the console, the existing `y0f` entry in `docs/dev/debt/libc.md` (which states `y0f` follows `release/10.0.0` with unmeasured console provenance and 10.0.0 thresholds) is now stale, as noted by maintainer `oneandonlydean`. Requesting changes for the points above.
PrivacyOnion commented 2026-11-16 09:17:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T09:17:49Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 49fb02fd68:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_bessel_tests built cleanly.
  • CTest (guest_bessel):
    1/1 Test #1172: guest_bessel .....................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/src/J0f.cpp, core/libs/prx/libc/src/J1f.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #1172: guest_bessel .....................Subprocess aborted***Exception:   0.34 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified threshold updates in core/libs/prx/libc/src/J0f.cpp (PZero, QZero, j0f_nid_postfix, y0f_nid_postfix) and core/libs/prx/libc/src/J1f.cpp (POne, QOne, j1f_nid_postfix, y1f_nid_postfix) match FreeBSD msun revision a737ef56ab.
    • Verified special-case handling for NaNs, infinities, signed zeros, and negative finite arguments in j0f_nid_postfix, y0f_nid_postfix, j1f_nid_postfix, and y1f_nid_postfix.
    • Checked boundary test cases in core/libs/tests/GuestBessel.cpp against the updated bit-pattern cutoffs (0x4036d917, 0x409173eb, 0x58000000, 0x3b000000, 0x39800000, 0x39000000, 0x33000000).
    • Verified docs/dev/debt/changes/fix-libc-float-bessel-revision.md now includes the ## change [y0f] section alongside [j1f and y1f] and [j0f] as requested by maintainer oneandonlydean.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5917569779 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21013#pullrequestreview-5917569779). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-16T09:17:49Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `49fb02fd68`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_bessel_tests` built cleanly. - **CTest** (`guest_bessel`): ``` 1/1 Test #1172: guest_bessel ..................... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libc/src/J0f.cpp`, `core/libs/prx/libc/src/J1f.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #1172: guest_bessel .....................Subprocess aborted***Exception: 0.34 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified threshold updates in core/libs/prx/libc/src/J0f.cpp (PZero, QZero, j0f_nid_postfix, y0f_nid_postfix) and core/libs/prx/libc/src/J1f.cpp (POne, QOne, j1f_nid_postfix, y1f_nid_postfix) match FreeBSD msun revision a737ef56ab. - Verified special-case handling for NaNs, infinities, signed zeros, and negative finite arguments in j0f_nid_postfix, y0f_nid_postfix, j1f_nid_postfix, and y1f_nid_postfix. - Checked boundary test cases in core/libs/tests/GuestBessel.cpp against the updated bit-pattern cutoffs (0x4036d917, 0x409173eb, 0x58000000, 0x3b000000, 0x39800000, 0x39000000, 0x33000000). - Verified docs/dev/debt/changes/fix-libc-float-bessel-revision.md now includes the ## change [y0f] section alongside [j1f and y1f] and [j0f] as requested by maintainer oneandonlydean. Looks Good To Me
PrivacyOnion commented 2026-11-16 09:33:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T09:33:13Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against ad66a84863:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_bessel_tests built cleanly.
  • CTest (guest_bessel):
    1/1 Test #1172: guest_bessel .....................   Passed    0.00 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/src/J0f.cpp, core/libs/prx/libc/src/J1f.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #1172: guest_bessel .....................Subprocess aborted***Exception:   0.12 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified threshold updates in core/libs/prx/libc/src/J0f.cpp (PZero, QZero, j0f_nid_postfix, y0f_nid_postfix) and core/libs/prx/libc/src/J1f.cpp (POne, QOne, j1f_nid_postfix, y1f_nid_postfix) match FreeBSD msun revision a737ef56ab.
    • Verified special-case handling for NaNs, infinities, signed zeros, and negative finite arguments in j0f_nid_postfix, y0f_nid_postfix, j1f_nid_postfix, and y1f_nid_postfix.
    • Checked boundary test cases in core/libs/tests/GuestBessel.cpp against the updated bit-pattern cutoffs (0x4036d917, 0x409173eb, 0x58000000, 0x3b000000, 0x39800000, 0x39000000, 0x33000000).
    • Verified docs/dev/debt/changes/fix-libc-float-bessel-revision.md includes the ## change [y0f] section alongside [j1f and y1f] and [j0f] as requested by maintainer oneandonlydean.
    • Confirmed C++20 type safety, absence of undefined behavior, and full compliance with AGENTS.md rules.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5917758203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21013#pullrequestreview-5917758203). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-16T09:33:13Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `ad66a84863`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_bessel_tests` built cleanly. - **CTest** (`guest_bessel`): ``` 1/1 Test #1172: guest_bessel ..................... Passed 0.00 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libc/src/J0f.cpp`, `core/libs/prx/libc/src/J1f.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #1172: guest_bessel .....................Subprocess aborted***Exception: 0.12 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified threshold updates in core/libs/prx/libc/src/J0f.cpp (PZero, QZero, j0f_nid_postfix, y0f_nid_postfix) and core/libs/prx/libc/src/J1f.cpp (POne, QOne, j1f_nid_postfix, y1f_nid_postfix) match FreeBSD msun revision a737ef56ab. - Verified special-case handling for NaNs, infinities, signed zeros, and negative finite arguments in j0f_nid_postfix, y0f_nid_postfix, j1f_nid_postfix, and y1f_nid_postfix. - Checked boundary test cases in core/libs/tests/GuestBessel.cpp against the updated bit-pattern cutoffs (0x4036d917, 0x409173eb, 0x58000000, 0x3b000000, 0x39800000, 0x39000000, 0x33000000). - Verified docs/dev/debt/changes/fix-libc-float-bessel-revision.md includes the ## change [y0f] section alongside [j1f and y1f] and [j0f] as requested by maintainer oneandonlydean. - Confirmed C++20 type safety, absence of undefined behavior, and full compliance with AGENTS.md rules. Looks Good To Me
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!21013
No description provided.