feat(libc): implement _Hypot, _FHypot and _LHypot Dinkumware math helpers #12363

Closed
PrivacyOnion wants to merge 4 commits from upstream-pr/12363 into main
PrivacyOnion commented 2026-10-28 10:55:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-10-28T10:55:31Z.


What

Implement the PS5 3.20 Dinkumware scaled-hypotenuse helpers _Hypot, _FHypot, and _LHypot in libc (core/libs/prx/libc/src/DinkumwareInternals.cpp), taking (x, y, int* exponent), writing the scaling exponent *exponent, and returning the scaled mantissa via ScaledHypot derived from Dinkumware VC12 xmath.h and xxxhypot.h (retaining the verbatim P.J. Plauger notice at the top of DinkumwareInternals.cpp and recorded in docs/dev/debt/libc.md, and NaN checked before infinity), matching firmware 13.42 libSceLibcInternal.sprx measurements. Provenance: libSceLibcInternal.c in DNNDHH/PS5-3.20_Libs.

Tested

Windows 11, unit tests in core/libs/tests/GuestDinkumwareInternals.cpp verifying _Hypot, _FHypot, and _LHypot across all measured firmware 13.42 inputs ((3, 4), (-5, 12), (0.1, 0.2), (0, 0), (1e300, 1e300), (1e-310, 1e-310), (inf, NaN), (NaN, 1), (inf, 1), and null exponent rejection).

Ran locally on 3f865021bf:

$ ctest --test-dir build -R '^guest_dinkumware_internals$' --output-on-failure
    Start 592: guest_dinkumware_internals
1/1 Test #592: guest_dinkumware_internals .......   Passed    0.02 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.15 sec

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #11752, #12364
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5049286601 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12363). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-10-28T10:55:31Z. --- ### What Implement the PS5 3.20 Dinkumware scaled-hypotenuse helpers `_Hypot`, `_FHypot`, and `_LHypot` in `libc` (`core/libs/prx/libc/src/DinkumwareInternals.cpp`), taking `(x, y, int* exponent)`, writing the scaling exponent `*exponent`, and returning the scaled mantissa via `ScaledHypot` derived from Dinkumware [VC12 `xmath.h`](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/xmath.h) and [`xxxhypot.h`](https://github.com/bergsteiger/realwork/blob/19b446ce8ad2adf82ab8ce7988bc003221accad2/common/components/rtl/external/Embarcadero/DelphiBerlin/cpprtl/Source/dinkumware64/source/xxxhypot.h) (retaining the verbatim P.J. Plauger notice at the top of `DinkumwareInternals.cpp` and recorded in `docs/dev/debt/libc.md`, and NaN checked before infinity), matching firmware 13.42 `libSceLibcInternal.sprx` measurements. Provenance: [`libSceLibcInternal.c` in `DNNDHH/PS5-3.20_Libs`](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c). ### Tested Windows 11, unit tests in `core/libs/tests/GuestDinkumwareInternals.cpp` verifying `_Hypot`, `_FHypot`, and `_LHypot` across all measured firmware 13.42 inputs (`(3, 4)`, `(-5, 12)`, `(0.1, 0.2)`, `(0, 0)`, `(1e300, 1e300)`, `(1e-310, 1e-310)`, `(inf, NaN)`, `(NaN, 1)`, `(inf, 1)`, and null exponent rejection). Ran locally on `3f865021bf`: ``` $ ctest --test-dir build -R '^guest_dinkumware_internals$' --output-on-failure Start 592: guest_dinkumware_internals 1/1 Test #592: guest_dinkumware_internals ....... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 Total Test time (real) = 0.15 sec ``` ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #11752, #12364 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-28 17:28:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T17:28:00Z.

Review: APPROVED


Reviewed — looks good\n\nThe implementation, ABI declarations, debt notes, and edge-case tests were reviewed; the focused Linux/GCC test passed locally at this exact head, as did the Windows hosted job. Other platform behavior and console behavior remain unverified; no blocking issue found.\n\nReviewed head against base ; no blocking finding. This approval covers this exact diff only.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5686931940 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12363#pullrequestreview-5686931940). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T17:28:00Z. **Review:** APPROVED --- # Reviewed — looks good\n\nThe implementation, ABI declarations, debt notes, and edge-case tests were reviewed; the focused Linux/GCC test passed locally at this exact head, as did the Windows hosted job. Other platform behavior and console behavior remain unverified; no blocking issue found.\n\nReviewed head against base ; no blocking finding. This approval covers this exact diff only.
MarcZX10 commented 2026-10-28 17:29:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T17:29:05Z.

Review: APPROVED


Reviewed — looks good

The implementation, ABI declarations, debt notes, and edge-case tests were reviewed; the focused Linux/GCC test passed locally at this exact head, as did the Windows hosted job. Other platform behavior and console behavior remain unverified; no blocking issue found.

Reviewed head 817de5b106e25d6113d2e2823dc9669d1f28c984 against base 750cf6cf48; no blocking finding. This approval covers this exact diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5686946743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12363#pullrequestreview-5686946743). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T17:29:05Z. **Review:** APPROVED --- # Reviewed — looks good The implementation, ABI declarations, debt notes, and edge-case tests were reviewed; the focused Linux/GCC test passed locally at this exact head, as did the Windows hosted job. Other platform behavior and console behavior remain unverified; no blocking issue found. Reviewed head 817de5b106e25d6113d2e2823dc9669d1f28c984 against base 750cf6cf487f948017295b1f3717af6f886f0f85; no blocking finding. This approval covers this exact diff.
MarcZX10 commented 2026-10-29 09:21:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:21:59Z.

Review: CHANGES_REQUESTED


Re-review — changes requested for current-main integration

The scoped Dinkumware change remains consistent with the previously reviewed implementation. The new head adds the original P.J. Plauger notice to technical debt, records the implementation's known limits, and retains the three ABI declarations, scaled-hypot implementation, and edge-case tests. The author reports the exact-head guest_dinkumware_internals test passing and refreshed the conventions check.

The branch is still based on 750cf6cf, while current upstream main is aaccd0ba. Please refresh this small diff onto current main, preserve the declared #11752 and #12364 order, and rerun the focused Dinkumware test plus the convention/overlap checks on the exact rebased head. I did not rerun the test locally. This request concerns integration freshness; it does not identify a new defect in the scoped math implementation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5695411479 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12363#pullrequestreview-5695411479). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T09:21:59Z. **Review:** CHANGES_REQUESTED --- # Re-review — changes requested for current-main integration The scoped Dinkumware change remains consistent with the previously reviewed implementation. The new head adds the original P.J. Plauger notice to technical debt, records the implementation's known limits, and retains the three ABI declarations, scaled-hypot implementation, and edge-case tests. The author reports the exact-head `guest_dinkumware_internals` test passing and refreshed the conventions check. The branch is still based on 750cf6cf, while current upstream main is aaccd0ba. Please refresh this small diff onto current main, preserve the declared #11752 and #12364 order, and rerun the focused Dinkumware test plus the convention/overlap checks on the exact rebased head. I did not rerun the test locally. This request concerns integration freshness; it does not identify a new defect in the scoped math implementation.
MarcZX10 commented 2026-10-29 09:44:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:44:01Z.

Review: APPROVED


Re-checked — approved

The branch now includes current main aaccd0ba39 and preserves the declared dependency order #11752, then #12364. The scaled-hypot implementation, ABI declarations and edge-case tests are unchanged from the previously reviewed code; the new debt entry records the implementation limits and pinned source provenance.

The author reports guest_dinkumware_internals passing on exact head 4a9c566cfe60dafe169872fa43c6d07bd25e8962. The new conventions, eligibility, labels and report checks are pending. I did not run the test locally or validate console behavior. No blocking issue found; approval covers this exact head and the stated dependency order.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5695685112 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12363#pullrequestreview-5695685112). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T09:44:01Z. **Review:** APPROVED --- # Re-checked — approved The branch now includes current `main` `aaccd0ba39` and preserves the declared dependency order `#11752`, then `#12364`. The scaled-hypot implementation, ABI declarations and edge-case tests are unchanged from the previously reviewed code; the new debt entry records the implementation limits and pinned source provenance. The author reports `guest_dinkumware_internals` passing on exact head `4a9c566cfe60dafe169872fa43c6d07bd25e8962`. The new conventions, eligibility, labels and report checks are pending. I did not run the test locally or validate console behavior. No blocking issue found; approval covers this exact head and the stated dependency order.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12363
No description provided.