feat(libc): export the std::__sce_v2 _Poly and _XLgamma helpers #15484
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15484"
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 Danigamer05 on 2026-11-03T14:47:15Z.
What
Export the versioned
std::__sce_v2_Polyand the three_XLgammaoverloads from libc._ZNSt8__sce_v25_PolyEdPKdiQKveql1SwSo0x10BA60_ZNSt8__sce_v28_XLgammaEfBEK4zTmR87w0x10D2E0_ZNSt8__sce_v28_XLgammaEde7wxmyU9QtE0x10D3D0_ZNSt8__sce_v28_XLgammaEeHX-r2mZEP1A0x10D4C0The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).The new code sits in
MathExact.cpp, beside the other__sce_v2math helpers:_Polyevaluates the table with one fused multiply-add per coefficient, as the module'svfmadd213sdloop does. When an operand is a NaN, the module returns the quieted NaN ofxfirst, then of the running value, then of the coefficient. The hostfmapicks another operand, soOperandOrderFmakeeps the host result and only chooses which NaN to return. NaNs are tested on their bits, because a floating-point compare would raise the denormal flag the module does not raise._XLgammais the module's six-term Lanczos series. It shifts by 5.5, sums the six coefficients overx + 1tox + 6, scales by √(2π) / x and subtracts(x + 5.5) - (x + 0.5) log(x + 5.5). The constants, operation order and precision follow each overload:floatuses thefloatconstants and starts the sum at 1;doublestarts the sum at 1.000000000190015 and fuses the last multiply-subtract;long doubleuses thedoubleconstants in x87 extended precision and does not fuse the last step, as the module does.One known difference remains, and the debt entry records it. Each overload calls this libc's
log,logfandlogl, as the module calls its own. Those are host functions, not the module's. They return other last bits for some arguments and do not raise the module's x87 invalid flag on negative arguments, so_XLgammainherits that difference. Matching them is a separate change tologitself.Tested
Windows x86-64 (AMD Zen 2), WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, main4f41f4c375f. Exact tested commit:5609e53b0e6.Built libc, libkernel, their NID-patched production libraries and the related tests. The new
guest_sce_v2_log_gamma,public_headers,guest_math_exactandguest_dinkumware_float_bitspass, along with the otherguest_sce_v2_*CTests.The new test checks:
_XLgammaoverload at 1, 2, 0.5, 3, 10, 0.25, 1.5, 100, 1e10, 1e300, 2^-20, ±0, -1, -2.5, 1e-300, the smallest subnormal, ±infinity, NaN, 7.25, 33 and 170.5, with the result bits anderrno(EDOM for negative and -0 arguments, ERANGE for infinities);_Polywith degrees -1 to 7 over a table holding a huge, a subnormal and ordinary coefficients;_PolyNaN order, with quiet and signaling NaNs inx, in the first coefficient and in later coefficients, and with an infinite first coefficient times zero.Every expected value was taken from the original module, not from this implementation. Rows where this libc's
logdiffers from the module's are left out of the_XLgammatables: 7.25 fordouble, 1 and 1e10 forlong double.The original functions were loaded from the bundled module with its relocations applied. Its imports were bound by NID to this branch's libc and libkernel, with
__stack_chk_guardpointing at a local value. The few imports with no provider would have stopped the run, and none was called.Side by side with the patched production library, comparing the result bits,
errno, MXCSR and the x87 control and status words:_Poly: identical in all 2,000,000 calls over two seeds, with random and specialx, degrees -2 to 14 and tables of random, scaled-down, special and zero coefficients._XLgamma: values anderrnoagree in 98.3% (double), 84% (long double) and 99.95% (float) of 1,000,000 calls each. The rest come fromlog: mostly the last bits, and for unnormal 80-bit arguments this libc'sloglreturns a NaN where the module's returns a number. The flags also differ on negative arguments, for the reason given above.log, the same formula was run in the test program with the module's ownlog,logfandlogl. It matched the module's_XLgammain every one of 6,000,000 calls over two seeds, flags included. Over those arguments, this libc'slog,logfandloglalone already differ from the module's in about 28%, 26% and 43% of calls once flags are counted.Negative control: five lines were altered one at a time:
_Polyreused a coefficient;_Polypreferred the running value's NaN overx's;x + 2;long doubleconstants were written aslong doubleliterals.The new CTest failed on each, and the side-by-side run reported more differences than the unaltered code for each altered function. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run were back to the numbers above.
Code conventions and
git diff --checkpass.tools/pr_overlap.pyread 1,708 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 36 branches that already conflict with main. None of them adds a line naming these exports or helpers. Merging each of the 36 with this branch and with main usinggit merge-treegives the same conflict blocks. #10780 also edits the top ofMathExact.cpp, so this change adds no include there. The branch also merges cleanly with #15336 and #15471.Not tested: Linux, macOS, an Intel host, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.
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