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>
13 // Note: To ensure the swap functions can be called directly in the std::experimental namespace,
14 // the implementation approach might not fully align with the specification.
17 // friend void swap(reference&& a, reference&& b) noexcept;
18 // friend void swap(value_type& a, reference&& b) noexcept;
19 // friend void swap(reference&& a, value_type& b) noexcept;
21 #include "../test_utils.h"
22 #include <experimental/simd>
24 namespace ex
= std::experimental::parallelism_v2
;
26 template <class T
, std::size_t>
27 struct CheckSimdRefSwap
{
28 template <class SimdAbi
>
30 ex::simd
<T
, SimdAbi
> origin_simd_1(1);
31 ex::simd
<T
, SimdAbi
> origin_simd_2(2);
34 static_assert(noexcept(ex::swap(std::move(origin_simd_1
[0]), std::move(origin_simd_2
[0]))));
35 ex::swap(std::move(origin_simd_1
[0]), std::move(origin_simd_2
[0]));
36 assert((origin_simd_1
[0] == 2) && (origin_simd_2
[0] == 1));
38 static_assert(noexcept(ex::swap(std::move(origin_simd_1
[0]), value
)));
39 ex::swap(std::move(origin_simd_1
[0]), value
);
40 assert((origin_simd_1
[0] == 3) && (value
== 2));
42 static_assert(noexcept(ex::swap(value
, std::move(origin_simd_2
[0]))));
43 ex::swap(value
, std::move(origin_simd_2
[0]));
44 assert((value
== 1) && (origin_simd_2
[0] == 2));
48 template <class T
, std::size_t>
49 struct CheckMaskRefSwap
{
50 template <class SimdAbi
>
52 ex::simd_mask
<T
, SimdAbi
> origin_mask_1(true);
53 ex::simd_mask
<T
, SimdAbi
> origin_mask_2(false);
56 static_assert(noexcept(ex::swap(std::move(origin_mask_1
[0]), std::move(origin_mask_2
[0]))));
57 ex::swap(std::move(origin_mask_1
[0]), std::move(origin_mask_2
[0]));
58 assert((origin_mask_1
[0] == false) && (origin_mask_2
[0] == true));
60 static_assert(noexcept(ex::swap(std::move(origin_mask_1
[0]), value
)));
61 ex::swap(std::move(origin_mask_1
[0]), value
);
62 assert((origin_mask_1
[0] == true) && (value
== false));
64 static_assert(noexcept(ex::swap(value
, std::move(origin_mask_2
[0]))));
65 ex::swap(value
, std::move(origin_mask_2
[0]));
66 assert((value
== true) && (origin_mask_2
[0] == false));
70 int main(int, char**) {
71 test_all_simd_abi
<CheckSimdRefSwap
>();
72 test_all_simd_abi
<CheckMaskRefSwap
>();