All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
quadInt.h
Go to the documentation of this file.
1 /* quadInt.h
2  */
3 #ifndef EVAL_CONTAINER_QUAD_INT_H
4 #define EVAL_CONTAINER_QUAD_INT_H
5 
6 #include "osl/config.h"
7 #include "osl/misc/carray.h"
8 #include "osl/misc/align16New.h"
9 
10 #ifdef __INTEL_COMPILER
11 # include <emmintrin.h>
12 # define __builtin_ia32_pxor128 _mm_xor_pd
13 # define __builtin_ia32_psubd128 _mm_sub_epi32
14 # define __builtin_ia32_paddd128 _mm_add_epi32
15 #endif
16 
17 #ifndef OSL_NO_SSE
18 #if (defined __x86_64__) || (defined __i386__)
19 # ifndef OSL_USE_SSE
20 # define OSL_USE_SSE 1
21 # endif
22 #else
23 # warning "QuadInt without SSE"
24 #endif
25 #endif
26 
27 namespace osl
28 {
29  namespace container
30  {
31 #ifdef OSL_USE_SSE
32 # ifdef __INTEL_COMPILER
33  typedef __v4si v4si;
34  typedef __v2di v2di;
35 # else
36  typedef int v4si __attribute__ ((vector_size (16)));
37  typedef long long v2di __attribute__ ((vector_size (16)));
38 # endif
39 #endif
40  struct QuadInt : public misc::Align16New
41  {
42  union XMM{
43  CArray<int,4> iv;
44  CArray<long long,2> llv;
45 #ifdef OSL_USE_SSE
46  v4si v4;
47  v2di v2;
48 #endif
49  } v
50 #ifdef OSL_USE_SSE
51  __attribute__((aligned(16)))
52 #endif
53  ;
55  clear();
56  }
57  QuadInt(QuadInt const& si){
58 #if OSL_USE_SSE
59  v.v4=si.v.v4;
60 #else
61  v.llv = si.v.llv;
62 #endif
63  }
64  QuadInt& operator=(QuadInt const& si)
65  {
66 #if OSL_USE_SSE
67  v.v4=si.v.v4;
68 #else
69  v.llv = si.v.llv;
70 #endif
71  return *this;
72  }
73  void clear()
74  {
75 #if OSL_USE_SSE
76  v.v4=(v4si){ 0, 0, 0, 0 };
77 #else
78  v.llv[0] = v.llv[1] = 0;
79 #endif
80  }
81  int& operator[](int i) {
82  return v.iv[i];
83  }
84  const int& operator[](int i) const {
85  return v.iv[i];
86  }
87  QuadInt operator-() const{
88  QuadInt ret;
89  ret -= *this;
90  return ret;
91  }
92  QuadInt& operator+=(QuadInt const& si){
93 #if OSL_USE_SSE
94  v.v4=__builtin_ia32_paddd128(v.v4,si.v.v4);
95 #else
96  for(int i=0;i<4;i++) v.iv[i]+=si.v.iv[i];
97 #endif
98  return *this;
99  }
101 #if OSL_USE_SSE
102  v.v4=__builtin_ia32_psubd128(v.v4,si.v.v4);
103 #else
104  for(int i=0;i<4;i++) v.iv[i]-=si.v.iv[i];
105 #endif
106  return *this;
107  }
108  QuadInt& operator*=(int scale){
109 #if OSL_USE_SSE41
110  XMM val;
111  unsigned long long scalescale=(unsigned long long )((unsigned int)scale);
112  scalescale|=scalescale<<32ull;
113  val.v2=__builtin_ia32_vec_set_v2di(val.v2,(long long)scalescale,0);
114  val.v2=__builtin_ia32_vec_set_v2di(val.v2,(long long)scalescale,1);
115  v.v4=__builtin_ia32_pmulld128(v.v4,val.v4);
116 #else
117  for(int i=0;i<4;i++) v.iv[i]*=scale;
118 #endif
119  return *this;
120  }
121  static size_t size() { return 4; }
122  };
123  inline QuadInt operator+(QuadInt const& si0,QuadInt const& si1)
124  {
125  QuadInt ret(si0);
126  ret+=si1;
127  return ret;
128  }
129  inline QuadInt operator-(QuadInt const& si0,QuadInt const& si1)
130  {
131  QuadInt ret(si0);
132  ret-=si1;
133  return ret;
134  }
135  inline QuadInt operator*(QuadInt const& si0,int scale)
136  {
137  QuadInt ret(si0);
138  ret*=scale;
139  return ret;
140  }
141  inline bool operator==(QuadInt const& l,QuadInt const& r)
142  {
143  return l.v.llv[0] == r.v.llv[0] && l.v.llv[1] == r.v.llv[1];
144  }
145  inline bool operator<(QuadInt const& l,QuadInt const& r)
146  {
147  if (l.v.llv[0] != r.v.llv[0])
148  return (l.v.llv[0] < r.v.llv[0]);
149  return l.v.llv[1] < r.v.llv[1];
150  }
151 
153  {
154  CArray<QuadInt,2> v;
155  public:
157  const QuadInt& operator[](int i) const{
158  return v[i];
159  }
160  const QuadInt& operator[](Player pl) const{
161  return v[pl];
162  }
164  return v[i];
165  }
167  return v[pl];
168  }
170  v[0]+=a.v[0];
171  v[1]+=a.v[1];
172  return *this;
173  }
175  v[0]-=a.v[0];
176  v[1]-=a.v[1];
177  return *this;
178  }
179  };
180  inline QuadIntPair operator+(QuadIntPair const& si0,QuadIntPair const& si1)
181  {
182  QuadIntPair ret(si0);
183  ret+=si1;
184  return ret;
185  }
186  inline QuadIntPair operator-(QuadIntPair const& si0,QuadIntPair const& si1)
187  {
188  QuadIntPair ret(si0);
189  ret-=si1;
190  return ret;
191  }
192  inline bool operator==(QuadIntPair const& l,QuadIntPair const& r)
193  {
194  return l[0] == r[0] && l[1] == r[1];
195  }
196  }
197 
198  using container::QuadInt;
199  using container::QuadIntPair;
200 }
201 #endif // EVAL_CONTAINER_QUAD_INT_H
202 // ;;; Local Variables:
203 // ;;; mode:c++
204 // ;;; c-basic-offset:2
205 // ;;; End: