From 950c0838d3a672a267ec06ecf42b3dd7d37a2057 Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Wed, 13 Mar 2024 08:37:18 -0700 Subject: [PATCH 1/6] [SYCL] Make swizzle mutating operators const friends In https://github.com/intel/llvm/pull/12682 the mutating operators for swizzles (+=, -=, ..., ++, --) were reverted to be members rather than friends. Since swizzles mutate the underlying vec rather than themselves these operators should take and return constant references instead, which this commit implements. Signed-off-by: Larsen, Steffen --- sycl/include/sycl/types.hpp | 35 ++++++++- sycl/test-e2e/Regression/swizzle_opassign.cpp | 78 +++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 sycl/test-e2e/Regression/swizzle_opassign.cpp diff --git a/sycl/include/sycl/types.hpp b/sycl/include/sycl/types.hpp index 7d904a8246b03..4562f8fad4d83 100644 --- a/sycl/include/sycl/types.hpp +++ b/sycl/include/sycl/types.hpp @@ -1849,6 +1849,25 @@ class SwizzleOp { #ifdef __SYCL_OPASSIGN #error "Undefine __SYCL_OPASSIGN macro." #endif +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +#define __SYCL_OPASSIGN(OPASSIGN, OP) \ + friend const SwizzleOp &operator OPASSIGN(const SwizzleOp & Lhs, \ + const DataT & Rhs) { \ + Lhs.operatorHelper(vec_t(Rhs)); \ + return Lhs; \ + } \ + template \ + friend const SwizzleOp &operator OPASSIGN(const SwizzleOp & Lhs, \ + const RhsOperation & Rhs) { \ + Lhs.operatorHelper(Rhs); \ + return Lhs; \ + } \ + friend const SwizzleOp &operator OPASSIGN(const SwizzleOp & Lhs, \ + const vec_t & Rhs) { \ + Lhs.operatorHelper(Rhs); \ + return Lhs; \ + } +#else // __INTEL_PREVIEW_BREAKING_CHANGES #define __SYCL_OPASSIGN(OPASSIGN, OP) \ SwizzleOp &operator OPASSIGN(const DataT & Rhs) { \ operatorHelper(vec_t(Rhs)); \ @@ -1859,6 +1878,7 @@ class SwizzleOp { operatorHelper(Rhs); \ return *this; \ } +#endif // __INTEL_PREVIEW_BREAKING_CHANGES __SYCL_OPASSIGN(+=, std::plus) __SYCL_OPASSIGN(-=, std::minus) @@ -1875,6 +1895,18 @@ class SwizzleOp { #ifdef __SYCL_UOP #error "Undefine __SYCL_UOP macro" #endif +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +#define __SYCL_UOP(UOP, OPASSIGN) \ + friend const SwizzleOp &operator UOP(const SwizzleOp & sv) { \ + sv OPASSIGN static_cast(1); \ + return sv; \ + } \ + friend vec_t operator UOP(const SwizzleOp &sv, int) { \ + vec_t Ret = sv; \ + sv OPASSIGN static_cast(1); \ + return Ret; \ + } +#else // __INTEL_PREVIEW_BREAKING_CHANGES #define __SYCL_UOP(UOP, OPASSIGN) \ SwizzleOp &operator UOP() { \ *this OPASSIGN static_cast(1); \ @@ -1885,6 +1917,7 @@ class SwizzleOp { *this OPASSIGN static_cast(1); \ return Ret; \ } +#endif // __INTEL_PREVIEW_BREAKING_CHANGES __SYCL_UOP(++, +=) __SYCL_UOP(--, -=) @@ -2416,7 +2449,7 @@ class SwizzleOp { } template