feat(libc): answer the remaining gamma and lgamma entry points #16438
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16438"
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 Opensource55 on 2026-11-06T17:46:03Z.
What
The
libcbundled with PPSA01341 v01.007.000 exports eight names this tree did not:lgamma_rEjL+gY1G2lklgammafi-ifjh3SLBUlgammaf_rRlGUiqyKf9Itgammab7J3q7-UABYgammaBD-xV2fLe2Mgamma_rq+AdV-EHiKcgammafsZ93QMbGRJYgammaf_rE3RYvWbYLgkEach NID is the hash its name carries under
tools/nid_names.py.Seven of the eight are the same two routines, and the module says so itself:
So
lgammais rewritten to forward throughlgamma_r— which is all it ever was — and the six names above become forwards of those two.signgamis the one this tree already exports.lgammaf_rtakes the same shape as the double routine one size down, including the shortcut the module takes at0x49d9c: at or below0x35000000the answer is-log|x|rather than a series. The magnitude is computed in double and narrowed, exactly astgammafandlgammalin this tree already do.tgammais the one real implementation — the module carries msun'se_gamma.c. This tree takes it from the host, astgammafalready does, keeping the three things the module's tail does differently:0xfff8000000000000) rather than whatever payload the host produces;EDOM;One deliberate difference from the module
lgammaf_rstores1into the sign at entry (49d71: movl $0x1,(%rdi)) and returns for a zero or a non-finite argument before touching it again, so the module answers1for-0.0. This tree'slgammahas always answered-1there, and an existing check inguest_mathpins that:The new names follow the tree rather than answering a third way, so all six agree with each other. If a maintainer would rather match the module, the change is in
LgammaSignplus that one existing assertion.Tested
Windows 10 22H2 (19045.6456), MinGW-W64 GCC 15.2.0 (ucrt, Release build), head
351f177d5bon top ofmain5779a4ea51; no title was run.guest_gammais new (core/libs/tests/GuestGamma.cpp) and covers:lgamma_rat1,2,0.5,10,-0.5and0, andlgammaf_rat the same shapes plus a tiny1e-30fthat has to take the-logshortcut;the sign reported through the pointer, for both widths:
0.5,10,±0,-0.5,-1.5,-2.5, the integers, and both infinities and a NaN;each alias agreeing bit for bit with the name it stands for, over ten double and seven float arguments, and reporting the same sign;
signgambeing written bygamma,gammafandlgammaf;tgamma's exact small integers,0.5,-0.5, and both zeroes answering signed infinities;tgamma's poles answering0xfff8000000000000withEDOM, and left-aloneerrnoelsewhere.Red side, with
tgammahanding straight to the host:guest_gammaaborts on the pole payload at line 110.Red side, with
gammadropping the sign it forwards:guest_gammaaborts at line 86.Green side:
guest_gammapasses in 0.01 s, andguest_math_elementaryandguest_math_exact— which carry the pre-existinglgammaandsigngamchecks the rewrite has to keep — still pass.tools/check_conventions.pyreportsAll conventions checks passed;objdump -p libc.prxlists all eight entries.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)Pull request closed