feat(libc): export the std::__sce_v2 _Exp and _FExp helpers #15501
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15501"
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-03T16:06:55Z.
What
Export the versioned
std::__sce_v2_Expand_FExpfrom libc._ZNSt8__sce_v24_ExpEPdds1UlKEANeY440x10B5C0_ZNSt8__sce_v25_FExpEPffsHypw5kMsuRs0x10B8A0The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).Both store
y · e^x · 2^scalethrough the pointer and return the versioned_Dscale/_FDscalecode. They are not the unversioned_Exp/_FExp. Run side by side, the unversioned exports in main differ from the module's versioned ones in about 60% of calls: they seterrnoon overflow and underflow, which the versioned module code never does, and they return other bits. SoVersionedExpfollows the module's versioned code:yis stored as is and returns 0;float) or above 1842 (229) return 0 or 1 with the module's underflow or overflow value, built ascopysign(min, y) · minorcopysign(max, y) · max;y; any other uses the module's rational approximation of 2·e^x, with one fused step per coefficient where the module fuses, and n - 1;_Dscale/_FDscale. Codes 0 and 1 are replaced with the underflow and overflow values above; other codes are returned.The constants live in a per-type struct of
constexprvalues.MathExact.cppis built with-frounding-math, so initializing afloatfrom adoubleliteral would happen at run time and raise the inexact flag, which the module does not do. When bothyand the ratio are NaNs, the module's multiply returnsy's NaN;ExpProductkeeps that order, since the compiler may swap the operands of a product.Tested
Windows x86-64, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, main4f41f4c375f. Exact tested commit:694cf319cf3.Built libc, libkernel, their NID-patched production libraries and the related tests. The new
guest_sce_v2_exp,public_headers,guest_math_exactandguest_dinkumware_float_bitspass, along with the otherguest_sce_v2_*CTests.The new test checks 25 rows per type, with the stored bits, the returned code and an unchanged
errno: 0, ±1, 1/2, 10, a factor of 3 and -2, zero and negative zero factors, arguments too small for the reduction, positive and negative scales, a large argument, overflowing, underflowing and subnormal scaled results, arguments just past and at the limits, ±infinity, and NaN arguments and factors. Every expected value was taken from the original module, not from this implementation.The original functions were loaded from the bundled module with its relocations applied. Their imports were bound by NID to this branch's libc and libkernel, with
__stack_chk_guardpointing at a local value; the module's owncopysignand versioned_Dscale/_FDscaleran from the module.Side by side with the patched production library, the stored value, the returned code,
errno, MXCSR and the x87 control and status words agree in all 10,000,000 calls over two seeds. The inputs mixed special values, random bit patterns, arguments around the limits and across the whole exponent range, factors of 1 and random factors, and scales of 0, small, large and random 16-bit values.Negative control: four lines were altered one at a time:
floatcoefficient was shortened.The new CTest failed on each, and the side-by-side run reported differences for each altered type. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run passed again.
Code conventions and
git diff --checkpass.tools/pr_overlap.pyread 1,724 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 these exports; #10780 only has a test namedCheckLongDoubleExpOverflowRounding. Merging each of the 36 with this branch and with main usinggit merge-treegives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484 and #15490.Not tested: Linux, macOS, 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