[libcxx-commits] [PATCH] D59813: The other fix for equal algo

Mikhail Dvorskiy via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Apr 3 02:56:14 PDT 2019


MikeDvorskiy updated this revision to Diff 193458.
MikeDvorskiy edited the summary of this revision.
MikeDvorskiy added a comment.

Rebased  on top of latest master (+ uglification)


Repository:
  rPSTL pstl

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59813/new/

https://reviews.llvm.org/D59813

Files:
  include/pstl/internal/algorithm_impl.h
  include/pstl/internal/glue_algorithm_impl.h


Index: include/pstl/internal/glue_algorithm_impl.h
===================================================================
--- include/pstl/internal/glue_algorithm_impl.h
+++ include/pstl/internal/glue_algorithm_impl.h
@@ -745,10 +745,10 @@
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _ForwardIterator2 __last2, _BinaryPredicate __p)
 {
-    if (std::distance(__first1, __last1) == std::distance(__first2, __last2))
-        return std::equal(__first1, __last1, __first2, __p);
-
-    return false;
+    using namespace __pstl;
+    return __internal::__pattern_equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __p,
+                                   __internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator1>(__exec),
+                                   __internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator1>(__exec));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
@@ -757,7 +757,7 @@
       _ForwardIterator2 __last2)
 {
     return equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
-                 __pstl::__internal::__pstl_equal());
+                 __pstl::__internal::pstl_equal());
 }
 
 // [alg.move]
Index: include/pstl/internal/algorithm_impl.h
===================================================================
--- include/pstl/internal/algorithm_impl.h
+++ include/pstl/internal/algorithm_impl.h
@@ -406,10 +406,66 @@
 // equal
 //------------------------------------------------------------------------
 
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+bool
+__brick_equal(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
+            _ForwardIterator2 __last2, _BinaryPredicate __p, /* IsVector = */ std::false_type) noexcept
+{
+    return std::equal(__first1, __last1, __first2, __last2, __p);
+}
+
+template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
+bool
+__brick_equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+            _RandomAccessIterator2 __last2, _BinaryPredicate __p, /* is_vector = */ std::true_type) noexcept
+{
+    if (__last1 - __first1 != __last2 - __first2)
+        return false;
+
+    return __unseq_backend::simd_first(__first1, __last1 - __first1, __first2, not_pred<_BinaryPredicate>(__p)).first ==
+           __last1;
+}
+
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate,
+          class _IsVector>
+bool
+__pattern_equal(_ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
+              _ForwardIterator2 __last2, _BinaryPredicate __p, _IsVector __is_vector, /* is_parallel = */
+              std::false_type) noexcept
+{
+    return __internal::__brick_equal(__first1, __last1, __first2, __last2, __p, __is_vector);
+}
+
+#if __PSTL_USE_PAR_POLICIES
+template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate,
+          class _IsVector>
+bool
+__pattern_equal(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
+              _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __p,
+              _IsVector __is_vector, /*is_parallel=*/std::true_type)
+{
+    if (__last1 - __first1 != __last2 - __first2)
+        return false;
+
+    return __internal::except_handler([&]() {
+        return !__internal::parallel_or(
+            std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+            [__first1, __first2, __p, __is_vector](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                return !__internal__brick_equal(__i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1), __p,
+                                    __is_vector);
+            });
+    });
+}
+#endif
+
+//------------------------------------------------------------------------
+// equal version for sequences with equal lenght
+//------------------------------------------------------------------------
+
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 bool
 __brick_equal(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __p,
-              /* IsVector = */ std::false_type) noexcept
+            /* IsVector = */ std::false_type) noexcept
 {
     return std::equal(__first1, __last1, __first2, __p);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59813.193458.patch
Type: text/x-patch
Size: 4709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190403/0ea4684e/attachment-0001.bin>


More information about the libcxx-commits mailing list