[v3,3/3] x86_64: Add rsqrt with FMA
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
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
@@ -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
@@ -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 \
new file mode 100644
@@ -0,0 +1,5 @@
+#define __rsqrt __rsqrt_fma
+
+#define SECTION __attribute__ ((section (".text.fma")))
+
+#include <sysdeps/ieee754/dbl-64/s_rsqrt.c>
new file mode 100644
@@ -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>