fix(libc): compute j0f with FreeBSD msun's algorithm #16747
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16747"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T15:10:18Z.
What
libc
j0f(NIDRmE3aE8WHuY) returned the host's doublej0rounded to float:static_cast<float>(::j0(x)). The console's libc uses FreeBSD msun's floate_j0f.c, which evaluates its own float rational approximations, so results differ in the last bit even where no trigonometry is involved. For example, on glibc 2.43:main0x3f8000010x3f43e3fe0x3f43e3fd0x3f8000050x3f43e3fa0x3f43e3f90x3f8000090x3f43e3f70x3f43e3f6This PR ports
e_j0f.cat FreeBSD release/10.0.0, meaning__ieee754_j0fwith itspzerofandqzeroftables, into a newcore/libs/prx/libc/src/J0f.cpp. It keeps the upstream notice byte for byte, the coefficients, thresholds, evaluation order and thevolatile hugeread.j0,j1,jn,y0,y1andynfollow (Bessel.cpp, #7998).e_j0f.cchanges the tiny-input cutoffs (2^-13 and 2^-27 become 2^-9 and 2^-12), fixes the unreachable large-input shortcut, moves both table-selection thresholds (0x40f71c58→0x409173eb,0x4036db68→0x4036d917) and usessincosf. Without float measurements from the console, this PR stays with the family's revision, and the debt entry records that choice.|x| >= 2it calls this libc's msunsinf,cosfandsqrtf, not the host's.errnois untouched, as onmain.j1f,jnf,y0f,y1fandynfare unchanged; the only line removed fromMath.cppis the oldj0fwrapper.Tested
guest_math(core/libs/tests/GuestMath.cpp) gains 116 exact-bitj0fcases, and every existing assertion is kept. They cover:|x| < 2, the fourpzerof/qzeroftable ranges and the large-argument path;Expected values come from upstream
e_j0f.ccompiled locally with-O2 -ffp-contract=off -fno-builtin. 995,999 sampled finite inputs also matched that reference exactly.Linux x86-64 (Ubuntu 26.04, GCC 15, glibc 2.43, Release):
main,guest_mathfails withGuest j0f failed for 3f800001: 3f43e3fe expected 3f43e3fd;53acf73d72),guest_math,guest_math_elementary,guest_math_exactandguest_besselpass 4/4.Windows 11 (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release):
53acf73d72, with no compiler warnings;main'sMath.cpp,guest_mathfails with the sameGuest j0f failed for 3f800001: 3f43e3fe expected 3f43e3fd(70 mismatches).Mutation check: changing the
R02coefficient fails the new cases.python3 tools/check_conventions.py --base origin/main: no errors. The one warning is about the double Bessel debt entry, which was already over 1000 characters (1,439 onmain); this PR only removesj0ffrom it (1,434).python3 tools/pr_overlap.py --branch fix/libc-j0f-msun: no open PR changesj0f. 62 PRs were trial-merged, including my #16740 (sincos) and the open msun PRs, and #16740 merges cleanly. The PRs that gain a conflict:hypot3lline directly above the removed wrapper, so they conflict on that adjacent line. The export can be defined in only one place, so removing the wrapper is unavoidable.libc.mdentries.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T15:46:26Z.
Review: COMMENTED
A question on the source revision. I compared
J0f.cppwith FreeBSD'se_j0f.cat release/10.0.0: the 92 table constants,R02–S04, the thresholds and the evaluation order match. That part looks right. My question is whether 10.0.0 is the right revision for the console.The new debt entry says 10.0.0 matches "the established double Bessel family's source revision". The double entry places the console before
186f620727(2015-03-10). But FreeBSD's2656e946c8(2014-12-05), which is before that commit, changed both files together:e_j0.c, the tiny-input branch went fromone - 0.25*x*xtoone - x*x/4;e_j0f.c, the constants and the tiny-input cutoffs changed. 10.2.0 hasix<0x3b000000(2^-9) andix<0x39800000(2^-12), where 10.0.0 has 2^-13 and 2^-27.main'sBessel.cpp, which follows theJ03093718disassembly with the console's fused multiply-adds, computes that double branch asFused(x * x, -0.25, One)(line 188). That is the shapeone - x*x/4compiles to:x*xfirst, then fused with −0.25.one - 0.25*x*xwould givefma(0.25*x, -x, 1)instead. If line 188 mirrors the disassembly, and isn't just written that way, the console'se_j0.calready has2656e946c8. Itse_j0f.cwould then have the newer cutoffs and constants too, which this PR leaves out on purpose.Disassembling
j0finJ03093718, or the |x| < 2^-13 branch ofj0, would settle it. Until then, the entry might say the revision is unknown rather than matched.Read only; not built or run here.
AI-assisted: yes.