Skip to content

Commit 1717a14

Browse files
authored
[SYCL][ESIMD] Add support for esimd_trunc function (#4624)
* [SYCL][ESIMD] Add support for esimd_trunc function Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent 007f6b2 commit 1717a14

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,32 @@ ESIMD_INLINE RT esimd_ceil(const float &src0, const uint flags = 0) {
19141914
return esimd_rndu<RT, 1U>(src0, flags);
19151915
}
19161916

1917+
/// Round to integral value using the round to zero rounding mode (vector
1918+
/// version).
1919+
/// \tparam RT element type of the return vector.
1920+
/// \tparam SZ size of the input and returned vectors.
1921+
/// @param src0 the input vector.
1922+
/// @param flag enables/disables the saturation (off by default). Possible
1923+
/// values: saturation_on/saturation_off.
1924+
/// @return vector of rounded values.
1925+
template <typename RT, int SZ>
1926+
ESIMD_NODEBUG ESIMD_INLINE simd<RT, SZ> esimd_trunc(const simd<float, SZ> &src0,
1927+
const uint flag = 0) {
1928+
return esimd_rndz<RT, SZ>(src0, flag);
1929+
}
1930+
1931+
/// Round to integral value using the round to zero rounding mode (scalar
1932+
/// version).
1933+
/// \tparam RT type of the return value.
1934+
/// @param src0 the input operand.
1935+
/// @param flag enables/disables the saturation (off by default). Possible
1936+
/// values: saturation_on/saturation_off.
1937+
/// @return rounded value.
1938+
template <typename RT>
1939+
ESIMD_NODEBUG ESIMD_INLINE RT esimd_trunc(float src0, const uint flag = 0) {
1940+
return esimd_rndz<RT, 1U>(src0, flag)[0];
1941+
}
1942+
19171943
/* esimd_atan2_fast - a fast atan2 implementation */
19181944
/* vector input */
19191945
template <int N>

sycl/test/esimd/esimd_math.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,15 @@ bool test_esimd_dp4() __attribute__((sycl_device)) {
6060
return (ret[0] == ret[1] && ret[1] == ret[2] && ret[2] == ret[3]) &&
6161
(ret[0] == 14.0f && ret[4] == 126.0f);
6262
}
63+
64+
bool test_esimd_trunc() __attribute__((sycl_device)) {
65+
simd<float, 16> vfa(1.4f);
66+
simd<float, 16> vfr = esimd_trunc<float, 16>(vfa);
67+
simd<short, 16> vsr = esimd_trunc<short, 16>(vfa);
68+
69+
float sfa = 2.8f;
70+
float sfr = esimd_trunc<float>(sfa);
71+
short ssr = esimd_trunc<short>(sfa);
72+
73+
return (vfr[0] == 1.f) && (vsr[0] == 1) && (sfr == 2.f) && (ssr == 2);
74+
}

0 commit comments

Comments
 (0)