feat(libc): implement __umodti3 #4462

Merged
milescoviello merged 1 commit from upstream-pr/4462 into main 2026-10-12 18:27:07 +00:00
milescoviello commented 2026-10-12 12:28:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-12T12:28:13Z.


What

Fixes #4460. Carries @screamm's fix branch from that issue (screamm:feat/libc-umodti3, 2d3ac3d5), keeping the commit and its authorship, as the issue invites.

libc lacks __umodti3 (NID ELSr5qm4K1M). Kart PS5 (PPSA99611) stops on it right after __divti3 (#4037 reports the stop), and PS5CEMU-HAR (PPSA99360) imports it too. The division loop of SonyUdivti3 moves into a shared SonyUdivmod128 helper that returns the quotient and the remainder; SonyUdivti3 behaves as before and SonyUmodti3 returns the remainder, as compiler-rt's umodti3.c does. A zero divisor throws and names the dividend, as __udivti3 throws. The export sits in libc beside __udivti3, since libSceLibcInternal imports fall back to libc.prx. A TechnicalDebt entry sits beside the __udivti3 one.

Since the branch was cut, #4037 (__divti3) merged and touched the same two spots, as the issue expected. I resolved the conflict when cherry-picking: SonyCrt.hpp keeps SonyDivti3 after the new helpers (it calls SonyUdivti3), and in GuestCrt.cpp the new cases follow the __divti3 ones, with their maximum renamed to unsignedMaximum because __divti3's tests already declare a maximum in the same scope. Nothing else changed.

Tested

  • From the issue: Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release: guest_crt 3/3 and 606/606 of ctest -E "^agc_driver_|^video_out_flip".
  • Linux, added for this carry: Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main fb23e85f. guest_crt passes, and with main's SonyCrt.hpp and RuntimeSupport.cpp it does not build (the export does not exist there). All 304 guest_* tests pass.
  • Title run by @Nixitov on the same export (Windows 11, MinGW-w64 GCC 15.2.0, comment on #4519): Kart PS5 (PPSA99611), which stops at FAIL: unresolved ELF import ELSr5qm4K1M from libc.prx on main, gets past it and stops at gacfOmO8hNs (ceil).
  • tools/check_conventions.py --base upstream/main passes.

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 in TechnicalDebt
  • 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: PPSA99611 (Kart PS5), its stop after __divti3, verified by the title run above; I found no Game bring-up discussion for it
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4829401516 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4462). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-12T12:28:13Z. --- ### What Fixes #4460. Carries @screamm's fix branch from that issue (`screamm:feat/libc-umodti3`, `2d3ac3d5`), keeping the commit and its authorship, as the issue invites. libc lacks `__umodti3` (NID `ELSr5qm4K1M`). Kart PS5 (PPSA99611) stops on it right after `__divti3` (#4037 reports the stop), and PS5CEMU-HAR (PPSA99360) imports it too. The division loop of `SonyUdivti3` moves into a shared `SonyUdivmod128` helper that returns the quotient and the remainder; `SonyUdivti3` behaves as before and `SonyUmodti3` returns the remainder, as compiler-rt's `umodti3.c` does. A zero divisor throws and names the dividend, as `__udivti3` throws. The export sits in libc beside `__udivti3`, since `libSceLibcInternal` imports fall back to `libc.prx`. A TechnicalDebt entry sits beside the `__udivti3` one. Since the branch was cut, #4037 (`__divti3`) merged and touched the same two spots, as the issue expected. I resolved the conflict when cherry-picking: `SonyCrt.hpp` keeps `SonyDivti3` after the new helpers (it calls `SonyUdivti3`), and in `GuestCrt.cpp` the new cases follow the `__divti3` ones, with their `maximum` renamed to `unsignedMaximum` because `__divti3`'s tests already declare a `maximum` in the same scope. Nothing else changed. ### Tested - From the issue: Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release: `guest_crt` 3/3 and 606/606 of `ctest -E "^agc_driver_|^video_out_flip"`. - Linux, added for this carry: Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` fb23e85f. `guest_crt` passes, and with `main`'s `SonyCrt.hpp` and `RuntimeSupport.cpp` it does not build (the export does not exist there). All 304 `guest_*` tests pass. - Title run by @Nixitov on the same export (Windows 11, MinGW-w64 GCC 15.2.0, [comment on #4519](https://github.com/boykopovar/AnyPS5/pull/4519#issuecomment-6128613355)): Kart PS5 (PPSA99611), which stops at `FAIL: unresolved ELF import ELSr5qm4K1M from libc.prx` on `main`, gets past it and stops at `gacfOmO8hNs` (`ceil`). - `tools/check_conventions.py --base upstream/main` passes. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: PPSA99611 (Kart PS5), its stop after `__divti3`, verified by the title run above; I found no Game bring-up discussion for it - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-12 12:29:30 +00:00 (Migrated from github.com)

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


Progress report (104bb65 → 23ac439)

➖ System libraries: 86.25% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libc __umodti3_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6124282055 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4462#issuecomment-6124282055). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T12:29:30Z. --- <!-- progress-report --> ### Progress report (104bb65 → 23ac439) ➖ **System libraries**: 86.25% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `__umodti3_nid_postfix` | </details>
github-actions[bot] commented 2026-10-12 13:00:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T13:00:42Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4164 core/libs/prx/libc/src/RuntimeSupport.cpp L190
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6124778455 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4462#issuecomment-6124778455). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T13:00:42Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4164 | `core/libs/prx/libc/src/RuntimeSupport.cpp` [L190](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/libs/prx/libc/src/RuntimeSupport.cpp#L190) | | |
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!4462
No description provided.