1 /* 2 * Single-precision polynomial evaluation function for scalar and vector 3 * atan(x) and atan2(y,x). 4 * 5 * Copyright (c) 2021-2023, Arm Limited. 6 * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception 7 */ 8 9 #ifndef PL_MATH_ATANF_COMMON_H 10 #define PL_MATH_ATANF_COMMON_H 11 12 #include "math_config.h" 13 #include "estrinf.h" 14 15 #if V_SUPPORTED 16 17 #include "v_math.h" 18 19 #define FLT_T v_f32_t 20 #define P(i) v_f32 (__atanf_poly_data.poly[i]) 21 22 #else 23 24 #define FLT_T float 25 #define P(i) __atanf_poly_data.poly[i] 26 27 #endif 28 29 /* Polynomial used in fast atanf(x) and atan2f(y,x) implementations 30 The order 7 polynomial P approximates (atan(sqrt(x))-sqrt(x))/x^(3/2). */ 31 static inline FLT_T 32 eval_poly (FLT_T z, FLT_T az, FLT_T shift) 33 { 34 /* Use 2-level Estrin scheme for P(z^2) with deg(P)=7. However, 35 a standard implementation using z8 creates spurious underflow 36 in the very last fma (when z^8 is small enough). 37 Therefore, we split the last fma into a mul and and an fma. 38 Horner and single-level Estrin have higher errors that exceed 39 threshold. */ 40 FLT_T z2 = z * z; 41 FLT_T z4 = z2 * z2; 42 43 /* Then assemble polynomial. */ 44 FLT_T y = FMA (z4, z4 * ESTRIN_3_ (z2, z4, P, 4), ESTRIN_3 (z2, z4, P)); 45 46 /* Finalize: 47 y = shift + z * P(z^2). */ 48 return FMA (y, z2 * az, az) + shift; 49 } 50 51 #endif // PL_MATH_ATANF_COMMON_H 52