clang 20.0.0git
__clang_hip_cmath.h
Go to the documentation of this file.
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.
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.
268template <bool __B, class __T = void> struct __hip_enable_if {};
269
270template <class __T> struct __hip_enable_if<true, __T> { typedef __T type; };
271
272namespace __hip {
273template <class _Tp> struct is_integral {
274 enum { value = 0 };
275};
276template <> struct is_integral<bool> {
277 enum { value = 1 };
278};
279template <> struct is_integral<char> {
280 enum { value = 1 };
281};
282template <> struct is_integral<signed char> {
283 enum { value = 1 };
284};
285template <> struct is_integral<unsigned char> {
286 enum { value = 1 };
287};
288template <> struct is_integral<wchar_t> {
289 enum { value = 1 };
290};
291template <> struct is_integral<short> {
292 enum { value = 1 };
293};
294template <> struct is_integral<unsigned short> {
295 enum { value = 1 };
296};
297template <> struct is_integral<int> {
298 enum { value = 1 };
299};
300template <> struct is_integral<unsigned int> {
301 enum { value = 1 };
302};
303template <> struct is_integral<long> {
304 enum { value = 1 };
305};
306template <> struct is_integral<unsigned long> {
307 enum { value = 1 };
308};
309template <> struct is_integral<long long> {
310 enum { value = 1 };
311};
312template <> struct is_integral<unsigned long long> {
313 enum { value = 1 };
314};
315
316// ToDo: specializes is_arithmetic<_Float16>
317template <class _Tp> struct is_arithmetic {
318 enum { value = 0 };
319};
320template <> struct is_arithmetic<bool> {
321 enum { value = 1 };
322};
323template <> struct is_arithmetic<char> {
324 enum { value = 1 };
325};
326template <> struct is_arithmetic<signed char> {
327 enum { value = 1 };
328};
329template <> struct is_arithmetic<unsigned char> {
330 enum { value = 1 };
331};
332template <> struct is_arithmetic<wchar_t> {
333 enum { value = 1 };
334};
335template <> struct is_arithmetic<short> {
336 enum { value = 1 };
337};
338template <> struct is_arithmetic<unsigned short> {
339 enum { value = 1 };
340};
341template <> struct is_arithmetic<int> {
342 enum { value = 1 };
343};
344template <> struct is_arithmetic<unsigned int> {
345 enum { value = 1 };
346};
347template <> struct is_arithmetic<long> {
348 enum { value = 1 };
349};
350template <> struct is_arithmetic<unsigned long> {
351 enum { value = 1 };
352};
353template <> struct is_arithmetic<long long> {
354 enum { value = 1 };
355};
356template <> struct is_arithmetic<unsigned long long> {
357 enum { value = 1 };
358};
359template <> struct is_arithmetic<float> {
360 enum { value = 1 };
361};
362template <> struct is_arithmetic<double> {
363 enum { value = 1 };
364};
365
366struct true_type {
367 static const __constant__ bool value = true;
368};
369struct false_type {
370 static const __constant__ bool value = false;
371};
372
373template <typename __T, typename __U> struct is_same : public false_type {};
374template <typename __T> struct is_same<__T, __T> : public true_type {};
375
376template <typename __T> struct add_rvalue_reference { typedef __T &&type; };
377
378template <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
383template <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
407template <> struct __numeric_type<void> { static const bool value = true; };
408
409template <class _A1, class _A2 = void, class _A3 = void,
410 bool = __numeric_type<_A1>::value &&__numeric_type<_A2>::value
411 &&__numeric_type<_A3>::value>
412class __promote_imp {
413public:
414 static const bool value = false;
415};
416
417template <class _A1, class _A2, class _A3>
418class __promote_imp<_A1, _A2, _A3, true> {
419private:
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
424public:
425 typedef decltype(__type1() + __type2() + __type3()) type;
426 static const bool value = true;
427};
428
429template <class _A1, class _A2> class __promote_imp<_A1, _A2, void, true> {
430private:
431 typedef typename __promote_imp<_A1>::type __type1;
432 typedef typename __promote_imp<_A2>::type __type2;
433
434public:
435 typedef decltype(__type1() + __type2()) type;
436 static const bool value = true;
437};
438
439template <class _A1> class __promote_imp<_A1, void, void, true> {
440public:
441 typedef typename __numeric_type<_A1>::type type;
442 static const bool value = true;
443};
444
445template <class _A1, class _A2 = void, class _A3 = void>
446class __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 ambibuity. 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 ambibuity. 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__ typename __hip_enable_if< \
468 __hip::is_arithmetic<__T1>::value && __hip::is_arithmetic<__T2>::value, \
469 typename __hip::__promote<__T1, __T2>::type>::type \
470 __fn(__T1 __x, __T2 __y) { \
471 typedef typename __hip::__promote<__T1, __T2>::type __result_type; \
472 return __fn((__result_type)__x, (__result_type)__y); \
473 }
474#else
475#define __HIP_OVERLOAD2(__retty, __fn) \
476 template <typename __T1, typename __T2> \
477 __DEVICE__ __CONSTEXPR__ \
478 typename __hip_enable_if<__hip::is_arithmetic<__T1>::value && \
479 __hip::is_arithmetic<__T2>::value, \
480 __retty>::type \
481 __fn(__T1 __x, __T2 __y) { \
482 return __fn((double)__x, (double)__y); \
483 }
484#endif
485
486__HIP_OVERLOAD1(double, acos)
487__HIP_OVERLOAD1(double, acosh)
488__HIP_OVERLOAD1(double, asin)
489__HIP_OVERLOAD1(double, asinh)
490__HIP_OVERLOAD1(double, atan)
491__HIP_OVERLOAD2(double, atan2)
492__HIP_OVERLOAD1(double, atanh)
493__HIP_OVERLOAD1(double, cbrt)
494__HIP_OVERLOAD1(double, ceil)
495__HIP_OVERLOAD2(double, copysign)
496__HIP_OVERLOAD1(double, cos)
497__HIP_OVERLOAD1(double, cosh)
498__HIP_OVERLOAD1(double, erf)
499__HIP_OVERLOAD1(double, erfc)
500__HIP_OVERLOAD1(double, exp)
501__HIP_OVERLOAD1(double, exp2)
502__HIP_OVERLOAD1(double, expm1)
503__HIP_OVERLOAD1(double, fabs)
504__HIP_OVERLOAD2(double, fdim)
505__HIP_OVERLOAD1(double, floor)
506__HIP_OVERLOAD2(double, fmax)
507__HIP_OVERLOAD2(double, fmin)
508__HIP_OVERLOAD2(double, fmod)
509#if !defined(__HIPCC_RTC__)
510__HIP_OVERLOAD1(int, fpclassify)
511#endif // !defined(__HIPCC_RTC__)
512__HIP_OVERLOAD2(double, hypot)
513__HIP_OVERLOAD1(int, ilogb)
514__HIP_OVERLOAD1(bool, isfinite)
515__HIP_OVERLOAD2(bool, isgreater)
516__HIP_OVERLOAD2(bool, isgreaterequal)
517__HIP_OVERLOAD1(bool, isinf)
518__HIP_OVERLOAD2(bool, isless)
519__HIP_OVERLOAD2(bool, islessequal)
520__HIP_OVERLOAD2(bool, islessgreater)
521__HIP_OVERLOAD1(bool, isnan)
522__HIP_OVERLOAD1(bool, isnormal)
523__HIP_OVERLOAD2(bool, isunordered)
524__HIP_OVERLOAD1(double, lgamma)
525__HIP_OVERLOAD1(double, log)
526__HIP_OVERLOAD1(double, log10)
527__HIP_OVERLOAD1(double, log1p)
528__HIP_OVERLOAD1(double, log2)
529__HIP_OVERLOAD1(double, logb)
530__HIP_OVERLOAD1(long long, llrint)
531__HIP_OVERLOAD1(long long, llround)
532__HIP_OVERLOAD1(long, lrint)
533__HIP_OVERLOAD1(long, lround)
534__HIP_OVERLOAD1(double, nearbyint)
535__HIP_OVERLOAD2(double, nextafter)
536__HIP_OVERLOAD2(double, pow)
537__HIP_OVERLOAD2(double, remainder)
538__HIP_OVERLOAD1(double, rint)
539__HIP_OVERLOAD1(double, round)
540__HIP_OVERLOAD1(bool, signbit)
541__HIP_OVERLOAD1(double, sin)
542__HIP_OVERLOAD1(double, sinh)
543__HIP_OVERLOAD1(double, sqrt)
544__HIP_OVERLOAD1(double, tan)
545__HIP_OVERLOAD1(double, tanh)
546__HIP_OVERLOAD1(double, tgamma)
547__HIP_OVERLOAD1(double, trunc)
548
549// Overload these but don't add them to std, they are not part of cmath.
550__HIP_OVERLOAD2(double, max)
551__HIP_OVERLOAD2(double, min)
552
553// Additional Overloads that don't quite match HIP_OVERLOAD.
554#if __cplusplus >= 201103L
555template <typename __T1, typename __T2, typename __T3>
556__DEVICE__ __CONSTEXPR__ typename __hip_enable_if<
557 __hip::is_arithmetic<__T1>::value && __hip::is_arithmetic<__T2>::value &&
558 __hip::is_arithmetic<__T3>::value,
559 typename __hip::__promote<__T1, __T2, __T3>::type>::type
560fma(__T1 __x, __T2 __y, __T3 __z) {
561 typedef typename __hip::__promote<__T1, __T2, __T3>::type __result_type;
562 return ::fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
563}
564#else
565template <typename __T1, typename __T2, typename __T3>
567 typename __hip_enable_if<__hip::is_arithmetic<__T1>::value &&
568 __hip::is_arithmetic<__T2>::value &&
569 __hip::is_arithmetic<__T3>::value,
570 double>::type
571 fma(__T1 __x, __T2 __y, __T3 __z) {
572 return ::fma((double)__x, (double)__y, (double)__z);
573}
574#endif
575
576template <typename __T>
578 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
579 frexp(__T __x, int *__exp) {
580 return ::frexp((double)__x, __exp);
581}
582
583template <typename __T>
585 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
586 ldexp(__T __x, int __exp) {
587 return ::ldexp((double)__x, __exp);
588}
589
590template <typename __T>
592 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
593 modf(__T __x, double *__exp) {
594 return ::modf((double)__x, __exp);
595}
596
597#if __cplusplus >= 201103L
598template <typename __T1, typename __T2>
600 typename __hip_enable_if<__hip::is_arithmetic<__T1>::value &&
601 __hip::is_arithmetic<__T2>::value,
602 typename __hip::__promote<__T1, __T2>::type>::type
603 remquo(__T1 __x, __T2 __y, int *__quo) {
604 typedef typename __hip::__promote<__T1, __T2>::type __result_type;
605 return ::remquo((__result_type)__x, (__result_type)__y, __quo);
606}
607#else
608template <typename __T1, typename __T2>
610 typename __hip_enable_if<__hip::is_arithmetic<__T1>::value &&
611 __hip::is_arithmetic<__T2>::value,
612 double>::type
613 remquo(__T1 __x, __T2 __y, int *__quo) {
614 return ::remquo((double)__x, (double)__y, __quo);
615}
616#endif
617
618template <typename __T>
620 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
621 scalbln(__T __x, long int __exp) {
622 return ::scalbln((double)__x, __exp);
623}
624
625template <typename __T>
627 typename __hip_enable_if<__hip::is_integral<__T>::value, double>::type
628 scalbn(__T __x, int __exp) {
629 return ::scalbn((double)__x, __exp);
630}
631
632#pragma pop_macro("__HIP_OVERLOAD1")
633#pragma pop_macro("__HIP_OVERLOAD2")
634
635// END HIP_OVERLOAD
636
637// END DEF_FUN and HIP_OVERLOAD
638
639#endif // ifndef __OPENMP_AMDGCN__
640#endif // defined(__cplusplus)
641
642#ifndef __OPENMP_AMDGCN__
643// Define these overloads inside the namespace our standard library uses.
644#if !defined(__HIPCC_RTC__)
645#ifdef _LIBCPP_BEGIN_NAMESPACE_STD
646_LIBCPP_BEGIN_NAMESPACE_STD
647#else
648namespace std {
649#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION
650_GLIBCXX_BEGIN_NAMESPACE_VERSION
651#endif // _GLIBCXX_BEGIN_NAMESPACE_VERSION
652#endif // _LIBCPP_BEGIN_NAMESPACE_STD
653
654// Pull the new overloads we defined above into namespace std.
655// using ::abs; - This may be considered for C++.
656using ::acos;
657using ::acosh;
658using ::asin;
659using ::asinh;
660using ::atan;
661using ::atan2;
662using ::atanh;
663using ::cbrt;
664using ::ceil;
665using ::copysign;
666using ::cos;
667using ::cosh;
668using ::erf;
669using ::erfc;
670using ::exp;
671using ::exp2;
672using ::expm1;
673using ::fabs;
674using ::fdim;
675using ::floor;
676using ::fma;
677using ::fmax;
678using ::fmin;
679using ::fmod;
680using ::fpclassify;
681using ::frexp;
682using ::hypot;
683using ::ilogb;
684using ::isfinite;
685using ::isgreater;
686using ::isgreaterequal;
687using ::isless;
688using ::islessequal;
689using ::islessgreater;
690using ::isnormal;
691using ::isunordered;
692using ::ldexp;
693using ::lgamma;
694using ::llrint;
695using ::llround;
696using ::log;
697using ::log10;
698using ::log1p;
699using ::log2;
700using ::logb;
701using ::lrint;
702using ::lround;
703using ::modf;
704// using ::nan; - This may be considered for C++.
705// using ::nanf; - This may be considered for C++.
706// using ::nanl; - This is not yet defined.
707using ::nearbyint;
708using ::nextafter;
709// using ::nexttoward; - Omit this since we do not have a definition.
710using ::pow;
711using ::remainder;
712using ::remquo;
713using ::rint;
714using ::round;
715using ::scalbln;
716using ::scalbn;
717using ::signbit;
718using ::sin;
719using ::sinh;
720using ::sqrt;
721using ::tan;
722using ::tanh;
723using ::tgamma;
724using ::trunc;
725
726// Well this is fun: We need to pull these symbols in for libc++, but we can't
727// pull them in with libstdc++, because its ::isinf and ::isnan are different
728// than its std::isinf and std::isnan.
729#ifndef __GLIBCXX__
730using ::isinf;
731using ::isnan;
732#endif
733
734// Finally, pull the "foobarf" functions that HIP defines into std.
735using ::acosf;
736using ::acoshf;
737using ::asinf;
738using ::asinhf;
739using ::atan2f;
740using ::atanf;
741using ::atanhf;
742using ::cbrtf;
743using ::ceilf;
744using ::copysignf;
745using ::cosf;
746using ::coshf;
747using ::erfcf;
748using ::erff;
749using ::exp2f;
750using ::expf;
751using ::expm1f;
752using ::fabsf;
753using ::fdimf;
754using ::floorf;
755using ::fmaf;
756using ::fmaxf;
757using ::fminf;
758using ::fmodf;
759using ::frexpf;
760using ::hypotf;
761using ::ilogbf;
762using ::ldexpf;
763using ::lgammaf;
764using ::llrintf;
765using ::llroundf;
766using ::log10f;
767using ::log1pf;
768using ::log2f;
769using ::logbf;
770using ::logf;
771using ::lrintf;
772using ::lroundf;
773using ::modff;
774using ::nearbyintf;
775using ::nextafterf;
776// using ::nexttowardf; - Omit this since we do not have a definition.
777using ::powf;
778using ::remainderf;
779using ::remquof;
780using ::rintf;
781using ::roundf;
782using ::scalblnf;
783using ::scalbnf;
784using ::sinf;
785using ::sinhf;
786using ::sqrtf;
787using ::tanf;
788using ::tanhf;
789using ::tgammaf;
790using ::truncf;
791
792#ifdef _LIBCPP_END_NAMESPACE_STD
793_LIBCPP_END_NAMESPACE_STD
794#else
795#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION
796_GLIBCXX_END_NAMESPACE_VERSION
797#endif // _GLIBCXX_BEGIN_NAMESPACE_VERSION
798} // namespace std
799#endif // _LIBCPP_END_NAMESPACE_STD
800#endif // !defined(__HIPCC_RTC__)
801
802// Define device-side math functions from <ymath.h> on MSVC.
803#if !defined(__HIPCC_RTC__)
804#if defined(_MSC_VER)
805
806// Before VS2019, `<ymath.h>` is also included in `<limits>` and other headers.
807// But, from VS2019, it's only included in `<complex>`. Need to include
808// `<ymath.h>` here to ensure C functions declared there won't be markded as
809// `__host__` and `__device__` through `<complex>` wrapper.
810#include <ymath.h>
811
812#if defined(__cplusplus)
813extern "C" {
814#endif // defined(__cplusplus)
815__DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) double _Cosh(double x,
816 double y) {
817 return cosh(x) * y;
818}
819__DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) float _FCosh(float x,
820 float y) {
821 return coshf(x) * y;
822}
823__DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) short _Dtest(double *p) {
824 return fpclassify(*p);
825}
826__DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) short _FDtest(float *p) {
827 return fpclassify(*p);
828}
829__DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) double _Sinh(double x,
830 double y) {
831 return sinh(x) * y;
832}
833__DEVICE__ __CONSTEXPR__ __attribute__((overloadable)) float _FSinh(float x,
834 float y) {
835 return sinhf(x) * y;
836}
837#if defined(__cplusplus)
838}
839#endif // defined(__cplusplus)
840#endif // defined(_MSC_VER)
841#endif // !defined(__HIPCC_RTC__)
842#endif // ifndef __OPENMP_AMDGCN__
843
844#pragma pop_macro("__DEVICE__")
845#pragma pop_macro("__CONSTEXPR__")
846
847#endif // __CLANG_HIP_CMATH_H__
__DEVICE__ bool isunordered(float __x, float __y)
Test if arguments are unordered.
__DEVICE__ bool isgreater(float __x, float __y)
Returns the component-wise compare of x > y.
__DEVICE__ bool islessgreater(float __x, float __y)
Returns the component-wise compare of (x < y) || (x > y) .
__DEVICE__ bool isnan(float __x)
Test for a NaN.
__DEVICE__ int fpclassify(float __x)
__DEVICE__ bool isfinite(float __x)
Test for finite value.
__DEVICE__ bool signbit(float __x)
Test for sign bit.
__DEVICE__ bool isinf(float __x)
Test for infinity value (+ve or -ve) .
__DEVICE__ float modf(float __x, float *__iptr)
__DEVICE__ bool islessequal(float __x, float __y)
Returns the component-wise compare of x <= y.
__DEVICE__ long long abs(long long __n)
__DEVICE__ bool isless(float __x, float __y)
Returns the component-wise compare of x < y.
__DEVICE__ bool isnormal(float __x)
Test for a normal value.
__DEVICE__ bool isgreaterequal(float __x, float __y)
Returns the component-wise compare of x >= y.
__DEVICE__ int min(int __a, int __b)
__DEVICE__ float sinhf(float __a)
__DEVICE__ float coshf(float __a)
__DEVICE__ int max(int __a, int __b)
#define __DEVICE__
#define __CONSTEXPR__
_Float16 __2f16 __attribute__((ext_vector_type(2)))
Zeroes the upper 128 bits (bits 255:128) of all YMM registers.
__device__ double
__device__ int
__device__ _Float16
__device__ float
#define __constant__
__WCHAR_TYPE__ wchar_t
static __inline__ uint32_t uint32_t __y
Definition: arm_acle.h:130
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
#define true
Definition: stdbool.h:25
#define bool
Definition: stdbool.h:24
#define sinh(__x)
Definition: tgmath.h:373
#define asin(__x)
Definition: tgmath.h:112
#define scalbln(__x, __y)
Definition: tgmath.h:1182
#define sqrt(__x)
Definition: tgmath.h:520
#define acos(__x)
Definition: tgmath.h:83
#define fmin(__x, __y)
Definition: tgmath.h:780
#define exp(__x)
Definition: tgmath.h:431
#define ilogb(__x)
Definition: tgmath.h:851
#define copysign(__x, __y)
Definition: tgmath.h:618
#define erf(__x)
Definition: tgmath.h:636
#define atanh(__x)
Definition: tgmath.h:228
#define remquo(__x, __y, __z)
Definition: tgmath.h:1111
#define nextafter(__x, __y)
Definition: tgmath.h:1055
#define frexp(__x, __y)
Definition: tgmath.h:816
#define asinh(__x)
Definition: tgmath.h:199
#define erfc(__x)
Definition: tgmath.h:653
#define atan2(__x, __y)
Definition: tgmath.h:566
#define hypot(__x, __y)
Definition: tgmath.h:833
#define exp2(__x)
Definition: tgmath.h:670
#define sin(__x)
Definition: tgmath.h:286
#define cbrt(__x)
Definition: tgmath.h:584
#define log2(__x)
Definition: tgmath.h:970
#define llround(__x)
Definition: tgmath.h:919
#define cosh(__x)
Definition: tgmath.h:344
#define trunc(__x)
Definition: tgmath.h:1216
#define fmax(__x, __y)
Definition: tgmath.h:762
#define ldexp(__x, __y)
Definition: tgmath.h:868
#define acosh(__x)
Definition: tgmath.h:170
#define tgamma(__x)
Definition: tgmath.h:1199
#define scalbn(__x, __y)
Definition: tgmath.h:1165
#define round(__x)
Definition: tgmath.h:1148
#define fmod(__x, __y)
Definition: tgmath.h:798
#define llrint(__x)
Definition: tgmath.h:902
#define tan(__x)
Definition: tgmath.h:315
#define cos(__x)
Definition: tgmath.h:257
#define log10(__x)
Definition: tgmath.h:936
#define fabs(__x)
Definition: tgmath.h:549
#define pow(__x, __y)
Definition: tgmath.h:490
#define log1p(__x)
Definition: tgmath.h:953
#define rint(__x)
Definition: tgmath.h:1131
#define expm1(__x)
Definition: tgmath.h:687
#define remainder(__x, __y)
Definition: tgmath.h:1090
#define fdim(__x, __y)
Definition: tgmath.h:704
#define lgamma(__x)
Definition: tgmath.h:885
#define tanh(__x)
Definition: tgmath.h:402
#define lrint(__x)
Definition: tgmath.h:1004
#define atan(__x)
Definition: tgmath.h:141
#define floor(__x)
Definition: tgmath.h:722
#define ceil(__x)
Definition: tgmath.h:601
#define log(__x)
Definition: tgmath.h:460
#define logb(__x)
Definition: tgmath.h:987
#define nearbyint(__x)
Definition: tgmath.h:1038
#define lround(__x)
Definition: tgmath.h:1021
#define fma(__x, __y, __z)
Definition: tgmath.h:742