|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +// UNSUPPORTED: c++03, c++11, c++14 |
| 10 | + |
| 11 | +// <experimental/simd> |
| 12 | +// |
| 13 | +// [simd.reference] |
| 14 | +// template<class U> reference=(U&& x) && noexcept; |
| 15 | +// |
| 16 | +// XFAIL: LIBCXX-AIX-FIXME |
| 17 | + |
| 18 | +#include "../test_utils.h" |
| 19 | +#include <experimental/simd> |
| 20 | + |
| 21 | +namespace ex = std::experimental::parallelism_v2; |
| 22 | + |
| 23 | +template <class T, class SimdAbi> |
| 24 | +struct CheckSimdReferenceAssignmentHelper { |
| 25 | + template <class U> |
| 26 | + void operator()() const { |
| 27 | + if constexpr (std::is_assignable_v<T&, U&&>) { |
| 28 | + ex::simd<T, SimdAbi> origin_simd([](T i) { return i; }); |
| 29 | + for (size_t i = 0; i < origin_simd.size(); ++i) { |
| 30 | + static_assert(noexcept(origin_simd[i] = static_cast<U>(i + 1))); |
| 31 | + origin_simd[i] = static_cast<U>(i + 1); |
| 32 | + assert(origin_simd[i] == static_cast<T>(std::forward<U>(i + 1))); |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | +}; |
| 37 | + |
| 38 | +template <class T, class SimdAbi> |
| 39 | +struct CheckMaskReferenceAssignmentHelper { |
| 40 | + template <class U> |
| 41 | + void operator()() const { |
| 42 | + if constexpr (std::is_assignable_v<bool&, U&&>) { |
| 43 | + ex::simd_mask<T, SimdAbi> origin_mask(true); |
| 44 | + for (size_t i = 0; i < origin_mask.size(); ++i) { |
| 45 | + static_assert(noexcept(origin_mask[i] = static_cast<U>(i + 1))); |
| 46 | + origin_mask[i] = static_cast<U>(i % 2); |
| 47 | + assert(origin_mask[i] == static_cast<T>(std::forward<U>(i % 2))); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | +}; |
| 52 | + |
| 53 | +template <class T, class SimdAbi> |
| 54 | +struct CheckReferenceAssignmentTraitsHelper { |
| 55 | + template <class U> |
| 56 | + void operator()() const { |
| 57 | + if constexpr (std::is_assignable_v<T&, U&&>) |
| 58 | + static_assert(std::is_assignable_v<typename ex::simd<T, SimdAbi>::reference&&, U&&>); |
| 59 | + else |
| 60 | + static_assert(!std::is_assignable_v<typename ex::simd<T, SimdAbi>::reference&&, U&&>); |
| 61 | + |
| 62 | + if constexpr (std::is_assignable_v<bool&, U&&>) |
| 63 | + static_assert(std::is_assignable_v<typename ex::simd_mask<T, SimdAbi>::reference&&, U&&>); |
| 64 | + else |
| 65 | + static_assert(!std::is_assignable_v<typename ex::simd_mask<T, SimdAbi>::reference&&, U&&>); |
| 66 | + } |
| 67 | +}; |
| 68 | + |
| 69 | +template <class T, std::size_t> |
| 70 | +struct CheckReferenceAssignment { |
| 71 | + template <class SimdAbi> |
| 72 | + void operator()() { |
| 73 | + types::for_each(arithmetic_no_bool_types(), CheckSimdReferenceAssignmentHelper<T, SimdAbi>()); |
| 74 | + types::for_each(arithmetic_no_bool_types(), CheckMaskReferenceAssignmentHelper<T, SimdAbi>()); |
| 75 | + |
| 76 | + types::for_each(arithmetic_no_bool_types(), CheckReferenceAssignmentTraitsHelper<T, SimdAbi>()); |
| 77 | + } |
| 78 | +}; |
| 79 | + |
| 80 | +int main(int, char**) { |
| 81 | + test_all_simd_abi<CheckReferenceAssignment>(); |
| 82 | + return 0; |
| 83 | +} |
0 commit comments