Skip to content

feat(libc): implement __umodti3 - #4462

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:carry/libc-umodti3-4460
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:carry/libc-umodti3-4460

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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 fb23e85. 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

Kart PS5 (PPSA99611, Phi1ow/mkwii-ps5 v1.0.0-rc1) stops on it right
after __divti3. The related open PR boykopovar#4037 reports: "with this change it
passes `__divti3` and stops at `ELSr5qm4K1M` (`__umodti3`)".
PS5CEMU-HAR (PPSA99360) imports it too: tools/import_audit.py lists
ELSr5qm4K1M __umodti3 as absent from libSceLibcInternal.prx (registry
index 359), so the predicted stop is
"FAIL: unresolved ELF import ELSr5qm4K1M from libSceLibcInternal.prx".
libSceLibcInternal imports fall back to libc.prx, so the export lives in
libc beside __udivti3. compute_nid and aerolib (zecoxao/sce_symbols
2883963a) both give ELSr5qm4K1M = __umodti3.

__umodti3 is compiler-rt's lib/builtins/umodti3.c (llvm-project
0ee439b705e82a4fe20e266bc8fea96d0e60e1ec): the remainder that
__udivmodti4 leaves. The restoring division of SonyUdivti3 already
computes it, so the loop moves to SonyUdivmod128 and both helpers use
it. A zero divisor reaches a 64-bit divide in __udivmodti4 and traps on
x86-64; this throws instead, as __udivti3 does, and names the dividend.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Progress report (104bb65 → 23ac439)

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

✅ 1 implemented
Library Name
libc __umodti3_nid_postfix

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

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

@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
10 tasks done
@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@milescoviello milescoviello mentioned this pull request Oct 12, 2026
10 tasks done
@oneandonlydean
oneandonlydean merged commit d4ccf91 into boykopovar:main Oct 12, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libc: __umodti3 is absent (Kart PS5's stop after __divti3, PS5CEMU-HAR); fix branch ready

3 participants