feat(libc): implement __powidf2 and _WStoul #1980

Closed
overlordxrz-source wants to merge 1 commit from upstream-pr/1980 into main
overlordxrz-source commented 2026-10-09 03:41:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-09T03:41:24Z.


What

Cyberpunk 2077 (PPSA04029) imports two libc functions that are still throwing stubs on main, libcCyberUnknown08 and libcCyberUnknown09. tools/nid_names.py resolves their NIDs:

NID Name
H+8UBOwfScI __powidf2
JhVR7D4Ax6Y _WStoul

Both NIDs are in the PPSA04029 import list attached to #266. None of the other import lists in #267 to #272 contain them.

  • __powidf2(double, int) is the compiler-rt builtin that clang emits for __builtin_powi. This is its square-and-multiply loop, so it returns the same bits as the guest's own copy. It differs from pow and from multiplying n times, for example 1.1^13 and -1.7^-13. Negative exponents return 1/r, and INT_MIN works.
  • _WStoul(const wchar_t*, wchar_t**, int) is the Dinkumware function behind wcstoul. It forwards to the existing wcstoul export, which already reads 16-bit guest wchar_t and returns a 64-bit unsigned long on every host. Host wcstoul would read 32-bit units on Linux.

The stubs are removed from Export.cpp. _WStoul sits where the two stubs were, next to the existing std_execute_once forwarder. That keeps the hunk apart from #1952's deletions in the same file, so the two PRs merge cleanly in either order (checked with git merge-tree).

Not included: CyXs2l-1kNA (_Iswctype, stub 07). Its second argument indexes Dinkumware's class table, and only index 9 (space) is known from the disassembly quoted in #492. The other indices aren't confirmed, so it keeps throwing. #1498 also changes these stubs as part of its omnibus change and conflicts with this PR in Export.cpp. Its _Iswctype treats the argument as a bitmask.

Log

I don't own Cyberpunk 2077, so I can't paste a line where PPSA04029 stops on main. I found no stop line for these NIDs in any issue or PR. The evidence is the import list in #266. If someone with the title can post the NotImplemented line for H+8UBOwfScI or JhVR7D4Ax6Y from main, I'll add it here.

Tested

aarch64 Debian 13 host. The full project can't be built here because it needs x86-64.

  • New core/libs/tests/GuestNumericHelpers.cpp (guest_numeric_helpers), linked natively against Math.cpp, Strings.cpp and Export.cpp, passes 30 of 30 runs and also passes with UBSan. It compares __powidf2 bit patterns with an independent IEEE double reference: square-and-multiply cases that differ from pow, negative exponents, NaN^0, ±0 to negative powers, INT_MIN and INT_MAX. _WStoul checks cover bases 0, 10, 16 and 36, wrapping of negative values, the 64-bit maximum, overflow to ULONG_MAX with ERANGE, a non-ASCII digit, no conversion and a null end pointer.
  • Math.cpp, Export.cpp and the test compile for x86_64-linux-gnu and x86_64-windows-gnu with -Wall -Wextra (Zig 0.17, clang 22). The only warning is the existing -Wreturn-type-c-linkage from General.hpp.
  • python3 tools/check_conventions.py --base origin/main passes.
  • Not run with a title.

Checklist

  • Based on current main. The one other open PR that changes these functions is #1498, which also changes these stubs as part of a larger change; see What
  • 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:4795686066 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1980). Originally posted by [overlordxrz-source](https://github.com/overlordxrz-source) on 2026-10-09T03:41:24Z. --- ### What Cyberpunk 2077 (PPSA04029) imports two `libc` functions that are still throwing stubs on `main`, `libcCyberUnknown08` and `libcCyberUnknown09`. `tools/nid_names.py` resolves their NIDs: | NID | Name | | - | - | | `H+8UBOwfScI` | `__powidf2` | | `JhVR7D4Ax6Y` | `_WStoul` | Both NIDs are in the PPSA04029 import list attached to #266. None of the other import lists in #267 to #272 contain them. - `__powidf2(double, int)` is the compiler-rt builtin that clang emits for `__builtin_powi`. This is its square-and-multiply loop, so it returns the same bits as the guest's own copy. It differs from `pow` and from multiplying `n` times, for example `1.1^13` and `-1.7^-13`. Negative exponents return `1/r`, and `INT_MIN` works. - `_WStoul(const wchar_t*, wchar_t**, int)` is the Dinkumware function behind `wcstoul`. It forwards to the existing `wcstoul` export, which already reads 16-bit guest `wchar_t` and returns a 64-bit `unsigned long` on every host. Host `wcstoul` would read 32-bit units on Linux. The stubs are removed from `Export.cpp`. `_WStoul` sits where the two stubs were, next to the existing `std_execute_once` forwarder. That keeps the hunk apart from #1952's deletions in the same file, so the two PRs merge cleanly in either order (checked with `git merge-tree`). Not included: `CyXs2l-1kNA` (`_Iswctype`, stub 07). Its second argument indexes Dinkumware's class table, and only index 9 (space) is known from the disassembly quoted in #492. The other indices aren't confirmed, so it keeps throwing. #1498 also changes these stubs as part of its omnibus change and conflicts with this PR in `Export.cpp`. Its `_Iswctype` treats the argument as a bitmask. ### Log I don't own Cyberpunk 2077, so I can't paste a line where PPSA04029 stops on `main`. I found no stop line for these NIDs in any issue or PR. The evidence is the import list in #266. If someone with the title can post the `NotImplemented` line for `H+8UBOwfScI` or `JhVR7D4Ax6Y` from `main`, I'll add it here. ### Tested aarch64 Debian 13 host. The full project can't be built here because it needs x86-64. - New `core/libs/tests/GuestNumericHelpers.cpp` (`guest_numeric_helpers`), linked natively against `Math.cpp`, `Strings.cpp` and `Export.cpp`, passes 30 of 30 runs and also passes with UBSan. It compares `__powidf2` bit patterns with an independent IEEE double reference: square-and-multiply cases that differ from `pow`, negative exponents, `NaN^0`, `±0` to negative powers, `INT_MIN` and `INT_MAX`. `_WStoul` checks cover bases 0, 10, 16 and 36, wrapping of negative values, the 64-bit maximum, overflow to `ULONG_MAX` with `ERANGE`, a non-ASCII digit, no conversion and a null end pointer. - `Math.cpp`, `Export.cpp` and the test compile for x86_64-linux-gnu and x86_64-windows-gnu with `-Wall -Wextra` (Zig 0.17, clang 22). The only warning is the existing `-Wreturn-type-c-linkage` from `General.hpp`. - `python3 tools/check_conventions.py --base origin/main` passes. - Not run with a title. ### Checklist - [x] Based on current `main`. The one other open PR that changes these functions is #1498, which also changes these stubs as part of a larger change; see What - [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-09 03:41:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T03:41:44Z.


Progress report (f145139 → a8614c7)

📈 System libraries: 84.83% (+0.07%, +2 implemented, -2 removed functions)

✅ 2 implemented
Library Name
libc _WStoul_nid_postfix
libc __powidf2_nid_postfix
🗑️ 2 removed
Library Name
libc libcCyberUnknown08
libc libcCyberUnknown09
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6073804116 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1980#issuecomment-6073804116). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T03:41:44Z. --- <!-- progress-report --> ### Progress report (f145139 → a8614c7) 📈 **System libraries**: 84.83% (+0.07%, +2 implemented, -2 removed functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `_WStoul_nid_postfix` | | libc | `__powidf2_nid_postfix` | </details> <details> <summary>🗑️ 2 removed</summary> | Library | Name | | - | - | | libc | `libcCyberUnknown08` | | libc | `libcCyberUnknown09` | </details>
MarcZX10 commented 2026-10-09 04:13:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T04:13:37Z.

Review: CHANGES_REQUESTED


The implementation looks technically sound: __powidf2 matches LLVM compiler-rt’s square-and-multiply routine, and _WStoul forwards to the 16-bit guest wcstoul; the updated Linux/Windows and conventions checks pass. I cannot approve yet because the PR says the only evidence is the import list and that no current-main NotImplemented stop line was found. CONTRIBUTING.md explicitly says an import list alone does not show a title reaches the export and asks for a reproduced failure or a concrete project need with its limits. Please add the current-main runtime evidence, or explain a demonstrated need that meets that rule.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5465630543 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1980#pullrequestreview-5465630543). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T04:13:37Z. **Review:** CHANGES_REQUESTED --- The implementation looks technically sound: `__powidf2` matches LLVM compiler-rt’s square-and-multiply routine, and `_WStoul` forwards to the 16-bit guest `wcstoul`; the updated Linux/Windows and conventions checks pass. I cannot approve yet because the PR says the only evidence is the import list and that no current-main `NotImplemented` stop line was found. CONTRIBUTING.md explicitly says an import list alone does not show a title reaches the export and asks for a reproduced failure or a concrete project need with its limits. Please add the current-main runtime evidence, or explain a demonstrated need that meets that rule.
overlordxrz-source commented 2026-10-09 04:54:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-09T04:54:53Z.


Thanks for the review. I looked for runtime evidence and found none. No AnyPS5, KytyPS5 or shadPS4 issue or log has a line where a title calls H+8UBOwfScI or JhVR7D4Ax6Y, and the #358 liveness pass on PPSA04029 marked neighbouring stubs as live but left these two without a note. There's also a reason to doubt they're reached at all: Cyberpunk's PPSA03974 build ships its own sce_module/libc.prx (KytyPS5#182 log: Loading: …[PPSA03974]\sce_module\libc.prx), and since 7103f390 a title's own imports bind to its guest modules first. I'm converting this to a draft, and I'll mark it ready only with a current-main … not implemented line from a title, or close it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074539809 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1980#issuecomment-6074539809). Originally posted by [overlordxrz-source](https://github.com/overlordxrz-source) on 2026-10-09T04:54:53Z. --- Thanks for the review. I looked for runtime evidence and found none. No AnyPS5, KytyPS5 or shadPS4 issue or log has a line where a title calls `H+8UBOwfScI` or `JhVR7D4Ax6Y`, and the #358 liveness pass on PPSA04029 marked neighbouring stubs as live but left these two without a note. There's also a reason to doubt they're reached at all: Cyberpunk's PPSA03974 build ships its own `sce_module/libc.prx` (KytyPS5#182 log: `Loading: …[PPSA03974]\sce_module\libc.prx`), and since 7103f390 a title's own imports bind to its guest modules first. I'm converting this to a draft, and I'll mark it ready only with a current-main `… not implemented` line from a title, or close it.
github-actions[bot] commented 2026-10-09 05:35:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T05:35:05Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2001 wcstoul_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074984565 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1980#issuecomment-6074984565). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T05:35:05Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2001 | | `wcstoul_nid_postfix` | |
oneandonlydean commented 2026-10-09 08:56:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:56:51Z.


Closing, as you suggested above. Reopen with the not implemented line from main if a title turns one up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077735516 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1980#issuecomment-6077735516). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T08:56:51Z. --- Closing, as you suggested above. Reopen with the `not implemented` line from main if a title turns one up.

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