Skip to content

Commit b777b39

Browse files
committed
Add a test for various type combinations.
1 parent 1f463fe commit b777b39

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

sycl/test/basic_tests/vectors/vectors.cpp

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,48 @@
1010

1111
#define SYCL_SIMPLE_SWIZZLES
1212
#include <CL/sycl.hpp>
13-
using namespace cl::sycl;
1413

15-
void check_vectors(int4 a, int4 b, int4 c, int4 gold) {
16-
int4 result = a * (int4)b.y() + c;
14+
void check_vectors(cl::sycl::int4 a, cl::sycl::int4 b, cl::sycl::int4 c,
15+
cl::sycl::int4 gold) {
16+
cl::sycl::int4 result = a * (cl::sycl::int4)b.y() + c;
1717
assert((int)result.x() == (int)gold.x());
1818
assert((int)result.y() == (int)gold.y());
19-
assert((int)result.w() == (int)gold.w());
2019
assert((int)result.z() == (int)gold.z());
20+
assert((int)result.w() == (int)gold.w());
21+
}
22+
23+
template <typename From, typename To> void check_convert() {
24+
cl::sycl::vec<From, 4> vec{1, 2, 3, 4};
25+
cl::sycl::vec<To, 4> result = vec.template convert<To>();
26+
assert((int)result.x() == (int)vec.x());
27+
assert((int)result.y() == (int)vec.y());
28+
assert((int)result.z() == (int)vec.z());
29+
assert((int)result.w() == (int)vec.w());
30+
}
31+
32+
template <typename From, typename To> void check_signed_unsigned_convert_to() {
33+
check_convert<From, To>();
34+
check_convert<From, cl::sycl::detail::make_unsigned_t<To>>();
35+
check_convert<cl::sycl::detail::make_unsigned_t<From>, To>();
36+
check_convert<cl::sycl::detail::make_unsigned_t<From>,
37+
cl::sycl::detail::make_unsigned_t<To>>();
38+
}
39+
40+
template <typename From> void check_convert_from() {
41+
check_signed_unsigned_convert_to<From, int8_t>();
42+
check_signed_unsigned_convert_to<From, int16_t>();
43+
check_signed_unsigned_convert_to<From, int32_t>();
44+
check_signed_unsigned_convert_to<From, int64_t>();
45+
check_signed_unsigned_convert_to<From, half>();
46+
check_signed_unsigned_convert_to<From, float>();
47+
check_signed_unsigned_convert_to<From, double>();
2148
}
2249

2350
int main() {
24-
int4 a = {1, 2, 3, 4};
25-
const int4 b = {10, 20, 30, 40};
26-
const int4 gold = {21, 42, 90, 120};
27-
const int2 a_xy = a.xy();
51+
cl::sycl::int4 a = {1, 2, 3, 4};
52+
const cl::sycl::int4 b = {10, 20, 30, 40};
53+
const cl::sycl::int4 gold = {21, 42, 90, 120};
54+
const cl::sycl::int2 a_xy = a.xy();
2855
check_vectors(a, b, {1, 2, 30, 40}, gold);
2956
check_vectors(a, b, {a.x(), a.y(), b.z(), b.w()}, gold);
3057
check_vectors(a, b, {a.x(), 2, b.z(), 40}, gold);
@@ -82,5 +109,14 @@ int main() {
82109
assert((std::is_same<cl::sycl::vec<unsigned long, 8>, cl::sycl::ulong8>::value));
83110
assert((std::is_same<cl::sycl::vec<unsigned long, 16>, cl::sycl::ulong16>::value));
84111

112+
// Check convert() from and to various types.
113+
check_convert_from<int8_t>();
114+
check_convert_from<int16_t>();
115+
check_convert_from<int32_t>();
116+
check_convert_from<int64_t>();
117+
check_convert_from<half>();
118+
check_convert_from<float>();
119+
check_convert_from<double>();
120+
85121
return 0;
86122
}

0 commit comments

Comments
 (0)