[v3,3/3] x86_64: Add rsqrt with FMA

Message ID 20261020195246.1451595-4-adhemerval.zanella@linaro.org (mailing list archive)
State New
Headers
Series math: Make rsqrt and rsqrtf correctly rounded |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

Adhemerval Zanella Netto Oct. 20, 2026, 7:52 p.m. UTC
  The rsqrt calls the __fma ifunc twice per call.  Add an FMA variant,
similar to tanh.

Checked on x86_64-linux-gnu.
---
 sysdeps/ieee754/dbl-64/s_rsqrt.c           |  7 +++++
 sysdeps/x86_64/fpu/multiarch/Makefile      |  2 ++
 sysdeps/x86_64/fpu/multiarch/s_rsqrt-fma.c |  5 ++++
 sysdeps/x86_64/fpu/multiarch/s_rsqrt.c     | 33 ++++++++++++++++++++++
 4 files changed, 47 insertions(+)
 create mode 100644 sysdeps/x86_64/fpu/multiarch/s_rsqrt-fma.c
 create mode 100644 sysdeps/x86_64/fpu/multiarch/s_rsqrt.c
  

Patch

diff --git a/sysdeps/ieee754/dbl-64/s_rsqrt.c b/sysdeps/ieee754/dbl-64/s_rsqrt.c
index 72c78a0b8f4..bf021a55532 100644
--- a/sysdeps/ieee754/dbl-64/s_rsqrt.c
+++ b/sysdeps/ieee754/dbl-64/s_rsqrt.c
@@ -94,6 +94,11 @@  as_rsqrt_refine (double rf, double a)
   return asdouble (ir);
 }
 
+#ifndef SECTION
+# define SECTION
+#endif
+
+SECTION
 double
 __rsqrt (double x)
 {
@@ -138,4 +143,6 @@  __rsqrt (double x)
     rf = as_rsqrt_refine (rf, x);
   return rf;
 }
+#ifndef __rsqrt
 libm_alias_double (__rsqrt, rsqrt)
+#endif
diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile
index 28e5123810d..6e085cb5d7a 100644
--- a/sysdeps/x86_64/fpu/multiarch/Makefile
+++ b/sysdeps/x86_64/fpu/multiarch/Makefile
@@ -11,6 +11,7 @@  CFLAGS-e_sinh-fma.c = -mfma -mavx2
 CFLAGS-s_atan-fma.c = -mfma -mavx2
 CFLAGS-s_expm1-fma.c = -mfma -mavx2
 CFLAGS-s_log1p-fma.c = -mfma -mavx2
+CFLAGS-s_rsqrt-fma.c = -mfma -mavx2
 CFLAGS-s_sin-fma.c = -mfma -mavx2
 CFLAGS-s_tan-fma.c = -mfma -mavx2
 CFLAGS-s_tanh-fma.c = -mfma -mavx2
@@ -105,6 +106,7 @@  libm-sysdep_routines += \
   s_rintf-sse4_1 \
   s_roundeven-sse4_1 \
   s_roundevenf-sse4_1 \
+  s_rsqrt-fma \
   s_sin-avx \
   s_sin-fma \
   s_sincos-avx \
diff --git a/sysdeps/x86_64/fpu/multiarch/s_rsqrt-fma.c b/sysdeps/x86_64/fpu/multiarch/s_rsqrt-fma.c
new file mode 100644
index 00000000000..e0d11f47e47
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/s_rsqrt-fma.c
@@ -0,0 +1,5 @@ 
+#define __rsqrt __rsqrt_fma
+
+#define SECTION __attribute__ ((section (".text.fma")))
+
+#include <sysdeps/ieee754/dbl-64/s_rsqrt.c>
diff --git a/sysdeps/x86_64/fpu/multiarch/s_rsqrt.c b/sysdeps/x86_64/fpu/multiarch/s_rsqrt.c
new file mode 100644
index 00000000000..9100b6eb49b
--- /dev/null
+++ b/sysdeps/x86_64/fpu/multiarch/s_rsqrt.c
@@ -0,0 +1,33 @@ 
+/* Multiple versions of rsqrt.
+   Copyright (C) 2026 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 <sysdeps/x86/isa-level.h>
+#if MINIMUM_X86_ISA_LEVEL < AVX2_X86_ISA_LEVEL
+#include <libm-alias-double.h>
+
+extern double __redirect_rsqrt (double);
+
+# define SYMBOL_NAME rsqrt
+# include "ifunc-fma.h"
+
+libc_ifunc_redirected (__redirect_rsqrt, __rsqrt, IFUNC_SELECTOR ());
+libm_alias_double (__rsqrt, rsqrt)
+
+# define __rsqrt __rsqrt_sse2
+#endif
+#include <sysdeps/ieee754/dbl-64/s_rsqrt.c>