feat(libc): implement hypot and hypotf #1196
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1196"
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 MathiasDevelopes on 2026-10-07T17:12:07Z.
What
hypotandhypotfwere not exported, so a title importing them from libSceLibcInternal stopped at startup with an unresolved import (iz2shAGFIxc).Both now forward to
std::hypot, next to the other math functions inMath.cpp. That gives the C99 behaviour: no intermediate overflow or underflow, and infinity when either argument is infinite, even if the other is NaN.GuestMathchecks the plain case, both signs, arguments whose squares overflow (1e308and2e38f), infinity with NaN in either order, and NaN propagation.Tested
guest_mathpassestools/check_conventions.py --base mainpasseshypotf; without it, it stops at startup with the unresolved import, and with it, it gets past thatChecklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-07T17:12:14Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T17:13:31Z.
Progress report (
9619edf→2a253b3)📈 System libraries: 85.58% (+0.01%, +2 implemented functions)
✅ 2 implemented
hypot_nid_postfixhypotf_nid_postfixImported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-07T19:25:22Z.
Data point: PPSA03306 (Silt, Unity) imports
hypotf(iz2shAGFIxc). Onmain(cea1ef13) plus #1141, startup stops atFAIL: unresolved ELF import iz2shAGFIxc from libSceLibcInternal.prx. With this PR merged as well, every startup import resolves and the title starts running (IL2CPP opensMedia/MetadataandMedia/Resources). Windows 11, GCC 15.2.0, RTX 3070.Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-07T19:48:49Z.
Review: COMMENTED
I found a reproducible
hypotfexception difference ate84f43aceb8e32eb43b00349c47331695c1c66dcon Windows 11, WinLibs GCC 15.2.0 UCRT, Release. The existing GuestMath test passes, but the float overload losesFE_INVALIDfor a signaling NaN paired with infinity.Minimal check inside
GuestMath.cpp(add<bit>and<cfenv>, using the existinghypotf_nid_postfixdeclaration):Both versions return positive infinity. This PR's DLL produces
invalid == false; a retained original PS5 title's bundled libc routine sets it. Swapping the inputs reproduces the difference. Quiet NaN plus infinity leaves invalid clear, and(3, 4)returns 5 without invalid.This local one-line correction restores the observed exception on this toolchain:
An extended full GuestMath fixture fails against the unchanged PR DLL and passes with that correction. It covers signaling/quiet NaNs, both argument orders, all four rounding modes and retention of an existing division-by-zero flag. A separate small DLL-loading probe reproduced the two signaling failures and both controls again before this comment.
The broader private comparison executes 4,457 input pairs under 16 rounding/FTZ/DAZ combinations. The correction removes the 52 invalid-flag discrepancies per mode and preserves the PR's tested numeric results apart from NaN payload bits. Other exception-status differences remain; this is not a bit-exact claim.
The original reference is an isolated unchanged routine from PPSA03524/01.003.000, run on the Windows CPU without title initialization. Component builds reuse audited dependencies from main
3c054008. No console hardware, native Linux or gameplay result is claimed, and no proprietary code/data is included here. The existing implementation remains your contribution; this is a narrow follow-up finding. Tests and this report were prepared with AI assistance.Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-08T02:33:54Z.
Thanks @eliasbruno124-dev for the detailed report, it checks out.
std::hypot(float, float)goes to the CRT'shypotf, which returns +inf as soon as it sees an infinity and never touches the signaling NaN, so FE_INVALID was lost.Fixed in
2a253b37with your suggested correction:hypotfnow widens both arguments to double before callinghypot. The float-to-double conversion raises FE_INVALID and quiets the sNaN, sohypotf(sNaN, inf)returns +inf with the flag set in either argument order. I also added a case toGuestMath.cppthat checks both orders.I verified it with GCC and Clang on Linux, where the old code even returned NaN for this case. Quiet NaN plus infinity still leaves the flag clear,
(3, 4)still gives 5, and 20M random float pairs return bit-identical results before and after. I haven't rerun it on Windows/UCRT myself, so a confirmation against your fixture would be welcome.Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T02:57:31Z.
Another title this unblocks: Homebrew UI Lab (PPSA99050, blackbearreloaded/ps5-homebrew-ui) calls
hypotfwhen switching pages with L1/R1. Without it AnyPS5 aborts every time withhypotf iz2shAGFIxc not implemented. With this PR merged locally, page switching works andguest_mathpasses. Windows 11, MinGW GCC 15.2.0 (WinLibs r7), RTX 5070 Ti.To be clear about the setup: unmodified
maindoes not get UI Lab far enough to callhypotf. I tested on a local branch that carries several other pending fixes (rendering and pixel shader input changes I'm preparing as separate PRs), with this PR merged on top.Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-08T07:09:15Z.
Confirmed on Windows 11 with WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release, using a fresh complete library and relinker build of upstream main
dcbf089d28eddca63a95faaf33b9848454b632f5, which includes your correction in2a253b37.The current full
guest_mathfixture passes. I also rebuilt and ran the unchanged four-case DLL-loading reproducer from my earlier review against the newlibc.prx:The input bit patterns are unchanged (
0x7f800001for the signaling NaN and0x7fc00001for the quiet NaN). All four outputs match the corrected Windows results from the original report. The tested library hashes remain unchanged afterward.This confirms the requested Windows/UCRT exception behavior. I did not rerun the larger private numeric corpus, native Linux or console tests, and this is not a gameplay result. Tests and this follow-up were prepared with AI assistance.