feat(libc): implement __divti3 #4037

Merged
Nixitov merged 1 commit from upstream-pr/4037 into main 2026-10-12 12:20:26 +00:00
Nixitov commented 2026-10-11 21:56:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-11T21:56:54Z.


What

Implement the guest __divti3 (__int128 signed division) export in libc, alongside the existing __udivti3. Kart PS5 (PPSA99611) imports XU4yLKvcDh0 (__divti3) and stops at start-up on main:

FAIL: unresolved ELF import XU4yLKvcDh0 from libc.prx

With this change the title gets past it and stops at its next missing import, ELSr5qm4K1M (__umodti3).

SonyDivti3 divides the operands' magnitudes through SonyUdivti3 and gives the quotient the sign of the operands, i.e. truncation toward zero as the compiler runtime does. A zero divisor throws, as __udivti3 does; INT128_MIN / -1 wraps to INT128_MIN.

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.

  • guest_crt passes: cmake --build build --target libc guest_crt_tests && ctest --test-dir build -R "^guest_crt$".
  • Kart PS5 (PPSA99611, Phi1ow/mkwii-ps5 release v1.0.0-rc1, asset Kart-PS5.zip), eboot.bin unwrapped from its SELF and relinked with the built relinker --windows: on main it stops at FAIL: unresolved ELF import XU4yLKvcDh0 from libc.prx; with this change it passes __divti3 and stops at ELSr5qm4K1M (__umodti3).
  • python tools/check_conventions.py --base origin/main passes.
  • Note: current main does not build libkernel on Windows (Socket.cpp: 'HostPoll' was not declared in this scope), unrelated to this change; the runs above used main with #4021 applied. This PR does not depend on #4021.
  • Not tested on Linux or macOS.

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4822670168 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4037). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-11T21:56:54Z. --- ### What Implement the guest `__divti3` (`__int128` signed division) export in libc, alongside the existing `__udivti3`. Kart PS5 (PPSA99611) imports `XU4yLKvcDh0` (`__divti3`) and stops at start-up on `main`: ``` FAIL: unresolved ELF import XU4yLKvcDh0 from libc.prx ``` With this change the title gets past it and stops at its next missing import, `ELSr5qm4K1M` (`__umodti3`). `SonyDivti3` divides the operands' magnitudes through `SonyUdivti3` and gives the quotient the sign of the operands, i.e. truncation toward zero as the compiler runtime does. A zero divisor throws, as `__udivti3` does; `INT128_MIN / -1` wraps to `INT128_MIN`. ### Tested Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. - `guest_crt` passes: `cmake --build build --target libc guest_crt_tests && ctest --test-dir build -R "^guest_crt$"`. - Kart PS5 (PPSA99611, `Phi1ow/mkwii-ps5` release `v1.0.0-rc1`, asset `Kart-PS5.zip`), `eboot.bin` unwrapped from its SELF and relinked with the built relinker `--windows`: on `main` it stops at `FAIL: unresolved ELF import XU4yLKvcDh0 from libc.prx`; with this change it passes `__divti3` and stops at `ELSr5qm4K1M` (`__umodti3`). - `python tools/check_conventions.py --base origin/main` passes. - Note: current `main` does not build `libkernel` on Windows (`Socket.cpp: 'HostPoll' was not declared in this scope`), unrelated to this change; the runs above used `main` with #4021 applied. This PR does not depend on #4021. - Not tested on Linux or macOS. ### 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 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] AI-assisted: yes
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!4037
No description provided.