Index: include/pstl/internal/algorithm_impl.h =================================================================== --- include/pstl/internal/algorithm_impl.h +++ include/pstl/internal/algorithm_impl.h @@ -408,6 +408,63 @@ template 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 +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, + __internal::__not_pred<_BinaryPredicate>(__p)) + .first == __last1; +} + +template +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 +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 length +//------------------------------------------------------------------------ + +template +bool __brick_equal(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __p, /* IsVector = */ std::false_type) noexcept { 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,11 @@ 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