fix(libc): implement __powidf2 import #2465

Closed
SwazNaj7 wants to merge 2 commits from upstream-pr/2465 into main
SwazNaj7 commented 2026-10-09 22:16:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SwazNaj7 on 2026-10-09T22:16:04Z.


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 #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 #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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4806439074 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465). Originally posted by [SwazNaj7](https://github.com/SwazNaj7) on 2026-10-09T22:16:04Z. --- ### 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 #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 - [x] Based on current `main`; `abs` left to #1097, no other open PR implements `__powidf2` - [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
adriadam10 commented 2026-10-09 22:20:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:20:16Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5475875765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465#pullrequestreview-5475875765). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T22:20:16Z. **Review:** CHANGES_REQUESTED --- 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[bot] commented 2026-10-09 22:44:57 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090533156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465#issuecomment-6090533156). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:44:57Z. --- 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.
Kikoarl commented 2026-10-09 22:50:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T22:50:07Z.


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!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090593741 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465#issuecomment-6090593741). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-09T22:50:07Z. --- 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[bot] commented 2026-10-09 23:26:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T23:26:27Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090984211 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465#issuecomment-6090984211). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T23:26:27Z. --- <!-- progress-report --> ### Progress report (a11c8f7 → b3845e9) 📈 **System libraries**: 85.82% (+0.01%, +2 implemented, +1 declared functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `__powidf2_nid_postfix` | | libc | `libcCyberUnknown08` | </details> <details> <summary>🆕 1 declared as stubs</summary> | Library | Name | | - | - | | libc | `libcCyberUnknown02` | </details>
oneandonlydean commented 2026-10-11 05:09:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T05:09:25Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105707716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465#issuecomment-6105707716). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T05:09:25Z. --- 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`.
Mouhand-Kaddo commented 2026-10-11 07:26:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:26:44Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106666362 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465#issuecomment-6106666362). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-11T07:26:44Z. --- <!-- anyps5-platform-validation:aa7f1f4d6e416c700d92bfd28bf62de6d8e1b1d3 --> 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.
SwazNaj7 commented 2026-10-11 14:06:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SwazNaj7 on 2026-10-11T14:06:03Z.


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!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109855630 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465#issuecomment-6109855630). Originally posted by [SwazNaj7](https://github.com/SwazNaj7) on 2026-10-11T14:06:03Z. --- 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](https://github.com/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!
adriadam10 commented 2026-10-11 16:09:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T16:09:29Z.

Review: CHANGES_REQUESTED


Thanks for the rebase. The current head doesn't link when merged onto main (a11c8f7f7); 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483982855 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465#pullrequestreview-5483982855). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T16:09:29Z. **Review:** CHANGES_REQUESTED --- Thanks for the rebase. The current head doesn't link when merged onto `main` (a11c8f7f7); 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 commented 2026-10-14 02:33:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:33:19Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159592135 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2465#issuecomment-6159592135). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:33:19Z. --- Closing: `__powidf2` is on main since #5174. Reopen if something here is still missing on current main.

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