Skip to content

Commit 00ce1fa

Browse files
[ESIMD][NFC] Refactored simd_view bitwise and relational ops (#4415)
* [ESIMD][NFC] Refactored simd_view bitwise and relational ops This patch removes versions of operators from the base class (simd_view_impl) that are guarded by SFINAE and puts them into the appropriate template specialization.
1 parent 16ca224 commit 00ce1fa

File tree

2 files changed

+58
-44
lines changed

2 files changed

+58
-44
lines changed

sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_view_impl.hpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -202,31 +202,6 @@ class simd_view_impl {
202202
}
203203

204204
#define DEF_BINOP(BINOP, OPASSIGN) \
205-
template <class T1 = Derived, class = std::enable_if_t<T1::length != 1>> \
206-
ESIMD_INLINE friend auto operator BINOP(const Derived &X, \
207-
const value_type &Y) { \
208-
using ComputeTy = detail::compute_type_t<value_type>; \
209-
auto V0 = \
210-
detail::convert<typename ComputeTy::vector_type>(X.read().data()); \
211-
auto V1 = detail::convert<typename ComputeTy::vector_type>(Y.data()); \
212-
auto V2 = V0 BINOP V1; \
213-
return ComputeTy(V2); \
214-
} \
215-
template <class T1 = Derived, class = std::enable_if_t<T1::length != 1>> \
216-
ESIMD_INLINE friend auto operator BINOP(const Derived &X, \
217-
const element_type &Y) { \
218-
return X BINOP(value_type) Y; \
219-
} \
220-
template <class T1 = Derived, class = std::enable_if_t<T1::length != 1>> \
221-
ESIMD_INLINE friend auto operator BINOP(const value_type &X, \
222-
const Derived &Y) { \
223-
using ComputeTy = detail::compute_type_t<value_type>; \
224-
auto V0 = detail::convert<typename ComputeTy::vector_type>(X.data()); \
225-
auto V1 = \
226-
detail::convert<typename ComputeTy::vector_type>(Y.read().data()); \
227-
auto V2 = V0 BINOP V1; \
228-
return ComputeTy(V2); \
229-
} \
230205
ESIMD_INLINE friend auto operator BINOP(const Derived &X, \
231206
const Derived &Y) { \
232207
return (X BINOP Y.read()); \
@@ -253,25 +228,6 @@ class simd_view_impl {
253228
#undef DEF_BINOP
254229

255230
#define DEF_BITWISE_OP(BITWISE_OP, OPASSIGN) \
256-
template <class T1 = Derived, class = std::enable_if_t<T1::length != 1>> \
257-
ESIMD_INLINE friend auto operator BITWISE_OP(const Derived &X, \
258-
const value_type &Y) { \
259-
static_assert(std::is_integral<element_type>(), "not integral type"); \
260-
auto V2 = X.read().data() BITWISE_OP Y.data(); \
261-
return simd<element_type, length>(V2); \
262-
} \
263-
template <class T1 = Derived, class = std::enable_if_t<T1::length != 1>> \
264-
ESIMD_INLINE friend auto operator BITWISE_OP(const Derived &X, \
265-
const element_type &Y) { \
266-
return X BITWISE_OP(value_type) Y; \
267-
} \
268-
template <class T1 = Derived, class = std::enable_if_t<T1::length != 1>> \
269-
ESIMD_INLINE friend auto operator BITWISE_OP(const value_type &X, \
270-
const Derived &Y) { \
271-
static_assert(std::is_integral<element_type>(), "not integral type"); \
272-
auto V2 = X.data() BITWISE_OP Y.read().data(); \
273-
return simd<element_type, length>(V2); \
274-
} \
275231
ESIMD_INLINE friend auto operator BITWISE_OP(const Derived &X, \
276232
const Derived &Y) { \
277233
return (X BITWISE_OP Y.read()); \

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,64 @@ class simd_view : public detail::simd_view_impl<BaseTy, RegionTy,
6868
return *this;
6969
}
7070

71+
#define DEF_BINOP(BINOP, OPASSIGN) \
72+
ESIMD_INLINE friend auto operator BINOP(const simd_view &X, \
73+
const value_type &Y) { \
74+
using ComputeTy = detail::compute_type_t<value_type>; \
75+
auto V0 = \
76+
detail::convert<typename ComputeTy::vector_type>(X.read().data()); \
77+
auto V1 = detail::convert<typename ComputeTy::vector_type>(Y.data()); \
78+
auto V2 = V0 BINOP V1; \
79+
return ComputeTy(V2); \
80+
} \
81+
ESIMD_INLINE friend auto operator BINOP(const simd_view &X, \
82+
const element_type &Y) { \
83+
return X BINOP(value_type) Y; \
84+
} \
85+
ESIMD_INLINE friend auto operator BINOP(const value_type &X, \
86+
const simd_view &Y) { \
87+
using ComputeTy = detail::compute_type_t<value_type>; \
88+
auto V0 = detail::convert<typename ComputeTy::vector_type>(X.data()); \
89+
auto V1 = \
90+
detail::convert<typename ComputeTy::vector_type>(Y.read().data()); \
91+
auto V2 = V0 BINOP V1; \
92+
return ComputeTy(V2); \
93+
}
94+
95+
DEF_BINOP(+, +=)
96+
DEF_BINOP(-, -=)
97+
DEF_BINOP(*, *=)
98+
DEF_BINOP(/, /=)
99+
DEF_BINOP(%, %=)
100+
101+
#undef DEF_BINOP
102+
103+
#define DEF_BITWISE_OP(BITWISE_OP, OPASSIGN) \
104+
ESIMD_INLINE friend auto operator BITWISE_OP(const simd_view &X, \
105+
const value_type &Y) { \
106+
static_assert(std::is_integral<element_type>(), "not integral type"); \
107+
auto V2 = X.read().data() BITWISE_OP Y.data(); \
108+
return simd<element_type, length>(V2); \
109+
} \
110+
ESIMD_INLINE friend auto operator BITWISE_OP(const simd_view &X, \
111+
const element_type &Y) { \
112+
return X BITWISE_OP(value_type) Y; \
113+
} \
114+
ESIMD_INLINE friend auto operator BITWISE_OP(const value_type &X, \
115+
const simd_view &Y) { \
116+
static_assert(std::is_integral<element_type>(), "not integral type"); \
117+
auto V2 = X.data() BITWISE_OP Y.read().data(); \
118+
return simd<element_type, length>(V2); \
119+
}
120+
121+
DEF_BITWISE_OP(&, &=)
122+
DEF_BITWISE_OP(|, |=)
123+
DEF_BITWISE_OP(^, ^=)
124+
DEF_BITWISE_OP(>>, >>=)
125+
DEF_BITWISE_OP(<<, <<=)
126+
127+
#undef DEF_BITWISE_OP
128+
71129
#define DEF_RELOP(RELOP) \
72130
ESIMD_INLINE friend simd<uint16_t, length> operator RELOP( \
73131
const simd_view &X, const value_type &Y) { \

0 commit comments

Comments
 (0)