Repository navigation
feat(libSceLibcInternal): implement _Hypot, _FHypot and _LHypot - #21704
Conversation
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d3e41cb996:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_libc_internal_scaled_hypot_testsbuilt cleanly. - CTest (
guest_libc_internal_scaled_hypot):1/1 Test #4072: guest_libc_internal_scaled_hypot ... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceLibcInternal/Export.cpp,core/libs/prx/libSceLibcInternal/include/MathInternals.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass. - Code reading:
- Verified pointer safety in ScaledHypot.cpp:11-14: StoreExponent validates the guest pointer via GuestCopyOut_nid_no_patch before writing 0 initially and before writing the computed scale, throwing std::invalid_argument on failure.
- Verified IEEE-754 special-value handling in ScaledHypot.cpp:19-22: NaN arguments are checked before infinity (so _Hypot(inf, NaN) returns NaN with exponent 0), infinities return +infinity with exponent 0, and two signed/unsigned zeros return +0.0 with exponent 0.
- Verified exponent scaling formula in ScaledHypot.cpp:23-28: std::frexp on the larger magnitude divided by 4 (truncated) times 2 (or 2 when 0) matches the firmware 13.42 measurements and avoids overflow/underflow before calling hypotf_nid_postfix / hypot_nid_postfix / hypotl_nid_postfix.
- Verified cross-platform LP64/LLP64 portability and ABI signatures in MathInternals.hpp and ScaledHypot.cpp: APS5_VABI is applied to _FHypot_nid_postfix, _Hypot_nid_postfix, and _LHypot_nid_postfix, and CMakeLists.txt configures Windows unwind and PATH properly.
- Verified AGENTS.md compliance and technical debt tracking in docs/dev/debt/changes/feat-libsce-libcinternal-hypot.md: stubs removed from Export.cpp are removed from the debt inventory and known last-ulp/fault differences are documented under Functional debt.
- Verified unit test coverage in GuestLibcInternalScaledHypot.cpp: tests cover _Hypot, _FHypot, and _LHypot across normal values, subnormals/near-maxima (1e308, 5e-324, 3e38f), signed zeros, NaN vs infinity precedence, and null exponent pointer handling.
Looks Good To Me
Progress report (86bf1f0 → d3773c6)📈 System libraries: 45.74% (+0.01%, +3 implemented functions) ✅ 3 implemented
Changed libraries (implemented exports)
|
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; its scaled result logic and exponent handling are consistent with the documented behavior, with remaining firmware-specific differences recorded as technical debt.
What I ran
- Read the prepared diff and all changed files at head
d3e41cb996e228e19d9125fb7fad67ac8c081282usingrepo_read.py. - No build or tests were run for this review.
Results
| Check | Result | Note |
|---|---|---|
| Changed code review | passed | All six changed files read |
| Build and tests | not run | Author-reported results are not independently verified |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported test runs and platform behavior were not independently verified. The firmware comparison was measured by the author on a PC, not a console; firmware-specific bit-level behavior, signalling NaNs, directed rounding, and exception flags remain unconfirmed. No excluded changed files were listed in the manifest.
To get this to a good state
Nothing is required.
d3e41cb to
2440525
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The implementation follows the documented measured exponent and special-value rules, while the firmware comparison remains incomplete and the reported tests were not run by this review.
What I ran
- Read the prepared description, commits, diff, manifest and all eight changed files at head
24405258b9d014f4339a8034ff60bf214d8ee1aa. - Inspected
GuestCopyOut_nid_no_patchdeclarations and the existinghypot_nid_postfiximplementation for targeted context. - No commands or tests were run in this review.
Results
| Check | Result | Note |
|---|---|---|
| Changed-file review | passed | All eight manifest files read |
| Targeted context | passed | Memory-write API and host hypot inspected |
| Tests in this review | not run | No test output available |
Findings
Blocking
None.
Non-blocking
core/libs/dev/debt/changes/feat-libsce-libcinternal-hypot.md:5documents that_Hypot,_FHypotand_LHypotmay differ from firmware in last-bit results, with only limited float and long-double measurements. The implementation’s generic use of the host hypot routines is consistent with that stated limitation. Consider adding more firmware comparisons when available, especially for float and long double.
Not verified
- No tests or build were run on this head. The test results in the PR description are author-reported, including the full suite result from before rebase.
- Windows, macOS, console behavior, signaling NaNs, directed rounding, and floating-point exception flags were not verified.
files.jsonwas not available through the reader; the manifest lists eight changed files, and all eight were read. No files were marked excluded in the manifest.
To get this to a good state
Nothing is required. Optional: expand the firmware comparisons for float and long double when measurements are available.
2440525 to
d3773c6
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
The implementation follows the stated scaling and special-value rules, but I could not run the reported checks in this review, so a formal approval is not justified.
What I ran
Reviewed head d3773c67a0872c44cf21487e1549de74e02f56a4. I read the prepared description, commits, manifest, and diff; used repo_read.py to inspect the changed implementation, declarations, build wiring, tests, and debt entries. No test or build command was run here. The author reports Linux x86-64 Debian/GCC 14.2 results; those were not independently verified.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Changed files and relevant hunks inspected |
| Reported test suite | not run | Results are author reported |
| Negative control | not run | Not independently checked |
Negative control
Could not run the reported mutation check that removes the NaN check.
Findings
Blocking
None.
Non-blocking
- The compatibility evidence is limited: the implementation intentionally differs by one ULP for
(0.1, 0.2), while_FHypotand_LHypotwere measured only for(3, 4)and(inf, NaN). The debt entry records these limits. Additional firmware comparisons would strengthen confidence in the edge cases and rounding behavior.
Sources
Not verified
No build, test, negative control, Windows or macOS run, title test, or physical-console behavior was verified here. I read the changed files listed in the manifest: core/libs/prx/libSceLibcInternal/CMakeLists.txt, core/libs/prx/libSceLibcInternal/Export.cpp (relevant changed hunks), core/libs/prx/libSceLibcInternal/ScaledHypot.cpp, core/libs/prx/libSceLibcInternal/include/MathInternals.hpp, core/libs/tests/GuestLibcInternalScaledHypot.cpp, and the three changed debt fragments. No changed file was excluded by the manifest.
To get this to a good state
Nothing is required. Optional: add broader firmware comparisons for float and long-double edge cases and rounding behavior.
|
Works on Windows, with two non-blocking points: a test gap for Existing runs: the author, Krille2004zzz, tested on Linux x86-64 (Debian, GCC 14.2) and lists Windows as not tested. PrivacyOnion approved at What this run adds
Code
Negative control and mutation Each row was built on the merge and run against
Tests The tests matching
Times are in seconds. Host
AI-assisted: yes |
What
Implements
_Hypot,_FHypotand_LHypotin libSceLibcInternal (newScaledHypot.cpp), replacing the parameterless stubs.(x, y, int* exponent)come from Dinkumware's public xmath.h declarations. No Dinkumware code is ported; the body is written from the measured behaviour.libSceLibcInternal.sprxmeasurements that @BunnyFl posted in feat(libc): implement _Hypot, _FHypot and _LHypot Dinkumware math helpers #12363 (module run natively on a PC, not a console). Thanks for those:exponentbefore anything elsefrexpexponent of the larger magnitude, divided by 4 (truncated), times 2, or 2 when that is 0, and the result ishypot/hypotf/hypotlof the arguments scaled by 2^-exponentstd::invalid_argumentwhere the module faults.Tested
Linux x86-64 (Debian, GCC 14.2.0), Release,
BUILD_TESTING=ON, on this branch rebased on currentmain. No title tested.guest_libc_internal_scaled_hypotpasses. It checks every feat(libc): implement _Hypot, _FHypot and _LHypot Dinkumware math helpers #12363 measured case: (3, 4), (-5, 12), (0, 0), (1e300, 1e300) giving1.7281329749791539e150and 498, (1e-310, 1e-310) giving7.584601526487318e-156and -514, (0.1, 0.2), (inf, NaN), (NaN, 1), plus (inf, 1), the float/long double (3, 4) and (inf, NaN) cases,result * 2^exponent == hypoton extra pairs, and the null exponent. Removing the NaN check makes it fail at_Hypot nan 1.ctest -R "libc_internal|dinkumware|public_headers": 159/159 pass.ctest -j8(before the rebase): 5846/5847 pass. The failure isguest_http2_transport, which also fails on unmodifiedmainon this machine. GPU tests were skipped (no Vulkan device).tools/check_conventions.py --base origin/main: all checks pass.tools/pr_overlap.py --branch: no shared exports. Six PRs that already conflict withmain(feat(libSceLibcInternal): implement the msun trigonometric kernels #13778, refactor(prx): name the libSceLibcInternal export aliases the NID databases resolve #17300, feat(libSceLibcInternal): construct the moneypunct facet and answer its members #18135, feat(libSceLibcInternal): implement std mutex object lifecycle and locking #19602, feat(libSceLibcInternal): implement Dinkum thread errors #20059, test(agc): keep the packed image table guard programs at different addresses #21255) could not be compared automatically. I compared their hunks by hand: none touches these functions or the changed lines.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)