[v2] x86_64: Add sinh with FMA
Checks
Context |
Check |
Description |
redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
redhat-pt-bot/TryBot-32bit |
success
|
Build for i686
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
Commit Message
On SPR, it improves sinh bench performance by:
Before After Improvement
max 56.49 43.367 23%
min 10.87 8.344 23%
mean 12.7086 10.6824 16%
---
sysdeps/ieee754/dbl-64/e_sinh.c | 8 ++++++
sysdeps/x86_64/fpu/multiarch/Makefile | 2 ++
sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c | 12 ++++++++
sysdeps/x86_64/fpu/multiarch/e_sinh.c | 35 +++++++++++++++++++++++
4 files changed, 57 insertions(+)
create mode 100644 sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c
create mode 100644 sysdeps/x86_64/fpu/multiarch/e_sinh.c
Comments
On 13/03/25 02:16, Sunil K Pandey wrote:
> On SPR, it improves sinh bench performance by:
>
> Before After Improvement
> max 56.49 43.367 23%
> min 10.87 8.344 23%
> mean 12.7086 10.6824 16%
Maybe change the benchmark to also run throughput with '## name: workload-random'
entry, to get a better understanding of performance profile besides just latency.
> ---
> sysdeps/ieee754/dbl-64/e_sinh.c | 8 ++++++
> sysdeps/x86_64/fpu/multiarch/Makefile | 2 ++
> sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c | 12 ++++++++
> sysdeps/x86_64/fpu/multiarch/e_sinh.c | 35 +++++++++++++++++++++++
> 4 files changed, 57 insertions(+)
> create mode 100644 sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c
> create mode 100644 sysdeps/x86_64/fpu/multiarch/e_sinh.c
>
> diff --git a/sysdeps/ieee754/dbl-64/e_sinh.c b/sysdeps/ieee754/dbl-64/e_sinh.c
> index b4b5857ddd..3f787967f9 100644
> --- a/sysdeps/ieee754/dbl-64/e_sinh.c
> +++ b/sysdeps/ieee754/dbl-64/e_sinh.c
> @@ -41,6 +41,11 @@ static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $";
>
> static const double one = 1.0, shuge = 1.0e307;
>
> +#ifndef SECTION
> +# define SECTION
> +#endif
> +
> +SECTION
> double
> __ieee754_sinh (double x)
> {
> @@ -90,4 +95,7 @@ __ieee754_sinh (double x)
> /* |x| > overflowthresold, sinh(x) overflow */
> return math_narrow_eval (x * shuge);
> }
> +
> +#ifndef __ieee754_sinh
> libm_alias_finite (__ieee754_sinh, __sinh)
> +#endif
> diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile
> index e823d2fcc6..d2d96dd089 100644
> --- a/sysdeps/x86_64/fpu/multiarch/Makefile
> +++ b/sysdeps/x86_64/fpu/multiarch/Makefile
> @@ -5,6 +5,7 @@ CFLAGS-e_exp-fma.c = -mfma -mavx2
> CFLAGS-e_log-fma.c = -mfma -mavx2
> CFLAGS-e_log2-fma.c = -mfma -mavx2
> CFLAGS-e_pow-fma.c = -mfma -mavx2
> +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
> @@ -68,6 +69,7 @@ libm-sysdep_routines += \
> e_logf-fma \
> e_pow-fma \
> e_powf-fma \
> + e_sinh-fma \
> s_atan-avx \
> s_atan-fma \
> s_ceil-sse4_1 \
> diff --git a/sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c b/sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c
> new file mode 100644
> index 0000000000..e0e1e39a7a
> --- /dev/null
> +++ b/sysdeps/x86_64/fpu/multiarch/e_sinh-fma.c
> @@ -0,0 +1,12 @@
> +#define __ieee754_sinh __ieee754_sinh_fma
> +#define __ieee754_exp __ieee754_exp_fma
> +#define __expm1 __expm1_fma
> +
> +/* NB: __expm1 may be expanded to __expm1_fma in the following
> + prototypes. */
> +extern long double __expm1l (long double);
> +extern long double __expm1f128 (long double);
> +
> +#define SECTION __attribute__ ((section (".text.fma")))
> +
> +#include <sysdeps/ieee754/dbl-64/e_sinh.c>
> diff --git a/sysdeps/x86_64/fpu/multiarch/e_sinh.c b/sysdeps/x86_64/fpu/multiarch/e_sinh.c
> new file mode 100644
> index 0000000000..3d3c18ccdf
> --- /dev/null
> +++ b/sysdeps/x86_64/fpu/multiarch/e_sinh.c
> @@ -0,0 +1,35 @@
> +/* Multiple versions of sinh.
> + Copyright (C) 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 <sysdeps/x86/isa-level.h>
> +#if MINIMUM_X86_ISA_LEVEL < AVX2_X86_ISA_LEVEL
> +# include <libm-alias-finite.h>
> +
> +extern double __redirect_ieee754_sinh (double);
> +
> +# define SYMBOL_NAME ieee754_sinh
> +# include "ifunc-fma.h"
> +
> +libc_ifunc_redirected (__redirect_ieee754_sinh, __ieee754_sinh,
> + IFUNC_SELECTOR ());
> +
> +libm_alias_finite (__ieee754_sinh, __sinh)
> +
> +# define __ieee754_sinh __ieee754_sinh_sse2
> +#endif
> +#include <sysdeps/ieee754/dbl-64/e_sinh.c>
@@ -41,6 +41,11 @@ static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $";
static const double one = 1.0, shuge = 1.0e307;
+#ifndef SECTION
+# define SECTION
+#endif
+
+SECTION
double
__ieee754_sinh (double x)
{
@@ -90,4 +95,7 @@ __ieee754_sinh (double x)
/* |x| > overflowthresold, sinh(x) overflow */
return math_narrow_eval (x * shuge);
}
+
+#ifndef __ieee754_sinh
libm_alias_finite (__ieee754_sinh, __sinh)
+#endif
@@ -5,6 +5,7 @@ CFLAGS-e_exp-fma.c = -mfma -mavx2
CFLAGS-e_log-fma.c = -mfma -mavx2
CFLAGS-e_log2-fma.c = -mfma -mavx2
CFLAGS-e_pow-fma.c = -mfma -mavx2
+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
@@ -68,6 +69,7 @@ libm-sysdep_routines += \
e_logf-fma \
e_pow-fma \
e_powf-fma \
+ e_sinh-fma \
s_atan-avx \
s_atan-fma \
s_ceil-sse4_1 \
new file mode 100644
@@ -0,0 +1,12 @@
+#define __ieee754_sinh __ieee754_sinh_fma
+#define __ieee754_exp __ieee754_exp_fma
+#define __expm1 __expm1_fma
+
+/* NB: __expm1 may be expanded to __expm1_fma in the following
+ prototypes. */
+extern long double __expm1l (long double);
+extern long double __expm1f128 (long double);
+
+#define SECTION __attribute__ ((section (".text.fma")))
+
+#include <sysdeps/ieee754/dbl-64/e_sinh.c>
new file mode 100644
@@ -0,0 +1,35 @@
+/* Multiple versions of sinh.
+ Copyright (C) 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 <sysdeps/x86/isa-level.h>
+#if MINIMUM_X86_ISA_LEVEL < AVX2_X86_ISA_LEVEL
+# include <libm-alias-finite.h>
+
+extern double __redirect_ieee754_sinh (double);
+
+# define SYMBOL_NAME ieee754_sinh
+# include "ifunc-fma.h"
+
+libc_ifunc_redirected (__redirect_ieee754_sinh, __ieee754_sinh,
+ IFUNC_SELECTOR ());
+
+libm_alias_finite (__ieee754_sinh, __sinh)
+
+# define __ieee754_sinh __ieee754_sinh_sse2
+#endif
+#include <sysdeps/ieee754/dbl-64/e_sinh.c>