Vc  1.3.2-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 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright
7  notice, this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright
9  notice, this list of conditions and the following disclaimer in the
10  documentation and/or other materials provided with the distribution.
11  * Neither the names of contributing organizations nor the
12  names of its contributors may be used to endorse or promote products
13  derived from this software without specific prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 }}}*/
27 
28 #ifndef VC_COMMON_MASK_H_
29 #define VC_COMMON_MASK_H_
30 
31 #include "macros.h"
32 
33 namespace Vc_VERSIONED_NAMESPACE
34 {
41 template <typename T, typename Abi = VectorAbi::Best<T>> class Mask
42 {
43 public:
57  static constexpr size_t size() { return VectorTraits<T, Abi>::size(); }
60  static constexpr size_t Size = VectorTraits<T, Abi>::size();
61 
66  static constexpr size_t MemoryAlignment = VectorTraits<T, Abi>::maskMemoryAlignment();
67 
69  using abi = Abi;
70 
74  using EntryType = bool;
77 
79  using EntryReference = typename VectorTraits<T, Abi>::EntryReference;
82 
88  using VectorEntryType = typename VectorTraits<T, Abi>::VectorEntryType;
89 
93  using VectorType = typename VectorTraits<T, Abi>::VectorType;
97  using vector_type = VectorType;
98 
99  /*
100  * The associated Vector<T> type.
101  */
102  //using Vector = Vector<T, Abi>;
103 
106 
111  Vc_INTRINSIC static Mask Zero();
112 
118  Vc_INTRINSIC static Mask One();
119 
121  template <typename G> static Vc_INTRINSIC Mask generate(G &&gen);
123 
126 
135  Vc_INTRINSIC Mask() = default;
136 
139  Vc_INTRINSIC explicit Mask(VectorSpecialInitializerZero);
140 
143  Vc_INTRINSIC explicit Mask(VectorSpecialInitializerOne);
145 
148 
155  Vc_INTRINSIC explicit Mask(bool b);
156 
163  template <typename U>
164  Vc_INTRINSIC Mask(U &&otherMask,
165  Common::enable_if_mask_converts_implicitly<T, U> = nullarg);
166 
167 #if Vc_IS_VERSION_1
168 
176  template <typename U>
177  Vc_DEPRECATED(
178  "use simd_cast instead of explicit type casting to convert between mask types")
179  Vc_INTRINSIC_L
180  explicit Mask(U &&otherMask, Common::enable_if_mask_converts_explicitly<T, U> =
181  nullarg) Vc_INTRINSIC_R;
183 #endif
184 
188 
198  Vc_ALWAYS_INLINE explicit Mask(const bool *mem);
207  template <typename Flags> Vc_ALWAYS_INLINE explicit Mask(const bool *mem, Flags flags);
208 
215  Vc_ALWAYS_INLINE void load(const bool *mem);
224  template <typename Flags> Vc_ALWAYS_INLINE void load(const bool *mem, Flags flags);
225 
232  Vc_ALWAYS_INLINE void store(bool *mem) const;
240  template <typename Flags> Vc_ALWAYS_INLINE void store(bool *mem, Flags flags) const;
242 
245 
258  Vc_ALWAYS_INLINE bool operator==(const Mask &mask) const;
259 
269  Vc_ALWAYS_INLINE bool operator!=(const Mask &mask) const;
271 
280 
283  Vc_ALWAYS_INLINE Mask operator&&(const Mask &mask) const;
285  Vc_ALWAYS_INLINE Mask operator&(const Mask &mask) const;
287  Vc_ALWAYS_INLINE Mask operator||(const Mask &mask) const;
289  Vc_ALWAYS_INLINE Mask operator|(const Mask &mask) const;
291  Vc_ALWAYS_INLINE Mask operator^(const Mask &mask) const;
293  Vc_ALWAYS_INLINE Mask operator!() const;
294 
296  Vc_ALWAYS_INLINE Mask &operator&=(const Mask &mask);
298  Vc_ALWAYS_INLINE Mask &operator|=(const Mask &mask);
300  Vc_ALWAYS_INLINE Mask &operator^=(const Mask &mask);
302 
308 
311  Vc_ALWAYS_INLINE bool isFull() const;
313  Vc_ALWAYS_INLINE bool isNotEmpty() const;
315  Vc_ALWAYS_INLINE bool isEmpty() const;
317  Vc_ALWAYS_INLINE bool isMix() const;
319 
323  Vc_ALWAYS_INLINE bool data() const;
325  Vc_ALWAYS_INLINE bool dataI() const;
326  Vc_ALWAYS_INLINE bool dataD() const;
328 
331 
341  Vc_ALWAYS_INLINE EntryReference operator[](size_t index);
342 
352  Vc_ALWAYS_INLINE EntryType operator[](size_t index) const;
354 
356  Vc_ALWAYS_INLINE int count() const;
357 
368  Vc_ALWAYS_INLINE int firstOne() const;
369 
377  Vc_ALWAYS_INLINE int toInt() const;
378 
380  Vc_INTRINSIC Vc_PURE Mask shifted(int amount) const;
381 
382  Vc_FREE_STORE_OPERATORS_ALIGNED(alignof(Mask));
383 
384 private:
385  VectorType d;
386 };
387 
388 } // namespace Vc
389 
390 #endif // VC_COMMON_MASK_H_
391 
392 // vim: foldmethod=marker
typename VectorTraits< T, Abi >::EntryReference EntryReference
The reference wrapper type used for accessing individual mask components.
Definition: mask.h:79
bool EntryType
The EntryType of masks is always bool, independent of T.
Definition: mask.h:74
result_vector_type< L, R > operator|(L &&lhs, R &&rhs)
Applies | component-wise and concurrently.
Definition: simdarray.h:1612
result_vector_type< L, R > operator^(L &&lhs, R &&rhs)
Applies ^ component-wise and concurrently.
Definition: simdarray.h:1612
static constexpr size_t size()
Returns the number of boolean components ( ) in a mask of this type.
Definition: mask.h:57
result_vector_type< L, R >::mask_type operator!=(L &&lhs, R &&rhs)
Applies != component-wise and concurrently.
Definition: simdarray.h:1642
Abi abi
The ABI tag type of the current template instantiation.
Definition: mask.h:69
EntryType value_type
The EntryType of masks is always bool, independent of T.
Definition: mask.h:76
result_vector_type< L, R >::mask_type operator==(L &&lhs, R &&rhs)
Applies == component-wise and concurrently.
Definition: simdarray.h:1642
typename VectorTraits< T, Abi >::VectorEntryType VectorEntryType
The VectorEntryType, in contrast to EntryType, reveals information about the SIMD implementation...
Definition: mask.h:88
EntryReference value_reference
The reference wrapper type used for accessing individual mask components.
Definition: mask.h:81
result_vector_type< L, R > operator&(L &&lhs, R &&rhs)
Applies & component-wise and concurrently.
Definition: simdarray.h:1612
The main SIMD mask class.
Definition: mask.h:41
constexpr VectorSpecialInitializerZero Zero
The special object Vc::Zero can be used to construct Vector and Mask objects initialized to zero/fals...
Definition: types.h:84
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:1069
constexpr VectorSpecialInitializerOne One
The special object Vc::One can be used to construct Vector and Mask objects initialized to one/true...
Definition: types.h:89
constexpr std::size_t MemoryAlignment
Specifies the most conservative memory alignment necessary for aligned loads and stores of Vector typ...
Definition: vector.h:218