From 3524739757ac432a67d674453a2d9b10e9cec565 Mon Sep 17 00:00:00 2001 From: aelovikov-intel Date: Fri, 13 Dec 2024 13:53:41 -0800 Subject: [PATCH] [SYCL] Implement "swizzle" member function on swizzles (#16353) It brings it closer to SYCL spec and makes more consistent by having "named" swizzle member functions (like `.hi()`/`.lo()`) and `.swizzle<...>()` behave in a similar way, i.e. we still have a bug when doing a swizzle on an expression tree. Note that the whole "expression tree" machinery is not standard-conformant and will be completely removed separately (under `-fpreview-breaking-changes` flag). I still want to implement this partial bugfix so that I could switch to a unified mixin-based implementation for swizzles on `vec`/`swizzle` classes, instead of doing preprocessor tricks with `swizzles.def` file. --- sycl/include/sycl/vector.hpp | 10 ++++++++++ sycl/test/basic_tests/vectors/swizzle.cpp | 16 ++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/sycl/include/sycl/vector.hpp b/sycl/include/sycl/vector.hpp index 97d9704c3cc26..75eb80cac829c 100644 --- a/sycl/include/sycl/vector.hpp +++ b/sycl/include/sycl/vector.hpp @@ -1207,6 +1207,16 @@ class SwizzleOp { }; public: + template + ConstSwizzle::value...> swizzle() const { + return m_Vector; + } + + template + Swizzle::value...> swizzle() { + return m_Vector; + } + #ifdef __SYCL_ACCESS_RETURN #error "Undefine __SYCL_ACCESS_RETURN macro" #endif diff --git a/sycl/test/basic_tests/vectors/swizzle.cpp b/sycl/test/basic_tests/vectors/swizzle.cpp index 3fb7717dcca0f..2c6ce60331dc8 100644 --- a/sycl/test/basic_tests/vectors/swizzle.cpp +++ b/sycl/test/basic_tests/vectors/swizzle.cpp @@ -1,9 +1,6 @@ // RUN: %clangxx -fsycl %s -o %t_default.out // RUN: %t_default.out -// FIXME: Everything should compile cleanly. -// RUN: %clangxx -fsycl -fsycl-device-only -DCHECK_ERRORS -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,error %s - #include int main() { @@ -15,27 +12,22 @@ int main() { // FIXME: Should be "4": assert((sw + sw).lo()[0] == 2); - // FIXME: The below should compile. -#if CHECK_ERRORS - // expected-error-re@+1 {{no template named 'swizzle' in {{.*}}}} assert(sw.swizzle<0>()[0] == 2); - // expected-error-re@+1 {{no template named 'swizzle' in {{.*}}}} assert(sw.swizzle<1>()[0] == 3); { - // expected-error-re@+1 {{no template named 'swizzle' in {{.*}}}} auto tmp = sw.swizzle<1, 0>(); assert(tmp[0] == 3); assert(tmp[1] == 2); } { - // expected-error-re@+1 {{no template named 'swizzle' in {{.*}}}} auto tmp = (sw + sw).swizzle<1, 0>(); - assert(tmp[0] == 6); - assert(tmp[1] == 4); + + // FIXME: Should be "6" and "4", respectively. + assert(tmp[0] == 3); + assert(tmp[1] == 2); } -#endif return 0; }