[PATCH 15/15] x86_64: Add asinpif with FMA

DJ Delorie dj@redhat.com
Tue Feb 11 01:31:18 GMT 2025


LGTM

Reviewed-by: DJ Delorie <dj@redhat.com>

Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> The CORE-MATH asinpif implementation showed slight worse performance
> when using x86_64 baseline ABI due its usage of fma on fast path.
> This patch adds a ifunc variant with similar performance for x86_64-v3.

Do you have the performance numbers to report?

> ---
>  sysdeps/ieee754/flt-32/s_asinpif.c           |  2 ++
>  sysdeps/x86_64/fpu/multiarch/Makefile        |  2 ++
>  sysdeps/x86_64/fpu/multiarch/s_asinpif-fma.c |  4 +++
>  sysdeps/x86_64/fpu/multiarch/s_asinpif.c     | 33 ++++++++++++++++++++

So this is an ifunc of asinpf() itself, not fma...

> diff --git a/sysdeps/ieee754/flt-32/s_asinpif.c b/sysdeps/ieee754/flt-32/s_asinpif.c
>        return r;
>      }
>  }
> +#ifndef __asinpif
>  libm_alias_float (__asinpi, asinpi)
> +#endif

Ok.

> diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile
>  CFLAGS-s_sincos-fma.c = -mfma -mavx2
>  CFLAGS-s_exp10m1f-fma.c = -mfma -mavx2
>  CFLAGS-s_exp2m1f-fma.c = -mfma -mavx2
> +CFLAGS-s_asinpif-fma.c = -mfma -mavx2
>  
>  CFLAGS-e_exp2f-fma.c = -mfma -mavx2
>  CFLAGS-e_expf-fma.c = -mfma -mavx2
> @@ -68,6 +69,7 @@ libm-sysdep_routines += \
>    e_logf-fma \
>    e_pow-fma \
>    e_powf-fma \
> +  s_asinpif-fma \
>    s_atan-avx \
>    s_atan-fma \
>    s_ceil-sse4_1 \

Ok.

> diff --git a/sysdeps/x86_64/fpu/multiarch/s_asinpif-fma.c b/sysdeps/x86_64/fpu/multiarch/s_asinpif-fma.c
> +#define __asinpif __asinpif_fma
> +#define SECTION __attribute__ ((section (".text.fma")))
> +
> +#include <sysdeps/ieee754/flt-32/s_asinpif.c>

So same code, but without the alias and built with different options, to
make a variant.  Ok.

> diff --git a/sysdeps/x86_64/fpu/multiarch/s_asinpif.c b/sysdeps/x86_64/fpu/multiarch/s_asinpif.c
> +/* Multiple versions of asinpif.
> +   Copyright (C) 2024-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/>.  */

Ok.

> +#include <sysdeps/x86/isa-level.h>
> +#if MINIMUM_X86_ISA_LEVEL < AVX2_X86_ISA_LEVEL
> +# include <libm-alias-float.h>
> +
> +extern float __redirect_asinpif (float);
> +
> +# define SYMBOL_NAME asinpif
> +# include "ifunc-fma.h"
> +
> +libc_ifunc_redirected (__redirect_asinpif, __asinpif, IFUNC_SELECTOR ());
> +libm_alias_float (__asinpi, asinpi)
> +
> +# define __asinpif __asinpif_sse2
> +#endif
> +#include <sysdeps/ieee754/flt-32/s_asinpif.c>

So if the build picks this *.c file, it adds the ifunc code but also
includes the default asinpf() as __asinpif_sse2().  Ok.



More information about the Libc-alpha mailing list