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