Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:58

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___PSTL_BACKENDS_STD_THREAD_H
0010 #define _LIBCPP___PSTL_BACKENDS_STD_THREAD_H
0011 
0012 #include <__config>
0013 #include <__pstl/backend_fwd.h>
0014 #include <__pstl/cpu_algos/any_of.h>
0015 #include <__pstl/cpu_algos/cpu_traits.h>
0016 #include <__pstl/cpu_algos/fill.h>
0017 #include <__pstl/cpu_algos/find_if.h>
0018 #include <__pstl/cpu_algos/for_each.h>
0019 #include <__pstl/cpu_algos/merge.h>
0020 #include <__pstl/cpu_algos/stable_sort.h>
0021 #include <__pstl/cpu_algos/transform.h>
0022 #include <__pstl/cpu_algos/transform_reduce.h>
0023 #include <__utility/empty.h>
0024 #include <__utility/move.h>
0025 #include <optional>
0026 
0027 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0028 #  pragma GCC system_header
0029 #endif
0030 
0031 _LIBCPP_PUSH_MACROS
0032 #include <__undef_macros>
0033 
0034 #if _LIBCPP_STD_VER >= 17
0035 
0036 _LIBCPP_BEGIN_NAMESPACE_STD
0037 namespace __pstl {
0038 
0039 //
0040 // This partial backend implementation is for testing purposes only and not meant for production use. This will be
0041 // replaced by a proper implementation once the PSTL implementation is somewhat stable.
0042 //
0043 // This is intended to be used on top of the "default backend".
0044 //
0045 
0046 template <>
0047 struct __cpu_traits<__std_thread_backend_tag> {
0048   template <class _RandomAccessIterator, class _Fp>
0049   _LIBCPP_HIDE_FROM_ABI static optional<__empty>
0050   __for_each(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
0051     __f(__first, __last);
0052     return __empty{};
0053   }
0054 
0055   template <class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce>
0056   _LIBCPP_HIDE_FROM_ABI static optional<_Tp>
0057   __transform_reduce(_Index __first, _Index __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduce __reduce) {
0058     return __reduce(std::move(__first), std::move(__last), std::move(__init));
0059   }
0060 
0061   template <class _RandomAccessIterator, class _Compare, class _LeafSort>
0062   _LIBCPP_HIDE_FROM_ABI static optional<__empty>
0063   __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort) {
0064     __leaf_sort(__first, __last, __comp);
0065     return __empty{};
0066   }
0067 
0068   _LIBCPP_HIDE_FROM_ABI static void __cancel_execution() {}
0069 
0070   template <class _RandomAccessIterator1,
0071             class _RandomAccessIterator2,
0072             class _RandomAccessIterator3,
0073             class _Compare,
0074             class _LeafMerge>
0075   _LIBCPP_HIDE_FROM_ABI static optional<__empty>
0076   __merge(_RandomAccessIterator1 __first1,
0077           _RandomAccessIterator1 __last1,
0078           _RandomAccessIterator2 __first2,
0079           _RandomAccessIterator2 __last2,
0080           _RandomAccessIterator3 __outit,
0081           _Compare __comp,
0082           _LeafMerge __leaf_merge) {
0083     __leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
0084     return __empty{};
0085   }
0086 
0087   static constexpr size_t __lane_size = 64;
0088 };
0089 
0090 // Mandatory implementations of the computational basis
0091 template <class _ExecutionPolicy>
0092 struct __find_if<__std_thread_backend_tag, _ExecutionPolicy>
0093     : __cpu_parallel_find_if<__std_thread_backend_tag, _ExecutionPolicy> {};
0094 
0095 template <class _ExecutionPolicy>
0096 struct __for_each<__std_thread_backend_tag, _ExecutionPolicy>
0097     : __cpu_parallel_for_each<__std_thread_backend_tag, _ExecutionPolicy> {};
0098 
0099 template <class _ExecutionPolicy>
0100 struct __merge<__std_thread_backend_tag, _ExecutionPolicy>
0101     : __cpu_parallel_merge<__std_thread_backend_tag, _ExecutionPolicy> {};
0102 
0103 template <class _ExecutionPolicy>
0104 struct __stable_sort<__std_thread_backend_tag, _ExecutionPolicy>
0105     : __cpu_parallel_stable_sort<__std_thread_backend_tag, _ExecutionPolicy> {};
0106 
0107 template <class _ExecutionPolicy>
0108 struct __transform<__std_thread_backend_tag, _ExecutionPolicy>
0109     : __cpu_parallel_transform<__std_thread_backend_tag, _ExecutionPolicy> {};
0110 
0111 template <class _ExecutionPolicy>
0112 struct __transform_binary<__std_thread_backend_tag, _ExecutionPolicy>
0113     : __cpu_parallel_transform_binary<__std_thread_backend_tag, _ExecutionPolicy> {};
0114 
0115 template <class _ExecutionPolicy>
0116 struct __transform_reduce<__std_thread_backend_tag, _ExecutionPolicy>
0117     : __cpu_parallel_transform_reduce<__std_thread_backend_tag, _ExecutionPolicy> {};
0118 
0119 template <class _ExecutionPolicy>
0120 struct __transform_reduce_binary<__std_thread_backend_tag, _ExecutionPolicy>
0121     : __cpu_parallel_transform_reduce_binary<__std_thread_backend_tag, _ExecutionPolicy> {};
0122 
0123 // Not mandatory, but better optimized
0124 template <class _ExecutionPolicy>
0125 struct __any_of<__std_thread_backend_tag, _ExecutionPolicy>
0126     : __cpu_parallel_any_of<__std_thread_backend_tag, _ExecutionPolicy> {};
0127 
0128 template <class _ExecutionPolicy>
0129 struct __fill<__std_thread_backend_tag, _ExecutionPolicy>
0130     : __cpu_parallel_fill<__std_thread_backend_tag, _ExecutionPolicy> {};
0131 
0132 } // namespace __pstl
0133 _LIBCPP_END_NAMESPACE_STD
0134 
0135 #endif // _LIBCPP_STD_VER >= 17
0136 
0137 _LIBCPP_POP_MACROS
0138 
0139 #endif // _LIBCPP___PSTL_BACKENDS_STD_THREAD_H