[memprof] Move YAML traits to MemProf.h (NFC) (#118668)
[llvm-project.git] / libcxx / test / std / experimental / simd / simd.mask.class / simd_mask_ctor_default.pass.cpp
blob3a63cdeb9451d848b3784c89cb5c480311b7be9c
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.mask.class]
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>
27 void operator()() {
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>
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];
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>
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];
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>
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];
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>
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];
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>();
122 return 0;