xref: /freebsd/contrib/arm-optimized-routines/math/aarch64/sve/sincosf.c (revision f3087bef11543b42e0d69b708f367097a4118d24)
1 /*
2  * Single-precision vector sincos function.
3  *
4  * Copyright (c) 2023-2024, Arm Limited.
5  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6  */
7 
8 /* Define _GNU_SOURCE in order to include sincosf 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 
13 #include "sv_math.h"
14 #include "sv_sincosf_common.h"
15 #include "test_defs.h"
16 
17 #include <math.h>
18 
19 /* sincos not available for all scalar libm implementations.  */
20 #ifndef __GLIBC__
21 static void
sincosf(float x,float * out_sin,float * out_cos)22 sincosf (float x, float *out_sin, float *out_cos)
23 {
24   *out_sin = sinf (x);
25   *out_cos = cosf (x);
26 }
27 #endif
28 
29 static void NOINLINE
special_case(svfloat32_t x,svbool_t special,float * out_sin,float * out_cos)30 special_case (svfloat32_t x, svbool_t special, float *out_sin, float *out_cos)
31 {
32   svbool_t p = svptrue_pat_b32 (SV_VL1);
33   for (int i = 0; i < svcntw (); i++)
34     {
35       if (svptest_any (special, p))
36 	sincosf (svlastb (p, x), out_sin + i, out_cos + i);
37       p = svpnext_b32 (svptrue_b32 (), p);
38     }
39 }
40 
41 /* Single-precision vector function allowing calculation of both sin and cos in
42    one function call, using shared argument reduction and separate low-order
43    polynomials.
44    Worst-case error for sin is 1.67 ULP:
45    sv_sincosf_sin(0x1.c704c4p+19) got 0x1.fff698p-5 want 0x1.fff69cp-5
46    Worst-case error for cos is 1.81 ULP:
47    sv_sincosf_cos(0x1.e506fp+19) got -0x1.ffec6ep-6 want -0x1.ffec72p-6.  */
48 void
_ZGVsMxvl4l4_sincosf(svfloat32_t x,float * out_sin,float * out_cos,svbool_t pg)49 _ZGVsMxvl4l4_sincosf (svfloat32_t x, float *out_sin, float *out_cos,
50 		      svbool_t pg)
51 {
52   const struct sv_sincosf_data *d = ptr_barrier (&sv_sincosf_data);
53   svbool_t special = check_ge_rangeval (pg, x, d);
54 
55   svfloat32x2_t sc = sv_sincosf_inline (pg, x, d);
56 
57   svst1_f32 (pg, out_sin, svget2 (sc, 0));
58   svst1_f32 (pg, out_cos, svget2 (sc, 1));
59 
60   if (unlikely (svptest_any (pg, special)))
61     special_case (x, special, out_sin, out_cos);
62 }
63 
64 TEST_DISABLE_FENV (_ZGVsMxv_sincosf_sin)
65 TEST_DISABLE_FENV (_ZGVsMxv_sincosf_cos)
66 TEST_ULP (_ZGVsMxv_sincosf_sin, 1.17)
67 TEST_ULP (_ZGVsMxv_sincosf_cos, 1.31)
68 #define SV_SINCOSF_INTERVAL(lo, hi, n)                                        \
69   TEST_SYM_INTERVAL (_ZGVsMxv_sincosf_sin, lo, hi, n)                         \
70   TEST_SYM_INTERVAL (_ZGVsMxv_sincosf_cos, lo, hi, n)
71 SV_SINCOSF_INTERVAL (0, 0x1p-31, 50000)
72 SV_SINCOSF_INTERVAL (0x1p-31, 0x1p20, 500000)
73 SV_SINCOSF_INTERVAL (0x1p20, inf, 10000)
74 CLOSE_SVE_ATTR
75