• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Single-precision polynomial evaluation function for SVE atan(x) and
3  * 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_SV_ATANF_COMMON_H
10 #define PL_MATH_SV_ATANF_COMMON_H
11 
12 #include "math_config.h"
13 #include "sv_math.h"
14 
15 #define P(i) sv_f32 (__atanf_poly_data.poly[i])
16 
17 /* Polynomial used in fast SVE atanf(x) and atan2f(y,x) implementations
18    The order 7 polynomial P approximates (f(sqrt(x))-sqrt(x))/x^(3/2).  */
19 static inline sv_f32_t
__sv_atanf_common(svbool_t pg,svbool_t red,sv_f32_t z,sv_f32_t az,sv_f32_t shift)20 __sv_atanf_common (svbool_t pg, svbool_t red, sv_f32_t z, sv_f32_t az,
21 		   sv_f32_t shift)
22 {
23   /* Use full Estrin scheme for P(z^2) with deg(P)=7.  */
24 
25   /* First compute square powers of z.  */
26   sv_f32_t z2 = svmul_f32_x (pg, z, z);
27   sv_f32_t z4 = svmul_f32_x (pg, z2, z2);
28   sv_f32_t z8 = svmul_f32_x (pg, z4, z4);
29 
30   /* Then assemble polynomial.  */
31   sv_f32_t p_4_7 = sv_fma_f32_x (pg, z4, (sv_fma_f32_x (pg, z2, P (7), P (6))),
32 				 (sv_fma_f32_x (pg, z2, P (5), P (4))));
33   sv_f32_t p_0_3 = sv_fma_f32_x (pg, z4, (sv_fma_f32_x (pg, z2, P (3), P (2))),
34 				 (sv_fma_f32_x (pg, z2, P (1), P (0))));
35   sv_f32_t y = sv_fma_f32_x (pg, z8, p_4_7, p_0_3);
36 
37   /* Finalize. y = shift + z + z^3 * P(z^2).  */
38   sv_f32_t z3 = svmul_f32_x (pg, z2, az);
39   y = sv_fma_f32_x (pg, y, z3, az);
40 
41   /* Apply shift as indicated by 'red' predicate.  */
42   y = svadd_f32_m (red, y, shift);
43 
44   return y;
45 }
46 
47 #endif // PL_MATH_SV_ATANF_COMMON_H
48