feat(libc): implement __modti3 #6133

Merged
AkulTyagi11 merged 1 commit from upstream-pr/6133 into main 2026-10-17 19:06:43 +00:00
AkulTyagi11 commented 2026-10-14 23:02:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AkulTyagi11 on 2026-10-14T23:02:22Z.


What

Implements __modti3, the signed 128-bit integer modulo runtime helper complementing __divti3, __udivti3 and __umodti3.

  • Adds SonyModti3 in core/libs/prx/libc/include/SonyCrt.hpp using the existing bitwise 128-bit division engine.
  • Exports __modti3_nid_postfix in core/libs/prx/libc/src/RuntimeSupport.cpp.
  • Adds test cases in core/libs/tests/GuestCrt.cpp covering sign rules, large 128-bit powers, extremes, and zero-divisor trapping.
  • Documents the zero-divisor exception in docs/dev/debt/libc.md.

Tested

Windows 11, x86-64:

  • Standalone test of SonyModti3 and __modti3_nid_postfix verifying truncated remainder rules for both signs, zero dividend, INT128_MIN, INT128_MAX, large powers of 2, and zero divisor exception.
  • Full relinker test suite passed (167 / 167 ctest tests passed).
  • python tools/check_conventions.py --base origin/main passed with 0 errors.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4865728005 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6133). Originally posted by [AkulTyagi11](https://github.com/AkulTyagi11) on 2026-10-14T23:02:22Z. --- ### What Implements `__modti3`, the signed 128-bit integer modulo runtime helper complementing `__divti3`, `__udivti3` and `__umodti3`. - Adds `SonyModti3` in `core/libs/prx/libc/include/SonyCrt.hpp` using the existing bitwise 128-bit division engine. - Exports `__modti3_nid_postfix` in `core/libs/prx/libc/src/RuntimeSupport.cpp`. - Adds test cases in `core/libs/tests/GuestCrt.cpp` covering sign rules, large 128-bit powers, extremes, and zero-divisor trapping. - Documents the zero-divisor exception in `docs/dev/debt/libc.md`. ### Tested Windows 11, x86-64: - Standalone test of `SonyModti3` and `__modti3_nid_postfix` verifying truncated remainder rules for both signs, zero dividend, `INT128_MIN`, `INT128_MAX`, large powers of 2, and zero divisor exception. - Full relinker test suite passed (167 / 167 ctest tests passed). - `python tools/check_conventions.py --base origin/main` passed with 0 errors. ### 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] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-14 23:03:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T23:03:07Z.


Progress report (6239cef → ec2acea)

📈 System libraries: 88.7% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc __modti3_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6180408295 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6133#issuecomment-6180408295). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T23:03:07Z. --- <!-- progress-report --> ### Progress report (6239cef → ec2acea) 📈 **System libraries**: 88.7% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `__modti3_nid_postfix` | </details>
github-actions[bot] commented 2026-10-15 12:15:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:15:18Z.


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.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6044 core/libs/tests/GuestCrt.cpp
PR 6222 docs/dev/debt/libc.md
PR 6334 docs/dev/debt/libc.md
PR 6447 core/libs/prx/libc/src/RuntimeSupport.cpp
PR 6565 docs/dev/debt/libc.md
PR 6975 core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 7081 core/libs/prx/libc/include/SonyCrt.hpp
core/libs/tests/GuestCrt.cpp
docs/dev/debt/libc.md
PR 7201 core/libs/prx/libc/src/RuntimeSupport.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191806846 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6133#issuecomment-6191806846). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:15:18Z. --- <!-- pr-overlap --> 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. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/RuntimeSupport.cpp`<br>`docs/dev/debt/libc.md` | | [PR 5303](https://www.github.com/boykopovar/AnyPS5/pull/5303) | `docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestCrt.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `docs/dev/debt/libc.md` | | [PR 6334](https://www.github.com/boykopovar/AnyPS5/pull/6334) | `docs/dev/debt/libc.md` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libc/src/RuntimeSupport.cpp` | | [PR 6565](https://www.github.com/boykopovar/AnyPS5/pull/6565) | `docs/dev/debt/libc.md` | | [PR 6975](https://www.github.com/boykopovar/AnyPS5/pull/6975) | `core/libs/prx/libc/src/RuntimeSupport.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/prx/libc/include/SonyCrt.hpp`<br>`core/libs/tests/GuestCrt.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/RuntimeSupport.cpp` |
coltken95 commented 2026-10-15 21:03:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T21:03:53Z.


Tested on Linux x86-64 (Release build), with ec2acea5b merged into main 4eb91eacd:

  • With the PR: guest_crt passes.
  • With main's libc sources: guest_crt_tests can't resolve __modti3_nid_postfix (symbol lookup error: ... undefined symbol: __modti3_nid_postfix), since main doesn't export it.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6202233846 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6133#issuecomment-6202233846). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-15T21:03:53Z. --- Tested on Linux x86-64 (Release build), with ec2acea5b merged into main 4eb91eacd: - With the PR: `guest_crt` passes. - With main's libc sources: `guest_crt_tests` can't resolve `__modti3_nid_postfix` (`symbol lookup error: ... undefined symbol: __modti3_nid_postfix`), since main doesn't export it. AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-16 23:40:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T23:40:38Z.


Checked __modti3: the remainder takes the dividend's sign, INT128_MIN % -1 gives 0, and a zero divisor throws like the sibling helpers (documented in docs/dev/debt/libc.md). guest_crt passes and fails to build without the change. Confirmed on Linux by @coltken95. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226744424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6133#issuecomment-6226744424). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T23:40:38Z. --- Checked `__modti3`: the remainder takes the dividend's sign, `INT128_MIN % -1` gives 0, and a zero divisor throws like the sibling helpers (documented in `docs/dev/debt/libc.md`). `guest_crt` passes and fails to build without the change. Confirmed on Linux by @coltken95. Merging once the full Build is green.
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!6133
No description provided.