Skip to content

Commit 3979516

Browse files
authored
[ESIMD] esimd::saturate : fix bug, hide unsupported type combinations. (#5441)
* [ESIMD] esimd::saturate : fix bug, hide unsupported type combinations. Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent 56af04a commit 3979516

File tree

1 file changed

+12
-4
lines changed
  • sycl/include/sycl/ext/intel/experimental/esimd

1 file changed

+12
-4
lines changed

sycl/include/sycl/ext/intel/experimental/esimd/math.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ namespace esimd {
3939
/// @param src the input vector.
4040
/// @return vector of elements converted to \p T0 with saturation.
4141
template <typename T0, typename T1, int SZ>
42-
__ESIMD_API simd<T0, SZ> saturate(simd<T1, SZ> src) {
42+
__ESIMD_API std::enable_if_t<!detail::is_generic_floating_point_v<T0> ||
43+
std::is_same_v<T1, T0>,
44+
simd<T0, SZ>>
45+
saturate(simd<T1, SZ> src) {
4346
if constexpr (detail::is_generic_floating_point_v<T0>)
4447
return __esimd_sat<T0, T1, SZ>(src.data());
4548
else if constexpr (detail::is_generic_floating_point_v<T1>) {
@@ -54,9 +57,9 @@ __ESIMD_API simd<T0, SZ> saturate(simd<T1, SZ> src) {
5457
return __esimd_ustrunc_sat<T0, T1, SZ>(src.data());
5558
} else {
5659
if constexpr (std::is_signed<T1>::value)
57-
return __esimd_sutrunc_sat<T0, T1, SZ>(src.data());
58-
else
5960
return __esimd_sstrunc_sat<T0, T1, SZ>(src.data());
61+
else
62+
return __esimd_sutrunc_sat<T0, T1, SZ>(src.data());
6063
}
6164
}
6265

@@ -1723,7 +1726,12 @@ ESIMD_NODEBUG ESIMD_INLINE T exp(T src0) {
17231726
simd<float, SZ> Result = __esimd_##name<SZ>(src0.data()); \
17241727
if (flag != saturation_on) \
17251728
return Result; \
1726-
return esimd::saturate<T>(Result); \
1729+
if constexpr (!std::is_same_v<float, T>) { \
1730+
auto RawRes = esimd::saturate<float>(Result).data(); \
1731+
return detail::convert_vector<T, float, SZ>(std::move(RawRes)); \
1732+
} else { \
1733+
return esimd::saturate<T>(Result); \
1734+
} \
17271735
} \
17281736
template <typename T> \
17291737
__ESIMD_API T name(float src0, int flag = saturation_off) { \

0 commit comments

Comments
 (0)