fix(libc): compute _Exp and _FExp as titles do #12037
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12037"
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 JJenkx on 2026-10-27T17:19:11Z.
What
_Expand_FExpcomputed finite results in a different form from thelibc.prxthat titles ship. As a result, about one result in five was one unit in the last place (ulp) away from the titles. The titles' disassembly (PPSA07923,_FExpat 0x8712d,_Expat 0x86a60) shows three differences:((Q(z) + g·P(z)) + 1) / ((Q(z) − g·P(z)) + 1).mainevaluated(w + g) / (w − g) · 2and decremented the exponent._Expuses its own ln 2 split (0x1.62e42f8p-1,0x1.be8e7bcd5e4f2p-27) and four coefficients.mainused a different coefficient set. These are now taken bit for bit from the binary._FExp's constants already matched.Special operands, cutoffs and flags are unchanged.
No audited title imports these two directly: none of the 22 relinker registries I checked lists them. They matter as building blocks. The titles'
_FSinhand_FCoshgo through_FExp, which is the gap the existing_FSinh/_FCoshdebt entry describes.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON, onmain3ae8209b64.Comparison: a scratch loader runs the decrypted
libc.prxof 11 titles natively. It calls their_Exp/_FExpby NID and compares the full result bits, return kind anderrnowith this build's._Exp, ±100 for_FExp). Multipliers are 0.25 to 3 and either sign, and offsets are −3 to 3.main_FExp/_Exp_FExp/_ExpThe second group's
libc.prxcontracts multiply-adds to FMA (PPSA13934's has 1,105vfmadd-family instructions), which portable C++ doesn't reproduce. Its remaining differences are one ulp.guest_dinkumware_internals: eight new checks pin titles' bits wheremaindiffered. That covers three ordinary arguments and one just above half an epsilon, for each function.Results:
guest_dinkumware_internalsandguest_mathpass in each of 3 runs onf94e461665. That commit has the same code and tests as the head79d65956a1, which only shortens the debt entry.main'sDinkumwareInternals.cppand these tests,guest_dinkumware_internalsfails at "_Exp rounds a negative exponent as titles do".python tools/check_conventions.py --base origin/mainandgit diff --checkpass.Not tested: a console, Linux and macOS, signaling NaNs, and non-default rounding or flush-to-zero modes.
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)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T19:44:23Z.
Review: APPROVED
Reviewed exact head
79d65956a182ed5f130e38d4eed9e51247f824a1. The implementation and pinned tests align with the cited bundledlibc.prxoperation order, constants and half-epsilon threshold. The report includes title-by-title oracle comparisons, a negative control showing the old implementation fails the new test, and records the remaining one-ulp differences for binaries that contract multiply-adds to FMA in the debt entry. The targetedguest_dinkumware_internalsandguest_mathtests are reported passing three times; hosted Windows and the current relinker, ASan, register-context and write-watch matrices pass. Conventions, intake, labels and report checks pass. Linux full-build checks were skipped, and I did not independently run the Windows title oracle or a console test.