Vc 1.4.5
SIMD Vector Classes for C++
 
Loading...
Searching...
No Matches
vector.h
1/* This file is part of the Vc library. {{{
2Copyright © 2009-2015 Matthias Kretz <kretz@kde.org>
3
4Redistribution and use in source and binary forms, with or without
5modification, 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
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22ON 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
24SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26}}}*/
27
28#ifndef VC_VECTOR_H_
29#define VC_VECTOR_H_
30
31// 1. define all of Vc::Scalar - this one is always present, so it makes sense to put it first
32#include "scalar/vector.h"
33
34#if defined(Vc_IMPL_SSE)
35# include "sse/vector.h"
36#endif
37#ifdef Vc_IMPL_AVX
38# include "avx/vector.h"
39#endif
40
41namespace Vc_VERSIONED_NAMESPACE
42{
48
64using llong_v = Vector<llong>;
66using ullong_v = Vector<ullong>;
68using long_v = Vector<long>;
70using ulong_v = Vector<ulong>;
72using schar_v = Vector<schar>;
74using uchar_v = Vector<uchar>;
77
83
91using llong_m = Mask< llong>;
93using ullong_m = Mask<ullong>;
95using long_m = Mask< long>;
97using ulong_m = Mask< ulong>;
107using schar_m = Mask< schar>;
109using uchar_m = Mask< uchar>;
112
113 typedef Vector<std:: int_least64_t> int_least64_v;
114 typedef Vector<std::uint_least64_t> uint_least64_v;
115 typedef Vector<std:: int_least32_t> int_least32_v;
116 typedef Vector<std::uint_least32_t> uint_least32_v;
117 typedef Vector<std:: int_least16_t> int_least16_v;
118 typedef Vector<std::uint_least16_t> uint_least16_v;
119 typedef Vector<std:: int_least8_t> int_least8_v;
120 typedef Vector<std:: uint_least8_t> uint_least8_v;
121
122 typedef Mask<std:: int_least64_t> int_least64_m;
123 typedef Mask<std::uint_least64_t> uint_least64_m;
124 typedef Mask<std:: int_least32_t> int_least32_m;
125 typedef Mask<std::uint_least32_t> uint_least32_m;
126 typedef Mask<std:: int_least16_t> int_least16_m;
127 typedef Mask<std::uint_least16_t> uint_least16_m;
128 typedef Mask<std:: int_least8_t> int_least8_m;
129 typedef Mask<std:: uint_least8_t> uint_least8_m;
130
131 typedef Vector<std:: int_fast64_t> int_fast64_v;
132 typedef Vector<std::uint_fast64_t> uint_fast64_v;
133 typedef Vector<std:: int_fast32_t> int_fast32_v;
134 typedef Vector<std::uint_fast32_t> uint_fast32_v;
135 typedef Vector<std:: int_fast16_t> int_fast16_v;
136 typedef Vector<std::uint_fast16_t> uint_fast16_v;
137 typedef Vector<std:: int_fast8_t> int_fast8_v;
138 typedef Vector<std:: uint_fast8_t> uint_fast8_v;
139
140 typedef Mask<std:: int_fast64_t> int_fast64_m;
141 typedef Mask<std::uint_fast64_t> uint_fast64_m;
142 typedef Mask<std:: int_fast32_t> int_fast32_m;
143 typedef Mask<std::uint_fast32_t> uint_fast32_m;
144 typedef Mask<std:: int_fast16_t> int_fast16_m;
145 typedef Mask<std::uint_fast16_t> uint_fast16_m;
146 typedef Mask<std:: int_fast8_t> int_fast8_m;
147 typedef Mask<std:: uint_fast8_t> uint_fast8_m;
148
149#if defined INT64_MAX && defined UINT64_MAX
150 typedef Vector<std:: int64_t> int64_v;
151 typedef Vector<std::uint64_t> uint64_v;
152 typedef Mask<std:: int64_t> int64_m;
153 typedef Mask<std::uint64_t> uint64_m;
154#endif
155#if defined INT32_MAX && defined UINT32_MAX
156 typedef Vector<std:: int32_t> int32_v;
157 typedef Vector<std::uint32_t> uint32_v;
158 typedef Mask<std:: int32_t> int32_m;
159 typedef Mask<std::uint32_t> uint32_m;
160#endif
161#if defined INT16_MAX && defined UINT16_MAX
162 typedef Vector<std:: int16_t> int16_v;
163 typedef Vector<std::uint16_t> uint16_v;
164 typedef Mask<std:: int16_t> int16_m;
165 typedef Mask<std::uint16_t> uint16_m;
166#endif
167#if defined INT8_MAX && defined UINT8_MAX
168 typedef Vector<std:: int8_t> int8_v;
169 typedef Vector<std::uint8_t> uint8_v;
170 typedef Mask<std:: int8_t> int8_m;
171 typedef Mask<std::uint8_t> uint8_m;
172#endif
173
174 namespace {
175 static_assert(double_v::Size == Vc_DOUBLE_V_SIZE, "Vc_DOUBLE_V_SIZE macro defined to an incorrect value");
176 static_assert(float_v::Size == Vc_FLOAT_V_SIZE , "Vc_FLOAT_V_SIZE macro defined to an incorrect value ");
177 static_assert(int_v::Size == Vc_INT_V_SIZE , "Vc_INT_V_SIZE macro defined to an incorrect value ");
178 static_assert(uint_v::Size == Vc_UINT_V_SIZE , "Vc_UINT_V_SIZE macro defined to an incorrect value ");
179 static_assert(short_v::Size == Vc_SHORT_V_SIZE , "Vc_SHORT_V_SIZE macro defined to an incorrect value ");
180 static_assert(ushort_v::Size == Vc_USHORT_V_SIZE, "Vc_USHORT_V_SIZE macro defined to an incorrect value");
181 }
182}
183
184
185// finally define the non-member operators
186#include "common/operators.h"
187
188#include "common/simdarray.h"
189// XXX See bottom of common/simdmaskarray.h:
190//#include "common/simd_cast_caller.tcc"
191
192#include "common/alignedbase.h"
193namespace Vc_VERSIONED_NAMESPACE {
204constexpr std::size_t VectorAlignment = alignof(VectorAlignedBase);
215constexpr std::size_t MemoryAlignment = alignof(MemoryAlignedBase);
216} // namespace Vc_VERSIONED_NAMESPACE
217
218#define Vc_VECTOR_DECLARED_ 1
219
220#include "scalar/helperimpl.h"
221#include "scalar/math.h"
222#include "scalar/simd_cast_caller.tcc"
223#if defined(Vc_IMPL_SSE)
224# include "sse/helperimpl.h"
225# include "sse/math.h"
226# include "sse/simd_cast_caller.tcc"
227#endif
228#if defined(Vc_IMPL_AVX)
229# include "avx/helperimpl.h"
230# include "avx/math.h"
231# include "avx/simd_cast_caller.tcc"
232#endif
233
234#include "common/math.h"
235
236#ifdef isfinite
237#undef isfinite
238#endif
239#ifdef isnan
240#undef isnan
241#endif
242
243#include "common/vectortuple.h"
244#include "common/where.h"
245#include "common/iif.h"
246
247#ifndef Vc_NO_STD_FUNCTIONS
248namespace std
249{
250 using Vc::min;
251 using Vc::max;
252
253 using Vc::abs;
254 using Vc::asin;
255 using Vc::atan;
256 using Vc::atan2;
257 using Vc::ceil;
258 using Vc::cos;
259 using Vc::exp;
260 using Vc::fma;
261 using Vc::trunc;
262 using Vc::floor;
263 using Vc::frexp;
264 using Vc::ldexp;
265 using Vc::log;
266 using Vc::log10;
267 using Vc::log2;
268 using Vc::round;
269 using Vc::sin;
270 using Vc::sqrt;
271
272 using Vc::isfinite;
273 using Vc::isnan;
274} // namespace std
275#endif
276
277Vc_RESET_DIAGNOSTICS
278
279#endif // VC_VECTOR_H_
The main SIMD mask class.
Definition mask.h:42
The main vector class for expressing data parallelism.
Definition vector.h:126
static constexpr size_t Size
Definition vector.h:772
Mask< short > short_m
mask type for short_v vectors
Definition vector.h:103
Mask< int > int_m
mask type for int_v vectors
Definition vector.h:99
Mask< double > double_m
mask type for double_v vectors
Definition vector.h:87
Mask< uint > uint_m
mask type for uint_v vectors
Definition vector.h:101
Mask< float > float_m
mask type for float_v vectors
Definition vector.h:89
Mask< ushort > ushort_m
mask type for ushort_v vectors
Definition vector.h:105
Vc::Vector< T > ldexp(Vc::Vector< T > x, Vc::SimdArray< int, size()> e)
Multiply floating-point number by integral power of 2.
Vc::Vector< T > max(const Vc::Vector< T > &x, const Vc::Vector< T > &y)
Vc::Vector< T > log(const Vc::Vector< T > &v)
Vc::Vector< T > log2(const Vc::Vector< T > &v)
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 > 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 > abs(const Vc::Vector< T > &v)
Returns the absolute value of v.
Vc::Vector< T > exp(const Vc::Vector< T > &v)
Vc::Vector< T > log10(const Vc::Vector< T > &v)
Vc::Vector< T > sqrt(const Vc::Vector< T > &v)
Returns the square root of v.
Vc::Mask< T > isnan(const Vc::Vector< T > &x)
Vc::Vector< T > min(const Vc::Vector< T > &x, const Vc::Vector< T > &y)
Vc::Vector< T > round(const Vc::Vector< T > &v)
Returns the closest integer to v; 0.5 is rounded to even.
Vc::Mask< T > isfinite(const Vc::Vector< T > &x)
fixed_size_simd< T, N > atan2(const SimdArray< T, N, V, M > &x, const SimdArray< T, N, V, M > &y)
Applies the std::atan2 function component-wise and concurrently.
Definition simdarray.h:1809
fixed_size_simd< T, N > trunc(const SimdArray< T, N, V, M > &x)
Applies the std::trunc function component-wise and concurrently.
Definition simdarray.h:1853
fixed_size_simd< T, N > ceil(const SimdArray< T, N, V, M > &x)
Applies the std::ceil function component-wise and concurrently.
Definition simdarray.h:1810
fixed_size_simd< T, N > sin(const SimdArray< T, N, V, M > &x)
Applies the std::sin function component-wise and concurrently.
Definition simdarray.h:1845
fixed_size_simd< T, N > cos(const SimdArray< T, N, V, M > &x)
Applies the std::cos function component-wise and concurrently.
Definition simdarray.h:1812
fixed_size_simd< T, N > atan(const SimdArray< T, N, V, M > &x)
Applies the std::atan function component-wise and concurrently.
Definition simdarray.h:1808
fixed_size_simd< T, N > floor(const SimdArray< T, N, V, M > &x)
Applies the std::floor function component-wise and concurrently.
Definition simdarray.h:1815
fixed_size_simd< T, N > asin(const SimdArray< T, N, V, M > &x)
Applies the std::asin function component-wise and concurrently.
Definition simdarray.h:1807
#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:697
#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:677
#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:682
#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:687
#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:702
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<T> type (us...
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<T> type (using the default VectorAbi).
Definition alignedbase.h:86
#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:692
Vector< ushort > ushort_v
vector of unsigned short integers
Definition vector.h:62
Vector< double > double_v
vector of double precision
Definition vector.h:52
Vector< short > short_v
vector of signed short integers
Definition vector.h:60
Vector< float > float_v
vector of single precision
Definition vector.h:54
constexpr std::size_t MemoryAlignment
Specifies the most conservative memory alignment necessary for aligned loads and stores of Vector typ...
Definition vector.h:215
Vector< uint > uint_v
vector of unsigned integers
Definition vector.h:58
constexpr std::size_t VectorAlignment
Specifies the most conservative memory alignment necessary for Vector<T> objects with default VectorA...
Definition vector.h:204
Vector< int > int_v
vector of signed integers
Definition vector.h:56