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