Skip to content

feat(libc): implement __powidf2 and _WStoul - #1980

Closed
overlordxrz-source wants to merge 1 commit into
boykopovar:mainfrom
overlordxrz-source:feat/libc-cyber-numeric
Closed

overlordxrz-source wants to merge 1 commit into
boykopovar:mainfrom
overlordxrz-source:feat/libc-cyber-numeric

Conversation

@overlordxrz-source

@overlordxrz-source overlordxrz-source commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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 feat(libs): implement font, libc, libkernel and misc prx stubs #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

H+8UBOwfScI and JhVR7D4Ax6Y were throwing libcCyberUnknown08/09 stubs.
They are the NIDs of __powidf2 and _WStoul.

__powidf2 is compiler-rt's square and multiply, so results match the
guest's own libc bit for bit, including negative exponents and INT_MIN.
_WStoul is the Dinkumware helper behind wcstoul and forwards to the
existing 16-bit wcstoul export.
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

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

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

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 7103f39 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

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants