Debian Codegraph @

clang/lib/Headers/__clang_hip_math.h

raw
1 /*===---- __clang_hip_math.h - Device-side HIP math support ----------------===
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 #ifndef __CLANG_HIP_MATH_H__
10 #define __CLANG_HIP_MATH_H__
11
12 #if !defined(__HIP__) && !defined(__OPENMP_AMDGCN__)
13 #error "This file is for HIP and OpenMP AMDGCN device compilation only."
14 #endif
15
16 // The __CLANG_GPU_DISABLE_MATH_WRAPPERS macro provides a way to let standard
17 // libcalls reach the link step instead of being eagerly replaced.
18 #ifndef __CLANG_GPU_DISABLE_MATH_WRAPPERS
19
20 #if !defined(__HIPCC_RTC__)
21 #include <limits.h>
22 #include <stdint.h>
23 #ifdef __OPENMP_AMDGCN__
24 #include <omp.h>
25 #endif
26 #endif // !defined(__HIPCC_RTC__)
27
28 #pragma push_macro("__DEVICE__")
29
30 #ifdef __OPENMP_AMDGCN__
31 #define __DEVICE__ static inline __attribute__((always_inline, nothrow))
32 #else
33 #define __DEVICE__ static __device__ inline __attribute__((always_inline))
34 #endif
35
36 #pragma push_macro("__PRIVATE_AS")
37
38 #define __PRIVATE_AS __attribute__((opencl_private))
39 // Device library provides fast low precision and slow full-recision
40 // implementations for some functions. Which one gets selected depends on
41 // __CLANG_GPU_APPROX_TRANSCENDENTALS__ which gets defined by clang if
42 // -ffast-math or -fgpu-approx-transcendentals are in effect.
43 #pragma push_macro("__FAST_OR_SLOW")
44 #if defined(__CLANG_GPU_APPROX_TRANSCENDENTALS__)
45 #define __FAST_OR_SLOW(fast, slow) fast
46 #else
47 #define __FAST_OR_SLOW(fast, slow) slow
48 #endif
49
50 // A few functions return bool type starting only in C++11.
51 #pragma push_macro("__RETURN_TYPE")
52 #ifdef __OPENMP_AMDGCN__
53 #define __RETURN_TYPE int
54 #else
55 #if defined(__cplusplus)
56 #define __RETURN_TYPE bool
57 #else
58 #define __RETURN_TYPE int
59 #endif
60 #endif // __OPENMP_AMDGCN__
61
62 #if defined (__cplusplus) && __cplusplus < 201103L
63 // emulate static_assert on type sizes
64 template<bool>
65 struct __compare_result{};
66 template<>
67 struct __compare_result<true> {
68 static const __device__ bool valid;
69 };
70
71 __DEVICE__
72 void __suppress_unused_warning(bool b){};
73 template <unsigned int S, unsigned int T>
74 __DEVICE__ void __static_assert_equal_size() {
75 __suppress_unused_warning(__compare_result<S == T>::valid);
76 }
77
78 #define __static_assert_type_size_equal(A, B) \
79 __static_assert_equal_size<A,B>()
80
81 #else
82 #define __static_assert_type_size_equal(A,B) \
83 static_assert((A) == (B), "")
84
85 #endif
86
87 __DEVICE__
88 uint64_t __make_mantissa_base8(const char *__tagp __attribute__((nonnull))) {
89 uint64_t __r = 0;
90 while (*__tagp != '\0') {
91 char __tmp = *__tagp;
92
93 if (__tmp >= '0' && __tmp <= '7')
94 __r = (__r * 8u) + __tmp - '0';
95 else
96 return 0;
97
98 ++__tagp;
99 }
100
101 return __r;
102 }
103
104 __DEVICE__
105 uint64_t __make_mantissa_base10(const char *__tagp __attribute__((nonnull))) {
106 uint64_t __r = 0;
107 while (*__tagp != '\0') {
108 char __tmp = *__tagp;
109
110 if (__tmp >= '0' && __tmp <= '9')
111 __r = (__r * 10u) + __tmp - '0';
112 else
113 return 0;
114
115 ++__tagp;
116 }
117
118 return __r;
119 }
120
121 __DEVICE__
122 uint64_t __make_mantissa_base16(const char *__tagp __attribute__((nonnull))) {
123 uint64_t __r = 0;
124 while (*__tagp != '\0') {
125 char __tmp = *__tagp;
126
127 if (__tmp >= '0' && __tmp <= '9')
128 __r = (__r * 16u) + __tmp - '0';
129 else if (__tmp >= 'a' && __tmp <= 'f')
130 __r = (__r * 16u) + __tmp - 'a' + 10;
131 else if (__tmp >= 'A' && __tmp <= 'F')
132 __r = (__r * 16u) + __tmp - 'A' + 10;
133 else
134 return 0;
135
136 ++__tagp;
137 }
138
139 return __r;
140 }
141
142 __DEVICE__
143 uint64_t __make_mantissa(const char *__tagp __attribute__((nonnull))) {
144 if (*__tagp == '0') {
145 ++__tagp;
146
147 if (*__tagp == 'x' || *__tagp == 'X')
148 return __make_mantissa_base16(__tagp);
149 else
150 return __make_mantissa_base8(__tagp);
151 }
152
153 return __make_mantissa_base10(__tagp);
154 }
155
156 // BEGIN FLOAT
157
158 // BEGIN INTRINSICS
159
160 __DEVICE__
161 float __cosf(float __x) { return __ocml_native_cos_f32(__x); }
162
163 __DEVICE__
164 float __exp10f(float __x) {
165 const float __log2_10 = 0x1.a934f0p+1f;
166 return __builtin_amdgcn_exp2f(__log2_10 * __x);
167 }
168
169 __DEVICE__
170 float __expf(float __x) {
171 const float __log2_e = 0x1.715476p+0;
172 return __builtin_amdgcn_exp2f(__log2_e * __x);
173 }
174
175 #if defined OCML_BASIC_ROUNDED_OPERATIONS
176 __DEVICE__
177 float __fadd_rd(float __x, float __y) { return __ocml_add_rtn_f32(__x, __y); }
178 __DEVICE__
179 float __fadd_rn(float __x, float __y) { return __ocml_add_rte_f32(__x, __y); }
180 __DEVICE__
181 float __fadd_ru(float __x, float __y) { return __ocml_add_rtp_f32(__x, __y); }
182 __DEVICE__
183 float __fadd_rz(float __x, float __y) { return __ocml_add_rtz_f32(__x, __y); }
184 #else
185 __DEVICE__
186 float __fadd_rn(float __x, float __y) { return __x + __y; }
187 #endif
188
189 #if defined OCML_BASIC_ROUNDED_OPERATIONS
190 __DEVICE__
191 float __fdiv_rd(float __x, float __y) { return __ocml_div_rtn_f32(__x, __y); }
192 __DEVICE__
193 float __fdiv_rn(float __x, float __y) { return __ocml_div_rte_f32(__x, __y); }
194 __DEVICE__
195 float __fdiv_ru(float __x, float __y) { return __ocml_div_rtp_f32(__x, __y); }
196 __DEVICE__
197 float __fdiv_rz(float __x, float __y) { return __ocml_div_rtz_f32(__x, __y); }
198 #else
199 __DEVICE__
200 float __fdiv_rn(float __x, float __y) { return __x / __y; }
201 #endif
202
203 __DEVICE__
204 float __fdividef(float __x, float __y) { return __x / __y; }
205
206 #if defined OCML_BASIC_ROUNDED_OPERATIONS
207 __DEVICE__
208 float __fmaf_rd(float __x, float __y, float __z) {
209 return __ocml_fma_rtn_f32(__x, __y, __z);
210 }
211 __DEVICE__
212 float __fmaf_rn(float __x, float __y, float __z) {
213 return __ocml_fma_rte_f32(__x, __y, __z);
214 }
215 __DEVICE__
216 float __fmaf_ru(float __x, float __y, float __z) {
217 return __ocml_fma_rtp_f32(__x, __y, __z);
218 }
219 __DEVICE__
220 float __fmaf_rz(float __x, float __y, float __z) {
221 return __ocml_fma_rtz_f32(__x, __y, __z);
222 }
223 #else
224 __DEVICE__
225 float __fmaf_rn(float __x, float __y, float __z) {
226 return __builtin_fmaf(__x, __y, __z);
227 }
228 #endif
229
230 #if defined OCML_BASIC_ROUNDED_OPERATIONS
231 __DEVICE__
232 float __fmul_rd(float __x, float __y) { return __ocml_mul_rtn_f32(__x, __y); }
233 __DEVICE__
234 float __fmul_rn(float __x, float __y) { return __ocml_mul_rte_f32(__x, __y); }
235 __DEVICE__
236 float __fmul_ru(float __x, float __y) { return __ocml_mul_rtp_f32(__x, __y); }
237 __DEVICE__
238 float __fmul_rz(float __x, float __y) { return __ocml_mul_rtz_f32(__x, __y); }
239 #else
240 __DEVICE__
241 float __fmul_rn(float __x, float __y) { return __x * __y; }
242 #endif
243
244 #if defined OCML_BASIC_ROUNDED_OPERATIONS
245 __DEVICE__
246 float __frcp_rd(float __x) { return __ocml_div_rtn_f32(1.0f, __x); }
247 __DEVICE__
248 float __frcp_rn(float __x) { return __ocml_div_rte_f32(1.0f, __x); }
249 __DEVICE__
250 float __frcp_ru(float __x) { return __ocml_div_rtp_f32(1.0f, __x); }
251 __DEVICE__
252 float __frcp_rz(float __x) { return __ocml_div_rtz_f32(1.0f, __x); }
253 #else
254 __DEVICE__
255 float __frcp_rn(float __x) { return 1.0f / __x; }
256 #endif
257
258 __DEVICE__
259 float __frsqrt_rn(float __x) { return __builtin_amdgcn_rsqf(__x); }
260
261 #if defined OCML_BASIC_ROUNDED_OPERATIONS
262 __DEVICE__
263 float __fsqrt_rd(float __x) { return __ocml_sqrt_rtn_f32(__x); }
264 __DEVICE__
265 float __fsqrt_rn(float __x) { return __ocml_sqrt_rte_f32(__x); }
266 __DEVICE__
267 float __fsqrt_ru(float __x) { return __ocml_sqrt_rtp_f32(__x); }
268 __DEVICE__
269 float __fsqrt_rz(float __x) { return __ocml_sqrt_rtz_f32(__x); }
270 #else
271 __DEVICE__
272 float __fsqrt_rn(float __x) { return __ocml_native_sqrt_f32(__x); }
273 #endif
274
275 #if defined OCML_BASIC_ROUNDED_OPERATIONS
276 __DEVICE__
277 float __fsub_rd(float __x, float __y) { return __ocml_sub_rtn_f32(__x, __y); }
278 __DEVICE__
279 float __fsub_rn(float __x, float __y) { return __ocml_sub_rte_f32(__x, __y); }
280 __DEVICE__
281 float __fsub_ru(float __x, float __y) { return __ocml_sub_rtp_f32(__x, __y); }
282 __DEVICE__
283 float __fsub_rz(float __x, float __y) { return __ocml_sub_rtz_f32(__x, __y); }
284 #else
285 __DEVICE__
286 float __fsub_rn(float __x, float __y) { return __x - __y; }
287 #endif
288
289 __DEVICE__
290 float __log10f(float __x) { return __builtin_log10f(__x); }
291
292 __DEVICE__
293 float __log2f(float __x) { return __builtin_amdgcn_logf(__x); }
294
295 __DEVICE__
296 float __logf(float __x) { return __builtin_logf(__x); }
297
298 __DEVICE__
299 float __powf(float __x, float __y) { return __ocml_pow_f32(__x, __y); }
300
301 __DEVICE__
302 float __saturatef(float __x) { return (__x < 0) ? 0 : ((__x > 1) ? 1 : __x); }
303
304 __DEVICE__
305 void __sincosf(float __x, float *__sinptr, float *__cosptr) {
306 *__sinptr = __ocml_native_sin_f32(__x);
307 *__cosptr = __ocml_native_cos_f32(__x);
308 }
309
310 __DEVICE__
311 float __sinf(float __x) { return __ocml_native_sin_f32(__x); }
312
313 __DEVICE__
314 float __tanf(float __x) {
315 return __sinf(__x) * __builtin_amdgcn_rcpf(__cosf(__x));
316 }
317 // END INTRINSICS
318
319 #if defined(__cplusplus)
320 __DEVICE__
321 int abs(int __x) {
322 return __builtin_abs(__x);
323 }
324 __DEVICE__
325 long labs(long __x) {
326 return __builtin_labs(__x);
327 }
328 __DEVICE__
329 long long llabs(long long __x) {
330 return __builtin_llabs(__x);
331 }
332 #endif
333
334 __DEVICE__
335 float acosf(float __x) { return __ocml_acos_f32(__x); }
336
337 __DEVICE__
338 float acoshf(float __x) { return __ocml_acosh_f32(__x); }
339
340 __DEVICE__
341 float asinf(float __x) { return __ocml_asin_f32(__x); }
342
343 __DEVICE__
344 float asinhf(float __x) { return __ocml_asinh_f32(__x); }
345
346 __DEVICE__
347 float atan2f(float __x, float __y) { return __ocml_atan2_f32(__x, __y); }
348
349 __DEVICE__
350 float atanf(float __x) { return __ocml_atan_f32(__x); }
351
352 __DEVICE__
353 float atanhf(float __x) { return __ocml_atanh_f32(__x); }
354
355 __DEVICE__
356 float cbrtf(float __x) { return __ocml_cbrt_f32(__x); }
357
358 __DEVICE__
359 float ceilf(float __x) { return __builtin_ceilf(__x); }
360
361 __DEVICE__
362 float copysignf(float __x, float __y) { return __builtin_copysignf(__x, __y); }
363
364 __DEVICE__
365 float cosf(float __x) { return __FAST_OR_SLOW(__cosf, __ocml_cos_f32)(__x); }
366
367 __DEVICE__
368 float coshf(float __x) { return __ocml_cosh_f32(__x); }
369
370 __DEVICE__
371 float cospif(float __x) { return __ocml_cospi_f32(__x); }
372
373 __DEVICE__
374 float cyl_bessel_i0f(float __x) { return __ocml_i0_f32(__x); }
375
376 __DEVICE__
377 float cyl_bessel_i1f(float __x) { return __ocml_i1_f32(__x); }
378
379 __DEVICE__
380 float erfcf(float __x) { return __ocml_erfc_f32(__x); }
381
382 __DEVICE__
383 float erfcinvf(float __x) { return __ocml_erfcinv_f32(__x); }
384
385 __DEVICE__
386 float erfcxf(float __x) { return __ocml_erfcx_f32(__x); }
387
388 __DEVICE__
389 float erff(float __x) { return __ocml_erf_f32(__x); }
390
391 __DEVICE__
392 float erfinvf(float __x) { return __ocml_erfinv_f32(__x); }
393
394 __DEVICE__
395 float exp10f(float __x) { return __builtin_exp10f(__x); }
396
397 __DEVICE__
398 float exp2f(float __x) { return __builtin_exp2f(__x); }
399
400 __DEVICE__
401 float expf(float __x) { return __builtin_expf(__x); }
402
403 __DEVICE__
404 float expm1f(float __x) { return __ocml_expm1_f32(__x); }
405
406 __DEVICE__
407 float fabsf(float __x) { return __builtin_fabsf(__x); }
408
409 __DEVICE__
410 float fdimf(float __x, float __y) { return __ocml_fdim_f32(__x, __y); }
411
412 __DEVICE__
413 float fdividef(float __x, float __y) { return __x / __y; }
414
415 __DEVICE__
416 float floorf(float __x) { return __builtin_floorf(__x); }
417
418 __DEVICE__
419 float fmaf(float __x, float __y, float __z) {
420 return __builtin_fmaf(__x, __y, __z);
421 }
422
423 __DEVICE__
424 float fmaxf(float __x, float __y) { return __builtin_fmaxf(__x, __y); }
425
426 __DEVICE__
427 float fminf(float __x, float __y) { return __builtin_fminf(__x, __y); }
428
429 __DEVICE__
430 float fmodf(float __x, float __y) { return __ocml_fmod_f32(__x, __y); }
431
432 __DEVICE__
433 float frexpf(float __x, int *__nptr) {
434 return __builtin_frexpf(__x, __nptr);
435 }
436
437 __DEVICE__
438 float hypotf(float __x, float __y) { return __ocml_hypot_f32(__x, __y); }
439
440 __DEVICE__
441 int ilogbf(float __x) { return __ocml_ilogb_f32(__x); }
442
443 __DEVICE__
444 __RETURN_TYPE __finitef(float __x) { return __builtin_isfinite(__x); }
445
446 __DEVICE__
447 __RETURN_TYPE __isinff(float __x) { return __builtin_isinf(__x); }
448
449 __DEVICE__
450 __RETURN_TYPE __isnanf(float __x) { return __builtin_isnan(__x); }
451
452 __DEVICE__
453 float j0f(float __x) { return __ocml_j0_f32(__x); }
454
455 __DEVICE__
456 float j1f(float __x) { return __ocml_j1_f32(__x); }
457
458 __DEVICE__
459 float jnf(int __n, float __x) { // TODO: we could use Ahmes multiplication
460 // and the Miller & Brown algorithm
461 // for linear recurrences to get O(log n) steps, but it's unclear if
462 // it'd be beneficial in this case.
463 if (__n == 0)
464 return j0f(__x);
465 if (__n == 1)
466 return j1f(__x);
467
468 float __x0 = j0f(__x);
469 float __x1 = j1f(__x);
470 for (int __i = 1; __i < __n; ++__i) {
471 float __x2 = (2 * __i) / __x * __x1 - __x0;
472 __x0 = __x1;
473 __x1 = __x2;
474 }
475
476 return __x1;
477 }
478
479 __DEVICE__
480 float ldexpf(float __x, int __e) { return __builtin_amdgcn_ldexpf(__x, __e); }
481
482 __DEVICE__
483 float lgammaf(float __x) { return __ocml_lgamma_f32(__x); }
484
485 __DEVICE__
486 long long int llrintf(float __x) { return __builtin_rintf(__x); }
487
488 __DEVICE__
489 long long int llroundf(float __x) { return __builtin_roundf(__x); }
490
491 __DEVICE__
492 float log10f(float __x) { return __builtin_log10f(__x); }
493
494 __DEVICE__
495 float log1pf(float __x) { return __ocml_log1p_f32(__x); }
496
497 __DEVICE__
498 float log2f(float __x) { return __FAST_OR_SLOW(__log2f, __builtin_log2f)(__x); }
499
500 __DEVICE__
501 float logbf(float __x) { return __builtin_logbf(__x); }
502
503 __DEVICE__
504 float logf(float __x) { return __FAST_OR_SLOW(__logf, __builtin_logf)(__x); }
505
506 __DEVICE__
507 long int lrintf(float __x) { return __builtin_rintf(__x); }
508
509 __DEVICE__
510 long int lroundf(float __x) { return __builtin_roundf(__x); }
511
512 __DEVICE__
513 float modff(float __x, float *__iptr) {
514 float __tmp;
515 #ifdef __OPENMP_AMDGCN__
516 #pragma omp allocate(__tmp) allocator(omp_thread_mem_alloc)
517 #endif
518 float __r = __ocml_modf_f32(__x, (__PRIVATE_AS float *)&__tmp);
519 *__iptr = __tmp;
520 return __r;
521 }
522
523 __DEVICE__
524 float nanf(const char *__tagp __attribute__((nonnull))) {
525 union {
526 float val;
527 struct ieee_float {
528 unsigned int mantissa : 22;
529 unsigned int quiet : 1;
530 unsigned int exponent : 8;
531 unsigned int sign : 1;
532 } bits;
533 } __tmp;
534 __static_assert_type_size_equal(sizeof(__tmp.val), sizeof(__tmp.bits));
535
536 __tmp.bits.sign = 0u;
537 __tmp.bits.exponent = ~0u;
538 __tmp.bits.quiet = 1u;
539 __tmp.bits.mantissa = __make_mantissa(__tagp);
540
541 return __tmp.val;
542 }
543
544 __DEVICE__
545 float nearbyintf(float __x) { return __builtin_nearbyintf(__x); }
546
547 __DEVICE__
548 float nextafterf(float __x, float __y) {
549 return __ocml_nextafter_f32(__x, __y);
550 }
551
552 __DEVICE__
553 float norm3df(float __x, float __y, float __z) {
554 return __ocml_len3_f32(__x, __y, __z);
555 }
556
557 __DEVICE__
558 float norm4df(float __x, float __y, float __z, float __w) {
559 return __ocml_len4_f32(__x, __y, __z, __w);
560 }
561
562 __DEVICE__
563 float normcdff(float __x) { return __ocml_ncdf_f32(__x); }
564
565 __DEVICE__
566 float normcdfinvf(float __x) { return __ocml_ncdfinv_f32(__x); }
567
568 __DEVICE__
569 float normf(int __dim,
570 const float *__a) { // TODO: placeholder until OCML adds support.
571 float __r = 0;
572 while (__dim--) {
573 __r += __a[0] * __a[0];
574 ++__a;
575 }
576
577 return __builtin_sqrtf(__r);
578 }
579
580 __DEVICE__
581 float powf(float __x, float __y) { return __ocml_pow_f32(__x, __y); }
582
583 __DEVICE__
584 float powif(float __x, int __y) { return __ocml_pown_f32(__x, __y); }
585
586 __DEVICE__
587 float rcbrtf(float __x) { return __ocml_rcbrt_f32(__x); }
588
589 __DEVICE__
590 float remainderf(float __x, float __y) {
591 return __ocml_remainder_f32(__x, __y);
592 }
593
594 __DEVICE__
595 float remquof(float __x, float __y, int *__quo) {
596 int __tmp;
597 #ifdef __OPENMP_AMDGCN__
598 #pragma omp allocate(__tmp) allocator(omp_thread_mem_alloc)
599 #endif
600 float __r = __ocml_remquo_f32(__x, __y, (__PRIVATE_AS int *)&__tmp);
601 *__quo = __tmp;
602
603 return __r;
604 }
605
606 __DEVICE__
607 float rhypotf(float __x, float __y) { return __ocml_rhypot_f32(__x, __y); }
608
609 __DEVICE__
610 float rintf(float __x) { return __builtin_rintf(__x); }
611
612 __DEVICE__
613 float rnorm3df(float __x, float __y, float __z) {
614 return __ocml_rlen3_f32(__x, __y, __z);
615 }
616
617 __DEVICE__
618 float rnorm4df(float __x, float __y, float __z, float __w) {
619 return __ocml_rlen4_f32(__x, __y, __z, __w);
620 }
621
622 __DEVICE__
623 float rnormf(int __dim,
624 const float *__a) { // TODO: placeholder until OCML adds support.
625 float __r = 0;
626 while (__dim--) {
627 __r += __a[0] * __a[0];
628 ++__a;
629 }
630
631 return __ocml_rsqrt_f32(__r);
632 }
633
634 __DEVICE__
635 float roundf(float __x) { return __builtin_roundf(__x); }
636
637 __DEVICE__
638 float rsqrtf(float __x) { return __ocml_rsqrt_f32(__x); }
639
640 __DEVICE__
641 float scalblnf(float __x, long int __n) {
642 if (__n > INT_MAX)
643 __n = INT_MAX;
644 else if (__n < INT_MIN)
645 __n = INT_MIN;
646 return __builtin_ldexpf(__x, (int)__n);
647 }
648
649 __DEVICE__
650 float scalbnf(float __x, int __n) { return __builtin_amdgcn_ldexpf(__x, __n); }
651
652 __DEVICE__
653 __RETURN_TYPE __signbitf(float __x) { return __builtin_signbitf(__x); }
654
655 __DEVICE__
656 void sincosf(float __x, float *__sinptr, float *__cosptr) {
657 float __tmp;
658 #ifdef __OPENMP_AMDGCN__
659 #pragma omp allocate(__tmp) allocator(omp_thread_mem_alloc)
660 #endif
661 #ifdef __CLANG_CUDA_APPROX_TRANSCENDENTALS__
662 __sincosf(__x, __sinptr, __cosptr);
663 #else
664 *__sinptr = __ocml_sincos_f32(__x, (__PRIVATE_AS float *)&__tmp);
665 *__cosptr = __tmp;
666 #endif
667 }
668
669 __DEVICE__
670 void sincospif(float __x, float *__sinptr, float *__cosptr) {
671 float __tmp;
672 #ifdef __OPENMP_AMDGCN__
673 #pragma omp allocate(__tmp) allocator(omp_thread_mem_alloc)
674 #endif
675 *__sinptr = __ocml_sincospi_f32(__x, (__PRIVATE_AS float *)&__tmp);
676 *__cosptr = __tmp;
677 }
678
679 __DEVICE__
680 float sinf(float __x) { return __FAST_OR_SLOW(__sinf, __ocml_sin_f32)(__x); }
681
682 __DEVICE__
683 float sinhf(float __x) { return __ocml_sinh_f32(__x); }
684
685 __DEVICE__
686 float sinpif(float __x) { return __ocml_sinpi_f32(__x); }
687
688 __DEVICE__
689 float sqrtf(float __x) { return __builtin_sqrtf(__x); }
690
691 __DEVICE__
692 float tanf(float __x) { return __ocml_tan_f32(__x); }
693
694 __DEVICE__
695 float tanhf(float __x) { return __ocml_tanh_f32(__x); }
696
697 __DEVICE__
698 float tgammaf(float __x) { return __ocml_tgamma_f32(__x); }
699
700 __DEVICE__
701 float truncf(float __x) { return __builtin_truncf(__x); }
702
703 __DEVICE__
704 float y0f(float __x) { return __ocml_y0_f32(__x); }
705
706 __DEVICE__
707 float y1f(float __x) { return __ocml_y1_f32(__x); }
708
709 __DEVICE__
710 float ynf(int __n, float __x) { // TODO: we could use Ahmes multiplication
711 // and the Miller & Brown algorithm
712 // for linear recurrences to get O(log n) steps, but it's unclear if
713 // it'd be beneficial in this case. Placeholder until OCML adds
714 // support.
715 if (__n == 0)
716 return y0f(__x);
717 if (__n == 1)
718 return y1f(__x);
719
720 float __x0 = y0f(__x);
721 float __x1 = y1f(__x);
722 for (int __i = 1; __i < __n; ++__i) {
723 float __x2 = (2 * __i) / __x * __x1 - __x0;
724 __x0 = __x1;
725 __x1 = __x2;
726 }
727
728 return __x1;
729 }
730
731
732 // END FLOAT
733
734 // BEGIN DOUBLE
735 __DEVICE__
736 double acos(double __x) { return __ocml_acos_f64(__x); }
737
738 __DEVICE__
739 double acosh(double __x) { return __ocml_acosh_f64(__x); }
740
741 __DEVICE__
742 double asin(double __x) { return __ocml_asin_f64(__x); }
743
744 __DEVICE__
745 double asinh(double __x) { return __ocml_asinh_f64(__x); }
746
747 __DEVICE__
748 double atan(double __x) { return __ocml_atan_f64(__x); }
749
750 __DEVICE__
751 double atan2(double __x, double __y) { return __ocml_atan2_f64(__x, __y); }
752
753 __DEVICE__
754 double atanh(double __x) { return __ocml_atanh_f64(__x); }
755
756 __DEVICE__
757 double cbrt(double __x) { return __ocml_cbrt_f64(__x); }
758
759 __DEVICE__
760 double ceil(double __x) { return __builtin_ceil(__x); }
761
762 __DEVICE__
763 double copysign(double __x, double __y) {
764 return __builtin_copysign(__x, __y);
765 }
766
767 __DEVICE__
768 double cos(double __x) { return __ocml_cos_f64(__x); }
769
770 __DEVICE__
771 double cosh(double __x) { return __ocml_cosh_f64(__x); }
772
773 __DEVICE__
774 double cospi(double __x) { return __ocml_cospi_f64(__x); }
775
776 __DEVICE__
777 double cyl_bessel_i0(double __x) { return __ocml_i0_f64(__x); }
778
779 __DEVICE__
780 double cyl_bessel_i1(double __x) { return __ocml_i1_f64(__x); }
781
782 __DEVICE__
783 double erf(double __x) { return __ocml_erf_f64(__x); }
784
785 __DEVICE__
786 double erfc(double __x) { return __ocml_erfc_f64(__x); }
787
788 __DEVICE__
789 double erfcinv(double __x) { return __ocml_erfcinv_f64(__x); }
790
791 __DEVICE__
792 double erfcx(double __x) { return __ocml_erfcx_f64(__x); }
793
794 __DEVICE__
795 double erfinv(double __x) { return __ocml_erfinv_f64(__x); }
796
797 __DEVICE__
798 double exp(double __x) { return __ocml_exp_f64(__x); }
799
800 __DEVICE__
801 double exp10(double __x) { return __ocml_exp10_f64(__x); }
802
803 __DEVICE__
804 double exp2(double __x) { return __ocml_exp2_f64(__x); }
805
806 __DEVICE__
807 double expm1(double __x) { return __ocml_expm1_f64(__x); }
808
809 __DEVICE__
810 double fabs(double __x) { return __builtin_fabs(__x); }
811
812 __DEVICE__
813 double fdim(double __x, double __y) { return __ocml_fdim_f64(__x, __y); }
814
815 __DEVICE__
816 double floor(double __x) { return __builtin_floor(__x); }
817
818 __DEVICE__
819 double fma(double __x, double __y, double __z) {
820 return __builtin_fma(__x, __y, __z);
821 }
822
823 __DEVICE__
824 double fmax(double __x, double __y) { return __builtin_fmax(__x, __y); }
825
826 __DEVICE__
827 double fmin(double __x, double __y) { return __builtin_fmin(__x, __y); }
828
829 __DEVICE__
830 double fmod(double __x, double __y) { return __ocml_fmod_f64(__x, __y); }
831
832 __DEVICE__
833 double frexp(double __x, int *__nptr) {
834 return __builtin_frexp(__x, __nptr);
835 }
836
837 __DEVICE__
838 double hypot(double __x, double __y) { return __ocml_hypot_f64(__x, __y); }
839
840 __DEVICE__
841 int ilogb(double __x) { return __ocml_ilogb_f64(__x); }
842
843 __DEVICE__
844 __RETURN_TYPE __finite(double __x) { return __builtin_isfinite(__x); }
845
846 __DEVICE__
847 __RETURN_TYPE __isinf(double __x) { return __builtin_isinf(__x); }
848
849 __DEVICE__
850 __RETURN_TYPE __isnan(double __x) { return __builtin_isnan(__x); }
851
852 __DEVICE__
853 double j0(double __x) { return __ocml_j0_f64(__x); }
854
855 __DEVICE__
856 double j1(double __x) { return __ocml_j1_f64(__x); }
857
858 __DEVICE__
859 double jn(int __n, double __x) { // TODO: we could use Ahmes multiplication
860 // and the Miller & Brown algorithm
861 // for linear recurrences to get O(log n) steps, but it's unclear if
862 // it'd be beneficial in this case. Placeholder until OCML adds
863 // support.
864 if (__n == 0)
865 return j0(__x);
866 if (__n == 1)
867 return j1(__x);
868
869 double __x0 = j0(__x);
870 double __x1 = j1(__x);
871 for (int __i = 1; __i < __n; ++__i) {
872 double __x2 = (2 * __i) / __x * __x1 - __x0;
873 __x0 = __x1;
874 __x1 = __x2;
875 }
876 return __x1;
877 }
878
879 __DEVICE__
880 double ldexp(double __x, int __e) { return __builtin_amdgcn_ldexp(__x, __e); }
881
882 __DEVICE__
883 double lgamma(double __x) { return __ocml_lgamma_f64(__x); }
884
885 __DEVICE__
886 long long int llrint(double __x) { return __builtin_rint(__x); }
887
888 __DEVICE__
889 long long int llround(double __x) { return __builtin_round(__x); }
890
891 __DEVICE__
892 double log(double __x) { return __ocml_log_f64(__x); }
893
894 __DEVICE__
895 double log10(double __x) { return __ocml_log10_f64(__x); }
896
897 __DEVICE__
898 double log1p(double __x) { return __ocml_log1p_f64(__x); }
899
900 __DEVICE__
901 double log2(double __x) { return __ocml_log2_f64(__x); }
902
903 __DEVICE__
904 double logb(double __x) { return __builtin_logb(__x); }
905
906 __DEVICE__
907 long int lrint(double __x) { return __builtin_rint(__x); }
908
909 __DEVICE__
910 long int lround(double __x) { return __builtin_round(__x); }
911
912 __DEVICE__
913 double modf(double __x, double *__iptr) {
914 double __tmp;
915 #ifdef __OPENMP_AMDGCN__
916 #pragma omp allocate(__tmp) allocator(omp_thread_mem_alloc)
917 #endif
918 double __r = __ocml_modf_f64(__x, (__PRIVATE_AS double *)&__tmp);
919 *__iptr = __tmp;
920
921 return __r;
922 }
923
924 __DEVICE__
925 double nan(const char *__tagp) {
926 #if !_WIN32
927 union {
928 double val;
929 struct ieee_double {
930 uint64_t mantissa : 51;
931 uint32_t quiet : 1;
932 uint32_t exponent : 11;
933 uint32_t sign : 1;
934 } bits;
935 } __tmp;
936 __static_assert_type_size_equal(sizeof(__tmp.val), sizeof(__tmp.bits));
937
938 __tmp.bits.sign = 0u;
939 __tmp.bits.exponent = ~0u;
940 __tmp.bits.quiet = 1u;
941 __tmp.bits.mantissa = __make_mantissa(__tagp);
942
943 return __tmp.val;
944 #else
945 __static_assert_type_size_equal(sizeof(uint64_t), sizeof(double));
946 uint64_t __val = __make_mantissa(__tagp);
947 __val |= 0xFFF << 51;
948 return *reinterpret_cast<double *>(&__val);
949 #endif
950 }
951
952 __DEVICE__
953 double nearbyint(double __x) { return __builtin_nearbyint(__x); }
954
955 __DEVICE__
956 double nextafter(double __x, double __y) {
957 return __ocml_nextafter_f64(__x, __y);
958 }
959
960 __DEVICE__
961 double norm(int __dim,
962 const double *__a) { // TODO: placeholder until OCML adds support.
963 double __r = 0;
964 while (__dim--) {
965 __r += __a[0] * __a[0];
966 ++__a;
967 }
968
969 return __builtin_sqrt(__r);
970 }
971
972 __DEVICE__
973 double norm3d(double __x, double __y, double __z) {
974 return __ocml_len3_f64(__x, __y, __z);
975 }
976
977 __DEVICE__
978 double norm4d(double __x, double __y, double __z, double __w) {
979 return __ocml_len4_f64(__x, __y, __z, __w);
980 }
981
982 __DEVICE__
983 double normcdf(double __x) { return __ocml_ncdf_f64(__x); }
984
985 __DEVICE__
986 double normcdfinv(double __x) { return __ocml_ncdfinv_f64(__x); }
987
988 __DEVICE__
989 double pow(double __x, double __y) { return __ocml_pow_f64(__x, __y); }
990
991 __DEVICE__
992 double powi(double __x, int __y) { return __ocml_pown_f64(__x, __y); }
993
994 __DEVICE__
995 double rcbrt(double __x) { return __ocml_rcbrt_f64(__x); }
996
997 __DEVICE__
998 double remainder(double __x, double __y) {
999 return __ocml_remainder_f64(__x, __y);
1000 }
1001
1002 __DEVICE__
1003 double remquo(double __x, double __y, int *__quo) {
1004 int __tmp;
1005 #ifdef __OPENMP_AMDGCN__
1006 #pragma omp allocate(__tmp) allocator(omp_thread_mem_alloc)
1007 #endif
1008 double __r = __ocml_remquo_f64(__x, __y, (__PRIVATE_AS int *)&__tmp);
1009 *__quo = __tmp;
1010
1011 return __r;
1012 }
1013
1014 __DEVICE__
1015 double rhypot(double __x, double __y) { return __ocml_rhypot_f64(__x, __y); }
1016
1017 __DEVICE__
1018 double rint(double __x) { return __builtin_rint(__x); }
1019
1020 __DEVICE__
1021 double rnorm(int __dim,
1022 const double *__a) { // TODO: placeholder until OCML adds support.
1023 double __r = 0;
1024 while (__dim--) {
1025 __r += __a[0] * __a[0];
1026 ++__a;
1027 }
1028
1029 return __ocml_rsqrt_f64(__r);
1030 }
1031
1032 __DEVICE__
1033 double rnorm3d(double __x, double __y, double __z) {
1034 return __ocml_rlen3_f64(__x, __y, __z);
1035 }
1036
1037 __DEVICE__
1038 double rnorm4d(double __x, double __y, double __z, double __w) {
1039 return __ocml_rlen4_f64(__x, __y, __z, __w);
1040 }
1041
1042 __DEVICE__
1043 double round(double __x) { return __builtin_round(__x); }
1044
1045 __DEVICE__
1046 double rsqrt(double __x) { return __ocml_rsqrt_f64(__x); }
1047
1048 __DEVICE__
1049 double scalbln(double __x, long int __n) {
1050 if (__n > INT_MAX)
1051 __n = INT_MAX;
1052 else if (__n < INT_MIN)
1053 __n = INT_MIN;
1054 return __builtin_ldexp(__x, (int)__n);
1055 }
1056 __DEVICE__
1057 double scalbn(double __x, int __n) { return __builtin_amdgcn_ldexp(__x, __n); }
1058
1059 __DEVICE__
1060 __RETURN_TYPE __signbit(double __x) { return __builtin_signbit(__x); }
1061
1062 __DEVICE__
1063 double sin(double __x) { return __ocml_sin_f64(__x); }
1064
1065 __DEVICE__
1066 void sincos(double __x, double *__sinptr, double *__cosptr) {
1067 double __tmp;
1068 #ifdef __OPENMP_AMDGCN__
1069 #pragma omp allocate(__tmp) allocator(omp_thread_mem_alloc)
1070 #endif
1071 *__sinptr = __ocml_sincos_f64(__x, (__PRIVATE_AS double *)&__tmp);
1072 *__cosptr = __tmp;
1073 }
1074
1075 __DEVICE__
1076 void sincospi(double __x, double *__sinptr, double *__cosptr) {
1077 double __tmp;
1078 #ifdef __OPENMP_AMDGCN__
1079 #pragma omp allocate(__tmp) allocator(omp_thread_mem_alloc)
1080 #endif
1081 *__sinptr = __ocml_sincospi_f64(__x, (__PRIVATE_AS double *)&__tmp);
1082 *__cosptr = __tmp;
1083 }
1084
1085 __DEVICE__
1086 double sinh(double __x) { return __ocml_sinh_f64(__x); }
1087
1088 __DEVICE__
1089 double sinpi(double __x) { return __ocml_sinpi_f64(__x); }
1090
1091 __DEVICE__
1092 double sqrt(double __x) { return __builtin_sqrt(__x); }
1093
1094 __DEVICE__
1095 double tan(double __x) { return __ocml_tan_f64(__x); }
1096
1097 __DEVICE__
1098 double tanh(double __x) { return __ocml_tanh_f64(__x); }
1099
1100 __DEVICE__
1101 double tgamma(double __x) { return __ocml_tgamma_f64(__x); }
1102
1103 __DEVICE__
1104 double trunc(double __x) { return __builtin_trunc(__x); }
1105
1106 __DEVICE__
1107 double y0(double __x) { return __ocml_y0_f64(__x); }
1108
1109 __DEVICE__
1110 double y1(double __x) { return __ocml_y1_f64(__x); }
1111
1112 __DEVICE__
1113 double yn(int __n, double __x) { // TODO: we could use Ahmes multiplication
1114 // and the Miller & Brown algorithm
1115 // for linear recurrences to get O(log n) steps, but it's unclear if
1116 // it'd be beneficial in this case. Placeholder until OCML adds
1117 // support.
1118 if (__n == 0)
1119 return y0(__x);
1120 if (__n == 1)
1121 return y1(__x);
1122
1123 double __x0 = y0(__x);
1124 double __x1 = y1(__x);
1125 for (int __i = 1; __i < __n; ++__i) {
1126 double __x2 = (2 * __i) / __x * __x1 - __x0;
1127 __x0 = __x1;
1128 __x1 = __x2;
1129 }
1130
1131 return __x1;
1132 }
1133
1134 // BEGIN INTRINSICS
1135 #if defined OCML_BASIC_ROUNDED_OPERATIONS
1136 __DEVICE__
1137 double __dadd_rd(double __x, double __y) {
1138 return __ocml_add_rtn_f64(__x, __y);
1139 }
1140 __DEVICE__
1141 double __dadd_rn(double __x, double __y) {
1142 return __ocml_add_rte_f64(__x, __y);
1143 }
1144 __DEVICE__
1145 double __dadd_ru(double __x, double __y) {
1146 return __ocml_add_rtp_f64(__x, __y);
1147 }
1148 __DEVICE__
1149 double __dadd_rz(double __x, double __y) {
1150 return __ocml_add_rtz_f64(__x, __y);
1151 }
1152 #else
1153 __DEVICE__
1154 double __dadd_rn(double __x, double __y) { return __x + __y; }
1155 #endif
1156
1157 #if defined OCML_BASIC_ROUNDED_OPERATIONS
1158 __DEVICE__
1159 double __ddiv_rd(double __x, double __y) {
1160 return __ocml_div_rtn_f64(__x, __y);
1161 }
1162 __DEVICE__
1163 double __ddiv_rn(double __x, double __y) {
1164 return __ocml_div_rte_f64(__x, __y);
1165 }
1166 __DEVICE__
1167 double __ddiv_ru(double __x, double __y) {
1168 return __ocml_div_rtp_f64(__x, __y);
1169 }
1170 __DEVICE__
1171 double __ddiv_rz(double __x, double __y) {
1172 return __ocml_div_rtz_f64(__x, __y);
1173 }
1174 #else
1175 __DEVICE__
1176 double __ddiv_rn(double __x, double __y) { return __x / __y; }
1177 #endif
1178
1179 #if defined OCML_BASIC_ROUNDED_OPERATIONS
1180 __DEVICE__
1181 double __dmul_rd(double __x, double __y) {
1182 return __ocml_mul_rtn_f64(__x, __y);
1183 }
1184 __DEVICE__
1185 double __dmul_rn(double __x, double __y) {
1186 return __ocml_mul_rte_f64(__x, __y);
1187 }
1188 __DEVICE__
1189 double __dmul_ru(double __x, double __y) {
1190 return __ocml_mul_rtp_f64(__x, __y);
1191 }
1192 __DEVICE__
1193 double __dmul_rz(double __x, double __y) {
1194 return __ocml_mul_rtz_f64(__x, __y);
1195 }
1196 #else
1197 __DEVICE__
1198 double __dmul_rn(double __x, double __y) { return __x * __y; }
1199 #endif
1200
1201 #if defined OCML_BASIC_ROUNDED_OPERATIONS
1202 __DEVICE__
1203 double __drcp_rd(double __x) { return __ocml_div_rtn_f64(1.0, __x); }
1204 __DEVICE__
1205 double __drcp_rn(double __x) { return __ocml_div_rte_f64(1.0, __x); }
1206 __DEVICE__
1207 double __drcp_ru(double __x) { return __ocml_div_rtp_f64(1.0, __x); }
1208 __DEVICE__
1209 double __drcp_rz(double __x) { return __ocml_div_rtz_f64(1.0, __x); }
1210 #else
1211 __DEVICE__
1212 double __drcp_rn(double __x) { return 1.0 / __x; }
1213 #endif
1214
1215 #if defined OCML_BASIC_ROUNDED_OPERATIONS
1216 __DEVICE__
1217 double __dsqrt_rd(double __x) { return __ocml_sqrt_rtn_f64(__x); }
1218 __DEVICE__
1219 double __dsqrt_rn(double __x) { return __ocml_sqrt_rte_f64(__x); }
1220 __DEVICE__
1221 double __dsqrt_ru(double __x) { return __ocml_sqrt_rtp_f64(__x); }
1222 __DEVICE__
1223 double __dsqrt_rz(double __x) { return __ocml_sqrt_rtz_f64(__x); }
1224 #else
1225 __DEVICE__
1226 double __dsqrt_rn(double __x) { return __builtin_sqrt(__x); }
1227 #endif
1228
1229 #if defined OCML_BASIC_ROUNDED_OPERATIONS
1230 __DEVICE__
1231 double __dsub_rd(double __x, double __y) {
1232 return __ocml_sub_rtn_f64(__x, __y);
1233 }
1234 __DEVICE__
1235 double __dsub_rn(double __x, double __y) {
1236 return __ocml_sub_rte_f64(__x, __y);
1237 }
1238 __DEVICE__
1239 double __dsub_ru(double __x, double __y) {
1240 return __ocml_sub_rtp_f64(__x, __y);
1241 }
1242 __DEVICE__
1243 double __dsub_rz(double __x, double __y) {
1244 return __ocml_sub_rtz_f64(__x, __y);
1245 }
1246 #else
1247 __DEVICE__
1248 double __dsub_rn(double __x, double __y) { return __x - __y; }
1249 #endif
1250
1251 #if defined OCML_BASIC_ROUNDED_OPERATIONS
1252 __DEVICE__
1253 double __fma_rd(double __x, double __y, double __z) {
1254 return __ocml_fma_rtn_f64(__x, __y, __z);
1255 }
1256 __DEVICE__
1257 double __fma_rn(double __x, double __y, double __z) {
1258 return __ocml_fma_rte_f64(__x, __y, __z);
1259 }
1260 __DEVICE__
1261 double __fma_ru(double __x, double __y, double __z) {
1262 return __ocml_fma_rtp_f64(__x, __y, __z);
1263 }
1264 __DEVICE__
1265 double __fma_rz(double __x, double __y, double __z) {
1266 return __ocml_fma_rtz_f64(__x, __y, __z);
1267 }
1268 #else
1269 __DEVICE__
1270 double __fma_rn(double __x, double __y, double __z) {
1271 return __builtin_fma(__x, __y, __z);
1272 }
1273 #endif
1274 // END INTRINSICS
1275 // END DOUBLE
1276
1277 // C only macros
1278 #if !defined(__cplusplus) && __STDC_VERSION__ >= 201112L
1279 #define isfinite(__x) _Generic((__x), float : __finitef, double : __finite)(__x)
1280 #define isinf(__x) _Generic((__x), float : __isinff, double : __isinf)(__x)
1281 #define isnan(__x) _Generic((__x), float : __isnanf, double : __isnan)(__x)
1282 #define signbit(__x) \
1283 _Generic((__x), float : __signbitf, double : __signbit)(__x)
1284 #endif // !defined(__cplusplus) && __STDC_VERSION__ >= 201112L
1285
1286 #if defined(__cplusplus)
1287 template <class T> __DEVICE__ T min(T __arg1, T __arg2) {
1288 return (__arg1 < __arg2) ? __arg1 : __arg2;
1289 }
1290
1291 template <class T> __DEVICE__ T max(T __arg1, T __arg2) {
1292 return (__arg1 > __arg2) ? __arg1 : __arg2;
1293 }
1294
1295 __DEVICE__ int min(int __arg1, int __arg2) {
1296 return (__arg1 < __arg2) ? __arg1 : __arg2;
1297 }
1298 __DEVICE__ int max(int __arg1, int __arg2) {
1299 return (__arg1 > __arg2) ? __arg1 : __arg2;
1300 }
1301
1302 __DEVICE__
1303 float max(float __x, float __y) { return __builtin_fmaxf(__x, __y); }
1304
1305 __DEVICE__
1306 double max(double __x, double __y) { return __builtin_fmax(__x, __y); }
1307
1308 __DEVICE__
1309 float min(float __x, float __y) { return __builtin_fminf(__x, __y); }
1310
1311 __DEVICE__
1312 double min(double __x, double __y) { return __builtin_fmin(__x, __y); }
1313
1314 // Define host min/max functions.
1315 #if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) && \
1316 !defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
1317
1318 // TODO: make this default to 1 after existing HIP apps adopting this change.
1319 #ifndef __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__
1320 #define __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__ 0
1321 #endif
1322
1323 #ifndef __HIP_DEFINE_MIXED_HOST_MIN_MAX__
1324 #define __HIP_DEFINE_MIXED_HOST_MIN_MAX__ 0
1325 #endif
1326
1327 #pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
1328 #pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
1329 #define DEFINE_MIN_MAX_FUNCTIONS(ret_type, type1, type2) \
1330 inline ret_type min(const type1 __a, const type2 __b) { \
1331 return (__a < __b) ? __a : __b; \
1332 } \
1333 inline ret_type max(const type1 __a, const type2 __b) { \
1334 return (__a > __b) ? __a : __b; \
1335 }
1336
1337 // Define min and max functions for same type comparisons
1338 DEFINE_MIN_MAX_FUNCTIONS(int, int, int)
1339
1340 #if __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__
1341 DEFINE_MIN_MAX_FUNCTIONS(unsigned int, unsigned int, unsigned int)
1342 DEFINE_MIN_MAX_FUNCTIONS(long, long, long)
1343 DEFINE_MIN_MAX_FUNCTIONS(unsigned long, unsigned long, unsigned long)
1344 DEFINE_MIN_MAX_FUNCTIONS(long long, long long, long long)
1345 DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, unsigned long long,
1346 unsigned long long)
1347 #endif // if __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__
1348
1349 // The host min/max functions below accept mixed signed/unsigned integer
1350 // parameters and perform unsigned comparisons, which may produce unexpected
1351 // results if a signed integer was passed unintentionally. To avoid this
1352 // happening silently, these overloaded functions are not defined by default.
1353 // However, for compatibility with CUDA, they will be defined if users define
1354 // __HIP_DEFINE_MIXED_HOST_MIN_MAX__.
1355 #if __HIP_DEFINE_MIXED_HOST_MIN_MAX__
1356 DEFINE_MIN_MAX_FUNCTIONS(unsigned int, int, unsigned int)
1357 DEFINE_MIN_MAX_FUNCTIONS(unsigned int, unsigned int, int)
1358 DEFINE_MIN_MAX_FUNCTIONS(unsigned long, long, unsigned long)
1359 DEFINE_MIN_MAX_FUNCTIONS(unsigned long, unsigned long, long)
1360 DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, long long, unsigned long long)
1361 DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, unsigned long long, long long)
1362 #endif // if __HIP_DEFINE_MIXED_HOST_MIN_MAX__
1363
1364 // Floating-point comparisons using built-in functions
1365 #if __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__
1366 inline float min(float const __a, float const __b) {
1367 return __builtin_fminf(__a, __b);
1368 }
1369 inline double min(double const __a, double const __b) {
1370 return __builtin_fmin(__a, __b);
1371 }
1372 inline double min(float const __a, double const __b) {
1373 return __builtin_fmin(__a, __b);
1374 }
1375 inline double min(double const __a, float const __b) {
1376 return __builtin_fmin(__a, __b);
1377 }
1378
1379 inline float max(float const __a, float const __b) {
1380 return __builtin_fmaxf(__a, __b);
1381 }
1382 inline double max(double const __a, double const __b) {
1383 return __builtin_fmax(__a, __b);
1384 }
1385 inline double max(float const __a, double const __b) {
1386 return __builtin_fmax(__a, __b);
1387 }
1388 inline double max(double const __a, float const __b) {
1389 return __builtin_fmax(__a, __b);
1390 }
1391 #endif // if __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__
1392
1393 #pragma pop_macro("DEFINE_MIN_MAX_FUNCTIONS")
1394
1395 #endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) &&
1396 // !defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
1397 #endif
1398
1399 #pragma pop_macro("__DEVICE__")
1400 #pragma pop_macro("__PRIVATE_AS")
1401 #pragma pop_macro("__RETURN_TYPE")
1402 #pragma pop_macro("__FAST_OR_SLOW")
1403
1404 #endif // __CLANG_GPU_DISABLE_MATH_WRAPPERS
1405 #endif // __CLANG_HIP_MATH_H__