DPC++ Runtime
Runtime libraries for oneAPI DPC++
builtins_math.cpp
Go to the documentation of this file.
1 //==----------- builtins_math.cpp - SYCL built-in math functions -----------==//
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 // This file defines the host versions of functions defined
10 // in SYCL SPEC section - 4.13.3 Math functions.
11 
12 // Define _USE_MATH_DEFINES to enforce math defines of macros like M_PI in
13 // <cmath>. _USE_MATH_DEFINES is defined here before includes of SYCL header
14 // files to avoid include of <cmath> via those SYCL headers with unset
15 // _USE_MATH_DEFINES.
16 #define _USE_MATH_DEFINES
17 
18 #include "builtins_helper.hpp"
20 
21 #include <cmath>
22 
23 namespace s = cl::sycl;
24 namespace d = s::detail;
25 
27 namespace __host_std {
28 
29 namespace {
30 template <typename T> inline T __acospi(T x) { return std::acos(x) / M_PI; }
31 
32 template <typename T> inline T __asinpi(T x) { return std::asin(x) / M_PI; }
33 
34 template <typename T> inline T __atanpi(T x) { return std::atan(x) / M_PI; }
35 
36 template <typename T> inline T __atan2pi(T x, T y) {
37  return std::atan2(x, y) / M_PI;
38 }
39 
40 template <typename T> inline T __cospi(T x) { return std::cos(M_PI * x); }
41 
42 template <typename T> T inline __fract(T x, T *iptr) {
43  T f = std::floor(x);
44  *(iptr) = f;
45  return std::fmin(x - f, std::nextafter(T(1.0), T(0.0)));
46 }
47 
48 template <typename T> inline T __lgamma_r(T x, s::cl_int *signp) {
49  T g = std::tgamma(x);
50  *signp = std::signbit(d::cast_if_host_half(g)) ? -1 : 1;
51  return std::log(std::abs(g));
52 }
53 
54 template <typename T> inline T __mad(T a, T b, T c) { return (a * b) + c; }
55 
56 template <typename T> inline T __maxmag(T x, T y) {
57  if (std::fabs(x) > std::fabs(y))
58  return x;
59  if (std::fabs(y) > std::fabs(x))
60  return y;
61  return std::fmax(x, y);
62 }
63 
64 template <typename T> inline T __minmag(T x, T y) {
65  if (std::fabs(x) < std::fabs(y))
66  return x;
67  if (std::fabs(y) < std::fabs(x))
68  return y;
69  return std::fmin(x, y);
70 }
71 
72 template <typename T> inline T __powr(T x, T y) {
73  return (x >= T(0)) ? T(std::pow(x, y)) : x;
74 }
75 
76 template <typename T> inline T __rootn(T x, s::cl_int y) {
77  return std::pow(x, T(1.0) / y);
78 }
79 
80 template <typename T> inline T __rsqrt(T x) { return T(1.0) / std::sqrt(x); }
81 
82 template <typename T> inline T __sincos(T x, T *cosval) {
83  (*cosval) = std::cos(x);
84  return std::sin(x);
85 }
86 
87 template <typename T> inline T __sinpi(T x) { return std::sin(M_PI * x); }
88 
89 template <typename T> inline T __tanpi(T x) { return std::tan(M_PI * x); }
90 
91 } // namespace
92 
93 // ----------------- 4.13.3 Math functions. Host implementations ---------------
94 // acos
95 __SYCL_EXPORT s::cl_float acos(s::cl_float x) __NOEXC { return std::acos(x); }
96 __SYCL_EXPORT s::cl_double acos(s::cl_double x) __NOEXC { return std::acos(x); }
97 __SYCL_EXPORT s::cl_half acos(s::cl_half x) __NOEXC { return std::acos(x); }
101 
102 // acosh
103 __SYCL_EXPORT s::cl_float acosh(s::cl_float x) __NOEXC { return std::acosh(x); }
105  return std::acosh(x);
106 }
107 __SYCL_EXPORT s::cl_half acosh(s::cl_half x) __NOEXC { return std::acosh(x); }
111 
112 // acospi
113 __SYCL_EXPORT s::cl_float acospi(s::cl_float x) __NOEXC { return __acospi(x); }
115  return __acospi(x);
116 }
117 __SYCL_EXPORT s::cl_half acospi(s::cl_half x) __NOEXC { return __acospi(x); }
121 
122 // asin
123 __SYCL_EXPORT s::cl_float asin(s::cl_float x) __NOEXC { return std::asin(x); }
124 __SYCL_EXPORT s::cl_double asin(s::cl_double x) __NOEXC { return std::asin(x); }
125 __SYCL_EXPORT s::cl_half asin(s::cl_half x) __NOEXC { return std::asin(x); }
129 
130 // asinh
131 __SYCL_EXPORT s::cl_float asinh(s::cl_float x) __NOEXC { return std::asinh(x); }
133  return std::asinh(x);
134 }
135 __SYCL_EXPORT s::cl_half asinh(s::cl_half x) __NOEXC { return std::asinh(x); }
139 
140 // asinpi
141 __SYCL_EXPORT s::cl_float asinpi(s::cl_float x) __NOEXC { return __asinpi(x); }
143  return __asinpi(x);
144 }
145 __SYCL_EXPORT s::cl_half asinpi(s::cl_half x) __NOEXC { return __asinpi(x); }
149 
150 // atan
151 __SYCL_EXPORT s::cl_float atan(s::cl_float x) __NOEXC { return std::atan(x); }
152 __SYCL_EXPORT s::cl_double atan(s::cl_double x) __NOEXC { return std::atan(x); }
153 __SYCL_EXPORT s::cl_half atan(s::cl_half x) __NOEXC { return std::atan(x); }
157 
158 // atan2
159 __SYCL_EXPORT s::cl_float atan2(s::cl_float x, s::cl_float y) __NOEXC {
160  return std::atan2(x, y);
161 }
163  return std::atan2(x, y);
164 }
166  return std::atan2(x, y);
167 }
171 
172 // atanh
173 __SYCL_EXPORT s::cl_float atanh(s::cl_float x) __NOEXC { return std::atanh(x); }
175  return std::atanh(x);
176 }
177 __SYCL_EXPORT s::cl_half atanh(s::cl_half x) __NOEXC { return std::atanh(x); }
181 
182 // atanpi
183 __SYCL_EXPORT s::cl_float atanpi(s::cl_float x) __NOEXC { return __atanpi(x); }
185  return __atanpi(x);
186 }
187 __SYCL_EXPORT s::cl_half atanpi(s::cl_half x) __NOEXC { return __atanpi(x); }
191 
192 // atan2pi
193 __SYCL_EXPORT s::cl_float atan2pi(s::cl_float x, s::cl_float y) __NOEXC {
194  return __atan2pi(x, y);
195 }
197  return __atan2pi(x, y);
198 }
200  return __atan2pi(x, y);
201 }
205 
206 // cbrt
207 __SYCL_EXPORT s::cl_float cbrt(s::cl_float x) __NOEXC { return std::cbrt(x); }
208 __SYCL_EXPORT s::cl_double cbrt(s::cl_double x) __NOEXC { return std::cbrt(x); }
209 __SYCL_EXPORT s::cl_half cbrt(s::cl_half x) __NOEXC { return std::cbrt(x); }
213 
214 // ceil
215 __SYCL_EXPORT s::cl_float ceil(s::cl_float x) __NOEXC { return std::ceil(x); }
216 __SYCL_EXPORT s::cl_double ceil(s::cl_double x) __NOEXC { return std::ceil(x); }
217 __SYCL_EXPORT s::cl_half ceil(s::cl_half x) __NOEXC { return std::ceil(x); }
221 
222 // copysign
223 __SYCL_EXPORT s::cl_float copysign(s::cl_float x, s::cl_float y) __NOEXC {
224  return std::copysign(x, y);
225 }
227  return std::copysign(x, y);
228 }
230  return std::copysign(x, y);
231 }
235 
236 // cos
237 __SYCL_EXPORT s::cl_float cos(s::cl_float x) __NOEXC { return std::cos(x); }
238 __SYCL_EXPORT s::cl_double cos(s::cl_double x) __NOEXC { return std::cos(x); }
239 __SYCL_EXPORT s::cl_half cos(s::cl_half x) __NOEXC { return std::cos(x); }
243 
244 // cosh
245 __SYCL_EXPORT s::cl_float cosh(s::cl_float x) __NOEXC { return std::cosh(x); }
246 __SYCL_EXPORT s::cl_double cosh(s::cl_double x) __NOEXC { return std::cosh(x); }
247 __SYCL_EXPORT s::cl_half cosh(s::cl_half x) __NOEXC { return std::cosh(x); }
251 
252 // cospi
253 __SYCL_EXPORT s::cl_float cospi(s::cl_float x) __NOEXC { return __cospi(x); }
254 __SYCL_EXPORT s::cl_double cospi(s::cl_double x) __NOEXC { return __cospi(x); }
255 __SYCL_EXPORT s::cl_half cospi(s::cl_half x) __NOEXC { return __cospi(x); }
259 
260 // erfc
261 __SYCL_EXPORT s::cl_float erfc(s::cl_float x) __NOEXC { return std::erfc(x); }
262 __SYCL_EXPORT s::cl_double erfc(s::cl_double x) __NOEXC { return std::erfc(x); }
263 __SYCL_EXPORT s::cl_half erfc(s::cl_half x) __NOEXC { return std::erfc(x); }
267 
268 // erf
269 __SYCL_EXPORT s::cl_float erf(s::cl_float x) __NOEXC { return std::erf(x); }
270 __SYCL_EXPORT s::cl_double erf(s::cl_double x) __NOEXC { return std::erf(x); }
271 __SYCL_EXPORT s::cl_half erf(s::cl_half x) __NOEXC { return std::erf(x); }
275 
276 // exp
277 __SYCL_EXPORT s::cl_float exp(s::cl_float x) __NOEXC { return std::exp(x); }
278 __SYCL_EXPORT s::cl_double exp(s::cl_double x) __NOEXC { return std::exp(x); }
279 __SYCL_EXPORT s::cl_half exp(s::cl_half x) __NOEXC { return std::exp(x); }
283 
284 // exp2
285 __SYCL_EXPORT s::cl_float exp2(s::cl_float x) __NOEXC { return std::exp2(x); }
286 __SYCL_EXPORT s::cl_double exp2(s::cl_double x) __NOEXC { return std::exp2(x); }
287 __SYCL_EXPORT s::cl_half exp2(s::cl_half x) __NOEXC { return std::exp2(x); }
291 
292 // exp10
293 __SYCL_EXPORT s::cl_float exp10(s::cl_float x) __NOEXC {
294  return std::pow(10, x);
295 }
297  return std::pow(10, x);
298 }
299 __SYCL_EXPORT s::cl_half exp10(s::cl_half x) __NOEXC { return std::pow(10, x); }
303 
304 // expm1
305 __SYCL_EXPORT s::cl_float expm1(s::cl_float x) __NOEXC { return std::expm1(x); }
307  return std::expm1(x);
308 }
309 __SYCL_EXPORT s::cl_half expm1(s::cl_half x) __NOEXC { return std::expm1(x); }
313 
314 // fabs
315 __SYCL_EXPORT s::cl_float fabs(s::cl_float x) __NOEXC { return std::fabs(x); }
316 __SYCL_EXPORT s::cl_double fabs(s::cl_double x) __NOEXC { return std::fabs(x); }
317 __SYCL_EXPORT s::cl_half fabs(s::cl_half x) __NOEXC { return std::fabs(x); }
321 
322 // fdim
323 __SYCL_EXPORT s::cl_float fdim(s::cl_float x, s::cl_float y) __NOEXC {
324  return std::fdim(x, y);
325 }
327  return std::fdim(x, y);
328 }
330  return std::fdim(x, y);
331 }
335 
336 // floor
337 __SYCL_EXPORT s::cl_float floor(s::cl_float x) __NOEXC { return std::floor(x); }
339  return std::floor(x);
340 }
341 __SYCL_EXPORT s::cl_half floor(s::cl_half x) __NOEXC { return std::floor(x); }
345 
346 // fma
347 __SYCL_EXPORT s::cl_float fma(s::cl_float a, s::cl_float b,
348  s::cl_float c) __NOEXC {
349  return std::fma(a, b, c);
350 }
352  s::cl_double c) __NOEXC {
353  return std::fma(a, b, c);
354 }
356  return std::fma(a, b, c);
357 }
361 
362 // fmax
363 __SYCL_EXPORT s::cl_float fmax(s::cl_float x, s::cl_float y) __NOEXC {
364  return std::fmax(x, y);
365 }
367  return std::fmax(x, y);
368 }
370  return std::fmax(x, y);
371 }
375 
376 // fmin
377 __SYCL_EXPORT s::cl_float fmin(s::cl_float x, s::cl_float y) __NOEXC {
378  return std::fmin(x, y);
379 }
381  return std::fmin(x, y);
382 }
384  return std::fmin(x, y);
385 }
389 
390 // fmod
391 __SYCL_EXPORT s::cl_float fmod(s::cl_float x, s::cl_float y) __NOEXC {
392  return std::fmod(x, y);
393 }
395  return std::fmod(x, y);
396 }
398  return std::fmod(x, y);
399 }
403 
404 // nextafter
405 __SYCL_EXPORT s::cl_float nextafter(s::cl_float x, s::cl_float y) __NOEXC {
406  return std::nextafter(x, y);
407 }
409  return std::nextafter(x, y);
410 }
412  return std::nextafter(x, y);
413 }
417 
418 // fract
419 __SYCL_EXPORT s::cl_float fract(s::cl_float x, s::cl_float *iptr) __NOEXC {
420  return __fract(x, iptr);
421 }
423  return __fract(x, iptr);
424 }
425 __SYCL_EXPORT s::cl_half fract(s::cl_half x, s::cl_half *iptr) __NOEXC {
426  return __fract(x, iptr);
427 }
431 
432 // frexp
433 __SYCL_EXPORT s::cl_float frexp(s::cl_float x, s::cl_int *exp) __NOEXC {
434  return std::frexp(x, exp);
435 }
437  return std::frexp(x, exp);
438 }
440  return std::frexp(x, exp);
441 }
445 
446 // hypot
447 __SYCL_EXPORT s::cl_float hypot(s::cl_float x, s::cl_float y) __NOEXC {
448  return std::hypot(x, y);
449 }
451  return std::hypot(x, y);
452 }
454  return std::hypot(x, y);
455 }
459 
460 // ilogb
461 __SYCL_EXPORT s::cl_int ilogb(s::cl_float x) __NOEXC { return std::ilogb(x); }
462 __SYCL_EXPORT s::cl_int ilogb(s::cl_double x) __NOEXC { return std::ilogb(x); }
463 __SYCL_EXPORT s::cl_int ilogb(s::cl_half x) __NOEXC { return std::ilogb(x); }
467 
468 // ldexp
469 __SYCL_EXPORT s::cl_float ldexp(s::cl_float x, s::cl_int k) __NOEXC {
470  return std::ldexp(x, k);
471 }
473  return std::ldexp(x, k);
474 }
476  return std::ldexp(x, k);
477 }
481 
482 // lgamma
483 __SYCL_EXPORT s::cl_float lgamma(s::cl_float x) __NOEXC {
484  return std::lgamma(x);
485 }
487  return std::lgamma(x);
488 }
489 __SYCL_EXPORT s::cl_half lgamma(s::cl_half x) __NOEXC { return std::lgamma(x); }
493 
494 // lgamma_r
495 __SYCL_EXPORT s::cl_float lgamma_r(s::cl_float x, s::cl_int *signp) __NOEXC {
496  return __lgamma_r(x, signp);
497 }
499  return __lgamma_r(x, signp);
500 }
501 __SYCL_EXPORT s::cl_half lgamma_r(s::cl_half x, s::cl_int *signp) __NOEXC {
502  return __lgamma_r(x, signp);
503 }
507 
508 // log
509 __SYCL_EXPORT s::cl_float log(s::cl_float x) __NOEXC { return std::log(x); }
510 __SYCL_EXPORT s::cl_double log(s::cl_double x) __NOEXC { return std::log(x); }
511 __SYCL_EXPORT s::cl_half log(s::cl_half x) __NOEXC { return std::log(x); }
515 
516 // log2
517 __SYCL_EXPORT s::cl_float log2(s::cl_float x) __NOEXC { return std::log2(x); }
518 __SYCL_EXPORT s::cl_double log2(s::cl_double x) __NOEXC { return std::log2(x); }
519 __SYCL_EXPORT s::cl_half log2(s::cl_half x) __NOEXC { return std::log2(x); }
523 
524 // log10
525 __SYCL_EXPORT s::cl_float log10(s::cl_float x) __NOEXC { return std::log10(x); }
527  return std::log10(x);
528 }
529 __SYCL_EXPORT s::cl_half log10(s::cl_half x) __NOEXC { return std::log10(x); }
533 
534 // log1p
535 __SYCL_EXPORT s::cl_float log1p(s::cl_float x) __NOEXC { return std::log1p(x); }
537  return std::log1p(x);
538 }
539 __SYCL_EXPORT s::cl_half log1p(s::cl_half x) __NOEXC { return std::log1p(x); }
543 
544 // logb
545 __SYCL_EXPORT s::cl_float logb(s::cl_float x) __NOEXC { return std::logb(x); }
546 __SYCL_EXPORT s::cl_double logb(s::cl_double x) __NOEXC { return std::logb(x); }
547 __SYCL_EXPORT s::cl_half logb(s::cl_half x) __NOEXC { return std::logb(x); }
551 
552 // mad
553 __SYCL_EXPORT s::cl_float mad(s::cl_float a, s::cl_float b,
554  s::cl_float c) __NOEXC {
555  return __mad(a, b, c);
556 }
558  s::cl_double c) __NOEXC {
559  return __mad(a, b, c);
560 }
562  return __mad(a, b, c);
563 }
567 
568 // maxmag
569 __SYCL_EXPORT s::cl_float maxmag(s::cl_float x, s::cl_float y) __NOEXC {
570  return __maxmag(x, y);
571 }
573  return __maxmag(x, y);
574 }
576  return __maxmag(x, y);
577 }
581 
582 // minmag
583 __SYCL_EXPORT s::cl_float minmag(s::cl_float x, s::cl_float y) __NOEXC {
584  return __minmag(x, y);
585 }
587  return __minmag(x, y);
588 }
590  return __minmag(x, y);
591 }
595 
596 // modf
597 __SYCL_EXPORT s::cl_float modf(s::cl_float x, s::cl_float *iptr) __NOEXC {
598  return std::modf(x, iptr);
599 }
601  return std::modf(x, iptr);
602 }
603 __SYCL_EXPORT s::cl_half modf(s::cl_half x, s::cl_half *iptr) __NOEXC {
604  return std::modf(x, reinterpret_cast<s::cl_float *>(iptr));
605 }
609 
610 // nan
611 __SYCL_EXPORT s::cl_float nan(s::cl_uint nancode) __NOEXC {
612  (void)nancode;
613  return d::quiet_NaN<s::cl_float>();
614 }
615 __SYCL_EXPORT s::cl_double nan(s::cl_ulong nancode) __NOEXC {
616  (void)nancode;
617  return d::quiet_NaN<s::cl_double>();
618 }
619 __SYCL_EXPORT s::cl_half nan(s::cl_ushort nancode) __NOEXC {
620  (void)nancode;
621  return s::cl_half(d::quiet_NaN<s::cl_float>());
622 }
626 
627 // pow
628 __SYCL_EXPORT s::cl_float pow(s::cl_float x, s::cl_float y) __NOEXC {
629  return std::pow(x, y);
630 }
632  return std::pow(x, y);
633 }
635  return std::pow(x, y);
636 }
640 
641 // pown
642 __SYCL_EXPORT s::cl_float pown(s::cl_float x, s::cl_int y) __NOEXC {
643  return std::pow(x, y);
644 }
646  return std::pow(x, y);
647 }
649  return std::pow(x, y);
650 }
654 
655 // powr
656 __SYCL_EXPORT s::cl_float powr(s::cl_float x, s::cl_float y) __NOEXC {
657  return __powr(x, y);
658 }
660  return __powr(x, y);
661 }
663  return __powr(x, y);
664 }
668 
669 // remainder
670 __SYCL_EXPORT s::cl_float remainder(s::cl_float x, s::cl_float y) __NOEXC {
671  return std::remainder(x, y);
672 }
674  return std::remainder(x, y);
675 }
677  return std::remainder(x, y);
678 }
682 
683 // remquo
684 __SYCL_EXPORT s::cl_float remquo(s::cl_float x, s::cl_float y,
685  s::cl_int *quo) __NOEXC {
686  return std::remquo(x, y, quo);
687 }
689  s::cl_int *quo) __NOEXC {
690  return std::remquo(x, y, quo);
691 }
693  s::cl_int *quo) __NOEXC {
694  return std::remquo(x, y, quo);
695 }
699 
700 // rint
701 __SYCL_EXPORT s::cl_float rint(s::cl_float x) __NOEXC { return std::rint(x); }
702 __SYCL_EXPORT s::cl_double rint(s::cl_double x) __NOEXC { return std::rint(x); }
703 __SYCL_EXPORT s::cl_half rint(s::cl_half x) __NOEXC { return std::rint(x); }
707 
708 // rootn
709 __SYCL_EXPORT s::cl_float rootn(s::cl_float x, s::cl_int y) __NOEXC {
710  return __rootn(x, y);
711 }
713  return __rootn(x, y);
714 }
716  return __rootn(x, y);
717 }
721 
722 // round
723 __SYCL_EXPORT s::cl_float round(s::cl_float x) __NOEXC { return std::round(x); }
725  return std::round(x);
726 }
727 __SYCL_EXPORT s::cl_half round(s::cl_half x) __NOEXC { return std::round(x); }
731 
732 // rsqrt
733 __SYCL_EXPORT s::cl_float rsqrt(s::cl_float x) __NOEXC { return __rsqrt(x); }
734 __SYCL_EXPORT s::cl_double rsqrt(s::cl_double x) __NOEXC { return __rsqrt(x); }
735 __SYCL_EXPORT s::cl_half rsqrt(s::cl_half x) __NOEXC { return __rsqrt(x); }
739 
740 // sin
741 __SYCL_EXPORT s::cl_float sin(s::cl_float x) __NOEXC { return std::sin(x); }
742 __SYCL_EXPORT s::cl_double sin(s::cl_double x) __NOEXC { return std::sin(x); }
743 __SYCL_EXPORT s::cl_half sin(s::cl_half x) __NOEXC { return std::sin(x); }
747 
748 // sincos
749 __SYCL_EXPORT s::cl_float sincos(s::cl_float x, s::cl_float *cosval) __NOEXC {
750  return __sincos(x, cosval);
751 }
753  s::cl_double *cosval) __NOEXC {
754  return __sincos(x, cosval);
755 }
756 __SYCL_EXPORT s::cl_half sincos(s::cl_half x, s::cl_half *cosval) __NOEXC {
757  return __sincos(x, cosval);
758 }
762 
763 // sinh
764 __SYCL_EXPORT s::cl_float sinh(s::cl_float x) __NOEXC { return std::sinh(x); }
765 __SYCL_EXPORT s::cl_double sinh(s::cl_double x) __NOEXC { return std::sinh(x); }
766 __SYCL_EXPORT s::cl_half sinh(s::cl_half x) __NOEXC { return std::sinh(x); }
770 
771 // sinpi
772 __SYCL_EXPORT s::cl_float sinpi(s::cl_float x) __NOEXC { return __sinpi(x); }
773 __SYCL_EXPORT s::cl_double sinpi(s::cl_double x) __NOEXC { return __sinpi(x); }
774 __SYCL_EXPORT s::cl_half sinpi(s::cl_half x) __NOEXC { return __sinpi(x); }
778 
779 // sqrt
780 __SYCL_EXPORT s::cl_float sqrt(s::cl_float x) __NOEXC { return std::sqrt(x); }
781 __SYCL_EXPORT s::cl_double sqrt(s::cl_double x) __NOEXC { return std::sqrt(x); }
782 __SYCL_EXPORT s::cl_half sqrt(s::cl_half x) __NOEXC { return std::sqrt(x); }
786 
787 // tan
788 __SYCL_EXPORT s::cl_float tan(s::cl_float x) __NOEXC { return std::tan(x); }
789 __SYCL_EXPORT s::cl_double tan(s::cl_double x) __NOEXC { return std::tan(x); }
790 __SYCL_EXPORT s::cl_half tan(s::cl_half x) __NOEXC { return std::tan(x); }
794 
795 // tanh
796 __SYCL_EXPORT s::cl_float tanh(s::cl_float x) __NOEXC { return std::tanh(x); }
797 __SYCL_EXPORT s::cl_double tanh(s::cl_double x) __NOEXC { return std::tanh(x); }
798 __SYCL_EXPORT s::cl_half tanh(s::cl_half x) __NOEXC { return std::tanh(x); }
802 
803 // tanpi
804 __SYCL_EXPORT s::cl_float tanpi(s::cl_float x) __NOEXC { return __tanpi(x); }
805 __SYCL_EXPORT s::cl_double tanpi(s::cl_double x) __NOEXC { return __tanpi(x); }
806 __SYCL_EXPORT s::cl_half tanpi(s::cl_half x) __NOEXC { return __tanpi(x); }
810 
811 // tgamma
812 __SYCL_EXPORT s::cl_float tgamma(s::cl_float x) __NOEXC {
813  return std::tgamma(x);
814 }
816  return std::tgamma(x);
817 }
818 __SYCL_EXPORT s::cl_half tgamma(s::cl_half x) __NOEXC { return std::tgamma(x); }
822 
823 // trunc
824 __SYCL_EXPORT s::cl_float trunc(s::cl_float x) __NOEXC { return std::trunc(x); }
826  return std::trunc(x);
827 }
828 __SYCL_EXPORT s::cl_half trunc(s::cl_half x) __NOEXC { return std::trunc(x); }
832 
833 // --------------- 4.13.3 Native Math functions. Host implementations. ---------
834 // native_cos
835 __SYCL_EXPORT s::cl_float native_cos(s::cl_float x) __NOEXC {
836  return std::cos(x);
837 }
839 
840 // native_divide
841 __SYCL_EXPORT s::cl_float native_divide(s::cl_float x, s::cl_float y) __NOEXC {
842  return x / y;
843 }
845 
846 // native_exp
847 __SYCL_EXPORT s::cl_float native_exp(s::cl_float x) __NOEXC {
848  return std::exp(x);
849 }
851 
852 // native_exp2
853 __SYCL_EXPORT s::cl_float native_exp2(s::cl_float x) __NOEXC {
854  return std::exp2(x);
855 }
857 
858 // native_exp10
859 __SYCL_EXPORT s::cl_float native_exp10(s::cl_float x) __NOEXC {
860  return std::pow(10, x);
861 }
863 
864 // native_log
865 __SYCL_EXPORT s::cl_float native_log(s::cl_float x) __NOEXC {
866  return std::log(x);
867 }
869 
870 // native_log2
871 __SYCL_EXPORT s::cl_float native_log2(s::cl_float x) __NOEXC {
872  return std::log2(x);
873 }
875 
876 // native_log10
877 __SYCL_EXPORT s::cl_float native_log10(s::cl_float x) __NOEXC {
878  return std::log10(x);
879 }
881 
882 // native_powr
883 __SYCL_EXPORT s::cl_float native_powr(s::cl_float x, s::cl_float y) __NOEXC {
884  return (x >= 0 ? std::pow(x, y) : x);
885 }
887 
888 // native_recip
889 __SYCL_EXPORT s::cl_float native_recip(s::cl_float x) __NOEXC {
890  return 1.0 / x;
891 }
893 
894 // native_rsqrt
895 __SYCL_EXPORT s::cl_float native_rsqrt(s::cl_float x) __NOEXC {
896  return 1.0 / std::sqrt(x);
897 }
899 
900 // native_sin
901 __SYCL_EXPORT s::cl_float native_sin(s::cl_float x) __NOEXC {
902  return std::sin(x);
903 }
905 
906 // native_sqrt
907 __SYCL_EXPORT s::cl_float native_sqrt(s::cl_float x) __NOEXC {
908  return std::sqrt(x);
909 }
911 
912 // native_tan
913 __SYCL_EXPORT s::cl_float native_tan(s::cl_float x) __NOEXC {
914  return std::tan(x);
915 }
917 
918 // ---------- 4.13.3 Half Precision Math functions. Host implementations. ------
919 // half_cos
920 __SYCL_EXPORT s::cl_float half_cos(s::cl_float x) __NOEXC {
921  return std::cos(x);
922 }
924 
925 // half_divide
926 __SYCL_EXPORT s::cl_float half_divide(s::cl_float x, s::cl_float y) __NOEXC {
927  return x / y;
928 }
930 
931 // half_exp
932 __SYCL_EXPORT s::cl_float half_exp(s::cl_float x) __NOEXC {
933  return std::exp(x);
934 }
936 // half_exp2
937 __SYCL_EXPORT s::cl_float half_exp2(s::cl_float x) __NOEXC {
938  return std::exp2(x);
939 }
941 
942 // half_exp10
943 __SYCL_EXPORT s::cl_float half_exp10(s::cl_float x) __NOEXC {
944  return std::pow(10, x);
945 }
947 // half_log
948 __SYCL_EXPORT s::cl_float half_log(s::cl_float x) __NOEXC {
949  return std::log(x);
950 }
952 
953 // half_log2
954 __SYCL_EXPORT s::cl_float half_log2(s::cl_float x) __NOEXC {
955  return std::log2(x);
956 }
958 
959 // half_log10
960 __SYCL_EXPORT s::cl_float half_log10(s::cl_float x) __NOEXC {
961  return std::log10(x);
962 }
964 
965 // half_powr
966 __SYCL_EXPORT s::cl_float half_powr(s::cl_float x, s::cl_float y) __NOEXC {
967  return (x >= 0 ? std::pow(x, y) : x);
968 }
970 
971 // half_recip
972 __SYCL_EXPORT s::cl_float half_recip(s::cl_float x) __NOEXC { return 1.0 / x; }
974 
975 // half_rsqrt
976 __SYCL_EXPORT s::cl_float half_rsqrt(s::cl_float x) __NOEXC {
977  return 1.0 / std::sqrt(x);
978 }
980 
981 // half_sin
982 __SYCL_EXPORT s::cl_float half_sin(s::cl_float x) __NOEXC {
983  return std::sin(x);
984 }
986 
987 // half_sqrt
988 __SYCL_EXPORT s::cl_float half_sqrt(s::cl_float x) __NOEXC {
989  return std::sqrt(x);
990 }
992 
993 // half_tan
994 __SYCL_EXPORT s::cl_float half_tan(s::cl_float x) __NOEXC {
995  return std::tan(x);
996 }
998 
999 } // namespace __host_std
1000 } // __SYCL_INLINE_NAMESPACE(cl)
cl::__host_std::half_sqrt
s::cl_float half_sqrt(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:988
cl::__host_std::ilogb
s::cl_int ilogb(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:463
cl::__host_std::native_sqrt
s::cl_float native_sqrt(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:907
cl::__host_std::rootn
s::cl_half rootn(s::cl_half x, s::cl_int y) __NOEXC
Definition: builtins_math.cpp:715
cl::__host_std::rint
s::cl_half rint(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:703
cl::__host_std::half_divide
s::cl_float half_divide(s::cl_float x, s::cl_float y) __NOEXC
Definition: builtins_math.cpp:926
cl::__host_std::tgamma
s::cl_half tgamma(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:818
cl::__host_std::lgamma_r
s::cl_half lgamma_r(s::cl_half x, s::cl_int *signp) __NOEXC
Definition: builtins_math.cpp:501
cl::__host_std::half_exp10
s::cl_float half_exp10(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:943
cl::sycl::detail::cast_if_host_half
T cast_if_host_half(T val)
Definition: half_type.hpp:617
cl::sycl::cl_double
double cl_double
Definition: aliases.hpp:89
cl::sycl::cl_half
half cl_half
Definition: aliases.hpp:87
cl::__host_std::sqrt
s::cl_half sqrt(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:782
MAKE_1V_2V_3V
#define MAKE_1V_2V_3V(Fun, Ret, Arg1, Arg2, Arg3)
Definition: builtins_helper.hpp:140
cl::__host_std::exp2
s::cl_half exp2(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:287
cl::__host_std::native_sin
s::cl_float native_sin(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:901
cl::__host_std::tanpi
s::cl_half tanpi(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:806
T
cl::__host_std::asin
s::cl_half asin(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:125
cl::__host_std::native_tan
s::cl_float native_tan(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:913
cl::__host_std::tanh
s::cl_half tanh(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:798
cl::__host_std::cbrt
s::cl_half cbrt(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:209
cl::__host_std::half_tan
s::cl_float half_tan(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:994
cl::__host_std::native_recip
s::cl_float native_recip(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:889
cl::__host_std::fract
s::cl_half fract(s::cl_half x, s::cl_half *iptr) __NOEXC
Definition: builtins_math.cpp:425
cl::__host_std::cospi
s::cl_half cospi(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:255
cl::__host_std::maxmag
s::cl_half maxmag(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:575
cl::__host_std::native_divide
s::cl_float native_divide(s::cl_float x, s::cl_float y) __NOEXC
Definition: builtins_math.cpp:841
cl::sycl
Definition: access.hpp:14
cl::__host_std::asinpi
s::cl_half asinpi(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:145
cl::__host_std::tan
s::cl_half tan(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:790
cl::__host_std::native_cos
s::cl_float native_cos(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:835
cl::__host_std::minmag
s::cl_half minmag(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:589
cl::__host_std::half_recip
s::cl_float half_recip(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:972
cl::__host_std::log10
s::cl_half log10(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:529
cl::__host_std::mad
s::cl_half mad(s::cl_half a, s::cl_half b, s::cl_half c) __NOEXC
Definition: builtins_math.cpp:561
cl::__host_std::native_exp
s::cl_float native_exp(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:847
MAKE_1V_2V
#define MAKE_1V_2V(Fun, Ret, Arg1, Arg2)
Definition: builtins_helper.hpp:129
cl::__host_std::pow
s::cl_half pow(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:634
cl::__host_std::native_log2
s::cl_float native_log2(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:871
cl::__host_std::half_sin
s::cl_float half_sin(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:982
cl::__host_std::cosh
s::cl_half cosh(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:247
cl::__host_std::half_exp
s::cl_float half_exp(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:932
cl::__host_std::rsqrt
s::cl_half rsqrt(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:735
cl::__host_std::fmod
s::cl_half fmod(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:397
cl::__host_std::atan
s::cl_half atan(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:153
cl::__host_std::hypot
s::cl_half hypot(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:453
cl::__host_std::log
s::cl_half log(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:511
export.hpp
cl::__host_std::fma
s::cl_half fma(s::cl_half a, s::cl_half b, s::cl_half c) __NOEXC
Definition: builtins_math.cpp:355
cl::__host_std::atanh
s::cl_half atanh(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:177
cl::__host_std::lgamma
s::cl_half lgamma(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:489
cl::__host_std::asinh
s::cl_half asinh(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:135
cl::sycl::cl_ushort
std::uint16_t cl_ushort
Definition: aliases.hpp:82
cl::__host_std::half_exp2
s::cl_float half_exp2(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:937
cl::sycl::detail::half_impl::half
Definition: half_type.hpp:329
cl::__host_std::powr
s::cl_half powr(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:662
MAKE_1V_2P
#define MAKE_1V_2P(Fun, Ret, Arg1, Arg2)
Definition: builtins_helper.hpp:196
cl::sycl::abs
detail::enable_if_t< detail::is_genfloat< T >::value, T > abs(T x) __NOEXC
Definition: builtins.hpp:530
cl::__host_std::logb
s::cl_half logb(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:547
cl::__host_std::modf
s::cl_half modf(s::cl_half x, s::cl_half *iptr) __NOEXC
Definition: builtins_math.cpp:603
cl::__host_std::atanpi
s::cl_half atanpi(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:187
cl::__host_std::acospi
s::cl_half acospi(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:117
cl::__host_std::pown
s::cl_half pown(s::cl_half x, s::cl_int y) __NOEXC
Definition: builtins_math.cpp:648
cl::__host_std::erf
s::cl_half erf(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:271
cl::__host_std::sincos
s::cl_half sincos(s::cl_half x, s::cl_half *cosval) __NOEXC
Definition: builtins_math.cpp:756
__NOEXC
#define __NOEXC
Definition: builtins.hpp:18
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::signbit
detail::common_rel_ret_t< T > signbit(T x) __NOEXC
Definition: builtins.hpp:1276
cl::__host_std::trunc
s::cl_half trunc(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:828
cl::__host_std::ldexp
s::cl_half ldexp(s::cl_half x, s::cl_int k) __NOEXC
Definition: builtins_math.cpp:475
builtins_helper.hpp
cl::__host_std::half_log2
s::cl_float half_log2(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:954
cl::__host_std::native_rsqrt
s::cl_float native_rsqrt(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:895
cl::__host_std::erfc
s::cl_half erfc(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:263
cl::__host_std::round
s::cl_half round(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:727
cl::sycl::cl_ulong
std::uint64_t cl_ulong
Definition: aliases.hpp:86
cl::__host_std::acos
s::cl_half acos(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:97
cl::sycl::cl_float
float cl_float
Definition: aliases.hpp:88
cl::__host_std::log1p
s::cl_half log1p(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:539
cl::__host_std::half_rsqrt
s::cl_float half_rsqrt(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:976
cl::__host_std::sinpi
s::cl_half sinpi(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:774
cl::__host_std::half_log10
s::cl_float half_log10(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:960
cl::__host_std::nextafter
s::cl_half nextafter(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:411
cl::__host_std::exp
s::cl_half exp(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:279
cl::__host_std::native_powr
s::cl_float native_powr(s::cl_float x, s::cl_float y) __NOEXC
Definition: builtins_math.cpp:883
cl::__host_std::remainder
s::cl_half remainder(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:676
cl::__host_std::sin
s::cl_half sin(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:743
cl::sycl::cl_int
std::int32_t cl_int
Definition: aliases.hpp:83
cl::__host_std::native_log10
s::cl_float native_log10(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:877
cl::__host_std::fmax
s::cl_half fmax(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:369
cl::__host_std::sinh
s::cl_half sinh(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:766
cl::__host_std::frexp
s::cl_half frexp(s::cl_half x, s::cl_int *exp) __NOEXC
Definition: builtins_math.cpp:439
cl::__host_std::fmin
s::cl_half fmin(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:383
cl::sycl::cl_uint
std::uint32_t cl_uint
Definition: aliases.hpp:84
cl::__host_std::fdim
s::cl_half fdim(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:329
cl::__host_std::half_powr
s::cl_float half_powr(s::cl_float x, s::cl_float y) __NOEXC
Definition: builtins_math.cpp:966
cl::__host_std::log2
s::cl_half log2(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:519
cl::__host_std::native_exp2
s::cl_float native_exp2(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:853
cl::__host_std::atan2pi
s::cl_half atan2pi(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:199
MAKE_1V
#define MAKE_1V(Fun, Ret, Arg1)
Definition: builtins_helper.hpp:119
cl::__host_std::acosh
s::cl_half acosh(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:107
cl::__host_std::copysign
s::cl_half copysign(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:229
MAKE_1V_2V_3P
#define MAKE_1V_2V_3P(Fun, Ret, Arg1, Arg2, Arg3)
Definition: builtins_helper.hpp:212
cl::__host_std::half_log
s::cl_float half_log(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:948
cl::__host_std::ceil
s::cl_half ceil(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:217
cl::__host_std::half_cos
s::cl_float half_cos(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:920
cl::__host_std::floor
s::cl_half floor(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:341
cl::__host_std::native_log
s::cl_float native_log(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:865
cl::__host_std::nan
s::cl_half nan(s::cl_ushort nancode) __NOEXC
Definition: builtins_math.cpp:619
cl::__host_std::atan2
s::cl_half atan2(s::cl_half x, s::cl_half y) __NOEXC
Definition: builtins_math.cpp:165
cl::__host_std::remquo
s::cl_half remquo(s::cl_half x, s::cl_half y, s::cl_int *quo) __NOEXC
Definition: builtins_math.cpp:692
cl::__host_std::expm1
s::cl_half expm1(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:309
cl::__host_std::cos
s::cl_half cos(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:239
cl::__host_std::exp10
s::cl_half exp10(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:299
cl::__host_std::fabs
s::cl_half fabs(s::cl_half x) __NOEXC
Definition: builtins_math.cpp:317
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12
cl::__host_std::native_exp10
s::cl_float native_exp10(s::cl_float x) __NOEXC
Definition: builtins_math.cpp:859