Skip to content

fix(libc): implement __powidf2 import - #2465

Closed
SwazNaj7 wants to merge 2 commits into
boykopovar:mainfrom
SwazNaj7:fix/libc-abs-powidf2
Closed

SwazNaj7 wants to merge 2 commits into
boykopovar:mainfrom
SwazNaj7:fix/libc-abs-powidf2

Conversation

@SwazNaj7

@SwazNaj7 SwazNaj7 commented Oct 9, 2026 •

Copy link
Copy Markdown

What

Implements the Cyberpunk 2077 libc import that called NotImplemented_nid_no_patch:

  • H+8UBOwfScI (__powidf2): new __powidf2_nid_postfix(double, int) in core/libs/prx/libc/src/Math.cpp using exponentiation by squaring per the GCC libgcc algorithm (unsigned magnitude so INT_MIN is safe, reciprocal for negative exponents); libcCyberUnknown08 retyped to (double, int) -> double and forwards to it.

Ye20uNnlglA (abs) is intentionally left as the NotImplemented stub here; it is covered by still-open #1097, which adds the same abs_nid_postfix(int) wrapper plus the same GuestMath.cpp checks.

NID hashes and APS5_EXPORT names are unchanged. Adds CheckIntegerPower regression tests to core/libs/tests/GuestMath.cpp (exact powers, 0^0/0^+/-n, negative bases/exponents, near-normal-range bases, INT_MIN exponents).

Tested

  • Rebased onto upstream/main (c6e3aa76, no merge commits); git diff --check: clean; mergeable: MERGEABLE.
  • python tools/check_conventions.py --base upstream/main: pass.
  • python tools/nid_names.py --nid H+8UBOwfScI: already-implemented __powidf2; --nid Ye20uNnlglA: rename-ready abs (still a stub, left for feat(libc): implement abs #1097).
  • g++ -std=c++20 -fsyntax-only on Math.cpp, Export.cpp, GuestMath.cpp: pass (MSYS2 MinGW GCC 16.2.0).
  • Standalone harness linking the real Math.cpp object: all 18 CheckIntegerPower assertions pass, plus a 117-case sweep against __builtin_powi with 0 mismatches (bit-exact).
  • Not run here: full CMake build and ctest -R guest_math (no Ninja/supported toolchain and submodules uninitialized in this environment); CI needs to be green.

Checklist

  • Based on current main; abs left to feat(libc): implement abs #1097, no other open PR implements __powidf2
  • 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

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 9, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR. Two things before this can go in:

  • abs overlaps with #1097, which is still open and adds the same abs_nid_postfix(int) wrapper plus the same GuestMath.cpp checks. Please drop abs (the Ye20uNnlglA export change, abs_nid_postfix and CheckAbsoluteValue) from this PR, keep __powidf2, and list #1097 under "Depends on" only if you still need it for the test list; otherwise just leave it out.
  • The branch conflicts with main in core/libs/tests/GuestMath.cpp. Please rebase (no merge commits) after the change above.

The __powidf2 part looks fine on reading (square-and-multiply, INT_MIN handled via unsigned magnitude, reciprocal for negative exponents). Once rebased, please also run ctest -R guest_math and put the result under "Tested" (it's currently listed as not run); CI will need to be green too.

@github-actions github-actions Bot mentioned this pull request Oct 9, 2026
9 tasks done
@SwazNaj7
SwazNaj7 force-pushed the fix/libc-abs-powidf2 branch from 27b517a to aa7f1f4 Compare October 9, 2026 22:36
@SwazNaj7 SwazNaj7 changed the title fix(libc): implement abs and __powidf2 imports fix(libc): implement __powidf2 import Oct 9, 2026
@github-actions github-actions Bot added intake paused Closed while PR intake is limited to authors with at least 10 PRs merged into main and removed needs rebase Conflicts with main, rebase needed labels Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

@github-actions github-actions Bot closed this Oct 9, 2026
@Kikoarl

Kikoarl commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at aa7f1f4d:

  • Build: Built cleanly in RAM (/tmp/anyps5_build) with zero warnings/errors.
  • Conventions: python3 tools/check_conventions.py --base origin/main --head HEAD -> PASS (0 errors).
  • Verification: Verified __powidf2 implementation in Math.cpp and GuestMath.cpp tests. Properly exposes software integer exponentiation helper expected by guest LLVM/clang compiler-rt runtimes.

LGTM!

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Progress report (a11c8f7 → b3845e9)

📈 System libraries: 85.82% (+0.01%, +2 implemented, +1 declared functions)

✅ 2 implemented
Library Name
libc __powidf2_nid_postfix
libc libcCyberUnknown08
🆕 1 declared as stubs
Library Name
libc libcCyberUnknown02

@oneandonlydean oneandonlydean removed the intake paused Closed while PR intake is limited to authors with at least 10 PRs merged into main label Oct 11, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Reopened. Conflict in core/libs/prx/libc/Export.cpp; can you rebase? Does Cyberpunk 2077 call __powidf2 on main? Please post the line where it stops, and run the full build with ctest -R guest_math.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed libc labels Oct 11, 2026
@Mouhand-Kaddo

Copy link
Copy Markdown
Contributor

Additional platform validation of standalone PR head aa7f1f4d6e416c700d92bfd28bf62de6d8e1b1d3 (2026-10-11):

Windows: passed — Windows 11, WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja; Release, BUILD_TESTING=ON.

1 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.

Checks: guest_math.

Command after building: ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_math$".

No title/gameplay validation. These results cover the standalone head, not a merge with current main.

@ivica00 ivica00 mentioned this pull request Oct 11, 2026
9 tasks done
@SwazNaj7
SwazNaj7 force-pushed the fix/libc-abs-powidf2 branch from aa7f1f4 to aafe117 Compare October 11, 2026 14:03
@SwazNaj7

Copy link
Copy Markdown
Author

I've rebased the PR onto the latest main to address the conflict in core/libs/prx/libc/Export.cpp and pushed the updated branch.

This PR implements __powidf2, which computes a floating-point base raised to an integer exponent. The implementation uses exponentiation by squaring, and the associated guest_math test covers the implementation.

Testing and validation: referring to the earlier checks made by Mouhand-Kaddo

  • Additional Windows validation was reported for the previous standalone PR head, aa7f1f4d6e416c700d92bfd28bf62de6d8e1b1d3.
  • The guest_math CTest passed with 0 failures and 0 skips under Windows 11, using WinLibs GCC 15.2.0, CMake 4.3.1, and Ninja in Release mode with BUILD_TESTING=ON.
  • The selected test targets and their dependencies built successfully.
  • This was focused test validation, not a full build or full test-suite run.
  • These results apply to the previously tested commit, not necessarily the rebased branch, so the updated branch still needs validation.

Regarding Cyberpunk 2077: I haven't been able to run the game against this build, so I can't independently confirm whether it calls __powidf2 on the current main branch or provide the exact line where execution stops. I don't want to speculate about the runtime behavior without being able to reproduce it.

Could someone with a working build verify the updated branch and check whether Cyberpunk 2077 reaches or calls __powidf2 on main? If it does, the exact stopping point or relevant log would help confirm the behavior this PR needs to address.

Thanks!

@github-actions github-actions Bot added docs and removed needs rebase Conflicts with main, rebase needed labels Oct 11, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the rebase. The current head doesn't link when merged onto main (a11c8f7); the rebase resurrected old stubs:

  • core/libs/prx/libc/Export.cpp re-adds vsnprintf_s_nid_postfix, vsscanf_s_nid_postfix, _Mtx_destroy_nid_postfix, _Cnd_destroy_nid_postfix and _Iswctype_nid_postfix. main already implements them (src/Formatting.cpp, src/Threads.cpp, src/RuneLocale.cpp), so libc.prx fails with multiple definition of ... for all five.
  • It also re-adds the Ye20uNnlglA / libcCyberUnknown02 stub. abs is already implemented on main (src/Math.cpp:78, with tests in GuestMath.cpp), so the stub must not come back.
  • docs/dev/TechnicalDebt.md:346 adds a vsnprintf_s, vsscanf_s line that is false on main (they are implemented). The _ZSt14_Atomic_assert line is fine, but note the code comment above that function is only moved, not needed; keep main's comment as is or move it, but not both.

Fix: start again from current upstream/main and keep only the __powidf2 change: the Math.cpp function, the H+8UBOwfScI export retyped to (double, int) -> double in Export.cpp, and the CheckIntegerPower test. git diff upstream/main --stat should then show those three files only. The __powidf2 algorithm and the tests look right; I'll run guest_math and the negative check once it builds.

As @oneandonlydean asked: please also post the line where Cyberpunk 2077 stops on main without this change, and the output of ctest -R guest_math from a full build.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: __powidf2 is on main since #5174.
Reopen if something here is still missing on current main.

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

Labels

docs libc needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants