[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / pstl / test / std / algorithms / alg.nonmodifying / search_n.pass.cpp
blob573f364edef21b30225d203d5e897d8f0fd94f24
1 // -*- C++ -*-
2 //===-- search_n.pass.cpp -------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++03, c++11, c++14
12 #include "support/pstl_test_config.h"
14 #include <execution>
15 #include <algorithm>
17 #include "support/utils.h"
19 using namespace TestUtils;
21 struct test_one_policy
23 #if defined(_PSTL_ICC_17_VC141_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN) || \
24 defined(_PSTL_ICC_16_VC14_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN) //dummy specialization by policy type, in case of broken configuration
25 template <typename Iterator, typename Size, typename T, typename Predicate>
26 void
27 operator()(pstl::execution::unsequenced_policy, Iterator b, Iterator e, Size count, const T& value, Predicate pred)
30 template <typename Iterator, typename Size, typename T, typename Predicate>
31 void
32 operator()(pstl::execution::parallel_unsequenced_policy, Iterator b, Iterator e, Size count, const T& value,
33 Predicate pred)
36 #endif
38 template <typename ExecutionPolicy, typename Iterator, typename Size, typename T, typename Predicate>
39 void
40 operator()(ExecutionPolicy&& exec, Iterator b, Iterator e, Size count, const T& value, Predicate pred)
42 using namespace std;
43 auto expected = search_n(b, e, count, value, pred);
44 auto actual = search_n(exec, b, e, count, value);
45 EXPECT_TRUE(actual == expected, "wrong return result from search_n");
47 actual = search_n(exec, b, e, count, value, pred);
48 EXPECT_TRUE(actual == expected, "wrong return result from search_n with a predicate");
52 template <typename T>
53 void
54 test()
57 const std::size_t max_n1 = 100000;
58 const T value = T(1);
59 for (std::size_t n1 = 0; n1 <= max_n1; n1 = n1 <= 16 ? n1 + 1 : size_t(3.1415 * n1))
61 std::size_t sub_n[] = {0, 1, 3, n1, (n1 * 10) / 8};
62 std::size_t res[] = {0, 1, n1 / 2, n1};
63 for (auto n2 : sub_n)
65 // Some of standard libraries return "first" in this case. We return "last" according to the standard
66 if (n2 == 0)
68 continue;
70 for (auto r : res)
72 Sequence<T> in(n1, [](std::size_t) { return T(0); });
73 std::size_t i = r, isub = 0;
74 for (; i < n1 && isub < n2; ++i, ++isub)
75 in[i] = value;
77 invoke_on_all_policies(test_one_policy(), in.begin(), in.begin() + n1, n2, value, std::equal_to<T>());
78 invoke_on_all_policies(test_one_policy(), in.cbegin(), in.cbegin() + n1, n2, value, std::equal_to<T>());
84 template <typename T>
85 struct test_non_const
87 template <typename Policy, typename Iterator>
88 void
89 operator()(Policy&& exec, Iterator iter)
91 invoke_if(exec, [&]() { search_n(exec, iter, iter, 0, T(0), non_const(std::equal_to<T>())); });
95 int
96 main()
98 test<int32_t>();
99 test<uint16_t>();
100 test<float64_t>();
101 #if !defined(_PSTL_ICC_16_17_TEST_REDUCTION_BOOL_TYPE_RELEASE_64_BROKEN)
102 test<bool>();
103 #endif
105 test_algo_basic_single<int32_t>(run_for_rnd_fw<test_non_const<int32_t>>());
107 std::cout << done() << std::endl;
108 return 0;