Skip to content

Commit d0a6262

Browse files
committed
[SYCL][ESIMD] Fix compile-time evaluated functions, add test.
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
1 parent bc7cd5c commit d0a6262

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

sycl/include/CL/sycl/intel/esimd/detail/esimd_util.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ template <unsigned int N, unsigned int K> struct NextPowerOf2<N, K, false> {
3131
}
3232
};
3333

34-
template <unsigned int N> unsigned int getNextPowerOf2() {
34+
template <unsigned int N> constexpr unsigned int getNextPowerOf2() {
3535
return NextPowerOf2<N, 1, (1 >= N)>::get();
3636
}
3737

38-
template <> unsigned int getNextPowerOf2<0>() { return 0; }
38+
template <> constexpr unsigned int getNextPowerOf2<0>() { return 0; }
3939

4040
/// Compute binary logarithm of a constexpr with guaranteed compile-time
4141
/// evaluation.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clangxx -fsycl -fsycl-explicit-simd -fsycl-device-only -c %s
2+
// This test checks compile-time evaluation of functions from esimd_util.hpp
3+
4+
#include "CL/sycl.hpp"
5+
#include "CL/sycl/intel/esimd/esimd.hpp"
6+
7+
static_assert(__esimd::getNextPowerOf2<0>() == 0, "");
8+
static_assert(__esimd::getNextPowerOf2<1>() == 1, "");
9+
static_assert(__esimd::getNextPowerOf2<7>() == 8, "");
10+
static_assert(__esimd::getNextPowerOf2<1024>() == 1024, "");
11+
12+
static_assert(__esimd::log2<0>() == 0, "");
13+
static_assert(__esimd::log2<1>() == 0, "");
14+
static_assert(__esimd::log2<7>() == 2, "");
15+
static_assert(__esimd::log2<1024 * 1024>() == 20, "");

0 commit comments

Comments
 (0)