feat(libc): implement div #718

Merged
adriadam10 merged 1 commit from upstream-pr/718 into main 2026-10-05 19:00:09 +00:00
adriadam10 commented 2026-10-05 17:53:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T17:53:58Z.


What

Implements libc div (NID 2gbcltk3swE, hash-verified with tools/nid_names.py), until now the libcCyberUnknown00 stub that threw.

Behaviour is the C standard (C11 7.22.6.2): quotient truncated toward zero, remainder with the sign of the numerator, quot * denom + rem == numer. div_t is two ints returned in rax under the SysV ABI, same layout as the host's std::div_t.

Tested

Linux, GCC Release. guest_math gains cases for both operand signs and INT_MIN / 10; values from the standard's rules, not from our output. On main the test aborts (the stub throws). Negative check: flipping the remainder sign for negative numerators makes it fail. Checked that libc.prx exports 2gbcltk3swE. ctest -R 'guest_|libc': 95/95 pass.

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:4748863255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/718). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T17:53:58Z. --- ### What Implements libc `div` (NID `2gbcltk3swE`, hash-verified with `tools/nid_names.py`), until now the `libcCyberUnknown00` stub that threw. Behaviour is the C standard (C11 7.22.6.2): quotient truncated toward zero, remainder with the sign of the numerator, `quot * denom + rem == numer`. `div_t` is two `int`s returned in `rax` under the SysV ABI, same layout as the host's `std::div_t`. ### Tested Linux, GCC Release. `guest_math` gains cases for both operand signs and `INT_MIN / 10`; values from the standard's rules, not from our output. On `main` the test aborts (the stub throws). Negative check: flipping the remainder sign for negative numerators makes it fail. Checked that `libc.prx` exports `2gbcltk3swE`. `ctest -R 'guest_|libc'`: 95/95 pass. ### 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
github-actions[bot] commented 2026-10-05 17:54:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T17:54:23Z.


Progress report (0518f0e → afe2b14)

📈 System libraries: 79.24% (+0.03%, +1 implemented, -1 removed functions)

✅ 1 implemented
Library Name
libc div_nid_postfix
🗑️ 1 removed
Library Name
libc libcCyberUnknown00
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6000047782 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/718#issuecomment-6000047782). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T17:54:23Z. --- <!-- progress-report --> ### Progress report (0518f0e → afe2b14) 📈 **System libraries**: 79.24% (+0.03%, +1 implemented, -1 removed functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `div_nid_postfix` | </details> <details> <summary>🗑️ 1 removed</summary> | Library | Name | | - | - | | libc | `libcCyberUnknown00` | </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!718
No description provided.