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 | // XFAIL: target=powerpc{{.*}}le-unknown-linux-gnu |
11 | |
12 | // <experimental/simd> |
13 | // |
14 | // [simd.class] |
15 | // reference operator[](size_t i); |
16 | // value_type operator[](size_t i) const; |
17 | |
18 | #include "../test_utils.h" |
19 | #include <experimental/simd> |
20 | |
21 | namespace ex = std::experimental::parallelism_v2; |
22 | |
23 | template <class T, std::size_t> |
24 | struct CheckSimdReferenceSubscr { |
25 | template <class SimdAbi> |
26 | void operator()() { |
27 | ex::simd<T, SimdAbi> origin_simd([](T i) { return i; }); |
28 | for (size_t i = 0; i < origin_simd.size(); ++i) { |
29 | static_assert(noexcept(origin_simd[i])); |
30 | static_assert(std::is_same_v<typename ex::simd<T, SimdAbi>::reference, decltype(origin_simd[i])>); |
31 | assert(origin_simd[i] == static_cast<T>(i)); |
32 | } |
33 | } |
34 | }; |
35 | |
36 | template <class T, std::size_t> |
37 | struct CheckSimdValueTypeSubscr { |
38 | template <class SimdAbi> |
39 | void operator()() { |
40 | const ex::simd<T, SimdAbi> origin_simd([](T i) { return i; }); |
41 | for (size_t i = 0; i < origin_simd.size(); ++i) { |
42 | static_assert(noexcept(origin_simd[i])); |
43 | static_assert(std::is_same_v<T, decltype(origin_simd[i])>); |
44 | assert(origin_simd[i] == static_cast<T>(i)); |
45 | } |
46 | } |
47 | }; |
48 | |
49 | int main(int, char**) { |
50 | test_all_simd_abi<CheckSimdReferenceSubscr>(); |
51 | test_all_simd_abi<CheckSimdValueTypeSubscr>(); |
52 | return 0; |
53 | } |
54 | |