[libcxx-commits] [PATCH] D102005: [libcxx]: Unroll std::find on AIX
Ettore Tiotto via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 6 10:05:05 PDT 2021
etiotto created this revision.
etiotto added reviewers: jasonliu, xingxue.
etiotto added a project: libc++.
Herald added a subscriber: libcxx-commits.
etiotto requested review of this revision.
This patch specializes the std::find implementation on AIX to unroll the while loop in that function for RandomAccessIterators.
Repository:
rCXX libc++
https://reviews.llvm.org/D102005
Files:
libcxx/include/algorithm
Index: libcxx/include/algorithm
===================================================================
--- libcxx/include/algorithm
+++ libcxx/include/algorithm
@@ -919,6 +919,64 @@
// find
+#if defined(_AIX)
+
+template <class _InputIterator, class _Tp>
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_InputIterator
+__find(_InputIterator __first, _InputIterator __last, const _Tp& __value_, input_iterator_tag)
+{
+ for (; __first != __last; ++__first)
+ if (*__first == __value_)
+ break;
+ return __first;
+}
+
+template <class _RandomAccessIterator, class _Tp>
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_RandomAccessIterator
+__find(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag)
+{
+ typename iterator_traits<_RandomAccessIterator>::difference_type __d = (__last - __first);
+ while (__d >= 4) {
+ if (*__first == __value_)
+ return __first;
+ ++__first;
+
+ if (*__first == __value_)
+ return __first;
+ ++__first;
+
+ if (*__first == __value_)
+ return __first;
+ ++__first;
+
+ if (*__first == __value_)
+ return __first;
+ ++__first;
+
+ __d -= 4;
+ }
+
+ for (; __first != __last; ++__first)
+ if (*__first == __value_)
+ break;
+ return __first;
+}
+
+template <class _InputIterator, class _Tp>
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_InputIterator
+find(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
+{
+ return __find(__first, __last, __value_, typename iterator_traits<_InputIterator>::iterator_category());
+}
+
+#else
+
template <class _InputIterator, class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
@@ -930,6 +988,7 @@
break;
return __first;
}
+#endif
// find_if
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102005.343428.patch
Type: text/x-patch
Size: 2046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210506/70b7ef96/attachment.bin>
More information about the libcxx-commits
mailing list