12
12
13
13
#ifndef __SYCL_DEVICE_ONLY__
14
14
15
+ #include < assert.h>
15
16
#include < limits>
16
17
18
+ #include < sycl/ext/intel/experimental/esimd/detail/elem_type_traits.hpp>
19
+
17
20
#define SIMDCF_ELEMENT_SKIP (i )
18
21
19
22
__SYCL_INLINE_NAMESPACE (cl) {
@@ -46,7 +49,12 @@ static long long abs(long long a) {
46
49
}
47
50
}
48
51
49
- template <typename RT> struct satur {
52
+ template <typename RT, class SFINAE = void > struct satur ;
53
+
54
+ template <typename RT>
55
+ struct satur <RT, std::enable_if_t <std::is_integral_v<RT>>> {
56
+ static_assert (!__SEIEED::is_wrapper_elem_type_v<RT>);
57
+
50
58
template <typename T> static RT saturate (const T val, const int flags) {
51
59
if ((flags & sat_is_on) == 0 ) {
52
60
return (RT)val;
@@ -72,35 +80,29 @@ template <typename RT> struct satur {
72
80
}
73
81
};
74
82
75
- template <> struct satur <float > {
76
- template <typename T> static float saturate (const T val, const int flags) {
77
- if ((flags & sat_is_on) == 0 ) {
78
- return (float )val;
79
- }
80
-
81
- if (val < 0 .) {
82
- return 0 ;
83
- } else if (val > 1 .) {
84
- return 1 .;
85
- } else {
86
- return (float )val;
87
- }
88
- }
89
- };
90
-
91
- template <> struct satur <double > {
92
- template <typename T> static double saturate (const T val, const int flags) {
93
- if ((flags & sat_is_on) == 0 ) {
94
- return (double )val;
83
+ // Host implemenation of saturation for FP types, including non-standarad
84
+ // wrapper types such as sycl::half. Template parameters are defined in terms
85
+ // of user-level types (sycl::half), function parameter and return types -
86
+ // in terms of raw bit representation type(_Float16 for half on device).
87
+ template <class Tdst >
88
+ struct satur <Tdst,
89
+ std::enable_if_t <__SEIEED::is_generic_floating_point_v<Tdst>>> {
90
+ template <typename Tsrc>
91
+ static __SEIEED::__raw_t <Tdst> saturate (const __SEIEED::__raw_t <Tsrc> raw_src,
92
+ const int flags) {
93
+ Tsrc src = __SEIEED::bitcast_to_wrapper_type<Tsrc>(raw_src);
94
+
95
+ // perform comparison on user type!
96
+ if ((flags & sat_is_on) == 0 || (src >= 0 && src <= 1 )) {
97
+ // convert_scalar accepts/returns user types - need to bitcast
98
+ Tdst dst = __SEIEED::convert_scalar<Tdst, Tsrc>(src);
99
+ return __SEIEED::bitcast_to_raw_type<Tdst>(dst);
95
100
}
96
-
97
- if (val < 0 .) {
98
- return 0 ;
99
- } else if (val > 1 .) {
100
- return 1 .;
101
- } else {
102
- return (double )val;
101
+ if (src < 0 ) {
102
+ return __SEIEED::bitcast_to_raw_type<Tdst>(Tdst{0 });
103
103
}
104
+ assert (src > 1 );
105
+ return __SEIEED::bitcast_to_raw_type<Tdst>(Tdst{1 });
104
106
}
105
107
};
106
108
@@ -116,6 +118,10 @@ template <> struct SetSatur<double, true> {
116
118
static unsigned int set () { return sat_is_on; }
117
119
};
118
120
121
+ // TODO replace restype_ex with detail::computation_type_t and represent half
122
+ // as sycl::half rather than 'using half = sycl::detail::half_impl::half;'
123
+ // above
124
+
119
125
// used for intermediate type in dp4a emulation
120
126
template <typename T1, typename T2> struct restype_ex {
121
127
private:
@@ -430,36 +436,6 @@ template <> struct fptype<float> { static const bool value = true; };
430
436
template <typename T> struct dftype { static const bool value = false ; };
431
437
template <> struct dftype <double > { static const bool value = true ; };
432
438
433
- template <typename T> struct esimdtype ;
434
- template <> struct esimdtype <char > { static const bool value = true ; };
435
-
436
- template <> struct esimdtype <signed char > { static const bool value = true ; };
437
-
438
- template <> struct esimdtype <unsigned char > { static const bool value = true ; };
439
-
440
- template <> struct esimdtype <short > { static const bool value = true ; };
441
-
442
- template <> struct esimdtype <unsigned short > {
443
- static const bool value = true ;
444
- };
445
- template <> struct esimdtype <int > { static const bool value = true ; };
446
-
447
- template <> struct esimdtype <unsigned int > { static const bool value = true ; };
448
-
449
- template <> struct esimdtype <unsigned long > { static const bool value = true ; };
450
-
451
- template <> struct esimdtype <half> { static const bool value = true ; };
452
-
453
- template <> struct esimdtype <float > { static const bool value = true ; };
454
-
455
- template <> struct esimdtype <double > { static const bool value = true ; };
456
-
457
- template <> struct esimdtype <long long > { static const bool value = true ; };
458
-
459
- template <> struct esimdtype <unsigned long long > {
460
- static const bool value = true ;
461
- };
462
-
463
439
template <typename T> struct bytetype ;
464
440
template <> struct bytetype <char > { static const bool value = true ; };
465
441
template <> struct bytetype <unsigned char > { static const bool value = true ; };
0 commit comments