fix(libc): build libc without floating-point contraction #11059
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11059"
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 MarcZX10 on 2026-10-25T16:13:46Z.
What
guest_mathfails onubuntu-latestrunners, which now ship Ubuntu GCC 15.2.0 (15.2.0-16ubuntu1). That compiler targets x86-64-v3 by default (g++ -Q --help=targetreports-march=x86-64-v3and-mfma [enabled];__FP_FAST_FMAis defined). In the defaultgnu++20mode GCC also defaults to-ffp-contract=fast, so it fuses thea * b + csteps of libc's msun-style float code into FMA instructions. That rounds once instead of twice and changes the last bit of results that are meant to match the console. Withatanfon that runner:0x3e0007c90x3dfebd2a0x3dfebd290xbdccce4c0xbdcc20900xbdcc208fThe same
atanfsource built there with-ffp-contract=offor-march=x86-64has no FMA instructions (12 with the default flags) and returns the console bits. Debian's GCC 15 and GCC 12, which target baseline x86-64, pass. Anyone who builds with a toolchain that defaults to x86-64-v3, or who adds-march=nativeon a CPU with FMA, gets the same drift in every libc math function written this way.This compiles libc with
-ffp-contract=offon GCC and Clang, which is what ISO-std=c++20already does. MSVC does not contract unless/fp:contractis given, so it is left alone. The flag only stops fusion that the source does not ask for; explicitstd::fmacalls are unaffected.libc_floating_point_contractionis a new CMake script test for x86-64 GCC and Clang builds. It compilesfloat MultiplyAdd(float a, float b, float c) { return a * b + c; }with-O2 -mfmaplus libc's own-fcompile options and fails if the assembly contains avfmadd/vfmsub-style instruction. Only compilation is involved, so it guards the fix on hosts without FMA too, whereguest_mathcannot see the problem. BUILD.md notes why libc is built this way.Tested
ubuntu-latestrunner (AMD EPYC 7763, Ubuntu GCC 15.2.0), before this change:guest_mathaborts inCheckAtanfConsoleBits(GuestMath.cpp:373with theRequireline printed). With this branch:libc_floating_point_contractionandguest_mathpass.-ffp-contract=off(it reportsvfmadd132ss) and passes with it, with GCC 12, Debian GCC 15 and Clang 19.-ffp-contract=offcompiles with MinGW-Builds GCC 15.2.0 onwindows-latest, Apple clang 17.0.0 onmacos-15-inteland Apple clang 21.0.0 onmacos-latest, and the contraction script test passes with the first two (x86-64). The full project was not built there, since this pull request'slinuxandwindowsjobs are skipped by path.python3 tools/check_conventions.py --base upstream/mainandgit diff --check upstream/mainpass.tools/pr_overlap.py --branchlists only pull requests that also editcore/libs/prx/libc/CMakeLists.txtordocs/dev/BUILD.md, with no conflicting lines.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 THEMANnt on 2026-10-26T19:16:46Z.
Review: APPROVED
Reviewed
6c1ac043c2888afb838449ee5ef477762d33f7af. Approve; no actionable finding in this focused review.The libc compile option disables contraction for GNU/Clang regardless of target CPU, and the focused test receives the actual target compile options. The x86-only assembly check is kept off unsupported toolchains.
Validation: Ran the submitted LibcFloatingPointContraction.cmake with WinLibs GCC 15.2: -ffp-contract=off passes. The controlled fast-contraction arm fails after detecting vfmadd132ss, showing that the check is sensitive.
Scope / next step: No full libc math, Clang or console bit-accuracy run is claimed.