28 #ifndef VC_COMMON_ITERATORS_H_ 29 #define VC_COMMON_ITERATORS_H_ 34 #include "elementreference.h" 37 namespace Vc_VERSIONED_NAMESPACE
43 template<
typename _V,
typename Flags>
class MemoryVectorIterator;
45 template <
typename V>
class Iterator;
46 template <
typename V,
bool>
class IteratorBase;
47 template <
typename V>
class IteratorBase<V, true>
50 using iterator_category = std::input_iterator_tag;
51 using value_type =
typename V::value_type;
52 using difference_type = int;
53 using reference = value_type;
54 Vc_ALWAYS_INLINE reference
operator*()
const {
return v()[i()]; }
55 Vc_ALWAYS_INLINE reference operator[](difference_type i2)
const {
return v()[i2]; }
58 Vc_INTRINSIC V &v()
const {
return *
static_cast<const Iterator<V> *
>(
this)->v; }
59 Vc_INTRINSIC difference_type i()
const 61 return static_cast<const Iterator<V> *
>(
this)->i;
65 template <
typename V>
class IteratorBase<V, false>
68 using iterator_category = std::input_iterator_tag;
69 using value_type =
typename V::value_type;
70 using difference_type = int;
71 using reference = Vc::Detail::ElementReference<V, IteratorBase>;
72 Vc_ALWAYS_INLINE reference
operator*()
const {
return {*v(), i()}; }
73 Vc_ALWAYS_INLINE reference operator[](difference_type i2)
const {
return {*v(), i2}; }
76 Vc_INTRINSIC V *v()
const {
return static_cast<const Iterator<V> *
>(
this)->v; }
77 Vc_INTRINSIC difference_type i()
const 79 return static_cast<const Iterator<V> *
>(
this)->i;
83 static Vc_INTRINSIC value_type
get(
const V &o,
int i)
87 template <
typename T>
static Vc_INTRINSIC
void set(V &o,
int i, T &&v)
89 o[i] = std::forward<T>(v);
94 template <
typename V>
class Iterator :
public IteratorBase<V, std::is_const<V>::value>
96 using Base = IteratorBase<V, std::is_const<V>::value>;
100 using typename Base::iterator_category;
101 using typename Base::value_type;
102 using typename Base::difference_type;
103 using pointer =
const Iterator *;
104 using typename Base::reference;
106 constexpr Iterator() =
default;
107 constexpr Iterator(V &_v, difference_type _i) : v(&_v), i(_i) {}
110 Vc_ALWAYS_INLINE pointer operator->()
const {
return this; }
111 using Base::operator*;
113 Vc_ALWAYS_INLINE Iterator &operator++() { ++i;
return *
this; }
114 Vc_ALWAYS_INLINE Iterator operator++(
int) { Iterator tmp = *
this; ++i;
return tmp; }
117 Vc_ALWAYS_INLINE Iterator &operator--() { --i;
return *
this; }
118 Vc_ALWAYS_INLINE Iterator operator--(
int) { Iterator tmp = *
this; --i;
return tmp; }
121 using Base::operator[];
122 Vc_ALWAYS_INLINE Iterator &operator+=(difference_type d) { i += d;
return *
this; }
123 Vc_ALWAYS_INLINE Iterator &operator-=(difference_type d) { i -= d;
return *
this; }
124 Vc_ALWAYS_INLINE Iterator
operator+(difference_type d)
const {
return {*v, i + d}; }
125 Vc_ALWAYS_INLINE Iterator
operator-(difference_type d)
const {
return {*v, i - d}; }
126 Vc_ALWAYS_INLINE difference_type
operator-(
const Iterator &rhs)
const {
return i - rhs.i; }
127 friend Vc_ALWAYS_INLINE Iterator
operator+(difference_type d,
const Iterator &rhs)
129 return {*rhs.v, rhs.i + d};
134 Vc_ALWAYS_INLINE
bool operator==(
const Iterator<V> &rhs)
const {
return v == rhs.v && i == rhs.i; }
135 Vc_ALWAYS_INLINE
bool operator!=(
const Iterator<V> &rhs)
const {
return v == rhs.v && i != rhs.i; }
136 Vc_ALWAYS_INLINE
bool operator< (const Iterator<V> &rhs)
const {
return v == rhs.v && i < rhs.i; }
137 Vc_ALWAYS_INLINE
bool operator<=(const Iterator<V> &rhs)
const {
return v == rhs.v && i <= rhs.i; }
138 Vc_ALWAYS_INLINE
bool operator> (
const Iterator<V> &rhs)
const {
return v == rhs.v && i > rhs.i; }
139 Vc_ALWAYS_INLINE
bool operator>=(
const Iterator<V> &rhs)
const {
return v == rhs.v && i >= rhs.i; }
143 difference_type i = 0;
146 template <
typename V>
using ConstIterator = Iterator<const V>;
149 class BitmaskIterator
154 Vc_ALWAYS_INLINE BitmaskIterator(
int m) : mask(m), bit(_mm_tzcnt_32(mask)) {}
155 Vc_ALWAYS_INLINE BitmaskIterator(
const BitmaskIterator &) =
default;
156 Vc_ALWAYS_INLINE BitmaskIterator(BitmaskIterator &&) =
default;
158 Vc_ALWAYS_INLINE
size_t operator->()
const {
return bit; }
159 Vc_ALWAYS_INLINE
size_t operator*()
const {
return bit; }
161 Vc_ALWAYS_INLINE BitmaskIterator &operator++() {
162 bit = _mm_tzcnti_32(bit, mask);
165 Vc_ALWAYS_INLINE BitmaskIterator operator++(
int) {
166 BitmaskIterator tmp = *
this;
167 bit = _mm_tzcnti_32(bit, mask);
171 Vc_ALWAYS_INLINE
bool operator==(
const BitmaskIterator &rhs)
const {
return bit == rhs.bit; }
172 Vc_ALWAYS_INLINE
bool operator!=(
const BitmaskIterator &rhs)
const {
return bit != rhs.bit; }
175 class BitmaskIterator
188 bit = __builtin_ctzl(mask);
189 #elif defined(Vc_MSVC) 190 _BitScanForward(&bit, mask);
192 #error "Not implemented yet. Please contact vc-devel@compeng.uni-frankfurt.de" 212 BitmaskIterator(decltype(mask) m) : mask(m) { nextBit(); }
213 BitmaskIterator(
const BitmaskIterator &) =
default;
214 BitmaskIterator(BitmaskIterator &&) =
default;
216 Vc_ALWAYS_INLINE
size_t operator->()
const {
return bit; }
217 Vc_ALWAYS_INLINE
size_t operator*()
const {
return bit; }
219 Vc_ALWAYS_INLINE BitmaskIterator &operator++() { resetLsb(); nextBit();
return *
this; }
220 Vc_ALWAYS_INLINE BitmaskIterator operator++(
int) { BitmaskIterator tmp = *
this; resetLsb(); nextBit();
return tmp; }
222 Vc_ALWAYS_INLINE
bool operator==(
const BitmaskIterator &rhs)
const {
return mask == rhs.mask; }
223 Vc_ALWAYS_INLINE
bool operator!=(
const BitmaskIterator &rhs)
const {
return mask != rhs.mask; }
227 template <
typename T>
230 Iterator<typename std::remove_reference<T>::type>>
233 return {std::forward<T>(x), 0};
236 template <
typename T>
239 Iterator<typename std::remove_reference<T>::type>>
242 using TT =
typename std::decay<T>::type;
243 return {std::forward<T>(x),
int(TT::size())};
246 template <
typename T>
247 Vc_ALWAYS_INLINE enable_if<
254 template <
typename T>
255 Vc_ALWAYS_INLINE enable_if<
259 return {v, int(T::size())};
262 template<
typename M> Vc_ALWAYS_INLINE BitmaskIterator begin(
const WhereImpl::WhereMask<M> &w)
264 return w.mask.toInt();
267 template<
typename M> Vc_ALWAYS_INLINE BitmaskIterator end(
const WhereImpl::WhereMask<M> &)
272 template<
typename V,
typename Flags,
typename T> Vc_ALWAYS_INLINE MemoryVectorIterator<V, Flags>
273 makeIterator(T *mem, Flags)
278 template<
typename V,
typename Flags,
typename T> Vc_ALWAYS_INLINE MemoryVectorIterator<const V, Flags>
279 makeIterator(
const T *mem, Flags)
284 template<
typename V,
typename Flags,
typename FlagsX> Vc_ALWAYS_INLINE MemoryVectorIterator<V, Flags>
290 template<
typename V,
typename Flags,
typename FlagsX> Vc_ALWAYS_INLINE MemoryVectorIterator<const V, Flags>
300 using Common::cbegin;
302 using Common::makeIterator;
305 #endif // VC_COMMON_ITERATORS_H_ result_vector_type< L, R > operator-(L &&lhs, R &&rhs)
Applies - component-wise and concurrently.
result_vector_type< L, R >::mask_type operator!=(L &&lhs, R &&rhs)
Applies != component-wise and concurrently.
result_vector_type< L, R > operator*(L &&lhs, R &&rhs)
Applies * component-wise and concurrently.
Identifies any SIMD vector type (independent of implementation or whether it's SimdArray<T, N>).
Helper class for the Memory::vector(size_t) class of functions.
result_vector_type< L, R >::mask_type operator==(L &&lhs, R &&rhs)
Applies == component-wise and concurrently.
result_vector_type< L, R > operator+(L &&lhs, R &&rhs)
Applies + component-wise and concurrently.
result_vector_type< L, R >::mask_type operator>=(L &&lhs, R &&rhs)
Applies >= component-wise and concurrently.
result_vector_type< L, R >::mask_type operator>(L &&lhs, R &&rhs)
Applies > component-wise and concurrently.
Identifies any SIMD mask type (independent of implementation or whether it's SimdMaskArray<T, N>).