Skip to content

Commit 4e41992

Browse files
authored
[SYCL][ESIMD][E2E] Fix rotate.cpp on Windows (intel#14152)
The rotate functions are technically c++20 and MSVC hasn't implemented them yet. Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
1 parent c2e5529 commit 4e41992

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

sycl/test-e2e/ESIMD/rotate.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
#define NS sycl::ext::intel::esimd
2222
#endif
2323

24+
// https://stackoverflow.com/questions/776508
25+
template <typename T> T rotl(T n, unsigned int c) {
26+
const unsigned int mask = (CHAR_BIT * sizeof(n) - 1);
27+
c &= mask;
28+
return (n << c) | (n >> ((-c) & mask));
29+
}
30+
31+
template <typename T> T rotr(T n, unsigned int c) {
32+
const unsigned int mask = (CHAR_BIT * sizeof(n) - 1);
33+
c &= mask;
34+
return (n >> c) | (n << ((-c) & mask));
35+
}
36+
2437
using namespace sycl;
2538
using namespace sycl::ext::intel::esimd;
2639

@@ -85,14 +98,14 @@ template <typename T> bool test_rotate(sycl::queue &Queue) {
8598

8699
for (int I = 0; I < VL; I++) {
87100
using OpT = std::make_unsigned_t<T>;
88-
ExpectedRorScalar[I] = std::rotr<OpT>(
89-
sycl::bit_cast<OpT>(ExpectedRorScalar[I]), ScalarRotateFactor);
90-
ExpectedRolScalar[I] = std::rotl<OpT>(
91-
sycl::bit_cast<OpT>(ExpectedRolScalar[I]), ScalarRotateFactor);
92-
ExpectedRorVector[I] = std::rotr<OpT>(
93-
sycl::bit_cast<OpT>(ExpectedRorVector[I]), VectorRotateFactor[I]);
94-
ExpectedRolVector[I] = std::rotl<OpT>(
95-
sycl::bit_cast<OpT>(ExpectedRolVector[I]), VectorRotateFactor[I]);
101+
ExpectedRorScalar[I] = rotr<OpT>(sycl::bit_cast<OpT>(ExpectedRorScalar[I]),
102+
ScalarRotateFactor);
103+
ExpectedRolScalar[I] = rotl<OpT>(sycl::bit_cast<OpT>(ExpectedRolScalar[I]),
104+
ScalarRotateFactor);
105+
ExpectedRorVector[I] = rotr<OpT>(sycl::bit_cast<OpT>(ExpectedRorVector[I]),
106+
VectorRotateFactor[I]);
107+
ExpectedRolVector[I] = rotl<OpT>(sycl::bit_cast<OpT>(ExpectedRolVector[I]),
108+
VectorRotateFactor[I]);
96109
}
97110
for (int I = 0; I < VL; I++) {
98111
if (ExpectedRorScalar[I] != OutputRorScalar[I]) {

0 commit comments

Comments
 (0)