head 1.1; branch 1.1.1; access; symbols netbsd-11-0-RC5:1.1.1.3 netbsd-11-0-RC4:1.1.1.3 netbsd-11-0-RC3:1.1.1.3 netbsd-11-0-RC2:1.1.1.3 netbsd-11-0-RC1:1.1.1.3 gcc-14-3-0:1.1.1.4 perseant-exfatfs-base-20250801:1.1.1.3 netbsd-11:1.1.1.3.0.4 netbsd-11-base:1.1.1.3 gcc-12-5-0:1.1.1.3 netbsd-10-1-RELEASE:1.1.1.2 perseant-exfatfs-base-20240630:1.1.1.3 gcc-12-4-0:1.1.1.3 perseant-exfatfs:1.1.1.3.0.2 perseant-exfatfs-base:1.1.1.3 netbsd-10-0-RELEASE:1.1.1.2 netbsd-10-0-RC6:1.1.1.2 netbsd-10-0-RC5:1.1.1.2 netbsd-10-0-RC4:1.1.1.2 netbsd-10-0-RC3:1.1.1.2 netbsd-10-0-RC2:1.1.1.2 netbsd-10-0-RC1:1.1.1.2 gcc-12-3-0:1.1.1.3 gcc-10-5-0:1.1.1.2 netbsd-10:1.1.1.2.0.6 netbsd-10-base:1.1.1.2 gcc-10-4-0:1.1.1.2 cjep_sun2x-base1:1.1.1.2 cjep_sun2x:1.1.1.2.0.4 cjep_sun2x-base:1.1.1.2 cjep_staticlib_x-base1:1.1.1.2 cjep_staticlib_x:1.1.1.2.0.2 cjep_staticlib_x-base:1.1.1.2 gcc-10-3-0:1.1.1.2 gcc-9-3-0:1.1.1.1 FSF:1.1.1; locks; strict; comment @ * @; 1.1 date 2020.09.05.07.52.10; author mrg; state Exp; branches 1.1.1.1; next ; commitid ZRYA7IOuwfMjAPmC; 1.1.1.1 date 2020.09.05.07.52.10; author mrg; state Exp; branches; next 1.1.1.2; commitid ZRYA7IOuwfMjAPmC; 1.1.1.2 date 2021.04.10.22.10.04; author mrg; state Exp; branches; next 1.1.1.3; commitid eC4g0MRpqTvEkNOC; 1.1.1.3 date 2023.07.30.05.21.20; author mrg; state Exp; branches; next 1.1.1.4; commitid tk6nV4mbc9nVEMyE; 1.1.1.4 date 2025.09.13.23.45.48; author mrg; state Exp; branches; next ; commitid KwhwN4krNWa6XBaG; desc @@ 1.1 log @Initial revision @ text @// -*- C++ -*- //===-- unseq_backend_simd.h ----------------------------------------------===// // // 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 __PSTL_unseq_backend_simd_H #define __PSTL_unseq_backend_simd_H #include #include "utils.h" // This header defines the minimum set of vector routines required // to support parallel STL. namespace __pstl { namespace __unseq_backend { // Expect vector width up to 64 (or 512 bit) const std::size_t __lane_size = 64; template _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 _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 _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; } // TODO: check whether __simd_first() can be used here template bool __simd_or(_Index __first, _DifferenceType __n, _Pred __pred) noexcept { #if __PSTL_EARLYEXIT_PRESENT _DifferenceType __i; __PSTL_PRAGMA_VECTOR_UNALIGNED __PSTL_PRAGMA_SIMD_EARLYEXIT for (__i = 0; __i < __n; ++__i) if (__pred(__first[__i])) break; return __i < __n; #else _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; #endif } template _Index __simd_first(_Index __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp) noexcept { #if __PSTL_EARLYEXIT_PRESENT _DifferenceType __i = __begin; __PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part __PSTL_PRAGMA_SIMD_EARLYEXIT for (; __i < __end; ++__i) { if (__comp(__first, __i)) { break; } } return __first + __i; #else // 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_VECTOR_UNALIGNED // Do not generate peel loop part __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; #endif //__PSTL_EARLYEXIT_PRESENT } template std::pair<_Index1, _Index2> __simd_first(_Index1 __first1, _DifferenceType __n, _Index2 __first2, _Pred __pred) noexcept { #if __PSTL_EARLYEXIT_PRESENT _DifferenceType __i = 0; __PSTL_PRAGMA_VECTOR_UNALIGNED __PSTL_PRAGMA_SIMD_EARLYEXIT for (; __i < __n; ++__i) if (__pred(__first1[__i], __first2[__i])) break; return std::make_pair(__first1 + __i, __first2 + __i); #else const _Index1 __last1 = __first1 + __n; const _Index2 __last2 = __first2 + __n; // Experiments show good block sizes like this const _DifferenceType __block_size = 8; alignas(__lane_size) _DifferenceType __lane[__block_size] = {0}; while (__last1 - __first1 >= __block_size) { _DifferenceType __found = 0; _DifferenceType __i; __PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part __PSTL_PRAGMA_SIMD_REDUCTION(| : __found) for (__i = 0; __i < __block_size; ++__i) { const _DifferenceType __t = __pred(__first1[__i], __first2[__i]); __lane[__i] = __t; __found |= __t; } if (__found) { _DifferenceType __i; // This will vectorize for (__i = 0; __i < __block_size; ++__i) { if (__lane[__i]) break; } return std::make_pair(__first1 + __i, __first2 + __i); } __first1 += __block_size; __first2 += __block_size; } //Keep remainder scalar for (; __last1 != __first1; ++__first1, ++__first2) if (__pred(*(__first1), *(__first2))) return std::make_pair(__first1, __first2); return std::make_pair(__last1, __last2); #endif //__PSTL_EARLYEXIT_PRESENT } template _DifferenceType __simd_count(_Index __index, _DifferenceType __n, _Pred __pred) noexcept { _DifferenceType __count = 0; __PSTL_PRAGMA_SIMD_REDUCTION(+ : __count) for (_DifferenceType __i = 0; __i < __n; ++__i) if (__pred(*(__index + __i))) ++__count; return __count; } template _OutputIterator __simd_unique_copy(_InputIterator __first, _DifferenceType __n, _OutputIterator __result, _BinaryPredicate __pred) noexcept { if (__n == 0) return __result; _DifferenceType __cnt = 1; __result[0] = __first[0]; __PSTL_PRAGMA_SIMD for (_DifferenceType __i = 1; __i < __n; ++__i) { __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1) if (!__pred(__first[__i], __first[__i - 1])) { __result[__cnt] = __first[__i]; ++__cnt; } } return __result + __cnt; } template _OutputIterator __simd_assign(_InputIterator __first, _DifferenceType __n, _OutputIterator __result, _Assigner __assigner) noexcept { __PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED __PSTL_PRAGMA_SIMD for (_DifferenceType __i = 0; __i < __n; ++__i) __assigner(__first + __i, __result + __i); return __result + __n; } template _OutputIterator __simd_copy_if(_InputIterator __first, _DifferenceType __n, _OutputIterator __result, _UnaryPredicate __pred) noexcept { _DifferenceType __cnt = 0; __PSTL_PRAGMA_SIMD for (_DifferenceType __i = 0; __i < __n; ++__i) { __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1) if (__pred(__first[__i])) { __result[__cnt] = __first[__i]; ++__cnt; } } return __result + __cnt; } template _DifferenceType __simd_calc_mask_2(_InputIterator __first, _DifferenceType __n, bool* __mask, _BinaryPredicate __pred) noexcept { _DifferenceType __count = 0; __PSTL_PRAGMA_SIMD_REDUCTION(+ : __count) for (_DifferenceType __i = 0; __i < __n; ++__i) { __mask[__i] = !__pred(__first[__i], __first[__i - 1]); __count += __mask[__i]; } return __count; } template _DifferenceType __simd_calc_mask_1(_InputIterator __first, _DifferenceType __n, bool* __mask, _UnaryPredicate __pred) noexcept { _DifferenceType __count = 0; __PSTL_PRAGMA_SIMD_REDUCTION(+ : __count) for (_DifferenceType __i = 0; __i < __n; ++__i) { __mask[__i] = __pred(__first[__i]); __count += __mask[__i]; } return __count; } template void __simd_copy_by_mask(_InputIterator __first, _DifferenceType __n, _OutputIterator __result, bool* __mask, _Assigner __assigner) noexcept { _DifferenceType __cnt = 0; __PSTL_PRAGMA_SIMD for (_DifferenceType __i = 0; __i < __n; ++__i) { if (__mask[__i]) { __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1) { __assigner(__first + __i, __result + __cnt); ++__cnt; } } } } template void __simd_partition_by_mask(_InputIterator __first, _DifferenceType __n, _OutputIterator1 __out_true, _OutputIterator2 __out_false, bool* __mask) noexcept { _DifferenceType __cnt_true = 0, __cnt_false = 0; __PSTL_PRAGMA_SIMD for (_DifferenceType __i = 0; __i < __n; ++__i) { __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(__cnt_true : 1, __cnt_false : 1) if (__mask[__i]) { __out_true[__cnt_true] = __first[__i]; ++__cnt_true; } else { __out_false[__cnt_false] = __first[__i]; ++__cnt_false; } } } template _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 _Index __simd_generate_n(_Index __first, _DifferenceType __size, _Generator __g) noexcept { __PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED __PSTL_PRAGMA_SIMD for (_DifferenceType __i = 0; __i < __size; ++__i) __first[__i] = __g(); return __first + __size; } template _Index __simd_adjacent_find(_Index __first, _Index __last, _BinaryPredicate __pred, bool __or_semantic) noexcept { if (__last - __first < 2) return __last; typedef typename std::iterator_traits<_Index>::difference_type _DifferenceType; _DifferenceType __i = 0; #if __PSTL_EARLYEXIT_PRESENT //Some compiler versions fail to compile the following loop when iterators are used. Indices are used instead const _DifferenceType __n = __last - __first - 1; __PSTL_PRAGMA_VECTOR_UNALIGNED __PSTL_PRAGMA_SIMD_EARLYEXIT for (; __i < __n; ++__i) if (__pred(__first[__i], __first[__i + 1])) break; return __i < __n ? __first + __i : __last; #else // Experiments show good block sizes like this //TODO: to consider tuning block_size for various data types const _DifferenceType __block_size = 8; alignas(__lane_size) _DifferenceType __lane[__block_size] = {0}; while (__last - __first >= __block_size) { _DifferenceType __found = 0; __PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part __PSTL_PRAGMA_SIMD_REDUCTION(| : __found) for (__i = 0; __i < __block_size - 1; ++__i) { //TODO: to improve SIMD vectorization const _DifferenceType __t = __pred(*(__first + __i), *(__first + __i + 1)); __lane[__i] = __t; __found |= __t; } //Process a pair of elements on a boundary of a data block if (__first + __block_size < __last && __pred(*(__first + __i), *(__first + __i + 1))) __lane[__i] = __found = 1; if (__found) { if (__or_semantic) return __first; // This will vectorize for (__i = 0; __i < __block_size; ++__i) if (__lane[__i]) break; return __first + __i; //As far as found is true a __result (__lane[__i] is true) is guaranteed } __first += __block_size; } //Process the rest elements for (; __last - __first > 1; ++__first) if (__pred(*__first, *(__first + 1))) return __first; return __last; #endif } // It was created to reduce the code inside std::enable_if template using is_arithmetic_plus = std::integral_constant::value && std::is_same<_BinaryOperation, std::plus<_Tp>>::value>; template typename std::enable_if::value, _Tp>::type __simd_transform_reduce(_DifferenceType __n, _Tp __init, _BinaryOperation, _UnaryOperation __f) noexcept { __PSTL_PRAGMA_SIMD_REDUCTION(+ : __init) for (_DifferenceType __i = 0; __i < __n; ++__i) __init += __f(__i); return __init; } template typename std::enable_if::value, _Tp>::type __simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _UnaryOperation __f) noexcept { const _Size __block_size = __lane_size / sizeof(_Tp); if (__n > 2 * __block_size && __block_size > 1) { alignas(__lane_size) char __lane_[__lane_size]; _Tp* __lane = reinterpret_cast<_Tp*>(__lane_); // initializer __PSTL_PRAGMA_SIMD for (_Size __i = 0; __i < __block_size; ++__i) { ::new (__lane + __i) _Tp(__binary_op(__f(__i), __f(__block_size + __i))); } // main loop _Size __i = 2 * __block_size; const _Size last_iteration = __block_size * (__n / __block_size); for (; __i < last_iteration; __i += __block_size) { __PSTL_PRAGMA_SIMD for (_Size __j = 0; __j < __block_size; ++__j) { __lane[__j] = __binary_op(__lane[__j], __f(__i + __j)); } } // remainder __PSTL_PRAGMA_SIMD for (_Size __j = 0; __j < __n - last_iteration; ++__j) { __lane[__j] = __binary_op(__lane[__j], __f(last_iteration + __j)); } // combiner for (_Size __i = 0; __i < __block_size; ++__i) { __init = __binary_op(__init, __lane[__i]); } // destroyer __PSTL_PRAGMA_SIMD for (_Size __i = 0; __i < __block_size; ++__i) { __lane[__i].~_Tp(); } } else { for (_Size __i = 0; __i < __n; ++__i) { __init = __binary_op(__init, __f(__i)); } } return __init; } // Exclusive scan for "+" and arithmetic types template typename std::enable_if::value, std::pair<_OutputIterator, _Tp>>::type __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init, _BinaryOperation, /*Inclusive*/ std::false_type) { __PSTL_PRAGMA_SIMD_SCAN(+ : __init) for (_Size __i = 0; __i < __n; ++__i) { __result[__i] = __init; __PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init) __init += __unary_op(__first[__i]); } return std::make_pair(__result + __n, __init); } // As soon as we cannot call __binary_op in "combiner" we create a wrapper over _Tp to encapsulate __binary_op template struct _Combiner { _Tp __value; _BinaryOp* __bin_op; // Here is a pointer to function because of default ctor _Combiner() : __value{}, __bin_op(nullptr) {} _Combiner(const _Tp& value, const _BinaryOp* bin_op) : __value(value), __bin_op(const_cast<_BinaryOp*>(bin_op)) {} _Combiner(const _Combiner& __obj) : __value{}, __bin_op(__obj.__bin_op) {} void operator()(const _Combiner& __obj) { __value = (*__bin_op)(__value, __obj.__value); } }; // Exclusive scan for other binary operations and types template typename std::enable_if::value, std::pair<_OutputIterator, _Tp>>::type __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op, /*Inclusive*/ std::false_type) { typedef _Combiner<_Tp, _BinaryOperation> _CombinerType; _CombinerType __init_{__init, &__binary_op}; __PSTL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType) __PSTL_PRAGMA_SIMD_SCAN(__bin_op : __init_) for (_Size __i = 0; __i < __n; ++__i) { __result[__i] = __init_.__value; __PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init_) __PSTL_PRAGMA_FORCEINLINE __init_.__value = __binary_op(__init_.__value, __unary_op(__first[__i])); } return std::make_pair(__result + __n, __init_.__value); } // Inclusive scan for "+" and arithmetic types template typename std::enable_if::value, std::pair<_OutputIterator, _Tp>>::type __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init, _BinaryOperation, /*Inclusive*/ std::true_type) { __PSTL_PRAGMA_SIMD_SCAN(+ : __init) for (_Size __i = 0; __i < __n; ++__i) { __init += __unary_op(__first[__i]); __PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init) __result[__i] = __init; } return std::make_pair(__result + __n, __init); } // Inclusive scan for other binary operations and types template typename std::enable_if::value, std::pair<_OutputIterator, _Tp>>::type __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op, std::true_type) { typedef _Combiner<_Tp, _BinaryOperation> _CombinerType; _CombinerType __init_{__init, &__binary_op}; __PSTL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType) __PSTL_PRAGMA_SIMD_SCAN(__bin_op : __init_) for (_Size __i = 0; __i < __n; ++__i) { __PSTL_PRAGMA_FORCEINLINE __init_.__value = __binary_op(__init_.__value, __unary_op(__first[__i])); __PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init_) __result[__i] = __init_.__value; } return std::make_pair(__result + __n, __init_.__value); } // [restriction] - std::iterator_traits<_ForwardIterator>::value_type should be DefaultConstructible. // complexity [violation] - We will have at most (__n-1 + number_of_lanes) comparisons instead of at most __n-1. template _ForwardIterator __simd_min_element(_ForwardIterator __first, _Size __n, _Compare __comp) noexcept { if (__n == 0) { return __first; } typedef typename std::iterator_traits<_ForwardIterator>::value_type _ValueType; struct _ComplexType { _ValueType __min_val; _Size __min_ind; _Compare* __min_comp; _ComplexType() : __min_val{}, __min_ind{}, __min_comp(nullptr) {} _ComplexType(const _ValueType& val, const _Compare* comp) : __min_val(val), __min_ind(0), __min_comp(const_cast<_Compare*>(comp)) { } _ComplexType(const _ComplexType& __obj) : __min_val(__obj.__min_val), __min_ind(__obj.__min_ind), __min_comp(__obj.__min_comp) { } __PSTL_PRAGMA_DECLARE_SIMD void operator()(const _ComplexType& __obj) { if (!(*__min_comp)(__min_val, __obj.__min_val) && ((*__min_comp)(__obj.__min_val, __min_val) || __obj.__min_ind - __min_ind < 0)) { __min_val = __obj.__min_val; __min_ind = __obj.__min_ind; } } }; _ComplexType __init{*__first, &__comp}; __PSTL_PRAGMA_DECLARE_REDUCTION(__min_func, _ComplexType) __PSTL_PRAGMA_SIMD_REDUCTION(__min_func : __init) for (_Size __i = 1; __i < __n; ++__i) { const _ValueType __min_val = __init.__min_val; const _ValueType __current = __first[__i]; if (__comp(__current, __min_val)) { __init.__min_val = __current; __init.__min_ind = __i; } } return __first + __init.__min_ind; } // [restriction] - std::iterator_traits<_ForwardIterator>::value_type should be DefaultConstructible. // complexity [violation] - We will have at most (2*(__n-1) + 4*number_of_lanes) comparisons instead of at most [1.5*(__n-1)]. template std::pair<_ForwardIterator, _ForwardIterator> __simd_minmax_element(_ForwardIterator __first, _Size __n, _Compare __comp) noexcept { if (__n == 0) { return std::make_pair(__first, __first); } typedef typename std::iterator_traits<_ForwardIterator>::value_type _ValueType; struct _ComplexType { _ValueType __min_val; _ValueType __max_val; _Size __min_ind; _Size __max_ind; _Compare* __minmax_comp; _ComplexType() : __min_val{}, __max_val{}, __min_ind{}, __max_ind{}, __minmax_comp(nullptr) {} _ComplexType(const _ValueType& min_val, const _ValueType& max_val, const _Compare* comp) : __min_val(min_val), __max_val(max_val), __min_ind(0), __max_ind(0), __minmax_comp(const_cast<_Compare*>(comp)) { } _ComplexType(const _ComplexType& __obj) : __min_val(__obj.__min_val), __max_val(__obj.__max_val), __min_ind(__obj.__min_ind), __max_ind(__obj.__max_ind), __minmax_comp(__obj.__minmax_comp) { } void operator()(const _ComplexType& __obj) { // min if ((*__minmax_comp)(__obj.__min_val, __min_val)) { __min_val = __obj.__min_val; __min_ind = __obj.__min_ind; } else if (!(*__minmax_comp)(__min_val, __obj.__min_val)) { __min_val = __obj.__min_val; __min_ind = (__min_ind - __obj.__min_ind < 0) ? __min_ind : __obj.__min_ind; } // max if ((*__minmax_comp)(__max_val, __obj.__max_val)) { __max_val = __obj.__max_val; __max_ind = __obj.__max_ind; } else if (!(*__minmax_comp)(__obj.__max_val, __max_val)) { __max_val = __obj.__max_val; __max_ind = (__max_ind - __obj.__max_ind < 0) ? __obj.__max_ind : __max_ind; } } }; _ComplexType __init{*__first, *__first, &__comp}; __PSTL_PRAGMA_DECLARE_REDUCTION(__min_func, _ComplexType); __PSTL_PRAGMA_SIMD_REDUCTION(__min_func : __init) for (_Size __i = 1; __i < __n; ++__i) { auto __min_val = __init.__min_val; auto __max_val = __init.__max_val; auto __current = __first + __i; if (__comp(*__current, __min_val)) { __init.__min_val = *__current; __init.__min_ind = __i; } else if (!__comp(*__current, __max_val)) { __init.__max_val = *__current; __init.__max_ind = __i; } } return std::make_pair(__first + __init.__min_ind, __first + __init.__max_ind); } template std::pair<_OutputIterator1, _OutputIterator2> __simd_partition_copy(_InputIterator __first, _DifferenceType __n, _OutputIterator1 __out_true, _OutputIterator2 __out_false, _UnaryPredicate __pred) noexcept { _DifferenceType __cnt_true = 0, __cnt_false = 0; __PSTL_PRAGMA_SIMD for (_DifferenceType __i = 0; __i < __n; ++__i) { __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(__cnt_true : 1, __cnt_false : 1) if (__pred(__first[__i])) { __out_true[__cnt_true] = __first[__i]; ++__cnt_true; } else { __out_false[__cnt_false] = __first[__i]; ++__cnt_false; } } return std::make_pair(__out_true + __cnt_true, __out_false + __cnt_false); } template _ForwardIterator1 __simd_find_first_of(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first, _ForwardIterator2 __s_last, _BinaryPredicate __pred) noexcept { typedef typename std::iterator_traits<_ForwardIterator1>::difference_type _DifferencType; const _DifferencType __n1 = __last - __first; const _DifferencType __n2 = __s_last - __s_first; if (__n1 == 0 || __n2 == 0) { return __last; // according to the standard } // Common case // If first sequence larger than second then we'll run simd_first with parameters of first sequence. // Otherwise, vice versa. if (__n1 < __n2) { for (; __first != __last; ++__first) { if (__unseq_backend::__simd_or(__s_first, __n2, __internal::__equal_value_by_pred(*__first, __pred))) { return __first; } } } else { for (; __s_first != __s_last; ++__s_first) { const auto __result = __unseq_backend::__simd_first(__first, _DifferencType(0), __n1, [__s_first, &__pred](_ForwardIterator1 __it, _DifferencType __i) { return __pred(__it[__i], *__s_first); }); if (__result != __last) { return __result; } } } return __last; } template _RandomAccessIterator __simd_remove_if(_RandomAccessIterator __first, _DifferenceType __n, _UnaryPredicate __pred) noexcept { // find first element we need to remove auto __current = __unseq_backend::__simd_first(__first, _DifferenceType(0), __n, [&__pred](_RandomAccessIterator __it, _DifferenceType __i) { return __pred(__it[__i]); }); __n -= __current - __first; // if we have in sequence only one element that pred(__current[1]) != false we can exit the function if (__n < 2) { return __current; } _DifferenceType __cnt = 0; __PSTL_PRAGMA_SIMD for (_DifferenceType __i = 1; __i < __n; ++__i) { __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1) if (!__pred(__current[__i])) { __current[__cnt] = std::move(__current[__i]); ++__cnt; } } return __current + __cnt; } } // namespace __unseq_backend } // namespace __pstl #endif /* __PSTL_unseq_backend_simd_H */ @ 1.1.1.1 log @initial import of GCC 9.3.0. changes include: - live patching support - shell completion help - generally better diagnostic output (less verbose/more useful) - diagnostics and optimisation choices can be emitted in json - asan memory usage reduction - many general, and specific to switch, inter-procedure, profile and link-time optimisations. from the release notes: "Overall compile time of Firefox 66 and LibreOffice 6.2.3 on an 8-core machine was reduced by about 5% compared to GCC 8.3" - OpenMP 5.0 support - better spell-guesser - partial experimental support for c2x and c++2a - c++17 is no longer experimental - arm AAPCS GCC 6-8 structure passing bug fixed, may cause incompatibility (restored compat with GCC 5 and earlier.) - openrisc support @ text @@ 1.1.1.2 log @initial import of GCC 10.3.0. main changes include: caveats: - ABI issue between c++14 and c++17 fixed - profile mode is removed from libstdc++ - -fno-common is now the default new features: - new flags -fallocation-dce, -fprofile-partial-training, -fprofile-reproducible, -fprofile-prefix-path, and -fanalyzer - many new compile and link time optimisations - enhanced drive optimisations - openacc 2.6 support - openmp 5.0 features - new warnings: -Wstring-compare and -Wzero-length-bounds - extended warnings: -Warray-bounds, -Wformat-overflow, -Wrestrict, -Wreturn-local-addr, -Wstringop-overflow, -Warith-conversion, -Wmismatched-tags, and -Wredundant-tags - some likely C2X features implemented - more C++20 implemented - many new arm & intel CPUs known hundreds of reported bugs are fixed. full list of changes can be found at: https://gcc.gnu.org/gcc-10/changes.html @ text @d10 2 a11 2 #ifndef _PSTL_UNSEQ_BACKEND_SIMD_H #define _PSTL_UNSEQ_BACKEND_SIMD_H d31 1 a31 1 _PSTL_PRAGMA_SIMD d42 1 a42 1 _PSTL_PRAGMA_SIMD d53 1 a53 1 _PSTL_PRAGMA_SIMD d64 1 a64 1 #if _PSTL_EARLYEXIT_PRESENT d66 2 a67 2 _PSTL_PRAGMA_VECTOR_UNALIGNED _PSTL_PRAGMA_SIMD_EARLYEXIT d78 1 a78 1 _PSTL_PRAGMA_SIMD_REDUCTION(& : __flag) d104 1 a104 1 #if _PSTL_EARLYEXIT_PRESENT d106 2 a107 2 _PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part _PSTL_PRAGMA_SIMD_EARLYEXIT for (; __i < __end; ++__i) d122 4 a125 4 _PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part _PSTL_PRAGMA_SIMD_REDUCTION(| : __found) for (_DifferenceType __i = __begin; __i < __begin + __block_size; ++__i) d157 1 a157 1 #endif //_PSTL_EARLYEXIT_PRESENT d164 1 a164 1 #if _PSTL_EARLYEXIT_PRESENT d166 2 a167 2 _PSTL_PRAGMA_VECTOR_UNALIGNED _PSTL_PRAGMA_SIMD_EARLYEXIT d182 2 a183 2 _PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part _PSTL_PRAGMA_SIMD_REDUCTION(| d211 1 a211 1 #endif //_PSTL_EARLYEXIT_PRESENT d219 1 a219 1 _PSTL_PRAGMA_SIMD_REDUCTION(+ : __count) d238 1 a238 1 _PSTL_PRAGMA_SIMD d241 1 a241 1 _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1) d255 2 a256 2 _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED _PSTL_PRAGMA_SIMD d268 1 a268 1 _PSTL_PRAGMA_SIMD d271 1 a271 1 _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1) d287 1 a287 1 _PSTL_PRAGMA_SIMD_REDUCTION(+ : __count) d302 1 a302 1 _PSTL_PRAGMA_SIMD_REDUCTION(+ : __count) d317 1 a317 1 _PSTL_PRAGMA_SIMD d322 1 a322 1 _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1) d337 1 a337 1 _PSTL_PRAGMA_SIMD d340 1 a340 1 _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(__cnt_true : 1, __cnt_false : 1) d358 2 a359 2 _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED _PSTL_PRAGMA_SIMD d369 2 a370 2 _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED _PSTL_PRAGMA_SIMD d386 1 a386 1 #if _PSTL_EARLYEXIT_PRESENT d389 2 a390 2 _PSTL_PRAGMA_VECTOR_UNALIGNED _PSTL_PRAGMA_SIMD_EARLYEXIT d404 2 a405 2 _PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part _PSTL_PRAGMA_SIMD_REDUCTION(| d449 1 a449 1 _PSTL_PRAGMA_SIMD_REDUCTION(+ : __init) d466 1 a466 1 _PSTL_PRAGMA_SIMD d476 1 a476 1 _PSTL_PRAGMA_SIMD d483 1 a483 1 _PSTL_PRAGMA_SIMD d494 1 a494 1 _PSTL_PRAGMA_SIMD d517 1 a517 1 _PSTL_PRAGMA_SIMD_SCAN(+ : __init) d521 1 a521 1 _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init) d555 1 a555 1 _PSTL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType) d557 1 a557 1 _PSTL_PRAGMA_SIMD_SCAN(__bin_op : __init_) d561 2 a562 2 _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init_) _PSTL_PRAGMA_FORCEINLINE d575 1 a575 1 _PSTL_PRAGMA_SIMD_SCAN(+ : __init) d579 1 a579 1 _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init) d595 1 a595 1 _PSTL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType) d597 1 a597 1 _PSTL_PRAGMA_SIMD_SCAN(__bin_op : __init_) d600 1 a600 1 _PSTL_PRAGMA_FORCEINLINE d602 1 a602 1 _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init_) d636 1 a636 1 _PSTL_PRAGMA_DECLARE_SIMD d651 1 a651 1 _PSTL_PRAGMA_DECLARE_REDUCTION(__min_func, _ComplexType) d653 1 a653 1 _PSTL_PRAGMA_SIMD_REDUCTION(__min_func : __init) d730 1 a730 1 _PSTL_PRAGMA_DECLARE_REDUCTION(__min_func, _ComplexType); d732 1 a732 1 _PSTL_PRAGMA_SIMD_REDUCTION(__min_func : __init) d760 1 a760 1 _PSTL_PRAGMA_SIMD d763 1 a763 1 _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(__cnt_true : 1, __cnt_false : 1) d840 1 a840 1 _PSTL_PRAGMA_SIMD d843 1 a843 1 _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1) d855 1 a855 1 #endif /* _PSTL_UNSEQ_BACKEND_SIMD_H */ @ 1.1.1.3 log @initial import of GCC 12.3.0. major changes in GCC 11 included: - The default mode for C++ is now -std=gnu++17 instead of -std=gnu++14. - When building GCC itself, the host compiler must now support C++11, rather than C++98. - Some short options of the gcov tool have been renamed: -i to -j and -j to -H. - ThreadSanitizer improvements. - Introduce Hardware-assisted AddressSanitizer support. - For targets that produce DWARF debugging information GCC now defaults to DWARF version 5. This can produce up to 25% more compact debug information compared to earlier versions. - Many optimisations. - The existing malloc attribute has been extended so that it can be used to identify allocator/deallocator API pairs. A pair of new -Wmismatched-dealloc and -Wmismatched-new-delete warnings are added. - Other new warnings: -Wsizeof-array-div, enabled by -Wall, warns about divisions of two sizeof operators when the first one is applied to an array and the divisor does not equal the size of the array element. -Wstringop-overread, enabled by default, warns about calls to string functions reading past the end of the arrays passed to them as arguments. -Wtsan, enabled by default, warns about unsupported features in ThreadSanitizer (currently std::atomic_thread_fence). - Enchanced warnings: -Wfree-nonheap-object detects many more instances of calls to deallocation functions with pointers not returned from a dynamic memory allocation function. -Wmaybe-uninitialized diagnoses passing pointers or references to uninitialized memory to functions taking const-qualified arguments. -Wuninitialized detects reads from uninitialized dynamically allocated memory. -Warray-parameter warns about functions with inconsistent array forms. -Wvla-parameter warns about functions with inconsistent VLA forms. - Several new features from the upcoming C2X revision of the ISO C standard are supported with -std=c2x and -std=gnu2x. - Several C++20 features have been implemented. - The C++ front end has experimental support for some of the upcoming C++23 draft. - Several new C++ warnings. - Enhanced Arm, AArch64, x86, and RISC-V CPU support. - The implementation of how program state is tracked within -fanalyzer has been completely rewritten with many enhancements. see https://gcc.gnu.org/gcc-11/changes.html for a full list. major changes in GCC 12 include: - An ABI incompatibility between C and C++ when passing or returning by value certain aggregates containing zero width bit-fields has been discovered on various targets. x86-64, ARM and AArch64 will always ignore them (so there is a C ABI incompatibility between GCC 11 and earlier with GCC 12 or later), PowerPC64 ELFv2 always take them into account (so there is a C++ ABI incompatibility, GCC 4.4 and earlier compatible with GCC 12 or later, incompatible with GCC 4.5 through GCC 11). RISC-V has changed the handling of these already starting with GCC 10. As the ABI requires, MIPS takes them into account handling function return values so there is a C++ ABI incompatibility with GCC 4.5 through 11. - STABS: Support for emitting the STABS debugging format is deprecated and will be removed in the next release. All ports now default to emit DWARF (version 2 or later) debugging info or are obsoleted. - Vectorization is enabled at -O2 which is now equivalent to the original -O2 -ftree-vectorize -fvect-cost-model=very-cheap. - GCC now supports the ShadowCallStack sanitizer. - Support for __builtin_shufflevector compatible with the clang language extension was added. - Support for attribute unavailable was added. - Support for __builtin_dynamic_object_size compatible with the clang language extension was added. - New warnings: -Wbidi-chars warns about potentially misleading UTF-8 bidirectional control characters. -Warray-compare warns about comparisons between two operands of array type. - Some new features from the upcoming C2X revision of the ISO C standard are supported with -std=c2x and -std=gnu2x. - Several C++23 features have been implemented. - Many C++ enhancements across warnings and -f options. see https://gcc.gnu.org/gcc-12/changes.html for a full list. @ text @d184 1 a184 1 : __found) for (__i = 0; __i < __block_size; ++__i) d192 1 a192 1 _DifferenceType __i2; d194 1 a194 1 for (__i2 = 0; __i2 < __block_size; ++__i2) d196 1 a196 1 if (__lane[__i2]) d199 1 a199 1 return std::make_pair(__first1 + __i2, __first2 + __i2); d406 1 a406 1 : __found) for (__i = 0; __i < __block_size - 1; ++__i) d489 1 a489 1 for (_Size __j = 0; __j < __block_size; ++__j) d491 1 a491 1 __init = __binary_op(__init, __lane[__j]); d495 1 a495 1 for (_Size __j = 0; __j < __block_size; ++__j) d497 1 a497 1 __lane[__j].~_Tp(); d799 2 a800 3 if (__unseq_backend::__simd_or( __s_first, __n2, __internal::__equal_value_by_pred(*__first, __pred))) d810 4 a813 4 const auto __result = __unseq_backend::__simd_first( __first, _DifferencType(0), __n1, [__s_first, &__pred](_ForwardIterator1 __it, _DifferencType __i) { return __pred(__it[__i], *__s_first); }); d828 3 a830 3 auto __current = __unseq_backend::__simd_first( __first, _DifferenceType(0), __n, [&__pred](_RandomAccessIterator __it, _DifferenceType __i) { return __pred(__it[__i]); }); @ 1.1.1.4 log @initial import of GCC 14.3.0. major changes in GCC 13: - improved sanitizer - zstd debug info compression - LTO improvements - SARIF based diagnostic support - new warnings: -Wxor-used-as-pow, -Wenum-int-mismatch, -Wself-move, -Wdangling-reference - many new -Wanalyzer* specific warnings - enhanced warnings: -Wpessimizing-move, -Wredundant-move - new attributes to mark file descriptors, c++23 "assume" - several C23 features added - several C++23 features added - many new features for Arm, x86, RISC-V major changes in GCC 14: - more strict C99 or newer support - ia64* marked deprecated (but seemingly still in GCC 15.) - several new hardening features - support for "hardbool", which can have user supplied values of true/false - explicit support for stack scrubbing upon function exit - better auto-vectorisation support - added clang-compatible __has_feature and __has_extension - more C23, including -std=c23 - several C++26 features added - better diagnostics in C++ templates - new warnings: -Wnrvo, Welaborated-enum-base - many new features for Arm, x86, RISC-V - possible ABI breaking change for SPARC64 and small structures with arrays of floats. @ text @d64 1 a64 1 #if defined(_PSTL_EARLYEXIT_PRESENT) d77 1 a77 1 __INT32_TYPE__ __flag = 1; d104 1 a104 1 #if defined(_PSTL_EARLYEXIT_PRESENT) d164 1 a164 1 #if defined(_PSTL_EARLYEXIT_PRESENT) d386 1 a386 1 #if defined(_PSTL_EARLYEXIT_PRESENT) d535 1 a535 1 _Combiner(const _Tp& __v, const _BinaryOp* __b) : __value(__v), __bin_op(const_cast<_BinaryOp*>(__b)) {} d688 3 a690 3 _ComplexType(const _ValueType& __min, const _ValueType& __max, const _Compare* __comp) : __min_val(__min), __max_val(__max), __min_ind(0), __max_ind(0), __minmax_comp(const_cast<_Compare*>(__comp)) @