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.mask.class] |
14 | // simd_mask() noexcept = default; |
15 | |
16 | #include "../test_utils.h" |
17 | #include <experimental/simd> |
18 | |
19 | namespace ex = std::experimental::parallelism_v2; |
20 | |
21 | // See https://www.open-std.org/jtc1/sc22/WG21/docs/papers/2019/n4808.pdf |
22 | // Default initialization performs no initialization of the elements; value-initialization initializes each element with T(). |
23 | // Thus, default initialization leaves the elements in an indeterminate state. |
24 | template <class T, std::size_t> |
25 | struct CheckSimdMaskDefaultCtor { |
26 | template <class SimdAbi> |
27 | void operator()() { |
28 | ex::simd_mask<T, SimdAbi> pure_mask; |
29 | // trash value in default ctor |
30 | static_assert(pure_mask.size() > 0); |
31 | } |
32 | }; |
33 | |
34 | template <class T, std::size_t> |
35 | struct CheckSimdMaskDefaultCopyCtor { |
36 | template <class SimdAbi> |
37 | void operator()() { |
38 | ex::simd_mask<T, SimdAbi> pure_mask; |
39 | constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>; |
40 | std::array<bool, array_size> expected_value; |
41 | for (size_t i = 0; i < array_size; ++i) { |
42 | if (i % 2 == 0) |
43 | pure_mask[i] = true; |
44 | else |
45 | pure_mask[i] = false; |
46 | expected_value[i] = pure_mask[i]; |
47 | } |
48 | |
49 | ex::simd_mask<T, SimdAbi> from_copy_ctor(pure_mask); |
50 | assert_simd_mask_values_equal<array_size>(from_copy_ctor, expected_value); |
51 | } |
52 | }; |
53 | |
54 | template <class T, std::size_t> |
55 | struct CheckSimdMaskDefaultMoveCtor { |
56 | template <class SimdAbi> |
57 | void operator()() { |
58 | ex::simd_mask<T, SimdAbi> pure_mask; |
59 | constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>; |
60 | std::array<bool, array_size> expected_value; |
61 | for (size_t i = 0; i < array_size; ++i) { |
62 | if (i % 2 == 0) |
63 | pure_mask[i] = true; |
64 | else |
65 | pure_mask[i] = false; |
66 | expected_value[i] = pure_mask[i]; |
67 | } |
68 | |
69 | ex::simd_mask<T, SimdAbi> from_move_ctor(std::move(pure_mask)); |
70 | assert_simd_mask_values_equal<array_size>(from_move_ctor, expected_value); |
71 | } |
72 | }; |
73 | |
74 | template <class T, std::size_t> |
75 | struct CheckSimdMaskDefaultCopyAssignment { |
76 | template <class SimdAbi> |
77 | void operator()() { |
78 | ex::simd_mask<T, SimdAbi> pure_mask; |
79 | constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>; |
80 | std::array<bool, array_size> expected_value; |
81 | for (size_t i = 0; i < array_size; ++i) { |
82 | if (i % 2 == 0) |
83 | pure_mask[i] = true; |
84 | else |
85 | pure_mask[i] = false; |
86 | expected_value[i] = pure_mask[i]; |
87 | } |
88 | |
89 | ex::simd_mask<T, SimdAbi> from_copy_assignment; |
90 | from_copy_assignment = pure_mask; |
91 | assert_simd_mask_values_equal<array_size>(from_copy_assignment, expected_value); |
92 | } |
93 | }; |
94 | |
95 | template <class T, std::size_t> |
96 | struct CheckSimdMaskDefaultMoveAssignment { |
97 | template <class SimdAbi> |
98 | void operator()() { |
99 | ex::simd_mask<T, SimdAbi> pure_mask; |
100 | constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>; |
101 | std::array<bool, array_size> expected_value; |
102 | for (size_t i = 0; i < array_size; ++i) { |
103 | if (i % 2 == 0) |
104 | pure_mask[i] = true; |
105 | else |
106 | pure_mask[i] = false; |
107 | expected_value[i] = pure_mask[i]; |
108 | } |
109 | |
110 | ex::simd_mask<T, SimdAbi> from_move_assignment; |
111 | from_move_assignment = std::move(pure_mask); |
112 | assert_simd_mask_values_equal<array_size>(from_move_assignment, expected_value); |
113 | } |
114 | }; |
115 | |
116 | int main(int, char**) { |
117 | test_all_simd_abi<CheckSimdMaskDefaultCtor>(); |
118 | test_all_simd_abi<CheckSimdMaskDefaultCopyCtor>(); |
119 | test_all_simd_abi<CheckSimdMaskDefaultMoveCtor>(); |
120 | test_all_simd_abi<CheckSimdMaskDefaultCopyAssignment>(); |
121 | test_all_simd_abi<CheckSimdMaskDefaultMoveAssignment>(); |
122 | return 0; |
123 | } |
124 | |