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