29 #ifndef VC_COMMON_ITERATORS_H_
30 #define VC_COMMON_ITERATORS_H_
37 namespace Vc_VERSIONED_NAMESPACE
43 template<
typename _V,
typename Flags>
class MemoryVectorIterator;
48 :
public std::iterator<std::bidirectional_iterator_tag, typename V::EntryType>
53 constexpr Iterator(V &_v,
size_t _i) : v(_v), i(_i) {}
54 constexpr Iterator(
const Iterator &) =
default;
55 constexpr Iterator(Iterator &&) =
default;
57 Vc_ALWAYS_INLINE decltype(v[i]) operator->() {
return v[i]; }
58 Vc_ALWAYS_INLINE decltype(v[i]) operator->()
const {
return v[i]; }
60 Vc_ALWAYS_INLINE decltype(v[i]) operator*() {
return v[i]; }
61 Vc_ALWAYS_INLINE decltype(v[i]) operator*()
const {
return v[i]; }
63 Vc_ALWAYS_INLINE Iterator &operator++() { ++i;
return *
this; }
64 Vc_ALWAYS_INLINE Iterator operator++(
int) { Iterator tmp = *
this; ++i;
return tmp; }
66 Vc_ALWAYS_INLINE Iterator &operator--() { --i;
return *
this; }
67 Vc_ALWAYS_INLINE Iterator operator--(
int) { Iterator tmp = *
this; --i;
return tmp; }
70 Vc_ALWAYS_INLINE
bool operator==(
const Iterator<V> &rhs)
const {
return i == rhs.i; }
71 Vc_ALWAYS_INLINE
bool operator!=(
const Iterator<V> &rhs)
const {
return i != rhs.i; }
72 Vc_ALWAYS_INLINE
bool operator< (const Iterator<V> &rhs)
const {
return i < rhs.i; }
73 Vc_ALWAYS_INLINE
bool operator<=(const Iterator<V> &rhs)
const {
return i <= rhs.i; }
74 Vc_ALWAYS_INLINE
bool operator> (
const Iterator<V> &rhs)
const {
return i > rhs.i; }
75 Vc_ALWAYS_INLINE
bool operator>=(
const Iterator<V> &rhs)
const {
return i >= rhs.i; }
78 template<
typename V>
using ConstIterator = Iterator<const V>;
86 Vc_ALWAYS_INLINE BitmaskIterator(
int m) : mask(m), bit(_mm_tzcnt_32(mask)) {}
87 Vc_ALWAYS_INLINE BitmaskIterator(
const BitmaskIterator &) =
default;
88 Vc_ALWAYS_INLINE BitmaskIterator(BitmaskIterator &&) =
default;
90 Vc_ALWAYS_INLINE
size_t operator->()
const {
return bit; }
91 Vc_ALWAYS_INLINE
size_t operator*()
const {
return bit; }
93 Vc_ALWAYS_INLINE BitmaskIterator &operator++() {
94 bit = _mm_tzcnti_32(bit, mask);
97 Vc_ALWAYS_INLINE BitmaskIterator operator++(
int) {
98 BitmaskIterator tmp = *
this;
99 bit = _mm_tzcnti_32(bit, mask);
103 Vc_ALWAYS_INLINE
bool operator==(
const BitmaskIterator &rhs)
const {
return bit == rhs.bit; }
104 Vc_ALWAYS_INLINE
bool operator!=(
const BitmaskIterator &rhs)
const {
return bit != rhs.bit; }
107 class BitmaskIterator
120 bit = __builtin_ctzl(mask);
121 #elif defined(Vc_MSVC)
122 _BitScanForward(&bit, mask);
124 #error "Not implemented yet. Please contact vc-devel@compeng.uni-frankfurt.de"
144 BitmaskIterator(decltype(mask) m) : mask(m) { nextBit(); }
145 BitmaskIterator(
const BitmaskIterator &) =
default;
146 BitmaskIterator(BitmaskIterator &&) =
default;
148 Vc_ALWAYS_INLINE
size_t operator->()
const {
return bit; }
149 Vc_ALWAYS_INLINE
size_t operator*()
const {
return bit; }
151 Vc_ALWAYS_INLINE BitmaskIterator &operator++() { resetLsb(); nextBit();
return *
this; }
152 Vc_ALWAYS_INLINE BitmaskIterator operator++(
int) { BitmaskIterator tmp = *
this; resetLsb(); nextBit();
return tmp; }
154 Vc_ALWAYS_INLINE
bool operator==(
const BitmaskIterator &rhs)
const {
return mask == rhs.mask; }
155 Vc_ALWAYS_INLINE
bool operator!=(
const BitmaskIterator &rhs)
const {
return mask != rhs.mask; }
159 template<
typename V> constexpr
typename std::enable_if<Traits::is_simd_vector<V>::value, Iterator<V>>::type begin(V &v)
164 template<
typename V> constexpr
typename std::enable_if<Traits::is_simd_vector<V>::value, Iterator<V>>::type end(V &v)
166 return { v, V::Size };
169 template<
typename V> constexpr
typename std::enable_if<Traits::is_simd_mask<V>::value || Traits::is_simd_vector<V>::value, ConstIterator<V>>::type begin(
const V &v)
174 template<
typename V> constexpr
typename std::enable_if<Traits::is_simd_mask<V>::value || Traits::is_simd_vector<V>::value, ConstIterator<V>>::type end(
const V &v)
176 return { v, V::Size };
179 template<
typename V> constexpr
typename std::enable_if<Traits::is_simd_mask<V>::value || Traits::is_simd_vector<V>::value, ConstIterator<V>>::type cbegin(
const V &v)
184 template<
typename V> constexpr
typename std::enable_if<Traits::is_simd_mask<V>::value || Traits::is_simd_vector<V>::value, ConstIterator<V>>::type cend(
const V &v)
186 return { v, V::Size };
189 template<
typename M> Vc_ALWAYS_INLINE BitmaskIterator begin(
const WhereImpl::WhereMask<M> &w)
191 return w.mask.toInt();
194 template<
typename M> Vc_ALWAYS_INLINE BitmaskIterator end(
const WhereImpl::WhereMask<M> &)
199 template<
typename V,
typename Flags,
typename T> Vc_ALWAYS_INLINE MemoryVectorIterator<V, Flags>
200 makeIterator(T *mem, Flags)
202 return new(mem) MemoryVector<V, Flags>;
205 template<
typename V,
typename Flags,
typename T> Vc_ALWAYS_INLINE MemoryVectorIterator<const V, Flags>
206 makeIterator(
const T *mem, Flags)
208 return new(
const_cast<T *
>(mem)) MemoryVector<const V, Flags>;
211 template<
typename V,
typename Flags,
typename FlagsX> Vc_ALWAYS_INLINE MemoryVectorIterator<V, Flags>
212 makeIterator(MemoryVector<V, FlagsX> &mv, Flags)
214 return new(&mv) MemoryVector<V, Flags>;
217 template<
typename V,
typename Flags,
typename FlagsX> Vc_ALWAYS_INLINE MemoryVectorIterator<const V, Flags>
218 makeIterator(MemoryVector<const V, FlagsX> &mv, Flags)
220 return new(&mv) MemoryVector<const V, Flags>;
227 using Common::makeIterator;
230 #endif // VC_COMMON_ITERATORS_H_
Helper class for the Memory::vector(size_t) class of functions.