Skip to content

Commit 4cbae16

Browse files
[NFCI][SYCL] Inline some traits related to fixed width int types (#16904)
Main reason is to avoid having partial specializations for swizzles in the implementation of the traits as we're going to have big changes in that area. Between this change and having to update the traits this approach seemed better.
1 parent a49e92e commit 4cbae16

File tree

4 files changed

+29
-71
lines changed

4 files changed

+29
-71
lines changed

sycl/include/sycl/builtins_utils_scalar.hpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,37 +80,6 @@ constexpr bool check_all_same_op_type_v = CheckAllSameOpType<Ts...>();
8080
// as MSVC thinks function definitions are the same otherwise.
8181
template <size_t... Ns> constexpr bool check_size_in_v = CheckSizeIn<Ns...>();
8282

83-
// Utility traits for getting a signed integer type with the specified size.
84-
template <size_t Size> struct get_signed_int_by_size {
85-
using type = select_scalar_by_size_t<Size, int8_t, int16_t, int32_t, int64_t>;
86-
};
87-
template <typename T> struct same_size_signed_int {
88-
using type = typename get_signed_int_by_size<sizeof(T)>::type;
89-
};
90-
91-
template <typename T>
92-
using same_size_signed_int_t = typename same_size_signed_int<T>::type;
93-
94-
// Utility traits for getting a unsigned integer type with the specified size.
95-
template <size_t Size> struct get_unsigned_int_by_size {
96-
using type =
97-
select_scalar_by_size_t<Size, uint8_t, uint16_t, uint32_t, uint64_t>;
98-
};
99-
template <typename T> struct same_size_unsigned_int {
100-
using type = typename get_unsigned_int_by_size<sizeof(T)>::type;
101-
};
102-
template <typename T>
103-
using same_size_unsigned_int_t = typename same_size_unsigned_int<T>::type;
104-
105-
template <typename T> struct get_fixed_sized_int {
106-
static_assert(std::is_integral_v<T>);
107-
using type =
108-
std::conditional_t<std::is_signed_v<T>, same_size_signed_int_t<T>,
109-
same_size_unsigned_int_t<T>>;
110-
};
111-
template <typename T>
112-
using get_fixed_sized_int_t = typename get_fixed_sized_int<T>::type;
113-
11483
// Utility for converting a swizzle to a vector or preserve the type if it isn't
11584
// a swizzle.
11685
template <typename T> struct simplify_if_swizzle {

sycl/include/sycl/builtins_utils_vec.hpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,6 @@ struct is_same_op<
4444
std::enable_if_t<is_vec_or_swizzle_v<T1> && is_vec_or_swizzle_v<T2>>>
4545
: std::is_same<simplify_if_swizzle_t<T1>, simplify_if_swizzle_t<T2>> {};
4646

47-
template <typename T, size_t N> struct same_size_signed_int<marray<T, N>> {
48-
using type = marray<typename same_size_signed_int<T>::type, N>;
49-
};
50-
template <typename T, int N> struct same_size_signed_int<vec<T, N>> {
51-
using type = vec<typename same_size_signed_int<T>::type, N>;
52-
};
53-
template <typename VecT, typename OperationLeftT, typename OperationRightT,
54-
template <typename> class OperationCurrentT, int... Indexes>
55-
struct same_size_signed_int<SwizzleOp<VecT, OperationLeftT, OperationRightT,
56-
OperationCurrentT, Indexes...>> {
57-
// Converts to vec for simplicity.
58-
using type =
59-
vec<typename same_size_signed_int<typename VecT::element_type>::type,
60-
sizeof...(Indexes)>;
61-
};
62-
63-
template <typename T, size_t N> struct same_size_unsigned_int<marray<T, N>> {
64-
using type = marray<typename same_size_unsigned_int<T>::type, N>;
65-
};
66-
template <typename T, int N> struct same_size_unsigned_int<vec<T, N>> {
67-
using type = vec<typename same_size_unsigned_int<T>::type, N>;
68-
};
69-
template <typename VecT, typename OperationLeftT, typename OperationRightT,
70-
template <typename> class OperationCurrentT, int... Indexes>
71-
struct same_size_unsigned_int<SwizzleOp<VecT, OperationLeftT, OperationRightT,
72-
OperationCurrentT, Indexes...>> {
73-
// Converts to vec for simplicity.
74-
using type =
75-
vec<typename same_size_unsigned_int<typename VecT::element_type>::type,
76-
sizeof...(Indexes)>;
77-
};
78-
7947
// Utility trait for changing the element type of a type T. If T is a scalar,
8048
// the new type replaces T completely.
8149
template <typename NewElemT, typename T> struct change_elements {

sycl/include/sycl/detail/builtins/builtins.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ auto builtin_marray_impl(FuncTy F, const Ts &...x) {
116116
auto PartialRes = [&]() {
117117
using elem_ty = get_elem_type_t<T>;
118118
if constexpr (std::is_integral_v<elem_ty>)
119-
return F(to_vec2(x, I * 2)
120-
.template as<vec<get_fixed_sized_int_t<elem_ty>, 2>>()...);
119+
return F(
120+
to_vec2(x, I * 2)
121+
.template as<vec<
122+
std::conditional_t<std::is_signed_v<elem_ty>,
123+
fixed_width_signed<sizeof(elem_ty)>,
124+
fixed_width_unsigned<sizeof(elem_ty)>>,
125+
2>>()...);
121126
else
122127
return F(to_vec2(x, I * 2)...);
123128
}();

sycl/include/sycl/detail/builtins/relational_functions.inc

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,29 @@ struct bitselect_elem_type
2222
(!is_vec_or_swizzle_v<T> &&
2323
check_type_in_v<get_elem_type_t<T>, INTEGER_TYPES>)> {};
2424

25+
template <typename T, typename = void> struct rel_ret_traits_impl {
26+
// Return type trait is instantiated even if the arguments don't pass
27+
// requirements check. Make sure it doesn't cause an error.
28+
using type = void;
29+
};
30+
31+
template <typename T>
32+
struct rel_ret_traits_impl<T, std::enable_if_t<is_scalar_arithmetic_v<T>>> {
33+
using type = bool;
34+
};
35+
2536
template <typename T>
26-
struct rel_ret_traits
27-
: std::conditional<is_scalar_arithmetic_v<T>, bool,
28-
std::conditional_t<
29-
is_marray_v<T>, marray<bool, num_elements<T>::value>,
30-
same_size_signed_int_t<simplify_if_swizzle_t<T>>>> {
37+
struct rel_ret_traits_impl<T, std::enable_if_t<is_marray_v<T>>> {
38+
using type = marray<bool, T::size()>;
3139
};
40+
41+
template <typename T>
42+
struct rel_ret_traits_impl<T, std::enable_if_t<is_vec_or_swizzle_v<T>>> {
43+
using type =
44+
vec<fixed_width_signed<sizeof(typename T::element_type)>, T::size()>;
45+
};
46+
47+
template <typename T> using rel_ret_traits = rel_ret_traits_impl<T>;
3248
} // namespace detail
3349

3450
BUILTIN_CREATE_ENABLER(builtin_enable_bitselect, default_ret_type,
@@ -67,7 +83,7 @@ auto builtin_delegate_rel_impl(FuncTy F, const Ts &...x) {
6783
return F(simplify_if_swizzle_t<T>{x}...);
6884
} else if constexpr (is_vec_v<T>) {
6985
// TODO: using Res{} to avoid Werror. Not sure if ok.
70-
vec<same_size_signed_int_t<get_elem_type_t<T>>, T::size()> Res{};
86+
vec<fixed_width_signed<sizeof(typename T::element_type)>, T::size()> Res{};
7187
detail::loop<T::size()>(
7288
[&](auto idx) { Res[idx] = F(x[idx]...) ? -1 : 0; });
7389
return Res;

0 commit comments

Comments
 (0)