Path: blob/main/contrib/llvm-project/libcxx/include/__pstl/cpu_algos/fill.h
35271 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___PSTL_CPU_ALGOS_FILL_H9#define _LIBCPP___PSTL_CPU_ALGOS_FILL_H1011#include <__algorithm/fill.h>12#include <__assert>13#include <__config>14#include <__iterator/concepts.h>15#include <__pstl/backend_fwd.h>16#include <__pstl/cpu_algos/cpu_traits.h>17#include <__type_traits/is_execution_policy.h>18#include <__utility/empty.h>19#include <optional>2021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)22# pragma GCC system_header23#endif2425_LIBCPP_BEGIN_NAMESPACE_STD26namespace __pstl {2728template <class _Index, class _DifferenceType, class _Tp>29_LIBCPP_HIDE_FROM_ABI _Index __simd_fill_n(_Index __first, _DifferenceType __n, const _Tp& __value) noexcept {30_PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED31_PSTL_PRAGMA_SIMD32for (_DifferenceType __i = 0; __i < __n; ++__i)33__first[__i] = __value;34return __first + __n;35}3637template <class _Backend, class _RawExecutionPolicy>38struct __cpu_parallel_fill {39template <class _Policy, class _ForwardIterator, class _Tp>40_LIBCPP_HIDE_FROM_ABI optional<__empty>41operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) const noexcept {42if constexpr (__is_parallel_execution_policy_v<_RawExecutionPolicy> &&43__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {44return __cpu_traits<_Backend>::__for_each(45__first, __last, [&__policy, &__value](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {46using _FillUnseq = __pstl::__fill<_Backend, __remove_parallel_policy_t<_RawExecutionPolicy>>;47[[maybe_unused]] auto __res =48_FillUnseq()(std::__remove_parallel_policy(__policy), __brick_first, __brick_last, __value);49_LIBCPP_ASSERT_INTERNAL(__res, "unseq/seq should never try to allocate!");50});51} else if constexpr (__is_unsequenced_execution_policy_v<_RawExecutionPolicy> &&52__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {53__pstl::__simd_fill_n(__first, __last - __first, __value);54return __empty{};55} else {56std::fill(__first, __last, __value);57return __empty{};58}59}60};6162} // namespace __pstl63_LIBCPP_END_NAMESPACE_STD6465#endif // _LIBCPP___PSTL_CPU_ALGOS_FILL_H666768