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_CPU_ALGOS_FILL_H
0010 #define _LIBCPP___CXX03___PSTL_CPU_ALGOS_FILL_H
0011 
0012 #include <__cxx03/__algorithm/fill.h>
0013 #include <__cxx03/__assert>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__iterator/concepts.h>
0016 #include <__cxx03/__pstl/backend_fwd.h>
0017 #include <__cxx03/__pstl/cpu_algos/cpu_traits.h>
0018 #include <__cxx03/__type_traits/is_execution_policy.h>
0019 #include <__cxx03/__utility/empty.h>
0020 #include <__cxx03/optional>
0021 
0022 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0023 #  pragma GCC system_header
0024 #endif
0025 
0026 _LIBCPP_BEGIN_NAMESPACE_STD
0027 namespace __pstl {
0028 
0029 template <class _Index, class _DifferenceType, class _Tp>
0030 _LIBCPP_HIDE_FROM_ABI _Index __simd_fill_n(_Index __first, _DifferenceType __n, const _Tp& __value) noexcept {
0031   _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
0032   _PSTL_PRAGMA_SIMD
0033   for (_DifferenceType __i = 0; __i < __n; ++__i)
0034     __first[__i] = __value;
0035   return __first + __n;
0036 }
0037 
0038 template <class _Backend, class _RawExecutionPolicy>
0039 struct __cpu_parallel_fill {
0040   template <class _Policy, class _ForwardIterator, class _Tp>
0041   _LIBCPP_HIDE_FROM_ABI optional<__empty>
0042   operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) const noexcept {
0043     if constexpr (__is_parallel_execution_policy_v<_RawExecutionPolicy> &&
0044                   __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
0045       return __cpu_traits<_Backend>::__for_each(
0046           __first, __last, [&__policy, &__value](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
0047             using _FillUnseq = __pstl::__fill<_Backend, __remove_parallel_policy_t<_RawExecutionPolicy>>;
0048             [[maybe_unused]] auto __res =
0049                 _FillUnseq()(std::__remove_parallel_policy(__policy), __brick_first, __brick_last, __value);
0050             _LIBCPP_ASSERT_INTERNAL(__res, "unseq/seq should never try to allocate!");
0051           });
0052     } else if constexpr (__is_unsequenced_execution_policy_v<_RawExecutionPolicy> &&
0053                          __has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
0054       __pstl::__simd_fill_n(__first, __last - __first, __value);
0055       return __empty{};
0056     } else {
0057       std::fill(__first, __last, __value);
0058       return __empty{};
0059     }
0060   }
0061 };
0062 
0063 } // namespace __pstl
0064 _LIBCPP_END_NAMESPACE_STD
0065 
0066 #endif // _LIBCPP___CXX03___PSTL_CPU_ALGOS_FILL_H