DPC++ Runtime
Runtime libraries for oneAPI DPC++
builtins_integer.cpp
Go to the documentation of this file.
1 //==---------- builtins_integer.cpp - SYCL built-in integer 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.4 Integer functions.
11 
12 #include "builtins_helper.hpp"
13 #include <sycl/detail/export.hpp>
14 
15 #include <algorithm>
16 #include <type_traits>
17 
18 namespace s = sycl;
19 namespace d = s::detail;
20 
21 namespace __host_std {
22 namespace {
23 
24 template <typename T> inline std::make_unsigned_t<T> __abs_diff(T x, T y) {
25  static_assert(std::is_integral<T>::value,
26  "Only integral types are supported");
27  using UT = std::make_unsigned_t<T>;
28 
29  // We need to be careful to avoid undefined behavior from signed integer
30  // overflow. That is, if only one of the operands are negative we can overflow
31  // the distance when using signed values. Instead, compute the distance as the
32  // sum of absolule values.
33  if constexpr (std::is_signed_v<T>)
34  if ((x < 0) != (y < 0))
35  return static_cast<UT>(std::abs(x)) + static_cast<UT>(std::abs(y));
36 
37  return (x > y) ? (x - y) : (y - x);
38 }
39 
40 template <typename T> inline T __u_add_sat(T x, T y) {
41  return (x < (d::max_v<T>() - y) ? x + y : d::max_v<T>());
42 }
43 
44 template <typename T> inline T __s_add_sat(T x, T y) {
45  if (x > 0 && y > 0)
46  return (x < (d::max_v<T>() - y) ? (x + y) : d::max_v<T>());
47  if (x < 0 && y < 0)
48  return (x > (d::min_v<T>() - y) ? (x + y) : d::min_v<T>());
49  return x + y;
50 }
51 
52 template <typename T> inline T __hadd(T x, T y) {
53  const T one = 1;
54  return (x >> one) + (y >> one) + ((y & x) & one);
55 }
56 
57 template <typename T> inline T __rhadd(T x, T y) {
58  const T one = 1;
59  return (x >> one) + (y >> one) + ((y | x) & one);
60 }
61 
62 template <typename T> inline T __clamp(T x, T minval, T maxval) {
63  return std::min(std::max(x, minval), maxval);
64 }
65 
66 template <typename T> inline constexpr T __clz_impl(T x, T m, T n = 0) {
67  return (x & m) ? n : __clz_impl(x, T(m >> 1), ++n);
68 }
69 
70 template <typename T> inline constexpr T __clz(T x) {
71  using UT = typename std::make_unsigned<T>::type;
72  return (x == T(0)) ? sizeof(T) * 8 : __clz_impl<UT>(x, d::msbMask<UT>(x));
73 }
74 
75 template <typename T> inline constexpr T __ctz_impl(T x, T m, T n = 0) {
76  return (x & m) ? n : __ctz_impl(x, T(m << 1), ++n);
77 }
78 
79 template <typename T> inline constexpr T __ctz(T x) {
80  using UT = typename std::make_unsigned<T>::type;
81  return (x == T(0)) ? sizeof(T) * 8 : __ctz_impl<UT>(x, 1);
82 }
83 
84 template <typename T> T __mul_hi(T a, T b) {
85  using UPT = typename d::make_larger<T>::type;
86  UPT a_s = a;
87  UPT b_s = b;
88  UPT mul = a_s * b_s;
89  return (mul >> (sizeof(T) * 8));
90 }
91 
92 // A helper function for mul_hi built-in for long
93 template <typename T> inline T __get_high_half(T a0b0, T a0b1, T a1b0, T a1b1) {
94  constexpr int halfsize = (sizeof(T) * 8) / 2;
95  // To get the upper 64 bits:
96  // 64 bits from a1b1, upper 32 bits from [a1b0 + (a0b1 + a0b0>>32 (carry bit
97  // in 33rd bit))] with carry bit on 64th bit - use of hadd. Add the a1b1 to
98  // the above 32 bit result.
99  return a1b1 + (__hadd(a1b0, (a0b1 + (a0b0 >> halfsize))) >> (halfsize - 1));
100 }
101 
102 // A helper function for mul_hi built-in for long
103 template <typename T>
104 inline void __get_half_products(T a, T b, T &a0b0, T &a0b1, T &a1b0, T &a1b1) {
105  constexpr s::cl_int halfsize = (sizeof(T) * 8) / 2;
106  T a1 = a >> halfsize;
107  T a0 = (a << halfsize) >> halfsize;
108  T b1 = b >> halfsize;
109  T b0 = (b << halfsize) >> halfsize;
110 
111  // a1b1 - for bits - [64-128)
112  // a1b0 a0b1 for bits - [32-96)
113  // a0b0 for bits - [0-64)
114  a1b1 = a1 * b1;
115  a0b1 = a0 * b1;
116  a1b0 = a1 * b0;
117  a0b0 = a0 * b0;
118 }
119 
120 // T is minimum of 64 bits- long or longlong
121 template <typename T> inline T __u_long_mul_hi(T a, T b) {
122  T a0b0, a0b1, a1b0, a1b1;
123  __get_half_products(a, b, a0b0, a0b1, a1b0, a1b1);
124  T result = __get_high_half(a0b0, a0b1, a1b0, a1b1);
125  return result;
126 }
127 
128 template <typename T> inline T __s_long_mul_hi(T a, T b) {
129  using UT = typename std::make_unsigned<T>::type;
130  UT absA = std::abs(a);
131  UT absB = std::abs(b);
132 
133  UT a0b0, a0b1, a1b0, a1b1;
134  __get_half_products(absA, absB, a0b0, a0b1, a1b0, a1b1);
135  T result = __get_high_half(a0b0, a0b1, a1b0, a1b1);
136 
137  bool isResultNegative = (a < 0) != (b < 0);
138  if (isResultNegative) {
139  result = ~result;
140 
141  // Find the low half to see if we need to carry
142  constexpr int halfsize = (sizeof(T) * 8) / 2;
143  UT low = a0b0 + ((a0b1 + a1b0) << halfsize);
144  if (low == 0)
145  ++result;
146  }
147 
148  return result;
149 }
150 
151 template <typename T> inline T __mad_hi(T a, T b, T c) {
152  return __mul_hi(a, b) + c;
153 }
154 
155 template <typename T> inline T __u_long_mad_hi(T a, T b, T c) {
156  return __u_long_mul_hi(a, b) + c;
157 }
158 
159 template <typename T> inline T __s_long_mad_hi(T a, T b, T c) {
160  return __s_long_mul_hi(a, b) + c;
161 }
162 
163 template <typename T> inline T __s_mad_sat(T a, T b, T c) {
164  using UPT = typename d::make_larger<T>::type;
165  UPT mul = UPT(a) * UPT(b);
166  UPT res = mul + UPT(c);
167  const UPT max = d::max_v<T>();
168  const UPT min = d::min_v<T>();
169  res = std::min(std::max(res, min), max);
170  return T(res);
171 }
172 
173 template <typename T> inline T __s_long_mad_sat(T a, T b, T c) {
174  bool neg_prod = (a < 0) ^ (b < 0);
175  T mulhi = __s_long_mul_hi(a, b);
176 
177  // check mul_hi. If it is any value != 0.
178  // if prod is +ve, any value in mulhi means we need to saturate.
179  // if prod is -ve, any value in mulhi besides -1 means we need to saturate.
180  if (!neg_prod && mulhi != 0)
181  return d::max_v<T>();
182  if (neg_prod && mulhi != -1)
183  return d::min_v<T>(); // essentially some other negative value.
184  return __s_add_sat(T(a * b), c);
185 }
186 
187 template <typename T> inline T __u_mad_sat(T a, T b, T c) {
188  using UPT = typename d::make_larger<T>::type;
189  UPT mul = UPT(a) * UPT(b);
190  const UPT min = d::min_v<T>();
191  const UPT max = d::max_v<T>();
192  mul = std::min(std::max(mul, min), max);
193  return __u_add_sat(T(mul), c);
194 }
195 
196 template <typename T> inline T __u_long_mad_sat(T a, T b, T c) {
197  T mulhi = __u_long_mul_hi(a, b);
198  // check mul_hi. If it is any value != 0.
199  if (mulhi != 0)
200  return d::max_v<T>();
201  return __u_add_sat(T(a * b), c);
202 }
203 
204 template <typename T> inline T __rotate(T x, T n) {
205  using UT = typename std::make_unsigned<T>::type;
206  // Shrink the shift width so that it's in the range [0, num_bits(T)). Cast
207  // everything to unsigned to avoid type conversion issues.
208  constexpr UT size = sizeof(x) * 8;
209  UT xu = UT(x);
210  UT nu = UT(n) & (size - 1);
211  return (xu << nu) | (xu >> (size - nu));
212 }
213 
214 template <typename T> inline T __u_sub_sat(T x, T y) {
215  return (y < (x - d::min_v<T>())) ? (x - y) : d::min_v<T>();
216 }
217 
218 template <typename T> inline T __s_sub_sat(T x, T y) {
219  using UT = typename std::make_unsigned<T>::type;
220  T result = UT(x) - UT(y);
221  // Saturate result if (+) - (-) = (-) or (-) - (+) = (+).
222  if (((x < 0) ^ (y < 0)) && ((x < 0) ^ (result < 0)))
223  result = result < 0 ? d::max_v<T>() : d::min_v<T>();
224  return result;
225 }
226 
227 template <typename T1, typename T2>
228 typename d::make_larger<T1>::type inline __upsample(T1 hi, T2 lo) {
229  using UT = typename d::make_larger<T1>::type;
230  return (UT(hi) << (sizeof(T1) * 8)) | lo;
231 }
232 
233 template <typename T> inline constexpr T __popcount_impl(T x, size_t n = 0) {
234  return (x == T(0)) ? n : __popcount_impl(x >> 1, ((x & T(1)) ? ++n : n));
235 }
236 
237 template <typename T> inline constexpr T __popcount(T x) {
238  using UT = typename d::make_unsigned<T>::type;
239  return __popcount_impl(UT(x));
240 }
241 
242 template <typename T> inline T __mad24(T x, T y, T z) { return (x * y) + z; }
243 
244 template <typename T> inline T __mul24(T x, T y) { return (x * y); }
245 
246 } // namespace
247 
248 // --------------- 4.13.4 Integer functions. Host implementations --------------
249 // u_abs
250 __SYCL_EXPORT s::cl_uchar sycl_host_u_abs(s::cl_uchar x) __NOEXC { return x; }
251 __SYCL_EXPORT s::cl_ushort sycl_host_u_abs(s::cl_ushort x) __NOEXC { return x; }
252 __SYCL_EXPORT s::cl_uint sycl_host_u_abs(s::cl_uint x) __NOEXC { return x; }
253 __SYCL_EXPORT s::cl_ulong sycl_host_u_abs(s::cl_ulong x) __NOEXC { return x; }
258 
259 // s_abs
261  return std::abs(x);
262 }
264  return std::abs(x);
265 }
267  return std::abs(x);
268 }
270  return std::abs(x);
271 }
276 
277 // u_abs_diff
279  s::cl_uchar y) __NOEXC {
280  return __abs_diff(x, y);
281 }
283  s::cl_ushort y) __NOEXC {
284  return __abs_diff(x, y);
285 }
287  s::cl_uint y) __NOEXC {
288  return __abs_diff(x, y);
289 }
291  s::cl_ulong y) __NOEXC {
292  return __abs_diff(x, y);
293 }
294 
299 
300 // s_abs_diff
302  s::cl_char y) __NOEXC {
303  return __abs_diff(x, y);
304 }
306  s::cl_short y) __NOEXC {
307  return __abs_diff(x, y);
308 }
310  s::cl_int y) __NOEXC {
311  return __abs_diff(x, y);
312 }
314  s::cl_long y) __NOEXC {
315  return __abs_diff(x, y);
316 }
321 
322 // u_add_sat
324  s::cl_uchar y) __NOEXC {
325  return __u_add_sat(x, y);
326 }
328  s::cl_ushort y) __NOEXC {
329  return __u_add_sat(x, y);
330 }
332  s::cl_uint y) __NOEXC {
333  return __u_add_sat(x, y);
334 }
336  s::cl_ulong y) __NOEXC {
337  return __u_add_sat(x, y);
338 }
343 
344 // s_add_sat
346  s::cl_char y) __NOEXC {
347  return __s_add_sat(x, y);
348 }
350  s::cl_short y) __NOEXC {
351  return __s_add_sat(x, y);
352 }
354  return __s_add_sat(x, y);
355 }
357  s::cl_long y) __NOEXC {
358  return __s_add_sat(x, y);
359 }
364 
365 // u_hadd
367  s::cl_uchar y) __NOEXC {
368  return __hadd(x, y);
369 }
371  s::cl_ushort y) __NOEXC {
372  return __hadd(x, y);
373 }
375  return __hadd(x, y);
376 }
378  s::cl_ulong y) __NOEXC {
379  return __hadd(x, y);
380 }
385 
386 // s_hadd
387 __SYCL_EXPORT s::cl_char sycl_host_s_hadd(s::cl_char x, s::cl_char y) __NOEXC {
388  return __hadd(x, y);
389 }
391  s::cl_short y) __NOEXC {
392  return __hadd(x, y);
393 }
395  return __hadd(x, y);
396 }
398  return __hadd(x, y);
399 }
404 
405 // u_rhadd
407  s::cl_uchar y) __NOEXC {
408  return __rhadd(x, y);
409 }
411  s::cl_ushort y) __NOEXC {
412  return __rhadd(x, y);
413 }
415  return __rhadd(x, y);
416 }
418  s::cl_ulong y) __NOEXC {
419  return __rhadd(x, y);
420 }
425 
426 // s_rhadd
428  return __rhadd(x, y);
429 }
431  s::cl_short y) __NOEXC {
432  return __rhadd(x, y);
433 }
435  return __rhadd(x, y);
436 }
438  return __rhadd(x, y);
439 }
444 
445 // u_clamp
448  return __clamp(x, minval, maxval);
449 }
453  return __clamp(x, minval, maxval);
454 }
457  return __clamp(x, minval, maxval);
458 }
461  return __clamp(x, minval, maxval);
462 }
464  s::cl_uchar)
466  s::cl_ushort)
469  s::cl_ulong)
471  s::cl_uchar)
473  s::cl_ushort)
476  s::cl_ulong)
477 
478 // s_clamp
480  s::cl_char maxval) __NOEXC {
481  return __clamp(x, minval, maxval);
482 }
485  return __clamp(x, minval, maxval);
486 }
489  return __clamp(x, minval, maxval);
490 }
493  return __clamp(x, minval, maxval);
494 }
497  s::cl_short)
502  s::cl_short)
505 
506 // clz
507 __SYCL_EXPORT s::cl_uchar sycl_host_clz(s::cl_uchar x) __NOEXC {
508  return __clz(x);
509 }
511  return __clz(x);
512 }
514  return __clz(x);
515 }
517  return __clz(x);
518 }
520  return __clz(x);
521 }
522 __SYCL_EXPORT s::cl_int sycl_host_clz(s::cl_int x) __NOEXC { return __clz(x); }
524  return __clz(x);
525 }
527  return __clz(x);
528 }
537 
538 // ctz
539 __SYCL_EXPORT s::cl_uchar sycl_host_ctz(s::cl_uchar x) __NOEXC {
540  return __ctz(x);
541 }
543  return __ctz(x);
544 }
546  return __ctz(x);
547 }
549  return __ctz(x);
550 }
552  return __ctz(x);
553 }
554 __SYCL_EXPORT s::cl_int sycl_host_ctz(s::cl_int x) __NOEXC { return __ctz(x); }
556  return __ctz(x);
557 }
559  return __ctz(x);
560 }
569 
570 // s_mul_hi
571 __SYCL_EXPORT s::cl_char sycl_host_s_mul_hi(s::cl_char a, s::cl_char b) {
572  return __mul_hi(a, b);
573 }
575  return __mul_hi(a, b);
576 }
578  return __mul_hi(a, b);
579 }
581  s::cl_long y) __NOEXC {
582  return __s_long_mul_hi(x, y);
583 }
588 
589 // u_mul_hi
590 __SYCL_EXPORT s::cl_uchar sycl_host_u_mul_hi(s::cl_uchar a, s::cl_uchar b) {
591  return __mul_hi(a, b);
592 }
594  return __mul_hi(a, b);
595 }
597  return __mul_hi(a, b);
598 }
600  s::cl_ulong y) __NOEXC {
601  return __u_long_mul_hi(x, y);
602 }
607 
608 // s_mad_hi
610  s::cl_char maxval) __NOEXC {
611  return __mad_hi(x, minval, maxval);
612 }
615  return __mad_hi(x, minval, maxval);
616 }
619  return __mad_hi(x, minval, maxval);
620 }
623  return __s_long_mad_hi(x, minval, maxval);
624 }
626  s::cl_char)
628  s::cl_short)
631  s::cl_long)
632 
633 // u_mad_hi
634 __SYCL_EXPORT s::cl_uchar sycl_host_u_mad_hi(s::cl_uchar x, s::cl_uchar minval,
636  return __mad_hi(x, minval, maxval);
637 }
638 __SYCL_EXPORT s::cl_ushort sycl_host_u_mad_hi(s::cl_ushort x,
641  return __mad_hi(x, minval, maxval);
642 }
643 __SYCL_EXPORT s::cl_uint sycl_host_u_mad_hi(s::cl_uint x, s::cl_uint minval,
645  return __mad_hi(x, minval, maxval);
646 }
647 __SYCL_EXPORT s::cl_ulong sycl_host_u_mad_hi(s::cl_ulong x, s::cl_ulong minval,
649  return __u_long_mad_hi(x, minval, maxval);
650 }
651 MAKE_1V_2V_3V(sycl_host_u_mad_hi, s::cl_uchar, s::cl_uchar, s::cl_uchar,
652  s::cl_uchar)
654  s::cl_ushort)
655 MAKE_1V_2V_3V(sycl_host_u_mad_hi, s::cl_uint, s::cl_uint, s::cl_uint,
656  s::cl_uint)
657 MAKE_1V_2V_3V(sycl_host_u_mad_hi, s::cl_ulong, s::cl_ulong, s::cl_ulong,
658  s::cl_ulong)
659 
660 // s_mad_sat
661 __SYCL_EXPORT s::cl_char sycl_host_s_mad_sat(s::cl_char a, s::cl_char b,
662  s::cl_char c) __NOEXC {
663  return __s_mad_sat(a, b, c);
664 }
665 __SYCL_EXPORT s::cl_short sycl_host_s_mad_sat(s::cl_short a, s::cl_short b,
667  return __s_mad_sat(a, b, c);
668 }
669 __SYCL_EXPORT s::cl_int sycl_host_s_mad_sat(s::cl_int a, s::cl_int b,
670  s::cl_int c) __NOEXC {
671  return __s_mad_sat(a, b, c);
672 }
673 __SYCL_EXPORT s::cl_long sycl_host_s_mad_sat(s::cl_long a, s::cl_long b,
674  s::cl_long c) __NOEXC {
675  return __s_long_mad_sat(a, b, c);
676 }
677 MAKE_1V_2V_3V(sycl_host_s_mad_sat, s::cl_char, s::cl_char, s::cl_char,
678  s::cl_char)
679 MAKE_1V_2V_3V(sycl_host_s_mad_sat, s::cl_short, s::cl_short, s::cl_short,
680  s::cl_short)
681 MAKE_1V_2V_3V(sycl_host_s_mad_sat, s::cl_int, s::cl_int, s::cl_int, s::cl_int)
682 MAKE_1V_2V_3V(sycl_host_s_mad_sat, s::cl_long, s::cl_long, s::cl_long,
683  s::cl_long)
684 
685 // u_mad_sat
686 __SYCL_EXPORT s::cl_uchar sycl_host_u_mad_sat(s::cl_uchar a, s::cl_uchar b,
688  return __u_mad_sat(a, b, c);
689 }
690 __SYCL_EXPORT s::cl_ushort sycl_host_u_mad_sat(s::cl_ushort a, s::cl_ushort b,
692  return __u_mad_sat(a, b, c);
693 }
694 __SYCL_EXPORT s::cl_uint sycl_host_u_mad_sat(s::cl_uint a, s::cl_uint b,
695  s::cl_uint c) __NOEXC {
696  return __u_mad_sat(a, b, c);
697 }
698 __SYCL_EXPORT s::cl_ulong sycl_host_u_mad_sat(s::cl_ulong a, s::cl_ulong b,
700  return __u_long_mad_sat(a, b, c);
701 }
702 MAKE_1V_2V_3V(sycl_host_u_mad_sat, s::cl_uchar, s::cl_uchar, s::cl_uchar,
703  s::cl_uchar)
704 MAKE_1V_2V_3V(sycl_host_u_mad_sat, s::cl_ushort, s::cl_ushort, s::cl_ushort,
705  s::cl_ushort)
706 MAKE_1V_2V_3V(sycl_host_u_mad_sat, s::cl_uint, s::cl_uint, s::cl_uint,
707  s::cl_uint)
708 MAKE_1V_2V_3V(sycl_host_u_mad_sat, s::cl_ulong, s::cl_ulong, s::cl_ulong,
709  s::cl_ulong)
710 
711 // s_max
712 __SYCL_EXPORT s::cl_char sycl_host_s_max(s::cl_char x, s::cl_char y) __NOEXC {
713  return std::max(x, y);
714 }
715 __SYCL_EXPORT s::cl_short sycl_host_s_max(s::cl_short x,
716  s::cl_short y) __NOEXC {
717  return std::max(x, y);
718 }
719 __SYCL_EXPORT s::cl_int sycl_host_s_max(s::cl_int x, s::cl_int y) __NOEXC {
720  return std::max(x, y);
721 }
722 __SYCL_EXPORT s::cl_long sycl_host_s_max(s::cl_long x, s::cl_long y) __NOEXC {
723  return std::max(x, y);
724 }
725 MAKE_1V_2V(sycl_host_s_max, s::cl_char, s::cl_char, s::cl_char)
726 MAKE_1V_2V(sycl_host_s_max, s::cl_short, s::cl_short, s::cl_short)
727 MAKE_1V_2V(sycl_host_s_max, s::cl_int, s::cl_int, s::cl_int)
728 MAKE_1V_2V(sycl_host_s_max, s::cl_long, s::cl_long, s::cl_long)
729 MAKE_1V_2S(sycl_host_s_max, s::cl_char, s::cl_char, s::cl_char)
730 MAKE_1V_2S(sycl_host_s_max, s::cl_short, s::cl_short, s::cl_short)
731 MAKE_1V_2S(sycl_host_s_max, s::cl_int, s::cl_int, s::cl_int)
732 MAKE_1V_2S(sycl_host_s_max, s::cl_long, s::cl_long, s::cl_long)
733 
734 // u_max
735 __SYCL_EXPORT s::cl_uchar sycl_host_u_max(s::cl_uchar x,
736  s::cl_uchar y) __NOEXC {
737  return std::max(x, y);
738 }
739 __SYCL_EXPORT s::cl_ushort sycl_host_u_max(s::cl_ushort x,
740  s::cl_ushort y) __NOEXC {
741  return std::max(x, y);
742 }
743 __SYCL_EXPORT s::cl_uint sycl_host_u_max(s::cl_uint x, s::cl_uint y) __NOEXC {
744  return std::max(x, y);
745 }
746 __SYCL_EXPORT s::cl_ulong sycl_host_u_max(s::cl_ulong x,
747  s::cl_ulong y) __NOEXC {
748  return std::max(x, y);
749 }
750 MAKE_1V_2V(sycl_host_u_max, s::cl_uchar, s::cl_uchar, s::cl_uchar)
752 MAKE_1V_2V(sycl_host_u_max, s::cl_uint, s::cl_uint, s::cl_uint)
753 MAKE_1V_2V(sycl_host_u_max, s::cl_ulong, s::cl_ulong, s::cl_ulong)
754 MAKE_1V_2S(sycl_host_u_max, s::cl_uchar, s::cl_uchar, s::cl_uchar)
756 MAKE_1V_2S(sycl_host_u_max, s::cl_uint, s::cl_uint, s::cl_uint)
757 MAKE_1V_2S(sycl_host_u_max, s::cl_ulong, s::cl_ulong, s::cl_ulong)
758 
759 // s_min
760 __SYCL_EXPORT s::cl_char sycl_host_s_min(s::cl_char x, s::cl_char y) __NOEXC {
761  return std::min(x, y);
762 }
763 __SYCL_EXPORT s::cl_short sycl_host_s_min(s::cl_short x,
764  s::cl_short y) __NOEXC {
765  return std::min(x, y);
766 }
767 __SYCL_EXPORT s::cl_int sycl_host_s_min(s::cl_int x, s::cl_int y) __NOEXC {
768  return std::min(x, y);
769 }
770 __SYCL_EXPORT s::cl_long sycl_host_s_min(s::cl_long x, s::cl_long y) __NOEXC {
771  return std::min(x, y);
772 }
773 MAKE_1V_2V(sycl_host_s_min, s::cl_char, s::cl_char, s::cl_char)
774 MAKE_1V_2V(sycl_host_s_min, s::cl_short, s::cl_short, s::cl_short)
775 MAKE_1V_2V(sycl_host_s_min, s::cl_int, s::cl_int, s::cl_int)
776 MAKE_1V_2V(sycl_host_s_min, s::cl_long, s::cl_long, s::cl_long)
777 MAKE_1V_2S(sycl_host_s_min, s::cl_char, s::cl_char, s::cl_char)
778 MAKE_1V_2S(sycl_host_s_min, s::cl_short, s::cl_short, s::cl_short)
779 MAKE_1V_2S(sycl_host_s_min, s::cl_int, s::cl_int, s::cl_int)
780 MAKE_1V_2S(sycl_host_s_min, s::cl_long, s::cl_long, s::cl_long)
781 
782 // u_min
783 __SYCL_EXPORT s::cl_uchar sycl_host_u_min(s::cl_uchar x,
784  s::cl_uchar y) __NOEXC {
785  return std::min(x, y);
786 }
787 __SYCL_EXPORT s::cl_ushort sycl_host_u_min(s::cl_ushort x,
788  s::cl_ushort y) __NOEXC {
789  return std::min(x, y);
790 }
791 __SYCL_EXPORT s::cl_uint sycl_host_u_min(s::cl_uint x, s::cl_uint y) __NOEXC {
792  return std::min(x, y);
793 }
794 __SYCL_EXPORT s::cl_ulong sycl_host_u_min(s::cl_ulong x,
795  s::cl_ulong y) __NOEXC {
796  return std::min(x, y);
797 }
798 MAKE_1V_2V(sycl_host_u_min, s::cl_uchar, s::cl_uchar, s::cl_uchar)
800 MAKE_1V_2V(sycl_host_u_min, s::cl_uint, s::cl_uint, s::cl_uint)
801 MAKE_1V_2V(sycl_host_u_min, s::cl_ulong, s::cl_ulong, s::cl_ulong)
802 MAKE_1V_2S(sycl_host_u_min, s::cl_uchar, s::cl_uchar, s::cl_uchar)
804 MAKE_1V_2S(sycl_host_u_min, s::cl_uint, s::cl_uint, s::cl_uint)
805 MAKE_1V_2S(sycl_host_u_min, s::cl_ulong, s::cl_ulong, s::cl_ulong)
806 
807 // rotate
808 __SYCL_EXPORT s::cl_uchar sycl_host_rotate(s::cl_uchar x,
809  s::cl_uchar y) __NOEXC {
810  return __rotate(x, y);
811 }
812 __SYCL_EXPORT s::cl_ushort sycl_host_rotate(s::cl_ushort x,
813  s::cl_ushort y) __NOEXC {
814  return __rotate(x, y);
815 }
816 __SYCL_EXPORT s::cl_uint sycl_host_rotate(s::cl_uint x, s::cl_uint y) __NOEXC {
817  return __rotate(x, y);
818 }
819 __SYCL_EXPORT s::cl_ulong sycl_host_rotate(s::cl_ulong x,
820  s::cl_ulong y) __NOEXC {
821  return __rotate(x, y);
822 }
823 __SYCL_EXPORT s::cl_char sycl_host_rotate(s::cl_char x, s::cl_char y) __NOEXC {
824  return __rotate(x, y);
825 }
826 __SYCL_EXPORT s::cl_short sycl_host_rotate(s::cl_short x,
827  s::cl_short y) __NOEXC {
828  return __rotate(x, y);
829 }
830 __SYCL_EXPORT s::cl_int sycl_host_rotate(s::cl_int x, s::cl_int y) __NOEXC {
831  return __rotate(x, y);
832 }
833 __SYCL_EXPORT s::cl_long sycl_host_rotate(s::cl_long x, s::cl_long y) __NOEXC {
834  return __rotate(x, y);
835 }
836 MAKE_1V_2V(sycl_host_rotate, s::cl_uchar, s::cl_uchar, s::cl_uchar)
838 MAKE_1V_2V(sycl_host_rotate, s::cl_uint, s::cl_uint, s::cl_uint)
839 MAKE_1V_2V(sycl_host_rotate, s::cl_ulong, s::cl_ulong, s::cl_ulong)
840 MAKE_1V_2V(sycl_host_rotate, s::cl_char, s::cl_char, s::cl_char)
841 MAKE_1V_2V(sycl_host_rotate, s::cl_short, s::cl_short, s::cl_short)
842 MAKE_1V_2V(sycl_host_rotate, s::cl_int, s::cl_int, s::cl_int)
843 MAKE_1V_2V(sycl_host_rotate, s::cl_long, s::cl_long, s::cl_long)
844 
845 // u_sub_sat
846 __SYCL_EXPORT s::cl_uchar sycl_host_u_sub_sat(s::cl_uchar x,
847  s::cl_uchar y) __NOEXC {
848  return __u_sub_sat(x, y);
849 }
850 __SYCL_EXPORT s::cl_ushort sycl_host_u_sub_sat(s::cl_ushort x,
851  s::cl_ushort y) __NOEXC {
852  return __u_sub_sat(x, y);
853 }
854 __SYCL_EXPORT s::cl_uint sycl_host_u_sub_sat(s::cl_uint x,
855  s::cl_uint y) __NOEXC {
856  return __u_sub_sat(x, y);
857 }
858 __SYCL_EXPORT s::cl_ulong sycl_host_u_sub_sat(s::cl_ulong x,
859  s::cl_ulong y) __NOEXC {
860  return __u_sub_sat(x, y);
861 }
862 MAKE_1V_2V(sycl_host_u_sub_sat, s::cl_uchar, s::cl_uchar, s::cl_uchar)
863 MAKE_1V_2V(sycl_host_u_sub_sat, s::cl_ushort, s::cl_ushort, s::cl_ushort)
864 MAKE_1V_2V(sycl_host_u_sub_sat, s::cl_uint, s::cl_uint, s::cl_uint)
865 MAKE_1V_2V(sycl_host_u_sub_sat, s::cl_ulong, s::cl_ulong, s::cl_ulong)
866 
867 // s_sub_sat
868 __SYCL_EXPORT s::cl_char sycl_host_s_sub_sat(s::cl_char x,
869  s::cl_char y) __NOEXC {
870  return __s_sub_sat(x, y);
871 }
872 __SYCL_EXPORT s::cl_short sycl_host_s_sub_sat(s::cl_short x,
873  s::cl_short y) __NOEXC {
874  return __s_sub_sat(x, y);
875 }
876 __SYCL_EXPORT s::cl_int sycl_host_s_sub_sat(s::cl_int x, s::cl_int y) __NOEXC {
877  return __s_sub_sat(x, y);
878 }
879 __SYCL_EXPORT s::cl_long sycl_host_s_sub_sat(s::cl_long x,
880  s::cl_long y) __NOEXC {
881  return __s_sub_sat(x, y);
882 }
883 MAKE_1V_2V(sycl_host_s_sub_sat, s::cl_char, s::cl_char, s::cl_char)
884 MAKE_1V_2V(sycl_host_s_sub_sat, s::cl_short, s::cl_short, s::cl_short)
885 MAKE_1V_2V(sycl_host_s_sub_sat, s::cl_int, s::cl_int, s::cl_int)
886 MAKE_1V_2V(sycl_host_s_sub_sat, s::cl_long, s::cl_long, s::cl_long)
887 
888 // u_upsample
889 __SYCL_EXPORT s::cl_ushort sycl_host_u_upsample(s::cl_uchar x,
890  s::cl_uchar y) __NOEXC {
891  return __upsample(x, y);
892 }
893 __SYCL_EXPORT s::cl_uint sycl_host_u_upsample(s::cl_ushort x,
894  s::cl_ushort y) __NOEXC {
895  return __upsample(x, y);
896 }
897 __SYCL_EXPORT s::cl_ulong sycl_host_u_upsample(s::cl_uint x,
898  s::cl_uint y) __NOEXC {
899  return __upsample(x, y);
900 }
901 MAKE_1V_2V(sycl_host_u_upsample, s::cl_ushort, s::cl_uchar, s::cl_uchar)
902 MAKE_1V_2V(sycl_host_u_upsample, s::cl_uint, s::cl_ushort, s::cl_ushort)
903 MAKE_1V_2V(sycl_host_u_upsample, s::cl_ulong, s::cl_uint, s::cl_uint)
904 
905 __SYCL_EXPORT s::cl_short sycl_host_s_upsample(s::cl_char x,
906  s::cl_uchar y) __NOEXC {
907  return __upsample(x, y);
908 }
909 __SYCL_EXPORT s::cl_int sycl_host_s_upsample(s::cl_short x,
910  s::cl_ushort y) __NOEXC {
911  return __upsample(x, y);
912 }
913 __SYCL_EXPORT s::cl_long sycl_host_s_upsample(s::cl_int x,
914  s::cl_uint y) __NOEXC {
915  return __upsample(x, y);
916 }
917 MAKE_1V_2V(sycl_host_s_upsample, s::cl_short, s::cl_char, s::cl_uchar)
918 MAKE_1V_2V(sycl_host_s_upsample, s::cl_int, s::cl_short, s::cl_ushort)
919 MAKE_1V_2V(sycl_host_s_upsample, s::cl_long, s::cl_int, s::cl_uint)
920 
921 // popcount
922 __SYCL_EXPORT s::cl_uchar sycl_host_popcount(s::cl_uchar x) __NOEXC {
923  return __popcount(x);
924 }
925 __SYCL_EXPORT s::cl_ushort sycl_host_popcount(s::cl_ushort x) __NOEXC {
926  return __popcount(x);
927 }
928 __SYCL_EXPORT s::cl_uint sycl_host_popcount(s::cl_uint x) __NOEXC {
929  return __popcount(x);
930 }
931 __SYCL_EXPORT s::cl_ulong sycl_host_popcount(s::cl_ulong x) __NOEXC {
932  return __popcount(x);
933 }
934 MAKE_1V(sycl_host_popcount, s::cl_uchar, s::cl_uchar)
935 MAKE_1V(sycl_host_popcount, s::cl_ushort, s::cl_ushort)
936 MAKE_1V(sycl_host_popcount, s::cl_uint, s::cl_uint)
937 MAKE_1V(sycl_host_popcount, s::cl_ulong, s::cl_ulong)
938 
939 __SYCL_EXPORT s::cl_char sycl_host_popcount(s::cl_char x) __NOEXC {
940  return __popcount(x);
941 }
942 __SYCL_EXPORT s::cl_short sycl_host_popcount(s::cl_short x) __NOEXC {
943  return __popcount(x);
944 }
945 __SYCL_EXPORT s::cl_int sycl_host_popcount(s::cl_int x) __NOEXC {
946  return __popcount(x);
947 }
948 __SYCL_EXPORT s::cl_long sycl_host_popcount(s::cl_long x) __NOEXC {
949  return __popcount(x);
950 }
951 MAKE_1V(sycl_host_popcount, s::cl_char, s::cl_char)
952 MAKE_1V(sycl_host_popcount, s::cl_short, s::cl_short)
953 MAKE_1V(sycl_host_popcount, s::cl_int, s::cl_int)
954 MAKE_1V(sycl_host_popcount, s::cl_long, s::cl_long)
955 
956 // u_mad24
957 __SYCL_EXPORT s::cl_uint sycl_host_u_mad24(s::cl_uint x, s::cl_uint y,
958  s::cl_uint z) __NOEXC {
959  return __mad24(x, y, z);
960 }
962 
963 // s_mad24
964 __SYCL_EXPORT s::cl_int sycl_host_s_mad24(s::cl_int x, s::cl_int y,
965  s::cl_int z) __NOEXC {
966  return __mad24(x, y, z);
967 }
968 MAKE_1V_2V_3V(sycl_host_s_mad24, s::cl_int, s::cl_int, s::cl_int, s::cl_int)
969 
970 // u_mul24
971 __SYCL_EXPORT s::cl_uint sycl_host_u_mul24(s::cl_uint x, s::cl_uint y) __NOEXC {
972  return __mul24(x, y);
973 }
974 MAKE_1V_2V(sycl_host_u_mul24, s::cl_uint, s::cl_uint, s::cl_uint)
975 
976 // s_mul24
977 __SYCL_EXPORT s::cl_int sycl_host_s_mul24(s::cl_int x, s::cl_int y) __NOEXC {
978  return __mul24(x, y);
979 }
980 MAKE_1V_2V(sycl_host_s_mul24, s::cl_int, s::cl_int, s::cl_int)
981 
982 } // namespace __host_std
#define __NOEXC
#define MAKE_1V_2V(Fun, Ret, Arg1, Arg2)
#define MAKE_1V(Fun, Ret, Arg1)
#define MAKE_1V_2S(Fun, Ret, Arg1, Arg2)
s::cl_uchar sycl_host_u_rhadd(s::cl_uchar x, s::cl_uchar y) __NOEXC
s::cl_char sycl_host_s_mul_hi(s::cl_char a, s::cl_char b)
MAKE_1V_2V_3V(sycl_host_fclamp, s::cl_float, s::cl_float, s::cl_float, s::cl_float) MAKE_1V_2V_3V(sycl_host_fclamp
s::cl_char sycl_host_s_rhadd(s::cl_char x, s::cl_char y) __NOEXC
s::cl_uchar sycl_host_u_hadd(s::cl_uchar x, s::cl_uchar y) __NOEXC
s::cl_uchar sycl_host_u_abs(s::cl_uchar x) __NOEXC
s::cl_uchar sycl_host_u_mul_hi(s::cl_uchar a, s::cl_uchar b)
s::cl_uchar sycl_host_u_add_sat(s::cl_uchar x, s::cl_uchar y) __NOEXC
s::cl_uchar sycl_host_s_abs(s::cl_char x) __NOEXC
s::cl_short s::cl_uchar sycl_host_clz(s::cl_uchar x) __NOEXC
s::cl_ushort s::cl_uchar s::cl_ulong s::cl_char sycl_host_s_clamp(s::cl_char x, s::cl_char minval, s::cl_char maxval) __NOEXC
s::cl_ushort s::cl_uchar MAKE_1V_2S_3S(sycl_host_u_clamp, s::cl_ushort, s::cl_ushort, s::cl_ushort, s::cl_ushort) MAKE_1V_2S_3S(sycl_host_u_clamp
s::cl_uchar sycl_host_s_abs_diff(s::cl_char x, s::cl_char y) __NOEXC
s::cl_uchar sycl_host_ctz(s::cl_uchar x) __NOEXC
s::cl_char sycl_host_s_add_sat(s::cl_char x, s::cl_char y) __NOEXC
s::cl_uchar sycl_host_u_clamp(s::cl_uchar x, s::cl_uchar minval, s::cl_uchar maxval) __NOEXC
s::cl_uchar sycl_host_u_abs_diff(s::cl_uchar x, s::cl_uchar y) __NOEXC
s::cl_char sycl_host_s_mad_hi(s::cl_char x, s::cl_char minval, s::cl_char maxval) __NOEXC
s::cl_char sycl_host_s_hadd(s::cl_char x, s::cl_char y) __NOEXC
static constexpr T min_v()
std::uint64_t cl_ulong
Definition: aliases.hpp:137
std::int32_t cl_int
Definition: aliases.hpp:134
std::int8_t cl_char
Definition: aliases.hpp:130
std::uint8_t cl_uchar
Definition: aliases.hpp:131
std::uint16_t cl_ushort
Definition: aliases.hpp:133
std::int16_t cl_short
Definition: aliases.hpp:132
std::uint32_t cl_uint
Definition: aliases.hpp:135
std::int64_t cl_long
Definition: aliases.hpp:136
static constexpr T __clz_impl(T x, T m, T n=0)
T detail::marray_element_t< T > y T T minval
static constexpr T __ctz(T x)
T detail::marray_element_t< T > y T T T maxval
T detail::marray_element_t< T > y T T T maxval[i] T T T a
y y maxval[j] maxval b
y y maxval[j] maxval c
y y maxval[j] maxval c[j] c[j] z
std::enable_if_t< detail::is_ugeninteger_v< T >, T > abs(T x)
static constexpr T __ctz_impl(T x, T m, T n=0)
static constexpr T __clz(T x)
Definition: access.hpp:18