]>
Commit | Line | Data |
---|---|---|
f22341db | 1 | /* This file is part of the Vc library. |
2 | ||
3 | Copyright (C) 2009-2011 Matthias Kretz <kretz@kde.org> | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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/>. | |
17 | ||
18 | */ | |
19 | ||
20 | #ifndef SSE_TYPES_H | |
21 | #define SSE_TYPES_H | |
22 | ||
23 | #include "intrinsics.h" | |
24 | #include "../common/storage.h" | |
f22341db | 25 | |
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 | |
33 | ||
34 | #include "../common/types.h" | |
c017a39f | 35 | #include "macros.h" |
f22341db | 36 | |
c017a39f | 37 | namespace AliRoot { |
f22341db | 38 | namespace Vc |
39 | { | |
40 | namespace SSE | |
41 | { | |
42 | template<typename T> class Vector; | |
43 | template<typename T> class WriteMaskedVector; | |
44 | ||
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 | |
47 | #ifdef _WIN64 | |
48 | typedef __int64 _long; | |
49 | typedef unsigned __int64 _ulong; | |
50 | #else | |
51 | typedef long _long; | |
52 | typedef unsigned long _ulong; | |
53 | #endif | |
54 | ||
55 | ||
56 | class Float8Mask; | |
57 | class Float8GatherMask; | |
58 | template<unsigned int VectorSize> class Mask; | |
59 | ||
60 | /* | |
61 | * Hack to create a vector object with 8 floats | |
62 | */ | |
63 | typedef Vc::sfloat float8; | |
64 | ||
65 | class M256 { | |
66 | public: | |
c017a39f | 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]; } | |
f22341db | 73 | private: |
c017a39f | 74 | #ifdef VC_COMPILE_BENCHMARKS |
75 | public: | |
76 | #endif | |
f22341db | 77 | _M128 d[2]; |
78 | }; | |
c017a39f | 79 | #ifdef VC_CHECK_ALIGNMENT |
80 | static Vc_ALWAYS_INLINE void assertCorrectAlignment(const M256 *ptr) | |
81 | { | |
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"); | |
85 | abort(); | |
86 | } | |
87 | } | |
88 | #endif | |
f22341db | 89 | |
90 | template<typename T> struct ParameterHelper { | |
91 | typedef T ByValue; | |
92 | typedef T & Reference; | |
93 | typedef const T & ConstRef; | |
94 | }; | |
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; | |
102 | }; | |
103 | #endif | |
104 | ||
105 | template<typename T> struct VectorHelper {}; | |
106 | ||
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; }; | |
112 | ||
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; }; | |
117 | ||
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; }; | |
122 | ||
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; }; | |
127 | ||
128 | template<typename T, unsigned int Size> struct DetermineMask { typedef Mask<Size> Type; }; | |
129 | template<> struct DetermineMask<sfloat, 8> { typedef Float8Mask Type; }; | |
130 | ||
131 | template<typename T> struct DetermineGatherMask { typedef T Type; }; | |
132 | template<> struct DetermineGatherMask<Float8Mask> { typedef Float8GatherMask Type; }; | |
133 | ||
134 | template<typename T> struct VectorTraits | |
135 | { | |
136 | typedef typename VectorTypeHelper<T>::Type VectorType; | |
137 | typedef typename DetermineEntryType<T>::Type EntryType; | |
138 | enum Constants { | |
139 | Size = sizeof(VectorType) / sizeof(EntryType), | |
140 | HasVectorDivision = !IsInteger<T>::Value | |
141 | }; | |
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; | |
146 | }; | |
147 | ||
148 | template<typename T> struct VectorHelperSize; | |
149 | ||
150 | template<typename V = Vector<float> > | |
151 | class STRUCT_ALIGN1(16) VectorAlignedBaseT | |
152 | { | |
153 | public: | |
154 | FREE_STORE_OPERATORS_ALIGNED(16) | |
155 | } STRUCT_ALIGN2(16); | |
156 | ||
157 | } // namespace SSE | |
158 | } // namespace Vc | |
c017a39f | 159 | } // namespace AliRoot |
160 | ||
161 | #include "undomacros.h" | |
f22341db | 162 | |
163 | #endif // SSE_TYPES_H |