| 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 |
// The machine emulated in tests does not have enough memory for code. |
| 12 |
// UNSUPPORTED: LIBCXX-PICOLIBC-FIXME |
| 13 |
|
| 14 |
// <experimental/simd> |
| 15 |
// |
| 16 |
// [simd.reference] |
| 17 |
// template<class U> reference=(U&& x) && noexcept; |
| 18 |
// XFAIL: target=powerpc{{.*}}le-unknown-linux-gnu |
| 19 |
|
| 20 |
#include "../test_utils.h" |
| 21 |
#include <experimental/simd> |
| 22 |
|
| 23 |
namespace ex = std::experimental::parallelism_v2; |
| 24 |
|
| 25 |
template <class T, class SimdAbi> |
| 26 |
struct CheckSimdReferenceAssignmentHelper { |
| 27 |
template <class U> |
| 28 |
void operator()() const { |
| 29 |
if constexpr (std::is_assignable_v<T&, U&&>) { |
| 30 |
ex::simd<T, SimdAbi> origin_simd([](T i) { return i; }); |
| 31 |
for (size_t i = 0; i < origin_simd.size(); ++i) { |
| 32 |
static_assert(noexcept(origin_simd[i] = static_cast<U>(i + 1))); |
| 33 |
origin_simd[i] = static_cast<U>(i + 1); |
| 34 |
assert(origin_simd[i] == static_cast<T>(std::forward<U>(i + 1))); |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
template <class T, class SimdAbi> |
| 41 |
struct CheckMaskReferenceAssignmentHelper { |
| 42 |
template <class U> |
| 43 |
void operator()() const { |
| 44 |
if constexpr (std::is_assignable_v<bool&, U&&>) { |
| 45 |
ex::simd_mask<T, SimdAbi> origin_mask(true); |
| 46 |
for (size_t i = 0; i < origin_mask.size(); ++i) { |
| 47 |
static_assert(noexcept(origin_mask[i] = static_cast<U>(i + 1))); |
| 48 |
origin_mask[i] = static_cast<U>(i % 2); |
| 49 |
assert(origin_mask[i] == static_cast<T>(std::forward<U>(i % 2))); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
}; |
| 54 |
|
| 55 |
template <class T, class SimdAbi> |
| 56 |
struct CheckReferenceAssignmentTraitsHelper { |
| 57 |
template <class U> |
| 58 |
void operator()() const { |
| 59 |
if constexpr (std::is_assignable_v<T&, U&&>) |
| 60 |
static_assert(std::is_assignable_v<typename ex::simd<T, SimdAbi>::reference&&, U&&>); |
| 61 |
else |
| 62 |
static_assert(!std::is_assignable_v<typename ex::simd<T, SimdAbi>::reference&&, U&&>); |
| 63 |
|
| 64 |
if constexpr (std::is_assignable_v<bool&, U&&>) |
| 65 |
static_assert(std::is_assignable_v<typename ex::simd_mask<T, SimdAbi>::reference&&, U&&>); |
| 66 |
else |
| 67 |
static_assert(!std::is_assignable_v<typename ex::simd_mask<T, SimdAbi>::reference&&, U&&>); |
| 68 |
} |
| 69 |
}; |
| 70 |
|
| 71 |
template <class T, std::size_t> |
| 72 |
struct CheckReferenceAssignment { |
| 73 |
template <class SimdAbi> |
| 74 |
void operator()() { |
| 75 |
types::for_each(simd_test_types(), CheckSimdReferenceAssignmentHelper<T, SimdAbi>()); |
| 76 |
types::for_each(simd_test_types(), CheckMaskReferenceAssignmentHelper<T, SimdAbi>()); |
| 77 |
|
| 78 |
types::for_each(simd_test_types(), CheckReferenceAssignmentTraitsHelper<T, SimdAbi>()); |
| 79 |
} |
| 80 |
}; |
| 81 |
|
| 82 |
int main(int, char**) { |
| 83 |
test_all_simd_abi<CheckReferenceAssignment>(); |
| 84 |
return 0; |
| 85 |
} |