feat(libSceLibcInternal): implement std::_MP_Add, _MP_Get, _MP_Mul and _MP_Rem #14936
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14936"
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 PanagiotisKaraliolios on 2026-11-02T01:53:32Z.
What
Implements four pending
libSceLibcInternalexports, the Dinkumware multiprecision helpers thatstd::linear_congruential_engineuses whena * x + cdoes not fit in 64 bits:std::_MP_Get(unsigned long long*)_ZSt7_MP_GetPylrQSsTRMMr4std::_MP_Add(unsigned long long*, unsigned long long)_ZSt7_MP_AddPyyQfPuSqhub7ostd::_MP_Mul(unsigned long long*, unsigned long long, unsigned long long)_ZSt7_MP_MulPyyyGav1Xt1Ce+cstd::_MP_Rem(unsigned long long*, unsigned long long)_ZSt7_MP_RemPyyOzk+Z6QnlTYstl/src/multprec.cppof the first microsoft/STL release (Apache-2.0 WITH LLVM-exception). Its notice is kept at the top ofMultiPrecision.cpp. That file is Dinkumware's code, with the same algorithm as V6.00._MP_Mulis Knuth's Algorithm M and_MP_Remis Algorithm D. They give that code's results for words wider than a digit, a carry into the fifth word and a borrow propagated past the top digit.std::invalid_argumentonly where that code reads outside its arrays:_MP_Rem, a zero divisor or value, a nonzero fifth word, or a nonzero quotient digit with a divisor below 2^32 (the code readsv[-1]there).libSceLibcInternal.sprxexports all four NIDs (review)._nid_no_patchfunctions, as inAlignedNew.cpp. The declarations are in a newinclude/MultiPrecision.hpp, included fromlibSceLibcInternal.hpplikeMathInternals.hpp.InventoryExports.cppand the table hold 292 there, because #14659 removed three 3.20 entries without changing the count.tools/progress.py --module libSceLibcInternal: 95/1140 on main9ab6a281ea, 99/1140 with this PR.docs/dev/debt/libSceLibcInternal.md.Tested
Debian 13 on WSL2, GCC 14.2, full Release build with
BUILD_TESTING=ON.New test.
ctest --test-dir build -R guest_libc_internal_multi_precision -Vpassed in 0.01 s. It checks:_MP_Mulagainst a schoolbook product, for 49 operand pairs;_MP_Addcarries, including into and out of the fifth word, and_MP_Get;Mul,Add,Rem,Get) for three moduli, against a shift-and-addmulmod;Related tests. The 79 tests matching
libc_internal|public_headers|...|progress_report|test_registrationpassed.Full suite.
ctest -j 16passed 3146 of 3154 tests. The 8 failures are AGC driver and shader tests, and none comes from this change:agc_driver_division,agc_driver_f32_constant_factor_tininess,agc_driver_f32_denormal_flush,agc_driver_mullit_f32_denormal_modesandvector_constant_factor_tininessfail the same way on main93dbd0f82in the same build tree.agc_driver_pipeline_journal,agc_driver_runtime_formatted_storeandagc_driver_runtime_formatted_store_x2timed out under-j 16. They pass when rerun serially, on main and on this branch.Differential checks (outside the repository, all built with
-fsanitize=address,undefined):_MP_Reminputs with divisors of at least 2^32, plus random_MP_Mul,_MP_Addand_MP_Getinputs, against V6.00multprec.cppcompiled from the crt.vc12 source: no differences._MP_Reminputs, mostly with divisors below 2^32, classified by a bounds-checked copy of V6.00:Repository tools.
python3 tools/check_conventions.py --base upstream/mainandcore/libs/tests/test_public_headers.py --audit-onlypassed.python3 tools/pr_overlap.py --branch feat/libc-internal-multiprecisionfound no shared exports or new files.CMakeLists.txt, the inventory count line and the Functional section of the debt file. They are with #10953, #13778, #13782, #14373, #14401, #14659, #14834 and #14864.Not tested: Windows (MinGW) and macOS.
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-02T02:06:15Z.
Review: APPROVED
Windows 11, WinLibs GCC 15.2.0 r7, Release. Head 1dd458e616 (already on top of upstream/main
93dbd0f82a):guest_libc_internal_multi_precisionpasses.MultiPrecision.cpp: making the carry propagation loop in the add path never run (carry != 0 &&→false &&) fails the test, and so does dropping the borrow in the division step (borrow = TakeBorrow(...)→borrow = 0). So the carry-into-the-fifth-word and propagated-borrow cases you describe are covered.libSceLibcInternal.sprx(objdump -T; behaviour not run).Following V6.00 rather than the 2025 MSVC rewrite, with the difference recorded, matches the firmware's age.
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T19:08:47Z.
Review: APPROVED
@PanagiotisKaraliolios approved again at
761dc38931, thanks for the rebase.The rebase:
git range-diffagainst9f212960fechanges none of the implementation or test lines. The debt entry is unchanged too. It now followsmain's newinet_netofentry, as you wrote. The provenance header and themicrosoft/STLsource of record are as I checked them above.What I ran: head
761dc38931, which already containsmain9ab6a281ea. Windows 11, WinLibs GCC 15.2.0, Release:guest_libc_internal_multi_precisionandpublic_headerspass (2 of 2)._MP_Getreturning onlyvalue[0](core/libs/prx/libSceLibcInternal/MultiPrecision.cpp:112),guest_libc_internal_multi_precisionaborts (0xc0000409). So the tests read the high digit.tools/check_conventions.py --base upstream/main --headon the head: all checks passed.pr_overlap.py --branchon the head:CMakeLists.txtline 329), and #15584 and #15588 (the debt count on line 9). Whichever lands later needs a rebase.MultiPrecision.cppand none of this PR's commits; it only declares the same four NIDs as old inventory stubs (libSceLibcInternalInventory_247to_250), the ones this PR removes.