fix(libc): compute y0f with FreeBSD msun's algorithm #16866

Merged
AlexWhitehouse merged 1 commit from upstream-pr/16866 into main 2026-11-11 23:43:24 +00:00
AlexWhitehouse commented 2026-11-07 19:20:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T19:20:32Z.


What

libc y0f (NID +tfKv1vt0QQ) returned the host's double y0 rounded to float. The console's libc uses FreeBSD msun's float e_j0f.c, which defines both j0f and y0f, so the last bit differs. For example, y0f(1.0f) is 0x3db4c011 on main and 0x3db4c010 in msun. Here logf(1) is exactly 0, so the logarithm can't explain the difference.

This PR adds the y0f half of e_j0f.c at FreeBSD release/10.0.0 to the J0f.cpp that #16747 creates. That means __ieee754_y0f with its u00-u06 and v01-v04 coefficients, reusing that file's pzerof/qzerof tables and j0f.

  • Source and revision: it keeps upstream's thresholds and evaluation order, at the revision the double Bessel family (Bessel.cpp, #7998) follows. It calls this libc's msun logf, sinf, cosf and sqrtf.
  • Special values:
    • y0f(±0) keeps the measured −∞, with errno and exception flags unchanged.
    • Infinities and NaNs are checked first, as upstream and the double y0 do: y0f(+inf) is +0, and y0f(-inf) and y0f(NaN) go through 1 / (x + x * x).
    • Finite negative arguments return a quiet NaN without setting errno or raising invalid, as the measured double y0 does.
  • Change from main: on Linux, main set EDOM for negative arguments because glibc's y0 does. That came from the host, not from a console measurement. The float negative domain is unmeasured, and the new debt entry says so. y1f in my #16847 follows the same rule.
  • Removed: only the old y0f wrapper line is removed from Math.cpp.

Tested

  • guest_bessel (core/libs/tests/GuestBessel.cpp) gains 81 exact-bit y0f cases, each also checking that errno is unchanged. They cover:

    • both signs of every branch boundary: the 2^-27 tiny cutoff, the subnormal and |x| < 2 ranges, the four pzerof/qzerof table ranges, the x + x overflow guard and FLT_MAX;
    • ±0, +∞ and NaN payloads;
    • inputs where the host's rounded double differs from msun.

    Further checks cover no invalid or divide-by-zero for finite negatives, and invalid for -inf. Every existing assertion is kept. Expected values come from upstream e_j0f.c compiled locally with -O2 -ffp-contract=off -fno-builtin.

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

    • on #16747's head, guest_bessel fails with Guest y0f failed for 3f800000: 3db4c011, expected 3db4c010;
    • with this PR, guest_bessel, guest_math, guest_math_elementary and guest_math_exact pass 4/4;
    • after the rebase onto main 750815131d, which has #16747 and #16847, the same four tests pass 4/4 at 75fa632dac.
  • Windows 11: (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release):

    • the same four tests pass at e063d12cc0, with no compiler warnings in the changed files;
    • with #16747's J0f.cpp and Math.cpp, guest_bessel fails with the same Guest y0f failed for 3f800000: 3db4c011, expected 3db4c010.
  • Mutation check: flipping the sign of u01 fails the new cases (be856e6d for 1.0), before and after the rebase.

  • 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 on main; this PR only removes y0f from it.

  • python3 tools/pr_overlap.py --branch fix/libc-y0f-msun: no other PR implements y0f.

    • It lists #16747, which this PR built on; it has merged.
    • #11634 and #15095 edit neighbouring libc.md entries.
    • #15802, #15803, #15804 and #15807 (lifted-build support) rewrite Math.cpp lines next to the removed wrapper.
    • My #16847 (j1f/y1f) added tests next to the new ones in GuestBessel.cpp and edited the same debt line. It has merged, and this branch is rebased onto it with both sets of tests and entries kept.
    • #18122 adds libSceLibcInternal forwarders with the j0f and y0f NIDs that call libc's functions; it merges cleanly with this branch.

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 (#16747 merged on 2026-11-11; this branch is one commit on main)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5205054178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16866). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-07T19:20:32Z. --- ### What libc `y0f` (NID `+tfKv1vt0QQ`) returned the host's double `y0` rounded to float. The console's libc uses FreeBSD msun's float `e_j0f.c`, which defines both `j0f` and `y0f`, so the last bit differs. For example, `y0f(1.0f)` is `0x3db4c011` on `main` and `0x3db4c010` in msun. Here `logf(1)` is exactly 0, so the logarithm can't explain the difference. This PR adds the `y0f` half of [`e_j0f.c` at FreeBSD release/10.0.0](https://github.com/freebsd/freebsd-src/blob/release/10.0.0/lib/msun/src/e_j0f.c) to the `J0f.cpp` that #16747 creates. That means `__ieee754_y0f` with its `u00`-`u06` and `v01`-`v04` coefficients, reusing that file's `pzerof`/`qzerof` tables and `j0f`. - **Source and revision:** it keeps upstream's thresholds and evaluation order, at the revision the double Bessel family (`Bessel.cpp`, #7998) follows. It calls this libc's msun `logf`, `sinf`, `cosf` and `sqrtf`. - **Special values:** - `y0f(±0)` keeps the measured −∞, with `errno` and exception flags unchanged. - Infinities and NaNs are checked first, as upstream and the double `y0` do: `y0f(+inf)` is +0, and `y0f(-inf)` and `y0f(NaN)` go through `1 / (x + x * x)`. - Finite negative arguments return a quiet NaN without setting `errno` or raising invalid, as the measured double `y0` does. - **Change from `main`:** on Linux, `main` set `EDOM` for negative arguments because glibc's `y0` does. That came from the host, not from a console measurement. The float negative domain is unmeasured, and the new debt entry says so. `y1f` in my #16847 follows the same rule. - **Removed:** only the old `y0f` wrapper line is removed from `Math.cpp`. ### Tested - **`guest_bessel`** (`core/libs/tests/GuestBessel.cpp`) gains 81 exact-bit `y0f` cases, each also checking that `errno` is unchanged. They cover: - both signs of every branch boundary: the 2^-27 tiny cutoff, the subnormal and `|x| < 2` ranges, the four `pzerof`/`qzerof` table ranges, the `x + x` overflow guard and `FLT_MAX`; - ±0, +∞ and NaN payloads; - inputs where the host's rounded double differs from msun. Further checks cover no invalid or divide-by-zero for finite negatives, and invalid for `-inf`. Every existing assertion is kept. Expected values come from upstream `e_j0f.c` compiled locally with `-O2 -ffp-contract=off -fno-builtin`. - **Linux x86-64** (Ubuntu 26.04, GCC 15, glibc 2.43, Release): - on #16747's head, `guest_bessel` fails with `Guest y0f failed for 3f800000: 3db4c011, expected 3db4c010`; - with this PR, `guest_bessel`, `guest_math`, `guest_math_elementary` and `guest_math_exact` pass 4/4; - after the rebase onto `main` 750815131d, which has #16747 and #16847, the same four tests pass 4/4 at 75fa632dac. - **Windows 11:** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): - the same four tests pass at e063d12cc0, with no compiler warnings in the changed files; - with #16747's `J0f.cpp` and `Math.cpp`, `guest_bessel` fails with the same `Guest y0f failed for 3f800000: 3db4c011, expected 3db4c010`. - **Mutation check:** flipping the sign of `u01` fails the new cases (`be856e6d` for 1.0), before and after the rebase. - `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 on `main`; this PR only removes `y0f` from it. - **`python3 tools/pr_overlap.py --branch fix/libc-y0f-msun`:** no other PR implements `y0f`. - It lists #16747, which this PR built on; it has merged. - #11634 and #15095 edit neighbouring `libc.md` entries. - #15802, #15803, #15804 and #15807 (lifted-build support) rewrite `Math.cpp` lines next to the removed wrapper. - My #16847 (`j1f`/`y1f`) added tests next to the new ones in `GuestBessel.cpp` and edited the same debt line. It has merged, and this branch is rebased onto it with both sets of tests and entries kept. - #18122 adds `libSceLibcInternal` forwarders with the `j0f` and `y0f` NIDs that call libc's functions; it merges cleanly with this branch. ### 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 (#16747 merged on 2026-11-11; this branch is one commit on `main`) - [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!16866
No description provided.