feat(libc): export the std::__sce_v2 binary scaling helpers #15099
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15099"
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-02T16:10:28Z.
What
Export six
std::__sce_v2Dinkumware binary scaling helpers from libc:_ZNSt8__sce_v27_DscaleEPdlgRj52WoTf5Q0xCB330_ZNSt8__sce_v28_FDscaleEPflwYwj23xDzPQ0xCF0F0_ZNSt8__sce_v28_LDscaleEPel+AqTGiV4vBA0x10D2D0_ZNSt8__sce_v29_DunscaleEPsPd1Vlo0OcN+sk0xCA210_ZNSt8__sce_v210_FDunscaleEPsPfr8xEVOsN7280xCA0C0_ZNSt8__sce_v210_LDunscaleEPsPeiAKatJKy6QY0xCA200The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).That module computes these helpers on the exponent and fraction bits:
_Dscalerounds a result that becomes subnormal to nearest even, returns an infinity on overflow and a signed zero on underflow._Dunscalereturns the significand in [1/2, 1) and its exponent.errnoor a floating-point exception flag.The new
ScaleFieldBitsandUnscaleFieldBitsinMathExact.cppdo the same with integer operations. The unversioned_Dscaleand_Dunscalealready here give the same values and codes for these inputs. They use hostldexpandfrexp, which raise the denormal, underflow, overflow, inexact or invalid flags that the original never raises, so the versioned exports do not forward to them. As in the original, whose_LDscaleand_LDunscalecall thedoubleforms, the__sce_v2long doubleforms take an 8-bytedouble.Tested
Windows x86-64, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, main5e85609d0b0152d14ae34d708d3237005ed311ca. Exact tested commit:1c5093f845ed7ec88cd5533cb14c86fdc8cf182f.The change was first tested on main
52e9ae6d57f37200c6b27234efb226b45d754528atef367efd7b803f96dfa7e8be523480663de73e0b, including the negative control below, then rebased onto the main above without conflicts; the diff of the change is the same apart from context lines. All four selected CTests and all 35,144,604 side-by-side vectors were run again at the tested commit and pass.Built libc, libkernel, their NID-patched production libraries and the
guest_sce_v2_binary_scaling,guest_math_exactandguest_dinkumware_float_bitstests. All three pass, as doespublic_headers.The new test checks 112 double and 96 float scaling cases and 42 unscaling cases, the
long doubleforms included. Inputs are zeros, subnormals, extremes, NaN and infinity, and exponents include the int64 limits. Every expected code, exponent and output was taken from the original module, not from this implementation.The original functions were loaded from the bundled module with its relocations applied. Its
__errorimport was bound to this libc and__stack_chk_guardto a local value; every other import would have stopped the run, and none was called. MXCSR was reset to0x1F80and the x87 unit reinitialized before every call. The originals then ran side by side with the patched production library, called by NID, on 35,144,604 vectors:Return code, output bits, exponent,
errno, the full MXCSR and the x87 control and status words agree for all six exports.Negative control, at the pre-rebase commit: two lines were temporarily altered. Rounding ties were taken upward, and the unscaled exponent was shifted by one. The new CTest failed, and the side-by-side run flagged all six exports and both tie sets. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and all four tests and all 35,144,604 vectors passed again.
Code conventions and
git diff --checkpass.tools/pr_overlap.pyread 1,748 open PRs at the tested commit and reports no confirmed overlap. An earlier placement of the CTest registration conflicted with #12887; it was moved before the rebase. It keeps exit 2 for 58 branches that already conflict with main (#5021, #5303, #6819, #7081, #7386, #7447, #7715, #8150, #8965, #9087, #9340, #9371, #9447, #9526, #9929, #10113, #10226, #10245, #10250, #10253, #10265, #10274, #10325, #10328, #10345, #10349, #10405, #10506, #10510, #10512, #10565, #10987, #11260, #11262, #11266, #11332, #11632, #11634, #11724, #11726, #11831, #11907, #12122, #12397, #12514, #12560, #12574, #12593, #12622, #12627, #12682, #12688, #12700, #12965, #13119, #13390, #13804, #14212). None of their added lines against their merge base contains the six names or NIDs. Merging each with this branch and with main usinggit merge-treegives the same conflict blocks, and no conflict block contains this change.Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, oracle 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
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T16:43:20Z.
Review: APPROVED
Cross-checked against firmware 13.42's system
libSceLibcInternal.sprx(sha256a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285) as well as the title's bundledlibc.prx. Read from disassembly only, not measured on a console:_LDscale(0x11e100) iscall 0xdc480, the versioned_Dscale._LDunscale(0xdb350) iscall 0xdb360, the versioned_Dunscale.So the 8-byte
long doubleforwarding matches the system module too. I didn't re-run the flag anderrnocomparison against the system module.Build and test on Windows (WinLibs GCC,
BUILD_TESTING=ON), PR merged into currentmain:guest_sce_v2_binary_scalingandguest_math_exactpass. Onmainthe exports don't exist, and the test doesn't link.