1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // <experimental/simd>
14 // simd_mask() noexcept = default;
16 #include "../test_utils.h"
17 #include <experimental/simd>
19 namespace ex
= std::experimental::parallelism_v2
;
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
>
28 ex::simd_mask
<T
, SimdAbi
> pure_mask
;
29 // trash value in default ctor
30 static_assert(pure_mask
.size() > 0);
34 template <class T
, std::size_t>
35 struct CheckSimdMaskDefaultCopyCtor
{
36 template <class SimdAbi
>
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
) {
46 expected_value
[i
] = pure_mask
[i
];
49 ex::simd_mask
<T
, SimdAbi
> from_copy_ctor(pure_mask
);
50 assert_simd_mask_values_equal
<array_size
>(from_copy_ctor
, expected_value
);
54 template <class T
, std::size_t>
55 struct CheckSimdMaskDefaultMoveCtor
{
56 template <class SimdAbi
>
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
) {
66 expected_value
[i
] = pure_mask
[i
];
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
);
74 template <class T
, std::size_t>
75 struct CheckSimdMaskDefaultCopyAssignment
{
76 template <class SimdAbi
>
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
) {
86 expected_value
[i
] = pure_mask
[i
];
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
);
95 template <class T
, std::size_t>
96 struct CheckSimdMaskDefaultMoveAssignment
{
97 template <class SimdAbi
>
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
) {
106 pure_mask
[i
] = false;
107 expected_value
[i
] = pure_mask
[i
];
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
);
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
>();