fix(libc): compute expm1l with FreeBSD msun's ld80 s_expl.c #19346
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19346"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by AlfaRojo on 2026-11-13T04:56:39Z.
What
expm1lreturned the host'sstd::expm1. It now follows theexpm1lof FreeBSD msun's ld80s_expl.c(release/11.4.0), reusing theexpltable and constants added in #18525. The debt entry indocs/dev/debt/libc.mdis updated.This is stacked on #18525, so the diff shows that PR's commits until it merges; this PR's own commit is
cd9a06a148.Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release.
core/libs/tests/GuestMath.cpp:3398: requirement failed, the first overflow exception-flag check. They pass with the port;guest_math,guest_math_elementaryandguest_math_exactpass 3 of 3.expm1ldiffers from that source by one ulp in 13 of the 72 pinned table inputs (for example x = 1.0) and in the exception flags it raises.libc.prx; the 11.4.0 source is the only evidence.tools/check_conventions.pyagainstorigin/fix/libc-expl-hyperbolic-msunand againstupstream/main: 0 errors, 1 existing debt-length warning on the host-math list line.expm1l. No other open PR defines it.d05d475996(merged with upstream/main, which now has #18525 and #19328):guest_math,guest_math_elementaryandguest_math_exact, all three test executables rebuilt, pass in 3/3 runs;check_conventions.py --base upstream/mainreports no errors.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T04:58:04Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
cd9a06a148:tools/check_conventions.pypassed;git diff --checkclean.guest_math_testsbuilt cleanly.guest_math,guest_math_elementary,guest_math_exact):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T17:02:39Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
3f9020345a:tools/check_conventions.pypassed;git diff --checkclean.guest_math_testsbuilt cleanly.guest_math,guest_math_elementary,guest_math_exact):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T23:03:40Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d05d475996:tools/check_conventions.pypassed;git diff --checkclean.guest_math_testsbuilt cleanly.guest_math,guest_math_elementary,guest_math_exact):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T20:55:30Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d05d475996:tools/check_conventions.pypassed;git diff --checkclean.guest_math_testsbuilt cleanly.guest_math):core/libs/prx/libc/src/Math.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Expm1lMsunspecial-case handling incore/libs/prx/libc/src/Math.cpp:4290-4300against FreeBSD 11.4.0ld80/s_expl.c(expm1l):exponent >= ExplBias + 6properly separatesNaN/+-Inf(exponent == ExplBias + 16384, returning-1 / x - 1for-Inf,x + xfor+Inf/NaN), overflow (x > ExplOverflowThresholdreturningExplHuge * ExplHuge), and large negative inputs ((signExponent & 0x8000) != 0returningExplTiny + -1).Expm1lSeriesincore/libs/prx/libc/src/Math.cpp:4251-4262for|x| < 0.1659: tiny exponent branch (exponent < ExplBias - 74) preserves signed zero and raisesFE_INEXACTvia(0x1p100 * x + std::fabs(x)) * 0x1p-100; polynomial coefficientsExpm1lB3throughExpm1lB12and high/low splitting viastatic_cast<float>(x)match upstreams_expl.c(T1 = 0.1659,B3..B12).Expm1lGeneralandExpm1lScaledincore/libs/prx/libc/src/Math.cpp:4264-4288: range reductionfn = x * ExplInvL + 0x1.8p63 - 0x1.8p63, table indexingstatic_cast<unsigned>(n) % ExplIntervals(INTERVALS = 128), shiftn >> ExplLog2Intervals, and all sixkscaling intervals (k == 0,k == -1,k < -7,k > 2 * Expm1lMantissaDigits - 1includingk == 16384,k > Expm1lMantissaDigits - 1, and[-7, 63]) match upstreams_expl.c.expm1l_nid_postfixincore/libs/prx/libc/src/Math.cpp:4805replaces thestd::expm1(x)wrapper and delegates directly toExpm1lMsun(x)withAPS5_VABIcalling convention.docs/dev/debt/libc.md:96accurately documents the FreeBSD 11.4.0ld80/s_expl.csource,errnobehavior, and x87 precision handling, andtools/check_conventions.pyandguest_mathCTest pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T04:08:00Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
16b1321295:tools/check_conventions.pypassed;git diff --checkclean.guest_math_testsbuilt cleanly.guest_math):core/libs/prx/libc/src/Math.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Expm1lMsunspecial-case branches incore/libs/prx/libc/src/Math.cpp:4500-4510against FreeBSD 11.4.0lib/msun/ld80/s_expl.c:exponent >= ExplBias + 6correctly handlesNaNand+-Inf(exponent == ExplBias + 16384, returning-1 / x - 1for-Infandx + xfor+Inf/NaN), overflow (x > ExplOverflowThresholdreturningExplHuge * ExplHuge), and large negative inputs ((signExponent & 0x8000) != 0returningExplTiny + -1).Expm1lSeriesincore/libs/prx/libc/src/Math.cpp:4461-4472for|x| < 0.1659: tiny exponent branch (exponent < ExplBias - 74) preserves signed zero and raisesFE_INEXACTvia(0x1p100 * x + std::fabs(x)) * 0x1p-100, polynomial coefficientsExpm1lB3throughExpm1lB12match upstreamB3..B12exactly, and high/low splitting viastatic_cast<float>(x)and theexponent >= ExplBias - 7branch matchs_expl.c.Expm1lGeneralandExpm1lScaledincore/libs/prx/libc/src/Math.cpp:4474-4498: argument reduction (fn = x * ExplInvL + 0x1.8p63 - 0x1.8p63,r1,r2, polynomialqwithExplA2..ExplA6), table indexing (static_cast<unsigned>(n) % ExplIntervals), shiftn >> ExplLog2Intervals, and all sixkscaling intervals (k == 0,k == -1,k < -7,k > 2 * Expm1lMantissaDigits - 1includingk == 16384,k > Expm1lMantissaDigits - 1, and[-7, 63]) match upstreams_expl.c.expm1l_nid_postfixincore/libs/prx/libc/src/Math.cpp:5139replaces the oldstd::expm1(x)delegation and callsExpm1lMsun(x)withAPS5_VABI.docs/dev/debt/libc.md:98accurately documents the FreeBSD 11.4.0ld80/s_expl.cport,errnobehavior, and x87 precision handling, and confirmedtools/check_conventions.pyandguest_mathCTest pass with negative control failing when reverted.Looks Good To Me