[memprof] Move YAML traits to MemProf.h (NFC) (#118668)
[llvm-project.git] / libcxx / test / std / experimental / simd / simd.mask.class / simd_mask_copy.pass.cpp
blob0c3b4c9ea6d5aca35a5dbf1f69dadbf2d7a9da8f
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // <experimental/simd>
13 // [simd.class]
14 // template<class Flags> void copy_from(const value_type* mem, Flags);
15 // template<class Flags> void copy_to(value_type* mem, Flags);
17 #include "../test_utils.h"
19 namespace ex = std::experimental::parallelism_v2;
21 template <class T, std::size_t>
22 struct CheckSimdMaskCopyFrom {
23 template <class SimdAbi>
24 void operator()() {
25 constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>;
27 // element aligned tag
28 constexpr std::size_t element_alignas_size = alignof(bool);
29 alignas(element_alignas_size) bool element_buffer[array_size];
30 for (size_t i = 0; i < array_size; ++i)
31 element_buffer[i] = static_cast<bool>(i % 2);
32 ex::simd_mask<T, SimdAbi> element_mask;
33 element_mask.copy_from(element_buffer, ex::element_aligned_tag());
34 assert_simd_mask_values_equal(element_mask, element_buffer);
36 // vector aligned tag
37 constexpr std::size_t vector_alignas_size = ex::memory_alignment_v<ex::simd_mask<T, SimdAbi>>;
38 alignas(vector_alignas_size) bool vector_buffer[array_size];
39 for (size_t i = 0; i < array_size; ++i)
40 vector_buffer[i] = static_cast<bool>(i % 2);
41 ex::simd_mask<T, SimdAbi> vector_mask;
42 vector_mask.copy_from(vector_buffer, ex::vector_aligned_tag());
43 assert_simd_mask_values_equal(vector_mask, vector_buffer);
45 // overaligned tag
46 constexpr std::size_t over_alignas_size = bit_ceil(sizeof(bool) + 1);
47 alignas(over_alignas_size) bool overaligned_buffer[array_size];
48 for (size_t i = 0; i < array_size; ++i)
49 overaligned_buffer[i] = static_cast<bool>(i % 2);
50 ex::simd_mask<T, SimdAbi> overaligned_mask;
51 overaligned_mask.copy_from(overaligned_buffer, ex::overaligned_tag<over_alignas_size>());
52 assert_simd_mask_values_equal(overaligned_mask, overaligned_buffer);
56 template <class T, std::size_t>
57 struct CheckSimdMaskCopyTo {
58 template <class SimdAbi>
59 void operator()() {
60 constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>;
62 // element aligned tag
63 constexpr std::size_t element_alignas_size = alignof(bool);
64 alignas(element_alignas_size) bool element_buffer[array_size];
65 ex::simd_mask<T, SimdAbi> element_mask(true);
66 element_mask.copy_to(element_buffer, ex::element_aligned_tag());
67 assert_simd_mask_values_equal(element_mask, element_buffer);
69 // vector aligned tag
70 constexpr std::size_t vector_alignas_size = ex::memory_alignment_v<ex::simd_mask<T, SimdAbi>>;
71 alignas(vector_alignas_size) bool vector_buffer[array_size];
72 ex::simd_mask<T, SimdAbi> vector_mask(false);
73 vector_mask.copy_to(vector_buffer, ex::vector_aligned_tag());
74 assert_simd_mask_values_equal(vector_mask, vector_buffer);
76 // overaligned tag
77 constexpr std::size_t over_alignas_size = bit_ceil(sizeof(bool) + 1);
78 alignas(over_alignas_size) bool overaligned_buffer[array_size];
79 ex::simd_mask<T, SimdAbi> overaligned_mask(true);
80 overaligned_mask.copy_to(overaligned_buffer, ex::overaligned_tag<over_alignas_size>());
81 assert_simd_mask_values_equal(overaligned_mask, overaligned_buffer);
85 template <class T, class Flags, class SimdAbi = ex::simd_abi::compatible<T>, class = void>
86 struct has_copy_from : std::false_type {};
88 template <class T, class Flags, class SimdAbi>
89 struct has_copy_from<T,
90 Flags,
91 SimdAbi,
92 std::void_t<decltype(std::declval<ex::simd_mask<T, SimdAbi>>().copy_from(
93 std::declval<const bool*>(), std::declval<Flags>()))>> : std::true_type {};
95 template <class T, class Flags, class SimdAbi = ex::simd_abi::compatible<T>, class = void>
96 struct has_copy_to : std::false_type {};
98 template <class T, class Flags, class SimdAbi>
99 struct has_copy_to<T,
100 Flags,
101 SimdAbi,
102 std::void_t<decltype(std::declval<ex::simd_mask<T, SimdAbi>>().copy_to(
103 std::declval<bool*>(), std::declval<Flags>()))>> : std::true_type {};
105 template <class T, std::size_t>
106 struct CheckSimdMaskCopyTraits {
107 template <class SimdAbi>
108 void operator()() {
109 // These functions shall not participate in overload resolution unless
110 // is_simd_flag_type_v<Flags> is true
111 static_assert(has_copy_from<T, ex::element_aligned_tag, SimdAbi>::value);
112 static_assert(has_copy_to<T, ex::element_aligned_tag, SimdAbi>::value);
114 // is_simd_flag_type_v<Flags> is false
115 static_assert(!has_copy_from<T, T, SimdAbi>::value);
116 static_assert(!has_copy_to<T, T, SimdAbi>::value);
117 static_assert(!has_copy_from<T, SimdAbi, SimdAbi>::value);
118 static_assert(!has_copy_to<T, SimdAbi, SimdAbi>::value);
122 int main(int, char**) {
123 test_all_simd_abi<CheckSimdMaskCopyFrom>();
124 test_all_simd_abi<CheckSimdMaskCopyTo>();
125 test_all_simd_abi<CheckSimdMaskCopyTraits>();
126 return 0;