Path: blob/main/contrib/arm-optimized-routines/math/aarch64/sve/atan.c
48375 views
/*1* Double-precision vector atan(x) function.2*3* Copyright (c) 2021-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include "sv_math.h"8#include "test_sig.h"9#include "test_defs.h"10#include "sv_poly_f64.h"1112static const struct data13{14float64_t poly[20];15float64_t pi_over_2;16} data = {17/* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on18[2**-1022, 1.0]. */19.poly = { -0x1.5555555555555p-2, 0x1.99999999996c1p-3, -0x1.2492492478f88p-3,200x1.c71c71bc3951cp-4, -0x1.745d160a7e368p-4, 0x1.3b139b6a88ba1p-4,21-0x1.11100ee084227p-4, 0x1.e1d0f9696f63bp-5, -0x1.aebfe7b418581p-5,220x1.842dbe9b0d916p-5, -0x1.5d30140ae5e99p-5, 0x1.338e31eb2fbbcp-5,23-0x1.00e6eece7de8p-5, 0x1.860897b29e5efp-6, -0x1.0051381722a59p-6,240x1.14e9dc19a4a4ep-7, -0x1.d0062b42fe3bfp-9, 0x1.17739e210171ap-10,25-0x1.ab24da7be7402p-13, 0x1.358851160a528p-16, },26.pi_over_2 = 0x1.921fb54442d18p+0,27};2829/* Useful constants. */30#define SignMask (0x8000000000000000)3132/* Fast implementation of SVE atan.33Based on atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1] using34z=1/x and shift = pi/2. Largest errors are close to 1. The maximum observed35error is 2.27 ulps:36_ZGVsMxv_atan (0x1.0005af27c23e9p+0) got 0x1.9225645bdd7c1p-137want 0x1.9225645bdd7c3p-1. */38svfloat64_t SV_NAME_D1 (atan) (svfloat64_t x, const svbool_t pg)39{40const struct data *d = ptr_barrier (&data);4142/* No need to trigger special case. Small cases, infs and nans43are supported by our approximation technique. */44svuint64_t ix = svreinterpret_u64 (x);45svuint64_t sign = svand_x (pg, ix, SignMask);4647/* Argument reduction:48y := arctan(x) for x < 149y := pi/2 + arctan(-1/x) for x > 150Hence, use z=-1/a if x>=1, otherwise z=a. */51svbool_t red = svacgt (pg, x, 1.0);52/* Avoid dependency in abs(x) in division (and comparison). */53svfloat64_t z = svsel (red, svdivr_x (pg, x, 1.0), x);54/* Use absolute value only when needed (odd powers of z). */55svfloat64_t az = svabs_x (pg, z);56az = svneg_m (az, red, az);5758/* Use split Estrin scheme for P(z^2) with deg(P)=19. */59svfloat64_t z2 = svmul_x (pg, z, z);60svfloat64_t x2 = svmul_x (pg, z2, z2);61svfloat64_t x4 = svmul_x (pg, x2, x2);62svfloat64_t x8 = svmul_x (pg, x4, x4);6364svfloat64_t y65= svmla_x (pg, sv_estrin_7_f64_x (pg, z2, x2, x4, d->poly),66sv_estrin_11_f64_x (pg, z2, x2, x4, x8, d->poly + 8), x8);6768/* y = shift + z + z^3 * P(z^2). */69svfloat64_t z3 = svmul_x (pg, z2, az);70y = svmla_x (pg, az, z3, y);7172/* Apply shift as indicated by `red` predicate. */73y = svadd_m (red, y, d->pi_over_2);7475/* y = atan(x) if x>0, -atan(-x) otherwise. */76y = svreinterpret_f64 (sveor_x (pg, svreinterpret_u64 (y), sign));7778return y;79}8081TEST_SIG (SV, D, 1, atan, -3.1, 3.1)82TEST_ULP (SV_NAME_D1 (atan), 1.78)83TEST_DISABLE_FENV (SV_NAME_D1 (atan))84TEST_INTERVAL (SV_NAME_D1 (atan), 0.0, 1.0, 40000)85TEST_INTERVAL (SV_NAME_D1 (atan), 1.0, 100.0, 40000)86TEST_INTERVAL (SV_NAME_D1 (atan), 100, inf, 40000)87TEST_INTERVAL (SV_NAME_D1 (atan), -0, -inf, 40000)88CLOSE_SVE_ATTR899091