Back to home page

EIC code displayed by LXR

 
 

    


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

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