[PATCH] x86_64: Add atanh with FMA
Sunil Pandey
skpgkp2@gmail.com
Mon Mar 17 15:48:54 GMT 2025
On Thu, Mar 13, 2025 at 1:24 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Mar 13, 2025 at 1:07 PM Sunil K Pandey <skpgkp2@gmail.com> wrote:
> >
> > On SPR, it improves atanh bench performance by:
> >
> > Before After Improvement
> > reciprocal-throughput 15.1715 14.8628 2%
> > latency 57.1941 56.1883 2%
> > ---
> > benchtests/atanh-inputs | 1 +
> > sysdeps/ieee754/dbl-64/e_atanh.c | 8 +++++
> > sysdeps/x86_64/fpu/multiarch/Makefile | 2 ++
> > sysdeps/x86_64/fpu/multiarch/e_atanh-fma.c | 6 ++++
> > sysdeps/x86_64/fpu/multiarch/e_atanh.c | 34 ++++++++++++++++++++++
> > 5 files changed, 51 insertions(+)
> > create mode 100644 sysdeps/x86_64/fpu/multiarch/e_atanh-fma.c
> > create mode 100644 sysdeps/x86_64/fpu/multiarch/e_atanh.c
> >
> > diff --git a/benchtests/atanh-inputs b/benchtests/atanh-inputs
> > index 455aa65b65..4985293254 100644
> > --- a/benchtests/atanh-inputs
> > +++ b/benchtests/atanh-inputs
> > @@ -1,6 +1,7 @@
> > ## args: double
> > ## ret: double
> > ## includes: math.h
> > +## name: workload-random
> > 0x1.5a2730bacd94ap-1
> > -0x1.b57eb40fc048ep-21
> > -0x1.c0b185fb450e2p-17
> > diff --git a/sysdeps/ieee754/dbl-64/e_atanh.c
> b/sysdeps/ieee754/dbl-64/e_atanh.c
> > index 1e09e46f0f..d1c71b2aa4 100644
> > --- a/sysdeps/ieee754/dbl-64/e_atanh.c
> > +++ b/sysdeps/ieee754/dbl-64/e_atanh.c
> > @@ -44,6 +44,11 @@
> >
> > static const double huge = 1e300;
> >
> > +#ifndef SECTION
> > +# define SECTION
> > +#endif
> > +
> > +SECTION
> > double
> > __ieee754_atanh (double x)
> > {
> > @@ -73,4 +78,7 @@ __ieee754_atanh (double x)
> >
> > return copysign (t, x);
> > }
> > +
> > +#ifndef __ieee754_atanh
> > libm_alias_finite (__ieee754_atanh, __atanh)
> > +#endif
> > diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile
> b/sysdeps/x86_64/fpu/multiarch/Makefile
> > index 61ff78efa3..3403422443 100644
> > --- a/sysdeps/x86_64/fpu/multiarch/Makefile
> > +++ b/sysdeps/x86_64/fpu/multiarch/Makefile
> > @@ -1,6 +1,7 @@
> > ifeq ($(subdir),math)
> > CFLAGS-e_asin-fma.c = -mfma -mavx2
> > CFLAGS-e_atan2-fma.c = -mfma -mavx2
> > +CFLAGS-e_atanh-fma.c = -mfma -mavx2
> > CFLAGS-e_exp-fma.c = -mfma -mavx2
> > CFLAGS-e_log-fma.c = -mfma -mavx2
> > CFLAGS-e_log2-fma.c = -mfma -mavx2
> > @@ -59,6 +60,7 @@ libm-sysdep_routines += \
> > e_asin-fma \
> > e_atan2-avx \
> > e_atan2-fma \
> > + e_atanh-fma \
> > e_exp-avx \
> > e_exp-fma \
> > e_exp2f-fma \
> > diff --git a/sysdeps/x86_64/fpu/multiarch/e_atanh-fma.c
> b/sysdeps/x86_64/fpu/multiarch/e_atanh-fma.c
> > new file mode 100644
> > index 0000000000..c3f2f9e550
> > --- /dev/null
> > +++ b/sysdeps/x86_64/fpu/multiarch/e_atanh-fma.c
> > @@ -0,0 +1,6 @@
> > +#define __ieee754_atanh __ieee754_atanh_fma
> > +#define __log1p __log1p_fma
> > +
> > +#define SECTION __attribute__ ((section (".text.fma")))
> > +
> > +#include <sysdeps/ieee754/dbl-64/e_atanh.c>
> > diff --git a/sysdeps/x86_64/fpu/multiarch/e_atanh.c
> b/sysdeps/x86_64/fpu/multiarch/e_atanh.c
> > new file mode 100644
> > index 0000000000..d2b785dfc0
> > --- /dev/null
> > +++ b/sysdeps/x86_64/fpu/multiarch/e_atanh.c
> > @@ -0,0 +1,34 @@
> > +/* Multiple versions of atanh.
> > + 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_atanh (double);
> > +
> > +# define SYMBOL_NAME ieee754_atanh
> > +# include "ifunc-fma.h"
> > +
> > +libc_ifunc_redirected (__redirect_ieee754_atanh, __ieee754_atanh,
> IFUNC_SELECTOR ());
> > +
> > +libm_alias_finite (__ieee754_atanh, __atanh)
> > +
> > +# define __ieee754_atanh __ieee754_atanh_sse2
> > +#endif
> > +#include <sysdeps/ieee754/dbl-64/e_atanh.c>
> > --
> > 2.48.1
> >
>
> LGTM.
>
> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
>
> Thanks.
>
> --
> H.J.
>
I would like to backport this patch to release branches.
Any comments or objections?
--Sunil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250317/9c820cba/attachment.htm>
More information about the Libc-alpha
mailing list