From bfee89dc8a1b3d6941c80c08b62cef066f45b9ba Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Wed, 8 Oct 2025 10:55:01 -0300 Subject: [PATCH] i386: Remove the SVID error handling from fmod The optimized i386 version is faster than the generic one, and gcc implements it through the builtin. It allows us to move the implementation to a C one. The performance on a Zen3 chip is similar to the SVID one. Tested on i686-linux-gnu. Reviewed-by: Wilco Dijkstra --- sysdeps/i386/fpu/Versions | 4 +++ sysdeps/i386/fpu/e_fmod.S | 18 ---------- sysdeps/i386/fpu/e_fmod.c | 41 +++++++++++++++++++++++ sysdeps/i386/fpu/w_fmod_compat.c | 15 --------- sysdeps/mach/hurd/i386/libm.abilist | 1 + sysdeps/unix/sysv/linux/i386/libm.abilist | 1 + 6 files changed, 47 insertions(+), 33 deletions(-) delete mode 100644 sysdeps/i386/fpu/e_fmod.S create mode 100644 sysdeps/i386/fpu/e_fmod.c delete mode 100644 sysdeps/i386/fpu/w_fmod_compat.c diff --git a/sysdeps/i386/fpu/Versions b/sysdeps/i386/fpu/Versions index a2eec371f16..940384a21f4 100644 --- a/sysdeps/i386/fpu/Versions +++ b/sysdeps/i386/fpu/Versions @@ -3,4 +3,8 @@ libm { # functions used in inline functions or macros __expl; __expm1l; } + GLIBC_2.43 { + # No SVID compatible error handling. + fmod; + } } diff --git a/sysdeps/i386/fpu/e_fmod.S b/sysdeps/i386/fpu/e_fmod.S deleted file mode 100644 index 86ac1bcfafa..00000000000 --- a/sysdeps/i386/fpu/e_fmod.S +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Public domain. - */ - -#include -#include - -ENTRY(__ieee754_fmod) - fldl 12(%esp) - fldl 4(%esp) -1: fprem - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret -END (__ieee754_fmod) -libm_alias_finite (__ieee754_fmod, __fmod) diff --git a/sysdeps/i386/fpu/e_fmod.c b/sysdeps/i386/fpu/e_fmod.c new file mode 100644 index 00000000000..281b23dffc0 --- /dev/null +++ b/sysdeps/i386/fpu/e_fmod.c @@ -0,0 +1,41 @@ +/* Floating-point remainder function. + Copyright (C) 2023-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include "math_config.h" + +double +__fmod (double x, double y) +{ + uint64_t hx = asuint64 (x); + uint64_t hy = asuint64 (y); + + /* fmod(+-Inf,y) or fmod(x,0) */ + if (__glibc_unlikely ((is_inf (hx) || y == 0.0) + && !is_nan (hy) + && !is_nan (hx))) + return __math_invalid (x); + + return __builtin_fmod (x, y); +} +strong_alias (__fmod, __ieee754_fmod) +libm_alias_finite (__ieee754_fmod, __fmod) +versioned_symbol (libm, __fmod, fmod, GLIBC_2_43); +libm_alias_double_other (__fmod, fmod) diff --git a/sysdeps/i386/fpu/w_fmod_compat.c b/sysdeps/i386/fpu/w_fmod_compat.c deleted file mode 100644 index 528bfc2a135..00000000000 --- a/sysdeps/i386/fpu/w_fmod_compat.c +++ /dev/null @@ -1,15 +0,0 @@ -/* i386 provides an optimized __ieee752_fmod. */ -#include -#ifdef SHARED -# undef SHLIB_COMPAT -# define SHLIB_COMPAT(a, b, c) 1 -# undef LIBM_SVID_COMPAT -# define LIBM_SVID_COMPAT 1 -# undef compat_symbol -# define compat_symbol(a, b, c, d) -# include -libm_alias_double (__fmod_compat, fmod) -#else -#include -#include -#endif diff --git a/sysdeps/mach/hurd/i386/libm.abilist b/sysdeps/mach/hurd/i386/libm.abilist index 47d215fae2f..6c8e2b6d9cb 100644 --- a/sysdeps/mach/hurd/i386/libm.abilist +++ b/sysdeps/mach/hurd/i386/libm.abilist @@ -1317,3 +1317,4 @@ GLIBC_2.42 rsqrtf32x F GLIBC_2.42 rsqrtf64 F GLIBC_2.42 rsqrtf64x F GLIBC_2.42 rsqrtl F +GLIBC_2.43 fmod F diff --git a/sysdeps/unix/sysv/linux/i386/libm.abilist b/sysdeps/unix/sysv/linux/i386/libm.abilist index de77b0f0713..5f545098126 100644 --- a/sysdeps/unix/sysv/linux/i386/libm.abilist +++ b/sysdeps/unix/sysv/linux/i386/libm.abilist @@ -1324,3 +1324,4 @@ GLIBC_2.42 rsqrtf32x F GLIBC_2.42 rsqrtf64 F GLIBC_2.42 rsqrtf64x F GLIBC_2.42 rsqrtl F +GLIBC_2.43 fmod F -- 2.47.3