Synchronize libstdc++ PSTL with upstream LLVM PSTL
[gcc.git] / libstdc++-v3 / include / pstl / numeric_impl.h
index b8e1282164711a330167b62ee249423b9d4a62c9..c5760b0f92eac240a275969756326378e18a4a8d 100644 (file)
@@ -7,21 +7,19 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef __PSTL_numeric_impl_H
-#define __PSTL_numeric_impl_H
+#ifndef _PSTL_NUMERIC_IMPL_H
+#define _PSTL_NUMERIC_IMPL_H
 
 #include <iterator>
 #include <type_traits>
 #include <numeric>
 
+#include "parallel_backend.h"
+#include "pstl_config.h"
 #include "execution_impl.h"
 #include "unseq_backend_simd.h"
 #include "algorithm_fwd.h"
 
-#if __PSTL_USE_PAR_POLICIES
-#include "parallel_backend.h"
-#endif
-
 namespace __pstl
 {
 namespace __internal
@@ -63,7 +61,6 @@ __pattern_transform_reduce(_ExecutionPolicy&&, _ForwardIterator1 __first1, _Forw
     return __brick_transform_reduce(__first1, __last1, __first2, __init, __binary_op1, __binary_op2, __is_vector);
 }
 
-#if __PSTL_USE_PAR_POLICIES
 template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2, class _Tp,
           class _BinaryOperation1, class _BinaryOperation2, class _IsVector>
 _Tp
@@ -82,11 +79,10 @@ __pattern_transform_reduce(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __f
             [__first1, __first2, __binary_op1, __binary_op2,
              __is_vector](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j, _Tp __init) -> _Tp {
                 return __internal::__brick_transform_reduce(__i, __j, __first2 + (__i - __first1), __init, __binary_op1,
-                                                __binary_op2, __is_vector);
+                                                            __binary_op2, __is_vector);
             });
     });
 }
-#endif
 
 //------------------------------------------------------------------------
 // transform_reduce (version with unary and binary functions)
@@ -125,7 +121,6 @@ __pattern_transform_reduce(_ExecutionPolicy&&, _ForwardIterator __first, _Forwar
     return __internal::__brick_transform_reduce(__first, __last, __init, __binary_op, __unary_op, __is_vector);
 }
 
-#if __PSTL_USE_PAR_POLICIES
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation,
           class _IsVector>
 _Tp
@@ -142,7 +137,6 @@ __pattern_transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first,
             });
     });
 }
-#endif
 
 //------------------------------------------------------------------------
 // transform_exclusive_scan
@@ -160,7 +154,7 @@ __brick_transform_scan(_ForwardIterator __first, _ForwardIterator __last, _Outpu
     for (; __first != __last; ++__first, ++__result)
     {
         *__result = __init;
-        __PSTL_PRAGMA_FORCEINLINE
+        _PSTL_PRAGMA_FORCEINLINE
         __init = __binary_op(__init, __unary_op(*__first));
     }
     return std::make_pair(__result, __init);
@@ -175,7 +169,7 @@ __brick_transform_scan(_ForwardIterator __first, _ForwardIterator __last, _Outpu
 {
     for (; __first != __last; ++__first, ++__result)
     {
-        __PSTL_PRAGMA_FORCEINLINE
+        _PSTL_PRAGMA_FORCEINLINE
         __init = __binary_op(__init, __unary_op(*__first));
         *__result = __init;
     }
@@ -196,13 +190,13 @@ __brick_transform_scan(_ForwardIterator __first, _ForwardIterator __last, _Outpu
                        _UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op, _Inclusive,
                        /*is_vector=*/std::true_type) noexcept
 {
-#if (__PSTL_UDS_PRESENT)
+#if (_PSTL_UDS_PRESENT)
     return __unseq_backend::__simd_scan(__first, __last - __first, __result, __unary_op, __init, __binary_op,
                                         _Inclusive());
 #else
     // We need to call serial brick here to call function for inclusive and exclusive scan that depends on _Inclusive() value
     return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, __init, __binary_op, _Inclusive(),
-                                  /*is_vector=*/std::false_type());
+                                              /*is_vector=*/std::false_type());
 #endif
 }
 
@@ -214,7 +208,7 @@ __brick_transform_scan(_ForwardIterator __first, _ForwardIterator __last, _Outpu
                        /*is_vector=*/std::true_type) noexcept
 {
     return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, __init, __binary_op, _Inclusive(),
-                                  /*is_vector=*/std::false_type());
+                                              /*is_vector=*/std::false_type());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _UnaryOperation, class _Tp,
@@ -224,11 +218,11 @@ __pattern_transform_scan(_ExecutionPolicy&&, _ForwardIterator __first, _ForwardI
                          _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op,
                          _Inclusive, _IsVector __is_vector, /*is_parallel=*/std::false_type) noexcept
 {
-    return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, __init, __binary_op, _Inclusive(), __is_vector)
+    return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, __init, __binary_op, _Inclusive(),
+                                              __is_vector)
         .first;
 }
 
-#if __PSTL_USE_PAR_POLICIES
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp,
           class _BinaryOperation, class _Inclusive, class _IsVector>
 typename std::enable_if<!std::is_floating_point<_Tp>::value, _OutputIterator>::type
@@ -245,21 +239,20 @@ __pattern_transform_scan(_ExecutionPolicy&& __exec, _RandomAccessIterator __firs
             __binary_op,
             [__first, __unary_op, __binary_op](_DifferenceType __i, _DifferenceType __j, _Tp __init) {
                 // Execute serial __brick_transform_reduce, due to the explicit SIMD vectorization (reduction) requires a commutative operation for the guarantee of correct scan.
-                return __internal::__brick_transform_reduce(__first + __i, __first + __j, __init, __binary_op, __unary_op,
-                                                /*__is_vector*/ std::false_type());
+                return __internal::__brick_transform_reduce(__first + __i, __first + __j, __init, __binary_op,
+                                                            __unary_op,
+                                                            /*__is_vector*/ std::false_type());
             },
             [__first, __unary_op, __binary_op, __result, __is_vector](_DifferenceType __i, _DifferenceType __j,
                                                                       _Tp __init) {
-                return __internal::__brick_transform_scan(__first + __i, __first + __j, __result + __i, __unary_op, __init,
-                                              __binary_op, _Inclusive(), __is_vector)
+                return __internal::__brick_transform_scan(__first + __i, __first + __j, __result + __i, __unary_op,
+                                                          __init, __binary_op, _Inclusive(), __is_vector)
                     .second;
             });
         return __result + (__last - __first);
     });
 }
-#endif
 
-#if __PSTL_USE_PAR_POLICIES
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp,
           class _BinaryOperation, class _Inclusive, class _IsVector>
 typename std::enable_if<std::is_floating_point<_Tp>::value, _OutputIterator>::type
@@ -278,15 +271,15 @@ __pattern_transform_scan(_ExecutionPolicy&& __exec, _RandomAccessIterator __firs
         __par_backend::__parallel_strict_scan(
             std::forward<_ExecutionPolicy>(__exec), __n, __init,
             [__first, __unary_op, __binary_op, __result, __is_vector](_DifferenceType __i, _DifferenceType __len) {
-                return __internal::__brick_transform_scan(__first + __i, __first + (__i + __len), __result + __i, __unary_op, _Tp{},
-                                              __binary_op, _Inclusive(), __is_vector)
+                return __internal::__brick_transform_scan(__first + __i, __first + (__i + __len), __result + __i,
+                                                          __unary_op, _Tp{}, __binary_op, _Inclusive(), __is_vector)
                     .second;
             },
             __binary_op,
             [__result, &__binary_op](_DifferenceType __i, _DifferenceType __len, _Tp __initial) {
                 return *(std::transform(__result + __i, __result + __i + __len, __result + __i,
                                         [&__initial, &__binary_op](const _Tp& __x) {
-                                            __PSTL_PRAGMA_FORCEINLINE
+                                            _PSTL_PRAGMA_FORCEINLINE
                                             return __binary_op(__initial, __x);
                                         }) -
                          1);
@@ -295,7 +288,6 @@ __pattern_transform_scan(_ExecutionPolicy&& __exec, _RandomAccessIterator __firs
         return __result + (__last - __first);
     });
 }
-#endif
 
 //------------------------------------------------------------------------
 // adjacent_difference
@@ -314,7 +306,7 @@ _ForwardIterator2
 __brick_adjacent_difference(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first,
                             BinaryOperation __op, /*is_vector=*/std::true_type) noexcept
 {
-    __PSTL_ASSERT(__first != __last);
+    _PSTL_ASSERT(__first != __last);
 
     typedef typename std::iterator_traits<_ForwardIterator1>::reference _ReferenceType1;
     typedef typename std::iterator_traits<_ForwardIterator2>::reference _ReferenceType2;
@@ -336,7 +328,6 @@ __pattern_adjacent_difference(_ExecutionPolicy&&, _ForwardIterator __first, _For
     return __internal::__brick_adjacent_difference(__first, __last, __d_first, __op, __is_vector);
 }
 
-#if __PSTL_USE_PAR_POLICIES
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation,
           class _IsVector>
 _ForwardIterator2
@@ -344,7 +335,7 @@ __pattern_adjacent_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __fir
                               _ForwardIterator2 __d_first, _BinaryOperation __op, _IsVector __is_vector,
                               /*is_parallel=*/std::true_type)
 {
-    __PSTL_ASSERT(__first != __last);
+    _PSTL_ASSERT(__first != __last);
     typedef typename std::iterator_traits<_ForwardIterator1>::reference _ReferenceType1;
     typedef typename std::iterator_traits<_ForwardIterator2>::reference _ReferenceType2;
 
@@ -360,9 +351,8 @@ __pattern_adjacent_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __fir
         });
     return __d_first + (__last - __first);
 }
-#endif
 
 } // namespace __internal
 } // namespace __pstl
 
-#endif /* __PSTL_numeric_impl_H */
+#endif /* _PSTL_NUMERIC_IMPL_H */