[libcxx-commits] [libcxx] [libc++] <experimental/simd> Add load constructor for class simd/simd_mask (PR #76610)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Dec 30 02:55:08 PST 2023


================
@@ -0,0 +1,105 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.class]
+// template<class U, class Flags> simd(const U* mem, Flags);
+
+#include "../test_utils.h"
+
+namespace ex = std::experimental::parallelism_v2;
+
+template <class T, class SimdAbi, std::size_t array_size>
+struct ElementAlignedLoadCtorHelper {
+  template <class U>
+  void operator()() const {
+    constexpr std::size_t alignas_size = alignof(U);
+    alignas(alignas_size) U buffer[array_size];
+    for (size_t i = 0; i < array_size; ++i)
+      buffer[i] = static_cast<U>(i);
+    ex::simd<T, SimdAbi> origin_simd(buffer, ex::element_aligned_tag());
+    assert_simd_values_equal(origin_simd, buffer);
+  }
+};
+
+template <class T, class SimdAbi, std::size_t array_size>
+struct VectorAlignedLoadCtorHelper {
+  template <class U>
+  void operator()() const {
+    constexpr std::size_t alignas_size = ex::memory_alignment_v<ex::simd<T, SimdAbi>, U>;
+    alignas(alignas_size) U buffer[array_size];
+    for (size_t i = 0; i < array_size; ++i)
+      buffer[i] = static_cast<U>(i);
+    ex::simd<T, SimdAbi> origin_simd(buffer, ex::vector_aligned_tag());
+    assert_simd_values_equal(origin_simd, buffer);
+  }
+};
+
+template <class T, class SimdAbi, std::size_t array_size>
+struct OveralignedLoadCtorHelper {
+  template <class U>
+  void operator()() const {
+    constexpr std::size_t alignas_size = bit_ceil(sizeof(U) + 1);
+    alignas(alignas_size) U buffer[array_size];
+    for (size_t i = 0; i < array_size; ++i)
+      buffer[i] = static_cast<U>(i);
+    ex::simd<T, SimdAbi> origin_simd(buffer, ex::overaligned_tag<alignas_size>());
+    assert_simd_values_equal(origin_simd, buffer);
+  }
+};
+
+template <class T, std::size_t>
+struct CheckSimdLoadCtor {
+  template <class SimdAbi>
+  void operator()() {
+    constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>;
+
+    types::for_each(arithmetic_no_bool_types(), ElementAlignedLoadCtorHelper<T, SimdAbi, array_size>());
+    types::for_each(arithmetic_no_bool_types(), VectorAlignedLoadCtorHelper<T, SimdAbi, array_size>());
+    types::for_each(arithmetic_no_bool_types(), OveralignedLoadCtorHelper<T, SimdAbi, array_size>());
+  }
+};
+
+template <class U, class T, class Flags, class SimdAbi = ex::simd_abi::compatible<T>, class = void>
+struct has_load_ctor : std::false_type {};
+
+template <class U, class T, class Flags, class SimdAbi>
+struct has_load_ctor<U,
+                     T,
+                     Flags,
+                     SimdAbi,
+                     std::void_t<decltype(ex::simd<T, SimdAbi>(std::declval<const U*>(), Flags()))>> : std::true_type {
----------------
joy2myself wrote:

It seems `std:: is_constructible_v` does not have a third template parameter for `Flags`.

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


More information about the libcxx-commits mailing list