Vc  1.0.0-dev
SIMD Vector Classes for C++
mask.h
1 /* This file is part of the Vc library. {{{
2 Copyright © 2015 Matthias Kretz <kretz@kde.org>
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the names of contributing organizations nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 }}}*/
28 
29 #ifndef VC_COMMON_MASK_H_
30 #define VC_COMMON_MASK_H_
31 
32 #include "macros.h"
33 
34 namespace Vc_VERSIONED_NAMESPACE
35 {
42 template <typename T, typename Abi = VectorAbi::Best<T>> class Mask
43 {
44 public:
58  static constexpr size_t size() { return VectorTraits<T, Abi>::size(); }
61  static constexpr size_t Size = VectorTraits<T, Abi>::size();
62 
67  static constexpr size_t MemoryAlignment = VectorTraits<T, Abi>::maskMemoryAlignment();
68 
70  using abi = Abi;
71 
75  using EntryType = bool;
78 
80  using EntryReference = typename VectorTraits<T, Abi>::EntryReference;
83 
89  using VectorEntryType = typename VectorTraits<T, Abi>::VectorEntryType;
90 
94  using VectorType = typename VectorTraits<T, Abi>::VectorType;
98  using vector_type = VectorType;
99 
100  /*
101  * The associated Vector<T> type.
102  */
103  //using Vector = Vector<T, Abi>;
104 
107 
112  Vc_INTRINSIC static Mask Zero();
113 
119  Vc_INTRINSIC static Mask One();
120 
122  template <typename G> static Vc_INTRINSIC Mask generate(G &&gen);
124 
127 
136  Vc_INTRINSIC Mask() = default;
137 
140  Vc_INTRINSIC explicit Mask(VectorSpecialInitializerZero);
141 
144  Vc_INTRINSIC explicit Mask(VectorSpecialInitializerOne);
146 
149 
156  Vc_INTRINSIC explicit Mask(bool b);
157 
164  template <typename U>
165  Vc_INTRINSIC Mask(U &&otherMask,
166  Common::enable_if_mask_converts_implicitly<T, U> = nullarg);
167 
176  template <typename U>
177  Vc_INTRINSIC_L explicit Mask(
178  U &&otherMask,
179  Common::enable_if_mask_converts_explicitly<T, U> = nullarg) Vc_INTRINSIC_R;
181 
185 
195  Vc_ALWAYS_INLINE explicit Mask(const bool *mem);
204  template <typename Flags> Vc_ALWAYS_INLINE explicit Mask(const bool *mem, Flags flags);
205 
212  Vc_ALWAYS_INLINE void load(const bool *mem);
221  template <typename Flags> Vc_ALWAYS_INLINE void load(const bool *mem, Flags flags);
222 
229  Vc_ALWAYS_INLINE void store(bool *mem) const;
237  template <typename Flags> Vc_ALWAYS_INLINE void store(bool *mem, Flags flags) const;
239 
242 
255  Vc_ALWAYS_INLINE bool operator==(const Mask &mask) const;
256 
266  Vc_ALWAYS_INLINE bool operator!=(const Mask &mask) const;
268 
277 
280  Vc_ALWAYS_INLINE Mask operator&&(const Mask &mask) const;
282  Vc_ALWAYS_INLINE Mask operator&(const Mask &mask) const;
284  Vc_ALWAYS_INLINE Mask operator||(const Mask &mask) const;
286  Vc_ALWAYS_INLINE Mask operator|(const Mask &mask) const;
288  Vc_ALWAYS_INLINE Mask operator^(const Mask &mask) const;
290  Vc_ALWAYS_INLINE Mask operator!() const;
291 
293  Vc_ALWAYS_INLINE Mask &operator&=(const Mask &mask);
295  Vc_ALWAYS_INLINE Mask &operator|=(const Mask &mask);
297  Vc_ALWAYS_INLINE Mask &operator^=(const Mask &mask);
299 
305 
308  Vc_ALWAYS_INLINE bool isFull() const;
310  Vc_ALWAYS_INLINE bool isNotEmpty() const;
312  Vc_ALWAYS_INLINE bool isEmpty() const;
314  Vc_ALWAYS_INLINE bool isMix() const;
316 
320  Vc_ALWAYS_INLINE bool data() const;
322  Vc_ALWAYS_INLINE bool dataI() const;
323  Vc_ALWAYS_INLINE bool dataD() const;
325 
328 
338  Vc_ALWAYS_INLINE EntryReference operator[](size_t index);
339 
349  Vc_ALWAYS_INLINE EntryType operator[](size_t index) const;
351 
353  Vc_ALWAYS_INLINE int count() const;
354 
365  Vc_ALWAYS_INLINE int firstOne() const;
366 
374  Vc_ALWAYS_INLINE int toInt() const;
375 
377  Vc_INTRINSIC Vc_PURE Mask shifted(int amount) const;
378 
380  void setEntry(size_t, bool x);
381 
382 private:
383  VectorType d;
384 };
385 
386 } // namespace Vc
387 
388 #endif // VC_COMMON_MASK_H_
389 
390 // vim: foldmethod=marker
typename VectorTraits< T, Abi >::EntryReference EntryReference
The reference wrapper type used for accessing individual mask components.
Definition: mask.h:80
bool EntryType
The EntryType of masks is always bool, independent of T.
Definition: mask.h:75
static constexpr size_t size()
Returns the number of boolean components ( ) in a mask of this type.
Definition: mask.h:58
Abi abi
The ABI tag type of the current template instantiation.
Definition: mask.h:70
EntryType value_type
The EntryType of masks is always bool, independent of T.
Definition: mask.h:77
typename VectorTraits< T, Abi >::VectorEntryType VectorEntryType
The VectorEntryType, in contrast to EntryType, reveals information about the SIMD implementation...
Definition: mask.h:89
EntryReference value_reference
The reference wrapper type used for accessing individual mask components.
Definition: mask.h:82
The main SIMD mask class.
Definition: mask.h:42
constexpr VectorSpecialInitializerZero Zero
The special object Vc::Zero can be used to construct Vector and Mask objects initialized to zero/fals...
Definition: types.h:85
Adapter< S, T, N > shifted(const Adapter< S, T, N > &a, int shift)
Returns a new vectorized object where each entry is shifted by shift.
Definition: simdize.h:1002
constexpr VectorSpecialInitializerOne One
The special object Vc::One can be used to construct Vector and Mask objects initialized to one/true...
Definition: types.h:90
constexpr std::size_t MemoryAlignment
Specifies the most conservative memory alignment necessary for aligned loads and stores of Vector typ...
Definition: vector.h:219