1 /* This file is part of the Vc library.
3 Copyright (C) 2009-2011 Matthias Kretz <kretz@kde.org>
5 Vc is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation, either version 3 of
8 the License, or (at your option) any later version.
10 Vc is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with Vc. If not, see <http://www.gnu.org/licenses/>.
23 #include "intrinsics.h"
24 #include "../common/storage.h"
26 #define VC_DOUBLE_V_SIZE 2
27 #define VC_FLOAT_V_SIZE 4
28 #define VC_SFLOAT_V_SIZE 8
29 #define VC_INT_V_SIZE 4
30 #define VC_UINT_V_SIZE 4
31 #define VC_SHORT_V_SIZE 8
32 #define VC_USHORT_V_SIZE 8
34 #include "../common/types.h"
42 template<typename T> class Vector;
43 template<typename T> class WriteMaskedVector;
45 // define our own long because on Windows64 long == int while on Linux long == max. register width
46 // since we want to have a type that depends on 32 vs. 64 bit we need to do some special casing on Windows
48 typedef __int64 _long;
49 typedef unsigned __int64 _ulong;
52 typedef unsigned long _ulong;
57 class Float8GatherMask;
58 template<unsigned int VectorSize> class Mask;
61 * Hack to create a vector object with 8 floats
63 typedef Vc::sfloat float8;
67 //Vc_INTRINSIC M256() {}
68 //Vc_INTRINSIC M256(_M128 a, _M128 b) { d[0] = a; d[1] = b; }
69 static Vc_INTRINSIC Vc_CONST M256 dup(_M128 a) { M256 r; r.d[0] = a; r.d[1] = a; return r; }
70 static Vc_INTRINSIC Vc_CONST M256 create(_M128 a, _M128 b) { M256 r; r.d[0] = a; r.d[1] = b; return r; }
71 Vc_INTRINSIC _M128 &operator[](int i) { return d[i]; }
72 Vc_INTRINSIC const _M128 &operator[](int i) const { return d[i]; }
74 #ifdef VC_COMPILE_BENCHMARKS
79 #ifdef VC_CHECK_ALIGNMENT
80 static Vc_ALWAYS_INLINE void assertCorrectAlignment(const M256 *ptr)
82 const size_t s = sizeof(__m128);
83 if((reinterpret_cast<size_t>(ptr) & ((s ^ (s & (s - 1))) - 1)) != 0) {
84 fprintf(stderr, "A vector with incorrect alignment has just been created. Look at the stacktrace to find the guilty object.\n");
90 template<typename T> struct ParameterHelper {
92 typedef T & Reference;
93 typedef const T & ConstRef;
95 #if defined VC_MSVC && !defined _WIN64
96 // The calling convention on WIN32 can't guarantee alignment.
97 // An exception are the first three arguments, which may be passed in a register.
98 template<> struct ParameterHelper<M256> {
99 typedef const M256 & ByValue;
100 typedef M256 & Reference;
101 typedef const M256 & ConstRef;
105 template<typename T> struct VectorHelper {};
107 template<unsigned int Size> struct IndexTypeHelper;
108 template<> struct IndexTypeHelper<2u> { typedef unsigned int Type; };
109 template<> struct IndexTypeHelper<4u> { typedef unsigned int Type; };
110 template<> struct IndexTypeHelper<8u> { typedef unsigned short Type; };
111 template<> struct IndexTypeHelper<16u>{ typedef unsigned char Type; };
113 template<typename T> struct CtorTypeHelper { typedef T Type; };
114 template<> struct CtorTypeHelper<short> { typedef int Type; };
115 template<> struct CtorTypeHelper<unsigned short> { typedef unsigned int Type; };
116 template<> struct CtorTypeHelper<float> { typedef double Type; };
118 template<typename T> struct ExpandTypeHelper { typedef T Type; };
119 template<> struct ExpandTypeHelper<short> { typedef int Type; };
120 template<> struct ExpandTypeHelper<unsigned short> { typedef unsigned int Type; };
121 template<> struct ExpandTypeHelper<float> { typedef double Type; };
123 template<typename T> struct VectorTypeHelper { typedef __m128i Type; };
124 template<> struct VectorTypeHelper<double> { typedef __m128d Type; };
125 template<> struct VectorTypeHelper< float> { typedef __m128 Type; };
126 template<> struct VectorTypeHelper<sfloat> { typedef M256 Type; };
128 template<typename T, unsigned int Size> struct DetermineMask { typedef Mask<Size> Type; };
129 template<> struct DetermineMask<sfloat, 8> { typedef Float8Mask Type; };
131 template<typename T> struct DetermineGatherMask { typedef T Type; };
132 template<> struct DetermineGatherMask<Float8Mask> { typedef Float8GatherMask Type; };
134 template<typename T> struct VectorTraits
136 typedef typename VectorTypeHelper<T>::Type VectorType;
137 typedef typename DetermineEntryType<T>::Type EntryType;
139 Size = sizeof(VectorType) / sizeof(EntryType),
140 HasVectorDivision = !IsInteger<T>::Value
142 typedef typename DetermineMask<T, Size>::Type MaskType;
143 typedef typename DetermineGatherMask<MaskType>::Type GatherMaskType;
144 typedef Vector<typename IndexTypeHelper<Size>::Type> IndexType;
145 typedef Common::VectorMemoryUnion<VectorType, EntryType> StorageType;
148 template<typename T> struct VectorHelperSize;
150 template<typename V = Vector<float> >
151 class STRUCT_ALIGN1(16) VectorAlignedBaseT
154 FREE_STORE_OPERATORS_ALIGNED(16)
159 } // namespace AliRoot
161 #include "undomacros.h"
163 #endif // SSE_TYPES_H