Skip to content

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

Closed
Aryansh1520 wants to merge 3 commits into
boykopovar:mainfrom
Aryansh1520:feat/libc-sinhf-logb-nearbyintf-powisf2
Closed

Aryansh1520 wants to merge 3 commits into
boykopovar:mainfrom
Aryansh1520:feat/libc-sinhf-logb-nearbyintf-powisf2

Conversation

@Aryansh1520

Copy link
Copy Markdown
Contributor

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

PPSA28997 imports them. __powisf2 follows compiler-rt: repeated squaring
in float, with the reciprocal taken at the end for a negative exponent.
@github-actions github-actions Bot added the libc label Oct 9, 2026
@MarcZX10

MarcZX10 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Contributor Author

Updated in a046106.

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

Copy link
Copy Markdown
Contributor Author

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 7550255. The checks are unchanged, and this PR no longer edits GuestMath.cpp.

@popcoder565

Copy link
Copy Markdown
Contributor

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 d70b899 in one build with 38 other PRs that had no Windows run.

No title was run.

🤖 Addressed by Claude Code

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

ycbuzi pushed a commit to ycbuzi/AnyPS5 that referenced this pull request Oct 10, 2026
…f and __powisf2 checks to their own test

Harvested from upstream (closed unmerged); library completion 2835/3232 -> 2839/3236.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011krDVCnnMQPaEFEqCDnKmA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants