feat(libc): implement ldiv #1818

Merged
DariusHQ merged 1 commit from upstream-pr/1818 into main 2026-10-09 22:02:42 +00:00
DariusHQ commented 2026-10-08 20:19:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DariusHQ on 2026-10-08T20:19:47Z.


What

ldiv (gfP0im5Z3g0) is absent from the libc exports. RetroArch (PPSA99169) imports it from libSceLibcInternal, one of the absent imports that #1578 lists for that title. Part of #1578; no open PR implements it.

The guest long is 64-bit, so the export takes std::int64_t and returns lldiv_t, whose layout matches the guest ldiv_t (two 64-bit members), the same way lldiv is exported. std::ldiv would truncate on Windows, where long is 32-bit.

$ python3 -c "import sys; sys.path.insert(0,'tools'); from nid_names import compute_nid; print(compute_nid('ldiv'))"
gfP0im5Z3g0

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with BUILD_TESTING=ON on 4b6ab6bb: ctest 479/479 passed, and the built libc.prx exports gfP0im5Z3g0. guest_math compares ldiv with lldiv for ±4294967301 divided by ±3, which a 32-bit long would truncate, and checks INT64_MIN / 2. Not tested on Linux. No title run: PPSA99169 still has other absent imports.

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:4792323359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1818). Originally posted by [DariusHQ](https://github.com/DariusHQ) on 2026-10-08T20:19:47Z. --- ### What `ldiv` (`gfP0im5Z3g0`) is absent from the libc exports. RetroArch (PPSA99169) imports it from `libSceLibcInternal`, one of the absent imports that #1578 lists for that title. Part of #1578; no open PR implements it. The guest `long` is 64-bit, so the export takes `std::int64_t` and returns `lldiv_t`, whose layout matches the guest `ldiv_t` (two 64-bit members), the same way `lldiv` is exported. `std::ldiv` would truncate on Windows, where `long` is 32-bit. ``` $ python3 -c "import sys; sys.path.insert(0,'tools'); from nid_names import compute_nid; print(compute_nid('ldiv'))" gfP0im5Z3g0 ``` ### Tested Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with `BUILD_TESTING=ON` on `4b6ab6bb`: `ctest` 479/479 passed, and the built `libc.prx` exports `gfP0im5Z3g0`. `guest_math` compares `ldiv` with `lldiv` for ±4294967301 divided by ±3, which a 32-bit `long` would truncate, and checks `INT64_MIN / 2`. Not tested on Linux. No title run: PPSA99169 still has other absent imports. ### 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
DariusHQ commented 2026-10-09 19:29:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DariusHQ on 2026-10-09T19:29:31Z.


The overlap with #2038 is gone. #2038 moved its lrand48 and srand48 checks from GuestMath.cpp to GuestRand48.cpp in cf569548. The bot comment stays because tools/pr_overlap.py lists only the 200 newest open pull requests (gh pr list -L 200), and #1818 is older, so the workflow no longer updates or deletes it.

pr_overlap.py --branch on 8b393b6e reports one overlap, with #2316 (abs): both add their export after lldiv in Math.cpp and their checks at the same lines of GuestMath.cpp. Whichever merges second keeps both sides. I will rebase this one if #2316 goes first

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6087820174 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1818#issuecomment-6087820174). Originally posted by [DariusHQ](https://github.com/DariusHQ) on 2026-10-09T19:29:31Z. --- The overlap with #2038 is gone. #2038 moved its `lrand48` and `srand48` checks from `GuestMath.cpp` to `GuestRand48.cpp` in cf569548. The bot comment stays because `tools/pr_overlap.py` lists only the 200 newest open pull requests (`gh pr list -L 200`), and #1818 is older, so the workflow no longer updates or deletes it. `pr_overlap.py --branch` on 8b393b6e reports one overlap, with #2316 (`abs`): both add their export after `lldiv` in `Math.cpp` and their checks at the same lines of `GuestMath.cpp`. Whichever merges second keeps both sides. I will rebase this one if #2316 goes first
itsbo5 commented 2026-10-09 19:47:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by itsbo5 on 2026-10-09T19:47:15Z.


Thanks for the heads-up! My PR #2316 is pretty much ready to go. You can rebase it once yours gets merged, or if you’d prefer to merge yours first, just let me know and I’ll take care of the rebase on my end.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088094206 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1818#issuecomment-6088094206). Originally posted by [itsbo5](https://github.com/itsbo5) on 2026-10-09T19:47:15Z. --- Thanks for the heads-up! My PR #2316 is pretty much ready to go. You can rebase it once yours gets merged, or if you’d prefer to merge yours first, just let me know and I’ll take care of the rebase on my end.
adriadam10 commented 2026-10-09 22:02:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:02:39Z.


Checked: ldiv NID gfP0im5Z3g0 matches compute_nid; lldiv_t has the same layout as the guest ldiv_t (two 64-bit members) and the fixed-width int64_t signature avoids the 32-bit long truncation on Windows. guest_math passes with the PR and fails to link without the Math.cpp change. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089996683 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1818#issuecomment-6089996683). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T22:02:39Z. --- Checked: `ldiv` NID `gfP0im5Z3g0` matches `compute_nid`; `lldiv_t` has the same layout as the guest `ldiv_t` (two 64-bit members) and the fixed-width `int64_t` signature avoids the 32-bit `long` truncation on Windows. `guest_math` passes with the PR and fails to link without the `Math.cpp` change. Merging once CI is green.
github-actions[bot] commented 2026-10-09 22:14:18 +00:00 (Migrated from github.com)

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


Progress report (364a56b → 668a1e6)

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

✅ 1 implemented
Library Name
libc ldiv_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090138132 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1818#issuecomment-6090138132). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:14:18Z. --- <!-- progress-report --> ### Progress report (364a56b → 668a1e6) ➖ **System libraries**: 84.76% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `ldiv_nid_postfix` | </details>
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!1818
No description provided.