feat(libc): export the std::__sce_v2 multiprecision helpers #15471
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15471"
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:08:01Z.
What
Export the four
std::__sce_v2multiprecision helpers from libc. They hold an unsigned value as five 32-bit digits, each stored in a 64-bit word._ZNSt8__sce_v27_MP_GetEPyPPRfp98KWh00x10CB80_ZNSt8__sce_v27_MP_AddEPyyVXdN8rHxS4s0x10CB90_ZNSt8__sce_v27_MP_MulEPyyydNaphWn7TxE0x10CBF0_ZNSt8__sce_v27_MP_RemEPyyaP5bpilz7aQ0x10CC90The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).VersionedMultiprecision.cppfollows that module's operations:_MP_Getcombines the two low digits._MP_Addadds a 64-bit value and carries no further than the fifth digit._MP_Mulwrites the four-digit product of two 64-bit values and clears the fifth digit._MP_Remuses Knuth's algorithm D: it scales the dividend and divisor, reduces one digit at a time, and unscales. As in the module, it propagates a borrow through every upper digit and adds back into one digit only.Three inputs cannot behave as in the module, and the debt entry records them:
_MP_Remreads the stack word past its one-digit divisor and the word before the dividend. Its result then changes with the contents of those words and with the dividend's address, and in about half of the side-by-side calls it is not the remainder. Here the exact remainder is returned.None of the three arises for a non-zero divisor of at least 2^32 and a dividend of at most four digits, such as a 64-bit product plus a 64-bit addend. On those inputs the module's
_MP_Remreturned the exact remainder in every side-by-side call.Tested
Windows x86-64, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, main4f41f4c375f. Exact tested commit:c4d4acb9804.Built libc, libkernel, their NID-patched production libraries and the related tests. The new
guest_sce_v2_multiprecision,public_headers,guest_math_exactandguest_dinkumware_float_bitspass, along with the other selected CTests.The new test checks:
_MP_Getwith digits wider than 32 bits;_MP_Addcarrying into the last digit, stopping early, the largest addend and wide digits;_MP_Mulwith zero, the largest operands and either half of the multiplier zero;_MP_Remwith a zero dividend, a dividend shorter than or below the divisor, a top divisor digit of all ones (no scaling), normalized and small divisors, and three engine steps built with_MP_Muland_MP_Add.Every expected word was taken from the original module, not from this implementation. One-digit divisors are checked against the exact remainder, which a separate 128-bit loop computes.
The original functions were loaded from the bundled module with its relocations applied. Its
__stack_chk_guardwas bound to a local value; every other import would have stopped the run, and none was called.The originals then ran side by side with the patched production library on 15,875,432 calls over two seeds. The inputs were:
a * x + c.The six words around and in the array agree for every call, except
_MP_Remwith a divisor below 2^32 (600,729 calls). The module's own result was not the remainder in 311,656 of those, a count that changes between runs with the addresses involved. Changing only the word before the dividend, or only its address, changed the module's result. On two-digit divisors the remainders agree in all 3,274,703 calls. That includes the 36,912 calls, all with a non-zero fifth digit, where the module's result is not the remainder.Negative control: four lines were altered one at a time:
_MP_Add's carry stopped one digit early;_MP_Mulno longer cleared the fifth digit;_MP_Remskipped a digit whose top equals the divisor's top digit;The new CTest failed on each, and the side-by-side run flagged the altered function each time. 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,700 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 36 branches that already conflict with main. Only #13486 adds a line naming these helpers, a table row for the unversioned_ZSt7_MP_*exports, which are other NIDs. Merging each of the 36 with this branch and with main usinggit merge-treegives the same conflict blocks, and no block contains a line of this change. The branch also merges cleanly with #15098, #15099, #15210 and #15336.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