[3/6] aarch64: Add vector implementations of atan routines

Message ID 20231103121224.16835-3-Joe.Ramsay@arm.com
State Committed
Commit d30c39f80d19d62e8fd750c424ccb7eb06b617e5
Headers
Series [1/6] aarch64: Add vector implementations of asin routines |

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_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed

Commit Message

Joe Ramsay Nov. 3, 2023, 12:12 p.m. UTC
  ---
Thanks,
Joe
 sysdeps/aarch64/fpu/Makefile                  |   1 +
 sysdeps/aarch64/fpu/Versions                  |   4 +
 sysdeps/aarch64/fpu/atan_advsimd.c            | 104 +++++++++++++++++
 sysdeps/aarch64/fpu/atan_sve.c                |  90 +++++++++++++++
 sysdeps/aarch64/fpu/atanf_advsimd.c           | 109 ++++++++++++++++++
 sysdeps/aarch64/fpu/atanf_sve.c               |  79 +++++++++++++
 sysdeps/aarch64/fpu/bits/math-vector.h        |   4 +
 .../fpu/test-double-advsimd-wrappers.c        |   1 +
 .../aarch64/fpu/test-double-sve-wrappers.c    |   1 +
 .../aarch64/fpu/test-float-advsimd-wrappers.c |   1 +
 sysdeps/aarch64/fpu/test-float-sve-wrappers.c |   1 +
 sysdeps/aarch64/libm-test-ulps                |   8 ++
 .../unix/sysv/linux/aarch64/libmvec.abilist   |   4 +
 13 files changed, 407 insertions(+)
 create mode 100644 sysdeps/aarch64/fpu/atan_advsimd.c
 create mode 100644 sysdeps/aarch64/fpu/atan_sve.c
 create mode 100644 sysdeps/aarch64/fpu/atanf_advsimd.c
 create mode 100644 sysdeps/aarch64/fpu/atanf_sve.c
  

Comments

Szabolcs Nagy Nov. 10, 2023, 5:54 p.m. UTC | #1
The 11/03/2023 12:12, Joe Ramsay wrote:
> ---

this is OK to commit.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>

> Thanks,
> Joe
>  sysdeps/aarch64/fpu/Makefile                  |   1 +
>  sysdeps/aarch64/fpu/Versions                  |   4 +
>  sysdeps/aarch64/fpu/atan_advsimd.c            | 104 +++++++++++++++++
>  sysdeps/aarch64/fpu/atan_sve.c                |  90 +++++++++++++++
>  sysdeps/aarch64/fpu/atanf_advsimd.c           | 109 ++++++++++++++++++
>  sysdeps/aarch64/fpu/atanf_sve.c               |  79 +++++++++++++
>  sysdeps/aarch64/fpu/bits/math-vector.h        |   4 +
>  .../fpu/test-double-advsimd-wrappers.c        |   1 +
>  .../aarch64/fpu/test-double-sve-wrappers.c    |   1 +
>  .../aarch64/fpu/test-float-advsimd-wrappers.c |   1 +
>  sysdeps/aarch64/fpu/test-float-sve-wrappers.c |   1 +
>  sysdeps/aarch64/libm-test-ulps                |   8 ++
>  .../unix/sysv/linux/aarch64/libmvec.abilist   |   4 +
>  13 files changed, 407 insertions(+)
>  create mode 100644 sysdeps/aarch64/fpu/atan_advsimd.c
>  create mode 100644 sysdeps/aarch64/fpu/atan_sve.c
>  create mode 100644 sysdeps/aarch64/fpu/atanf_advsimd.c
>  create mode 100644 sysdeps/aarch64/fpu/atanf_sve.c
> 
> diff --git a/sysdeps/aarch64/fpu/Makefile b/sysdeps/aarch64/fpu/Makefile
> index 606fdd804f..5bd77a749d 100644
> --- a/sysdeps/aarch64/fpu/Makefile
> +++ b/sysdeps/aarch64/fpu/Makefile
> @@ -1,5 +1,6 @@
>  libmvec-supported-funcs = acos \
>                            asin \
> +                          atan \
>                            cos \
>                            exp \
>                            exp10 \
> diff --git a/sysdeps/aarch64/fpu/Versions b/sysdeps/aarch64/fpu/Versions
> index 1037cd92bd..dfc3d2dad3 100644
> --- a/sysdeps/aarch64/fpu/Versions
> +++ b/sysdeps/aarch64/fpu/Versions
> @@ -26,6 +26,10 @@ libmvec {
>      _ZGVnN2v_asin;
>      _ZGVsMxv_asinf;
>      _ZGVsMxv_asin;
> +    _ZGVnN4v_atanf;
> +    _ZGVnN2v_atan;
> +    _ZGVsMxv_atanf;
> +    _ZGVsMxv_atan;
>      _ZGVnN4v_exp10f;
>      _ZGVnN2v_exp10;
>      _ZGVsMxv_exp10f;
> diff --git a/sysdeps/aarch64/fpu/atan_advsimd.c b/sysdeps/aarch64/fpu/atan_advsimd.c
> new file mode 100644
> index 0000000000..d52c07d8a0
> --- /dev/null
> +++ b/sysdeps/aarch64/fpu/atan_advsimd.c
> @@ -0,0 +1,104 @@
> +/* Double-precision AdvSIMD inverse tan
> +
> +   Copyright (C) 2023 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 "v_math.h"
> +#include "poly_advsimd_f64.h"
> +
> +static const struct data
> +{
> +  float64x2_t pi_over_2;
> +  float64x2_t poly[20];
> +} data = {
> +  /* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on
> +	      [2**-1022, 1.0].  */
> +  .poly = { V2 (-0x1.5555555555555p-2),	 V2 (0x1.99999999996c1p-3),
> +	    V2 (-0x1.2492492478f88p-3),	 V2 (0x1.c71c71bc3951cp-4),
> +	    V2 (-0x1.745d160a7e368p-4),	 V2 (0x1.3b139b6a88ba1p-4),
> +	    V2 (-0x1.11100ee084227p-4),	 V2 (0x1.e1d0f9696f63bp-5),
> +	    V2 (-0x1.aebfe7b418581p-5),	 V2 (0x1.842dbe9b0d916p-5),
> +	    V2 (-0x1.5d30140ae5e99p-5),	 V2 (0x1.338e31eb2fbbcp-5),
> +	    V2 (-0x1.00e6eece7de8p-5),	 V2 (0x1.860897b29e5efp-6),
> +	    V2 (-0x1.0051381722a59p-6),	 V2 (0x1.14e9dc19a4a4ep-7),
> +	    V2 (-0x1.d0062b42fe3bfp-9),	 V2 (0x1.17739e210171ap-10),
> +	    V2 (-0x1.ab24da7be7402p-13), V2 (0x1.358851160a528p-16), },
> +  .pi_over_2 = V2 (0x1.921fb54442d18p+0),
> +};
> +
> +#define SignMask v_u64 (0x8000000000000000)
> +#define TinyBound 0x3e10000000000000 /* asuint64(0x1p-30).  */
> +#define BigBound 0x4340000000000000  /* asuint64(0x1p53).  */
> +
> +/* Fast implementation of vector atan.
> +   Based on atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1] using
> +   z=1/x and shift = pi/2. Maximum observed error is 2.27 ulps:
> +   _ZGVnN2v_atan (0x1.0005af27c23e9p+0) got 0x1.9225645bdd7c1p-1
> +				       want 0x1.9225645bdd7c3p-1.  */
> +float64x2_t VPCS_ATTR V_NAME_D1 (atan) (float64x2_t x)
> +{
> +  const struct data *d = ptr_barrier (&data);
> +
> +  /* Small cases, infs and nans are supported by our approximation technique,
> +     but do not set fenv flags correctly. Only trigger special case if we need
> +     fenv.  */
> +  uint64x2_t ix = vreinterpretq_u64_f64 (x);
> +  uint64x2_t sign = vandq_u64 (ix, SignMask);
> +
> +#if WANT_SIMD_EXCEPT
> +  uint64x2_t ia12 = vandq_u64 (ix, v_u64 (0x7ff0000000000000));
> +  uint64x2_t special = vcgtq_u64 (vsubq_u64 (ia12, v_u64 (TinyBound)),
> +				  v_u64 (BigBound - TinyBound));
> +  /* If any lane is special, fall back to the scalar routine for all lanes.  */
> +  if (__glibc_unlikely (v_any_u64 (special)))
> +    return v_call_f64 (atan, x, v_f64 (0), v_u64 (-1));
> +#endif
> +
> +  /* Argument reduction:
> +     y := arctan(x) for x < 1
> +     y := pi/2 + arctan(-1/x) for x > 1
> +     Hence, use z=-1/a if x>=1, otherwise z=a.  */
> +  uint64x2_t red = vcagtq_f64 (x, v_f64 (1.0));
> +  /* Avoid dependency in abs(x) in division (and comparison).  */
> +  float64x2_t z = vbslq_f64 (red, vdivq_f64 (v_f64 (1.0), x), x);
> +  float64x2_t shift = vreinterpretq_f64_u64 (
> +      vandq_u64 (red, vreinterpretq_u64_f64 (d->pi_over_2)));
> +  /* Use absolute value only when needed (odd powers of z).  */
> +  float64x2_t az = vbslq_f64 (
> +      SignMask, vreinterpretq_f64_u64 (vandq_u64 (SignMask, red)), z);
> +
> +  /* Calculate the polynomial approximation.
> +     Use split Estrin scheme for P(z^2) with deg(P)=19. Use split instead of
> +     full scheme to avoid underflow in x^16.
> +     The order 19 polynomial P approximates
> +     (atan(sqrt(x))-sqrt(x))/x^(3/2).  */
> +  float64x2_t z2 = vmulq_f64 (z, z);
> +  float64x2_t x2 = vmulq_f64 (z2, z2);
> +  float64x2_t x4 = vmulq_f64 (x2, x2);
> +  float64x2_t x8 = vmulq_f64 (x4, x4);
> +  float64x2_t y
> +      = vfmaq_f64 (v_estrin_7_f64 (z2, x2, x4, d->poly),
> +		   v_estrin_11_f64 (z2, x2, x4, x8, d->poly + 8), x8);
> +
> +  /* Finalize. y = shift + z + z^3 * P(z^2).  */
> +  y = vfmaq_f64 (az, y, vmulq_f64 (z2, az));
> +  y = vaddq_f64 (y, shift);
> +
> +  /* y = atan(x) if x>0, -atan(-x) otherwise.  */
> +  y = vreinterpretq_f64_u64 (veorq_u64 (vreinterpretq_u64_f64 (y), sign));
> +  return y;
> +}
> diff --git a/sysdeps/aarch64/fpu/atan_sve.c b/sysdeps/aarch64/fpu/atan_sve.c
> new file mode 100644
> index 0000000000..35587ef212
> --- /dev/null
> +++ b/sysdeps/aarch64/fpu/atan_sve.c
> @@ -0,0 +1,90 @@
> +/* Double-precision SVE inverse tan
> +
> +   Copyright (C) 2023 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 "sv_math.h"
> +#include "poly_sve_f64.h"
> +
> +static const struct data
> +{
> +  float64_t poly[20];
> +  float64_t pi_over_2;
> +} data = {
> +  /* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on
> +     [2**-1022, 1.0].  */
> +  .poly = { -0x1.5555555555555p-2,  0x1.99999999996c1p-3, -0x1.2492492478f88p-3,
> +            0x1.c71c71bc3951cp-4,   -0x1.745d160a7e368p-4, 0x1.3b139b6a88ba1p-4,
> +            -0x1.11100ee084227p-4,  0x1.e1d0f9696f63bp-5, -0x1.aebfe7b418581p-5,
> +            0x1.842dbe9b0d916p-5,   -0x1.5d30140ae5e99p-5, 0x1.338e31eb2fbbcp-5,
> +            -0x1.00e6eece7de8p-5,   0x1.860897b29e5efp-6, -0x1.0051381722a59p-6,
> +            0x1.14e9dc19a4a4ep-7,  -0x1.d0062b42fe3bfp-9, 0x1.17739e210171ap-10,
> +            -0x1.ab24da7be7402p-13, 0x1.358851160a528p-16, },
> +  .pi_over_2 = 0x1.921fb54442d18p+0,
> +};
> +
> +/* Useful constants.  */
> +#define SignMask (0x8000000000000000)
> +
> +/* Fast implementation of SVE atan.
> +   Based on atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1] using
> +   z=1/x and shift = pi/2. Largest errors are close to 1. The maximum observed
> +   error is 2.27 ulps:
> +   _ZGVsMxv_atan (0x1.0005af27c23e9p+0) got 0x1.9225645bdd7c1p-1
> +				       want 0x1.9225645bdd7c3p-1.  */
> +svfloat64_t SV_NAME_D1 (atan) (svfloat64_t x, const svbool_t pg)
> +{
> +  const struct data *d = ptr_barrier (&data);
> +
> +  /* No need to trigger special case. Small cases, infs and nans
> +     are supported by our approximation technique.  */
> +  svuint64_t ix = svreinterpret_u64 (x);
> +  svuint64_t sign = svand_x (pg, ix, SignMask);
> +
> +  /* Argument reduction:
> +     y := arctan(x) for x < 1
> +     y := pi/2 + arctan(-1/x) for x > 1
> +     Hence, use z=-1/a if x>=1, otherwise z=a.  */
> +  svbool_t red = svacgt (pg, x, 1.0);
> +  /* Avoid dependency in abs(x) in division (and comparison).  */
> +  svfloat64_t z = svsel (red, svdivr_x (pg, x, 1.0), x);
> +  /* Use absolute value only when needed (odd powers of z).  */
> +  svfloat64_t az = svabs_x (pg, z);
> +  az = svneg_m (az, red, az);
> +
> +  /* Use split Estrin scheme for P(z^2) with deg(P)=19.  */
> +  svfloat64_t z2 = svmul_x (pg, z, z);
> +  svfloat64_t x2 = svmul_x (pg, z2, z2);
> +  svfloat64_t x4 = svmul_x (pg, x2, x2);
> +  svfloat64_t x8 = svmul_x (pg, x4, x4);
> +
> +  svfloat64_t y
> +      = svmla_x (pg, sv_estrin_7_f64_x (pg, z2, x2, x4, d->poly),
> +		 sv_estrin_11_f64_x (pg, z2, x2, x4, x8, d->poly + 8), x8);
> +
> +  /* y = shift + z + z^3 * P(z^2).  */
> +  svfloat64_t z3 = svmul_x (pg, z2, az);
> +  y = svmla_x (pg, az, z3, y);
> +
> +  /* Apply shift as indicated by `red` predicate.  */
> +  y = svadd_m (red, y, d->pi_over_2);
> +
> +  /* y = atan(x) if x>0, -atan(-x) otherwise.  */
> +  y = svreinterpret_f64 (sveor_x (pg, svreinterpret_u64 (y), sign));
> +
> +  return y;
> +}
> diff --git a/sysdeps/aarch64/fpu/atanf_advsimd.c b/sysdeps/aarch64/fpu/atanf_advsimd.c
> new file mode 100644
> index 0000000000..589b0e8c96
> --- /dev/null
> +++ b/sysdeps/aarch64/fpu/atanf_advsimd.c
> @@ -0,0 +1,109 @@
> +/* Single-precision AdvSIMD inverse tan
> +
> +   Copyright (C) 2023 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 "v_math.h"
> +#include "poly_advsimd_f32.h"
> +
> +static const struct data
> +{
> +  float32x4_t poly[8];
> +  float32x4_t pi_over_2;
> +} data = {
> +  /* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on
> +     [2**-128, 1.0].
> +     Generated using fpminimax between FLT_MIN and 1.  */
> +  .poly = { V4 (-0x1.55555p-2f), V4 (0x1.99935ep-3f), V4 (-0x1.24051ep-3f),
> +	    V4 (0x1.bd7368p-4f), V4 (-0x1.491f0ep-4f), V4 (0x1.93a2c0p-5f),
> +	    V4 (-0x1.4c3c60p-6f), V4 (0x1.01fd88p-8f) },
> +  .pi_over_2 = V4 (0x1.921fb6p+0f),
> +};
> +
> +#define SignMask v_u32 (0x80000000)
> +
> +#define P(i) d->poly[i]
> +
> +#define TinyBound 0x30800000 /* asuint(0x1p-30).  */
> +#define BigBound 0x4e800000  /* asuint(0x1p30).  */
> +
> +#if WANT_SIMD_EXCEPT
> +static float32x4_t VPCS_ATTR NOINLINE
> +special_case (float32x4_t x, float32x4_t y, uint32x4_t special)
> +{
> +  return v_call_f32 (atanf, x, y, special);
> +}
> +#endif
> +
> +/* Fast implementation of vector atanf based on
> +   atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1]
> +   using z=-1/x and shift = pi/2. Maximum observed error is 2.9ulps:
> +   _ZGVnN4v_atanf (0x1.0468f6p+0) got 0x1.967f06p-1 want 0x1.967fp-1.  */
> +float32x4_t VPCS_ATTR V_NAME_F1 (atan) (float32x4_t x)
> +{
> +  const struct data *d = ptr_barrier (&data);
> +
> +  /* Small cases, infs and nans are supported by our approximation technique,
> +     but do not set fenv flags correctly. Only trigger special case if we need
> +     fenv.  */
> +  uint32x4_t ix = vreinterpretq_u32_f32 (x);
> +  uint32x4_t sign = vandq_u32 (ix, SignMask);
> +
> +#if WANT_SIMD_EXCEPT
> +  uint32x4_t ia = vandq_u32 (ix, v_u32 (0x7ff00000));
> +  uint32x4_t special = vcgtq_u32 (vsubq_u32 (ia, v_u32 (TinyBound)),
> +				  v_u32 (BigBound - TinyBound));
> +  /* If any lane is special, fall back to the scalar routine for all lanes.  */
> +  if (__glibc_unlikely (v_any_u32 (special)))
> +    return special_case (x, x, v_u32 (-1));
> +#endif
> +
> +  /* Argument reduction:
> +     y := arctan(x) for x < 1
> +     y := pi/2 + arctan(-1/x) for x > 1
> +     Hence, use z=-1/a if x>=1, otherwise z=a.  */
> +  uint32x4_t red = vcagtq_f32 (x, v_f32 (1.0));
> +  /* Avoid dependency in abs(x) in division (and comparison).  */
> +  float32x4_t z = vbslq_f32 (red, vdivq_f32 (v_f32 (1.0f), x), x);
> +  float32x4_t shift = vreinterpretq_f32_u32 (
> +      vandq_u32 (red, vreinterpretq_u32_f32 (d->pi_over_2)));
> +  /* Use absolute value only when needed (odd powers of z).  */
> +  float32x4_t az = vbslq_f32 (
> +      SignMask, vreinterpretq_f32_u32 (vandq_u32 (SignMask, red)), z);
> +
> +  /* Calculate the polynomial approximation.
> +     Use 2-level Estrin scheme for P(z^2) with deg(P)=7. However,
> +     a standard implementation using z8 creates spurious underflow
> +     in the very last fma (when z^8 is small enough).
> +     Therefore, we split the last fma into a mul and an fma.
> +     Horner and single-level Estrin have higher errors that exceed
> +     threshold.  */
> +  float32x4_t z2 = vmulq_f32 (z, z);
> +  float32x4_t z4 = vmulq_f32 (z2, z2);
> +
> +  float32x4_t y = vfmaq_f32 (
> +      v_pairwise_poly_3_f32 (z2, z4, d->poly), z4,
> +      vmulq_f32 (z4, v_pairwise_poly_3_f32 (z2, z4, d->poly + 4)));
> +
> +  /* y = shift + z * P(z^2).  */
> +  y = vaddq_f32 (vfmaq_f32 (az, y, vmulq_f32 (z2, az)), shift);
> +
> +  /* y = atan(x) if x>0, -atan(-x) otherwise.  */
> +  y = vreinterpretq_f32_u32 (veorq_u32 (vreinterpretq_u32_f32 (y), sign));
> +
> +  return y;
> +}
> diff --git a/sysdeps/aarch64/fpu/atanf_sve.c b/sysdeps/aarch64/fpu/atanf_sve.c
> new file mode 100644
> index 0000000000..9453e7aa29
> --- /dev/null
> +++ b/sysdeps/aarch64/fpu/atanf_sve.c
> @@ -0,0 +1,79 @@
> +/* Single-precision SVE inverse tan
> +
> +   Copyright (C) 2023 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 "sv_math.h"
> +#include "poly_sve_f32.h"
> +
> +static const struct data
> +{
> +  float32_t poly[8];
> +  float32_t pi_over_2;
> +} data = {
> +  /* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on
> +    [2**-128, 1.0].  */
> +  .poly = { -0x1.55555p-2f, 0x1.99935ep-3f, -0x1.24051ep-3f, 0x1.bd7368p-4f,
> +	    -0x1.491f0ep-4f, 0x1.93a2c0p-5f, -0x1.4c3c60p-6f, 0x1.01fd88p-8f },
> +  .pi_over_2 = 0x1.921fb6p+0f,
> +};
> +
> +#define SignMask (0x80000000)
> +
> +/* Fast implementation of SVE atanf based on
> +   atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1] using
> +   z=-1/x and shift = pi/2.
> +   Largest observed error is 2.9 ULP, close to +/-1.0:
> +   _ZGVsMxv_atanf (0x1.0468f6p+0) got -0x1.967f06p-1
> +				 want -0x1.967fp-1.  */
> +svfloat32_t SV_NAME_F1 (atan) (svfloat32_t x, const svbool_t pg)
> +{
> +  const struct data *d = ptr_barrier (&data);
> +
> +  /* No need to trigger special case. Small cases, infs and nans
> +     are supported by our approximation technique.  */
> +  svuint32_t ix = svreinterpret_u32 (x);
> +  svuint32_t sign = svand_x (pg, ix, SignMask);
> +
> +  /* Argument reduction:
> +     y := arctan(x) for x < 1
> +     y := pi/2 + arctan(-1/x) for x > 1
> +     Hence, use z=-1/a if x>=1, otherwise z=a.  */
> +  svbool_t red = svacgt (pg, x, 1.0f);
> +  /* Avoid dependency in abs(x) in division (and comparison).  */
> +  svfloat32_t z = svsel (red, svdiv_x (pg, sv_f32 (1.0f), x), x);
> +  /* Use absolute value only when needed (odd powers of z).  */
> +  svfloat32_t az = svabs_x (pg, z);
> +  az = svneg_m (az, red, az);
> +
> +  /* Use split Estrin scheme for P(z^2) with deg(P)=7.  */
> +  svfloat32_t z2 = svmul_x (pg, z, z);
> +  svfloat32_t z4 = svmul_x (pg, z2, z2);
> +  svfloat32_t z8 = svmul_x (pg, z4, z4);
> +
> +  svfloat32_t y = sv_estrin_7_f32_x (pg, z2, z4, z8, d->poly);
> +
> +  /* y = shift + z + z^3 * P(z^2).  */
> +  svfloat32_t z3 = svmul_x (pg, z2, az);
> +  y = svmla_x (pg, az, z3, y);
> +
> +  /* Apply shift as indicated by 'red' predicate.  */
> +  y = svadd_m (red, y, sv_f32 (d->pi_over_2));
> +
> +  /* y = atan(x) if x>0, -atan(-x) otherwise.  */
> +  return svreinterpret_f32 (sveor_x (pg, svreinterpret_u32 (y), sign));
> +}
> diff --git a/sysdeps/aarch64/fpu/bits/math-vector.h b/sysdeps/aarch64/fpu/bits/math-vector.h
> index f313993d70..37aa74fe50 100644
> --- a/sysdeps/aarch64/fpu/bits/math-vector.h
> +++ b/sysdeps/aarch64/fpu/bits/math-vector.h
> @@ -51,6 +51,7 @@ typedef __SVBool_t __sv_bool_t;
>  
>  __vpcs __f32x4_t _ZGVnN4v_acosf (__f32x4_t);
>  __vpcs __f32x4_t _ZGVnN4v_asinf (__f32x4_t);
> +__vpcs __f32x4_t _ZGVnN4v_atanf (__f32x4_t);
>  __vpcs __f32x4_t _ZGVnN4v_cosf (__f32x4_t);
>  __vpcs __f32x4_t _ZGVnN4v_expf (__f32x4_t);
>  __vpcs __f32x4_t _ZGVnN4v_exp10f (__f32x4_t);
> @@ -63,6 +64,7 @@ __vpcs __f32x4_t _ZGVnN4v_tanf (__f32x4_t);
>  
>  __vpcs __f64x2_t _ZGVnN2v_acos (__f64x2_t);
>  __vpcs __f64x2_t _ZGVnN2v_asin (__f64x2_t);
> +__vpcs __f64x2_t _ZGVnN2v_atan (__f64x2_t);
>  __vpcs __f64x2_t _ZGVnN2v_cos (__f64x2_t);
>  __vpcs __f64x2_t _ZGVnN2v_exp (__f64x2_t);
>  __vpcs __f64x2_t _ZGVnN2v_exp10 (__f64x2_t);
> @@ -80,6 +82,7 @@ __vpcs __f64x2_t _ZGVnN2v_tan (__f64x2_t);
>  
>  __sv_f32_t _ZGVsMxv_acosf (__sv_f32_t, __sv_bool_t);
>  __sv_f32_t _ZGVsMxv_asinf (__sv_f32_t, __sv_bool_t);
> +__sv_f32_t _ZGVsMxv_atanf (__sv_f32_t, __sv_bool_t);
>  __sv_f32_t _ZGVsMxv_cosf (__sv_f32_t, __sv_bool_t);
>  __sv_f32_t _ZGVsMxv_expf (__sv_f32_t, __sv_bool_t);
>  __sv_f32_t _ZGVsMxv_exp10f (__sv_f32_t, __sv_bool_t);
> @@ -92,6 +95,7 @@ __sv_f32_t _ZGVsMxv_tanf (__sv_f32_t, __sv_bool_t);
>  
>  __sv_f64_t _ZGVsMxv_acos (__sv_f64_t, __sv_bool_t);
>  __sv_f64_t _ZGVsMxv_asin (__sv_f64_t, __sv_bool_t);
> +__sv_f64_t _ZGVsMxv_atan (__sv_f64_t, __sv_bool_t);
>  __sv_f64_t _ZGVsMxv_cos (__sv_f64_t, __sv_bool_t);
>  __sv_f64_t _ZGVsMxv_exp (__sv_f64_t, __sv_bool_t);
>  __sv_f64_t _ZGVsMxv_exp10 (__sv_f64_t, __sv_bool_t);
> diff --git a/sysdeps/aarch64/fpu/test-double-advsimd-wrappers.c b/sysdeps/aarch64/fpu/test-double-advsimd-wrappers.c
> index 5a0cbf743b..6954fe7435 100644
> --- a/sysdeps/aarch64/fpu/test-double-advsimd-wrappers.c
> +++ b/sysdeps/aarch64/fpu/test-double-advsimd-wrappers.c
> @@ -25,6 +25,7 @@
>  
>  VPCS_VECTOR_WRAPPER (acos_advsimd, _ZGVnN2v_acos)
>  VPCS_VECTOR_WRAPPER (asin_advsimd, _ZGVnN2v_asin)
> +VPCS_VECTOR_WRAPPER (atan_advsimd, _ZGVnN2v_atan)
>  VPCS_VECTOR_WRAPPER (cos_advsimd, _ZGVnN2v_cos)
>  VPCS_VECTOR_WRAPPER (exp_advsimd, _ZGVnN2v_exp)
>  VPCS_VECTOR_WRAPPER (exp10_advsimd, _ZGVnN2v_exp10)
> diff --git a/sysdeps/aarch64/fpu/test-double-sve-wrappers.c b/sysdeps/aarch64/fpu/test-double-sve-wrappers.c
> index bd89ff6133..1173d8f9ae 100644
> --- a/sysdeps/aarch64/fpu/test-double-sve-wrappers.c
> +++ b/sysdeps/aarch64/fpu/test-double-sve-wrappers.c
> @@ -34,6 +34,7 @@
>  
>  SVE_VECTOR_WRAPPER (acos_sve, _ZGVsMxv_acos)
>  SVE_VECTOR_WRAPPER (asin_sve, _ZGVsMxv_asin)
> +SVE_VECTOR_WRAPPER (atan_sve, _ZGVsMxv_atan)
>  SVE_VECTOR_WRAPPER (cos_sve, _ZGVsMxv_cos)
>  SVE_VECTOR_WRAPPER (exp_sve, _ZGVsMxv_exp)
>  SVE_VECTOR_WRAPPER (exp10_sve, _ZGVsMxv_exp10)
> diff --git a/sysdeps/aarch64/fpu/test-float-advsimd-wrappers.c b/sysdeps/aarch64/fpu/test-float-advsimd-wrappers.c
> index 3fafca7557..387efc30f8 100644
> --- a/sysdeps/aarch64/fpu/test-float-advsimd-wrappers.c
> +++ b/sysdeps/aarch64/fpu/test-float-advsimd-wrappers.c
> @@ -25,6 +25,7 @@
>  
>  VPCS_VECTOR_WRAPPER (acosf_advsimd, _ZGVnN4v_acosf)
>  VPCS_VECTOR_WRAPPER (asinf_advsimd, _ZGVnN4v_asinf)
> +VPCS_VECTOR_WRAPPER (atanf_advsimd, _ZGVnN4v_atanf)
>  VPCS_VECTOR_WRAPPER (cosf_advsimd, _ZGVnN4v_cosf)
>  VPCS_VECTOR_WRAPPER (expf_advsimd, _ZGVnN4v_expf)
>  VPCS_VECTOR_WRAPPER (exp10f_advsimd, _ZGVnN4v_exp10f)
> diff --git a/sysdeps/aarch64/fpu/test-float-sve-wrappers.c b/sysdeps/aarch64/fpu/test-float-sve-wrappers.c
> index b4ec9f777b..dddd4cb213 100644
> --- a/sysdeps/aarch64/fpu/test-float-sve-wrappers.c
> +++ b/sysdeps/aarch64/fpu/test-float-sve-wrappers.c
> @@ -34,6 +34,7 @@
>  
>  SVE_VECTOR_WRAPPER (acosf_sve, _ZGVsMxv_acosf)
>  SVE_VECTOR_WRAPPER (asinf_sve, _ZGVsMxv_asinf)
> +SVE_VECTOR_WRAPPER (atanf_sve, _ZGVsMxv_atanf)
>  SVE_VECTOR_WRAPPER (cosf_sve, _ZGVsMxv_cosf)
>  SVE_VECTOR_WRAPPER (expf_sve, _ZGVsMxv_expf)
>  SVE_VECTOR_WRAPPER (exp10f_sve, _ZGVsMxv_exp10f)
> diff --git a/sysdeps/aarch64/libm-test-ulps b/sysdeps/aarch64/libm-test-ulps
> index c2b6f21b9d..24a99e10da 100644
> --- a/sysdeps/aarch64/libm-test-ulps
> +++ b/sysdeps/aarch64/libm-test-ulps
> @@ -121,11 +121,19 @@ double: 1
>  float: 1
>  ldouble: 2
>  
> +Function: "atan_advsimd":
> +double: 1
> +float: 1
> +
>  Function: "atan_downward":
>  double: 1
>  float: 2
>  ldouble: 2
>  
> +Function: "atan_sve":
> +double: 1
> +float: 1
> +
>  Function: "atan_towardzero":
>  double: 1
>  float: 1
> diff --git a/sysdeps/unix/sysv/linux/aarch64/libmvec.abilist b/sysdeps/unix/sysv/linux/aarch64/libmvec.abilist
> index f79eaaf241..a2d1b8fb6d 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/libmvec.abilist
> +++ b/sysdeps/unix/sysv/linux/aarch64/libmvec.abilist
> @@ -16,6 +16,7 @@ GLIBC_2.38 _ZGVsMxv_sin F
>  GLIBC_2.38 _ZGVsMxv_sinf F
>  GLIBC_2.39 _ZGVnN2v_acos F
>  GLIBC_2.39 _ZGVnN2v_asin F
> +GLIBC_2.39 _ZGVnN2v_atan F
>  GLIBC_2.39 _ZGVnN2v_exp10 F
>  GLIBC_2.39 _ZGVnN2v_exp2 F
>  GLIBC_2.39 _ZGVnN2v_log10 F
> @@ -23,6 +24,7 @@ GLIBC_2.39 _ZGVnN2v_log2 F
>  GLIBC_2.39 _ZGVnN2v_tan F
>  GLIBC_2.39 _ZGVnN4v_acosf F
>  GLIBC_2.39 _ZGVnN4v_asinf F
> +GLIBC_2.39 _ZGVnN4v_atanf F
>  GLIBC_2.39 _ZGVnN4v_exp10f F
>  GLIBC_2.39 _ZGVnN4v_exp2f F
>  GLIBC_2.39 _ZGVnN4v_log10f F
> @@ -32,6 +34,8 @@ GLIBC_2.39 _ZGVsMxv_acos F
>  GLIBC_2.39 _ZGVsMxv_acosf F
>  GLIBC_2.39 _ZGVsMxv_asin F
>  GLIBC_2.39 _ZGVsMxv_asinf F
> +GLIBC_2.39 _ZGVsMxv_atan F
> +GLIBC_2.39 _ZGVsMxv_atanf F
>  GLIBC_2.39 _ZGVsMxv_exp10 F
>  GLIBC_2.39 _ZGVsMxv_exp10f F
>  GLIBC_2.39 _ZGVsMxv_exp2 F
> -- 
> 2.27.0
>
  

Patch

diff --git a/sysdeps/aarch64/fpu/Makefile b/sysdeps/aarch64/fpu/Makefile
index 606fdd804f..5bd77a749d 100644
--- a/sysdeps/aarch64/fpu/Makefile
+++ b/sysdeps/aarch64/fpu/Makefile
@@ -1,5 +1,6 @@ 
 libmvec-supported-funcs = acos \
                           asin \
+                          atan \
                           cos \
                           exp \
                           exp10 \
diff --git a/sysdeps/aarch64/fpu/Versions b/sysdeps/aarch64/fpu/Versions
index 1037cd92bd..dfc3d2dad3 100644
--- a/sysdeps/aarch64/fpu/Versions
+++ b/sysdeps/aarch64/fpu/Versions
@@ -26,6 +26,10 @@  libmvec {
     _ZGVnN2v_asin;
     _ZGVsMxv_asinf;
     _ZGVsMxv_asin;
+    _ZGVnN4v_atanf;
+    _ZGVnN2v_atan;
+    _ZGVsMxv_atanf;
+    _ZGVsMxv_atan;
     _ZGVnN4v_exp10f;
     _ZGVnN2v_exp10;
     _ZGVsMxv_exp10f;
diff --git a/sysdeps/aarch64/fpu/atan_advsimd.c b/sysdeps/aarch64/fpu/atan_advsimd.c
new file mode 100644
index 0000000000..d52c07d8a0
--- /dev/null
+++ b/sysdeps/aarch64/fpu/atan_advsimd.c
@@ -0,0 +1,104 @@ 
+/* Double-precision AdvSIMD inverse tan
+
+   Copyright (C) 2023 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 "v_math.h"
+#include "poly_advsimd_f64.h"
+
+static const struct data
+{
+  float64x2_t pi_over_2;
+  float64x2_t poly[20];
+} data = {
+  /* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on
+	      [2**-1022, 1.0].  */
+  .poly = { V2 (-0x1.5555555555555p-2),	 V2 (0x1.99999999996c1p-3),
+	    V2 (-0x1.2492492478f88p-3),	 V2 (0x1.c71c71bc3951cp-4),
+	    V2 (-0x1.745d160a7e368p-4),	 V2 (0x1.3b139b6a88ba1p-4),
+	    V2 (-0x1.11100ee084227p-4),	 V2 (0x1.e1d0f9696f63bp-5),
+	    V2 (-0x1.aebfe7b418581p-5),	 V2 (0x1.842dbe9b0d916p-5),
+	    V2 (-0x1.5d30140ae5e99p-5),	 V2 (0x1.338e31eb2fbbcp-5),
+	    V2 (-0x1.00e6eece7de8p-5),	 V2 (0x1.860897b29e5efp-6),
+	    V2 (-0x1.0051381722a59p-6),	 V2 (0x1.14e9dc19a4a4ep-7),
+	    V2 (-0x1.d0062b42fe3bfp-9),	 V2 (0x1.17739e210171ap-10),
+	    V2 (-0x1.ab24da7be7402p-13), V2 (0x1.358851160a528p-16), },
+  .pi_over_2 = V2 (0x1.921fb54442d18p+0),
+};
+
+#define SignMask v_u64 (0x8000000000000000)
+#define TinyBound 0x3e10000000000000 /* asuint64(0x1p-30).  */
+#define BigBound 0x4340000000000000  /* asuint64(0x1p53).  */
+
+/* Fast implementation of vector atan.
+   Based on atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1] using
+   z=1/x and shift = pi/2. Maximum observed error is 2.27 ulps:
+   _ZGVnN2v_atan (0x1.0005af27c23e9p+0) got 0x1.9225645bdd7c1p-1
+				       want 0x1.9225645bdd7c3p-1.  */
+float64x2_t VPCS_ATTR V_NAME_D1 (atan) (float64x2_t x)
+{
+  const struct data *d = ptr_barrier (&data);
+
+  /* Small cases, infs and nans are supported by our approximation technique,
+     but do not set fenv flags correctly. Only trigger special case if we need
+     fenv.  */
+  uint64x2_t ix = vreinterpretq_u64_f64 (x);
+  uint64x2_t sign = vandq_u64 (ix, SignMask);
+
+#if WANT_SIMD_EXCEPT
+  uint64x2_t ia12 = vandq_u64 (ix, v_u64 (0x7ff0000000000000));
+  uint64x2_t special = vcgtq_u64 (vsubq_u64 (ia12, v_u64 (TinyBound)),
+				  v_u64 (BigBound - TinyBound));
+  /* If any lane is special, fall back to the scalar routine for all lanes.  */
+  if (__glibc_unlikely (v_any_u64 (special)))
+    return v_call_f64 (atan, x, v_f64 (0), v_u64 (-1));
+#endif
+
+  /* Argument reduction:
+     y := arctan(x) for x < 1
+     y := pi/2 + arctan(-1/x) for x > 1
+     Hence, use z=-1/a if x>=1, otherwise z=a.  */
+  uint64x2_t red = vcagtq_f64 (x, v_f64 (1.0));
+  /* Avoid dependency in abs(x) in division (and comparison).  */
+  float64x2_t z = vbslq_f64 (red, vdivq_f64 (v_f64 (1.0), x), x);
+  float64x2_t shift = vreinterpretq_f64_u64 (
+      vandq_u64 (red, vreinterpretq_u64_f64 (d->pi_over_2)));
+  /* Use absolute value only when needed (odd powers of z).  */
+  float64x2_t az = vbslq_f64 (
+      SignMask, vreinterpretq_f64_u64 (vandq_u64 (SignMask, red)), z);
+
+  /* Calculate the polynomial approximation.
+     Use split Estrin scheme for P(z^2) with deg(P)=19. Use split instead of
+     full scheme to avoid underflow in x^16.
+     The order 19 polynomial P approximates
+     (atan(sqrt(x))-sqrt(x))/x^(3/2).  */
+  float64x2_t z2 = vmulq_f64 (z, z);
+  float64x2_t x2 = vmulq_f64 (z2, z2);
+  float64x2_t x4 = vmulq_f64 (x2, x2);
+  float64x2_t x8 = vmulq_f64 (x4, x4);
+  float64x2_t y
+      = vfmaq_f64 (v_estrin_7_f64 (z2, x2, x4, d->poly),
+		   v_estrin_11_f64 (z2, x2, x4, x8, d->poly + 8), x8);
+
+  /* Finalize. y = shift + z + z^3 * P(z^2).  */
+  y = vfmaq_f64 (az, y, vmulq_f64 (z2, az));
+  y = vaddq_f64 (y, shift);
+
+  /* y = atan(x) if x>0, -atan(-x) otherwise.  */
+  y = vreinterpretq_f64_u64 (veorq_u64 (vreinterpretq_u64_f64 (y), sign));
+  return y;
+}
diff --git a/sysdeps/aarch64/fpu/atan_sve.c b/sysdeps/aarch64/fpu/atan_sve.c
new file mode 100644
index 0000000000..35587ef212
--- /dev/null
+++ b/sysdeps/aarch64/fpu/atan_sve.c
@@ -0,0 +1,90 @@ 
+/* Double-precision SVE inverse tan
+
+   Copyright (C) 2023 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 "sv_math.h"
+#include "poly_sve_f64.h"
+
+static const struct data
+{
+  float64_t poly[20];
+  float64_t pi_over_2;
+} data = {
+  /* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on
+     [2**-1022, 1.0].  */
+  .poly = { -0x1.5555555555555p-2,  0x1.99999999996c1p-3, -0x1.2492492478f88p-3,
+            0x1.c71c71bc3951cp-4,   -0x1.745d160a7e368p-4, 0x1.3b139b6a88ba1p-4,
+            -0x1.11100ee084227p-4,  0x1.e1d0f9696f63bp-5, -0x1.aebfe7b418581p-5,
+            0x1.842dbe9b0d916p-5,   -0x1.5d30140ae5e99p-5, 0x1.338e31eb2fbbcp-5,
+            -0x1.00e6eece7de8p-5,   0x1.860897b29e5efp-6, -0x1.0051381722a59p-6,
+            0x1.14e9dc19a4a4ep-7,  -0x1.d0062b42fe3bfp-9, 0x1.17739e210171ap-10,
+            -0x1.ab24da7be7402p-13, 0x1.358851160a528p-16, },
+  .pi_over_2 = 0x1.921fb54442d18p+0,
+};
+
+/* Useful constants.  */
+#define SignMask (0x8000000000000000)
+
+/* Fast implementation of SVE atan.
+   Based on atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1] using
+   z=1/x and shift = pi/2. Largest errors are close to 1. The maximum observed
+   error is 2.27 ulps:
+   _ZGVsMxv_atan (0x1.0005af27c23e9p+0) got 0x1.9225645bdd7c1p-1
+				       want 0x1.9225645bdd7c3p-1.  */
+svfloat64_t SV_NAME_D1 (atan) (svfloat64_t x, const svbool_t pg)
+{
+  const struct data *d = ptr_barrier (&data);
+
+  /* No need to trigger special case. Small cases, infs and nans
+     are supported by our approximation technique.  */
+  svuint64_t ix = svreinterpret_u64 (x);
+  svuint64_t sign = svand_x (pg, ix, SignMask);
+
+  /* Argument reduction:
+     y := arctan(x) for x < 1
+     y := pi/2 + arctan(-1/x) for x > 1
+     Hence, use z=-1/a if x>=1, otherwise z=a.  */
+  svbool_t red = svacgt (pg, x, 1.0);
+  /* Avoid dependency in abs(x) in division (and comparison).  */
+  svfloat64_t z = svsel (red, svdivr_x (pg, x, 1.0), x);
+  /* Use absolute value only when needed (odd powers of z).  */
+  svfloat64_t az = svabs_x (pg, z);
+  az = svneg_m (az, red, az);
+
+  /* Use split Estrin scheme for P(z^2) with deg(P)=19.  */
+  svfloat64_t z2 = svmul_x (pg, z, z);
+  svfloat64_t x2 = svmul_x (pg, z2, z2);
+  svfloat64_t x4 = svmul_x (pg, x2, x2);
+  svfloat64_t x8 = svmul_x (pg, x4, x4);
+
+  svfloat64_t y
+      = svmla_x (pg, sv_estrin_7_f64_x (pg, z2, x2, x4, d->poly),
+		 sv_estrin_11_f64_x (pg, z2, x2, x4, x8, d->poly + 8), x8);
+
+  /* y = shift + z + z^3 * P(z^2).  */
+  svfloat64_t z3 = svmul_x (pg, z2, az);
+  y = svmla_x (pg, az, z3, y);
+
+  /* Apply shift as indicated by `red` predicate.  */
+  y = svadd_m (red, y, d->pi_over_2);
+
+  /* y = atan(x) if x>0, -atan(-x) otherwise.  */
+  y = svreinterpret_f64 (sveor_x (pg, svreinterpret_u64 (y), sign));
+
+  return y;
+}
diff --git a/sysdeps/aarch64/fpu/atanf_advsimd.c b/sysdeps/aarch64/fpu/atanf_advsimd.c
new file mode 100644
index 0000000000..589b0e8c96
--- /dev/null
+++ b/sysdeps/aarch64/fpu/atanf_advsimd.c
@@ -0,0 +1,109 @@ 
+/* Single-precision AdvSIMD inverse tan
+
+   Copyright (C) 2023 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 "v_math.h"
+#include "poly_advsimd_f32.h"
+
+static const struct data
+{
+  float32x4_t poly[8];
+  float32x4_t pi_over_2;
+} data = {
+  /* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on
+     [2**-128, 1.0].
+     Generated using fpminimax between FLT_MIN and 1.  */
+  .poly = { V4 (-0x1.55555p-2f), V4 (0x1.99935ep-3f), V4 (-0x1.24051ep-3f),
+	    V4 (0x1.bd7368p-4f), V4 (-0x1.491f0ep-4f), V4 (0x1.93a2c0p-5f),
+	    V4 (-0x1.4c3c60p-6f), V4 (0x1.01fd88p-8f) },
+  .pi_over_2 = V4 (0x1.921fb6p+0f),
+};
+
+#define SignMask v_u32 (0x80000000)
+
+#define P(i) d->poly[i]
+
+#define TinyBound 0x30800000 /* asuint(0x1p-30).  */
+#define BigBound 0x4e800000  /* asuint(0x1p30).  */
+
+#if WANT_SIMD_EXCEPT
+static float32x4_t VPCS_ATTR NOINLINE
+special_case (float32x4_t x, float32x4_t y, uint32x4_t special)
+{
+  return v_call_f32 (atanf, x, y, special);
+}
+#endif
+
+/* Fast implementation of vector atanf based on
+   atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1]
+   using z=-1/x and shift = pi/2. Maximum observed error is 2.9ulps:
+   _ZGVnN4v_atanf (0x1.0468f6p+0) got 0x1.967f06p-1 want 0x1.967fp-1.  */
+float32x4_t VPCS_ATTR V_NAME_F1 (atan) (float32x4_t x)
+{
+  const struct data *d = ptr_barrier (&data);
+
+  /* Small cases, infs and nans are supported by our approximation technique,
+     but do not set fenv flags correctly. Only trigger special case if we need
+     fenv.  */
+  uint32x4_t ix = vreinterpretq_u32_f32 (x);
+  uint32x4_t sign = vandq_u32 (ix, SignMask);
+
+#if WANT_SIMD_EXCEPT
+  uint32x4_t ia = vandq_u32 (ix, v_u32 (0x7ff00000));
+  uint32x4_t special = vcgtq_u32 (vsubq_u32 (ia, v_u32 (TinyBound)),
+				  v_u32 (BigBound - TinyBound));
+  /* If any lane is special, fall back to the scalar routine for all lanes.  */
+  if (__glibc_unlikely (v_any_u32 (special)))
+    return special_case (x, x, v_u32 (-1));
+#endif
+
+  /* Argument reduction:
+     y := arctan(x) for x < 1
+     y := pi/2 + arctan(-1/x) for x > 1
+     Hence, use z=-1/a if x>=1, otherwise z=a.  */
+  uint32x4_t red = vcagtq_f32 (x, v_f32 (1.0));
+  /* Avoid dependency in abs(x) in division (and comparison).  */
+  float32x4_t z = vbslq_f32 (red, vdivq_f32 (v_f32 (1.0f), x), x);
+  float32x4_t shift = vreinterpretq_f32_u32 (
+      vandq_u32 (red, vreinterpretq_u32_f32 (d->pi_over_2)));
+  /* Use absolute value only when needed (odd powers of z).  */
+  float32x4_t az = vbslq_f32 (
+      SignMask, vreinterpretq_f32_u32 (vandq_u32 (SignMask, red)), z);
+
+  /* Calculate the polynomial approximation.
+     Use 2-level Estrin scheme for P(z^2) with deg(P)=7. However,
+     a standard implementation using z8 creates spurious underflow
+     in the very last fma (when z^8 is small enough).
+     Therefore, we split the last fma into a mul and an fma.
+     Horner and single-level Estrin have higher errors that exceed
+     threshold.  */
+  float32x4_t z2 = vmulq_f32 (z, z);
+  float32x4_t z4 = vmulq_f32 (z2, z2);
+
+  float32x4_t y = vfmaq_f32 (
+      v_pairwise_poly_3_f32 (z2, z4, d->poly), z4,
+      vmulq_f32 (z4, v_pairwise_poly_3_f32 (z2, z4, d->poly + 4)));
+
+  /* y = shift + z * P(z^2).  */
+  y = vaddq_f32 (vfmaq_f32 (az, y, vmulq_f32 (z2, az)), shift);
+
+  /* y = atan(x) if x>0, -atan(-x) otherwise.  */
+  y = vreinterpretq_f32_u32 (veorq_u32 (vreinterpretq_u32_f32 (y), sign));
+
+  return y;
+}
diff --git a/sysdeps/aarch64/fpu/atanf_sve.c b/sysdeps/aarch64/fpu/atanf_sve.c
new file mode 100644
index 0000000000..9453e7aa29
--- /dev/null
+++ b/sysdeps/aarch64/fpu/atanf_sve.c
@@ -0,0 +1,79 @@ 
+/* Single-precision SVE inverse tan
+
+   Copyright (C) 2023 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 "sv_math.h"
+#include "poly_sve_f32.h"
+
+static const struct data
+{
+  float32_t poly[8];
+  float32_t pi_over_2;
+} data = {
+  /* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on
+    [2**-128, 1.0].  */
+  .poly = { -0x1.55555p-2f, 0x1.99935ep-3f, -0x1.24051ep-3f, 0x1.bd7368p-4f,
+	    -0x1.491f0ep-4f, 0x1.93a2c0p-5f, -0x1.4c3c60p-6f, 0x1.01fd88p-8f },
+  .pi_over_2 = 0x1.921fb6p+0f,
+};
+
+#define SignMask (0x80000000)
+
+/* Fast implementation of SVE atanf based on
+   atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1] using
+   z=-1/x and shift = pi/2.
+   Largest observed error is 2.9 ULP, close to +/-1.0:
+   _ZGVsMxv_atanf (0x1.0468f6p+0) got -0x1.967f06p-1
+				 want -0x1.967fp-1.  */
+svfloat32_t SV_NAME_F1 (atan) (svfloat32_t x, const svbool_t pg)
+{
+  const struct data *d = ptr_barrier (&data);
+
+  /* No need to trigger special case. Small cases, infs and nans
+     are supported by our approximation technique.  */
+  svuint32_t ix = svreinterpret_u32 (x);
+  svuint32_t sign = svand_x (pg, ix, SignMask);
+
+  /* Argument reduction:
+     y := arctan(x) for x < 1
+     y := pi/2 + arctan(-1/x) for x > 1
+     Hence, use z=-1/a if x>=1, otherwise z=a.  */
+  svbool_t red = svacgt (pg, x, 1.0f);
+  /* Avoid dependency in abs(x) in division (and comparison).  */
+  svfloat32_t z = svsel (red, svdiv_x (pg, sv_f32 (1.0f), x), x);
+  /* Use absolute value only when needed (odd powers of z).  */
+  svfloat32_t az = svabs_x (pg, z);
+  az = svneg_m (az, red, az);
+
+  /* Use split Estrin scheme for P(z^2) with deg(P)=7.  */
+  svfloat32_t z2 = svmul_x (pg, z, z);
+  svfloat32_t z4 = svmul_x (pg, z2, z2);
+  svfloat32_t z8 = svmul_x (pg, z4, z4);
+
+  svfloat32_t y = sv_estrin_7_f32_x (pg, z2, z4, z8, d->poly);
+
+  /* y = shift + z + z^3 * P(z^2).  */
+  svfloat32_t z3 = svmul_x (pg, z2, az);
+  y = svmla_x (pg, az, z3, y);
+
+  /* Apply shift as indicated by 'red' predicate.  */
+  y = svadd_m (red, y, sv_f32 (d->pi_over_2));
+
+  /* y = atan(x) if x>0, -atan(-x) otherwise.  */
+  return svreinterpret_f32 (sveor_x (pg, svreinterpret_u32 (y), sign));
+}
diff --git a/sysdeps/aarch64/fpu/bits/math-vector.h b/sysdeps/aarch64/fpu/bits/math-vector.h
index f313993d70..37aa74fe50 100644
--- a/sysdeps/aarch64/fpu/bits/math-vector.h
+++ b/sysdeps/aarch64/fpu/bits/math-vector.h
@@ -51,6 +51,7 @@  typedef __SVBool_t __sv_bool_t;
 
 __vpcs __f32x4_t _ZGVnN4v_acosf (__f32x4_t);
 __vpcs __f32x4_t _ZGVnN4v_asinf (__f32x4_t);
+__vpcs __f32x4_t _ZGVnN4v_atanf (__f32x4_t);
 __vpcs __f32x4_t _ZGVnN4v_cosf (__f32x4_t);
 __vpcs __f32x4_t _ZGVnN4v_expf (__f32x4_t);
 __vpcs __f32x4_t _ZGVnN4v_exp10f (__f32x4_t);
@@ -63,6 +64,7 @@  __vpcs __f32x4_t _ZGVnN4v_tanf (__f32x4_t);
 
 __vpcs __f64x2_t _ZGVnN2v_acos (__f64x2_t);
 __vpcs __f64x2_t _ZGVnN2v_asin (__f64x2_t);
+__vpcs __f64x2_t _ZGVnN2v_atan (__f64x2_t);
 __vpcs __f64x2_t _ZGVnN2v_cos (__f64x2_t);
 __vpcs __f64x2_t _ZGVnN2v_exp (__f64x2_t);
 __vpcs __f64x2_t _ZGVnN2v_exp10 (__f64x2_t);
@@ -80,6 +82,7 @@  __vpcs __f64x2_t _ZGVnN2v_tan (__f64x2_t);
 
 __sv_f32_t _ZGVsMxv_acosf (__sv_f32_t, __sv_bool_t);
 __sv_f32_t _ZGVsMxv_asinf (__sv_f32_t, __sv_bool_t);
+__sv_f32_t _ZGVsMxv_atanf (__sv_f32_t, __sv_bool_t);
 __sv_f32_t _ZGVsMxv_cosf (__sv_f32_t, __sv_bool_t);
 __sv_f32_t _ZGVsMxv_expf (__sv_f32_t, __sv_bool_t);
 __sv_f32_t _ZGVsMxv_exp10f (__sv_f32_t, __sv_bool_t);
@@ -92,6 +95,7 @@  __sv_f32_t _ZGVsMxv_tanf (__sv_f32_t, __sv_bool_t);
 
 __sv_f64_t _ZGVsMxv_acos (__sv_f64_t, __sv_bool_t);
 __sv_f64_t _ZGVsMxv_asin (__sv_f64_t, __sv_bool_t);
+__sv_f64_t _ZGVsMxv_atan (__sv_f64_t, __sv_bool_t);
 __sv_f64_t _ZGVsMxv_cos (__sv_f64_t, __sv_bool_t);
 __sv_f64_t _ZGVsMxv_exp (__sv_f64_t, __sv_bool_t);
 __sv_f64_t _ZGVsMxv_exp10 (__sv_f64_t, __sv_bool_t);
diff --git a/sysdeps/aarch64/fpu/test-double-advsimd-wrappers.c b/sysdeps/aarch64/fpu/test-double-advsimd-wrappers.c
index 5a0cbf743b..6954fe7435 100644
--- a/sysdeps/aarch64/fpu/test-double-advsimd-wrappers.c
+++ b/sysdeps/aarch64/fpu/test-double-advsimd-wrappers.c
@@ -25,6 +25,7 @@ 
 
 VPCS_VECTOR_WRAPPER (acos_advsimd, _ZGVnN2v_acos)
 VPCS_VECTOR_WRAPPER (asin_advsimd, _ZGVnN2v_asin)
+VPCS_VECTOR_WRAPPER (atan_advsimd, _ZGVnN2v_atan)
 VPCS_VECTOR_WRAPPER (cos_advsimd, _ZGVnN2v_cos)
 VPCS_VECTOR_WRAPPER (exp_advsimd, _ZGVnN2v_exp)
 VPCS_VECTOR_WRAPPER (exp10_advsimd, _ZGVnN2v_exp10)
diff --git a/sysdeps/aarch64/fpu/test-double-sve-wrappers.c b/sysdeps/aarch64/fpu/test-double-sve-wrappers.c
index bd89ff6133..1173d8f9ae 100644
--- a/sysdeps/aarch64/fpu/test-double-sve-wrappers.c
+++ b/sysdeps/aarch64/fpu/test-double-sve-wrappers.c
@@ -34,6 +34,7 @@ 
 
 SVE_VECTOR_WRAPPER (acos_sve, _ZGVsMxv_acos)
 SVE_VECTOR_WRAPPER (asin_sve, _ZGVsMxv_asin)
+SVE_VECTOR_WRAPPER (atan_sve, _ZGVsMxv_atan)
 SVE_VECTOR_WRAPPER (cos_sve, _ZGVsMxv_cos)
 SVE_VECTOR_WRAPPER (exp_sve, _ZGVsMxv_exp)
 SVE_VECTOR_WRAPPER (exp10_sve, _ZGVsMxv_exp10)
diff --git a/sysdeps/aarch64/fpu/test-float-advsimd-wrappers.c b/sysdeps/aarch64/fpu/test-float-advsimd-wrappers.c
index 3fafca7557..387efc30f8 100644
--- a/sysdeps/aarch64/fpu/test-float-advsimd-wrappers.c
+++ b/sysdeps/aarch64/fpu/test-float-advsimd-wrappers.c
@@ -25,6 +25,7 @@ 
 
 VPCS_VECTOR_WRAPPER (acosf_advsimd, _ZGVnN4v_acosf)
 VPCS_VECTOR_WRAPPER (asinf_advsimd, _ZGVnN4v_asinf)
+VPCS_VECTOR_WRAPPER (atanf_advsimd, _ZGVnN4v_atanf)
 VPCS_VECTOR_WRAPPER (cosf_advsimd, _ZGVnN4v_cosf)
 VPCS_VECTOR_WRAPPER (expf_advsimd, _ZGVnN4v_expf)
 VPCS_VECTOR_WRAPPER (exp10f_advsimd, _ZGVnN4v_exp10f)
diff --git a/sysdeps/aarch64/fpu/test-float-sve-wrappers.c b/sysdeps/aarch64/fpu/test-float-sve-wrappers.c
index b4ec9f777b..dddd4cb213 100644
--- a/sysdeps/aarch64/fpu/test-float-sve-wrappers.c
+++ b/sysdeps/aarch64/fpu/test-float-sve-wrappers.c
@@ -34,6 +34,7 @@ 
 
 SVE_VECTOR_WRAPPER (acosf_sve, _ZGVsMxv_acosf)
 SVE_VECTOR_WRAPPER (asinf_sve, _ZGVsMxv_asinf)
+SVE_VECTOR_WRAPPER (atanf_sve, _ZGVsMxv_atanf)
 SVE_VECTOR_WRAPPER (cosf_sve, _ZGVsMxv_cosf)
 SVE_VECTOR_WRAPPER (expf_sve, _ZGVsMxv_expf)
 SVE_VECTOR_WRAPPER (exp10f_sve, _ZGVsMxv_exp10f)
diff --git a/sysdeps/aarch64/libm-test-ulps b/sysdeps/aarch64/libm-test-ulps
index c2b6f21b9d..24a99e10da 100644
--- a/sysdeps/aarch64/libm-test-ulps
+++ b/sysdeps/aarch64/libm-test-ulps
@@ -121,11 +121,19 @@  double: 1
 float: 1
 ldouble: 2
 
+Function: "atan_advsimd":
+double: 1
+float: 1
+
 Function: "atan_downward":
 double: 1
 float: 2
 ldouble: 2
 
+Function: "atan_sve":
+double: 1
+float: 1
+
 Function: "atan_towardzero":
 double: 1
 float: 1
diff --git a/sysdeps/unix/sysv/linux/aarch64/libmvec.abilist b/sysdeps/unix/sysv/linux/aarch64/libmvec.abilist
index f79eaaf241..a2d1b8fb6d 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libmvec.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libmvec.abilist
@@ -16,6 +16,7 @@  GLIBC_2.38 _ZGVsMxv_sin F
 GLIBC_2.38 _ZGVsMxv_sinf F
 GLIBC_2.39 _ZGVnN2v_acos F
 GLIBC_2.39 _ZGVnN2v_asin F
+GLIBC_2.39 _ZGVnN2v_atan F
 GLIBC_2.39 _ZGVnN2v_exp10 F
 GLIBC_2.39 _ZGVnN2v_exp2 F
 GLIBC_2.39 _ZGVnN2v_log10 F
@@ -23,6 +24,7 @@  GLIBC_2.39 _ZGVnN2v_log2 F
 GLIBC_2.39 _ZGVnN2v_tan F
 GLIBC_2.39 _ZGVnN4v_acosf F
 GLIBC_2.39 _ZGVnN4v_asinf F
+GLIBC_2.39 _ZGVnN4v_atanf F
 GLIBC_2.39 _ZGVnN4v_exp10f F
 GLIBC_2.39 _ZGVnN4v_exp2f F
 GLIBC_2.39 _ZGVnN4v_log10f F
@@ -32,6 +34,8 @@  GLIBC_2.39 _ZGVsMxv_acos F
 GLIBC_2.39 _ZGVsMxv_acosf F
 GLIBC_2.39 _ZGVsMxv_asin F
 GLIBC_2.39 _ZGVsMxv_asinf F
+GLIBC_2.39 _ZGVsMxv_atan F
+GLIBC_2.39 _ZGVsMxv_atanf F
 GLIBC_2.39 _ZGVsMxv_exp10 F
 GLIBC_2.39 _ZGVsMxv_exp10f F
 GLIBC_2.39 _ZGVsMxv_exp2 F