feat(libc): implement abs and __powidf2 #4229

Closed
MarcZX10 wants to merge 1 commit from upstream-pr/4229 into main
MarcZX10 commented 2026-10-12 01:48:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T01:48:18Z.


What

Implement the abs and __powidf2 libc exports imported by Cyberpunk 2077. abs(INT_MIN) follows FreeBSD's observed choice to return INT_MIN; __powidf2 uses compiler-rt's integer-exponent square-and-multiply behavior. Add bit and edge-case regression checks and document the behavior in TechnicalDebt. Carried from #3161's Linux-verified rebased branch, with its original commit author preserved. The patch is rebased onto current main and retains the current __powisf2 implementation and tests.

Tested

  • python3 tools/check_conventions.py --base upstream/main --head HEAD — passed.
  • git diff --check upstream/main...HEAD — passed.
  • #3161 reports guest_math passing on Windows and Linux; its rebased Linux run reports 520/520 in the full test subset.
  • Local Linux CMake configure could not proceed because this worktree's SDL2 submodule is unpopulated and Linux audio development headers are missing.

Checklist

  • Rebased against current main; reviewed overlapping Math.cpp and GuestMath.cpp changes.
  • One topic; tests and TechnicalDebt updated.
  • Depends on: none
  • AI-assisted: yes (carried commit authored by David; author preserved)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823979344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4229). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T01:48:18Z. --- ### What Implement the `abs` and `__powidf2` libc exports imported by Cyberpunk 2077. `abs(INT_MIN)` follows FreeBSD's observed choice to return `INT_MIN`; `__powidf2` uses compiler-rt's integer-exponent square-and-multiply behavior. Add bit and edge-case regression checks and document the behavior in TechnicalDebt. Carried from #3161's Linux-verified rebased branch, with its original commit author preserved. The patch is rebased onto current main and retains the current `__powisf2` implementation and tests. ### Tested - `python3 tools/check_conventions.py --base upstream/main --head HEAD` — passed. - `git diff --check upstream/main...HEAD` — passed. - #3161 reports `guest_math` passing on Windows and Linux; its rebased Linux run reports 520/520 in the full test subset. - Local Linux CMake configure could not proceed because this worktree's SDL2 submodule is unpopulated and Linux audio development headers are missing. ### Checklist - [x] Rebased against current `main`; reviewed overlapping Math.cpp and GuestMath.cpp changes. - [x] One topic; tests and TechnicalDebt updated. - [x] Depends on: none - [x] AI-assisted: yes (carried commit authored by David; author preserved)
MarcZX10 commented 2026-10-12 01:48:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T01:48:23Z.


Carried the #3161 implementation from the Linux-verified rebased branch onto current main. Its initial cherry-pick conflicted with current __powisf2 and TechnicalDebt edits; I merged those contexts and retained both changes plus all tests. Conventions and diff checks pass. The issue reports focused guest_math validation on Linux and Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116308394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4229#issuecomment-6116308394). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T01:48:23Z. --- Carried the #3161 implementation from the Linux-verified rebased branch onto current main. Its initial cherry-pick conflicted with current __powisf2 and TechnicalDebt edits; I merged those contexts and retained both changes plus all tests. Conventions and diff checks pass. The issue reports focused guest_math validation on Linux and Windows.
github-actions[bot] commented 2026-10-12 01:48:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T01:48:44Z.


Progress report (d371ed3 → 0fb168b)

📈 System libraries: 86.48% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc __powidf2_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116311466 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4229#issuecomment-6116311466). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T01:48:44Z. --- <!-- progress-report --> ### Progress report (d371ed3 → 0fb168b) 📈 **System libraries**: 86.48% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `__powidf2_nid_postfix` | </details>
github-actions[bot] commented 2026-10-12 01:55:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T01:55:08Z.


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
#2465 __powidf2_nid_postfix
#3690 core/libs/prx/libc/src/Math.cpp L38-39, L147-159
#3700 docs/dev/TechnicalDebt.md L680
#3870 docs/dev/TechnicalDebt.md L680
#3905 core/libs/tests/GuestMath.cpp L465
#4296 docs/dev/TechnicalDebt.md L680
#4343 core/libs/prx/libc/src/Math.cpp L38-39
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116366027 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4229#issuecomment-6116366027). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T01:55:08Z. --- <!-- 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 | |---|---|---|---| | #2465 | | `__powidf2_nid_postfix` | | | #3690 | `core/libs/prx/libc/src/Math.cpp` [L38-39](https://github.com/boykopovar/AnyPS5/blob/436e310ddb56fcf5dd1d40ba1f8113fe8cb8c113/core/libs/prx/libc/src/Math.cpp#L38-L39), [L147-159](https://github.com/boykopovar/AnyPS5/blob/436e310ddb56fcf5dd1d40ba1f8113fe8cb8c113/core/libs/prx/libc/src/Math.cpp#L147-L159) | | | | #3700 | `docs/dev/TechnicalDebt.md` [L680](https://github.com/boykopovar/AnyPS5/blob/436e310ddb56fcf5dd1d40ba1f8113fe8cb8c113/docs/dev/TechnicalDebt.md#L680) | | | | #3870 | `docs/dev/TechnicalDebt.md` [L680](https://github.com/boykopovar/AnyPS5/blob/436e310ddb56fcf5dd1d40ba1f8113fe8cb8c113/docs/dev/TechnicalDebt.md#L680) | | | | #3905 | `core/libs/tests/GuestMath.cpp` [L465](https://github.com/boykopovar/AnyPS5/blob/436e310ddb56fcf5dd1d40ba1f8113fe8cb8c113/core/libs/tests/GuestMath.cpp#L465) | | | | #4296 | `docs/dev/TechnicalDebt.md` [L680](https://github.com/boykopovar/AnyPS5/blob/436e310ddb56fcf5dd1d40ba1f8113fe8cb8c113/docs/dev/TechnicalDebt.md#L680) | | | | #4343 | `core/libs/prx/libc/src/Math.cpp` [L38-39](https://github.com/boykopovar/AnyPS5/blob/436e310ddb56fcf5dd1d40ba1f8113fe8cb8c113/core/libs/prx/libc/src/Math.cpp#L38-L39) | | |
oneandonlydean commented 2026-10-12 07:46:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T07:46:54Z.


Closing: this doesn't build. abs_nid_postfix is already on main (core/libs/prx/libc/src/Math.cpp:90, e2b11c2dd8) and the branch defines it a second time at Math.cpp:39, and H+8UBOwfScI is still exported as libcCyberUnknown08 in Export.cpp. __powidf2 is #2465's, and no title is shown calling it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6119989924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4229#issuecomment-6119989924). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T07:46:54Z. --- Closing: this doesn't build. `abs_nid_postfix` is already on main (`core/libs/prx/libc/src/Math.cpp:90`, e2b11c2dd8) and the branch defines it a second time at `Math.cpp:39`, and `H+8UBOwfScI` is still exported as `libcCyberUnknown08` in `Export.cpp`. `__powidf2` is #2465's, and no title is shown calling it.

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