ROOT  6.06/09
Reference Guide
types.h
Go to the documentation of this file.
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 
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"
35 #include "macros.h"
36 
37 namespace ROOT {
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:
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]; }
73  private:
74 #ifdef VC_COMPILE_BENCHMARKS
75  public:
76 #endif
77  _M128 d[2];
78  };
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
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  {
138  enum Constants {
139  Size = sizeof(VectorType) / sizeof(EntryType),
141  };
146  };
147 
148  template<typename T> struct VectorHelperSize;
149 
150  template<typename V = Vector<float> >
151  class STRUCT_ALIGN1(16) VectorAlignedBaseT
152  {
153  public:
155  } STRUCT_ALIGN2(16);
156 
157 } // namespace SSE
158 } // namespace Vc
159 } // namespace ROOT
160 
161 #include "undomacros.h"
162 
163 #endif // SSE_TYPES_H
DetermineEntryType< T >::Type EntryType
Definition: types.h:137
DetermineGatherMask< MaskType >::Type GatherMaskType
Definition: types.h:143
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
Vector< typename IndexTypeHelper< Size >::Type > IndexType
Definition: types.h:144
double T(double x)
Definition: ChebyshevPol.h:34
#define FREE_STORE_OPERATORS_ALIGNED(alignment)
Definition: macros.h:165
_M128 d[2]
Definition: types.h:77
TArc * a
Definition: textangle.C:12
static Vc_INTRINSIC Vc_CONST M256 create(_M128 a, _M128 b)
Definition: types.h:70
#define Vc_INTRINSIC
Definition: macros.h:139
DetermineMask< T, Size >::Type MaskType
Definition: types.h:142
long _long
Definition: types.h:43
unsigned long _ulong
Definition: types.h:52
Vc_INTRINSIC _M128 & operator[](int i)
Definition: types.h:71
ROOT::R::TRInterface & r
Definition: Object.C:4
static Vc_ALWAYS_INLINE void assertCorrectAlignment(const _T *)
Definition: types.h:210
#define Vc_CONST
Definition: macros.h:133
#define _M128
Definition: macros.h:27
Vc_INTRINSIC const _M128 & operator[](int i) const
Definition: types.h:72
VectorTypeHelper< T >::Type VectorType
Definition: types.h:136
#define Vc_ALWAYS_INLINE
Definition: macros.h:130
Vc::sfloat float8
Definition: types.h:58
Common::VectorMemoryUnion< VectorType, EntryType > StorageType
Definition: types.h:145
#define SSE
Definition: global.h:84
class STRUCT_ALIGN1(16) VectorAlignedBaseT
Definition: types.h:151
static Vc_INTRINSIC Vc_CONST M256 dup(_M128 a)
Definition: types.h:69
Definition: casts.h:28
const char * Value
Definition: TXMLSetup.cxx:73