Skip to content

Commit

Permalink
[SYCL] Refactor vec/swizzle implementations, remove expression trees
Browse files Browse the repository at this point in the history
  • Loading branch information
aelovikov-intel committed Jul 29, 2024
1 parent 3c2c938 commit 9f163f6
Show file tree
Hide file tree
Showing 10 changed files with 2,003 additions and 2,429 deletions.
40 changes: 12 additions & 28 deletions sycl/include/sycl/builtins_utils_vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ struct is_valid_elem_type<marray<T, N>, Ts...>
template <typename T, int N, typename... Ts>
struct is_valid_elem_type<vec<T, N>, Ts...>
: std::bool_constant<check_type_in_v<T, Ts...>> {};
template <typename VecT, typename OperationLeftT, typename OperationRightT,
template <typename> class OperationCurrentT, int... Indexes,
typename... Ts>
struct is_valid_elem_type<SwizzleOp<VecT, OperationLeftT, OperationRightT,
OperationCurrentT, Indexes...>,
Ts...>
template <typename VecT, int... Indexes, typename... Ts>
struct is_valid_elem_type<Swizzle<VecT, Indexes...>, Ts...>
: std::bool_constant<check_type_in_v<typename VecT::element_type, Ts...>> {
};
template <typename ElementType, access::address_space Space,
Expand All @@ -48,10 +44,8 @@ template <typename T, size_t N>
struct num_elements<marray<T, N>> : std::integral_constant<size_t, N> {};
template <typename T, int N>
struct num_elements<vec<T, N>> : std::integral_constant<size_t, size_t(N)> {};
template <typename VecT, typename OperationLeftT, typename OperationRightT,
template <typename> class OperationCurrentT, int... Indexes>
struct num_elements<SwizzleOp<VecT, OperationLeftT, OperationRightT,
OperationCurrentT, Indexes...>>
template <typename VecT, int... Indexes>
struct num_elements<Swizzle<VecT, Indexes...>>
: std::integral_constant<size_t, sizeof...(Indexes)> {};

// Utilty trait for checking that the number of elements in T is in Ns.
Expand All @@ -64,10 +58,8 @@ constexpr bool is_valid_size_v = is_valid_size<T, Ns...>::value;

// Utility for converting a swizzle to a vector or preserve the type if it isn't
// a swizzle.
template <typename VecT, typename OperationLeftT, typename OperationRightT,
template <typename> class OperationCurrentT, int... Indexes>
struct simplify_if_swizzle<SwizzleOp<VecT, OperationLeftT, OperationRightT,
OperationCurrentT, Indexes...>> {
template <typename VecT, int... Indexes>
struct simplify_if_swizzle<Swizzle<VecT, Indexes...>> {
using type = vec<typename VecT::element_type, sizeof...(Indexes)>;
};

Expand All @@ -83,10 +75,8 @@ template <typename T, size_t N> struct same_size_signed_int<marray<T, N>> {
template <typename T, int N> struct same_size_signed_int<vec<T, N>> {
using type = vec<typename same_size_signed_int<T>::type, N>;
};
template <typename VecT, typename OperationLeftT, typename OperationRightT,
template <typename> class OperationCurrentT, int... Indexes>
struct same_size_signed_int<SwizzleOp<VecT, OperationLeftT, OperationRightT,
OperationCurrentT, Indexes...>> {
template <typename VecT, int... Indexes>
struct same_size_signed_int<Swizzle<VecT, Indexes...>> {
// Converts to vec for simplicity.
using type =
vec<typename same_size_signed_int<typename VecT::element_type>::type,
Expand All @@ -99,10 +89,8 @@ template <typename T, size_t N> struct same_size_unsigned_int<marray<T, N>> {
template <typename T, int N> struct same_size_unsigned_int<vec<T, N>> {
using type = vec<typename same_size_unsigned_int<T>::type, N>;
};
template <typename VecT, typename OperationLeftT, typename OperationRightT,
template <typename> class OperationCurrentT, int... Indexes>
struct same_size_unsigned_int<SwizzleOp<VecT, OperationLeftT, OperationRightT,
OperationCurrentT, Indexes...>> {
template <typename VecT, int... Indexes>
struct same_size_unsigned_int<Swizzle<VecT, Indexes...>> {
// Converts to vec for simplicity.
using type =
vec<typename same_size_unsigned_int<typename VecT::element_type>::type,
Expand All @@ -122,12 +110,8 @@ template <typename NewElemT, typename T, int N>
struct change_elements<NewElemT, vec<T, N>> {
using type = vec<typename change_elements<NewElemT, T>::type, N>;
};
template <typename NewElemT, typename VecT, typename OperationLeftT,
typename OperationRightT, template <typename> class OperationCurrentT,
int... Indexes>
struct change_elements<NewElemT,
SwizzleOp<VecT, OperationLeftT, OperationRightT,
OperationCurrentT, Indexes...>> {
template <typename NewElemT, typename VecT, int... Indexes>
struct change_elements<NewElemT, Swizzle<VecT, Indexes...>> {
// Converts to vec for simplicity.
using type =
vec<typename change_elements<NewElemT, typename VecT::element_type>::type,
Expand Down
Loading

0 comments on commit 9f163f6

Please sign in to comment.