Debian Codegraph @

clang/lib/Headers/__clang_hip_cmath.h

raw
1 /*===---- __clang_hip_cmath.h - HIP cmath decls -----------------------------===
2 *
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 *
7 *===-----------------------------------------------------------------------===
8 */
9
10 #ifndef __CLANG_HIP_CMATH_H__
11 #define __CLANG_HIP_CMATH_H__
12
13 #if !defined(__HIP__) && !defined(__OPENMP_AMDGCN__)
14 #error "This file is for HIP and OpenMP AMDGCN device compilation only."
15 #endif
16
17 #if !defined(__HIPCC_RTC__)
18 #if defined(__cplusplus)
19 #include <limits>
20 #include <type_traits>
21 #include <utility>
22 #endif
23 #include <limits.h>
24 #include <stdint.h>
25 #endif // !defined(__HIPCC_RTC__)
26
27 #pragma push_macro("__DEVICE__")
28 #pragma push_macro("__CONSTEXPR__")
29 #ifdef __OPENMP_AMDGCN__
30 #define __DEVICE__ static __attribute__((always_inline, nothrow))
31 #define __CONSTEXPR__ constexpr
32 #else
33 #define __DEVICE__ static __device__ inline __attribute__((always_inline))
34 #define __CONSTEXPR__
35 #endif // __OPENMP_AMDGCN__
36
37 // Start with functions that cannot be defined by DEF macros below.
38 #if defined(__cplusplus)
39 #if defined __OPENMP_AMDGCN__
40 __DEVICE__ __CONSTEXPR__ float fabs(float __x) { return ::fabsf(__x); }
41 __DEVICE__ __CONSTEXPR__ float sin(float __x) { return ::sinf(__x); }
42 __DEVICE__ __CONSTEXPR__ float cos(float __x) { return ::cosf(__x); }
43 #endif
44 __DEVICE__ __CONSTEXPR__ double abs(double __x) { return ::fabs(__x); }
45 __DEVICE__ __CONSTEXPR__ float abs(float __x) { return ::fabsf(__x); }
46 __DEVICE__ __CONSTEXPR__ long long abs(long long __n) { return ::llabs(__n); }
47 __DEVICE__ __CONSTEXPR__ long abs(long __n) { return ::labs(__n); }
48 __DEVICE__ __CONSTEXPR__ float fma(float __x, float __y, float __z) {
49 return ::fmaf(__x, __y, __z);
50 }
51 #if !defined(__HIPCC_RTC__)
52 // The value returned by fpclassify is platform dependent, therefore it is not
53 // supported by hipRTC.
54 __DEVICE__ __CONSTEXPR__ int fpclassify(float __x) {
55 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL,
56 FP_ZERO, __x);
57 }
58 __DEVICE__ __CONSTEXPR__ int fpclassify(double __x) {
59 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL,
60 FP_ZERO, __x);
61 }
62 #endif // !defined(__HIPCC_RTC__)
63
64 __DEVICE__ __CONSTEXPR__ float frexp(float __arg, int *__exp) {
65 return ::frexpf(__arg, __exp);
66 }
67
68 #if defined(__OPENMP_AMDGCN__)
69 // For OpenMP we work around some old system headers that have non-conforming
70 // `isinf(float)` and `isnan(float)` implementations that return an `int`. We do
71 // this by providing two versions of these functions, differing only in the
72 // return type. To avoid conflicting definitions we disable implicit base
73 // function generation. That means we will end up with two specializations, one
74 // per type, but only one has a base function defined by the system header.
75 #pragma omp begin declare variant match( \
76 implementation = {extension(disable_implicit_base)})
77
78 // FIXME: We lack an extension to customize the mangling of the variants, e.g.,
79 // add a suffix. This means we would clash with the names of the variants
80 // (note that we do not create implicit base functions here). To avoid
81 // this clash we add a new trait to some of them that is always true
82 // (this is LLVM after all ;)). It will only influence the mangled name
83 // of the variants inside the inner region and avoid the clash.
84 #pragma omp begin declare variant match(implementation = {vendor(llvm)})
85
86 __DEVICE__ __CONSTEXPR__ int isinf(float __x) { return ::__isinff(__x); }
87 __DEVICE__ __CONSTEXPR__ int isinf(double __x) { return ::__isinf(__x); }
88 __DEVICE__ __CONSTEXPR__ int isfinite(float __x) { return ::__finitef(__x); }
89 __DEVICE__ __CONSTEXPR__ int isfinite(double __x) { return ::__finite(__x); }
90 __DEVICE__ __CONSTEXPR__ int isnan(float __x) { return ::__isnanf(__x); }
91 __DEVICE__ __CONSTEXPR__ int isnan(double __x) { return ::__isnan(__x); }
92
93 #pragma omp end declare variant
94 #endif // defined(__OPENMP_AMDGCN__)
95
96 __DEVICE__ __CONSTEXPR__ bool isinf(float __x) { return ::__isinff(__x); }
97 __DEVICE__ __CONSTEXPR__ bool isinf(double __x) { return ::__isinf(__x); }
98 __DEVICE__ __CONSTEXPR__ bool isfinite(float __x) { return ::__finitef(__x); }
99 __DEVICE__ __CONSTEXPR__ bool isfinite(double __x) { return ::__finite(__x); }
100 __DEVICE__ __CONSTEXPR__ bool isnan(float __x) { return ::__isnanf(__x); }
101 __DEVICE__ __CONSTEXPR__ bool isnan(double __x) { return ::__isnan(__x); }
102
103 #if defined(__OPENMP_AMDGCN__)
104 #pragma omp end declare variant
105 #endif // defined(__OPENMP_AMDGCN__)
106
107 __DEVICE__ __CONSTEXPR__ bool isgreater(float __x, float __y) {
108 return __builtin_isgreater(__x, __y);
109 }
110 __DEVICE__ __CONSTEXPR__ bool isgreater(double __x, double __y) {
111 return __builtin_isgreater(__x, __y);
112 }
113 __DEVICE__ __CONSTEXPR__ bool isgreaterequal(float __x, float __y) {
114 return __builtin_isgreaterequal(__x, __y);
115 }
116 __DEVICE__ __CONSTEXPR__ bool isgreaterequal(double __x, double __y) {
117 return __builtin_isgreaterequal(__x, __y);
118 }
119 __DEVICE__ __CONSTEXPR__ bool isless(float __x, float __y) {
120 return __builtin_isless(__x, __y);
121 }
122 __DEVICE__ __CONSTEXPR__ bool isless(double __x, double __y) {
123 return __builtin_isless(__x, __y);
124 }
125 __DEVICE__ __CONSTEXPR__ bool islessequal(float __x, float __y) {
126 return __builtin_islessequal(__x, __y);
127 }
128 __DEVICE__ __CONSTEXPR__ bool islessequal(double __x, double __y) {
129 return __builtin_islessequal(__x, __y);
130 }
131 __DEVICE__ __CONSTEXPR__ bool islessgreater(float __x, float __y) {
132 return __builtin_islessgreater(__x, __y);
133 }
134 __DEVICE__ __CONSTEXPR__ bool islessgreater(double __x, double __y) {
135 return __builtin_islessgreater(__x, __y);
136 }
137 __DEVICE__ __CONSTEXPR__ bool isnormal(float __x) {
138 return __builtin_isnormal(__x);
139 }
140 __DEVICE__ __CONSTEXPR__ bool isnormal(double __x) {
141 return __builtin_isnormal(__x);
142 }
143 __DEVICE__ __CONSTEXPR__ bool isunordered(float __x, float __y) {
144 return __builtin_isunordered(__x, __y);
145 }
146 __DEVICE__ __CONSTEXPR__ bool isunordered(double __x, double __y) {
147 return __builtin_isunordered(__x, __y);
148 }
149 __DEVICE__ __CONSTEXPR__ float modf(float __x, float *__iptr) {
150 return ::modff(__x, __iptr);
151 }
152 __DEVICE__ __CONSTEXPR__ float pow(float __base, int __iexp) {
153 return ::powif(__base, __iexp);
154 }
155 __DEVICE__ __CONSTEXPR__ double pow(double __base, int __iexp) {
156 return ::powi(__base, __iexp);
157 }
158 __DEVICE__ __CONSTEXPR__ float remquo(float __x, float __y, int *__quo) {
159 return ::remquof(__x, __y, __quo);
160 }
161 __DEVICE__ __CONSTEXPR__ float scalbln(float __x, long int __n) {
162 return ::scalblnf(__x, __n);
163 }
164 __DEVICE__ __CONSTEXPR__ bool signbit(float __x) { return ::__signbitf(__x); }
165 __DEVICE__ __CONSTEXPR__ bool signbit(double __x) { return ::__signbit(__x); }
166
167 // Notably missing above is nexttoward. We omit it because
168 // ocml doesn't provide an implementation, and we don't want to be in the
169 // business of implementing tricky libm functions in this header.
170
171 // Other functions.
172 __DEVICE__ __CONSTEXPR__ _Float16 fma(_Float16 __x, _Float16 __y,
173 _Float16 __z) {
174 return __builtin_fmaf16(__x, __y, __z);
175 }
176 __DEVICE__ __CONSTEXPR__ _Float16 pow(_Float16 __base, int __iexp) {
177 return __ocml_pown_f16(__base, __iexp);
178 }
179
180 #ifndef __OPENMP_AMDGCN__
181 // BEGIN DEF_FUN and HIP_OVERLOAD
182
183 // BEGIN DEF_FUN
184
185 #pragma push_macro("__DEF_FUN1")
186 #pragma push_macro("__DEF_FUN2")
187 #pragma push_macro("__DEF_FUN2_FI")
188
189 // Define cmath functions with float argument and returns __retty.
190 #define __DEF_FUN1(__retty, __func) \
191 __DEVICE__ __CONSTEXPR__ __retty __func(float __x) { return __func##f(__x); }
192
193 // Define cmath functions with two float arguments and returns __retty.
194 #define __DEF_FUN2(__retty, __func) \
195 __DEVICE__ __CONSTEXPR__ __retty __func(float __x, float __y) { \
196 return __func##f(__x, __y); \
197 }
198
199 // Define cmath functions with a float and an int argument and returns __retty.
200 #define __DEF_FUN2_FI(__retty, __func) \
201 __DEVICE__ __CONSTEXPR__ __retty __func(float __x, int __y) { \
202 return __func##f(__x, __y); \
203 }
204
205 __DEF_FUN1(float, acos)
206 __DEF_FUN1(float, acosh)
207 __DEF_FUN1(float, asin)
208 __DEF_FUN1(float, asinh)
209 __DEF_FUN1(float, atan)
210 __DEF_FUN2(float, atan2)
211 __DEF_FUN1(float, atanh)
212 __DEF_FUN1(float, cbrt)
213 __DEF_FUN1(float, ceil)
214 __DEF_FUN2(float, copysign)
215 __DEF_FUN1(float, cos)
216 __DEF_FUN1(float, cosh)
217 __DEF_FUN1(float, erf)
218 __DEF_FUN1(float, erfc)
219 __DEF_FUN1(float, exp)
220 __DEF_FUN1(float, exp2)
221 __DEF_FUN1(float, expm1)
222 __DEF_FUN1(float, fabs)
223 __DEF_FUN2(float, fdim)
224 __DEF_FUN1(float, floor)
225 __DEF_FUN2(float, fmax)
226 __DEF_FUN2(float, fmin)
227 __DEF_FUN2(float, fmod)
228 __DEF_FUN2(float, hypot)
229 __DEF_FUN1(int, ilogb)
230 __DEF_FUN2_FI(float, ldexp)
231 __DEF_FUN1(float, lgamma)
232 __DEF_FUN1(float, log)
233 __DEF_FUN1(float, log10)
234 __DEF_FUN1(float, log1p)
235 __DEF_FUN1(float, log2)
236 __DEF_FUN1(float, logb)
237 __DEF_FUN1(long long, llrint)
238 __DEF_FUN1(long long, llround)
239 __DEF_FUN1(long, lrint)
240 __DEF_FUN1(long, lround)
241 __DEF_FUN1(float, nearbyint)
242 __DEF_FUN2(float, nextafter)
243 __DEF_FUN2(float, pow)
244 __DEF_FUN2(float, remainder)
245 __DEF_FUN1(float, rint)
246 __DEF_FUN1(float, round)
247 __DEF_FUN2_FI(float, scalbn)
248 __DEF_FUN1(float, sin)
249 __DEF_FUN1(float, sinh)
250 __DEF_FUN1(float, sqrt)
251 __DEF_FUN1(float, tan)
252 __DEF_FUN1(float, tanh)
253 __DEF_FUN1(float, tgamma)
254 __DEF_FUN1(float, trunc)
255
256 #pragma pop_macro("__DEF_FUN1")
257 #pragma pop_macro("__DEF_FUN2")
258 #pragma pop_macro("__DEF_FUN2_FI")
259
260 // END DEF_FUN
261
262 // BEGIN HIP_OVERLOAD
263
264 #pragma push_macro("__HIP_OVERLOAD1")
265 #pragma push_macro("__HIP_OVERLOAD2")
266
267 // __hip_enable_if::type is a type function which returns __T if __B is true.
268 template <bool __B, class __T = void> struct __hip_enable_if {};
269
270 template <class __T> struct __hip_enable_if<true, __T> { typedef __T type; };
271
272 namespace __hip {
273 template <class _Tp> struct is_integral {
274 enum { value = 0 };
275 };
276 template <> struct is_integral<bool> {
277 enum { value = 1 };
278 };
279 template <> struct is_integral<char> {
280 enum { value = 1 };
281 };
282 template <> struct is_integral<signed char> {
283 enum { value = 1 };
284 };
285 template <> struct is_integral<unsigned char> {
286 enum { value = 1 };
287 };
288 template <> struct is_integral<wchar_t> {
289 enum { value = 1 };
290 };
291 template <> struct is_integral<short> {
292 enum { value = 1 };
293 };
294 template <> struct is_integral<unsigned short> {
295 enum { value = 1 };
296 };
297 template <> struct is_integral<int> {
298 enum { value = 1 };
299 };
300 template <> struct is_integral<unsigned int> {
301 enum { value = 1 };
302 };
303 template <> struct is_integral<long> {
304 enum { value = 1 };
305 };
306 template <> struct is_integral<unsigned long> {
307 enum { value = 1 };
308 };
309 template <> struct is_integral<long long> {
310 enum { value = 1 };
311 };
312 template <> struct is_integral<unsigned long long> {
313 enum { value = 1 };
314 };
315
316 // ToDo: specializes is_arithmetic<_Float16>
317 template <class _Tp> struct is_arithmetic {
318 enum { value = 0 };
319 };
320 template <> struct is_arithmetic<bool> {
321 enum { value = 1 };
322 };
323 template <> struct is_arithmetic<char> {
324 enum { value = 1 };
325 };
326 template <> struct is_arithmetic<signed char> {
327 enum { value = 1 };
328 };
329 template <> struct is_arithmetic<unsigned char> {
330 enum { value = 1 };
331 };
332 template <> struct is_arithmetic<wchar_t> {
333 enum { value = 1 };
334 };
335 template <> struct is_arithmetic<short> {
336 enum { value = 1 };
337 };
338 template <> struct is_arithmetic<unsigned short> {
339 enum { value = 1 };
340 };
341 template <> struct is_arithmetic<int> {
342 enum { value = 1 };
343 };
344 template <> struct is_arithmetic<unsigned int> {
345 enum { value = 1 };
346 };
347 template <> struct is_arithmetic<long> {
348 enum { value = 1 };
349 };
350 template <> struct is_arithmetic<unsigned long> {
351 enum { value = 1 };
352 };
353 template <> struct is_arithmetic<long long> {
354 enum { value = 1 };
355 };
356 template <> struct is_arithmetic<unsigned long long> {
357 enum { value = 1 };
358 };
359 template <> struct is_arithmetic<float> {
360 enum { value = 1 };
361 };
362 template <> struct is_arithmetic<double> {
363 enum { value = 1 };
364 };
365
366 struct true_type {
367 static const __constant__ bool value = true;
368 };
369 struct false_type {
370 static const __constant__ bool value = false;
371 };
372
373 template <typename __T, typename __U> struct is_same : public false_type {};
374 template <typename __T> struct is_same<__T, __T> : public true_type {};
375
376 template <typename __T> struct add_rvalue_reference { typedef __T &&type; };
377
378 template <typename __T> typename add_rvalue_reference<__T>::type declval();
379
380 // decltype is only available in C++11 and above.
381 #if __cplusplus >= 201103L
382 // __hip_promote
383 template <class _Tp> struct __numeric_type {
384 static void __test(...);
385 static _Float16 __test(_Float16);
386 static float __test(float);
387 static double __test(char);
388 static double __test(int);
389 static double __test(unsigned);
390 static double __test(long);
391 static double __test(unsigned long);
392 static double __test(long long);
393 static double __test(unsigned long long);
394 static double __test(double);
395 // No support for long double, use double instead.
396 static double __test(long double);
397
398 template <typename _U>
399 static auto __test_impl(int) -> decltype(__test(declval<_U>()));
400
401 template <typename _U> static void __test_impl(...);
402
403 typedef decltype(__test_impl<_Tp>(0)) type;
404 static const bool value = !is_same<type, void>::value;
405 };
406
407 template <> struct __numeric_type<void> { static const bool value = true; };
408
409 template <class _A1, class _A2 = void, class _A3 = void,
410 bool = __numeric_type<_A1>::value &&__numeric_type<_A2>::value
411 &&__numeric_type<_A3>::value>
412 class __promote_imp {
413 public:
414 static const bool value = false;
415 };
416
417 template <class _A1, class _A2, class _A3>
418 class __promote_imp<_A1, _A2, _A3, true> {
419 private:
420 typedef typename __promote_imp<_A1>::type __type1;
421 typedef typename __promote_imp<_A2>::type __type2;
422 typedef typename __promote_imp<_A3>::type __type3;
423
424 public:
425 typedef decltype(__type1() + __type2() + __type3()) type;
426 static const bool value = true;
427 };
428
429 template <class _A1, class _A2> class __promote_imp<_A1, _A2, void, true> {
430 private:
431 typedef typename __promote_imp<_A1>::type __type1;
432 typedef typename __promote_imp<_A2>::type __type2;
433
434 public:
435 typedef decltype(__type1() + __type2()) type;
436 static const bool value = true;
437 };
438
439 template <class _A1> class __promote_imp<_A1, void, void, true> {
440 public:
441 typedef typename __numeric_type<_A1>::type type;
442 static const bool value = true;
443 };
444
445 template <class _A1, class _A2 = void, class _A3 = void>
446 class __promote : public __promote_imp<_A1, _A2, _A3> {};
447 #endif //__cplusplus >= 201103L
448 } // namespace __hip
449
450 // __HIP_OVERLOAD1 is used to resolve function calls with integer argument to
451 // avoid compilation error due to ambiguity. e.g. floor(5) is resolved with
452 // floor(double).
453 #define __HIP_OVERLOAD1(__retty, __fn) \
454 template <typename __T> \
455 __DEVICE__ __CONSTEXPR__ \
456 typename __hip_enable_if<__hip::is_integral<__T>::value, __retty>::type \
457 __fn(__T __x) { \
458 return ::__fn((double)__x); \
459 }
460
461 // __HIP_OVERLOAD2 is used to resolve function calls with mixed float/double
462 // or integer argument to avoid compilation error due to ambiguity. e.g.
463 // max(5.0f, 6.0) is resolved with max(double, double).
464 #if __cplusplus >= 201103L
465 #define __HIP_OVERLOAD2(__retty, __fn) \
466 template <typename __T1, typename __T2> \
467 __DEVICE__ __CONSTEXPR__ \
468 typename __hip_enable_if<__hip::is_arithmetic<__T1>::value && \
469 __hip::is_arithmetic<__T2>::value, \
470 __retty>::type \
471 __fn(__T1 __x, __T2 __y) { \
472 typedef typename __hip::__promote<__T1, __T2>::type __arg_type; \
473 return __fn((__arg_type)__x, (__arg_type)__y); \
474 }
475 #else
476 #define __HIP_OVERLOAD2(__retty, __fn) \
477 template <typename __T1, typename __T2> \
478 __DEVICE__ __CONSTEXPR__ \
479 typename __hip_enable_if<__hip::is_arithmetic<__T1>::value && \
480 __hip::is_arithmetic<__T2>::value, \
481 __retty>::type \
482 __fn(__T1 __x, __T2 __y) { \
483 return __fn((double)__x, (double)__y); \
484 }
485 #endif
486
487 __HIP_OVERLOAD1(double, acos)
488 __HIP_OVERLOAD1(double, acosh)
489 __HIP_OVERLOAD1(double, asin)
490 __HIP_OVERLOAD1(double, asinh)
491 __HIP_OVERLOAD1(double, atan)
492 __HIP_OVERLOAD2(double, atan2)
493 __HIP_OVERLOAD1(double, atanh)
494 __HIP_OVERLOAD1(double, cbrt)
495 __HIP_OVERLOAD1(double, ceil)
496 __HIP_OVERLOAD2(double, copysign)
497 __HIP_OVERLOAD1(double, cos)
498 __HIP_OVERLOAD1(double, cosh)
499 __HIP_OVERLOAD1(double, erf)
500 __HIP_OVERLOAD1(double, erfc)
501 __HIP_OVERLOAD1(double, exp)
502 __HIP_OVERLOAD1(double, exp2)
503 __HIP_OVERLOAD1(double, expm1)
504 __HIP_OVERLOAD1(double, fabs)
505 __HIP_OVERLOAD2(double, fdim)
506 __HIP_OVERLOAD1(double, floor)
507 __HIP_OVERLOAD2(double, fmax)
508 __HIP_OVERLOAD2(double, fmin)
509 __HIP_OVERLOAD2(double, fmod)
510 #if !defined(__HIPCC_RTC__)
511 __HIP_OVERLOAD1(int, fpclassify)
512 #endif // !defined(__HIPCC_RTC__)
513 __HIP_OVERLOAD2(double, hypot)
514 __HIP_OVERLOAD1(int, ilogb)
515 __HIP_OVERLOAD1(bool, isfinite)
516 __HIP_OVERLOAD2(bool, isgreater)
517 __HIP_OVERLOAD2(bool, isgreaterequal)
518 __HIP_OVERLOAD1(bool, isinf)
519 __HIP_OVERLOAD2(bool, isless)
520 __HIP_OVERLOAD2(bool, islessequal)
521 __HIP_OVERLOAD2(bool, islessgreater)
522 __HIP_OVERLOAD1(bool, isnan)
523 __HIP_OVERLOAD1(bool, isnormal)
524 __HIP_OVERLOAD2(bool, isunordered)
525 __HIP_OVERLOAD1(double, lgamma)
526 __HIP_OVERLOAD1(double, log)
527 __HIP_OVERLOAD1(double, log10)
528 __HIP_OVERLOAD1(double, log1p)
529 __HIP_OVERLOAD1(double, log2)
530 __HIP_OVERLOAD1(double, logb)
531 __HIP_OVERLOAD1(long long, llrint)
532 __HIP_OVERLOAD1(long long, llround)
533 __HIP_OVERLOAD1(long, lrint)
534 __HIP_OVERLOAD1(long, lround)
535 __HIP_OVERLOAD1(double, nearbyint)
536 __HIP_OVERLOAD2(double, nextafter)
537 __HIP_OVERLOAD2(double, pow)
538 __HIP_OVERLOAD2(double, remainder)
539 __HIP_OVERLOAD1(double, rint)
540 __HIP_OVERLOAD1(double, round)
541 __HIP_OVERLOAD1(bool, signbit)
542 __HIP_OVERLOAD1(double, sin)
543 __HIP_OVERLOAD1(double, sinh)
544 __HIP_OVERLOAD1(double, sqrt)
545 __HIP_OVERLOAD1(double, tan)
546 __HIP_OVERLOAD1(double, tanh)
547 __HIP_OVERLOAD1(double, tgamma)
548 __HIP_OVERLOAD1(double, trunc)
549
550 // Overload these but don't add them to std, they are not part of cmath.
551 __HIP_OVERLOAD2(double, max)
552 __HIP_OVERLOAD2(double, min)
553
554 // Additional Overloads that don't quite match HIP_OVERLOAD.
555 #if __cplusplus >= 201103L
556 template <typename __T1, typename __T2, typename __T3>
557 __DEVICE__ __CONSTEXPR__ typename __hip_enable_if<
558 __hip::is_arithmetic<__T1>::value && __hip::is_arithmetic<__T2>::value &&
559 __hip::is_arithmetic<__T3>::value,
560 typename __hip::__promote<__T1, __T2, __T3>::type>::type
561 fma(__T1 __x, __T2 __y, __T3 __z) {
562 typedef typename __hip::__promote<__T1, __T2, __T3>::type __result_type;
563 return ::fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
564 }
565 #else
566 template <typename __T1, typename __T2, typename __T3>
567 __DEVICE__ __CONSTEXPR__
568 typename __hip_enable_if<__hip::is_arithmetic<__T1>::value &&
569 __hip::is_arithmetic<__T2>::value &&
570 __hip::is_arithmetic<__T3>::value,
571 double>::type
572 fma(__T1 __x, __T2 __y, __T3 __z) {
573 return ::fma((double)__x, (double)__y, (double)__z);
574 }
575 #endif
576
577 template <typename __T>
578 __DEVICE__ __CONSTEXPR__
579 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
580 frexp(__T __x, int *__exp) {
581 return ::frexp((double)__x, __exp);
582 }
583
584 template <typename __T>
585 __DEVICE__ __CONSTEXPR__
586 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
587 ldexp(__T __x, int __exp) {
588 return ::ldexp((double)__x, __exp);
589 }
590
591 template <typename __T>
592 __DEVICE__ __CONSTEXPR__
593 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
594 modf(__T __x, double *__exp) {
595 return ::modf((double)__x, __exp);
596 }
597
598 #if __cplusplus >= 201103L
599 template <typename __T1, typename __T2>
600 __DEVICE__ __CONSTEXPR__
601 typename __hip_enable_if<__hip::is_arithmetic<__T1>::value &&
602 __hip::is_arithmetic<__T2>::value,
603 typename __hip::__promote<__T1, __T2>::type>::type
604 remquo(__T1 __x, __T2 __y, int *__quo) {
605 typedef typename __hip::__promote<__T1, __T2>::type __result_type;
606 return ::remquo((__result_type)__x, (__result_type)__y, __quo);
607 }
608 #else
609 template <typename __T1, typename __T2>
610 __DEVICE__ __CONSTEXPR__
611 typename __hip_enable_if<__hip::is_arithmetic<__T1>::value &&
612 __hip::is_arithmetic<__T2>::value,
613 double>::type
614 remquo(__T1 __x, __T2 __y, int *__quo) {
615 return ::remquo((double)__x, (double)__y, __quo);
616 }
617 #endif
618
619 template <typename __T>
620 __DEVICE__ __CONSTEXPR__
621 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
622 scalbln(__T __x, long int __exp) {
623 return ::scalbln((double)__x, __exp);
624 }
625
626 template <typename __T>
627 __DEVICE__ __CONSTEXPR__
628 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
629 scalbn(__T __x, int __exp) {
630 return ::scalbn((double)__x, __exp);
631 }
632
633 #pragma pop_macro("__HIP_OVERLOAD1")
634 #pragma pop_macro("__HIP_OVERLOAD2")
635
636 // END HIP_OVERLOAD
637
638 // END DEF_FUN and HIP_OVERLOAD
639
640 #endif // ifndef __OPENMP_AMDGCN__
641 #endif // defined(__cplusplus)
642
643 #ifndef __OPENMP_AMDGCN__
644 // Define these overloads inside the namespace our standard library uses.
645 #if !defined(__HIPCC_RTC__)
646 #ifdef _LIBCPP_BEGIN_NAMESPACE_STD
647 _LIBCPP_BEGIN_NAMESPACE_STD
648 #else
649 namespace std {
650 #ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION
651 _GLIBCXX_BEGIN_NAMESPACE_VERSION
652 #endif // _GLIBCXX_BEGIN_NAMESPACE_VERSION
653 #endif // _LIBCPP_BEGIN_NAMESPACE_STD
654
655 // Pull the new overloads we defined above into namespace std.
656 // using ::abs; - This may be considered for C++.
657 using ::acos;
658 using ::acosh;
659 using ::asin;
660 using ::asinh;
661 using ::atan;
662 using ::atan2;
663 using ::atanh;
664 using ::cbrt;
665 using ::ceil;
666 using ::copysign;
667 using ::cos;
668 using ::cosh;
669 using ::erf;
670 using ::erfc;
671 using ::exp;
672 using ::exp2;
673 using ::expm1;
674 using ::fabs;
675 using ::fdim;
676 using ::floor;
677 using ::fma;
678 using ::fmax;
679 using ::fmin;
680 using ::fmod;
681 using ::fpclassify;
682 using ::frexp;
683 using ::hypot;
684 using ::ilogb;
685 using ::isfinite;
686 using ::isgreater;
687 using ::isgreaterequal;
688 using ::isless;
689 using ::islessequal;
690 using ::islessgreater;
691 using ::isnormal;
692 using ::isunordered;
693 using ::ldexp;
694 using ::lgamma;
695 using ::llrint;
696 using ::llround;
697 using ::log;
698 using ::log10;
699 using ::log1p;
700 using ::log2;
701 using ::logb;
702 using ::lrint;
703 using ::lround;
704 using ::modf;
705 // using ::nan; - This may be considered for C++.
706 // using ::nanf; - This may be considered for C++.
707 // using ::nanl; - This is not yet defined.
708 using ::nearbyint;
709 using ::nextafter;
710 // using ::nexttoward; - Omit this since we do not have a definition.
711 using ::pow;
712 using ::remainder;
713 using ::remquo;
714 using ::rint;
715 using ::round;
716 using ::scalbln;
717 using ::scalbn;
718 using ::signbit;
719 using ::sin;
720 using ::sinh;
721 using ::sqrt;
722 using ::tan;
723 using ::tanh;
724 using ::tgamma;
725 using ::trunc;
726
727 // Well this is fun: We need to pull these symbols in for libc++, but we can't
728 // pull them in with libstdc++, because its ::isinf and ::isnan are different
729 // than its std::isinf and std::isnan.
730 #ifndef __GLIBCXX__
731 using ::isinf;
732 using ::isnan;
733 #endif
734
735 // Finally, pull the "foobarf" functions that HIP defines into std.
736 using ::acosf;
737 using ::acoshf;
738 using ::asinf;
739 using ::asinhf;
740 using ::atan2f;
741 using ::atanf;
742 using ::atanhf;
743 using ::cbrtf;
744 using ::ceilf;
745 using ::copysignf;
746 using ::cosf;
747 using ::coshf;
748 using ::erfcf;
749 using ::erff;
750 using ::exp2f;
751 using ::expf;
752 using ::expm1f;
753 using ::fabsf;
754 using ::fdimf;
755 using ::floorf;
756 using ::fmaf;
757 using ::fmaxf;
758 using ::fminf;
759 using ::fmodf;
760 using ::frexpf;
761 using ::hypotf;
762 using ::ilogbf;
763 using ::ldexpf;
764 using ::lgammaf;
765 using ::llrintf;
766 using ::llroundf;
767 using ::log10f;
768 using ::log1pf;
769 using ::log2f;
770 using ::logbf;
771 using ::logf;
772 using ::lrintf;
773 using ::lroundf;
774 using ::modff;
775 using ::nearbyintf;
776 using ::nextafterf;
777 // using ::nexttowardf; - Omit this since we do not have a definition.
778 using ::powf;
779 using ::remainderf;
780 using ::remquof;
781 using ::rintf;
782 using ::roundf;
783 using ::scalblnf;
784 using ::scalbnf;
785 using ::sinf;
786 using ::sinhf;
787 using ::sqrtf;
788 using ::tanf;
789 using ::tanhf;
790 using ::tgammaf;
791 using ::truncf;
792
793 #ifdef _LIBCPP_END_NAMESPACE_STD
794 _LIBCPP_END_NAMESPACE_STD
795 #else
796 #ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION
797 _GLIBCXX_END_NAMESPACE_VERSION
798 #endif // _GLIBCXX_BEGIN_NAMESPACE_VERSION
799 } // namespace std
800 #endif // _LIBCPP_END_NAMESPACE_STD
801 #endif // !defined(__HIPCC_RTC__)
802
803 // Define device-side math functions from <ymath.h> on MSVC.
804 #if !defined(__HIPCC_RTC__)
805 #if defined(_MSC_VER)
806
807 // Before VS2019, `<ymath.h>` is also included in `<limits>` and other headers.
808 // But, from VS2019, it's only included in `<complex>`. Need to include
809 // `<ymath.h>` here to ensure C functions declared there won't be markded as
810 // `__host__` and `__device__` through `<complex>` wrapper.
811 #include <ymath.h>
812
813 #if defined(__cplusplus)
814 extern "C" {
815 #endif // defined(__cplusplus)
816 __DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) double _Cosh(double x,
817 double y) {
818 return cosh(x) * y;
819 }
820 __DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) float _FCosh(float x,
821 float y) {
822 return coshf(x) * y;
823 }
824 __DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) short _Dtest(double *p) {
825 return fpclassify(*p);
826 }
827 __DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) short _FDtest(float *p) {
828 return fpclassify(*p);
829 }
830 __DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) double _Sinh(double x,
831 double y) {
832 return sinh(x) * y;
833 }
834 __DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) float _FSinh(float x,
835 float y) {
836 return sinhf(x) * y;
837 }
838 #if defined(__cplusplus)
839 }
840 #endif // defined(__cplusplus)
841 #endif // defined(_MSC_VER)
842 #endif // !defined(__HIPCC_RTC__)
843 #endif // ifndef __OPENMP_AMDGCN__
844
845 #pragma pop_macro("__DEVICE__")
846 #pragma pop_macro("__CONSTEXPR__")
847
848 #endif // __CLANG_HIP_CMATH_H__