]> git.uio.no Git - u/mrichter/AliRoot.git/blame - Vc/include/Vc/sse/types.h
Vc package added (version 0.6.79-dev)
[u/mrichter/AliRoot.git] / Vc / include / Vc / sse / types.h
CommitLineData
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"
25#include "macros.h"
26
27#define VC_DOUBLE_V_SIZE 2
28#define VC_FLOAT_V_SIZE 4
29#define VC_SFLOAT_V_SIZE 8
30#define VC_INT_V_SIZE 4
31#define VC_UINT_V_SIZE 4
32#define VC_SHORT_V_SIZE 8
33#define VC_USHORT_V_SIZE 8
34
35#include "../common/types.h"
36
37namespace Vc
38{
39namespace SSE
40{
41 template<typename T> class Vector;
42 template<typename T> class WriteMaskedVector;
43
44 // define our own long because on Windows64 long == int while on Linux long == max. register width
45 // since we want to have a type that depends on 32 vs. 64 bit we need to do some special casing on Windows
46#ifdef _WIN64
47 typedef __int64 _long;
48 typedef unsigned __int64 _ulong;
49#else
50 typedef long _long;
51 typedef unsigned long _ulong;
52#endif
53
54
55 class Float8Mask;
56 class Float8GatherMask;
57 template<unsigned int VectorSize> class Mask;
58
59 /*
60 * Hack to create a vector object with 8 floats
61 */
62 typedef Vc::sfloat float8;
63
64 class M256 {
65 public:
66 //inline M256() {}
67 //inline M256(_M128 a, _M128 b) { d[0] = a; d[1] = b; }
68 static inline M256 dup(_M128 a) { M256 r; r.d[0] = a; r.d[1] = a; return r; }
69 static inline M256 create(_M128 a, _M128 b) { M256 r; r.d[0] = a; r.d[1] = b; return r; }
70 inline _M128 &operator[](int i) { return d[i]; }
71 inline const _M128 &operator[](int i) const { return d[i]; }
72 private:
73 _M128 d[2];
74 };
75
76 template<typename T> struct ParameterHelper {
77 typedef T ByValue;
78 typedef T & Reference;
79 typedef const T & ConstRef;
80 };
81#if defined VC_MSVC && !defined _WIN64
82 // The calling convention on WIN32 can't guarantee alignment.
83 // An exception are the first three arguments, which may be passed in a register.
84 template<> struct ParameterHelper<M256> {
85 typedef const M256 & ByValue;
86 typedef M256 & Reference;
87 typedef const M256 & ConstRef;
88 };
89#endif
90
91 template<typename T> struct VectorHelper {};
92
93 template<unsigned int Size> struct IndexTypeHelper;
94 template<> struct IndexTypeHelper<2u> { typedef unsigned int Type; };
95 template<> struct IndexTypeHelper<4u> { typedef unsigned int Type; };
96 template<> struct IndexTypeHelper<8u> { typedef unsigned short Type; };
97 template<> struct IndexTypeHelper<16u>{ typedef unsigned char Type; };
98
99 template<typename T> struct CtorTypeHelper { typedef T Type; };
100 template<> struct CtorTypeHelper<short> { typedef int Type; };
101 template<> struct CtorTypeHelper<unsigned short> { typedef unsigned int Type; };
102 template<> struct CtorTypeHelper<float> { typedef double Type; };
103
104 template<typename T> struct ExpandTypeHelper { typedef T Type; };
105 template<> struct ExpandTypeHelper<short> { typedef int Type; };
106 template<> struct ExpandTypeHelper<unsigned short> { typedef unsigned int Type; };
107 template<> struct ExpandTypeHelper<float> { typedef double Type; };
108
109 template<typename T> struct VectorTypeHelper { typedef __m128i Type; };
110 template<> struct VectorTypeHelper<double> { typedef __m128d Type; };
111 template<> struct VectorTypeHelper< float> { typedef __m128 Type; };
112 template<> struct VectorTypeHelper<sfloat> { typedef M256 Type; };
113
114 template<typename T, unsigned int Size> struct DetermineMask { typedef Mask<Size> Type; };
115 template<> struct DetermineMask<sfloat, 8> { typedef Float8Mask Type; };
116
117 template<typename T> struct DetermineGatherMask { typedef T Type; };
118 template<> struct DetermineGatherMask<Float8Mask> { typedef Float8GatherMask Type; };
119
120 template<typename T> struct VectorTraits
121 {
122 typedef typename VectorTypeHelper<T>::Type VectorType;
123 typedef typename DetermineEntryType<T>::Type EntryType;
124 enum Constants {
125 Size = sizeof(VectorType) / sizeof(EntryType),
126 HasVectorDivision = !IsInteger<T>::Value
127 };
128 typedef typename DetermineMask<T, Size>::Type MaskType;
129 typedef typename DetermineGatherMask<MaskType>::Type GatherMaskType;
130 typedef Vector<typename IndexTypeHelper<Size>::Type> IndexType;
131 typedef Common::VectorMemoryUnion<VectorType, EntryType> StorageType;
132 };
133
134 template<typename T> struct VectorHelperSize;
135
136 template<typename V = Vector<float> >
137 class STRUCT_ALIGN1(16) VectorAlignedBaseT
138 {
139 public:
140 FREE_STORE_OPERATORS_ALIGNED(16)
141 } STRUCT_ALIGN2(16);
142
143} // namespace SSE
144} // namespace Vc
145
146#endif // SSE_TYPES_H