[win/asan] GetInstructionSize: Fix `83 E4 XX` to return 3. (#119644)
[llvm-project.git] / libcxx / test / std / experimental / simd / simd.reference / reference_swap.pass.cpp
blobfa1c3106970acfae2e605452140f2c9b053a3df8
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 // 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.
16 // [simd.reference]
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>
29 void operator()() {
30 ex::simd<T, SimdAbi> origin_simd_1(1);
31 ex::simd<T, SimdAbi> origin_simd_2(2);
32 T value = 3;
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>
51 void operator()() {
52 ex::simd_mask<T, SimdAbi> origin_mask_1(true);
53 ex::simd_mask<T, SimdAbi> origin_mask_2(false);
54 bool value = true;
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>();
73 return 0;