feat(libc): implement logb, sinhf, nearbyintf and __powisf2 #2037

Closed
Aryansh1520 wants to merge 3 commits from upstream-pr/2037 into main
Aryansh1520 commented 2026-10-09 05:36:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-09T05:36:51Z.


What

PPSA28997 (God of War Sons of Sparta) imports these four functions, and none of them is exported yet.

  • logb, sinhf and nearbyintf forward to the C++ standard library, like their existing neighbours (logbf, sinf).
  • __powisf2, the compiler-rt helper for powi on floats, uses compiler-rt's algorithm: repeated squaring in float, then the reciprocal for a negative exponent.

Tested

  • Linux (CachyOS, kernel 7.2), GCC: PPSA28997 (God of War Sons of Sparta) runs past the calls.
  • tools/check_conventions.py --base origin/main and tools/pr_overlap.py --branch pass.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796455768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2037). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-09T05:36:51Z. --- ### What PPSA28997 (God of War Sons of Sparta) imports these four functions, and none of them is exported yet. - `logb`, `sinhf` and `nearbyintf` forward to the C++ standard library, like their existing neighbours (`logbf`, `sinf`). - `__powisf2`, the compiler-rt helper for `powi` on floats, uses compiler-rt's algorithm: repeated squaring in `float`, then the reciprocal for a negative exponent. ### Tested - Linux (CachyOS, kernel 7.2), GCC: PPSA28997 (God of War Sons of Sparta) runs past the calls. - `tools/check_conventions.py --base origin/main` and `tools/pr_overlap.py --branch` pass. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
MarcZX10 commented 2026-10-09 05:57:50 +00:00 (Migrated from github.com)

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


Please add focused tests to guest_math for logb, sinhf, nearbyintf and powisf2, including exponents 0, -1 and INT_MIN, plus special values. The for-loop increment squares base after remaining has become zero; exponent 1 therefore computes an unused FLT_MAX * FLT_MAX, which can raise overflow. LLVM compiler-rt stops before that final square (reference: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/powisf2.c). I built exact head 23c84b2d on Linux with GCC 12; the existing guest_math passed 1/1 in 0.02 s and conventions passed, but that test does not cover these new exports. No GitHub checks are reported for this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6075239335 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2037#issuecomment-6075239335). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T05:57:50Z. --- Please add focused tests to guest_math for logb, sinhf, nearbyintf and powisf2, including exponents 0, -1 and INT_MIN, plus special values. The for-loop increment squares base after remaining has become zero; exponent 1 therefore computes an unused FLT_MAX * FLT_MAX, which can raise overflow. LLVM compiler-rt stops before that final square (reference: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/powisf2.c). I built exact head 23c84b2d on Linux with GCC 12; the existing guest_math passed 1/1 in 0.02 s and conventions passed, but that test does not cover these new exports. No GitHub checks are reported for this head.
oneandonlydean commented 2026-10-09 09:22:52 +00:00 (Migrated from github.com)

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


Which of these does PPSA28997 stop at on main? Please add that log line; with it and the tests MarcZX100 asked for, this can go in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078129233 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2037#issuecomment-6078129233). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:22:52Z. --- Which of these does PPSA28997 stop at on main? Please add that log line; with it and the tests MarcZX100 asked for, this can go in.
Aryansh1520 commented 2026-10-09 10:36:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-09T10:36:51Z.


Updated in a046106a.

  • __powisf2 now follows compiler-rt exactly: it halves the exponent and stops before squaring once it reaches zero, so exponent 1 no longer computes the unused FLT_MAX * FLT_MAX. With GCC 12+ at -O2 the old dead square was already optimized away (the new overflow-flag check passed on both versions here), but the code no longer depends on that.
  • guest_math now covers logb (powers of two, negatives, denormal min, max, ±0, -inf, NaN), sinhf (±0 sign, known values, overflow to ±inf, ±inf, NaN), nearbyintf (ties to even, -0 sign, large values, no FE_INEXACT, upward and toward-zero rounding modes) and __powisf2 (exponents 0, 1, -1, 10, 127, 128, -126, INT_MAX, INT_MIN; zero, infinity and NaN bases; no FE_OVERFLOW for FLT_MAX^1 and FLT_MAX^-1).

On where PPSA28997 stops: I don't have a log line for these four. I found them statically, among the unresolved imports of the title's modules (logb from Il2cppUserAssemblies.prx, nearbyintf from eboot.elf, sinhf and __powisf2 in the libc import table), and implemented them before any run reached them. So no recorded run stopped at one of them, and I won't claim a line I didn't see. On main (as of Oct 8) the title stops earlier, at LTov9gMEqCU (std::ios_base::_Addstd, covered by #545).

The build workflows on this head are waiting for approval to run (fork PR).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079202197 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2037#issuecomment-6079202197). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-09T10:36:51Z. --- Updated in a046106a. - `__powisf2` now follows compiler-rt exactly: it halves the exponent and stops before squaring once it reaches zero, so exponent 1 no longer computes the unused `FLT_MAX * FLT_MAX`. With GCC 12+ at -O2 the old dead square was already optimized away (the new overflow-flag check passed on both versions here), but the code no longer depends on that. - `guest_math` now covers `logb` (powers of two, negatives, denormal min, max, ±0, -inf, NaN), `sinhf` (±0 sign, known values, overflow to ±inf, ±inf, NaN), `nearbyintf` (ties to even, -0 sign, large values, no `FE_INEXACT`, upward and toward-zero rounding modes) and `__powisf2` (exponents 0, 1, -1, 10, 127, 128, -126, INT_MAX, INT_MIN; zero, infinity and NaN bases; no `FE_OVERFLOW` for `FLT_MAX^1` and `FLT_MAX^-1`). On where PPSA28997 stops: I don't have a log line for these four. I found them statically, among the unresolved imports of the title's modules (`logb` from `Il2cppUserAssemblies.prx`, `nearbyintf` from `eboot.elf`, `sinhf` and `__powisf2` in the libc import table), and implemented them before any run reached them. So no recorded run stopped at one of them, and I won't claim a line I didn't see. On main (as of Oct 8) the title stops earlier, at `LTov9gMEqCU` (`std::ios_base::_Addstd`, covered by #545). The build workflows on this head are waiting for approval to run (fork PR).
Aryansh1520 commented 2026-10-09 10:53:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-09T10:53:14Z.


To avoid the GuestMath.cpp overlap with #1818 and #2038, the new checks now live in their own test, GuestFloatMath.cpp (guest_float_math), in 7550255d. The checks are unchanged, and this PR no longer edits GuestMath.cpp.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079439432 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2037#issuecomment-6079439432). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-09T10:53:14Z. --- To avoid the `GuestMath.cpp` overlap with #1818 and #2038, the new checks now live in their own test, `GuestFloatMath.cpp` (`guest_float_math`), in 7550255d. The checks are unchanged, and this PR no longer edits `GuestMath.cpp`.
popcoder565 commented 2026-10-09 15:46:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:46:26Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 7550255d, merged onto main d70b8998 in one build with 38 other PRs that had no Windows run.

  • This PR's tests pass: guest_float_math. None of them reported skipping a case.
  • Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084271810 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2037#issuecomment-6084271810). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:46:26Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `7550255d`, merged onto `main` d70b8998 in one build with 38 other PRs that had no Windows run. - This PR's tests pass: `guest_float_math`. None of them reported skipping a case. - Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
oneandonlydean commented 2026-10-09 20:08:29 +00:00 (Migrated from github.com)

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


Closing: on main PPSA28997 stops at LTov9gMEqCU (#545) before it reaches any of these, and library functions go in when a title stops on them. Please reopen with the log line once one of them is the stop.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088419677 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2037#issuecomment-6088419677). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:08:29Z. --- Closing: on main PPSA28997 stops at `LTov9gMEqCU` (#545) before it reaches any of these, and library functions go in when a title stops on them. Please reopen with the log line once one of them is the stop.

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