[libcxx-commits] [libcxx] [libc++] <experimental/simd> Fix conversion constructor (PR #74693)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 6 19:44:03 PST 2023
https://github.com/joy2myself created https://github.com/llvm/llvm-project/pull/74693
None
>From bac19bf6b07927715e42a26c70fb9b1b916dfa9c Mon Sep 17 00:00:00 2001
From: Yin Zhang <zhangyin2018 at iscas.ac.cn>
Date: Thu, 7 Dec 2023 11:06:50 +0800
Subject: [PATCH] [libc++] <experimental/simd> Fix conversion constructor
---
libcxx/include/experimental/__simd/simd.h | 7 ++-----
libcxx/include/experimental/__simd/vec_ext.h | 9 +++++++++
.../simd/simd.class/simd_ctor_conversion.pass.cpp | 1 +
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/experimental/__simd/simd.h b/libcxx/include/experimental/__simd/simd.h
index ffb328eb345b1..568cf1a7c1b0c 100644
--- a/libcxx/include/experimental/__simd/simd.h
+++ b/libcxx/include/experimental/__simd/simd.h
@@ -55,11 +55,8 @@ class simd {
enable_if_t<!is_same_v<_Up, _Tp> && is_same_v<abi_type, simd_abi::fixed_size<size()>> &&
__is_non_narrowing_convertible_v<_Up, value_type>,
int> = 0>
- _LIBCPP_HIDE_FROM_ABI simd(const simd<_Up, simd_abi::fixed_size<size()>>& __v) noexcept {
- for (size_t __i = 0; __i < size(); __i++) {
- (*this)[__i] = static_cast<value_type>(__v[__i]);
- }
- }
+ _LIBCPP_HIDE_FROM_ABI simd(const simd<_Up, simd_abi::fixed_size<size()>>& __v) noexcept
+ : __s_(_Impl::__conversion(__v)) {}
// generator constructor
template <class _Generator, enable_if_t<__can_generate_v<value_type, _Generator, size()>, int> = 0>
diff --git a/libcxx/include/experimental/__simd/vec_ext.h b/libcxx/include/experimental/__simd/vec_ext.h
index baaeda6a7401a..78c86dd71ee67 100644
--- a/libcxx/include/experimental/__simd/vec_ext.h
+++ b/libcxx/include/experimental/__simd/vec_ext.h
@@ -64,6 +64,15 @@ struct __simd_operations<_Tp, simd_abi::__vec_ext<_Np>> {
return __result;
}
+ template <class _From>
+ static _LIBCPP_HIDE_FROM_ABI _SimdStorage __conversion(_From __v) noexcept {
+ _SimdStorage __result;
+ for (int __i = 0; __i < _Np; ++__i) {
+ __result.__set(__i, static_cast<_Tp>(__v[__i]));
+ }
+ return __result;
+ }
+
template <class _Generator, size_t... _Is>
static _LIBCPP_HIDE_FROM_ABI _SimdStorage __generate_init(_Generator&& __g, std::index_sequence<_Is...>) {
return _SimdStorage{{__g(std::integral_constant<size_t, _Is>())...}};
diff --git a/libcxx/test/std/experimental/simd/simd.class/simd_ctor_conversion.pass.cpp b/libcxx/test/std/experimental/simd/simd.class/simd_ctor_conversion.pass.cpp
index 7ce4bed9c7db8..6142be1c555c3 100644
--- a/libcxx/test/std/experimental/simd/simd.class/simd_ctor_conversion.pass.cpp
+++ b/libcxx/test/std/experimental/simd/simd.class/simd_ctor_conversion.pass.cpp
@@ -8,6 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14
// XFAIL: target=powerpc{{.*}}le-unknown-linux-gnu
+// ADDITIONAL_COMPILE_FLAGS: -O3
// <experimental/simd>
//
More information about the libcxx-commits
mailing list