Vc  1.4.2
SIMD Vector Classes for C++
simdarrayfwd.h
1 /* This file is part of the Vc library. {{{
2 Copyright © 2014-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_SIMDARRAYFWD_H_
29 #define VC_COMMON_SIMDARRAYFWD_H_
30 
31 #include "../scalar/types.h"
32 #include "../sse/types.h"
33 #include "../avx/types.h"
34 
35 #include "utility.h"
36 #include "macros.h"
37 
38 namespace Vc_VERSIONED_NAMESPACE
39 {
40 // specialization of Vector for fixed_size<N> {{{
41 template <class T, int N>
42 class Vector<T, simd_abi::fixed_size<N>> : public SimdArray<T, N>
43 {
45 
46 public:
47  // overload copy to force argument passing via the stack. This makes the type more
48  // usable on ABI boundaries
49  Vc_INTRINSIC Vector(const Vector &x) : SimdArray<T, N>(x) {}
50  Vc_INTRINSIC Vector &operator=(const Vector &x)
51  {
52  SimdArray<T, N>::operator=(x);
53  return *this;
54  }
55  Vector() = default;
56 
57  using abi_type = simd_abi::fixed_size<N>;
58  using abi = abi_type;
59 
60  Vc_DEPRECATED("use Vector([](int n) { return n; }) instead of "
61  "Vector::IndexesFromZero()") static Vector IndexesFromZero()
62  {
63  return Vector([](size_t i) -> T { return i; });
64  }
65  Vc_DEPRECATED("use 0 instead of Vector::Zero()") static Vector Zero() { return 0; }
66  Vc_DEPRECATED("use 1 instead of Vector::One()") static Vector One() { return 1; }
67 };
68 
69 template <class T, int N>
70 class Mask<T, simd_abi::fixed_size<N>> : public SimdMaskArray<T, N>
71 {
73 
74 public:
75  // overload copy to force argument passing via the stack. This makes the type more
76  // usable on ABI boundaries
77  Vc_INTRINSIC Mask(const Mask &x) : SimdMaskArray<T, N>(x) {}
78  Vc_INTRINSIC Mask &operator=(const Mask &x)
79  {
80  SimdMaskArray<T, N>::operator=(x);
81  return *this;
82  }
83  Mask() = default;
84 
85  using abi_type = simd_abi::fixed_size<N>;
86  using abi = abi_type;
87 };
88 // }}}
89 
94 template <typename T, std::size_t N> struct SimdArrayTraits {
95  static constexpr std::size_t N0 = Common::left_size<N>();
96  static constexpr std::size_t N1 = Common::right_size<N>();
97 
98  using storage_type0 = fixed_size_simd<T, N0>;
99  using storage_type1 = fixed_size_simd<T, N1>;
100 };
101 
102 template <typename T, std::size_t N, typename VectorType, std::size_t VectorSize>
103 Vc_INTRINSIC_L typename SimdArrayTraits<T, N>::storage_type0 &internal_data0(
104  SimdArray<T, N, VectorType, VectorSize> &x) Vc_INTRINSIC_R;
105 template <typename T, std::size_t N, typename VectorType, std::size_t VectorSize>
106 Vc_INTRINSIC_L typename SimdArrayTraits<T, N>::storage_type1 &internal_data1(
107  SimdArray<T, N, VectorType, VectorSize> &x) Vc_INTRINSIC_R;
108 template <typename T, std::size_t N, typename VectorType, std::size_t VectorSize>
109 Vc_INTRINSIC_L const typename SimdArrayTraits<T, N>::storage_type0 &internal_data0(
110  const SimdArray<T, N, VectorType, VectorSize> &x) Vc_INTRINSIC_R;
111 template <typename T, std::size_t N, typename VectorType, std::size_t VectorSize>
112 Vc_INTRINSIC_L const typename SimdArrayTraits<T, N>::storage_type1 &internal_data1(
113  const SimdArray<T, N, VectorType, VectorSize> &x) Vc_INTRINSIC_R;
114 
115 template <typename T, std::size_t N, typename V>
116 Vc_INTRINSIC_L V &internal_data(SimdArray<T, N, V, N> &x) Vc_INTRINSIC_R;
117 template <typename T, std::size_t N, typename V>
118 Vc_INTRINSIC_L const V &internal_data(const SimdArray<T, N, V, N> &x) Vc_INTRINSIC_R;
119 
120 namespace Traits
121 {
122 // is_fixed_size_simd {{{1
123 template <class T> struct is_fixed_size_simd : std::false_type {
124 };
125 template <class T, int N>
126 struct is_fixed_size_simd<fixed_size_simd<T, N>> : std::true_type {
127 };
128 template <class T, int N>
129 struct is_fixed_size_simd<fixed_size_simd_mask<T, N>> : std::true_type {
130 };
131 
132 // is_simd_vector_internal {{{1
133 template <class T, int N>
134 struct is_simd_vector_internal<fixed_size_simd<T, N>> : is_valid_vector_argument<T> {};
135 
136 // is_simd_mask_internal {{{1
137 template <class T, int N>
138 struct is_simd_mask_internal<fixed_size_simd_mask<T, N>> : is_valid_vector_argument<T> {};
139 
140 // is_atomic_simdarray_internal {{{1
141 template <typename T, std::size_t N, typename V>
142 struct is_atomic_simdarray_internal<SimdArray<T, N, V, N>> : is_valid_vector_argument<T> {};
143 template <typename T, int N>
144 struct is_atomic_simdarray_internal<fixed_size_simd<T, N>>
145  : is_atomic_simdarray_internal<SimdArray<T, N>> {
146 };
147 
148 // is_atomic_simd_mask_array_internal {{{1
149 template <typename T, std::size_t N, typename V>
150 struct is_atomic_simd_mask_array_internal<SimdMaskArray<T, N, V, N>>
151  : is_valid_vector_argument<T> {
152 };
153 template <typename T, int N>
154 struct is_atomic_simd_mask_array_internal<fixed_size_simd_mask<T, N>>
155  : is_atomic_simd_mask_array_internal<SimdMaskArray<T, N>> {
156 };
157 
158 // is_simdarray_internal {{{1
159 template <typename T, std::size_t N, typename VectorType, std::size_t M>
160 struct is_simdarray_internal<SimdArray<T, N, VectorType, M>>
161  : is_valid_vector_argument<T> {
162 };
163 template <typename T, int N>
164 struct is_simdarray_internal<fixed_size_simd<T, N>> : is_valid_vector_argument<T> {
165 };
166 
167 // is_simd_mask_array_internal {{{1
168 template <typename T, std::size_t N, typename VectorType, std::size_t M>
169 struct is_simd_mask_array_internal<SimdMaskArray<T, N, VectorType, M>>
170  : is_valid_vector_argument<T> {
171 };
172 template <typename T, int N>
173 struct is_simd_mask_array_internal<fixed_size_simd_mask<T, N>>
174  : is_valid_vector_argument<T> {
175 };
176 
177 // is_integral_internal {{{1
178 template <typename T, std::size_t N, typename V, std::size_t M>
179 struct is_integral_internal<SimdArray<T, N, V, M>, false> : std::is_integral<T> {
180 };
181 
182 // is_floating_point_internal {{{1
183 template <typename T, std::size_t N, typename V, std::size_t M>
184 struct is_floating_point_internal<SimdArray<T, N, V, M>, false>
185  : std::is_floating_point<T> {
186 };
187 
188 // is_signed_internal {{{1
189 template <typename T, std::size_t N, typename V, std::size_t M>
190 struct is_signed_internal<SimdArray<T, N, V, M>, false> : std::is_signed<T> {
191 };
192 
193 // is_unsigned_internal {{{1
194 template <typename T, std::size_t N, typename V, std::size_t M>
195 struct is_unsigned_internal<SimdArray<T, N, V, M>, false> : std::is_unsigned<T> {
196 };
197 
198 // has_no_allocated_data_impl {{{1
199 template <typename T, std::size_t N>
200 struct has_no_allocated_data_impl<Vc::SimdArray<T, N>> : std::true_type {
201 };
202 
203 // }}}1
204 } // namespace Traits
205 
206 } // namespace Vc
207 
208 #endif // VC_COMMON_SIMDARRAYFWD_H_
209 
210 // vim: foldmethod=marker
Vc::SimdArray< T, N >::SimdArray
SimdArray()=default
Vc::Zero
constexpr VectorSpecialInitializerZero Zero
The special object Vc::Zero can be used to construct Vector and Mask objects initialized to zero/fals...
Definition: types.h:81
Vc
Vector Classes Namespace.
Definition: dox.h:586
Vc::SimdMaskArray< T, N >::SimdMaskArray
SimdMaskArray()=default
Vc::One
constexpr VectorSpecialInitializerOne One
The special object Vc::One can be used to construct Vector and Mask objects initialized to one/true.
Definition: types.h:86
Vc::IndexesFromZero
constexpr VectorSpecialInitializerIndexesFromZero IndexesFromZero
The special object Vc::IndexesFromZero can be used to construct Vector objects initialized to values ...
Definition: types.h:91