mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-25 14:52:28 +00:00
Upgrade to 2022-era LLVM LIBCXX
This commit is contained in:
parent
2f4ca71f26
commit
8e68384e15
2078 changed files with 165657 additions and 65010 deletions
47
third_party/libcxx/__algorithm/pstl_backends/cpu_backend.h
vendored
Normal file
47
third_party/libcxx/__algorithm/pstl_backends/cpu_backend.h
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
/*
|
||||
|
||||
// _Functor takes a subrange for [__first, __last) that should be executed in serial
|
||||
template <class _RandomAccessIterator, class _Functor>
|
||||
void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Functor __func);
|
||||
|
||||
// Cancel the execution of other jobs - they aren't needed anymore
|
||||
void __cancel_execution();
|
||||
|
||||
template <class _RandomAccessIterator1,
|
||||
class _RandomAccessIterator2,
|
||||
class _RandomAccessIterator3,
|
||||
class _Compare,
|
||||
class _LeafMerge>
|
||||
void __parallel_merge(
|
||||
_RandomAccessIterator1 __first1,
|
||||
_RandomAccessIterator1 __last1,
|
||||
_RandomAccessIterator2 __first2,
|
||||
_RandomAccessIterator2 __last2,
|
||||
_RandomAccessIterator3 __outit,
|
||||
_Compare __comp,
|
||||
_LeafMerge __leaf_merge);
|
||||
|
||||
TODO: Document the parallel backend
|
||||
*/
|
||||
|
||||
#include <__algorithm/pstl_backends/cpu_backends/any_of.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/fill.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/find_if.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/for_each.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/merge.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/transform.h>
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_H
|
90
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/any_of.h
vendored
Normal file
90
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/any_of.h
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_ANY_OF_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_ANY_OF_H
|
||||
|
||||
#include <__algorithm/any_of.h>
|
||||
#include <__algorithm/find_if.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__atomic/atomic.h>
|
||||
#include <__atomic/memory_order.h>
|
||||
#include <__config>
|
||||
#include <__functional/operations.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
#include <cstdint>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Index, class _Brick>
|
||||
_LIBCPP_HIDE_FROM_ABI bool __parallel_or(_Index __first, _Index __last, _Brick __f) {
|
||||
std::atomic<bool> __found(false);
|
||||
__par_backend::__parallel_for(__first, __last, [__f, &__found](_Index __i, _Index __j) {
|
||||
if (!__found.load(std::memory_order_relaxed) && __f(__i, __j)) {
|
||||
__found.store(true, std::memory_order_relaxed);
|
||||
__par_backend::__cancel_execution();
|
||||
}
|
||||
});
|
||||
return __found;
|
||||
}
|
||||
|
||||
// TODO: check whether __simd_first() can be used here
|
||||
template <class _Index, class _DifferenceType, class _Pred>
|
||||
_LIBCPP_HIDE_FROM_ABI bool __simd_or(_Index __first, _DifferenceType __n, _Pred __pred) noexcept {
|
||||
_DifferenceType __block_size = 4 < __n ? 4 : __n;
|
||||
const _Index __last = __first + __n;
|
||||
while (__last != __first) {
|
||||
int32_t __flag = 1;
|
||||
_PSTL_PRAGMA_SIMD_REDUCTION(& : __flag)
|
||||
for (_DifferenceType __i = 0; __i < __block_size; ++__i)
|
||||
if (__pred(*(__first + __i)))
|
||||
__flag = 0;
|
||||
if (!__flag)
|
||||
return true;
|
||||
|
||||
__first += __block_size;
|
||||
if (__last - __first >= __block_size << 1) {
|
||||
// Double the block _Size. Any unnecessary iterations can be amortized against work done so far.
|
||||
__block_size <<= 1;
|
||||
} else {
|
||||
__block_size = __last - __first;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
|
||||
_LIBCPP_HIDE_FROM_ABI bool
|
||||
__pstl_any_of(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
return std::__terminate_on_exception([&] {
|
||||
return std::__parallel_or(
|
||||
__first, __last, [&__pred](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
return std::__pstl_any_of<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __pred);
|
||||
});
|
||||
});
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
return std::__simd_or(__first, __last - __first, __pred);
|
||||
} else {
|
||||
return std::any_of(__first, __last, __pred);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_ANY_OF_H
|
32
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/backend.h
vendored
Normal file
32
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/backend.h
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_BACKEND_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_BACKEND_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if defined(_LIBCPP_PSTL_CPU_BACKEND_SERIAL)
|
||||
# include <__algorithm/pstl_backends/cpu_backends/serial.h>
|
||||
#elif defined(_LIBCPP_PSTL_CPU_BACKEND_THREAD)
|
||||
# include <__algorithm/pstl_backends/cpu_backends/thread.h>
|
||||
#else
|
||||
# error "Invalid CPU backend choice"
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
struct __cpu_backend_tag {};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKEND_BACKEND_H
|
60
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/fill.h
vendored
Normal file
60
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/fill.h
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FILL_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FILL_H
|
||||
|
||||
#include <__algorithm/fill.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Index, class _DifferenceType, class _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI _Index __simd_fill_n(_Index __first, _DifferenceType __n, const _Tp& __value) noexcept {
|
||||
_PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
|
||||
_PSTL_PRAGMA_SIMD
|
||||
for (_DifferenceType __i = 0; __i < __n; ++__i)
|
||||
__first[__i] = __value;
|
||||
return __first + __n;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
__pstl_fill(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
std::__terminate_on_exception([&] {
|
||||
__par_backend::__parallel_for(
|
||||
__first, __last, [&__value](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
std::__pstl_fill<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __value);
|
||||
});
|
||||
});
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
std::__simd_fill_n(__first, __last - __first, __value);
|
||||
} else {
|
||||
std::fill(__first, __last, __value);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FILL_H
|
125
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/find_if.h
vendored
Normal file
125
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/find_if.h
vendored
Normal file
|
@ -0,0 +1,125 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FIND_IF_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FIND_IF_H
|
||||
|
||||
#include <__algorithm/find_if.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__atomic/atomic.h>
|
||||
#include <__config>
|
||||
#include <__functional/operations.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/pair.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
#include <cstddef>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Index, class _Brick, class _Compare>
|
||||
_LIBCPP_HIDE_FROM_ABI _Index
|
||||
__parallel_find(_Index __first, _Index __last, _Brick __f, _Compare __comp, bool __b_first) {
|
||||
typedef typename std::iterator_traits<_Index>::difference_type _DifferenceType;
|
||||
const _DifferenceType __n = __last - __first;
|
||||
_DifferenceType __initial_dist = __b_first ? __n : -1;
|
||||
std::atomic<_DifferenceType> __extremum(__initial_dist);
|
||||
// TODO: find out what is better here: parallel_for or parallel_reduce
|
||||
__par_backend::__parallel_for(__first, __last, [__comp, __f, __first, &__extremum](_Index __i, _Index __j) {
|
||||
// See "Reducing Contention Through Priority Updates", PPoPP '13, for discussion of
|
||||
// why using a shared variable scales fairly well in this situation.
|
||||
if (__comp(__i - __first, __extremum)) {
|
||||
_Index __res = __f(__i, __j);
|
||||
// If not '__last' returned then we found what we want so put this to extremum
|
||||
if (__res != __j) {
|
||||
const _DifferenceType __k = __res - __first;
|
||||
for (_DifferenceType __old = __extremum; __comp(__k, __old); __old = __extremum) {
|
||||
__extremum.compare_exchange_weak(__old, __k);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return __extremum != __initial_dist ? __first + __extremum : __last;
|
||||
}
|
||||
|
||||
const std::size_t __lane_size = 64;
|
||||
|
||||
template <class _Index, class _DifferenceType, class _Compare>
|
||||
_LIBCPP_HIDE_FROM_ABI _Index
|
||||
__simd_first(_Index __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp) noexcept {
|
||||
// Experiments show good block sizes like this
|
||||
const _DifferenceType __block_size = 8;
|
||||
alignas(__lane_size) _DifferenceType __lane[__block_size] = {0};
|
||||
while (__end - __begin >= __block_size) {
|
||||
_DifferenceType __found = 0;
|
||||
_PSTL_PRAGMA_SIMD_REDUCTION(| : __found) for (_DifferenceType __i = __begin; __i < __begin + __block_size; ++__i) {
|
||||
const _DifferenceType __t = __comp(__first, __i);
|
||||
__lane[__i - __begin] = __t;
|
||||
__found |= __t;
|
||||
}
|
||||
if (__found) {
|
||||
_DifferenceType __i;
|
||||
// This will vectorize
|
||||
for (__i = 0; __i < __block_size; ++__i) {
|
||||
if (__lane[__i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return __first + __begin + __i;
|
||||
}
|
||||
__begin += __block_size;
|
||||
}
|
||||
|
||||
// Keep remainder scalar
|
||||
while (__begin != __end) {
|
||||
if (__comp(__first, __begin)) {
|
||||
return __first + __begin;
|
||||
}
|
||||
++__begin;
|
||||
}
|
||||
return __first + __end;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
|
||||
__pstl_find_if(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
return std::__terminate_on_exception([&] {
|
||||
return std::__parallel_find(
|
||||
__first,
|
||||
__last,
|
||||
[&__pred](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
return std::__pstl_find_if<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __pred);
|
||||
},
|
||||
less<>{},
|
||||
true);
|
||||
});
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
using __diff_t = __iter_diff_t<_ForwardIterator>;
|
||||
return std::__simd_first(__first, __diff_t(0), __last - __first, [&__pred](_ForwardIterator __iter, __diff_t __i) {
|
||||
return __pred(__iter[__i]);
|
||||
});
|
||||
} else {
|
||||
return std::find_if(__first, __last, __pred);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_FIND_IF_H
|
60
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/for_each.h
vendored
Normal file
60
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/for_each.h
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKNEDS_FOR_EACH_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKNEDS_FOR_EACH_H
|
||||
|
||||
#include <__algorithm/for_each.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Iterator, class _DifferenceType, class _Function>
|
||||
_LIBCPP_HIDE_FROM_ABI _Iterator __simd_walk_1(_Iterator __first, _DifferenceType __n, _Function __f) noexcept {
|
||||
_PSTL_PRAGMA_SIMD
|
||||
for (_DifferenceType __i = 0; __i < __n; ++__i)
|
||||
__f(__first[__i]);
|
||||
|
||||
return __first + __n;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _Functor>
|
||||
_LIBCPP_HIDE_FROM_ABI void
|
||||
__pstl_for_each(__cpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Functor __func) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
std::__terminate_on_exception([&] {
|
||||
std::__par_backend::__parallel_for(
|
||||
__first, __last, [__func](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
std::__pstl_for_each<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __func);
|
||||
});
|
||||
});
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value) {
|
||||
std::__simd_walk_1(__first, __last - __first, __func);
|
||||
} else {
|
||||
std::for_each(__first, __last, __func);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKNEDS_FOR_EACH_H
|
79
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/merge.h
vendored
Normal file
79
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/merge.h
vendored
Normal file
|
@ -0,0 +1,79 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_MERGE_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_MERGE_H
|
||||
|
||||
#include <__algorithm/merge.h>
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _ForwardOutIterator,
|
||||
class _Comp>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_merge(
|
||||
__cpu_backend_tag,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardIterator2 __last2,
|
||||
_ForwardOutIterator __result,
|
||||
_Comp __comp) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator1>::value &&
|
||||
__has_random_access_iterator_category<_ForwardIterator2>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
return std::__terminate_on_exception([&] {
|
||||
__par_backend::__parallel_merge(
|
||||
__first1,
|
||||
__last1,
|
||||
__first2,
|
||||
__last2,
|
||||
__result,
|
||||
__comp,
|
||||
[](_ForwardIterator1 __g_first1,
|
||||
_ForwardIterator1 __g_last1,
|
||||
_ForwardIterator2 __g_first2,
|
||||
_ForwardIterator2 __g_last2,
|
||||
_ForwardOutIterator __g_result,
|
||||
_Comp __g_comp) {
|
||||
return std::__pstl_merge<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{},
|
||||
std::move(__g_first1),
|
||||
std::move(__g_last1),
|
||||
std::move(__g_first2),
|
||||
std::move(__g_last2),
|
||||
std::move(__g_result),
|
||||
std::move(__g_comp));
|
||||
});
|
||||
return __result + (__last1 - __first1) + (__last2 - __first2);
|
||||
});
|
||||
} else {
|
||||
return std::merge(__first1, __last1, __first2, __last2, __result, __comp);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_MERGE_H
|
58
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/serial.h
vendored
Normal file
58
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/serial.h
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_SERIAL_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_SERIAL_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace __par_backend {
|
||||
inline namespace __serial_cpu_backend {
|
||||
|
||||
template <class _RandomAccessIterator, class _Fp>
|
||||
_LIBCPP_HIDE_FROM_ABI void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
|
||||
__f(__first, __last);
|
||||
}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI inline void __cancel_execution() {}
|
||||
|
||||
template <class _RandomAccessIterator1,
|
||||
class _RandomAccessIterator2,
|
||||
class _RandomAccessIterator3,
|
||||
class _Compare,
|
||||
class _LeafMerge>
|
||||
_LIBCPP_HIDE_FROM_ABI void __parallel_merge(
|
||||
_RandomAccessIterator1 __first1,
|
||||
_RandomAccessIterator1 __last1,
|
||||
_RandomAccessIterator2 __first2,
|
||||
_RandomAccessIterator2 __last2,
|
||||
_RandomAccessIterator3 __outit,
|
||||
_Compare __comp,
|
||||
_LeafMerge __leaf_merge) {
|
||||
__leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
|
||||
}
|
||||
|
||||
// TODO: Complete this list
|
||||
|
||||
} // namespace __serial_cpu_backend
|
||||
} // namespace __par_backend
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_SERIAL_H
|
59
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/thread.h
vendored
Normal file
59
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/thread.h
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
|
||||
|
||||
#include <__assert>
|
||||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
// This backend implementation is for testing purposes only and not meant for production use. This will be replaced
|
||||
// by a proper implementation once the PSTL implementation is somewhat stable.
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace __par_backend {
|
||||
inline namespace __thread_cpu_backend {
|
||||
|
||||
template <class _RandomAccessIterator, class _Fp>
|
||||
_LIBCPP_HIDE_FROM_ABI void __parallel_for(_RandomAccessIterator __first, _RandomAccessIterator __last, _Fp __f) {
|
||||
__f(__first, __last);
|
||||
}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI inline void __cancel_execution() {}
|
||||
|
||||
template <class _RandomAccessIterator1,
|
||||
class _RandomAccessIterator2,
|
||||
class _RandomAccessIterator3,
|
||||
class _Compare,
|
||||
class _LeafMerge>
|
||||
_LIBCPP_HIDE_FROM_ABI void __parallel_merge(
|
||||
_RandomAccessIterator1 __first1,
|
||||
_RandomAccessIterator1 __last1,
|
||||
_RandomAccessIterator2 __first2,
|
||||
_RandomAccessIterator2 __last2,
|
||||
_RandomAccessIterator3 __outit,
|
||||
_Compare __comp,
|
||||
_LeafMerge __leaf_merge) {
|
||||
__leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
|
||||
}
|
||||
|
||||
} // namespace __thread_cpu_backend
|
||||
} // namespace __par_backend
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_THREAD_H
|
132
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/transform.h
vendored
Normal file
132
third_party/libcxx/__algorithm/pstl_backends/cpu_backends/transform.h
vendored
Normal file
|
@ -0,0 +1,132 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_TRANSFORM_H
|
||||
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_TRANSFORM_H
|
||||
|
||||
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
|
||||
#include <__algorithm/transform.h>
|
||||
#include <__config>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
#include <__type_traits/enable_if.h>
|
||||
#include <__type_traits/is_execution_policy.h>
|
||||
#include <__type_traits/remove_cvref.h>
|
||||
#include <__utility/terminate_on_exception.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template <class _Iterator1, class _DifferenceType, class _Iterator2, class _Function>
|
||||
_LIBCPP_HIDE_FROM_ABI _Iterator2
|
||||
__simd_walk_2(_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Function __f) noexcept {
|
||||
_PSTL_PRAGMA_SIMD
|
||||
for (_DifferenceType __i = 0; __i < __n; ++__i)
|
||||
__f(__first1[__i], __first2[__i]);
|
||||
return __first2 + __n;
|
||||
}
|
||||
|
||||
template <class _ExecutionPolicy, class _ForwardIterator, class _ForwardOutIterator, class _UnaryOperation>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
|
||||
__cpu_backend_tag,
|
||||
_ForwardIterator __first,
|
||||
_ForwardIterator __last,
|
||||
_ForwardOutIterator __result,
|
||||
_UnaryOperation __op) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
std::__terminate_on_exception([&] {
|
||||
std::__par_backend::__parallel_for(
|
||||
__first, __last, [__op, __first, __result](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
|
||||
return std::__pstl_transform<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{}, __brick_first, __brick_last, __result + (__brick_first - __first), __op);
|
||||
});
|
||||
});
|
||||
return __result + (__last - __first);
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
return std::__simd_walk_2(
|
||||
__first,
|
||||
__last - __first,
|
||||
__result,
|
||||
[&](__iter_reference<_ForwardIterator> __in_value, __iter_reference<_ForwardOutIterator> __out_value) {
|
||||
__out_value = __op(__in_value);
|
||||
});
|
||||
} else {
|
||||
return std::transform(__first, __last, __result, __op);
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Iterator1, class _DifferenceType, class _Iterator2, class _Iterator3, class _Function>
|
||||
_LIBCPP_HIDE_FROM_ABI _Iterator3 __simd_walk_3(
|
||||
_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Iterator3 __first3, _Function __f) noexcept {
|
||||
_PSTL_PRAGMA_SIMD
|
||||
for (_DifferenceType __i = 0; __i < __n; ++__i)
|
||||
__f(__first1[__i], __first2[__i], __first3[__i]);
|
||||
return __first3 + __n;
|
||||
}
|
||||
template <class _ExecutionPolicy,
|
||||
class _ForwardIterator1,
|
||||
class _ForwardIterator2,
|
||||
class _ForwardOutIterator,
|
||||
class _BinaryOperation,
|
||||
enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0>
|
||||
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
|
||||
__cpu_backend_tag,
|
||||
_ForwardIterator1 __first1,
|
||||
_ForwardIterator1 __last1,
|
||||
_ForwardIterator2 __first2,
|
||||
_ForwardOutIterator __result,
|
||||
_BinaryOperation __op) {
|
||||
if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator1>::value &&
|
||||
__has_random_access_iterator_category<_ForwardIterator2>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
std::__terminate_on_exception([&] {
|
||||
std::__par_backend::__parallel_for(
|
||||
__first1,
|
||||
__last1,
|
||||
[__op, __first1, __first2, __result](_ForwardIterator1 __brick_first, _ForwardIterator1 __brick_last) {
|
||||
return std::__pstl_transform<__remove_parallel_policy_t<_ExecutionPolicy>>(
|
||||
__cpu_backend_tag{},
|
||||
__brick_first,
|
||||
__brick_last,
|
||||
__first2 + (__brick_first - __first1),
|
||||
__result + (__brick_first - __first1),
|
||||
__op);
|
||||
});
|
||||
});
|
||||
return __result + (__last1 - __first1);
|
||||
} else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
|
||||
__has_random_access_iterator_category<_ForwardIterator1>::value &&
|
||||
__has_random_access_iterator_category<_ForwardIterator2>::value &&
|
||||
__has_random_access_iterator_category<_ForwardOutIterator>::value) {
|
||||
return std::__simd_walk_3(
|
||||
__first1,
|
||||
__last1 - __first1,
|
||||
__first2,
|
||||
__result,
|
||||
[&](__iter_reference<_ForwardIterator1> __in1,
|
||||
__iter_reference<_ForwardIterator2> __in2,
|
||||
__iter_reference<_ForwardOutIterator> __out_value) { __out_value = __op(__in1, __in2); });
|
||||
} else {
|
||||
return std::transform(__first1, __last1, __first2, __result, __op);
|
||||
}
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
|
||||
|
||||
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_TRANSFORM_H
|
Loading…
Add table
Add a link
Reference in a new issue