xref: /freebsd/contrib/arm-optimized-routines/math/include/mathlib.h (revision dd21556857e8d40f66bf5ad54754d9d52669ebf7)
1 /*
2  * Public API.
3  *
4  * Copyright (c) 2015-2024, Arm Limited.
5  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6  */
7 
8 #ifndef _MATHLIB_H
9 #define _MATHLIB_H
10 
11 #if __aarch64__
12 /* Low-accuracy scalar implementations of C23 routines.  */
13 float arm_math_cospif (float);
14 double arm_math_cospi (double);
15 float arm_math_sinpif (float);
16 double arm_math_sinpi (double);
17 float arm_math_tanpif (float);
18 double arm_math_tanpi (double);
19 void arm_math_sincospif (float, float *, float *);
20 void arm_math_sincospi (double, double *, double *);
21 #endif
22 
23 /* SIMD declaration for autovectorisation with fast-math enabled. Only GCC is
24    supported, and vector routines are only supported on Linux on AArch64.  */
25 #if defined __aarch64__ && __linux__ && defined(__GNUC__)                     \
26     && !defined(__clang__) && defined(__FAST_MATH__)
27 #  define DECL_SIMD_aarch64 __attribute__ ((__simd__ ("notinbranch"), const))
28 #else
29 #  define DECL_SIMD_aarch64
30 #endif
31 
32 #if WANT_EXPERIMENTAL_MATH
33 
34 float arm_math_erff (float);
35 DECL_SIMD_aarch64 float cospif (float);
36 DECL_SIMD_aarch64 float erfinvf (float);
37 DECL_SIMD_aarch64 float sinpif (float);
38 DECL_SIMD_aarch64 float tanpif (float);
39 
40 double arm_math_erf (double);
41 DECL_SIMD_aarch64 double cospi (double);
42 DECL_SIMD_aarch64 double erfinv (double);
43 DECL_SIMD_aarch64 double sinpi (double);
44 DECL_SIMD_aarch64 double tanpi (double);
45 
46 long double erfinvl (long double);
47 
48 #endif
49 
50 /* Note these routines may not be provided by AOR (some are only available with
51    WANT_EXPERIMENTAL_MATH, some are not provided at all. Redeclare them here to
52    add vector annotations.  */
53 DECL_SIMD_aarch64 float acosf (float);
54 DECL_SIMD_aarch64 float acoshf (float);
55 DECL_SIMD_aarch64 float asinf (float);
56 DECL_SIMD_aarch64 float asinhf (float);
57 DECL_SIMD_aarch64 float atan2f (float, float);
58 DECL_SIMD_aarch64 float atanf (float);
59 DECL_SIMD_aarch64 float atanhf (float);
60 DECL_SIMD_aarch64 float cbrtf (float);
61 DECL_SIMD_aarch64 float cosf (float);
62 DECL_SIMD_aarch64 float coshf (float);
63 DECL_SIMD_aarch64 float erfcf (float);
64 DECL_SIMD_aarch64 float erff (float);
65 DECL_SIMD_aarch64 float exp10f (float);
66 DECL_SIMD_aarch64 float exp2f (float);
67 DECL_SIMD_aarch64 float expf (float);
68 DECL_SIMD_aarch64 float expm1f (float);
69 DECL_SIMD_aarch64 float hypotf (float, float);
70 DECL_SIMD_aarch64 float log10f (float);
71 DECL_SIMD_aarch64 float log1pf (float);
72 DECL_SIMD_aarch64 float log2f (float);
73 DECL_SIMD_aarch64 float logf (float);
74 DECL_SIMD_aarch64 float powf (float, float);
75 DECL_SIMD_aarch64 float sinf (float);
76 void sincosf (float, float *, float *);
77 DECL_SIMD_aarch64 float sinhf (float);
78 DECL_SIMD_aarch64 float tanf (float);
79 DECL_SIMD_aarch64 float tanhf (float);
80 
81 DECL_SIMD_aarch64 double acos (double);
82 DECL_SIMD_aarch64 double acosh (double);
83 DECL_SIMD_aarch64 double asin (double);
84 DECL_SIMD_aarch64 double asinh (double);
85 DECL_SIMD_aarch64 double atan2 (double, double);
86 DECL_SIMD_aarch64 double atan (double);
87 DECL_SIMD_aarch64 double atanh (double);
88 DECL_SIMD_aarch64 double cbrt (double);
89 DECL_SIMD_aarch64 double cos (double);
90 DECL_SIMD_aarch64 double cosh (double);
91 DECL_SIMD_aarch64 double erfc (double);
92 DECL_SIMD_aarch64 double erf (double);
93 DECL_SIMD_aarch64 double exp10 (double);
94 DECL_SIMD_aarch64 double exp2 (double);
95 DECL_SIMD_aarch64 double exp (double);
96 DECL_SIMD_aarch64 double expm1 (double);
97 DECL_SIMD_aarch64 double hypot (double, double);
98 DECL_SIMD_aarch64 double log10 (double);
99 DECL_SIMD_aarch64 double log1p (double);
100 DECL_SIMD_aarch64 double log2 (double);
101 DECL_SIMD_aarch64 double log (double);
102 DECL_SIMD_aarch64 double pow (double, double);
103 DECL_SIMD_aarch64 double sin (double);
104 DECL_SIMD_aarch64 double sinh (double);
105 DECL_SIMD_aarch64 double tan (double);
106 DECL_SIMD_aarch64 double tanh (double);
107 
108 #if __aarch64__ && __linux__
109 # include <arm_neon.h>
110 # undef __vpcs
111 # define __vpcs __attribute__((__aarch64_vector_pcs__))
112 
113 /* Vector functions following the vector PCS using ABI names.  */
114 __vpcs float32x4_t _ZGVnN4v_acosf (float32x4_t);
115 __vpcs float32x4_t _ZGVnN4v_acoshf (float32x4_t);
116 __vpcs float32x4_t _ZGVnN4v_asinf (float32x4_t);
117 __vpcs float32x4_t _ZGVnN4v_asinhf (float32x4_t);
118 __vpcs float32x4_t _ZGVnN4v_atanf (float32x4_t);
119 __vpcs float32x4_t _ZGVnN4v_atanhf (float32x4_t);
120 __vpcs float32x4_t _ZGVnN4v_cbrtf (float32x4_t);
121 __vpcs float32x4_t _ZGVnN4v_cosf (float32x4_t);
122 __vpcs float32x4_t _ZGVnN4v_coshf (float32x4_t);
123 __vpcs float32x4_t _ZGVnN4v_cospif (float32x4_t);
124 __vpcs float32x4_t _ZGVnN4v_erfcf (float32x4_t);
125 __vpcs float32x4_t _ZGVnN4v_erff (float32x4_t);
126 __vpcs float32x4_t _ZGVnN4v_exp10f (float32x4_t);
127 __vpcs float32x4_t _ZGVnN4v_exp2f (float32x4_t);
128 __vpcs float32x4_t _ZGVnN4v_exp2f_1u (float32x4_t);
129 __vpcs float32x4_t _ZGVnN4v_expf (float32x4_t);
130 __vpcs float32x4_t _ZGVnN4v_expf_1u (float32x4_t);
131 __vpcs float32x4_t _ZGVnN4v_expm1f (float32x4_t);
132 __vpcs float32x4_t _ZGVnN4v_log10f (float32x4_t);
133 __vpcs float32x4_t _ZGVnN4v_log1pf (float32x4_t);
134 __vpcs float32x4_t _ZGVnN4v_log2f (float32x4_t);
135 __vpcs float32x4_t _ZGVnN4v_logf (float32x4_t);
136 __vpcs float32x4_t _ZGVnN4v_sinf (float32x4_t);
137 __vpcs float32x4_t _ZGVnN4v_sinhf (float32x4_t);
138 __vpcs float32x4_t _ZGVnN4v_sinpif (float32x4_t);
139 __vpcs float32x4_t _ZGVnN4v_tanf (float32x4_t);
140 __vpcs float32x4_t _ZGVnN4v_tanhf (float32x4_t);
141 __vpcs float32x4_t _ZGVnN4v_tanpif (float32x4_t);
142 __vpcs float32x4_t _ZGVnN4vl4_modff (float32x4_t, float *);
143 __vpcs float32x4_t _ZGVnN4vv_atan2f (float32x4_t, float32x4_t);
144 __vpcs float32x4_t _ZGVnN4vv_hypotf (float32x4_t, float32x4_t);
145 __vpcs float32x4_t _ZGVnN4vv_powf (float32x4_t, float32x4_t);
146 __vpcs float32x4x2_t _ZGVnN4v_cexpif (float32x4_t);
147 __vpcs void _ZGVnN4vl4l4_sincosf (float32x4_t, float *, float *);
148 __vpcs void _ZGVnN4vl4l4_sincospif (float32x4_t, float *, float *);
149 
150 __vpcs float64x2_t _ZGVnN2v_acos (float64x2_t);
151 __vpcs float64x2_t _ZGVnN2v_acosh (float64x2_t);
152 __vpcs float64x2_t _ZGVnN2v_asin (float64x2_t);
153 __vpcs float64x2_t _ZGVnN2v_asinh (float64x2_t);
154 __vpcs float64x2_t _ZGVnN2v_atan (float64x2_t);
155 __vpcs float64x2_t _ZGVnN2v_atanh (float64x2_t);
156 __vpcs float64x2_t _ZGVnN2v_cbrt (float64x2_t);
157 __vpcs float64x2_t _ZGVnN2v_cos (float64x2_t);
158 __vpcs float64x2_t _ZGVnN2v_cosh (float64x2_t);
159 __vpcs float64x2_t _ZGVnN2v_cospi (float64x2_t);
160 __vpcs float64x2_t _ZGVnN2v_erf (float64x2_t);
161 __vpcs float64x2_t _ZGVnN2v_erfc (float64x2_t);
162 __vpcs float64x2_t _ZGVnN2v_exp (float64x2_t);
163 __vpcs float64x2_t _ZGVnN2v_exp10 (float64x2_t);
164 __vpcs float64x2_t _ZGVnN2v_exp2 (float64x2_t);
165 __vpcs float64x2_t _ZGVnN2v_expm1 (float64x2_t);
166 __vpcs float64x2_t _ZGVnN2v_log (float64x2_t);
167 __vpcs float64x2_t _ZGVnN2v_log10 (float64x2_t);
168 __vpcs float64x2_t _ZGVnN2v_log1p (float64x2_t);
169 __vpcs float64x2_t _ZGVnN2v_log2 (float64x2_t);
170 __vpcs float64x2_t _ZGVnN2v_sin (float64x2_t);
171 __vpcs float64x2_t _ZGVnN2v_sinh (float64x2_t);
172 __vpcs float64x2_t _ZGVnN2v_sinpi (float64x2_t);
173 __vpcs float64x2_t _ZGVnN2v_tan (float64x2_t);
174 __vpcs float64x2_t _ZGVnN2v_tanh (float64x2_t);
175 __vpcs float64x2_t _ZGVnN2v_tanpi (float64x2_t);
176 __vpcs float64x2_t _ZGVnN2vl8_modf (float64x2_t, double *);
177 __vpcs float64x2_t _ZGVnN2vv_atan2 (float64x2_t, float64x2_t);
178 __vpcs float64x2_t _ZGVnN2vv_hypot (float64x2_t, float64x2_t);
179 __vpcs float64x2_t _ZGVnN2vv_pow (float64x2_t, float64x2_t);
180 __vpcs float64x2x2_t _ZGVnN2v_cexpi (float64x2_t);
181 __vpcs void _ZGVnN2vl8l8_sincos (float64x2_t, double *, double *);
182 __vpcs void _ZGVnN2vl8l8_sincospi (float64x2_t, double *, double *);
183 
184 # if WANT_EXPERIMENTAL_MATH
185 __vpcs float32x4_t _ZGVnN4v_erfinvf (float32x4_t);
186 __vpcs float64x2_t _ZGVnN2v_erfinv (float64x2_t);
187 # endif
188 
189 #  include <arm_sve.h>
190 svfloat32_t _ZGVsMxv_acosf (svfloat32_t, svbool_t);
191 svfloat32_t _ZGVsMxv_acoshf (svfloat32_t, svbool_t);
192 svfloat32_t _ZGVsMxv_asinf (svfloat32_t, svbool_t);
193 svfloat32_t _ZGVsMxv_asinhf (svfloat32_t, svbool_t);
194 svfloat32_t _ZGVsMxv_atanf (svfloat32_t, svbool_t);
195 svfloat32_t _ZGVsMxv_atanhf (svfloat32_t, svbool_t);
196 svfloat32_t _ZGVsMxv_cbrtf (svfloat32_t, svbool_t);
197 svfloat32_t _ZGVsMxv_cosf (svfloat32_t, svbool_t);
198 svfloat32_t _ZGVsMxv_coshf (svfloat32_t, svbool_t);
199 svfloat32_t _ZGVsMxv_cospif (svfloat32_t, svbool_t);
200 svfloat32_t _ZGVsMxv_erfcf (svfloat32_t, svbool_t);
201 svfloat32_t _ZGVsMxv_erff (svfloat32_t, svbool_t);
202 svfloat32_t _ZGVsMxv_exp10f (svfloat32_t, svbool_t);
203 svfloat32_t _ZGVsMxv_exp2f (svfloat32_t, svbool_t);
204 svfloat32_t _ZGVsMxv_expf (svfloat32_t, svbool_t);
205 svfloat32_t _ZGVsMxv_expm1f (svfloat32_t, svbool_t);
206 svfloat32_t _ZGVsMxv_log10f (svfloat32_t, svbool_t);
207 svfloat32_t _ZGVsMxv_log1pf (svfloat32_t, svbool_t);
208 svfloat32_t _ZGVsMxv_log2f (svfloat32_t, svbool_t);
209 svfloat32_t _ZGVsMxv_logf (svfloat32_t, svbool_t);
210 svfloat32_t _ZGVsMxv_sinf (svfloat32_t, svbool_t);
211 svfloat32_t _ZGVsMxv_sinhf (svfloat32_t, svbool_t);
212 svfloat32_t _ZGVsMxv_sinpif (svfloat32_t, svbool_t);
213 svfloat32_t _ZGVsMxv_tanf (svfloat32_t, svbool_t);
214 svfloat32_t _ZGVsMxv_tanhf (svfloat32_t, svbool_t);
215 svfloat32_t _ZGVsMxv_tanpif (svfloat32_t, svbool_t);
216 svfloat32_t _ZGVsMxvl4_modff (svfloat32_t, float *, svbool_t);
217 svfloat32_t _ZGVsMxvv_atan2f (svfloat32_t, svfloat32_t, svbool_t);
218 svfloat32_t _ZGVsMxvv_hypotf (svfloat32_t, svfloat32_t, svbool_t);
219 svfloat32_t _ZGVsMxvv_powf (svfloat32_t, svfloat32_t, svbool_t);
220 svfloat32x2_t _ZGVsMxv_cexpif (svfloat32_t, svbool_t);
221 void _ZGVsMxvl4l4_sincosf (svfloat32_t, float *, float *, svbool_t);
222 void _ZGVsMxvl4l4_sincospif (svfloat32_t, float *, float *, svbool_t);
223 
224 svfloat64_t _ZGVsMxv_acos (svfloat64_t, svbool_t);
225 svfloat64_t _ZGVsMxv_acosh (svfloat64_t, svbool_t);
226 svfloat64_t _ZGVsMxv_asin (svfloat64_t, svbool_t);
227 svfloat64_t _ZGVsMxv_asinh (svfloat64_t, svbool_t);
228 svfloat64_t _ZGVsMxv_atan (svfloat64_t, svbool_t);
229 svfloat64_t _ZGVsMxv_atanh (svfloat64_t, svbool_t);
230 svfloat64_t _ZGVsMxv_cbrt (svfloat64_t, svbool_t);
231 svfloat64_t _ZGVsMxv_cos (svfloat64_t, svbool_t);
232 svfloat64_t _ZGVsMxv_cosh (svfloat64_t, svbool_t);
233 svfloat64_t _ZGVsMxv_cospi (svfloat64_t, svbool_t);
234 svfloat64_t _ZGVsMxv_erf (svfloat64_t, svbool_t);
235 svfloat64_t _ZGVsMxv_erfc (svfloat64_t, svbool_t);
236 svfloat64_t _ZGVsMxv_exp (svfloat64_t, svbool_t);
237 svfloat64_t _ZGVsMxv_exp10 (svfloat64_t, svbool_t);
238 svfloat64_t _ZGVsMxv_exp2 (svfloat64_t, svbool_t);
239 svfloat64_t _ZGVsMxv_expm1 (svfloat64_t, svbool_t);
240 svfloat64_t _ZGVsMxv_log (svfloat64_t, svbool_t);
241 svfloat64_t _ZGVsMxv_log10 (svfloat64_t, svbool_t);
242 svfloat64_t _ZGVsMxv_log1p (svfloat64_t, svbool_t);
243 svfloat64_t _ZGVsMxv_log2 (svfloat64_t, svbool_t);
244 svfloat64_t _ZGVsMxv_sin (svfloat64_t, svbool_t);
245 svfloat64_t _ZGVsMxv_sinh (svfloat64_t, svbool_t);
246 svfloat64_t _ZGVsMxv_sinpi (svfloat64_t, svbool_t);
247 svfloat64_t _ZGVsMxv_tan (svfloat64_t, svbool_t);
248 svfloat64_t _ZGVsMxv_tanh (svfloat64_t, svbool_t);
249 svfloat64_t _ZGVsMxv_tanpi (svfloat64_t, svbool_t);
250 svfloat64_t _ZGVsMxvl8_modf (svfloat64_t, double *, svbool_t);
251 svfloat64_t _ZGVsMxvv_atan2 (svfloat64_t, svfloat64_t, svbool_t);
252 svfloat64_t _ZGVsMxvv_hypot (svfloat64_t, svfloat64_t, svbool_t);
253 svfloat64_t _ZGVsMxvv_pow (svfloat64_t, svfloat64_t, svbool_t);
254 svfloat64x2_t _ZGVsMxv_cexpi (svfloat64_t, svbool_t);
255 void _ZGVsMxvl8l8_sincos (svfloat64_t, double *, double *, svbool_t);
256 void _ZGVsMxvl8l8_sincospi (svfloat64_t, double *, double *, svbool_t);
257 
258 #  if WANT_EXPERIMENTAL_MATH
259 
260 svfloat32_t _ZGVsMxv_erfinvf (svfloat32_t, svbool_t);
261 svfloat32_t _ZGVsMxvv_powi (svfloat32_t, svint32_t, svbool_t);
262 
263 svfloat64_t _ZGVsMxvv_powk (svfloat64_t, svint64_t, svbool_t);
264 svfloat64_t _ZGVsMxv_erfinv (svfloat64_t, svbool_t);
265 
266 # endif
267 #endif
268 
269 #endif
270