feat(libSceLibcInternal): implement __std_bitset_to_string_1 and _2 #15577

Merged
GiannisG1 merged 1 commit from upstream-pr/15577 into main 2026-11-10 07:55:55 +00:00
GiannisG1 commented 2026-11-03 19:51:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GiannisG1 on 2026-11-03T19:51:34Z.


What

__std_bitset_to_string_1 and __std_bitset_to_string_2 (libSceLibcInternal, NIDs 40rZnNs8g7A and xM78av0AYxM) were parameterless placeholders in RecoveredInventory.cpp that throw. They are Microsoft STL's helpers behind std::bitset::to_string, vector_algorithms.cpp L12179-L12226, at the commit #15460 cites. The signatures come from there: (char* destination, const void* bitset, size_t bits, char zero, char one), and the same with 16-bit elements, the guest wchar_t, for _2. The behaviour is the source's scalar loop, which its vector paths match: bit i of the bitset bytes, least significant first, is written to destination[bits - 1 - i] as one or zero, and nothing else is written (no terminator). A null destination or bitset with a nonzero size throws std::invalid_argument, as #15460's helpers do for invalid ranges; a size of 0 writes nothing.

The two functions move to BitsetToString.cpp. The recovered-inventory debt entry now counts the remaining 7 placeholders, and a new entry records that the PS5 ABI and results are unmeasured.

This is rebased onto #15460 (unsigned byte extrema), #16029 (std::_Mtx_init_with_default_name_override), #16146 (the atomic wait deadline helpers), #15657 (signed and 16-bit integer extrema) and #15581 (float and double extrema), which implemented other placeholders of the same files. #15931 and #15822 change the same count line in docs/dev/debt/libSceLibcInternal.md. No function is implemented twice. Whichever lands later rebases, and I'll rebase this one if one of them lands first.

Tested

Linux Mint 22.3, kernel 7.0.0-38, GCC 13.3.0, Release, BUILD_TESTING=ON, head on main 56619b998c.

guest_libc_internal_bitset_to_string (new) checks every output position for 1 to 130 bits and for 255, 256, 257, 1000 and 4096 bits, with both element types and four character pairs; guard elements on both sides stay untouched, set bits past the size in the last byte are ignored and the bitset is not modified. The output equals the host's std::bitset<N>::to_string for N = 1, 63, 64, 100 and 257. A size of 0 writes nothing, and null pointers with a nonzero size throw. On the placeholders it fails (__std_bitset_to_string_1_nid_postfix not implemented); with this PR it passes.

All tests once and every GPU test on each of the three devices, under Xvfb: NVIDIA GeForce GTX 1050 Ti 4776 run, 2 failed; Intel HD Graphics 630 (Mesa 25.2.8) 1387 run, 11 failed; llvmpipe 1387 run, 2 failed. The new test passes. Against this PR's previous heads on main 69be504b67 and 532bd7981d, no result changed; of the tests main added since, all pass except agc_driver_vector_window_region, which skips on llvmpipe. The AGC tests that fail did so on main bb13564449 too, and so did this PR's previous head there. The one new failure, on all three, is guest_system_service_open_url (from #12895): it segfaults after zenity: cannot open display, and it does the same on main 69be504b67 without this PR (3 of 3).

check_conventions.py, check_test_registration.py, check_main_sync.py (merges cleanly with main 164ac9b078), check_compile.py (3 translation units) and git diff --check are clean.

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 (no AGC, shader recompiler or VideoOut change); the suite's GPU tests ran on NVIDIA GeForce GTX 1050 Ti (580.178.04), Intel HD Graphics 630 (Mesa 25.2.8) and llvmpipe (Mesa 25.2.8), Linux Mint 22.3
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5143573580 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15577). Originally posted by [GiannisG1](https://github.com/GiannisG1) on 2026-11-03T19:51:34Z. --- ### What `__std_bitset_to_string_1` and `__std_bitset_to_string_2` (libSceLibcInternal, NIDs `40rZnNs8g7A` and `xM78av0AYxM`) were parameterless placeholders in `RecoveredInventory.cpp` that throw. They are Microsoft STL's helpers behind `std::bitset::to_string`, [`vector_algorithms.cpp` L12179-L12226](https://github.com/microsoft/STL/blob/b53b100c3c08f3e2a4453bbe75e3156d4127ffc1/stl/src/vector_algorithms.cpp#L12179-L12226), at the commit #15460 cites. The signatures come from there: `(char* destination, const void* bitset, size_t bits, char zero, char one)`, and the same with 16-bit elements, the guest `wchar_t`, for `_2`. The behaviour is the source's scalar loop, which its vector paths match: bit `i` of the bitset bytes, least significant first, is written to `destination[bits - 1 - i]` as `one` or `zero`, and nothing else is written (no terminator). A null destination or bitset with a nonzero size throws `std::invalid_argument`, as #15460's helpers do for invalid ranges; a size of 0 writes nothing. The two functions move to `BitsetToString.cpp`. The recovered-inventory debt entry now counts the remaining 7 placeholders, and a new entry records that the PS5 ABI and results are unmeasured. This is rebased onto #15460 (unsigned byte extrema), #16029 (`std::_Mtx_init_with_default_name_override`), #16146 (the atomic wait deadline helpers), #15657 (signed and 16-bit integer extrema) and #15581 (float and double extrema), which implemented other placeholders of the same files. #15931 and #15822 change the same count line in `docs/dev/debt/libSceLibcInternal.md`. No function is implemented twice. Whichever lands later rebases, and I'll rebase this one if one of them lands first. ### Tested Linux Mint 22.3, kernel 7.0.0-38, GCC 13.3.0, Release, `BUILD_TESTING=ON`, head on `main` `56619b998c`. `guest_libc_internal_bitset_to_string` (new) checks every output position for 1 to 130 bits and for 255, 256, 257, 1000 and 4096 bits, with both element types and four character pairs; guard elements on both sides stay untouched, set bits past the size in the last byte are ignored and the bitset is not modified. The output equals the host's `std::bitset<N>::to_string` for N = 1, 63, 64, 100 and 257. A size of 0 writes nothing, and null pointers with a nonzero size throw. On the placeholders it fails (`__std_bitset_to_string_1_nid_postfix not implemented`); with this PR it passes. All tests once and every GPU test on each of the three devices, under Xvfb: NVIDIA GeForce GTX 1050 Ti 4776 run, 2 failed; Intel HD Graphics 630 (Mesa 25.2.8) 1387 run, 11 failed; llvmpipe 1387 run, 2 failed. The new test passes. Against this PR's previous heads on `main` `69be504b67` and `532bd7981d`, no result changed; of the tests `main` added since, all pass except `agc_driver_vector_window_region`, which skips on llvmpipe. The AGC tests that fail did so on `main` `bb13564449` too, and so did this PR's previous head there. The one new failure, on all three, is `guest_system_service_open_url` (from #12895): it segfaults after `zenity: cannot open display`, and it does the same on `main` `69be504b67` without this PR (3 of 3). `check_conventions.py`, `check_test_registration.py`, `check_main_sync.py` (merges cleanly with `main` `164ac9b078`), `check_compile.py` (3 translation units) and `git diff --check` are clean. ### 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 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 (no AGC, shader recompiler or VideoOut change); the suite's GPU tests ran on NVIDIA GeForce GTX 1050 Ti (580.178.04), Intel HD Graphics 630 (Mesa 25.2.8) and llvmpipe (Mesa 25.2.8), Linux Mint 22.3 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!15577
No description provided.