[libcxx-commits] [libcxx] [libc++] <experimental/simd> Add operator value_type() of simd reference (PR #68960)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 13 00:26:05 PDT 2023
https://github.com/joy2myself created https://github.com/llvm/llvm-project/pull/68960
None
>From 6ae5d8e017d31bb8d0edab2335e3333aa7856699 Mon Sep 17 00:00:00 2001
From: Zhangyin <zhangyin2018 at iscas.ac.cn>
Date: Mon, 25 Sep 2023 16:29:03 +0800
Subject: [PATCH] [libc++] <experimental/simd> Add operator value_type() of
simd reference
---
.../include/experimental/__simd/reference.h | 2 +
.../reference_value_type.pass.cpp | 49 +++++++++++++++++++
2 files changed, 51 insertions(+)
create mode 100644 libcxx/test/std/experimental/simd/simd.reference/reference_value_type.pass.cpp
diff --git a/libcxx/include/experimental/__simd/reference.h b/libcxx/include/experimental/__simd/reference.h
index a9c17a230458d61..63b00848a849c4b 100644
--- a/libcxx/include/experimental/__simd/reference.h
+++ b/libcxx/include/experimental/__simd/reference.h
@@ -40,6 +40,8 @@ class __simd_reference {
__simd_reference() = delete;
__simd_reference(const __simd_reference&) = delete;
+
+ _LIBCPP_HIDE_FROM_ABI operator value_type() const noexcept { return __get(); }
};
} // namespace parallelism_v2
diff --git a/libcxx/test/std/experimental/simd/simd.reference/reference_value_type.pass.cpp b/libcxx/test/std/experimental/simd/simd.reference/reference_value_type.pass.cpp
new file mode 100644
index 000000000000000..3191cc7b238c34c
--- /dev/null
+++ b/libcxx/test/std/experimental/simd/simd.reference/reference_value_type.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// 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]
+// operator value_type() const noexcept;
+
+#include "../test_utils.h"
+#include <experimental/simd>
+
+namespace ex = std::experimental::parallelism_v2;
+
+template <class T, std::size_t>
+struct CheckSimdReferenceValueType {
+ template <class SimdAbi>
+ void operator()() {
+ ex::simd<T, SimdAbi> origin_simd([](T i) { return static_cast<T>(i); });
+ for (size_t i = 0; i < origin_simd.size(); ++i) {
+ static_assert(std::is_same_v<T, decltype(T(origin_simd[i]))>);
+ assert(T(origin_simd[i]) == static_cast<T>(i));
+ }
+ }
+};
+
+template <class T, std::size_t>
+struct CheckMaskReferenceValueType {
+ template <class SimdAbi>
+ void operator()() {
+ ex::simd_mask<T, SimdAbi> origin_simd_mask(true);
+ for (size_t i = 0; i < origin_simd_mask.size(); ++i) {
+ static_assert(std::is_same_v<bool, decltype(bool(origin_simd_mask[i]))>);
+ assert(bool(origin_simd_mask[i]) == true);
+ }
+ }
+};
+
+int main(int, char**) {
+ test_all_simd_abi<CheckSimdReferenceValueType>();
+ test_all_simd_abi<CheckMaskReferenceValueType>();
+ return 0;
+}
More information about the libcxx-commits
mailing list