Skip to content

feat(libSceLibcInternal): implement the Dinkumware extended-precision helpers - #16237

Open
Ducengarth wants to merge 3 commits into
boykopovar:mainfrom
Ducengarth:feat/libcinternal-extended-precision
Open

Ducengarth wants to merge 3 commits into
boykopovar:mainfrom
Ducengarth:feat/libcinternal-extended-precision

Conversation

@Ducengarth

Copy link
Copy Markdown

What

Implement 26 Dinkumware extended-precision helpers in libSceLibcInternal, replacing their parameterless throwing placeholders in Export.cpp:

  • _Dtento, _FDtento, _LDtento: *value * 10^power, where value points to a three-word extended-precision accumulator that is updated in place. On overflow or underflow they set the guest errno to ERANGE (34) and OR 1 into *error when it is not null.
  • _FXp_addh, _FXp_addx, _FXp_invx, _FXp_ldexpx, _FXp_movx, _FXp_mulh, _FXp_mulx, _FXp_setn, _FXp_setw, _FXp_sqrtx, _FXp_subx (float).
  • _LXp_addh, _LXp_addx, _LXp_getw, _LXp_invx, _LXp_ldexpx, _LXp_movx, _LXp_mulh, _LXp_mulx, _LXp_setn, _LXp_setw, _LXp_sqrtx, _LXp_subx (long double).

An extended-precision value is an array of words in decreasing magnitude, each holding at most half the significand (12 bits for float, 26 for double, 32 for long double), ended by a zero word. One template in the new ExtendedPrecision.cpp serves all three types.

Source: Dinkumware V6.00 as shipped with Visual C++ 2013 (xxxprec.h, xxxdtent.h, prototypes in xmath.h), the reference the debt file already uses for _Thrd_sleep. The code is written from that algorithm, not copied. long arguments are std::int64_t, as in the PS5 ABI. Differences from V6.00, all recorded in docs/dev/debt/libSceLibcInternal.md:

  • _LXp_getw and the reads inside _Dtento follow the console's _FXp_getw from feat(libSceLibcInternal): answer _Daysto, _FXp_getw and _Isdst as firmware 13.42 does #14945, read from firmware 13.42: they add the fourth word when there are at least four, instead of V6.00's sticky bit. This also means the console runs a later revision than V6.00, so other helpers may differ in details.
  • Inputs on which V6.00 reads past an array or never returns are defined here. A one-word _Xp_mulx multiplier reads only that word (same result). A word count below 1 does nothing in _Xp_movx, _Xp_addh, _Xp_invx and _Xp_sqrtx, where V6.00 calls memcpy with a negative size for a finite invx or sqrtx argument. A _Dtento power of LONG_MIN underflows instead of looping on n = -n. The _Xp_addh carry bit count is not truncated to short.

Scope: _FXp_getw is already in main (#14945). The double _Xp_* exports are still unnamed placeholders, and #15777 names them; they can follow once it merges. _FAtan, _FSincos, _FTan, _FTgamma, _FLogpoly, _FQuad, _FQuadph and their _L and double versions still throw: no source I found gives their signatures or code.

No title's trace or disassembly was used, and no export was measured on a PS5.

pr_overlap reports no other pull request with the same exports or new files, only line conflicts: #15767 adds other math declarations between these in MathInternals.hpp and next to the _Dtento stubs in Export.cpp, #13881 and #14085 edit neighbouring debt lines, and #15665 and my #16146 add a test block at the same place in CMakeLists.txt. Whichever merges second resolves them; I will rebase this one as needed. Nine pull requests that conflict with main could not be compared by the tool (#5021, #13486, #13778, #13782, #14212, #14664, #14936, #15581, #15899); none of their diffs adds any of these 26 names.

Tested

Windows 11, MinGW-w64 GCC (WinLibs), Release build. No title or homebrew, and not built on Linux.

  • guest_libc_internal_extended_precision (new) passes, and passed 3 more runs in a row. It calls every one of the 26 exports, and _FXp_getw from main, and checks:
    • setw splits 20000 random floats into two exact half-width words, plus zero, one word, infinity, no room and subnormals.
    • setn holds 32-bit integers exactly and rounds the quotient by 10000 to float first for wider ones.
    • addh keeps exact sums of half-precision addends in decreasing words, and handles cancellation, infinity, Inf - Inf (FE_INVALID), NaN and a full array.
    • mulh and mulx keep exact or six-word products.
    • movx, ldexpx, addx and subx behave as above, and so do invx and sqrtx, within 2^-40 and 2^-36 of the exact result, read back within one ulp. sqrtx also covers negative values, -0 and ±infinity.
    • _Dtento gives correctly rounded powers of ten from 10^-22 to 10^22, the exact one-tenth words for each type, overflow, underflow, a null error pointer and a power of INT64_MIN.
    • _LXp_getw adds a fourth word where V6.00's sticky bit would round differently.
  • Making getw ignore the fourth word, making mulh drop the low half of a partial product, or changing the last word of the long double one-tenth table each makes the test fail with the matching message.
  • guest_libc_internal_firmware_answers, guest_libc_internal_aligned_new, guest_libc_internal_exception_destructors, guest_libc_internal_mtx, guest_libc_internal_pad and guest_statvfs pass. The full suite was not run.
  • objdump -p on libSceLibcInternal.prx lists all 26 names.
  • python3 tools/check_conventions.py --base upstream/main passes.

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

🤖 Generated with Claude Code

… helpers

Implement _Dtento, _FDtento, _LDtento, the float _FXp_* helpers other
than _FXp_getw and the twelve long double _LXp_* helpers after
Dinkumware V6.00 as shipped with Visual C++ 2013. _LXp_getw and the
reads inside _Dtento follow the console's _FXp_getw. Record the
unverified console behaviour and the differences from V6.00 as debt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Windows check of head c3798b1149, merged onto main bf80054e7c (76c6252c44, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_libc_internal_extended_precision passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Progress report (6bf3a19 → bfbd4f9)

📈 System libraries: 29.91% (+0.06%, +26 implemented functions)

✅ 26 implemented
Library Name
libSceLibcInternal _Dtento_nid_postfix
libSceLibcInternal _FDtento_nid_postfix
libSceLibcInternal _FXp_addh_nid_postfix
libSceLibcInternal _FXp_addx_nid_postfix
libSceLibcInternal _FXp_invx_nid_postfix
libSceLibcInternal _FXp_ldexpx_nid_postfix
libSceLibcInternal _FXp_movx_nid_postfix
libSceLibcInternal _FXp_mulh_nid_postfix
libSceLibcInternal _FXp_mulx_nid_postfix
libSceLibcInternal _FXp_setn_nid_postfix
libSceLibcInternal _FXp_setw_nid_postfix
libSceLibcInternal _FXp_sqrtx_nid_postfix
libSceLibcInternal _FXp_subx_nid_postfix
libSceLibcInternal _LDtento_nid_postfix
libSceLibcInternal _LXp_addh_nid_postfix
libSceLibcInternal _LXp_addx_nid_postfix
libSceLibcInternal _LXp_getw_nid_postfix
libSceLibcInternal _LXp_invx_nid_postfix
libSceLibcInternal _LXp_ldexpx_nid_postfix
libSceLibcInternal _LXp_movx_nid_postfix
libSceLibcInternal _LXp_mulh_nid_postfix
libSceLibcInternal _LXp_mulx_nid_postfix
libSceLibcInternal _LXp_setn_nid_postfix
libSceLibcInternal _LXp_setw_nid_postfix
libSceLibcInternal _LXp_sqrtx_nid_postfix
libSceLibcInternal _LXp_subx_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibcInternal 106/1141 (9.29%) 132/1141 (11.57%) +2.28%

…xtended-precision

# Conflicts:
#	docs/dev/debt/libSceLibcInternal.md
…/libcinternal-extended-precision

# Conflicts:
#	docs/dev/debt/libSceLibcInternal.md

This branch has not been deployed

No deployments
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.

2 participants