Skip to content

Commit 93eb065

Browse files
authored
[SYCL] Simplify make_(un)signed (#11514)
1 parent 9ef2b29 commit 93eb065

File tree

3 files changed

+35
-71
lines changed

3 files changed

+35
-71
lines changed

sycl/include/sycl/detail/type_traits.hpp

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -184,80 +184,35 @@ template <typename T, typename R> struct copy_cv_qualifiers {
184184
};
185185

186186
// make_signed with support SYCL vec class
187-
template <typename T, typename Enable = void> struct make_signed_impl;
188-
189-
template <typename T>
190-
using make_signed_impl_t = typename make_signed_impl<T, T>::type;
191-
192-
template <typename T>
193-
struct make_signed_impl<
194-
T, std::enable_if_t<is_contained<T, gtl::scalar_integer_list>::value, T>> {
187+
template <typename T> struct make_signed {
195188
using type = std::make_signed_t<T>;
196189
};
197-
198-
template <typename T>
199-
struct make_signed_impl<
200-
T, std::enable_if_t<is_contained<T, gtl::vector_integer_list>::value, T>> {
201-
using base_type = make_signed_impl_t<vector_element_t<T>>;
202-
using type = change_base_type_t<T, base_type>;
190+
template <typename T> using make_signed_t = typename make_signed<T>::type;
191+
template <class T> struct make_signed<const T> {
192+
using type = const make_signed_t<T>;
203193
};
204-
205-
// TODO Delete this specialization after solving the problems in the test
206-
// infrastructure.
207-
template <typename T>
208-
struct make_signed_impl<
209-
T, std::enable_if_t<!is_contained<T, gtl::integer_list>::value, T>> {
210-
using type = T;
194+
template <class T, int N> struct make_signed<vec<T, N>> {
195+
using type = vec<make_signed_t<T>, N>;
211196
};
212-
213-
template <typename T> struct make_signed {
214-
using new_type_wo_cv_qualifiers = make_signed_impl_t<std::remove_cv_t<T>>;
215-
using type = copy_cv_qualifiers_t<T, new_type_wo_cv_qualifiers>;
197+
template <class T, std::size_t N> struct make_signed<marray<T, N>> {
198+
using type = marray<make_signed_t<T>, N>;
216199
};
217200

218-
template <typename T> using make_signed_t = typename make_signed<T>::type;
219-
220201
// make_unsigned with support SYCL vec class
221-
template <typename T, typename Enable = void> struct make_unsigned_impl;
222-
223-
template <typename T>
224-
using make_unsigned_impl_t = typename make_unsigned_impl<T, T>::type;
225-
226-
template <typename T>
227-
struct make_unsigned_impl<
228-
T, std::enable_if_t<is_contained<T, gtl::scalar_integer_list>::value, T>> {
202+
template <typename T> struct make_unsigned {
229203
using type = std::make_unsigned_t<T>;
230204
};
231-
232-
template <typename T>
233-
struct make_unsigned_impl<
234-
T, std::enable_if_t<is_contained<T, gtl::vector_integer_list>::value, T>> {
235-
using base_type = make_unsigned_impl_t<vector_element_t<T>>;
236-
using type = change_base_type_t<T, base_type>;
237-
};
238-
239-
// TODO Delete this specialization after solving the problems in the test
240-
// infrastructure.
241-
template <typename T>
242-
struct make_unsigned_impl<
243-
T, std::enable_if_t<!is_contained<T, gtl::integer_list>::value, T>> {
244-
using type = T;
205+
template <typename T> using make_unsigned_t = typename make_unsigned<T>::type;
206+
template <class T> struct make_unsigned<const T> {
207+
using type = const make_unsigned_t<T>;
245208
};
246-
247-
template <typename T> struct make_unsigned {
248-
using new_type_wo_cv_qualifiers = make_unsigned_impl_t<std::remove_cv_t<T>>;
249-
using type = copy_cv_qualifiers_t<T, new_type_wo_cv_qualifiers>;
209+
template <class T, int N> struct make_unsigned<vec<T, N>> {
210+
using type = vec<make_unsigned_t<T>, N>;
250211
};
251-
252-
template <typename T, size_t N> struct make_unsigned<marray<T, N>> {
253-
using base_type = marray_element_t<marray<T, N>>;
254-
using new_type_wo_cv_qualifiers =
255-
make_unsigned_impl_t<std::remove_cv_t<base_type>>;
256-
using type = marray<copy_cv_qualifiers_t<T, new_type_wo_cv_qualifiers>, N>;
212+
template <class T, std::size_t N> struct make_unsigned<marray<T, N>> {
213+
using type = marray<make_unsigned_t<T>, N>;
257214
};
258215

259-
template <typename T> using make_unsigned_t = typename make_unsigned<T>::type;
260-
261216
// Checks that sizeof base type of T equal N and T satisfies S<T>::value
262217
template <typename T, int N, template <typename> class S>
263218
using is_gen_based_on_type_sizeof =

sycl/test/basic_tests/vectors/vectors.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@ template <typename From, typename To> void check_convert() {
3030
assert((int)result.w() == (int)vec.w());
3131
}
3232

33+
template <class T>
34+
constexpr auto has_unsigned_v =
35+
std::is_integral_v<T> && !std::is_same_v<T, bool>;
36+
3337
template <typename From, typename To> void check_signed_unsigned_convert_to() {
3438
check_convert<From, To>();
35-
check_convert<From, sycl::detail::make_unsigned_t<To>>();
36-
check_convert<sycl::detail::make_unsigned_t<From>, To>();
37-
check_convert<sycl::detail::make_unsigned_t<From>,
38-
sycl::detail::make_unsigned_t<To>>();
39+
if constexpr (has_unsigned_v<To>)
40+
check_convert<From, sycl::detail::make_unsigned_t<To>>();
41+
if constexpr (has_unsigned_v<From>)
42+
check_convert<sycl::detail::make_unsigned_t<From>, To>();
43+
if constexpr (has_unsigned_v<To> && has_unsigned_v<From>)
44+
check_convert<sycl::detail::make_unsigned_t<From>,
45+
sycl::detail::make_unsigned_t<To>>();
3946
}
4047

4148
template <typename From> void check_convert_from() {

sycl/test/regression/async_work_group_copy.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ template <typename T> void test() {
4646
async_work_group_test<vec<T, 4>>();
4747
async_work_group_test<vec<T, 8>>();
4848
async_work_group_test<vec<T, 16>>();
49-
async_work_group_test<detail::make_unsigned_t<T>>();
50-
async_work_group_test<vec<detail::make_unsigned_t<T>, 2>>();
51-
async_work_group_test<vec<detail::make_unsigned_t<T>, 3>>();
52-
async_work_group_test<vec<detail::make_unsigned_t<T>, 4>>();
53-
async_work_group_test<vec<detail::make_unsigned_t<T>, 8>>();
54-
async_work_group_test<vec<detail::make_unsigned_t<T>, 16>>();
49+
if constexpr (std::is_integral_v<T>) {
50+
async_work_group_test<detail::make_unsigned_t<T>>();
51+
async_work_group_test<vec<detail::make_unsigned_t<T>, 2>>();
52+
async_work_group_test<vec<detail::make_unsigned_t<T>, 3>>();
53+
async_work_group_test<vec<detail::make_unsigned_t<T>, 4>>();
54+
async_work_group_test<vec<detail::make_unsigned_t<T>, 8>>();
55+
async_work_group_test<vec<detail::make_unsigned_t<T>, 16>>();
56+
}
5557
}
5658

5759
int main() {

0 commit comments

Comments
 (0)