diff --git a/sycl/include/CL/sycl/types.hpp b/sycl/include/CL/sycl/types.hpp index a5b07eb291537..fb641df6ed5a5 100644 --- a/sycl/include/CL/sycl/types.hpp +++ b/sycl/include/CL/sycl/types.hpp @@ -242,9 +242,8 @@ using is_float_to_float = std::integral_constant::value && detail::is_floating_point::value>; template -using is_standard_type = std::integral_constant< - bool, detail::is_sgentype::value && !std::is_same::value && - !std::is_same::value>; +using is_standard_type = + std::integral_constant::value>; template @@ -330,7 +329,7 @@ convertImpl(T Value) { typename OpenCLT, typename OpenCLR> \ detail::enable_if_t::value && \ !std::is_same::value && \ - (std::is_same::value || \ + (std::is_same::value || \ (std::is_same::value && \ std::is_same::value)), \ R> \ @@ -352,7 +351,7 @@ __SYCL_GENERATE_CONVERT_IMPL(long) typename OpenCLT, typename OpenCLR> \ detail::enable_if_t::value && \ !std::is_same::value && \ - std::is_same::value, \ + std::is_same::value, \ R> \ convertImpl(T Value) { \ OpenCLT OpValue = cl::sycl::detail::convertDataToType(Value); \ @@ -454,7 +453,7 @@ __SYCL_GENERATE_CONVERT_IMPL_FOR_ROUNDING_MODE(rtn, Rtn) template \ detail::enable_if_t::value && \ - (std::is_same::value || \ + (std::is_same::value || \ std::is_same::value && \ std::is_same::value) && \ RoundingModeCondition::value, \ diff --git a/sycl/test/basic_tests/vectors/vectors.cpp b/sycl/test/basic_tests/vectors/vectors.cpp index dafbbc20a3e01..a3175f366d107 100644 --- a/sycl/test/basic_tests/vectors/vectors.cpp +++ b/sycl/test/basic_tests/vectors/vectors.cpp @@ -10,21 +10,52 @@ #define SYCL_SIMPLE_SWIZZLES #include -using namespace cl::sycl; -void check_vectors(int4 a, int4 b, int4 c, int4 gold) { - int4 result = a * (int4)b.y() + c; +void check_vectors(sycl::int4 a, sycl::int4 b, sycl::int4 c, sycl::int4 gold) { + sycl::int4 result = a * (sycl::int4)b.y() + c; assert((int)result.x() == (int)gold.x()); assert((int)result.y() == (int)gold.y()); - assert((int)result.w() == (int)gold.w()); assert((int)result.z() == (int)gold.z()); + assert((int)result.w() == (int)gold.w()); +} + +template void check_convert() { + sycl::vec vec{1, 2, 3, 4}; + sycl::vec result = vec.template convert(); + assert((int)result.x() == (int)vec.x()); + assert((int)result.y() == (int)vec.y()); + assert((int)result.z() == (int)vec.z()); + assert((int)result.w() == (int)vec.w()); +} + +template void check_signed_unsigned_convert_to() { + check_convert(); + check_convert>(); + check_convert, To>(); + check_convert, + sycl::detail::make_unsigned_t>(); +} + +template void check_convert_from() { + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); + check_signed_unsigned_convert_to(); } int main() { - int4 a = {1, 2, 3, 4}; - const int4 b = {10, 20, 30, 40}; - const int4 gold = {21, 42, 90, 120}; - const int2 a_xy = a.xy(); + sycl::int4 a = {1, 2, 3, 4}; + const sycl::int4 b = {10, 20, 30, 40}; + const sycl::int4 gold = {21, 42, 90, 120}; + const sycl::int2 a_xy = a.xy(); check_vectors(a, b, {1, 2, 30, 40}, gold); check_vectors(a, b, {a.x(), a.y(), b.z(), b.w()}, gold); check_vectors(a, b, {a.x(), 2, b.z(), 40}, gold); @@ -33,11 +64,11 @@ int main() { check_vectors(a, b, {a.xy(), b.zw()}, gold); // Constructing vector from a scalar - cl::sycl::vec vec_from_one_elem(1); + sycl::vec vec_from_one_elem(1); // implicit conversion - cl::sycl::vec vec_2(1, 2); - cl::sycl::vec vec_4(0, vec_2, 3); + sycl::vec vec_2(1, 2); + sycl::vec vec_4(0, vec_2, 3); assert(vec_4.get_count() == 4); assert(static_cast(vec_4.x()) == static_cast(0)); @@ -47,10 +78,10 @@ int main() { // explicit conversion int64_t(vec_2.x()); - cl::sycl::int4(vec_2.x()); + sycl::int4(vec_2.x()); // Check broadcasting operator= - cl::sycl::vec b_vec(1.0); + sycl::vec b_vec(1.0); b_vec = 0.5; assert(static_cast(b_vec.x()) == static_cast(0.5)); assert(static_cast(b_vec.y()) == static_cast(0.5)); @@ -60,27 +91,40 @@ int main() { // Check that vector with 'unsigned long long' elements has enough bits to // store value. unsigned long long ull_ref = 1ull - 2ull; - auto ull_vec = cl::sycl::vec(ull_ref); - unsigned long long ull_val = ull_vec.template swizzle(); + auto ull_vec = sycl::vec(ull_ref); + unsigned long long ull_val = ull_vec.template swizzle(); assert(ull_val == ull_ref); // Check that the function as() in swizzle vec class is working correctly - cl::sycl::vec inputVec = cl::sycl::vec(0, 1); - auto asVec = - inputVec.template swizzle() - .template as>(); + sycl::vec inputVec = sycl::vec(0, 1); + auto asVec = inputVec.template swizzle() + .template as>(); // Check that [u]long[n] type aliases match vec<[unsigned] long, n> types. - assert((std::is_same, cl::sycl::long2>::value)); - assert((std::is_same, cl::sycl::long3>::value)); - assert((std::is_same, cl::sycl::long4>::value)); - assert((std::is_same, cl::sycl::long8>::value)); - assert((std::is_same, cl::sycl::long16>::value)); - assert((std::is_same, cl::sycl::ulong2>::value)); - assert((std::is_same, cl::sycl::ulong3>::value)); - assert((std::is_same, cl::sycl::ulong4>::value)); - assert((std::is_same, cl::sycl::ulong8>::value)); - assert((std::is_same, cl::sycl::ulong16>::value)); + assert((std::is_same, sycl::long2>::value)); + assert((std::is_same, sycl::long3>::value)); + assert((std::is_same, sycl::long4>::value)); + assert((std::is_same, sycl::long8>::value)); + assert((std::is_same, sycl::long16>::value)); + assert((std::is_same, sycl::ulong2>::value)); + assert((std::is_same, sycl::ulong3>::value)); + assert((std::is_same, sycl::ulong4>::value)); + assert((std::is_same, sycl::ulong8>::value)); + assert((std::is_same, sycl::ulong16>::value)); + + // Check convert() from and to various types. + check_convert_from(); + check_convert_from(); + check_convert_from(); + check_convert_from(); + check_convert_from(); + check_convert_from(); + check_convert_from(); + check_convert_from(); + check_convert_from(); + check_convert_from(); + check_convert_from(); + check_convert_from(); return 0; }