feat(libSceLibcInternal): implement the Dinkumware extended-precision helpers #16237
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16237"
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 Ducengarth on 2026-11-05T21:42:12Z.
What
Implement 26 Dinkumware extended-precision helpers in
libSceLibcInternal, replacing their parameterless throwing placeholders inExport.cpp:_Dtento,_FDtento,_LDtento:*value * 10^power, wherevaluepoints to a three-word extended-precision accumulator that is updated in place. On overflow or underflow they set the guesterrnotoERANGE(34) and OR 1 into*errorwhen it is not null._FXp_addh,_FXp_addx,_FXp_invx,_FXp_ldexpx,_FXp_movx,_FXp_mulh,_FXp_mulx,_FXp_setn,_FXp_setw,_FXp_sqrtx,_FXp_subx(float)._LXp_addh,_LXp_addx,_LXp_getw,_LXp_invx,_LXp_ldexpx,_LXp_movx,_LXp_mulh,_LXp_mulx,_LXp_setn,_LXp_setw,_LXp_sqrtx,_LXp_subx(long double).An extended-precision value is an array of words in decreasing magnitude, each holding at most half the significand (12 bits for
float, 26 fordouble, 32 forlong double), ended by a zero word. One template in the newExtendedPrecision.cppserves all three types.Written from the specified behaviour. The helpers do not follow any implementation. Prototypes come from Dinkumware's
xmath.h;longarguments arestd::int64_t, as in the PS5 ABI.WordBitsbits at a time, truncated toward zero, without bits below the smallest subnormal. The words the old value occupied after the new terminating zero are cleared._Xp_invxis long division of a power of two by the value, and_Xp_sqrtxtakes square-root digits two bits at a time, both to one word beyond the array. The scratch arrays of_Xp_mulx,_Xp_invxand_Xp_sqrtxare accepted and not used._Xp_setwsplits a value into its leading half-significand word and the rest; the last word of a short array takes the whole rest._Xp_setnfollows the documented split by 10000 forfloat._Dtentomultiplies by ten, or by one tenth cut to three base-2^WordBitsdigits, once for each unit of the power. It stops as soon as the value is zero or infinite, so a power ofLONG_MINunderflows instead of looping._LXp_getwand the reads inside_Dtentofollow the console's_FXp_getwfrom #14945, read from firmware 13.42: they add the fourth word when there are at least four.FE_INVALIDcases give V6.00's results.Differences from Dinkumware V6.00 that a caller can see, all recorded in
docs/dev/debt/libSceLibcInternal.md:_Xp_invxand_Xp_sqrtxwith Newton iterations. So the lowest word of a full array, and a one-word reciprocal or square root, can differ here. For example,_FXp_invxof{3}with one word gives the leading twelve bits of one third, not1.0f / 3._Xp_setwwrites one zero, where V6.00 writes two. Every helper stops reading at the first zero._Xp_mulxmultiplier reads only that word, and a word count below 1 does nothing in_Xp_movx,_Xp_addh,_Xp_invxand_Xp_sqrtx. V6.00 reads past the array or callsmemcpywith a negative size in these cases.Scope:
_FXp_getwis already inmain(#14945), and so are thedouble_Xp_*(ExtendedPrecisionDouble.cpp,c5e1e8a203). This PR does not touch them;_Dtentouses this file's own helpers._FAtan,_FSincos,_FTan,_FTgamma,_FLogpoly,_FQuad,_FQuadphand their_Landdoubleversions still throw: no source I found gives their signatures or behaviour.No title's trace or disassembly was used, and no export was measured on a PS5.
Overlap:
pr_overlap --branchon the branch merged withmainreports no other pull request with the same exports or new files. It could not compare 7 pull requests that conflict withmain(#13778, #13782, #14834, #15822, #17300, #18135, #18298). I scanned the lines each of them adds and removes: none touches these 26 names orExtendedPrecision.cpp. #17300 renames thedouble_Xp_subxplaceholder, which is already implemented inmain.Tested
Head
b543659248, withmaind4556df8a8merged in. Release builds on Windows 11 with MinGW-w64 GCC 15.2 (WinLibs) and on Ubuntu 24.04 under WSL2 with GCC 13.3. No title or homebrew.guest_libc_internal_extended_precisionpasses 3 of 3 runs. The test calls the 26 exports and_FXp_getwfrommain, and checks:setwsplits 20000 random floats into at most two exact half-width words and one zero; it also covers zero, one word, infinity, no room and subnormals.setnholds 32-bit integers exactly, and rounds the quotient by 10000 tofloatfirst for wider ones.addhkeeps exact sums of half-precision addends in decreasing words. It also covers cancellation, infinity,Inf - Inf(FE_INVALID), NaN, a full array, and a borrow across fourlong doublewords that keeps every word the same sign.mulhandmulxkeep exact or six-word products. They also cover the specials, a subnormal product kept exactly, and bits below the smallest subnormal being dropped.movx,ldexpx,addxandsubxbehave as specified.invxandsqrtxland within 2^-40 and 2^-36 of the exact result and read back within one ulp. A one-wordinvxkeeps the leading twelve bits of one third.sqrtxalso covers negative values, -0 and ±infinity._Dtentogives correctly rounded powers of ten from 10^-22 to 10^22, the one-tenth words for each type, overflow, underflow, a nullerrorpointer and a power ofINT64_MIN._LXp_getwadds a fourth word before rounding.setwof a value with a single word no longer has to write a second zero, and the one-wordinvxcheck gains one third.getw's fourth word, or splitting the lastsetwword;subx, andKeepBelowwithout its mask.objdump -pon the WindowslibSceLibcInternal.prxlists all 26 names, and_FXp_getw.python3 tools/check_conventions.py --base upstream/mainpasses.Not covered: macOS, the rest of the
libSceLibcInternalsuite after this merge ofmain, and a run inside a title.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