Skip to content

feat(libSceLibcInternal): implement significand exports - #25706

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
fogydes:feat/libSceLibcInternal-significand
Nov 22, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
fogydes:feat/libSceLibcInternal-significand

Conversation

@fogydes

@fogydes fogydes commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

What

Implements libSceLibcInternal significand (Az3tTyAy380) and significandf (L2YaHYQdmHw). Both follow libSceLibcInternal.sprx firmware 13.60 at 0x59b40 and 0x59b70: call ilogb, apply the 32-bit exponent negation including the INT_MIN wraparound, then call scalbn with the original input. The implementation reuses the existing libc providers and binds unique helpers with APS5_EXPORT, so the libc export-preservation rule does not leave unpatched names.

Coverage for this module:

  • Firmware 3.20 export table: 1206 missing / 1065 provided / 0 unknown -> 1204 / 1067 / 0.
  • tools/progress.py on current main 144d41ab69f: 676 done / 448 TODO / 1124 total -> 678 / 448 / 1126 (+2 implemented and +2 declared).
  • No console execution, title advancement or performance result is claimed. The remaining floating-point side-effect uncertainty is recorded in the debt fragment.

Tested

  • Windows, WinLibs GCC 15.2.0: built libSceLibcInternal, guest_libc_internal_significand_tests, guest_math_tests, nid_patcher and the patched module; guest_libc_internal_significand and guest_math passed 2/2.
  • Linux, Debian GCC 14.2.0 in WSL: built the same runtime/test targets; guest_libc_internal_significand and guest_math passed 2/2.
  • Negative control: the pre-implementation throwing body failed the new test with significand_nid_postfix not implemented (0xc0000409); the implemented body passes normal, subnormal, signed-zero, infinity and NaN checks in both precisions.
  • Verified both Az3tTyAy380 and L2YaHYQdmHw in the freshly patched PE export table.
  • check_conventions.py --base origin/main, debt_fold.py --check, check_test_registration.py, git diff --check and the 1406-header public include-graph validation passed.
  • The full branch overlap scan completed. The two additive insertion conflicts (feat(libSceLibcInternal): implement _Hypot, _FHypot and _LHypot #21704 and feat(libSceLibcInternal): implement _Tgamma, _FTgamma and _LTgamma #24969) and all seven unconfirmed shared-CMake cases were manually checked against their exact PR heads: no export implements significand/significandf, and there is no semantic dependency.

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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libc_internal_significand_tests built cleanly.
  • CTest (guest_libc_internal_significand):
    1/1 Test #4544: guest_libc_internal_significand ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/include/MathInternals.hpp, core/libs/prx/libSceLibcInternal/Significand.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified sceLibcInternalSignificand_nid_no_patch and sceLibcInternalSignificandF_nid_no_patch implementations in Significand.cpp follow PS5 firmware 13.60 assembly by delegating scalbn(x, -ilogb(x)) with NegateExponent handling INT_MIN safely without signed overflow UB
    • Verified special floating-point edge cases (normal numbers, subnormals, +/-0.0, +/-inf, NaN) produce correct IEEE-754 results matching BSD/FreeBSD significand semantics
    • Verified CMakeLists.txt target definition, test registration, target linking against libSceLibcInternal, libc, libkernel, and Windows unwind setup
    • Verified debt fragment formatting in docs/dev/debt/changes/feat-libSceLibcInternal-significand.md adheres to TechnicalDebt.md rules and documents known side-effect gaps
    • Verified AGENTS.md rules: no code comments, valid Conventional Commit PR metadata, no banned or untracked files

Looks Good To Me

@throny throny left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: ✅ correct, significand = scalbn(x, -ilogb(x)) for every input class

Basis: host check: the PR's formula vs the existing libc significand on 14 edge bit patterns and 2M random doubles (gcc) · head c59f863545

Checked

  • Az3tTyAy380/L2YaHYQdmHw are new (no hits on main).
  • ±0 keeps its sign (the INT_MIN negate wraps instead of UB), ±inf stays ±inf, quiet NaN bits unchanged, subnormals correct (ilogb reads bits, so DAZ doesn't matter: least subnormal → ±1.0), errno untouched (scalbn restores it). No differences from the libc implementation on non-NaN inputs.
  • Follows the 13.60 ilogb → negate → scalbn chain cited in the fragment.

Findings

  1. Minor: for a signalling NaN this raises FE_INVALID and returns the quieted NaN, while libc's significand returns the sNaN unchanged; the PR's behaviour is the one the firmware call chain implies. The test checks NaN with isnan only, so payload/sign aren't pinned.

Suggested action: merge

AI-assisted review (Claude Code) · head c59f863545 · base main 2c08875217

@MarcZX10 MarcZX10 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.

Reviewed — looks good

Nothing blocks this change; the implementation follows the stated exponent-scaling approach, and the inspected code supports merging.

What I ran

Reviewed head c59f8635456134d1e774a4c2b4005c69f33efb89. I did not run build or test commands; the Windows and WSL results in the PR description are author-reported.

repo_read.py: review/description.md, review/commits.md, review/manifest.json, review/diff.patch
repo_read.py: targeted source reads and searches

Results

Check Result Note
Diff and source review passed All five changed files read
Build and tests not run Results reported by author only
Negative control not run Reported by author only

Findings

Blocking

None.

Non-blocking

None.

Sources

  • The added wrappers use the existing ilogb/ilogbf and scalbn/scalbnf providers; the providers return INT_MIN for zero and INT_MAX for infinities and NaNs, and NegateExponent preserves INT_MIN as described.
  • The new test covers normal and subnormal inputs, signed zero, infinities, and NaNs for both precisions.

Not verified

No commands were run, and no console execution or title import was verified. The author-reported Windows and WSL test runs and export-table checks were not independently confirmed. No files were excluded from the prepared changed-file bundle.

To get this to a good state

Nothing is required.

@github-actions

Copy link
Copy Markdown

Progress report (719516a → c59f863)

📈 System libraries: 45.6% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libSceLibcInternal sceLibcInternalSignificandF_nid_no_patch
libSceLibcInternal sceLibcInternalSignificand_nid_no_patch

Changed libraries (implemented exports)

Library Before After Change
libSceLibcInternal 676/1124 (60.14%) 678/1126 (60.21%) +0.07%

@oneandonlydean
oneandonlydean merged commit 3ce5fcb into boykopovar:main Nov 22, 2026
14 checks passed
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.

5 participants