feat(libc): implement __powidf2 #2158

Closed
reyani-dev wants to merge 1 commit from upstream-pr/2158 into main
reyani-dev commented 2026-10-09 10:15:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T10:15:27Z.


What

Implements __powidf2 (NID H+8UBOwfScI), replacing the libcCyberUnknown08 stub. It was one of the functions in #492, split out as suggested in that review.

  • Signature double __powidf2(double a, int b), as in compiler-rt lib/builtins/powidf2.c and libgcc libgcc2.c.
  • Same square-and-multiply loop as compiler-rt, so results round exactly as on the console. This covers review point 4 on #492: repeated multiplication rounds differently from x^4 on and is slow for large exponents.
  • Negative exponents, including INT_MIN, return 1 / r without negating the exponent.
  • Title: imported by Cyberpunk 2077 (PPSA04029), which the old stub name refers to. I don't have the title and haven't run it.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, -DBUILD_TESTING=ON:

  • New checks in guest_math_tests, next to exp2:
    • exact cases: x^0, 2^10, (-2)^3, 2^-2, 2^INT_MIN == 0, 0.5^INT_MIN == inf, (-1)^INT_MAX == -1, NaN propagation;
    • rounding: 1.1^4, 1.1^5 and 1.1^-4 must equal the square-and-multiply products;
    • __builtin_powi (libgcc __powidf2) for every exponent from -40 to 40.
  • Mutation check: replacing the loop with repeated multiplication makes guest_math fail, so the test pins the rounding.
  • ctest -R guest_math passes.
  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no conflict with other open PRs.
  • cmake --build build --target libs builds and NID-patches every library; the patched libc.prx exports H+8UBOwfScI, and tools/nid_names.py no longer lists it.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4799060468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2158). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T10:15:27Z. --- ### What Implements `__powidf2` (NID `H+8UBOwfScI`), replacing the `libcCyberUnknown08` stub. It was one of the functions in #492, split out as suggested in that review. - Signature `double __powidf2(double a, int b)`, as in compiler-rt `lib/builtins/powidf2.c` and libgcc `libgcc2.c`. - Same square-and-multiply loop as compiler-rt, so results round exactly as on the console. This covers review point 4 on #492: repeated multiplication rounds differently from x^4 on and is slow for large exponents. - Negative exponents, including `INT_MIN`, return `1 / r` without negating the exponent. - Title: imported by Cyberpunk 2077 (PPSA04029), which the old stub name refers to. I don't have the title and haven't run it. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - New checks in `guest_math_tests`, next to `exp2`: - exact cases: `x^0`, `2^10`, `(-2)^3`, `2^-2`, `2^INT_MIN == 0`, `0.5^INT_MIN == inf`, `(-1)^INT_MAX == -1`, NaN propagation; - rounding: `1.1^4`, `1.1^5` and `1.1^-4` must equal the square-and-multiply products; - `__builtin_powi` (libgcc `__powidf2`) for every exponent from -40 to 40. - Mutation check: replacing the loop with repeated multiplication makes `guest_math` fail, so the test pins the rounding. - `ctest -R guest_math` passes. - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no conflict with other open PRs. - `cmake --build build --target libs` builds and NID-patches every library; the patched `libc.prx` exports `H+8UBOwfScI`, and `tools/nid_names.py` no longer lists it. ### 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 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-09 10:16:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T10:16:13Z.


Progress report (51f69aa → ef27d8f)

📈 System libraries: 84.72% (+0.03%, +1 implemented, -1 removed functions)

✅ 1 implemented
Library Name
libc __powidf2_nid_postfix
🗑️ 1 removed
Library Name
libc libcCyberUnknown08
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078905639 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2158#issuecomment-6078905639). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T10:16:13Z. --- <!-- progress-report --> ### Progress report (51f69aa → ef27d8f) 📈 **System libraries**: 84.72% (+0.03%, +1 implemented, -1 removed functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `__powidf2_nid_postfix` | </details> <details> <summary>🗑️ 1 removed</summary> | Library | Name | | - | - | | libc | `libcCyberUnknown08` | </details>
MarcZX10 commented 2026-10-09 10:19:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T10:19:57Z.


I reviewed the full diff against LLVM compiler-rt's powidf2 implementation. The square-and-multiply loop and reciprocal handling match the reference, and the signed halving avoids negating INT_MIN. I found no correctness issue in the implementation or test diff.

The current upstream checks ran eligibility, conventions and the relinker matrix; Linux and Windows full-build jobs were skipped. Since this changes a system library, CONTRIBUTING requires the full build and relevant runtime tests. Please arrange a collaborator-triggered Build on this head before final review; I have not submitted an approval while those checks are absent.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078958525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2158#issuecomment-6078958525). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T10:19:57Z. --- I reviewed the full diff against LLVM compiler-rt's `powidf2` implementation. The square-and-multiply loop and reciprocal handling match the reference, and the signed halving avoids negating `INT_MIN`. I found no correctness issue in the implementation or test diff. The current upstream checks ran eligibility, conventions and the relinker matrix; Linux and Windows full-build jobs were skipped. Since this changes a system library, CONTRIBUTING requires the full build and relevant runtime tests. Please arrange a collaborator-triggered Build on this head before final review; I have not submitted an approval while those checks are absent.
reyani-dev commented 2026-10-09 11:24:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T11:24:32Z.


@MarcZX100 thanks for the review. Full Linux and Windows builds and tests for this head (ef27d8fe), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (d70b8998):

Job Result
linux full build, ctest: 516/516 passed
windows full build, ctest: 507/507 passed
relinker (Linux, Windows, macOS) passed

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37920402135

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079901283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2158#issuecomment-6079901283). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T11:24:32Z. --- @MarcZX100 thanks for the review. Full Linux and Windows builds and tests for this head (`ef27d8fe`), using the project's Build workflow. I can't start the upstream manual run, so I ran the same `build.yml` in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current `main` (`d70b8998`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/37920402135/job/113786746543) | full build, `ctest`: 516/516 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/37920402135/job/113786746201) | full build, `ctest`: 507/507 passed | | relinker (Linux, Windows, macOS) | passed | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37920402135
github-actions[bot] commented 2026-10-09 15:28:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T15:28:22Z.


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
#2301 core/libs/prx/libc/Export.cpp L69-77
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083971462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2158#issuecomment-6083971462). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T15:28:22Z. --- <!-- 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 | |---|---|---|---| | #2301 | `core/libs/prx/libc/Export.cpp` [L69-77](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/prx/libc/Export.cpp#L69-L77) | | |
oneandonlydean commented 2026-10-09 20:09:10 +00:00 (Migrated from github.com)

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


Closing: the only evidence is that Cyberpunk 2077 imports __powidf2, and no title is shown reaching the stub on main. The implementation itself looks right, so please reopen with the title ID and the log line once one stops there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088429621 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2158#issuecomment-6088429621). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:09:10Z. --- Closing: the only evidence is that Cyberpunk 2077 imports `__powidf2`, and no title is shown reaching the stub on main. The implementation itself looks right, so please reopen with the title ID and the log line once one stops there.

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