Vc  1.0.0-dev
SIMD Vector Classes for C++
vector.h
1 /* This file is part of the Vc library. {{{
2 Copyright © 2009-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_VECTOR_H_
30 #define VC_VECTOR_H_
31 
32 // 1. define all of Vc::Scalar - this one is always present, so it makes sense to put it first
33 #include "scalar/vector.h"
34 
35 #ifdef Vc_IMPL_AVX
36 # include "avx/vector.h"
37 #elif defined(Vc_IMPL_SSE)
38 # include "sse/vector.h"
39 #endif
40 
41 #if defined(Vc_IMPL_MIC)
42 # include "mic/vector.h"
43 #endif
44 
45 namespace Vc_VERSIONED_NAMESPACE
46 {
51 
55 using double_v = Vector<double>;
68 using llong_v = Vector<llong>;
70 using ullong_v = Vector<ullong>;
72 using long_v = Vector<long>;
74 using ulong_v = Vector<ulong>;
76 using schar_v = Vector<schar>;
78 using uchar_v = Vector<uchar>;
81 
86 
90 using double_m = Mask<double>;
95 using llong_m = Mask< llong>;
97 using ullong_m = Mask<ullong>;
99 using long_m = Mask< long>;
101 using ulong_m = Mask< ulong>;
111 using schar_m = Mask< schar>;
113 using uchar_m = Mask< uchar>;
116 
125 
134 
143 
152 
153 #if defined INT64_MAX && defined UINT64_MAX
154  typedef Vector<std:: int64_t> int64_v;
155  typedef Vector<std::uint64_t> uint64_v;
156  typedef Mask<std:: int64_t> int64_m;
157  typedef Mask<std::uint64_t> uint64_m;
158 #endif
159 #if defined INT32_MAX && defined UINT32_MAX
160  typedef Vector<std:: int32_t> int32_v;
161  typedef Vector<std::uint32_t> uint32_v;
162  typedef Mask<std:: int32_t> int32_m;
163  typedef Mask<std::uint32_t> uint32_m;
164 #endif
165 #if defined INT16_MAX && defined UINT16_MAX
166  typedef Vector<std:: int16_t> int16_v;
167  typedef Vector<std::uint16_t> uint16_v;
168  typedef Mask<std:: int16_t> int16_m;
169  typedef Mask<std::uint16_t> uint16_m;
170 #endif
171 #if defined INT8_MAX && defined UINT8_MAX
172  typedef Vector<std:: int8_t> int8_v;
173  typedef Vector<std::uint8_t> uint8_v;
174  typedef Mask<std:: int8_t> int8_m;
175  typedef Mask<std::uint8_t> uint8_m;
176 #endif
177 
178  namespace {
179  static_assert(double_v::Size == Vc_DOUBLE_V_SIZE, "Vc_DOUBLE_V_SIZE macro defined to an incorrect value");
180  static_assert(float_v::Size == Vc_FLOAT_V_SIZE , "Vc_FLOAT_V_SIZE macro defined to an incorrect value ");
181  static_assert(int_v::Size == Vc_INT_V_SIZE , "Vc_INT_V_SIZE macro defined to an incorrect value ");
182  static_assert(uint_v::Size == Vc_UINT_V_SIZE , "Vc_UINT_V_SIZE macro defined to an incorrect value ");
183  static_assert(short_v::Size == Vc_SHORT_V_SIZE , "Vc_SHORT_V_SIZE macro defined to an incorrect value ");
184  static_assert(ushort_v::Size == Vc_USHORT_V_SIZE, "Vc_USHORT_V_SIZE macro defined to an incorrect value");
185  }
186 }
187 
188 
189 // finally define the non-member operators
190 #include "common/operators.h"
191 
192 #include "common/simdarray.h"
193 // XXX See bottom of common/simdmaskarray.h:
194 //#include "common/simd_cast_caller.tcc"
195 
196 #include "common/alignedbase.h"
197 namespace Vc_VERSIONED_NAMESPACE {
208 constexpr std::size_t VectorAlignment = alignof(VectorAlignedBase);
219 constexpr std::size_t MemoryAlignment = alignof(MemoryAlignedBase);
220 } // namespace Vc_VERSIONED_NAMESPACE
221 
222 #define Vc_VECTOR_DECLARED__ 1
223 
224 #include "scalar/helperimpl.h"
225 #include "scalar/math.h"
226 #include "scalar/simd_cast_caller.tcc"
227 #if defined(Vc_IMPL_SSE)
228 # include "sse/helperimpl.h"
229 # include "sse/math.h"
230 # include "sse/simd_cast_caller.tcc"
231 #endif
232 #if defined(Vc_IMPL_AVX)
233 # include "avx/helperimpl.h"
234 # include "avx/math.h"
235 # include "avx/simd_cast_caller.tcc"
236 #endif
237 #if defined(Vc_IMPL_MIC)
238 # include "mic/helperimpl.h"
239 # include "mic/math.h"
240 # include "mic/simd_cast_caller.tcc"
241 #endif
242 
243 #include "common/math.h"
244 
245 #ifdef isfinite
246 #undef isfinite
247 #endif
248 #ifdef isnan
249 #undef isnan
250 #endif
251 
252 #include "common/vectortuple.h"
253 #include "common/algorithms.h"
254 #include "common/where.h"
255 #include "common/iif.h"
256 
257 #ifndef Vc_NO_STD_FUNCTIONS
258 namespace std
259 {
260  using Vc::min;
261  using Vc::max;
262 
263  using Vc::abs;
264  using Vc::asin;
265  using Vc::atan;
266  using Vc::atan2;
267  using Vc::ceil;
268  using Vc::cos;
269  using Vc::exp;
270  using Vc::fma;
271  using Vc::trunc;
272  using Vc::floor;
273  using Vc::frexp;
274  using Vc::ldexp;
275  using Vc::log;
276  using Vc::log10;
277  using Vc::log2;
278  using Vc::round;
279  using Vc::sin;
280  using Vc::sqrt;
281 
282  using Vc::isfinite;
283  using Vc::isnan;
284 } // namespace std
285 #endif
286 
287 #endif // VC_VECTOR_H_
Vc::Vector< T > frexp(const Vc::Vector< T > &x, Vc::SimdArray< int, size()> *e)
Convert floating-point number to fractional and integral components.
Vc::Vector< T > log2(const Vc::Vector< T > &v)
Vc::Vector< T > exp(const Vc::Vector< T > &v)
The main vector class for expressing data parallelism.
Definition: types.h:45
Vc::Vector< T > sin(const Vc::Vector< T > &v)
Vc::Vector< T > cos(const Vc::Vector< T > &v)
#define Vc_UINT_V_SIZE
An integer (for use with the preprocessor) that gives the number of entries in a uint_v.
Definition: dox.h:649
Vc::Vector< T > min(const Vc::Vector< T > &x, const Vc::Vector< T > &y)
Vc::Vector< T > ldexp(Vc::Vector< T > x, Vc::SimdArray< int, size()> e)
Multiply floating-point number by integral power of 2.
constexpr std::size_t VectorAlignment
Specifies the most conservative memory alignment necessary for Vector objects with default VectorA...
Definition: vector.h:208
#define Vc_SHORT_V_SIZE
An integer (for use with the preprocessor) that gives the number of entries in a short_v.
Definition: dox.h:654
Vc::Vector< T > abs(const Vc::Vector< T > &v)
Returns the absolute value of v.
Vc::Vector< T > max(const Vc::Vector< T > &x, const Vc::Vector< T > &y)
Definition: vector.h:258
Vc::Vector< T > log(const Vc::Vector< T > &v)
AlignedBase< Detail::max(alignof(Vector< float >), alignof(Vector< double >), alignof(Vector< ullong >), alignof(Vector< llong >), alignof(Vector< ulong >), alignof(Vector< long >), alignof(Vector< uint >), alignof(Vector< int >), alignof(Vector< ushort >), alignof(Vector< short >), alignof(Vector< uchar >), alignof(Vector< schar >))> VectorAlignedBase
Helper type to ensure suitable alignment for any Vc::Vector type (using the default VectorAbi)...
Definition: alignedbase.h:91
Vc::Vector< T > fma(Vc::Vector< T > a, Vc::Vector< T > b, Vc::Vector< T > c)
Multiplies a with b and then adds c, without rounding between the multiplication and the addition...
Vc::Vector< T > round(const Vc::Vector< T > &v)
Returns the closest integer to v; 0.5 is rounded to even.
#define Vc_USHORT_V_SIZE
An integer (for use with the preprocessor) that gives the number of entries in a ushort_v.
Definition: dox.h:659
Vc::Vector< T > log10(const Vc::Vector< T > &v)
Vector< double > double_v
vector of double precision
Definition: vector.h:56
#define Vc_DOUBLE_V_SIZE
An integer (for use with the preprocessor) that gives the number of entries in a double_v.
Definition: dox.h:634
#define Vc_FLOAT_V_SIZE
An integer (for use with the preprocessor) that gives the number of entries in a float_v.
Definition: dox.h:639
Vc::Vector< T > atan2(const Vc::Vector< T > &y, const Vc::Vector< T > &x)
Calculates the angle given the lengths of the opposite and adjacent legs in a right triangle...
Vc::Vector< T > atan(const Vc::Vector< T > &v)
Vc::Vector< T > asin(const Vc::Vector< T > &v)
Vc::Mask< T > isfinite(const Vc::Vector< T > &x)
The main SIMD mask class.
Definition: mask.h:42
Vc::Mask< T > isnan(const Vc::Vector< T > &x)
#define Vc_INT_V_SIZE
An integer (for use with the preprocessor) that gives the number of entries in a int_v.
Definition: dox.h:644
constexpr std::size_t MemoryAlignment
Specifies the most conservative memory alignment necessary for aligned loads and stores of Vector typ...
Definition: vector.h:219
Vc::Vector< T > sqrt(const Vc::Vector< T > &v)
Returns the square root of v.
AlignedBase< Detail::max(Vector< float >::MemoryAlignment, Vector< double >::MemoryAlignment, Vector< ullong >::MemoryAlignment, Vector< llong >::MemoryAlignment, Vector< ulong >::MemoryAlignment, Vector< long >::MemoryAlignment, Vector< uint >::MemoryAlignment, Vector< int >::MemoryAlignment, Vector< ushort >::MemoryAlignment, Vector< short >::MemoryAlignment, Vector< uchar >::MemoryAlignment, Vector< schar >::MemoryAlignment)> MemoryAlignedBase
Helper class to ensure suitable alignment for arrays of scalar objects for any Vc::Vector type (us...
Definition: alignedbase.h:123