18 #include <type_traits>
20 #ifdef __SYCL_DEVICE_ONLY__
21 #define __ESIMD_INTRIN __DPCPP_SYCL_EXTERNAL SYCL_ESIMD_FUNCTION
23 #define __ESIMD_INTRIN inline
24 #endif // __SYCL_DEVICE_ONLY__
28 namespace ext::intel::esimd::detail {
32 enum { BYTE = 1, WORD = 2, DWORD = 4, QWORD = 8, OWORD = 16, GRF = 32 };
37 template <
unsigned int N,
unsigned int K,
bool K_gt_eq_N>
struct NextPowerOf2;
39 template <
unsigned int N,
unsigned int K>
struct NextPowerOf2<N, K, true> {
40 static constexpr
unsigned int get() {
return K; }
43 template <
unsigned int N,
unsigned int K>
struct NextPowerOf2<N, K, false> {
44 static constexpr
unsigned int get() {
45 return NextPowerOf2<N, K * 2, K * 2 >= N>
::get();
49 template <
unsigned int N> constexpr
unsigned int getNextPowerOf2() {
50 return NextPowerOf2<N, 1, (1 >= N)>::
get();
53 template <> constexpr
unsigned int getNextPowerOf2<0>() {
return 0; }
57 template <
unsigned int N,
bool N_gt_1>
struct Log2;
59 template <
unsigned int N>
struct Log2<N, false> {
60 static constexpr
unsigned int get() {
return 0; }
63 template <
unsigned int N>
struct Log2<N, true> {
64 static constexpr
unsigned int get() {
65 return 1 + Log2<(N >> 1), ((N >> 1) > 1)>::
get();
69 template <
unsigned int N> constexpr
unsigned int log2() {
70 return Log2<N, (N > 1)>::
get();
74 template <
typename T>
struct is_esimd_vector :
public std::false_type {};
76 template <
typename T,
int N>
77 struct is_esimd_vector<
simd<
T, N>> :
public std::true_type {};
79 template <
typename T,
int N>
80 using is_hw_int_type =
81 typename std::bool_constant<std::is_integral_v<T> && (
sizeof(
T) == N)>;
83 template <
typename T>
using is_qword_type = is_hw_int_type<T, 8>;
84 template <
typename T>
using is_dword_type = is_hw_int_type<T, 4>;
85 template <
typename T>
using is_word_type = is_hw_int_type<T, 2>;
86 template <
typename T>
using is_byte_type = is_hw_int_type<T, 1>;
88 template <
typename T,
int N>
89 using is_hw_fp_type =
typename std::bool_constant<std::is_floating_point_v<T> &&
92 template <
typename T>
using is_fp_type = is_hw_fp_type<T, 4>;
93 template <
typename T>
using is_df_type = is_hw_fp_type<T, 8>;
96 using is_fp_or_dword_type =
97 typename std::bool_constant<is_fp_type<T>::value ||
98 is_dword_type<T>::value>;
101 template <
typename T>
struct simd_type {
104 template <
typename T,
int N>
struct simd_type<raw_vector_type<
T, N>> {
108 template <
typename T>
struct simd_type<
T &> {
109 using type =
typename simd_type<T>::type;
111 template <
typename T>
struct simd_type<
T &&> {
112 using type =
typename simd_type<T>::type;
114 template <
typename T>
struct simd_type<const
T> {
115 using type =
typename simd_type<T>::type;
118 template <
typename T>
struct dword_type {
121 template <>
struct dword_type<char> {
124 template <>
struct dword_type<short> {
127 template <>
struct dword_type<
uchar> {
130 template <>
struct dword_type<
ushort> {
134 template <
typename T>
struct byte_type {
137 template <>
struct byte_type<short> {
140 template <>
struct byte_type<int> {
143 template <>
struct byte_type<
ushort> {
146 template <>
struct byte_type<
uint> {
150 template <
typename T>
struct word_type {
153 template <>
struct word_type<char> {
156 template <>
struct word_type<int> {
159 template <>
struct word_type<
uchar> {
162 template <>
struct word_type<
uint> {
167 template <
unsigned N>
class ForHelper {
168 template <
unsigned I,
typename Action>
static inline void repeat(Action A) {
171 if constexpr (I + 1 < N)
172 repeat<I + 1, Action>(A);
176 template <
typename Action>
static inline void unroll(Action A) {
177 ForHelper::template repeat<0, Action>(A);
181 #ifdef __ESIMD_FORCE_STATELESS_MEM
182 template <
typename T,
typename AccessorTy,
typename OffsetTy = u
int32_t>
185 auto accessorToPointer(AccessorTy Acc, OffsetTy Offset = 0) {
186 using QualCharPtrType =
187 std::conditional_t<std::is_const_v<typename AccessorTy::value_type>,
188 const char *,
char *>;
190 std::conditional_t<std::is_const_v<typename AccessorTy::value_type>,
192 auto BytePtr =
reinterpret_cast<QualCharPtrType
>(Acc.get_pointer()) + Offset;
193 return reinterpret_cast<QualTPtrType
>(BytePtr);
195 #endif // __ESIMD_FORCE_STATELESS_MEM