File indexing completed on 2025-01-30 10:25:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef VC_COMMON_ALGORITHMS_H_
0029 #define VC_COMMON_ALGORITHMS_H_
0030
0031 #include "simdize.h"
0032
0033 namespace Vc_VERSIONED_NAMESPACE
0034 {
0035 #ifdef DOXYGEN
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 template <class InputIt, class UnaryFunction>
0064 UnaryFunction simd_for_each(InputIt first, InputIt last, UnaryFunction f);
0065 #else
0066 template <class InputIt, class UnaryFunction,
0067 class ValueType = typename std::iterator_traits<InputIt>::value_type>
0068 inline enable_if<
0069 Traits::is_functor_argument_immutable<UnaryFunction, simdize<ValueType>>::value,
0070 UnaryFunction>
0071 simd_for_each(InputIt first, InputIt last, UnaryFunction f)
0072 {
0073 typedef simdize<ValueType> V;
0074 typedef simdize<ValueType, 1> V1;
0075 const auto lastV = last - V::Size + 1;
0076 for (; first < lastV; first += V::Size) {
0077 V tmp;
0078 load_interleaved(tmp, std::addressof(*first));
0079 f(tmp);
0080 }
0081 for (; first != last; ++first) {
0082 V1 tmp;
0083 load_interleaved(tmp, std::addressof(*first));
0084 f(tmp);
0085 }
0086 return f;
0087 }
0088
0089 template <typename InputIt, typename UnaryFunction,
0090 class ValueType = typename std::iterator_traits<InputIt>::value_type>
0091 inline enable_if<
0092 !Traits::is_functor_argument_immutable<UnaryFunction, simdize<ValueType>>::value,
0093 UnaryFunction>
0094 simd_for_each(InputIt first, InputIt last, UnaryFunction f)
0095 {
0096 typedef simdize<ValueType> V;
0097 typedef simdize<ValueType, 1> V1;
0098 const auto lastV = last - V::size() + 1;
0099 for (; first < lastV; first += V::size()) {
0100 V tmp;
0101 load_interleaved(tmp, std::addressof(*first));
0102 f(tmp);
0103 store_interleaved(tmp, std::addressof(*first));
0104 }
0105 for (; first != last; ++first) {
0106 V1 tmp;
0107 load_interleaved(tmp, std::addressof(*first));
0108 f(tmp);
0109 store_interleaved(tmp, std::addressof(*first));
0110 }
0111 return f;
0112 }
0113 #endif
0114
0115
0116 template <typename InputIt, typename UnaryFunction,
0117 class ValueType = typename std::iterator_traits<InputIt>::value_type>
0118 inline enable_if<
0119 Traits::is_functor_argument_immutable<UnaryFunction, simdize<ValueType>>::value,
0120 UnaryFunction>
0121 simd_for_each_n(InputIt first, std::size_t count, UnaryFunction f)
0122 {
0123 typename std::make_signed<size_t>::type len = count;
0124 typedef simdize<ValueType> V;
0125 typedef simdize<ValueType, 1> V1;
0126 for (; len >= int(V::size()); len -= V::Size, first += V::Size) {
0127 V tmp;
0128 load_interleaved(tmp, std::addressof(*first));
0129 f(tmp);
0130 }
0131 for (; len != 0; --len, ++first) {
0132 V1 tmp;
0133 load_interleaved(tmp, std::addressof(*first));
0134 f(tmp);
0135 }
0136 return f;
0137 }
0138
0139 template <typename InputIt, typename UnaryFunction,
0140 class ValueType = typename std::iterator_traits<InputIt>::value_type>
0141 inline enable_if<
0142 !Traits::is_functor_argument_immutable<UnaryFunction, simdize<ValueType>>::value,
0143 UnaryFunction>
0144 simd_for_each_n(InputIt first, std::size_t count, UnaryFunction f)
0145 {
0146 typename std::make_signed<size_t>::type len = count;
0147 typedef simdize<ValueType> V;
0148 typedef simdize<ValueType, 1> V1;
0149 for (; len >= int(V::size()); len -= V::Size, first += V::Size) {
0150 V tmp;
0151 load_interleaved(tmp, std::addressof(*first));
0152 f(tmp);
0153 store_interleaved(tmp, std::addressof(*first));
0154 }
0155 for (; len != 0; --len, ++first) {
0156 V1 tmp;
0157 load_interleaved(tmp, std::addressof(*first));
0158 f(tmp);
0159 store_interleaved(tmp, std::addressof(*first));
0160 }
0161 return f;
0162 }
0163
0164 }
0165
0166 #endif