Skip to content

fix(libc): compute log10 with fdlibm's algorithm, as titles' libc.prx does - #10247

Merged
oneandonlydean merged 1593 commits into
boykopovar:mainfrom
JJenkx:windows/libc-log10-msun
Nov 2, 2026
Merged

oneandonlydean merged 1593 commits into
boykopovar:mainfrom
JJenkx:windows/libc-log10-msun

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What

log10 returned the host's log10, so its last bit and its errno depended on the host. On Windows (UCRT) it differs from the libc.prx that titles ship on 3,066,397 of 320 million random arguments. For example, log10(0x4003a67d5567227b) is 0x3fd8fa5a3b281494 in the bundled libc.prx and 0x3fd8fa5a3b281493 here, and log10(0x4047f462f020acde) is 0x3ffae2ff9b87b792 there and 0x3ffae2ff9b87b793 here.

The titles' copy (NID WuMbPBKN1TU) is not the FreeBSD 11.4 e_log10.c, which works through k_log1p. That version differs from the bundled library on about 1% of arguments. It is the older fdlibm e_log10.c over its k_log.h __kernel_log, the same lineage as the erff in #10226. log10 now computes it:

  • the same subnormal scaling and normalisation as log;
  • __kernel_log as a static Log10Kernel;
  • the ivln10hi/ivln10lo and log10_2hi/log10_2lo recombination, with x - 1 split at its low word.

errno: the bundled library's handling differs from log's (#10245). log10 sets EDOM for every nonzero argument with the sign bit set: the negative numbers, negative subnormals, -inf and negative NaNs. It leaves errno alone for ±0, where it returns -inf, and for positive NaN and +inf. This port does the same, and keeps the NaN payloads of fdlibm's x + x and (x - x) / 0. _Log with a positive base calls log10, and its existing test still passes: log10(1000) is exactly 3 here too.

Tested

Current Linux refresh: 19999e0615e1f97ce018d3cea034071743014e32 on main 6c52b649e7b1592f28db0cb8fe9ac604f0a242e7. Fresh isolated libc/math build passed; guest_math and guest_dinkumware_internals each passed three consecutive runs. Diff and conventions checks pass; math and test topic changes remain unchanged after rebase. Linux logs and rebase checks.

The Windows module comparisons and negative control below are historical evidence from original head a24a71c90f2add35da580c8bed491078c791a2d8; Windows was not rerun on the refreshed commit. The original report's console results mean the supplied titles' bundled libraries executed on the Windows host, not measurements on a physical console.

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, main 4997726.

  • Comparison: a scratch loader runs the decrypted libc.prx of PPSA07923, PPSA05916 and PPSA13934 natively and supplies __error. It compared their log10 with this PR's code, checking result bits (NaN payloads included) and errno, on two sets:

    • 320 million random arguments per title, half random bit patterns and half random significands with exponents 2^-32 to 2^31;
    • 31,165 structured arguments:
      • the integers 1 to 1024 and their reciprocals;
      • the 4,000 floats on each side of 1, 10 and −1;
      • every power of two from 2^-1074 to 2^1023;
      • every power of ten from 10^-300 to 10^300, with two neighbours on each side;
      • the special values.
    • PPSA07923 and PPSA05916: identical bits and errno on all of them.
    • PPSA13934: identical errno. The bits differ on 229,944 random arguments, because that copy is an FMA-contracted build.
  • guest_math: the new CheckLog10ConsoleBits has 26 cases with the bundled library's results and errno:

    • ±0, ± the smallest subnormal and the smallest normal;
    • 1 and its neighbours, 10, 1000 and 0.1;
    • both sides of the |f| < 2^-20 edge;
    • DBL_MAX, ±inf, −1 and NaN payloads of both signs;
    • six arguments where UCRT differs.

    guest_math and guest_dinkumware_internals pass in three runs out of three on the exact head.

  • Negative control: with main's Math.cpp and these tests, guest_math aborts in a Require, while guest_dinkumware_internals still passes.

  • python tools/check_conventions.py --base origin/main and git diff --check pass.

  • Overlap and order: Refreshed as one standalone log10 topic on main 6c52b649e7b1592f28db0cb8fe9ac604f0a242e7. The previous fix(libc): compute log with FreeBSD msun's algorithm, as titles' libc.prx does #10245 dependency described series order rather than a required implementation. Nearby math ports still share text/test/debt anchors. fix(libc): compute log2 with fdlibm's algorithm, as titles' libc.prx does #10317 requires this PR's kernel and remains stacked on it.

  • Not tested: macOS, a physical console, floating-point exception flags, and log10l. Original module comparison and negative control were Windows-only; the new Linux build and regression checks are scoped separately above.

Current Linux qualification (2026-10-28)

Rebased onto main 2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at 6bceecd018be481d9a2b66a36f1704472eeeca5f (Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON).

libc, guest_math_tests and guest_math_exact_tests rebuilt from this exact source. guest_math and guest_math_exact each passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass.

Exact source pins, preservation proofs, dependency checks, build logs and JUnit, SHA-256 1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed.

Canonical declaration cleanup (2026-10-28)

At 2f72ecea0435, removed 93 duplicate local export declarations from GuestMath.cpp; its included Api.hpp supplies them. Production code and numeric test bodies are unchanged. Original fails the actual header audit; candidate passes. Per-branch affected-test syntax compilation and conventions/whitespace pass; full standalone-header compilation passed once for the byte-identical header tree shared by the four affected PRs. Source/proofs/logs, SHA256 44f560018e4f6b52e8dda4158383f64fc3059fcdb6444840fe5c04fb2c884f11. No new numerical-runtime/platform claim; earlier runs retain original pins. Normal fast-forward only, no rebase. AI-assisted: Codex.

Current qualification — 2026-10-30

Integrated current main 08a10d225306ad102b57408e2ef7566bcfb829b2 into this existing topic at 476bb9f96cb5f66b7bfba9de65143f5d2568d24c. Current-main functions, fixtures, unrelated debt rows and exact dependency gitlinks are preserved; original topic functions and authored commits are retained.

Rebuilt actual Linux libc and focused test binaries. guest_math, guest_math_exact, guest_dinkumware_internals each passed three consecutive runs (9 runtime passes), plus public_headers; conventions and whitespace checks pass. Pinned main passed all seven selected runtime suites plus the header audit three times (24 runs). This is focused Linux CPU qualification; prior Windows/reference evidence retains its original pins. No new Windows, console, SDK-module, title, GPU or performance claim. AI-assisted: yes.

Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math6-main08a10-linux-20261030.tar.gz (SHA-256 b984a6334dce65b5c9148e3791ba21605074a5e762ea0f07f96de2f38062ef6e).

Checklist

AI-assisted (Claude Code).

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 11895 core/libs/tests/GuestMath.cpp L2710

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 5021 docs/dev/debt/libc.md
PR 6295 core/libs/prx/libc/src/Math.cpp
core/libs/tests/GuestMath.cpp
PR 7081 docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 9929 docs/dev/debt/libc.md
PR 10405 docs/dev/debt/libc.md
PR 10987 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11625 docs/dev/debt/libc.md
PR 11831 docs/dev/debt/libc.md
PR 12560 docs/dev/debt/libc.md
PR 14212 docs/dev/debt/libc.md

@JJenkx

JJenkx commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Linux run at this PR's exact head a24a71c90f (a24a71c90f2add35da580c8bed491078c791a2d8), not merged onto anything else; its base on main is 4997726a5f.

Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release, BUILD_TESTING=ON.

  • guest_math: passed in each of 3 runs, exit code 0 each time, with no failed, skipped or not-run tests.

This is the focused test only; no title, console or floating-point exception flags were checked.

AI-assisted: yes (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@JJenkx
JJenkx force-pushed the windows/libc-log10-msun branch from a24a71c to 19999e0 Compare October 24, 2026 04:30
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
JJenkx pushed a commit to JJenkx/AnyPS5 that referenced this pull request Oct 24, 2026
Additive conflicts with main's newer libc math changes: the debt list keeps
both sides' entries (per entry), the GuestMath.cpp test functions and calls
from both sides are kept, and Math.cpp keeps both sides' independent changes.

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

JJenkx commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main 1e20650e84 into this branch as 2e79449e8b (was 19999e0615), a merge commit rather than a rebase. Done on Linux while the Windows session is paused.

  • The conflicts were additive, next to main's newer libc math changes.
  • The docs/dev/debt/libc.md entry list keeps both sides' entries, checked per entry: this PR's entries keep their exact text, and so do main's.
  • GuestMath.cpp keeps both sides' test functions and calls.
  • New head, Linux only: guest_math and guest_math_exact pass (Arch Linux, kernel 7.2.9, GCC 16.2.1, glibc 2.44, Release, BUILD_TESTING=ON). tools/check_conventions.py --base origin/main reports no errors.
  • Earlier Windows and comparison evidence in this thread stays pinned to the heads it was measured on.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026

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

Checked against main 39a36bb and fdlibm e_log10.c and k_log.h at freebsd-src 59bc2f0952:

  • It merges cleanly into current main. Main's log10 is still the host's (Math.cpp:1082), and _Log (DinkumwareInternals.cpp:87) is the only internal caller.
  • I compared log10_nid_postfix and Log10Kernel line by line with e_log10.c and __kernel_log. Everything matches: the subnormal scaling, the 0x95f64 normalisation, the (2+hx) shortcut and i|=j select, and the hi/lo recombination order. After scaling a subnormal, the low word is correctly taken from the scaled value.
  • All the constants (two54, ivln10hi/lo, log10_2hi/lo, Lg1-Lg7) match the source literals and their hex comments.
  • I ran a separate Python transcription of the cited fdlibm source on the 21 non-special cases in CheckLog10ConsoleBits. All of them give the expected bits, including the subnormals, DBL_MAX and the six UCRT-differing arguments.
  • Small note: this PR and #10253 both add their test function and call at the same place in GuestMath.cpp (just before CheckExpm1ConsoleBits), so they conflict textually and the second to land needs a trivial rebase.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

@ycbuzi

ycbuzi commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Windows run of 2e79449 merged onto main fa515de (ee16a2bb1a, clean), since Windows was not run on this head. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libc, guest_math_tests and guest_dinkumware_internals_tests with no errors or warnings. ctest --repeat until-fail:2 on guest_math and guest_dinkumware_internals: both pass on both repeats. Negative control: with src/Math.cpp taken from main and the rest of this head, guest_math aborts (exit code 0xc0000409) and guest_dinkumware_internals still passes. Not run: a title.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 24, 2026
adriadam10 and others added 15 commits October 30, 2026 02:31
…h-window-buffer

fix(shader): keep mesh register windows out of local memory on NVIDIA
fix(libkernel): return EFAULT from the utimes family for an unreadable times array
…-size-and-event-queries

test(libSceRudp): cover max segment size and event lifecycle in GuestRudpStatus
fix(libkernel): return EFAULT from rtprio_thread and sched_rr_get_interval for a bad pointer
…ker-relative-jump-tables-address-space-bounds

fix(relinker): validate text section range before scanning relative jump tables
…sample-alpha-to-coverage

fix(agc): reject unmeasured single-sample dithered alpha-to-coverage
…module-pins

build(deps): restore the SPIRV-Tools, SPIRV-Headers and libvorbis pins
…-header-validation

fix(libc): validate guest heap block headers before freeing
…raw-pipeline-report-duplicate-format

fix(agc): eliminate duplicated read counters in pipelined draw reports
…ata-backup-dir-name-validation

fix(libSceSaveData.native): validate directory name in sceSaveDataBackup
…port

feat(agc): host system report and an actionable missing-Vulkan-feature message
…r-callbacks

feat(libSceIcu): implement converter stop and skip callbacks
…-sys-is-ps4-process

feat(libkernel_sys): implement sceKernelIsPs4Process query
…n-memory-font-entry

fix(libSceFont): reuse a font context entry by address only while it is active
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 30, 2026
@JJenkx

JJenkx commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Integrated current main 08a10d225306ad102b57408e2ef7566bcfb829b2 into this existing topic at 476bb9f96cb5f66b7bfba9de65143f5d2568d24c. Current-main functions, fixtures, unrelated debt rows and exact dependency gitlinks are preserved; original topic functions and authored commits are retained.

Rebuilt actual Linux libc and focused test binaries. guest_math, guest_math_exact, guest_dinkumware_internals each passed three consecutive runs (9 runtime passes), plus public_headers; conventions and whitespace checks pass. Pinned main passed all seven selected runtime suites plus the header audit three times (24 runs). This is focused Linux CPU qualification; prior Windows/reference evidence retains its original pins. No new Windows, console, SDK-module, title, GPU or performance claim. AI-assisted: yes.

Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math6-main08a10-linux-20261030.tar.gz (SHA-256 b984a6334dce65b5c9148e3791ba21605074a5e762ea0f07f96de2f38062ef6e).

@oneandonlydean
oneandonlydean merged commit 67a7602 into boykopovar:main Nov 2, 2026
19 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.