xref: /aosp_15_r20/external/arm-optimized-routines/pl/math/v_sincosf_1u8.c (revision 412f47f9e737e10ed5cc46ec6a8d7fa2264f8a14)
1*412f47f9SXin Li /*
2*412f47f9SXin Li  * Single-precision vector sincos function.
3*412f47f9SXin Li  *
4*412f47f9SXin Li  * Copyright (c) 2023, Arm Limited.
5*412f47f9SXin Li  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6*412f47f9SXin Li  */
7*412f47f9SXin Li 
8*412f47f9SXin Li /* Define _GNU_SOURCE in order to include sincosf declaration. If building
9*412f47f9SXin Li    pre-GLIBC 2.1, or on a non-GNU conforming system, this routine will need to
10*412f47f9SXin Li    be linked against the scalar sincosf from math/.  */
11*412f47f9SXin Li #define _GNU_SOURCE
12*412f47f9SXin Li #include <math.h>
13*412f47f9SXin Li #undef _GNU_SOURCE
14*412f47f9SXin Li 
15*412f47f9SXin Li #include "v_sincosf_common.h"
16*412f47f9SXin Li #include "v_math.h"
17*412f47f9SXin Li #include "pl_test.h"
18*412f47f9SXin Li 
19*412f47f9SXin Li static void VPCS_ATTR NOINLINE
special_case(float32x4_t x,uint32x4_t special,float * out_sin,float * out_cos)20*412f47f9SXin Li special_case (float32x4_t x, uint32x4_t special, float *out_sin,
21*412f47f9SXin Li 	      float *out_cos)
22*412f47f9SXin Li {
23*412f47f9SXin Li   for (int i = 0; i < 4; i++)
24*412f47f9SXin Li     if (special[i])
25*412f47f9SXin Li       sincosf (x[i], out_sin + i, out_cos + i);
26*412f47f9SXin Li }
27*412f47f9SXin Li 
28*412f47f9SXin Li /* Single-precision vector function allowing calculation of both sin and cos in
29*412f47f9SXin Li    one function call, using shared argument reduction and separate low-order
30*412f47f9SXin Li    polynomials.
31*412f47f9SXin Li    Worst-case error for sin is 1.67 ULP:
32*412f47f9SXin Li    v_sincosf_sin(0x1.c704c4p+19) got 0x1.fff698p-5 want 0x1.fff69cp-5
33*412f47f9SXin Li    Worst-case error for cos is 1.81 ULP:
34*412f47f9SXin Li    v_sincosf_cos(0x1.e506fp+19) got -0x1.ffec6ep-6 want -0x1.ffec72p-6.  */
35*412f47f9SXin Li VPCS_ATTR void
_ZGVnN4vl4l4_sincosf(float32x4_t x,float * out_sin,float * out_cos)36*412f47f9SXin Li _ZGVnN4vl4l4_sincosf (float32x4_t x, float *out_sin, float *out_cos)
37*412f47f9SXin Li {
38*412f47f9SXin Li   const struct v_sincosf_data *d = ptr_barrier (&v_sincosf_data);
39*412f47f9SXin Li   uint32x4_t special = check_ge_rangeval (x, d);
40*412f47f9SXin Li 
41*412f47f9SXin Li   float32x4x2_t sc = v_sincosf_inline (x, d);
42*412f47f9SXin Li 
43*412f47f9SXin Li   vst1q_f32 (out_sin, sc.val[0]);
44*412f47f9SXin Li   vst1q_f32 (out_cos, sc.val[1]);
45*412f47f9SXin Li 
46*412f47f9SXin Li   if (unlikely (v_any_u32 (special)))
47*412f47f9SXin Li     special_case (x, special, out_sin, out_cos);
48*412f47f9SXin Li }
49*412f47f9SXin Li 
50*412f47f9SXin Li PL_TEST_ULP (_ZGVnN4v_sincosf_sin, 1.17)
51*412f47f9SXin Li PL_TEST_ULP (_ZGVnN4v_sincosf_cos, 1.31)
52*412f47f9SXin Li #define V_SINCOSF_INTERVAL(lo, hi, n)                                         \
53*412f47f9SXin Li   PL_TEST_INTERVAL (_ZGVnN4v_sincosf_sin, lo, hi, n)                          \
54*412f47f9SXin Li   PL_TEST_INTERVAL (_ZGVnN4v_sincosf_cos, lo, hi, n)
55*412f47f9SXin Li V_SINCOSF_INTERVAL (0, 0x1p20, 500000)
56*412f47f9SXin Li V_SINCOSF_INTERVAL (-0, -0x1p20, 500000)
57*412f47f9SXin Li V_SINCOSF_INTERVAL (0x1p20, inf, 10000)
58*412f47f9SXin Li V_SINCOSF_INTERVAL (-0x1p20, -inf, 10000)
59