Skip to content

feat(libSceLibcInternal): implement the _Pow family for Dinkumware's pow - #21722

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Krille2004zzz:feat/libsce-libcinternal-pow
Nov 17, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Krille2004zzz:feat/libsce-libcinternal-pow

Conversation

@Krille2004zzz

@Krille2004zzz Krille2004zzz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements _Pow, _FPow and _LPow in libSceLibcInternal (new ScaledPow.cpp), replacing the parameterless stubs. Only the argument Dinkumware's own pow passes is implemented; any other argument still throws through NotImplemented_nid_no_patch. Because of that, tools/progress.py still counts all three as pending.

  • Signature. _Pow(x, y, short *pex) (and the float and long double forms) comes from the declaration in Dinkumware V6.50's xxpow.h.
  • Behaviour. In the same file, Dinkumware's pow(x, y) is return _Pow(x, y, 0); (xxpow.h). So a null pex returns libc's pow, powf or powl. A non-null pex throws: no caller there shows what the module writes through it or how it scales the result. No Dinkumware implementation is ported or used.
  • Results. They come from libc's msun pow/powf/powl, not Dinkumware's code, so last bits can differ.
  • Debt. A Functional entry records that none of this is measured on the console's module.
  • _Logpoly, _FLogpoly and _LLogpoly stay stubbed. Their only callers are inside Dinkumware's own _Pow and log code, so nothing public pins down their argument or result. To implement them honestly, someone needs a firmware measurement: the return value for a few w values in roughly [-0.2, 0.2].
  • No measurements. None were available. Nothing in this repository's PRs or issues measures these six, so no measurement is credited.

Tested

Linux x86-64 (Debian, GCC 14.2.0), Release, BUILD_TESTING=ON, rebased on current main. No title tested.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 1ba49db5ae:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libc_internal_scaled_pow_tests built cleanly.
  • CTest (guest_libc_internal_scaled_pow):
    1/1 Test #4065: guest_libc_internal_scaled_pow ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/Export.cpp, core/libs/prx/libSceLibcInternal/include/MathInternals.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified in core/libs/prx/libSceLibcInternal/ScaledPow.cpp and core/libs/prx/libSceLibcInternal/include/MathInternals.hpp that _Pow_nid_postfix, _FPow_nid_postfix, and _LPow_nid_postfix use APS5_VABI, match Dinkumware's (T x, T y, short* exponent) signatures, and have their old parameterless stubs removed from core/libs/prx/libSceLibcInternal/Export.cpp.
    • Verified in core/libs/prx/libSceLibcInternal/ScaledPow.cpp that a non-null exponent pointer triggers NotImplemented_nid_no_patch without dereferencing or mutating *exponent, while a nullptr exponent delegates directly to pow_nid_postfix, powf_nid_postfix, and powl_nid_postfix.
    • Verified that docs/dev/debt/changes/feat-libsce-libcinternal-pow.md properly documents the unmeasured console behavior, the non-null exponent gap, and the msun rounding difference under libSceLibcInternal (## add Functional).
    • Verified in core/libs/tests/GuestLibcInternalScaledPow.cpp and core/libs/prx/libSceLibcInternal/CMakeLists.txt that guest_libc_internal_scaled_pow_tests tests finite, zero, negative, overflowing, infinite, and NaN inputs (checking both value equality and std::signbit) for null exponent and verifies that non-null exponent throws std::runtime_error without modifying exponent.
    • Checked cross-platform LP64/LLP64 portability and CMake test configuration (configure_windows_unwind and WIN32 PATH modification for libSceLibcInternal).

Looks Good To Me

@oneandonlydean

Copy link
Copy Markdown
Collaborator

The implementation is fine for the case it covers: with a null exponent pointer _Pow, _FPow and _LPow return libc's pow, powf and powl, which is how Dinkumware's own pow calls them, and the signatures replace the old parameterless stubs. The problem is in GuestLibcInternalScaledPow.cpp: lines 56 to 59 only assert that a non-null exponent pointer makes each function throw (Require(Throws(...)), plus the unwritten-exponent check that depends on it). That throw is NotImplemented_nid_no_patch, the library saying it does not know what the module writes through the pointer, so the checks fail the day someone implements it.

Please drop those four lines and keep the null-exponent checks, which compare real results.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 13778 core/libs/prx/libSceLibcInternal/CMakeLists.txt
PR 17300 core/libs/prx/libSceLibcInternal/Export.cpp
PR 18135 core/libs/prx/libSceLibcInternal/CMakeLists.txt
core/libs/prx/libSceLibcInternal/Export.cpp
PR 19434 core/libs/prx/libSceLibcInternal/CMakeLists.txt
PR 20059 core/libs/prx/libSceLibcInternal/CMakeLists.txt

@Krille2004zzz

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Done: I dropped the assertions on the unimplemented non-null exponent path and kept the null-pointer checks against pow/powf/powl. I also removed the same kind of assertions from #21716.

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.

3 participants