fix(libc): compute j1f and y1f with FreeBSD msun's algorithm #16847

Merged
AlexWhitehouse merged 1 commit from upstream-pr/16847 into main 2026-11-11 21:58:15 +00:00
AlexWhitehouse commented 2026-11-07 18:07:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T18:07:25Z.


What

libc j1f (NID uVXcivvVHzU) and y1f (NID gklG+J87Pq4) returned the host's double j1/y1 rounded to float. The console's libc uses FreeBSD msun's float e_j1f.c, which evaluates its own float rational approximations, so the last bit differs. For example, on glibc 2.43:

call main msun
j1f(0x3fa00000) (1.25) 0x3f02b835 0x3f02b834
y1f(0x3fc00000) (1.5) 0xbed31a1e 0xbed31a1f

This PR ports e_j1f.c at FreeBSD release/10.0.0 (__ieee754_j1f, __ieee754_y1f and their ponef/qonef tables) into a new core/libs/prx/libc/src/J1f.cpp. It keeps the upstream notice byte for byte, the coefficients, thresholds, evaluation order and the volatile huge read.

  • Revision: release/10.0.0, the revision the repo's double Bessel family follows (Bessel.cpp, #7998) and that my #16747 uses for j0f.
  • Large arguments and logs: for |x| >= 2, and for y1f's logarithm, it calls this libc's msun sinf, cosf, sqrtf and logf, not the host's.
  • Special values:
    • y1f(±0) keeps the measured −∞, with errno and exception flags unchanged, as GuestBessel's existing zero checks require.
    • Infinities and NaNs are checked first, as upstream and the double y1 do: y1f(+inf) is +0, and y1f(-inf) and y1f(NaN) go through 1 / (x + x * x).
    • Finite negative arguments return a quiet NaN without setting errno or raising invalid, as the measured double y1 does. The float functions' negative domain is unmeasured, and the new debt entry says so.
  • Other functions: j0f, jnf, y0f and ynf are unchanged. The only lines removed from Math.cpp are the two old wrappers.

Tested

  • guest_bessel (core/libs/tests/GuestBessel.cpp) gains exact-bit j1f and y1f cases for both signs of 36 inputs, and every existing assertion is kept. They cover:

    • both sides of every branch boundary: the 2^-27 and 2^-54 tiny cutoffs, |x| < 2, the four ponef/qonef table ranges, the y1f 2^17 shortcut and the x + x overflow guard;
    • ±0, ±∞ and NaN payloads;
    • unchanged errno on every case;
    • no invalid or divide-by-zero for finite negative y1f, and invalid for y1f(-inf).

    Expected values come from upstream e_j1f.c compiled locally with -O2 -ffp-contract=off -fno-builtin.

  • Linux x86-64 (Ubuntu 26.04, GCC 15, glibc 2.43, Release):

    • on main, guest_bessel fails with Guest j1f failed for 3fa00000: 3f02b835, expected 3f02b834;
    • with this PR, guest_bessel, guest_math, guest_math_elementary and guest_math_exact pass 4/4.
  • Windows 11: (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release):

    • the same four tests pass at b82016e1b1, with no compiler warnings in the changed files;
    • with main's Math.cpp and CMakeLists.txt, guest_bessel fails with the same Guest j1f failed for 3fa00000: 3f02b835, expected 3f02b834.
  • Mutation check: changing r00 from -0.0625 to -0.06 fails the new cases (3f03eec5 instead of 3f02b834).

  • python3 tools/check_conventions.py --base origin/main: no errors. The one warning is about the shared host-results entry, which was already over 1,000 characters (1,439 on main); this PR only removes j1f and y1f from it (1,422), and the new j1f and y1f entry is under the limit.

  • python3 tools/pr_overlap.py --branch fix/libc-j1f-y1f-msun: no open PR changes j1f or y1f.

    • My #16747 (j0f) removes the adjacent wrapper line and adds its source and debt entry at the same spots, so it conflicts textually. Whichever merges second rebases; the two are otherwise independent.
    • #11634 (hypotl) edits the same shared debt line.
    • #15802, #15803, #15804 and #15807 (lifted-build support) rewrite the hypot3l line above the removed wrappers.
    • The remaining PRs it could not compare touch other parts of libc.md or CMakeLists.txt. I checked them by hand, and none changes these functions.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5204476473 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16847). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-07T18:07:25Z. --- ### What libc `j1f` (NID `uVXcivvVHzU`) and `y1f` (NID `gklG+J87Pq4`) returned the host's double `j1`/`y1` rounded to float. The console's libc uses FreeBSD msun's float `e_j1f.c`, which evaluates its own float rational approximations, so the last bit differs. For example, on glibc 2.43: | call | `main` | msun | |---|---|---| | `j1f(0x3fa00000)` (1.25) | `0x3f02b835` | `0x3f02b834` | | `y1f(0x3fc00000)` (1.5) | `0xbed31a1e` | `0xbed31a1f` | This PR ports [`e_j1f.c` at FreeBSD release/10.0.0](https://github.com/freebsd/freebsd-src/blob/release/10.0.0/lib/msun/src/e_j1f.c) (`__ieee754_j1f`, `__ieee754_y1f` and their `ponef`/`qonef` tables) into a new `core/libs/prx/libc/src/J1f.cpp`. It keeps the upstream notice byte for byte, the coefficients, thresholds, evaluation order and the `volatile huge` read. - **Revision:** release/10.0.0, the revision the repo's double Bessel family follows (`Bessel.cpp`, #7998) and that my #16747 uses for `j0f`. - **Large arguments and logs:** for `|x| >= 2`, and for `y1f`'s logarithm, it calls this libc's msun `sinf`, `cosf`, `sqrtf` and `logf`, not the host's. - **Special values:** - `y1f(±0)` keeps the measured −∞, with `errno` and exception flags unchanged, as `GuestBessel`'s existing zero checks require. - Infinities and NaNs are checked first, as upstream and the double `y1` do: `y1f(+inf)` is +0, and `y1f(-inf)` and `y1f(NaN)` go through `1 / (x + x * x)`. - Finite negative arguments return a quiet NaN without setting `errno` or raising invalid, as the measured double `y1` does. The float functions' negative domain is unmeasured, and the new debt entry says so. - **Other functions:** `j0f`, `jnf`, `y0f` and `ynf` are unchanged. The only lines removed from `Math.cpp` are the two old wrappers. ### Tested - **`guest_bessel`** (`core/libs/tests/GuestBessel.cpp`) gains exact-bit `j1f` and `y1f` cases for both signs of 36 inputs, and every existing assertion is kept. They cover: - both sides of every branch boundary: the 2^-27 and 2^-54 tiny cutoffs, `|x| < 2`, the four `ponef`/`qonef` table ranges, the `y1f` 2^17 shortcut and the `x + x` overflow guard; - ±0, ±∞ and NaN payloads; - unchanged `errno` on every case; - no invalid or divide-by-zero for finite negative `y1f`, and invalid for `y1f(-inf)`. Expected values come from upstream `e_j1f.c` compiled locally with `-O2 -ffp-contract=off -fno-builtin`. - **Linux x86-64** (Ubuntu 26.04, GCC 15, glibc 2.43, Release): - on `main`, `guest_bessel` fails with `Guest j1f failed for 3fa00000: 3f02b835, expected 3f02b834`; - with this PR, `guest_bessel`, `guest_math`, `guest_math_elementary` and `guest_math_exact` pass 4/4. - **Windows 11:** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): - the same four tests pass at b82016e1b1, with no compiler warnings in the changed files; - with `main`'s `Math.cpp` and `CMakeLists.txt`, `guest_bessel` fails with the same `Guest j1f failed for 3fa00000: 3f02b835, expected 3f02b834`. - **Mutation check:** changing `r00` from `-0.0625` to `-0.06` fails the new cases (`3f03eec5` instead of `3f02b834`). - `python3 tools/check_conventions.py --base origin/main`: no errors. The one warning is about the shared host-results entry, which was already over 1,000 characters (1,439 on `main`); this PR only removes `j1f` and `y1f` from it (1,422), and the new `j1f and y1f` entry is under the limit. - **`python3 tools/pr_overlap.py --branch fix/libc-j1f-y1f-msun`:** no open PR changes `j1f` or `y1f`. - **My #16747 (`j0f`)** removes the adjacent wrapper line and adds its source and debt entry at the same spots, so it conflicts textually. Whichever merges second rebases; the two are otherwise independent. - **#11634 (`hypotl`)** edits the same shared debt line. - **#15802, #15803, #15804 and #15807** (lifted-build support) rewrite the `hypot3l` line above the removed wrappers. - The remaining PRs it could not compare touch other parts of `libc.md` or `CMakeLists.txt`. I checked them by hand, and none changes these functions. ### 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) - [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 🤖 Generated with [Claude Code](https://claude.com/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!16847
No description provided.