]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
i386: Remove the SVID error handling from fmodf
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 8 Oct 2025 13:55:02 +0000 (10:55 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 30 Oct 2025 18:41:07 +0000 (15:41 -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 slight better:

reciprocal-throughput           input   master  no-SVID  improvement
i686                       subnormals  22.4741  20.1571       10.31%
i686                           normal  74.1631  70.3606        5.13%
i686                   close-exponent  22.5625  20.2435       10.28%

Tested on i686-linux-gnu.

Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
sysdeps/i386/fpu/Versions
sysdeps/i386/fpu/e_fmodf.S [deleted file]
sysdeps/i386/fpu/e_fmodf.c [new file with mode: 0644]
sysdeps/i386/fpu/e_fmodf_ver.h [new file with mode: 0644]
sysdeps/i386/fpu/w_fmodf_compat.c [deleted file]
sysdeps/mach/hurd/i386/libm.abilist
sysdeps/unix/sysv/linux/i386/libm.abilist

index 940384a21f441bdb0119307823e706dbc6565303..8668b42dd6a6f89e10a3e1663c96536263dfbdb4 100644 (file)
@@ -5,6 +5,6 @@ libm {
   }
   GLIBC_2.43 {
     # No SVID compatible error handling.
-    fmod;
+    fmod; fmodf;
   }
 }
diff --git a/sysdeps/i386/fpu/e_fmodf.S b/sysdeps/i386/fpu/e_fmodf.S
deleted file mode 100644 (file)
index f73ce9d..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Public domain.
- */
-
-#include <machine/asm.h>
-#include <libm-alias-finite.h>
-
-ENTRY(__ieee754_fmodf)
-       flds    8(%esp)
-       flds    4(%esp)
-1:     fprem
-       fstsw   %ax
-       sahf
-       jp      1b
-       fstp    %st(1)
-       ret
-END(__ieee754_fmodf)
-libm_alias_finite (__ieee754_fmodf, __fmodf)
diff --git a/sysdeps/i386/fpu/e_fmodf.c b/sysdeps/i386/fpu/e_fmodf.c
new file mode 100644 (file)
index 0000000..5b05d0f
--- /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-finite.h>
+#include <libm-alias-float.h>
+#include <math.h>
+#include "sysdeps/ieee754/flt-32/math_config.h"
+
+float
+__fmodf (float x, float y)
+{
+  uint32_t hx = asuint (x);
+  uint32_t hy = asuint (y);
+
+  /* fmod(+-Inf,y) or fmod(x,0) */
+  if (__glibc_unlikely ((is_inf (hx) || y == 0.0f)
+                       && !is_nan (hy)
+                       && !is_nan (hx)))
+    return __math_invalidf (x);
+
+  return __builtin_fmodf (x, y);
+}
+strong_alias (__fmodf, __ieee754_fmodf)
+versioned_symbol (libm, __fmodf, fmodf, GLIBC_2_43);
+libm_alias_float_other (__fmod, fmod)
+libm_alias_finite (__ieee754_fmodf, __fmodf)
diff --git a/sysdeps/i386/fpu/e_fmodf_ver.h b/sysdeps/i386/fpu/e_fmodf_ver.h
new file mode 100644 (file)
index 0000000..384d791
--- /dev/null
@@ -0,0 +1,2 @@
+/* i386 remove SVID wrapper on 2.43 */
+#define FMODF_NOSVID_VER   GLIBC_2_43
diff --git a/sysdeps/i386/fpu/w_fmodf_compat.c b/sysdeps/i386/fpu/w_fmodf_compat.c
deleted file mode 100644 (file)
index 5a61693..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/* i386 provides an optimized __ieee752_fmodf.  */
-#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_fmodf_compat.c>
-libm_alias_float (__fmod_compat, fmod)
-#else
-#include <math-type-macros-float.h>
-#include <w_fmod_template.c>
-#endif
index 6c8e2b6d9cb1dfafddd2e2b2d49ff35f1be4226a..3bf087812ca52d4fa1af5b2d4352cedc249a0176 100644 (file)
@@ -1318,3 +1318,4 @@ GLIBC_2.42 rsqrtf64 F
 GLIBC_2.42 rsqrtf64x F
 GLIBC_2.42 rsqrtl F
 GLIBC_2.43 fmod F
+GLIBC_2.43 fmodf F
index 5f54509812652b73b974b00334e17eb7fd25de45..38e31ed1a7666c0853735a05d9f886d7d889fa80 100644 (file)
@@ -1325,3 +1325,4 @@ GLIBC_2.42 rsqrtf64 F
 GLIBC_2.42 rsqrtf64x F
 GLIBC_2.42 rsqrtl F
 GLIBC_2.43 fmod F
+GLIBC_2.43 fmodf F