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.class] |
14 | // template<class Flags> simd_mask(const value_type* mem, Flags); |
15 | |
16 | #include "../test_utils.h" |
17 | |
18 | namespace ex = std::experimental::parallelism_v2; |
19 | |
20 | template <class T, std::size_t> |
21 | struct CheckSimdMaskLoadCtor { |
22 | template <class SimdAbi> |
23 | void operator()() { |
24 | constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>; |
25 | |
26 | // element aligned tag |
27 | bool element_buffer[array_size]; |
28 | for (size_t i = 0; i < array_size; ++i) |
29 | element_buffer[i] = static_cast<bool>(i % 2); |
30 | ex::simd_mask<T, SimdAbi> element_mask(element_buffer, ex::element_aligned_tag()); |
31 | assert_simd_mask_values_equal(element_mask, element_buffer); |
32 | |
33 | // vector aligned tag |
34 | alignas(ex::memory_alignment_v<ex::simd_mask<T, SimdAbi>>) bool vector_buffer[array_size]; |
35 | for (size_t i = 0; i < array_size; ++i) |
36 | vector_buffer[i] = static_cast<bool>(i % 2); |
37 | ex::simd_mask<T, SimdAbi> vector_mask(vector_buffer, ex::vector_aligned_tag()); |
38 | assert_simd_mask_values_equal(vector_mask, vector_buffer); |
39 | |
40 | // overaligned tag |
41 | alignas(bit_ceil(val: sizeof(bool) + 1)) bool overaligned_buffer[array_size]; |
42 | for (size_t i = 0; i < array_size; ++i) |
43 | overaligned_buffer[i] = static_cast<bool>(i % 2); |
44 | ex::simd_mask<T, SimdAbi> overaligned_mask(overaligned_buffer, ex::overaligned_tag<bit_ceil(val: sizeof(bool) + 1)>()); |
45 | assert_simd_mask_values_equal(overaligned_mask, overaligned_buffer); |
46 | } |
47 | }; |
48 | |
49 | template <class T, std::size_t> |
50 | struct CheckMaskLoadCtorTraits { |
51 | template <class SimdAbi> |
52 | void operator()() { |
53 | // This function shall not participate in overload resolution unless |
54 | // is_simd_flag_type_v<Flags> is true |
55 | static_assert(std::is_constructible_v<ex::simd_mask<T, SimdAbi>, const bool*, ex::element_aligned_tag>); |
56 | |
57 | // is_simd_flag_type_v<Flags> is false |
58 | static_assert(!std::is_constructible_v<ex::simd_mask<T, SimdAbi>, const bool*, T>); |
59 | static_assert(!std::is_constructible_v<ex::simd_mask<T, SimdAbi>, const bool*, SimdAbi>); |
60 | } |
61 | }; |
62 | |
63 | int main(int, char**) { |
64 | test_all_simd_abi<CheckSimdMaskLoadCtor>(); |
65 | test_all_simd_abi<CheckMaskLoadCtorTraits>(); |
66 | return 0; |
67 | } |
68 | |