[libcxx-commits] [libcxx] [libc++] <experimental/simd> Add operator value_type() of simd reference (PR #68960)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 17 01:36:11 PDT 2023
https://github.com/joy2myself updated https://github.com/llvm/llvm-project/pull/68960
>From 4e763f81b839d75428dcbc30d8ab87d5ced59ae9 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 1/2] [libc++] <experimental/simd> Add operator value_type() of
simd reference
---
libcxx/docs/Status/ParallelismProjects.csv | 1 +
.../include/experimental/__simd/reference.h | 4 +-
libcxx/include/experimental/__simd/simd.h | 4 +-
.../include/experimental/__simd/simd_mask.h | 2 +-
.../reference_value_type.pass.cpp | 49 +++++++++++++++++++
5 files changed, 56 insertions(+), 4 deletions(-)
create mode 100644 libcxx/test/std/experimental/simd/simd.reference/reference_value_type.pass.cpp
diff --git a/libcxx/docs/Status/ParallelismProjects.csv b/libcxx/docs/Status/ParallelismProjects.csv
index be3663bf087b47e..dd14e963281e99f 100644
--- a/libcxx/docs/Status/ParallelismProjects.csv
+++ b/libcxx/docs/Status/ParallelismProjects.csv
@@ -14,6 +14,7 @@ Section,Description,Dependencies,Assignee,Complete
| `[parallel.simd.traits] <https://wg21.link/N4808>`_, "simd type traits rebind_simd", None, Yin Zhang, |In Progress|
| `[parallel.simd.traits] <https://wg21.link/N4808>`_, "simd type traits resize_simd", None, Yin Zhang, |In Progress|
| `[parallel.simd.whereexpr] <https://wg21.link/N4808>`_, "Where expression class templates", None, Yin Zhang, |In Progress|
+| `[parallel.simd.reference] <https://wg21.link/N4808>`_, "`Element references operator value_type() <https://github.com/llvm/llvm-project/pull/68960>`_", None, Yin Zhang, |Complete|
| `[parallel.simd.class] <https://wg21.link/N4808>`_, "`Class template simd declaration and alias <https://reviews.llvm.org/D144362>`_", [parallel.simd.abi], Yin Zhang, |Complete|
| `[parallel.simd.class] <https://wg21.link/N4808>`_, "`simd<>::size() <https://reviews.llvm.org/D144363>`_", [parallel.simd.traits] simd_size[_v], Yin Zhang, |Complete|
| `[parallel.simd.class] <https://wg21.link/N4808>`_, "`simd broadcast constructor <https://reviews.llvm.org/D156225>`_", None, Yin Zhang, |Complete|
diff --git a/libcxx/include/experimental/__simd/reference.h b/libcxx/include/experimental/__simd/reference.h
index a9c17a230458d61..0d38f46fc4408b6 100644
--- a/libcxx/include/experimental/__simd/reference.h
+++ b/libcxx/include/experimental/__simd/reference.h
@@ -26,7 +26,7 @@ class __simd_reference {
_Storage& __s_;
size_t __idx_;
- _LIBCPP_HIDE_FROM_ABI _Vp __get() const { return __s_.__get(__idx_); }
+ _LIBCPP_HIDE_FROM_ABI _Vp __get() const noexcept { return __s_.__get(__idx_); }
_LIBCPP_HIDE_FROM_ABI void __set(_Vp __v) {
if constexpr (is_same_v<_Vp, bool>)
@@ -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/include/experimental/__simd/simd.h b/libcxx/include/experimental/__simd/simd.h
index 954f94c90784e2f..64d3223462b3c83 100644
--- a/libcxx/include/experimental/__simd/simd.h
+++ b/libcxx/include/experimental/__simd/simd.h
@@ -46,11 +46,11 @@ class simd {
// generator constructor
template <class _Generator, enable_if_t<__can_generate_v<value_type, _Generator, size()>, int> = 0>
- explicit _LIBCPP_HIDE_FROM_ABI simd(_Generator&& __g) : __s_(_Impl::__generate(std::forward<_Generator>(__g))) {}
+ explicit _LIBCPP_HIDE_FROM_ABI simd(_Generator&& __g) noexcept : __s_(_Impl::__generate(std::forward<_Generator>(__g))) {}
// scalar access [simd.subscr]
// Add operator[] temporarily to test braodcast. Add test for it in later patch.
- _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const { return __s_.__get(__i); }
+ _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
};
template <class _Tp>
diff --git a/libcxx/include/experimental/__simd/simd_mask.h b/libcxx/include/experimental/__simd/simd_mask.h
index 4862fd42c0d06ac..b093787ee474b42 100644
--- a/libcxx/include/experimental/__simd/simd_mask.h
+++ b/libcxx/include/experimental/__simd/simd_mask.h
@@ -43,7 +43,7 @@ class simd_mask {
// scalar access [simd.mask.subscr]
// Add operator[] temporarily to test braodcast. Add test for it in later patch.
- _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const { return __s_.__get(__i); }
+ _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
};
template <class _Tp>
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..8a1b54e3f5dd54c
--- /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(noexcept(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(noexcept(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;
+}
>From 1a29e49e8c02714425c5f58558f28a505d1c7876 Mon Sep 17 00:00:00 2001
From: Zhangyin <zhangyin2018 at iscas.ac.cn>
Date: Mon, 25 Sep 2023 16:54:11 +0800
Subject: [PATCH 2/2] [libcxx] <experimental/simd> Add subscript operators of
class simd/simd_mask
---
.../include/experimental/__simd/reference.h | 2 +
libcxx/include/experimental/__simd/simd.h | 2 +-
.../include/experimental/__simd/simd_mask.h | 2 +-
.../simd/simd.class/simd_subscr.pass.cpp | 52 +++++++++++++++++++
.../simd.mask.class/simd_mask_subscr.pass.cpp | 52 +++++++++++++++++++
5 files changed, 108 insertions(+), 2 deletions(-)
create mode 100644 libcxx/test/std/experimental/simd/simd.class/simd_subscr.pass.cpp
create mode 100644 libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_subscr.pass.cpp
diff --git a/libcxx/include/experimental/__simd/reference.h b/libcxx/include/experimental/__simd/reference.h
index 0d38f46fc4408b6..335b127bf271fad 100644
--- a/libcxx/include/experimental/__simd/reference.h
+++ b/libcxx/include/experimental/__simd/reference.h
@@ -26,6 +26,8 @@ class __simd_reference {
_Storage& __s_;
size_t __idx_;
+ _LIBCPP_HIDE_FROM_ABI __simd_reference(_Storage& __s, size_t __idx) : __s_(__s), __idx_(__idx) {}
+
_LIBCPP_HIDE_FROM_ABI _Vp __get() const noexcept { return __s_.__get(__idx_); }
_LIBCPP_HIDE_FROM_ABI void __set(_Vp __v) {
diff --git a/libcxx/include/experimental/__simd/simd.h b/libcxx/include/experimental/__simd/simd.h
index 64d3223462b3c83..fbc93d407f5fc92 100644
--- a/libcxx/include/experimental/__simd/simd.h
+++ b/libcxx/include/experimental/__simd/simd.h
@@ -49,7 +49,7 @@ class simd {
explicit _LIBCPP_HIDE_FROM_ABI simd(_Generator&& __g) noexcept : __s_(_Impl::__generate(std::forward<_Generator>(__g))) {}
// scalar access [simd.subscr]
- // Add operator[] temporarily to test braodcast. Add test for it in later patch.
+ _LIBCPP_HIDE_FROM_ABI reference operator[](size_t __i) noexcept { return reference(__s_, __i); }
_LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
};
diff --git a/libcxx/include/experimental/__simd/simd_mask.h b/libcxx/include/experimental/__simd/simd_mask.h
index b093787ee474b42..946338542ca0dda 100644
--- a/libcxx/include/experimental/__simd/simd_mask.h
+++ b/libcxx/include/experimental/__simd/simd_mask.h
@@ -42,7 +42,7 @@ class simd_mask {
_LIBCPP_HIDE_FROM_ABI explicit simd_mask(value_type __v) noexcept : __s_(_Impl::__broadcast(__v)) {}
// scalar access [simd.mask.subscr]
- // Add operator[] temporarily to test braodcast. Add test for it in later patch.
+ _LIBCPP_HIDE_FROM_ABI reference operator[](size_t __i) noexcept { return reference(__s_, __i); }
_LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
};
diff --git a/libcxx/test/std/experimental/simd/simd.class/simd_subscr.pass.cpp b/libcxx/test/std/experimental/simd/simd.class/simd_subscr.pass.cpp
new file mode 100644
index 000000000000000..32b0575230a1dde
--- /dev/null
+++ b/libcxx/test/std/experimental/simd/simd.class/simd_subscr.pass.cpp
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// 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]
+// reference operator[](size_t i);
+// value_type operator[](size_t i) const;
+
+#include "../test_utils.h"
+#include <experimental/simd>
+
+namespace ex = std::experimental::parallelism_v2;
+
+template <class T, std::size_t>
+struct CheckSimdReferenceSubscr {
+ template <class SimdAbi>
+ void operator()() {
+ ex::simd<T, SimdAbi> origin_simd([](T i) { return i; });
+ for (size_t i = 0; i < origin_simd.size(); ++i) {
+ static_assert(noexcept(origin_simd[i]));
+ static_assert(std::is_same_v<typename ex::simd<T, SimdAbi>::reference, decltype(origin_simd[i])>);
+ assert(origin_simd[i] == static_cast<T>(i));
+ }
+ }
+};
+
+template <class T, std::size_t>
+struct CheckSimdValueTypeSubscr {
+ template <class SimdAbi>
+ void operator()() {
+ const ex::simd<T, SimdAbi> origin_simd([](T i) { return i; });
+ for (size_t i = 0; i < origin_simd.size(); ++i) {
+ static_assert(noexcept(origin_simd[i]));
+ static_assert(std::is_same_v<T, decltype(origin_simd[i])>);
+ assert(origin_simd[i] == static_cast<T>(i));
+ }
+ }
+};
+
+int main(int, char**) {
+ test_all_simd_abi<CheckSimdReferenceSubscr>();
+ test_all_simd_abi<CheckSimdValueTypeSubscr>();
+ return 0;
+}
diff --git a/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_subscr.pass.cpp b/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_subscr.pass.cpp
new file mode 100644
index 000000000000000..4b38ff159306105
--- /dev/null
+++ b/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_subscr.pass.cpp
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// 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]
+// reference operator[](size_t i);
+// value_type operator[](size_t i) const;
+
+#include "../test_utils.h"
+#include <experimental/simd>
+
+namespace ex = std::experimental::parallelism_v2;
+
+template <class T, std::size_t>
+struct CheckSimdMaskReferenceSubscr {
+ 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(noexcept(origin_simd_mask[i]));
+ static_assert(std::is_same_v<typename ex::simd_mask<T, SimdAbi>::reference, decltype(origin_simd_mask[i])>);
+ assert(origin_simd_mask[i] == true);
+ }
+ }
+};
+
+template <class T, std::size_t>
+struct CheckSimdMaskValueTypeSubscr {
+ template <class SimdAbi>
+ void operator()() {
+ const ex::simd_mask<T, SimdAbi> origin_simd_mask(true);
+ for (size_t i = 0; i < origin_simd_mask.size(); ++i) {
+ static_assert(noexcept(origin_simd_mask[i]));
+ static_assert(std::is_same_v<bool, decltype(origin_simd_mask[i])>);
+ assert(origin_simd_mask[i] == true);
+ }
+ }
+};
+
+int main(int, char**) {
+ test_all_simd_abi<CheckSimdMaskReferenceSubscr>();
+ test_all_simd_abi<CheckSimdMaskValueTypeSubscr>();
+ return 0;
+}
More information about the libcxx-commits
mailing list