From 4cb8561e54f6778a0ddf7f12c7ebdc864b723582 Mon Sep 17 00:00:00 2001 From: DenisBakhvalov <61807338+DenisBakhvalov@users.noreply.github.com> Date: Wed, 18 Aug 2021 23:27:16 -0700 Subject: [PATCH] [ESIMD] Fix negation operator to return a mask (#4353) --- .../ext/intel/experimental/esimd/detail/simd_view_impl.hpp | 1 - sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp | 4 +++- .../include/sycl/ext/intel/experimental/esimd/simd_view.hpp | 6 ++++++ sycl/test/esimd/simd_view.cpp | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_view_impl.hpp b/sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_view_impl.hpp index edd116d037e5..b7af652d5235 100644 --- a/sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_view_impl.hpp +++ b/sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_view_impl.hpp @@ -289,7 +289,6 @@ template class simd_view_impl { auto V = UNARY_OP(read().data()); \ return simd(V); \ } - DEF_UNARY_OP(!) DEF_UNARY_OP(~) DEF_UNARY_OP(+) DEF_UNARY_OP(-) diff --git a/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp b/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp index afac5a586ea2..26abc25916ae 100644 --- a/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp +++ b/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp @@ -352,13 +352,15 @@ template class simd { auto V = UNARY_OP(data()); \ return simd(V); \ } - DEF_UNARY_OP(!) DEF_UNARY_OP(~) DEF_UNARY_OP(+) DEF_UNARY_OP(-) #undef DEF_UNARY_OP + // negation operator + auto operator!() { return *this == 0; } + /// \name Replicate /// Replicate simd instance given a region. /// @{ diff --git a/sycl/include/sycl/ext/intel/experimental/esimd/simd_view.hpp b/sycl/include/sycl/ext/intel/experimental/esimd/simd_view.hpp index 4f531a8c8f5b..4de2551789c5 100644 --- a/sycl/include/sycl/ext/intel/experimental/esimd/simd_view.hpp +++ b/sycl/include/sycl/ext/intel/experimental/esimd/simd_view.hpp @@ -90,6 +90,9 @@ class simd_view : public detail::simd_view_impl { DEF_RELOP(!=) #undef DEF_RELOP + + // negation operator + auto operator!() { return *this == 0; } }; /// This is a specialization of simd_view class with a single element. @@ -142,6 +145,9 @@ class simd_view> DEF_RELOP(!=) #undef DEF_RELOP + + // negation operator + auto operator!() { return *this == 0; } }; } // namespace esimd diff --git a/sycl/test/esimd/simd_view.cpp b/sycl/test/esimd/simd_view.cpp index 735c0abfedc4..06a55693e688 100644 --- a/sycl/test/esimd/simd_view.cpp +++ b/sycl/test/esimd/simd_view.cpp @@ -31,7 +31,7 @@ SYCL_ESIMD_FUNCTION bool test_simd_view_unary_ops() { ref0 <<= ref1; ref1 = -ref0; ref0 = ~ref1; - ref1 = !ref0; + auto mask = !ref0; return v1[0] == 1; }