2 // { dg-options "-std=gnu++17 -ltbb" }
3 // { dg-do run { target c++17 } }
4 // { dg-require-effective-target tbb-backend }
6 //===-- rotate.pass.cpp ---------------------------------------------------===//
8 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9 // See https://llvm.org/LICENSE.txt for license information.
10 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12 //===----------------------------------------------------------------------===//
14 #include "pstl/pstl_test_config.h"
16 #ifdef PSTL_STANDALONE_TESTS
19 #include "pstl/execution"
20 #include "pstl/algorithm"
24 #endif // PSTL_STANDALONE_TESTS
26 #include "pstl/test_utils.h"
28 using namespace TestUtils
;
35 explicit wrapper(T t_
) : t(t_
), move_count(0) {}
37 operator=(const T
& t_
)
43 wrapper(const wrapper
<T
>& a
) : move_count(0) { t
= a
.t
; }
46 operator=(wrapper
<T
>& a
)
53 operator=(wrapper
<T
>&& a
)
65 operator()(const T
& a
, const T
& b
)
72 struct compare
<wrapper
<T
>>
75 operator()(const wrapper
<T
>& a
, const wrapper
<T
>& b
)
82 struct test_one_policy
85 #if _PSTL_ICC_17_VC141_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN || \
86 _PSTL_ICC_16_VC14_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN // dummy specializations to skip testing in case of broken configuration
87 template <typename Iterator
, typename Size
>
89 operator()(__pstl::execution::unsequenced_policy
, Iterator data_b
, Iterator data_e
, Iterator actual_b
,
90 Iterator actual_e
, Size shift
)
93 template <typename Iterator
, typename Size
>
95 operator()(__pstl::execution::parallel_unsequenced_policy
, Iterator data_b
, Iterator data_e
, Iterator actual_b
,
96 Iterator actual_e
, Size shift
)
101 template <typename ExecutionPolicy
, typename Iterator
, typename Size
>
103 operator()(ExecutionPolicy
&& exec
, Iterator data_b
, Iterator data_e
, Iterator actual_b
, Iterator actual_e
,
107 using T
= typename iterator_traits
<Iterator
>::value_type
;
108 Iterator actual_m
= std::next(actual_b
, shift
);
110 copy(data_b
, data_e
, actual_b
);
111 Iterator actual_return
= rotate(exec
, actual_b
, actual_m
, actual_e
);
113 EXPECT_TRUE(actual_return
== std::next(actual_b
, std::distance(actual_m
, actual_e
)), "wrong result of rotate");
114 auto comparator
= compare
<T
>();
115 bool check
= std::equal(actual_return
, actual_e
, data_b
, comparator
);
116 check
= check
&& std::equal(actual_b
, actual_return
, std::next(data_b
, shift
), comparator
);
118 EXPECT_TRUE(check
, "wrong effect of rotate");
119 EXPECT_TRUE(check_move(exec
, actual_b
, actual_e
, shift
), "wrong move test of rotate");
122 template <typename ExecutionPolicy
, typename Iterator
, typename Size
>
123 typename
std::enable_if
<
124 is_same_iterator_category
<Iterator
, std::random_access_iterator_tag
>::value
&&
125 !std::is_same
<ExecutionPolicy
, __pstl::execution::sequenced_policy
>::value
&&
126 std::is_same
<typename
std::iterator_traits
<Iterator
>::value_type
, wrapper
<float32_t
>>::value
,
128 check_move(ExecutionPolicy
&& exec
, Iterator b
, Iterator e
, Size shift
)
130 bool result
= all_of(b
, e
, [](wrapper
<float32_t
>& a
) {
131 bool temp
= a
.move_count
> 0;
135 return shift
== 0 || result
;
138 template <typename ExecutionPolicy
, typename Iterator
, typename Size
>
139 typename
std::enable_if
<
140 !(is_same_iterator_category
<Iterator
, std::random_access_iterator_tag
>::value
&&
141 !std::is_same
<ExecutionPolicy
, __pstl::execution::sequenced_policy
>::value
&&
142 std::is_same
<typename
std::iterator_traits
<Iterator
>::value_type
, wrapper
<float32_t
>>::value
),
144 check_move(ExecutionPolicy
&& exec
, Iterator b
, Iterator e
, Size shift
)
150 template <typename T
>
154 const int32_t max_len
= 100000;
156 Sequence
<T
> actual(max_len
, [](std::size_t i
) { return T(i
); });
157 Sequence
<T
> data(max_len
, [](std::size_t i
) { return T(i
); });
159 for (int32_t len
= 0; len
< max_len
; len
= len
<= 16 ? len
+ 1 : int32_t(3.1415 * len
))
161 int32_t shifts
[] = {0, 1, 2, len
/ 3, (2 * len
) / 3, len
- 1};
162 for (auto shift
: shifts
)
164 if (shift
>= 0 && shift
< len
)
166 invoke_on_all_policies(test_one_policy(), data
.begin(), data
.begin() + len
, actual
.begin(),
167 actual
.begin() + len
, shift
);
177 test
<wrapper
<float64_t
>>();
179 std::cout
<< done() << std::endl
;