feat(libc): implement _Thrd_lt #10788

Merged
00xDisaster merged 4 commits from upstream-pr/10788 into main 2026-10-27 01:59:56 +00:00
00xDisaster commented 2026-10-25 00:49:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-25T00:49:15Z.


What

Add _Thrd_lt, the C11 thread-helper comparison that orders two thrd_t handles by their integer addresses. This provides the strict total order assumed to back std::thread::id. The declaration lives in Api.hpp; no other open PR implements this export.

_Thrd_yield is intentionally left to open PR #8352, and this PR does not claim the _Thrd_* family is complete; the abort and creation helpers remain separate gaps. Firmware 13.42's libSceLibcInternal.sprx exports _Thrd_lt (NID OCbJ96N1utA) as a plain unsigned 64-bit first < second on the two handles, returning 1 or 0, and BunnyFl verified it on all 121 tested handle pairs. C++ only requires a strict total order over thread IDs; arbitrary handle bit patterns still rely on the integer comparison.

Tested

Linux CachyOS 7.3.0-2-cachyos, GCC 16.2.1. Base upstream/main 5b5d24cb22; head 92db947130.

oneandonlydean merged current main after #10688 and #9269 landed. The merges kept both sides of the thread-test and debt conflicts; the _Thrd_lt implementation and tests are unchanged.

  • cmake --build build --target guest_libc_threads_tests --parallel 2: passed.
  • ctest --test-dir build -R '^guest_libc_threads$' --output-on-failure: 1/1 passed in 0.06 s.
  • guest_libc_threads checks that a handle is not less than itself and that _Thrd_lt(a, b) and _Thrd_lt(b, a) are opposite for two distinct handles.
  • BunnyFl checked firmware 13.42's libSceLibcInternal.sprx: _Thrd_lt compares the two unsigned 64-bit handles and returns 1/0 on all 121 tested pairs.
  • tools/check_conventions.py --base upstream/main --head HEAD and git diff --check: clean.
  • GPUs tested: n/a.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: no
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5000571287 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10788). Originally posted by [00xDisaster](https://github.com/00xDisaster) on 2026-10-25T00:49:15Z. --- ### What Add `_Thrd_lt`, the C11 thread-helper comparison that orders two `thrd_t` handles by their integer addresses. This provides the strict total order assumed to back `std::thread::id`. The declaration lives in `Api.hpp`; no other open PR implements this export. `_Thrd_yield` is intentionally left to open PR #8352, and this PR does not claim the `_Thrd_*` family is complete; the abort and creation helpers remain separate gaps. Firmware 13.42's `libSceLibcInternal.sprx` exports `_Thrd_lt` (NID `OCbJ96N1utA`) as a plain unsigned 64-bit `first < second` on the two handles, returning 1 or 0, and BunnyFl verified it on all 121 tested handle pairs. C++ only requires a strict total order over thread IDs; arbitrary handle bit patterns still rely on the integer comparison. ### Tested Linux CachyOS 7.3.0-2-cachyos, GCC 16.2.1. Base `upstream/main` `5b5d24cb22`; head `92db947130`. oneandonlydean merged current `main` after #10688 and #9269 landed. The merges kept both sides of the thread-test and debt conflicts; the `_Thrd_lt` implementation and tests are unchanged. - `cmake --build build --target guest_libc_threads_tests --parallel 2`: passed. - `ctest --test-dir build -R '^guest_libc_threads$' --output-on-failure`: 1/1 passed in 0.06 s. - `guest_libc_threads` checks that a handle is not less than itself and that `_Thrd_lt(a, b)` and `_Thrd_lt(b, a)` are opposite for two distinct handles. - BunnyFl checked firmware 13.42's `libSceLibcInternal.sprx`: `_Thrd_lt` compares the two unsigned 64-bit handles and returns 1/0 on all 121 tested pairs. - `tools/check_conventions.py --base upstream/main --head HEAD` and `git diff --check`: clean. - GPUs tested: n/a. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: no
MarcZX10 commented 2026-10-25 00:52:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T00:52:28Z.

Review: CHANGES_REQUESTED


Reviewed exact head ca84349a42. The implementation gives a strict total order over the opaque thread handles using their integer addresses, consistent with the local pointer-identity implementation. I compiled the changed source and test translation units with GCC 12.2, , and ran a harness linked to the exact implementation covering irreflexivity, pairwise asymmetry, expected address order and transitivity; all passed. and current-main conventions pass. The PR reports the focused CTest, while the full local target was unavailable because this environment lacks the full SDL2/XRandR build dependencies. One contribution-rule item needs correction before approval: the PR body says , but the commit message includes and GitHub lists Claude as a co-author. Please update the checklist to accurately disclose the assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5640831674 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10788#pullrequestreview-5640831674). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T00:52:28Z. **Review:** CHANGES_REQUESTED --- Reviewed exact head ca84349a4286b44fa7893e8e42a9edc6f56f32cc. The implementation gives a strict total order over the opaque thread handles using their integer addresses, consistent with the local pointer-identity implementation. I compiled the changed source and test translation units with GCC 12.2, , and ran a harness linked to the exact implementation covering irreflexivity, pairwise asymmetry, expected address order and transitivity; all passed. and current-main conventions pass. The PR reports the focused CTest, while the full local target was unavailable because this environment lacks the full SDL2/XRandR build dependencies. One contribution-rule item needs correction before approval: the PR body says , but the commit message includes and GitHub lists Claude as a co-author. Please update the checklist to accurately disclose the assistance.
MarcZX10 commented 2026-10-25 02:34:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T02:34:40Z.

Review: APPROVED


Reviewed exact head ca84349a4286b44fa7893e8e42a9edc6f56f32cc. _Thrd_lt compares the integer representations of the opaque handles, giving an irreflexive, asymmetric, transitive ordering for these values; this satisfies the unspecified total-order requirement used for std::thread::id. LLVM libc++ uses the same < comparison for its platform thread IDs. The console-specific handle ordering remains unverified, and the PR records that limitation in the libc debt list. The focused test and hosted relinker checks pass; hosted product jobs are skipped by repository workflow. I found no open PR implementing _Thrd_lt. git diff --check and the current-main conventions check pass locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5641190062 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10788#pullrequestreview-5641190062). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T02:34:40Z. **Review:** APPROVED --- Reviewed exact head `ca84349a4286b44fa7893e8e42a9edc6f56f32cc`. `_Thrd_lt` compares the integer representations of the opaque handles, giving an irreflexive, asymmetric, transitive ordering for these values; this satisfies the unspecified total-order requirement used for `std::thread::id`. LLVM libc++ uses the same `<` comparison for its platform thread IDs. The console-specific handle ordering remains unverified, and the PR records that limitation in the libc debt list. The focused test and hosted relinker checks pass; hosted product jobs are skipped by repository workflow. I found no open PR implementing `_Thrd_lt`. `git diff --check` and the current-main conventions check pass locally.
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!10788
No description provided.