]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
i386: Remove the SVID error handling from fmod
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 8 Oct 2025 13:55:01 +0000 (10:55 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 30 Oct 2025 18:40:41 +0000 (15:40 -0300)
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 <Wilco.Dijkstra@arm.com>
sysdeps/i386/fpu/Versions
sysdeps/i386/fpu/e_fmod.S [deleted file]
sysdeps/i386/fpu/e_fmod.c [new file with mode: 0644]
sysdeps/i386/fpu/w_fmod_compat.c [deleted file]
sysdeps/mach/hurd/i386/libm.abilist
sysdeps/unix/sysv/linux/i386/libm.abilist

index a2eec371f16958655a5fab0cd3bf2eae770d9e06..940384a21f441bdb0119307823e706dbc6565303 100644 (file)
@@ -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 (file)
index 86ac1bc..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Public domain.
- */
-
-#include <machine/asm.h>
-#include <libm-alias-finite.h>
-
-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 (file)
index 0000000..281b23d
--- /dev/null
@@ -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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <libm-alias-double.h>
+#include <libm-alias-finite.h>
+#include <math.h>
+#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 (file)
index 528bfc2..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/* i386 provides an optimized __ieee752_fmod.  */
-#include <math-svid-compat.h>
-#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 <math/w_fmod_compat.c>
-libm_alias_double (__fmod_compat, fmod)
-#else
-#include <math-type-macros-double.h>
-#include <w_fmod_template.c>
-#endif
index 47d215fae2f62f796cd674e946200391bfe8fbcf..6c8e2b6d9cb1dfafddd2e2b2d49ff35f1be4226a 100644 (file)
@@ -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
index de77b0f0713a1b71b399633563a5b7845d765208..5f54509812652b73b974b00334e17eb7fd25de45 100644 (file)
@@ -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