xref: /freebsd/contrib/arm-optimized-routines/pl/math/v_sincos_3u5.c (revision a91a246563dffa876a52f53a98de4af9fa364c52)
1 /*
2  * Double-precision vector sincos function.
3  *
4  * Copyright (c) 2023, Arm Limited.
5  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6  */
7 
8 /* Define _GNU_SOURCE in order to include sincos declaration. If building
9    pre-GLIBC 2.1, or on a non-GNU conforming system, this routine will need to
10    be linked against the scalar sincosf from math/.  */
11 #define _GNU_SOURCE
12 #include <math.h>
13 #undef _GNU_SOURCE
14 
15 #include "v_math.h"
16 #include "pl_test.h"
17 #include "v_sincos_common.h"
18 
19 static void VPCS_ATTR NOINLINE
20 special_case (float64x2_t x, uint64x2_t special, double *out_sin,
21 	      double *out_cos)
22 {
23   if (special[0])
24     sincos (x[0], out_sin, out_cos);
25   if (special[1])
26     sincos (x[1], out_sin + 1, out_cos + 1);
27 }
28 
29 /* Double-precision vector function allowing calculation of both sin and cos in
30    one function call, using shared argument reduction and separate polynomials.
31    Largest observed error is for sin, 3.22 ULP:
32    v_sincos_sin (0x1.d70eef40f39b1p+12) got -0x1.ffe9537d5dbb7p-3
33 				       want -0x1.ffe9537d5dbb4p-3.  */
34 VPCS_ATTR void
35 _ZGVnN2vl8l8_sincos (float64x2_t x, double *out_sin, double *out_cos)
36 {
37   const struct v_sincos_data *d = ptr_barrier (&v_sincos_data);
38   uint64x2_t special = check_ge_rangeval (x, d);
39 
40   float64x2x2_t sc = v_sincos_inline (x, d);
41 
42   vst1q_f64 (out_sin, sc.val[0]);
43   vst1q_f64 (out_cos, sc.val[1]);
44 
45   if (unlikely (v_any_u64 (special)))
46     special_case (x, special, out_sin, out_cos);
47 }
48 
49 PL_TEST_ULP (_ZGVnN2v_sincos_sin, 2.73)
50 PL_TEST_ULP (_ZGVnN2v_sincos_cos, 2.73)
51 #define V_SINCOS_INTERVAL(lo, hi, n)                                          \
52   PL_TEST_INTERVAL (_ZGVnN2v_sincos_sin, lo, hi, n)                           \
53   PL_TEST_INTERVAL (_ZGVnN2v_sincos_cos, lo, hi, n)
54 V_SINCOS_INTERVAL (0, 0x1p23, 500000)
55 V_SINCOS_INTERVAL (-0, -0x1p23, 500000)
56 V_SINCOS_INTERVAL (0x1p23, inf, 10000)
57 V_SINCOS_INTERVAL (-0x1p23, -inf, 10000)
58