[libcxx-commits] [libcxx] [libc++] <experimental/simd> Add compound assignment operators for simd reference (PR #86761)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 19 00:24:06 PDT 2024


================
@@ -0,0 +1,101 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// <experimental/simd>
+//
+// [simd.reference]
+// template<class U> reference+=(U&& x) && noexcept;
+// template<class U> reference-=(U&& x) && noexcept;
+// template<class U> reference*=(U&& x) && noexcept;
+// template<class U> reference/=(U&& x) && noexcept;
+// template<class U> reference%=(U&& x) && noexcept;
+// template<class U> reference|=(U&& x) && noexcept;
+// template<class U> reference&=(U&& x) && noexcept;
+// template<class U> reference^=(U&& x) && noexcept;
+// template<class U> reference<<=(U&& x) && noexcept;
+// template<class U> reference>>=(U&& x) && noexcept;
+
+#include "../test_utils.h"
+#include <experimental/simd>
+
+namespace ex = std::experimental::parallelism_v2;
+
+#define LIBCXX_SIMD_REFERENCE_OP_(op, name)                                                                            \
+  template <class T, class SimdAbi>                                                                                    \
+  struct SimdReferenceOperatorHelper##name {                                                                           \
+    template <class U>                                                                                                 \
+    void operator()() const {                                                                                          \
+      ex::simd<T, SimdAbi> origin_simd(static_cast<T>(3));                                                             \
+      static_assert(noexcept(origin_simd[0] op## = static_cast<U>(2)));                                                \
+      origin_simd[0] op## = static_cast<U>(2);                                                                         \
+      assert((T)origin_simd[0] == (T)(static_cast<T>(3) op static_cast<T>(std::forward<U>(2))));                       \
+    }                                                                                                                  \
+  };
----------------
philnik777 wrote:

Could we refactor this to take an operation as a functor instead? So the instantiation looks something like `SimdReferenceOperatorHelper<T, SimdAbi, decltype([](auto& lsh, auto ths) { lhs += rhs; })>` etc.

https://github.com/llvm/llvm-project/pull/86761


More information about the libcxx-commits mailing list