Repository navigation
feat(libc): export the std::__sce_v2 binary scaling helpers - #15099
oneandonlydean merged 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Progress report (1d91f29 → 1c5093f)📈 System libraries: 26.64% (+0.01%, +6 implemented functions) ✅ 6 implemented
Changed libraries (implemented exports)
|
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
BunnyFl
left a comment
There was a problem hiding this comment.
Cross-checked against firmware 13.42's system libSceLibcInternal.sprx (sha256 a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285) as well as the title's bundled libc.prx. Read from disassembly only, not measured on a console:
- All six NIDs are exported there.
_LDscale(0x11e100) iscall 0xdc480, the versioned_Dscale._LDunscale(0xdb350) iscall 0xdb360, the versioned_Dunscale.
So the 8-byte long double forwarding matches the system module too. I didn't re-run the flag and errno comparison against the system module.
Build and test on Windows (WinLibs GCC, BUILD_TESTING=ON), PR merged into current main: guest_sce_v2_binary_scaling and guest_math_exact pass. On main the exports don't exist, and the test doesn't link.
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 test(libc): tokenize guarded buffers with high-byte delimiters #12887; it was moved before the rebase. It keeps exit 2 for 58 branches that already conflict with main (feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, fix(libc): follow measured wide printf behavior #5303, feat(libc): answer every libunwind cursor slot of an unwind context #6819, fix(libs): share Sony CRT handler and lconv state between libc and libSceAmpr #7081, feat(libc): scan 16-bit wide conversions on Linux #7386, feat(libc): support archive-backed stdio reads #7447, fix(libc): provide ASOBI_ROOT environment variable for title path resolution #7715, fix(libc): support character reads from random device streams #8150, fix(libc): use the Annex K size limit and codes of the PS5 libc, as measured on a PS5 #8965, fix(libc): follow snprintf_s and sscanf_s constraints as measured on a PS5 #9087, feat(libc): decode non-ASCII scanset members and non-BMP characters in the guest wide scanf #9340, fix(libc): follow a Windows symbolic link before .. in a guest path #9371, feat(libc): add the std::__sce_v2 thread start, timed wait, clock and processor count calls #9447, feat(libc): add std::__sce_v2::_Random_device, _Fiopen and setw #9526, fix(libc): restore syslog program-name fallback #9929, fix(libc): compute expf with FreeBSD msun's algorithm, as titles' libc.prx does #10113, fix(libc): compute erff and erfcf with fdlibm's algorithm, as titles' libc.prx does #10226, fix(libc): compute log with FreeBSD msun's algorithm, as titles' libc.prx does #10245, fix(libc): compute sin, cos and tan with FreeBSD msun's algorithm, as titles' libc.prx does #10250, fix(libc): compute asin and acos with FreeBSD msun's algorithm, as titles' libc.prx does #10253, fix(libc): compute pow with fdlibm's algorithm, as titles' libc.prx does #10265, fix(libc): compute exp2 with FreeBSD msun's algorithm, as titles' libc.prx does #10274, fix(libc): compute hypot with FreeBSD msun's algorithm, as titles' libc.prx does #10325, fix(libc): compute hypotf with FreeBSD msun's algorithm, as titles' libc.prx does #10328, fix(libc): set EDOM in fmod and fmodf where titles' libc.prx does #10345, fix(libc): compute remainder and remquo with fprem1, as titles' libc.prx does #10349, fix(libc): share multibyte state in fgetwc #10405, fix(libc): preserve tanh saturation flags and directed rounding #10506, fix(libc): preserve expm1 overflow rounding and exception flags #10510, fix(libc): preserve log1p pole and domain exception flags #10512, fix(libc): preserve atanh pole and domain exception flags #10565, fix(libc): convert Windows time zone names to UTF-8 #10987, fix(libc): compute acosl with FreeBSD msun's ld80 code as the bundled libc.prx does #11260, fix(libc): compute atanl with FreeBSD msun's ld80 code as the bundled libc.prx does #11262, fix(libc): compute exp2l with FreeBSD msun's ld80 code as the bundled libc.prx does #11266, fix(libc): bound narrow formatting fields #11332, fix(libc): compute cbrtl with FreeBSD msun's ld80 code as the bundled libc.prx does #11632, fix(libc): compute hypotl with FreeBSD msun's ld80 code as the bundled libc.prx does #11634, feat(libc): read 16-bit wide fields in fscanf on Linux #11724, feat(libc): accept positional arguments with wide scanf fields on Linux #11726, feat(libc): implement fcloseall with tracked stream lifetimes #11831, fix(libc): print unknown printf conversions and ' as titles' libc.prx does #11907, fix(libc): compute cosh with fdlibm's algorithm, as titles' libc.prx does #12122, fix(libc): print %C, %S and a zero %lc in the printf families as titles' libc.prx does #12397, fix(libc): read swscanf floating fields as titles' libc.prx does #12514, fix(libkernel): preserve DOS device names and trailing dots or spaces on Windows #12560, fix(libc): check asctime_s and ctime_s arguments as titles' libc.prx does #12574, fix(libc): report null gmtime_s and localtime_s arguments to the constraint handler #12593, fix(libc): check sprintf_s and vsprintf_s as titles' libc.prx does #12622, fix(libc): check swprintf_s and snwprintf_s as titles' libc.prx does #12627, feat(libkernel): cancel blocked POSIX reads with owned operations #12682, fix(libkernel): preserve blocking sockets over nonblocking native transport #12688, feat(libkernel): cancel blocked POSIX writes with partial progress #12700, feat(libkernel): support deferred cancellation in POSIX accept #12965, fix(libc): retain ordinary short character scan fields #13119, fix(libc): keep host logging on the console when a guest reopens stdout or stderr #13390, fix(libc): return EFAULT from getifaddrs for an unwritable list store #13804, docs(debt): separate entries with blank lines and drop derived export totals #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