feat(libc): implement guest-width first-set-bit exports #4129

Closed
MiniRML wants to merge 2 commits from upstream-pr/4129 into main
MiniRML commented 2026-10-11 23:49:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MiniRML on 2026-10-11T23:49:33Z.


What

Provide ffs/ffsl/ffsll with one-based bit positions and zero for zero input. ffsl uses the guest 64-bit long ABI on Windows. Tests cover every bit position, sign bits and inputs with multiple set bits.

These exports (ffs, ffsl, ffsll) are named in the pinned symbol database used by AnyPS5's tools/nid_names.py. They are absent from the base implementation. The complete changed-file scan of 370 open PRs found no other added implementation of these exports. Related functions are kept together in one topic.

Sources and compatibility

The guest ABI follows the existing libc implementation: 16-bit wide code units, 64-bit long/intmax types, and x87 extended precision in 16-byte storage where used. PS5 hardware validation was not performed. Math exports that delegate to host libm do not establish bit-for-bit agreement with the console's libm; their tested behavior and that limitation are stated here.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, CMake 4.3.1, Ninja, Release, BUILD_TESTING=ON. Tested commit 5002c929405be13abfad1a05ac9e96056a9aef98, based on upstream bab7b3285221495463a4a2494dc410cf137b4a92.

  • cmake --build build --target libc guest_libc_first_set_bit_tests -j 8 passed.
  • ctest --test-dir build -R '^guest_libc_first_set_bit$' --output-on-failure --no-tests=error passed (one behavioral regression test, multiple assertions).
  • Base conventions checker and whitespace checks passed.
  • The real NID patcher was run on a temporary copy of the built libc module; all new symbol hashes were verified in its PE export table, and the temporary module was removed.
  • Merge simulation found no newly introduced build-registration conflict with the existing open PRs that edit this CMake file, and no conflicts with the other validated topics in this batch.
  • Initial validation found a Windows build error on base bab7b3285 (HostPoll undeclared). Upstream fixed it in merged #4021; the follow-up combined full build below passed.
  • The full CTest suite and Linux runtime tests were not run. Existing Defender-blocked relinker tests were not rerun; Defender remained enabled.

Checklist

  • Based on main; no other open PR implements the same functions
  • One topic per PR
  • No code comments added
  • No silent stubs added
  • No investigation notes, logs, images or extra repository copies added
  • No third-party code added
  • General behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Codex)

Follow-up combined validation

Updated this branch to upstream bca7a29d259299aaa8972c94d12694232bb3bb08 without changing this topic's tested libc or regression source files. Current PR head: 15951898c94b9445dc33ca95f91e404ba36cd4cb; independent tested head: 5002c929405be13abfad1a05ac9e96056a9aef98.

All 19 independent topics were then merged together on that upstream base in validation commit f1721a1c6caebf3a95bdf312d06dbf2de7f938c0 (saved in the fork under validation/libc-library-batch-2026-10-11):

  • cmake --build build --target all libs -j 8 passed on Windows 11.
  • All 19 new behavioral CTest tests passed together with four workers.
  • All 37 new NIDs were verified in the actual combined patched libc export table.
  • Every sibling branch merged cleanly in the combined checkout; the independent topic sources remain unchanged.

The earlier full-suite investigation remains paused. Linux runtime and PS5 hardware validation were not performed.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823308172 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4129). Originally posted by [MiniRML](https://github.com/MiniRML) on 2026-10-11T23:49:33Z. --- ### What Provide ffs/ffsl/ffsll with one-based bit positions and zero for zero input. ffsl uses the guest 64-bit long ABI on Windows. Tests cover every bit position, sign bits and inputs with multiple set bits. These exports (ffs, ffsl, ffsll) are named in the pinned symbol database used by AnyPS5's `tools/nid_names.py`. They are absent from the base implementation. The complete changed-file scan of 370 open PRs found no other added implementation of these exports. Related functions are kept together in one topic. ### Sources and compatibility - [Reference](https://man.freebsd.org/cgi/man.cgi?query=ffs&sektion=3) The guest ABI follows the existing libc implementation: 16-bit wide code units, 64-bit long/intmax types, and x87 extended precision in 16-byte storage where used. PS5 hardware validation was not performed. Math exports that delegate to host libm do not establish bit-for-bit agreement with the console's libm; their tested behavior and that limitation are stated here. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, CMake 4.3.1, Ninja, Release, `BUILD_TESTING=ON`. Tested commit `5002c929405be13abfad1a05ac9e96056a9aef98`, based on upstream `bab7b3285221495463a4a2494dc410cf137b4a92`. - `cmake --build build --target libc guest_libc_first_set_bit_tests -j 8` passed. - `ctest --test-dir build -R '^guest_libc_first_set_bit$' --output-on-failure --no-tests=error` passed (one behavioral regression test, multiple assertions). - Base conventions checker and whitespace checks passed. - The real NID patcher was run on a temporary copy of the built libc module; all new symbol hashes were verified in its PE export table, and the temporary module was removed. - Merge simulation found no newly introduced build-registration conflict with the existing open PRs that edit this CMake file, and no conflicts with the other validated topics in this batch. - Initial validation found a Windows build error on base bab7b3285 (`HostPoll` undeclared). Upstream fixed it in merged #4021; the follow-up combined full build below passed. - The full CTest suite and Linux runtime tests were not run. Existing Defender-blocked relinker tests were not rerun; Defender remained enabled. ### Checklist - [x] Based on main; no other open PR implements the same functions - [x] One topic per PR - [x] No code comments added - [x] No silent stubs added - [x] No investigation notes, logs, images or extra repository copies added - [x] No third-party code added - [x] General behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Codex) ### Follow-up combined validation Updated this branch to upstream `bca7a29d259299aaa8972c94d12694232bb3bb08` without changing this topic's tested libc or regression source files. Current PR head: `15951898c94b9445dc33ca95f91e404ba36cd4cb`; independent tested head: `5002c929405be13abfad1a05ac9e96056a9aef98`. All 19 independent topics were then merged together on that upstream base in validation commit `f1721a1c6caebf3a95bdf312d06dbf2de7f938c0` (saved in the fork under `validation/libc-library-batch-2026-10-11`): - `cmake --build build --target all libs -j 8` passed on Windows 11. - All 19 new behavioral CTest tests passed together with four workers. - All 37 new NIDs were verified in the actual combined patched libc export table. - Every sibling branch merged cleanly in the combined checkout; the independent topic sources remain unchanged. The earlier full-suite investigation remains paused. Linux runtime and PS5 hardware validation were not performed.
github-actions[bot] commented 2026-10-11 23:53:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T23:53:06Z.


Progress report (bca7a29 → 1595189)

📈 System libraries: 86.49% (+0.02%, +3 implemented functions)

✅ 3 implemented
Library Name
libc ffs_nid_postfix
libc ffsl_nid_postfix
libc ffsll_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115305292 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4129#issuecomment-6115305292). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T23:53:06Z. --- <!-- progress-report --> ### Progress report (bca7a29 → 1595189) 📈 **System libraries**: 86.49% (+0.02%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libc | `ffs_nid_postfix` | | libc | `ffsl_nid_postfix` | | libc | `ffsll_nid_postfix` | </details>
oneandonlydean commented 2026-10-12 08:26:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:26:48Z.


Same as #4122: no title is shown to reach this on main. Reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120558713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4129#issuecomment-6120558713). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T08:26:48Z. --- Same as #4122: no title is shown to reach this on main. Reopen with the title ID and the log line.

Pull request closed

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!4129
No description provided.