aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-07-04 12:01:29 +0100
committerThomas Koenig <tkoenig@gcc.gnu.org>2024-07-28 19:06:02 +0200
commit7ad3d3303bbc2c3fd78f91dee96b1c023f9a2744 (patch)
treece4a6e4e0122167f79f087cb099f0256f971f597
parent64948288f673b6b7e5083081c019d6ef50e6e04d (diff)
downloadgcc-7ad3d3303bbc2c3fd78f91dee96b1c023f9a2744.zip
gcc-7ad3d3303bbc2c3fd78f91dee96b1c023f9a2744.tar.gz
gcc-7ad3d3303bbc2c3fd78f91dee96b1c023f9a2744.tar.bz2
libstdc++: Remove __find_if unrolling for random access iterators
As the numbers in PR libstdc++/88545 show, the manual loop unrolling in std::__find_if doesn't actually help these days, and it prevents the compiler from auto-vectorizing. Remove the dispatching on iterator_category and just use the simple loop for all iterator categories. libstdc++-v3/ChangeLog: * include/bits/stl_algobase.h (__find_if): Remove overloads for dispatching on iterator_category. Do not unroll loop manually. * include/bits/stl_algo.h (__find_if_not): Remove iterator_category argument from __find_if call.
-rw-r--r--libstdc++-v3/include/bits/stl_algo.h3
-rw-r--r--libstdc++-v3/include/bits/stl_algobase.h70
2 files changed, 5 insertions, 68 deletions
diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index d250b2e..541f588 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -110,8 +110,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Predicate __pred)
{
return std::__find_if(__first, __last,
- __gnu_cxx::__ops::__negate(__pred),
- std::__iterator_category(__first));
+ __gnu_cxx::__ops::__negate(__pred));
}
/// Like find_if_not(), but uses and updates a count of the
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index dec1e4c..27f6c37 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -2098,77 +2098,15 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
_GLIBCXX_END_NAMESPACE_ALGO
- /// This is an overload used by find algos for the Input Iterator case.
- template<typename _InputIterator, typename _Predicate>
- _GLIBCXX20_CONSTEXPR
- inline _InputIterator
- __find_if(_InputIterator __first, _InputIterator __last,
- _Predicate __pred, input_iterator_tag)
- {
- while (__first != __last && !__pred(__first))
- ++__first;
- return __first;
- }
-
- /// This is an overload used by find algos for the RAI case.
- template<typename _RandomAccessIterator, typename _Predicate>
- _GLIBCXX20_CONSTEXPR
- _RandomAccessIterator
- __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
- _Predicate __pred, random_access_iterator_tag)
- {
- typename iterator_traits<_RandomAccessIterator>::difference_type
- __trip_count = (__last - __first) >> 2;
-
- for (; __trip_count > 0; --__trip_count)
- {
- if (__pred(__first))
- return __first;
- ++__first;
-
- if (__pred(__first))
- return __first;
- ++__first;
-
- if (__pred(__first))
- return __first;
- ++__first;
-
- if (__pred(__first))
- return __first;
- ++__first;
- }
-
- switch (__last - __first)
- {
- case 3:
- if (__pred(__first))
- return __first;
- ++__first;
- // FALLTHRU
- case 2:
- if (__pred(__first))
- return __first;
- ++__first;
- // FALLTHRU
- case 1:
- if (__pred(__first))
- return __first;
- ++__first;
- // FALLTHRU
- case 0:
- default:
- return __last;
- }
- }
-
+ // Implementation of std::find_if, also used in std::remove_if and others.
template<typename _Iterator, typename _Predicate>
_GLIBCXX20_CONSTEXPR
inline _Iterator
__find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
{
- return __find_if(__first, __last, __pred,
- std::__iterator_category(__first));
+ while (__first != __last && !__pred(__first))
+ ++__first;
+ return __first;
}
template<typename _InputIterator, typename _Predicate>