18 #include <type_traits>
20 #ifdef __SYCL_DEVICE_ONLY__
21 #define __ESIMD_INTRIN __DPCPP_SYCL_EXTERNAL SYCL_ESIMD_FUNCTION
22 #elif !defined(__ESIMD_BUILD_HOST_CODE)
23 #define __ESIMD_INTRIN ESIMD_NOINLINE __attribute__((internal_linkage))
25 #define __ESIMD_INTRIN inline
28 #ifdef __SYCL_DEVICE_ONLY__
29 #define __ESIMD_INTRIN_END ;
31 #define __ESIMD_INTRIN_END \
32 { __ESIMD_UNSUPPORTED_ON_HOST; }
36 inline namespace _V1 {
37 namespace ext::intel::esimd::detail {
41 enum { BYTE = 1, WORD = 2, DWORD = 4, QWORD = 8, OWORD = 16, GRF = 32 };
46 template <
unsigned int N,
unsigned int K,
bool K_gt_eq_N>
struct NextPowerOf2;
48 template <
unsigned int N,
unsigned int K>
struct NextPowerOf2<N, K, true> {
49 static constexpr
unsigned int get() {
return K; }
52 template <
unsigned int N,
unsigned int K>
struct NextPowerOf2<N, K, false> {
53 static constexpr
unsigned int get() {
54 return NextPowerOf2<N, K * 2, K * 2 >= N>
::get();
58 template <
unsigned int N> constexpr
unsigned int getNextPowerOf2() {
59 return NextPowerOf2<N, 1, (1 >= N)>::
get();
62 template <> constexpr
unsigned int getNextPowerOf2<0>() {
return 0; }
64 template <
unsigned int N,
unsigned int M>
65 constexpr
unsigned int roundUpNextMultiple() {
66 return ((N + M - 1) / M) * M;
71 template <
unsigned int N,
bool N_gt_1>
struct Log2;
73 template <
unsigned int N>
struct Log2<N, false> {
74 static constexpr
unsigned int get() {
return 0; }
77 template <
unsigned int N>
struct Log2<N, true> {
78 static constexpr
unsigned int get() {
79 return 1 + Log2<(N >> 1), ((N >> 1) > 1)>::
get();
83 template <
unsigned int N> constexpr
unsigned int log2() {
84 return Log2<N, (N > 1)>::
get();
88 template <
typename T>
struct is_esimd_vector :
public std::false_type {};
90 template <
typename T,
int N>
91 struct is_esimd_vector<
simd<T, N>> :
public std::true_type {};
93 template <
typename T,
int N>
94 using is_hw_int_type =
95 typename std::bool_constant<std::is_integral_v<T> && (
sizeof(T) == N)>;
97 template <
typename T>
using is_qword_type = is_hw_int_type<T, 8>;
98 template <
typename T>
using is_dword_type = is_hw_int_type<T, 4>;
99 template <
typename T>
using is_word_type = is_hw_int_type<T, 2>;
100 template <
typename T>
using is_byte_type = is_hw_int_type<T, 1>;
102 template <
typename T,
int N>
103 using is_hw_fp_type =
typename std::bool_constant<std::is_floating_point_v<T> &&
106 template <
typename T>
using is_fp_type = is_hw_fp_type<T, 4>;
107 template <
typename T>
using is_df_type = is_hw_fp_type<T, 8>;
109 template <
typename T>
110 using is_fp_or_dword_type =
111 typename std::bool_constant<is_fp_type<T>::value ||
112 is_dword_type<T>::value>;
115 template <
typename T>
struct simd_type {
118 template <
typename T,
int N>
struct simd_type<raw_vector_type<T, N>> {
122 template <
typename T>
struct simd_type<T &> {
123 using type =
typename simd_type<T>::type;
125 template <
typename T>
struct simd_type<T &&> {
126 using type =
typename simd_type<T>::type;
128 template <
typename T>
struct simd_type<const T> {
129 using type =
typename simd_type<T>::type;
132 template <
typename T>
struct dword_type {
135 template <>
struct dword_type<char> {
138 template <>
struct dword_type<short> {
141 template <>
struct dword_type<
uchar> {
144 template <>
struct dword_type<
ushort> {
148 template <
typename T>
struct byte_type {
151 template <>
struct byte_type<short> {
154 template <>
struct byte_type<int> {
157 template <>
struct byte_type<
ushort> {
160 template <>
struct byte_type<
uint> {
164 template <
typename T>
struct word_type {
167 template <>
struct word_type<char> {
170 template <>
struct word_type<int> {
173 template <>
struct word_type<
uchar> {
176 template <>
struct word_type<
uint> {
181 template <
unsigned N>
class ForHelper {
182 template <
unsigned I,
typename Action>
static void repeat(Action A) {
185 if constexpr (I + 1 < N)
186 repeat<I + 1, Action>(A);
190 template <
typename Action>
static void unroll(Action A) {
191 ForHelper::template repeat<0, Action>(A);
195 #ifdef __ESIMD_FORCE_STATELESS_MEM
198 template <
typename T,
typename AccessorTy,
typename OffsetTy = u
int32_t>
199 auto accessorToPointer(AccessorTy Acc, OffsetTy Offset = 0) {
200 using QualCharPtrType =
201 std::conditional_t<std::is_const_v<typename AccessorTy::value_type>,
202 const char *,
char *>;
204 std::conditional_t<std::is_const_v<typename AccessorTy::value_type>,
207 reinterpret_cast<QualCharPtrType
>(Acc.get_pointer().get()) + Offset;
208 return reinterpret_cast<QualTPtrType
>(BytePtr);
__ESIMD_API simd< T, N > log2(simd< T, N > src, Sat sat={})
Logarithm base 2.