aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include
diff options
context:
space:
mode:
authorZhangYin <zhangyin2018@iscas.ac.cn>2024-06-23 12:51:02 +0800
committerGitHub <noreply@github.com>2024-06-23 12:51:02 +0800
commit6ec1ddfd72656cbf8e4185239175e52d50e0f4a3 (patch)
tree82c6c46e19ceab90e2e1d992d2f3c9d1e02b153d /libcxx/include
parent95f983f8239c071712cc42d0d54d3ebfa7c32a22 (diff)
downloadllvm-6ec1ddfd72656cbf8e4185239175e52d50e0f4a3.zip
llvm-6ec1ddfd72656cbf8e4185239175e52d50e0f4a3.tar.gz
llvm-6ec1ddfd72656cbf8e4185239175e52d50e0f4a3.tar.bz2
[libc++] <experimental/simd> Add swap functions of simd reference (#86478)
Diffstat (limited to 'libcxx/include')
-rw-r--r--libcxx/include/experimental/__simd/reference.h41
-rw-r--r--libcxx/include/experimental/simd1
2 files changed, 42 insertions, 0 deletions
diff --git a/libcxx/include/experimental/__simd/reference.h b/libcxx/include/experimental/__simd/reference.h
index 7efbba9..af61dbc 100644
--- a/libcxx/include/experimental/__simd/reference.h
+++ b/libcxx/include/experimental/__simd/reference.h
@@ -13,10 +13,14 @@
#include <__type_traits/is_assignable.h>
#include <__type_traits/is_same.h>
#include <__utility/forward.h>
+#include <__utility/move.h>
#include <cstddef>
#include <experimental/__config>
#include <experimental/__simd/utility.h>
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
@@ -55,10 +59,47 @@ public:
__set(static_cast<value_type>(std::forward<_Up>(__v)));
return {__s_, __idx_};
}
+
+ // Note: This approach might not fully align with the specification,
+ // which might be a wording defect. (https://wg21.link/N4808 section 9.6.3)
+ template <class _Tp1, class _Storage1, class _Vp1>
+ friend void
+ swap(__simd_reference<_Tp1, _Storage1, _Vp1>&& __a, __simd_reference<_Tp1, _Storage1, _Vp1>&& __b) noexcept;
+
+ template <class _Tp1, class _Storage1, class _Vp1>
+ friend void swap(_Vp1& __a, __simd_reference<_Tp1, _Storage1, _Vp1>&& __b) noexcept;
+
+ template <class _Tp1, class _Storage1, class _Vp1>
+ friend void swap(__simd_reference<_Tp1, _Storage1, _Vp1>&& __a, _Vp1& __b) noexcept;
};
+template <class _Tp, class _Storage, class _Vp>
+_LIBCPP_HIDE_FROM_ABI void
+swap(__simd_reference<_Tp, _Storage, _Vp>&& __a, __simd_reference<_Tp, _Storage, _Vp>&& __b) noexcept {
+ _Vp __tmp(std::move(__a));
+ std::move(__a) = std::move(__b);
+ std::move(__b) = std::move(__tmp);
+}
+
+template <class _Tp, class _Storage, class _Vp>
+_LIBCPP_HIDE_FROM_ABI void swap(_Vp& __a, __simd_reference<_Tp, _Storage, _Vp>&& __b) noexcept {
+ _Vp __tmp(std::move(__a));
+ __a = std::move(__b);
+ std::move(__b) = std::move(__tmp);
+}
+
+template <class _Tp, class _Storage, class _Vp>
+_LIBCPP_HIDE_FROM_ABI void swap(__simd_reference<_Tp, _Storage, _Vp>&& __a, _Vp& __b) noexcept {
+ _Vp __tmp(std::move(__a));
+ std::move(__a) = std::move(__b);
+ __b = std::move(__tmp);
+}
+
} // namespace parallelism_v2
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
#endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
+
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_EXPERIMENTAL___SIMD_REFERENCE_H
diff --git a/libcxx/include/experimental/simd b/libcxx/include/experimental/simd
index fad6431..484543b 100644
--- a/libcxx/include/experimental/simd
+++ b/libcxx/include/experimental/simd
@@ -78,6 +78,7 @@ inline namespace parallelism_v2 {
#include <experimental/__config>
#include <experimental/__simd/aligned_tag.h>
#include <experimental/__simd/declaration.h>
+#include <experimental/__simd/reference.h>
#include <experimental/__simd/scalar.h>
#include <experimental/__simd/simd.h>
#include <experimental/__simd/simd_mask.h>