Path: blob/main/contrib/arm-optimized-routines/math/aarch64/sve/atanf.c
48375 views
/*1* Single-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_f32.h"1112static const struct data13{14float32_t poly[8];15float32_t pi_over_2;16} data = {17/* Coefficients of polynomial P such that atan(x)~x+x*P(x^2) on18[2**-128, 1.0]. */19.poly = { -0x1.55555p-2f, 0x1.99935ep-3f, -0x1.24051ep-3f, 0x1.bd7368p-4f,20-0x1.491f0ep-4f, 0x1.93a2c0p-5f, -0x1.4c3c60p-6f, 0x1.01fd88p-8f },21.pi_over_2 = 0x1.921fb6p+0f,22};2324#define SignMask (0x80000000)2526/* Fast implementation of SVE atanf based on27atan(x) ~ shift + z + z^3 * P(z^2) with reduction to [0,1] using28z=-1/x and shift = pi/2.29Largest observed error is 2.9 ULP, close to +/-1.0:30_ZGVsMxv_atanf (0x1.0468f6p+0) got -0x1.967f06p-131want -0x1.967fp-1. */32svfloat32_t SV_NAME_F1 (atan) (svfloat32_t x, const svbool_t pg)33{34const struct data *d = ptr_barrier (&data);3536/* No need to trigger special case. Small cases, infs and nans37are supported by our approximation technique. */38svuint32_t ix = svreinterpret_u32 (x);39svuint32_t sign = svand_x (pg, ix, SignMask);4041/* Argument reduction:42y := arctan(x) for x < 143y := pi/2 + arctan(-1/x) for x > 144Hence, use z=-1/a if x>=1, otherwise z=a. */45svbool_t red = svacgt (pg, x, 1.0f);46/* Avoid dependency in abs(x) in division (and comparison). */47svfloat32_t z = svsel (red, svdiv_x (pg, sv_f32 (1.0f), x), x);48/* Use absolute value only when needed (odd powers of z). */49svfloat32_t az = svabs_x (pg, z);50az = svneg_m (az, red, az);5152/* Use split Estrin scheme for P(z^2) with deg(P)=7. */53svfloat32_t z2 = svmul_x (pg, z, z);54svfloat32_t z4 = svmul_x (pg, z2, z2);55svfloat32_t z8 = svmul_x (pg, z4, z4);5657svfloat32_t y = sv_estrin_7_f32_x (pg, z2, z4, z8, d->poly);5859/* y = shift + z + z^3 * P(z^2). */60svfloat32_t z3 = svmul_x (pg, z2, az);61y = svmla_x (pg, az, z3, y);6263/* Apply shift as indicated by 'red' predicate. */64y = svadd_m (red, y, sv_f32 (d->pi_over_2));6566/* y = atan(x) if x>0, -atan(-x) otherwise. */67return svreinterpret_f32 (sveor_x (pg, svreinterpret_u32 (y), sign));68}6970TEST_SIG (SV, F, 1, atan, -3.1, 3.1)71TEST_ULP (SV_NAME_F1 (atan), 2.9)72TEST_DISABLE_FENV (SV_NAME_F1 (atan))73TEST_INTERVAL (SV_NAME_F1 (atan), 0.0, 1.0, 40000)74TEST_INTERVAL (SV_NAME_F1 (atan), 1.0, 100.0, 40000)75TEST_INTERVAL (SV_NAME_F1 (atan), 100, inf, 40000)76TEST_INTERVAL (SV_NAME_F1 (atan), -0, -inf, 40000)77CLOSE_SVE_ATTR787980