feat(libc): implement _Rint, _FRint and _LRint Dinkumware math helpers #12364

Closed
PrivacyOnion wants to merge 1 commit from upstream-pr/12364 into main
PrivacyOnion commented 2026-10-28 10:57:46 +00:00 (Migrated from github.com)

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


What

Implement the missing PS5 3.20 math dispatch helpers _Rint, _FRint, and _LRint in libc, forwarding to rint, rintf, and rintl, with unit tests in core/libs/tests/GuestDinkumwareInternals.cpp and debt documentation in docs/dev/debt/libc.md. Provenance: libSceLibcInternal.c in DNNDHH/PS5-3.20_Libs.

Tested

Windows 11, unit tests in core/libs/tests/GuestDinkumwareInternals.cpp verifying _Rint, _FRint, and _LRint dispatch and rounding results (including ties-to-even 0.5 -> 0, 1.5 -> 2, 2.5 -> 2) against rint, rintf, and rintl. Validated with tools/check_conventions.py, tools/check_test_registration.py, and tools/pr_overlap.py.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5049314243 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12364). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-10-28T10:57:46Z. --- ### What Implement the missing PS5 3.20 math dispatch helpers `_Rint`, `_FRint`, and `_LRint` in `libc`, forwarding to `rint`, `rintf`, and `rintl`, with unit tests in `core/libs/tests/GuestDinkumwareInternals.cpp` and debt documentation in `docs/dev/debt/libc.md`. 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 `_Rint`, `_FRint`, and `_LRint` dispatch and rounding results (including ties-to-even `0.5 -> 0`, `1.5 -> 2`, `2.5 -> 2`) against `rint`, `rintf`, and `rintl`. Validated with `tools/check_conventions.py`, `tools/check_test_registration.py`, and `tools/pr_overlap.py`. ### Checklist - [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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
BunnyFl commented 2026-10-28 12:44:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-10-28T12:44:08Z.

Review: APPROVED


Approving head f8b89cba1e. I read the whole diff and ran firmware 13.42's helpers: the decrypted system libSceLibcInternal.sprx's _Rint, _FRint and _LRint, natively on a PC (data in the comment above).

  • They take one argument and return what rint, rintf and rintl return for every input tried (double bit for bit), including all the values the new tests check.
  • The three names hash to the declared NIDs TzxDRcns9e4, TLvAYmLtdVw and fJmOr59K8QY, which are the exports I ran.
  • Conventions and the Windows build pass on this head.

Only the default rounding mode was compared, so the debt entry's "not verified" still holds for flags and other modes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5682755435 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12364#pullrequestreview-5682755435). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-10-28T12:44:08Z. **Review:** APPROVED --- Approving head `f8b89cba1e`. I read the whole diff and ran firmware 13.42's helpers: the decrypted system `libSceLibcInternal.sprx`'s `_Rint`, `_FRint` and `_LRint`, natively on a PC (data in the comment above). - They take one argument and return what `rint`, `rintf` and `rintl` return for every input tried (double bit for bit), including all the values the new tests check. - The three names hash to the declared NIDs `TzxDRcns9e4`, `TLvAYmLtdVw` and `fJmOr59K8QY`, which are the exports I ran. - Conventions and the Windows build pass on this head. Only the default rounding mode was compared, so the debt entry's "not verified" still holds for flags and other modes.
MarcZX10 commented 2026-10-29 05:31:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:31:18Z.

Review: APPROVED


Re-checked — approved

The provenance and merge-sequencing questions have been resolved. The three exports are declared with their verified NIDs and each wrapper forwards to the matching existing rint helper. I found no blocking issue in the exact current diff.

What I ran

  • Reviewed exact head f8b89cba1e against current main 52c09d567d.
  • Ran git merge-tree --write-tree and git diff --check against current main.
  • Read the wrapper implementation, focused assertions, current debt entry, and the later reviewer comment about rounding-mode coverage.
  • I did not run the CTest target locally.

Results

Check Result
Current-main merge preview Clean
git diff --check Pass
Author/reviewer test evidence Windows guest_dinkumware_internals passes 3/3; firmware 13.42 helpers were compared natively on a PC with the matching standard rint functions for the tested values
Hosted checks Windows, register-context, relinker, ASan, write-watch, conventions, eligibility, labels, and report pass; Linux product job is skipped

Negative control

Not run locally. The firmware comparison is reviewer-reported and uses default rounding mode only.

Findings

No blocking issue found. One useful non-blocking test addition would be to exercise the wrappers under FE_DOWNWARD, FE_UPWARD, and FE_TOWARDZERO, and to check the sign of a rounded negative zero and FE_INEXACT. The current tests cover default-mode nearest-even values; the implementation delegates directly to the corresponding rint helper, and the debt entry continues to mark console exception behavior unverified.

The author records that #12364 can land before #12363 and #12365; those branches can then be rebased onto the landed helper changes.

Sources

Not verified

  • I did not rerun the tests, compare firmware exports, or validate on console hardware.
  • Other rounding modes and floating-point exception behavior were not compared against firmware.

To get this to a good state

No further change is required for this review. The additional rounding-mode, signed-zero, and exception assertions would strengthen the regression coverage if the behavior is claimed as verified.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693284959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12364#pullrequestreview-5693284959). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T05:31:18Z. **Review:** APPROVED --- # Re-checked — approved The provenance and merge-sequencing questions have been resolved. The three exports are declared with their verified NIDs and each wrapper forwards to the matching existing rint helper. I found no blocking issue in the exact current diff. ## What I ran - Reviewed exact head f8b89cba1efebdfc687f4acc29d9f4319827515b against current main 52c09d567d2fa453494dd720fcf53a98149468e4. - Ran git merge-tree --write-tree and git diff --check against current main. - Read the wrapper implementation, focused assertions, current debt entry, and the later reviewer comment about rounding-mode coverage. - I did not run the CTest target locally. ## Results | Check | Result | |---|---| | Current-main merge preview | Clean | | git diff --check | Pass | | Author/reviewer test evidence | Windows guest_dinkumware_internals passes 3/3; firmware 13.42 helpers were compared natively on a PC with the matching standard rint functions for the tested values | | Hosted checks | Windows, register-context, relinker, ASan, write-watch, conventions, eligibility, labels, and report pass; Linux product job is skipped | ## Negative control Not run locally. The firmware comparison is reviewer-reported and uses default rounding mode only. ## Findings No blocking issue found. One useful non-blocking test addition would be to exercise the wrappers under FE_DOWNWARD, FE_UPWARD, and FE_TOWARDZERO, and to check the sign of a rounded negative zero and FE_INEXACT. The current tests cover default-mode nearest-even values; the implementation delegates directly to the corresponding rint helper, and the debt entry continues to mark console exception behavior unverified. The author records that #12364 can land before #12363 and #12365; those branches can then be rebased onto the landed helper changes. ## Sources - [Implementations at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/f8b89cba1efebdfc687f4acc29d9f4319827515b/core/libs/prx/libc/src/DinkumwareInternals.cpp#L441-L452) - [Focused tests at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/f8b89cba1efebdfc687f4acc29d9f4319827515b/core/libs/tests/GuestDinkumwareInternals.cpp#L402-L410) - [Pinned PS5 3.20 export inventory for the three names and NIDs](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c#L16023) - [Independent firmware comparison and default-mode scope](https://github.com/boykopovar/AnyPS5/pull/12364#pullrequestreview-5691884410) ## Not verified - I did not rerun the tests, compare firmware exports, or validate on console hardware. - Other rounding modes and floating-point exception behavior were not compared against firmware. ## To get this to a good state No further change is required for this review. The additional rounding-mode, signed-zero, and exception assertions would strengthen the regression coverage if the behavior is claimed as verified.

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!12364
No description provided.