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 U> simd_mask(const simd_mask<U, simd_abi::fixed_size<size()>>&) noexcept; |
15 | |
16 | #include "../test_utils.h" |
17 | #include <experimental/simd> |
18 | |
19 | namespace ex = std::experimental::parallelism_v2; |
20 | |
21 | template <class T, class SimdAbi, std::size_t array_size> |
22 | struct ConversionHelper { |
23 | const std::array<bool, array_size>& expected_value; |
24 | |
25 | ConversionHelper(const std::array<bool, array_size>& value) : expected_value(value) {} |
26 | |
27 | template <class U> |
28 | void operator()() const { |
29 | if constexpr (!std::is_same_v<U, T> && std::is_same_v<SimdAbi, ex::simd_abi::fixed_size<array_size>>) { |
30 | static_assert(noexcept(ex::simd_mask<T, SimdAbi>(ex::simd_mask<U, SimdAbi>{}))); |
31 | ex::simd_mask<U, SimdAbi> origin_mask(false); |
32 | ex::simd_mask<T, SimdAbi> mask_from_implicit_conversion(origin_mask); |
33 | assert_simd_mask_values_equal<array_size>(mask_from_implicit_conversion, expected_value); |
34 | } |
35 | } |
36 | }; |
37 | |
38 | template <class T, std::size_t> |
39 | struct CheckConversionMaskCtor { |
40 | template <class SimdAbi> |
41 | void operator()() { |
42 | constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>; |
43 | std::array<bool, array_size> expected_value{}; |
44 | |
45 | types::for_each(simd_test_types(), ConversionHelper<T, SimdAbi, array_size>(expected_value)); |
46 | } |
47 | }; |
48 | |
49 | template <class T, class SimdAbi, std::size_t array_size> |
50 | struct CheckConversionMaskCtorTraitsHelper { |
51 | template <class U> |
52 | void operator()() { |
53 | if constexpr (!std::is_same_v<U, T>) { |
54 | if constexpr (std::is_same_v<SimdAbi, ex::simd_abi::fixed_size<array_size>>) |
55 | static_assert(std::is_convertible_v<ex::simd_mask<U, SimdAbi>, ex::simd_mask<T, SimdAbi>>); |
56 | else |
57 | static_assert(!std::is_convertible_v<ex::simd_mask<U, SimdAbi>, ex::simd_mask<T, SimdAbi>>); |
58 | } |
59 | } |
60 | }; |
61 | |
62 | template <class T, std::size_t> |
63 | struct CheckConversionMaskCtorTraits { |
64 | template <class SimdAbi> |
65 | void operator()() { |
66 | constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>; |
67 | |
68 | types::for_each(simd_test_types(), CheckConversionMaskCtorTraitsHelper<T, SimdAbi, array_size>()); |
69 | } |
70 | }; |
71 | |
72 | int main(int, char**) { |
73 | test_all_simd_abi<CheckConversionMaskCtor>(); |
74 | test_all_simd_abi<CheckConversionMaskCtorTraits>(); |
75 | return 0; |
76 | } |
77 | |