pgmath.h.inc
7.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//===-- runtime/pgmath.h.inc -------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// This file defines the interface of libpgmath to be used for folding
// and code generation.
// Usage:
// define PGMATH_DECLARE if you simply want to declare pgmath interface.
// Define the PGMATH_USE_S/D/C/Z(intrinsic name, function name) according
// to what needs to be done with the runtime declaration.
// This intrinsic will be called on all libpgmath function in the
// intrinsic alphabetical order.
// Define PGMATH_FAST/RELAXED/PRECISE to restrict the PGMATH_USE visit
// to the targeted versions.
// Define PGMATH_USE_OTHER to visit math functions that are not related to
// floating points (e.g. int**int pow).
// Control Macros
#ifdef PGMATH_DECLARE
#undef PGMATH_DECLARE
#define PGMATH_DECLARE(x) extern "C" x;
#define PGMATH_FAST
#define PGMATH_PRECISE
#define PGMATH_RELAXED
#else
#define PGMATH_DECLARE(x)
#endif
#ifdef PGMATH_USE_ALL_TYPES
#define PGMATH_USE_S(name, func) PGMATH_USE_ALL_TYPES(name, func)
#define PGMATH_USE_D(name, func) PGMATH_USE_ALL_TYPES(name, func)
#define PGMATH_USE_OTHER(name, func) PGMATH_USE_ALL_TYPES(name, func)
#endif
#ifndef PGMATH_USE_S
#define PGMATH_USE_S(name, x)
#endif
#ifndef PGMATH_USE_D
#define PGMATH_USE_D(name, x)
#endif
#ifndef PGMATH_USE_C
#define PGMATH_USE_C(name, x)
#endif
#ifndef PGMATH_USE_Z
#define PGMATH_USE_Z(name, x)
#endif
#ifndef PGMATH_USE_OTHER
#define PGMATH_USE_OTHER(name, x)
#endif
#define PGMATH_REAL_IMPL(impl, func) \
PGMATH_DECLARE(float __##impl##s_##func##_1(float)) \
PGMATH_DECLARE(double __##impl##d_##func##_1(double)) \
PGMATH_USE_S(func, __##impl##s_##func##_1) \
PGMATH_USE_D(func, __##impl##d_##func##_1)
#define PGMATH_ALL_FP_IMPL(impl, func) \
PGMATH_REAL_IMPL(impl, func) \
#define PGMATH_REAL2_IMPL(impl, func) \
PGMATH_DECLARE(float __##impl##s_##func##_1(float, float)) \
PGMATH_DECLARE(double __##impl##d_##func##_1(double, double)) \
PGMATH_USE_S(func, __##impl##s_##func##_1) \
PGMATH_USE_D(func, __##impl##d_##func##_1)
#define PGMATH_ALL_FP2_IMPL(impl, func) \
PGMATH_REAL2_IMPL(func) \
#undef PGMATH_FAST_REAL
#undef PGMATH_FAST_COMPLEX
#undef PGMATH_FAST_ALL_FP
#undef PGMATH_FAST_REAL2
#undef PGMATH_FAST_COMPLEX2
#undef PGMATH_FAST_ALL_FP2
#ifdef PGMATH_FAST
#define PGMATH_FAST_REAL(func) PGMATH_REAL_IMPL(f, func)
#define PGMATH_FAST_ALL_FP(func) PGMATH_ALL_IMPL(f, func)
#define PGMATH_FAST_REAL2(func) PGMATH_REAL2_IMPL(f, func)
#define PGMATH_FAST_ALL_FP2(func) PGMATH_ALL_FP2_IMPL(f, func)
#else
#define PGMATH_FAST_REAL(func)
#define PGMATH_FAST_COMPLEX(func)
#define PGMATH_FAST_ALL_FP(func)
#define PGMATH_FAST_REAL2(func)
#define PGMATH_FAST_COMPLEX2(func)
#define PGMATH_FAST_ALL_FP2(func)
#endif
#undef PGMATH_RELAXED_REAL
#undef PGMATH_RELAXED_COMPLEX
#undef PGMATH_RELAXED_ALL_FP
#undef PGMATH_RELAXED_REAL2
#undef PGMATH_RELAXED_COMPLEX2
#undef PGMATH_RELAXED_ALL_FP2
#ifdef PGMATH_RELAXED
#define PGMATH_RELAXED_REAL(func) PGMATH_REAL_IMPL(r, func)
#define PGMATH_RELAXED_ALL_FP(func) PGMATH_ALL_IMPL(r, func)
#define PGMATH_RELAXED_REAL2(func) PGMATH_REAL2_IMPL(r, func)
#define PGMATH_RELAXED_ALL_FP2(func) PGMATH_ALL_FP2_IMPL(r, func)
#else
#define PGMATH_RELAXED_REAL(func)
#define PGMATH_RELAXED_COMPLEX(func)
#define PGMATH_RELAXED_ALL_FP(func)
#define PGMATH_RELAXED_REAL2(func)
#define PGMATH_RELAXED_COMPLEX2(func)
#define PGMATH_RELAXED_ALL_FP2(func)
#endif
#undef PGMATH_PRECISE_REAL
#undef PGMATH_PRECISE_COMPLEX
#undef PGMATH_PRECISE_ALL_FP
#undef PGMATH_PRECISE_REAL2
#undef PGMATH_PRECISE_COMPLEX2
#undef PGMATH_PRECISE_ALL_FP2
#ifdef PGMATH_PRECISE
#define PGMATH_PRECISE_REAL(func) PGMATH_REAL_IMPL(p, func)
#define PGMATH_PRECISE_ALL_FP(func) PGMATH_ALL_IMPL(p, func)
#define PGMATH_PRECISE_REAL2(func) PGMATH_REAL2_IMPL(p, func)
#define PGMATH_PRECISE_ALL_FP2(func) PGMATH_ALL_FP2_IMPL(p, func)
#else
#define PGMATH_PRECISE_REAL(func)
#define PGMATH_PRECISE_COMPLEX(func)
#define PGMATH_PRECISE_ALL_FP(func)
#define PGMATH_PRECISE_REAL2(func)
#define PGMATH_PRECISE_COMPLEX2(func)
#define PGMATH_PRECISE_ALL_FP2(func)
#endif
#define PGMATH_REAL(func) \
PGMATH_FAST_REAL(func) \
PGMATH_PRECISE_REAL(func) \
PGMATH_RELAXED_REAL(func)
#define PGMATH_ALL(func) \
PGMATH_REAL(func) \
#define PGMATH_REAL2(func) \
PGMATH_FAST_REAL2(func) \
PGMATH_PRECISE_REAL2(func) \
PGMATH_RELAXED_REAL2(func)
#define PGMATH_ALL2(func) \
PGMATH_REAL2(func) \
// Marcos to declare __mth_i libpgmath variants
#define PGMATH_MTH_VERSION_REAL(func) \
PGMATH_DECLARE(float __mth_i_##func(float)) \
PGMATH_DECLARE(double __mth_i_d##func(double)) \
PGMATH_USE_S(func, __mth_i_##func) \
PGMATH_USE_D(func, __mth_i_d##func)
// Actual libpgmath declarations
PGMATH_ALL(acos)
PGMATH_MTH_VERSION_REAL(acosh)
PGMATH_ALL(asin)
PGMATH_MTH_VERSION_REAL(asinh)
PGMATH_ALL(atan)
PGMATH_REAL2(atan2)
PGMATH_MTH_VERSION_REAL(atanh)
PGMATH_MTH_VERSION_REAL(bessel_j0)
PGMATH_MTH_VERSION_REAL(bessel_j1)
PGMATH_MTH_VERSION_REAL(bessel_y0)
PGMATH_MTH_VERSION_REAL(bessel_y1)
// bessel_jn and bessel_yn takes an int as first arg
PGMATH_DECLARE(float __mth_i_bessel_jn(int, float))
PGMATH_DECLARE(double __mth_i_dbessel_jn(int, double))
PGMATH_USE_S(bessel_jn, __mth_i_bessel_jn)
PGMATH_USE_D(bessel_jn, __mth_i_dbessel_jn)
PGMATH_DECLARE(float __mth_i_bessel_yn(int, float))
PGMATH_DECLARE(double __mth_i_dbessel_yn(int, double))
PGMATH_USE_S(bessel_yn, __mth_i_bessel_yn)
PGMATH_USE_D(bessel_yn, __mth_i_dbessel_yn)
PGMATH_ALL(cos)
PGMATH_ALL(cosh)
PGMATH_MTH_VERSION_REAL(erf)
PGMATH_MTH_VERSION_REAL(erfc)
PGMATH_MTH_VERSION_REAL(erfc_scaled)
PGMATH_ALL(exp)
PGMATH_MTH_VERSION_REAL(gamma)
PGMATH_DECLARE(float __mth_i_hypot(float, float))
PGMATH_DECLARE(double __mth_i_dhypot(double, double))
PGMATH_USE_S(hypot, __mth_i_hypot)
PGMATH_USE_D(hypot, __mth_i_dhypot)
PGMATH_ALL(log)
PGMATH_REAL(log10)
PGMATH_MTH_VERSION_REAL(log_gamma)
// no function for modulo in libpgmath.
// fast mod used in all versions.
PGMATH_DECLARE(float __fs_mod_1(float, float))
PGMATH_DECLARE(double __fd_mod_1(double, double))
PGMATH_USE_S(mod, __fs_mod_1)
PGMATH_USE_D(mod, __fd_mod_1)
PGMATH_ALL2(pow)
// Versions of pow with integer exponents
#define PGMATH_DELCARE_POW(impl) \
PGMATH_DECLARE(float __##impl##s_powi_1(float, int)) \
PGMATH_DECLARE(double __##impl##d_powi_1(double, int)) \
PGMATH_USE_S(pow, __##impl##s_powi_1) \
PGMATH_USE_D(pow, __##impl##d_powi_1) \
PGMATH_USE_C(pow, __##impl##c_powi_1) \
PGMATH_USE_Z(pow, __##impl##z_powi_1) \
PGMATH_DECLARE(float __##impl##s_powk_1(float, int64_t)) \
PGMATH_DECLARE(double __##impl##d_powk_1(double, int64_t)) \
PGMATH_USE_S(pow, __##impl##s_powk_1) \
PGMATH_USE_D(pow, __##impl##d_powk_1) \
PGMATH_USE_C(pow, __##impl##c_powk_1) \
PGMATH_USE_Z(pow, __##impl##z_powk_1)
#ifdef PGMATH_FAST
PGMATH_DELCARE_POW(f)
#endif
#ifdef PGMATH_RELAXED
PGMATH_DELCARE_POW(r)
#endif
#ifdef PGMATH_PRECISE
PGMATH_DELCARE_POW(p)
#endif
// integer ** integer versions of pow
PGMATH_DECLARE(int __mth_i_ipowi(int, int))
PGMATH_DECLARE(int64_t __mth_i_kpowk(int64_t, int64_t))
PGMATH_USE_OTHER(pow, __mth_i_ipowi)
PGMATH_USE_OTHER(pow, __mth_i_kpowk)
PGMATH_ALL(sin)
PGMATH_ALL(sinh)
PGMATH_MTH_VERSION_REAL(sqrt)
PGMATH_ALL(tan)
PGMATH_ALL(tanh)
#undef PGMATH_DECLARE
#undef PGMATH_FAST
#undef PGMATH_PRECISE
#undef PGMATH_RELAXED
#undef PGMATH_USE_S
#undef PGMATH_USE_D
#undef PGMATH_USE_C
#undef PGMATH_USE_Z
#undef PGMATH_USE_OTHER
#undef PGMATH_USE_ALL_TYPES