CMS 3D CMS Logo

AVXVec.h
Go to the documentation of this file.
1 #ifndef DataFormat_Math_AVXVec_H
2 #define DataFormat_Math_AVXVec_H
3 
4 // in principle it should not be used alone
5 // only as part of SSEVec
6 namespace mathSSE {
7 
8  template<>
9  union Vec4<double> {
10  typedef __m256d nativeType;
11  __m256d vec;
12  double __attribute__ ((aligned(32))) arr[4];
13  OldVec<double> o;
14 
15  Vec4(__m256d ivec) : vec(ivec) {}
16 
17  Vec4(OldVec<double> const & ivec) : o(ivec) {}
18 
19  Vec4() {
20  vec = _mm256_setzero_pd();
21  }
22 
23 
24  inline Vec4(Vec4<float> ivec) {
25  vec = _mm256_cvtps_pd(ivec.vec);
26  }
27 
28  explicit Vec4(double f1) {
29  set1(f1);
30  }
31 
32  Vec4(double f1, double f2, double f3, double f4=0) {
33  arr[0] = f1; arr[1] = f2; arr[2] = f3; arr[3]=f4;
34  }
35 
36 
37  Vec4( Vec2<double> ivec0, Vec2<double> ivec1) {
38  vec = _mm256_insertf128_pd(vec,ivec0.vec,0);
39  vec = _mm256_insertf128_pd(vec,ivec1.vec,1);
40 
41  }
42 
43  Vec4( Vec2<double> ivec0, double f3, double f4=0) {
44  vec = _mm256_insertf128_pd(vec,ivec0.vec,0);
45  arr[2] = f3; arr[3] = f4;
46  }
47 
48  Vec4( Vec2<double> ivec0) {
49  vec = _mm256_setzero_pd();
50  vec = _mm256_insertf128_pd(vec,ivec0.vec,0);
51  }
52 
53 
54  // for masking
55  void setMask(unsigned int m1, unsigned int m2, unsigned int m3, unsigned int m4) {
56  Mask4<double> mask(m1,m2,m3,m4); vec=mask.vec;
57  }
58 
59  void set(double f1, double f2, double f3, double f4=0) {
60  vec = _mm256_set_pd(f4, f3, f2, f1);
61  }
62 
63  void set1(double f1) {
64  vec = _mm256_set1_pd(f1);
65  }
66 
67  template<int N>
68  Vec4 get1() const {
69  return _mm256_set1_pd(arr[N]); //FIXME
70  }
71  /*
72  Vec4 get1(unsigned int n) const {
73  return _mm256_set1_pd(arr[n]); //FIXME
74  }
75  */
76  double & operator[](unsigned int n) {
77  return arr[n];
78  }
79 
80  double operator[](unsigned int n) const {
81  return arr[n];
82  }
83 
84  Vec2<double> xy() const { return Vec2<double>(_mm256_castpd256_pd128(vec));}
85  Vec2<double> zw() const { return Vec2<double>(_mm256_castpd256_pd128(_mm256_permute2f128_pd(vec,vec,1)));}
86 
87  };
88 
89  inline Vec4<float>::Vec4(Vec4<double> ivec) {
90  vec = _mm256_cvtpd_ps(ivec.vec);
91  }
92 } // namespace mathSSE
93 
94 
95 
97  return _mm256_movemask_pd(_mm256_cmp_pd(a.vec,b.vec,_CMP_EQ_OS))==0xf;
98 }
99 
101  return _mm256_cmp_pd(a.vec,b.vec,_CMP_EQ_OS);
102 }
103 
105  return _mm256_cmp_pd(a.vec,b.vec,_CMP_GT_OS);
106 }
107 
109  return _mm256_hadd_pd(a.vec,b.vec);
110 }
111 
112 
113 
115  const __m256d neg = _mm256_set_pd ( -0.0 , -0.0 , -0.0, -0.0);
116  return _mm256_xor_pd(a.vec,neg);
117 }
118 
120  return _mm256_and_pd(a.vec,b.vec);
121 }
123  return _mm256_or_pd(a.vec,b.vec);
124 }
126  return _mm256_xor_pd(a.vec,b.vec);
127 }
129  return _mm256_andnot_pd(a.vec,b.vec);
130 }
131 
132 
134  return _mm256_add_pd(a.vec,b.vec);
135 }
136 
138  return _mm256_sub_pd(a.vec,b.vec);
139 }
140 
142  return _mm256_mul_pd(a.vec,b.vec);
143 }
144 
146  return _mm256_div_pd(a.vec,b.vec);
147 }
148 
150  return _mm256_mul_pd(_mm256_set1_pd(a),b.vec);
151 }
152 
154  return _mm256_mul_pd(_mm256_set1_pd(a),b.vec);
155 }
156 
158  return _mm256_div_pd(b.vec,_mm256_set1_pd(a));
159 }
160 
161 
162 inline double
163 __attribute__((always_inline)) __attribute__ ((pure))
165  using mathSSE::_mm256_dot_pd;
167  ret.vec = _mm256_dot_pd(a.vec,b.vec);
168  return ret.arr[0];
169 }
170 
171 inline mathSSE::Vec4<double>
172 __attribute__((always_inline)) __attribute__ ((pure))
174  using mathSSE::_mm256_cross_pd;
175  return _mm256_cross_pd(a.vec,b.vec);
176 }
177 
178 inline double
179 __attribute__((always_inline)) __attribute__ ((pure))
181  mathSSE::Vec4<double> mul = a*b;
182  mul = hadd(mul,mul);
183  return mul.arr[0];
184 }
185 
186 
187 #endif
dot
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
Definition: Basic3DVectorLD.h:212
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:373
mathSSE::Vec4::__attribute__
T __attribute__((aligned(16))) arr[4]
mathSSE::Vec4::Vec4
Vec4()
Definition: SSEVec.h:165
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
mathSSE::Vec4< double >
Definition: AVXVec.h:9
mathSSE::Vec4< double >::operator[]
double & operator[](unsigned int n)
Definition: AVXVec.h:76
mathSSE::Vec4< double >::Vec4
Vec4()
Definition: AVXVec.h:19
mathSSE::Vec4< double >::nativeType
__m256d nativeType
Definition: AVXVec.h:10
mathSSE::Vec4< double >::Vec4
Vec4(Vec2< double > ivec0)
Definition: AVXVec.h:48
mathSSE::Vec4< double >::Vec4
Vec4(double f1)
Definition: AVXVec.h:28
mathSSE::Vec4< double >::vec
__m256d vec
Definition: AVXVec.h:11
operator==
bool operator==(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:96
mathSSE::Vec4< double >::Vec4
Vec4(double f1, double f2, double f3, double f4=0)
Definition: AVXVec.h:32
Vec4
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:64
operator-
mathSSE::Vec4< double > operator-(mathSSE::Vec4< double > a)
Definition: AVXVec.h:114
operator/
mathSSE::Vec4< double > operator/(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:145
operator|
mathSSE::Vec4< double > operator|(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:122
mathSSE::Vec2< double >
N
#define N
Definition: blowfish.cc:9
mathSSE::Vec4< double >::zw
Vec2< double > zw() const
Definition: AVXVec.h:85
mathSSE::OldVec
Definition: SSEVec.h:98
b
double b
Definition: hdecay.h:118
mathSSE::Vec4< double >::Vec4
Vec4(Vec2< double > ivec0, Vec2< double > ivec1)
Definition: AVXVec.h:37
mathSSE::Vec4< double >::Vec4
Vec4(OldVec< double > const &ivec)
Definition: AVXVec.h:17
mathSSE::Vec4< double >::get1
Vec4 get1() const
Definition: AVXVec.h:68
cross
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
Definition: Basic3DVectorLD.h:225
mathSSE::Vec4::set1
void set1(float f1)
Definition: SSEVec.h:184
a
double a
Definition: hdecay.h:119
cmpgt
mathSSE::Vec4< double > cmpgt(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:104
DeadROC_duringRun.f2
f2
Definition: DeadROC_duringRun.py:220
mathSSE
Definition: AVXVec.h:6
mathSSE::Vec4
Definition: SSEVec.h:115
mathSSE::Vec4::o
OldVec< T > o
Definition: SSEVec.h:204
mathSSE::Vec4< double >::Vec4
Vec4(Vec2< double > ivec0, double f3, double f4=0)
Definition: AVXVec.h:43
mathSSE::Vec4< double >::setMask
void setMask(unsigned int m1, unsigned int m2, unsigned int m3, unsigned int m4)
Definition: AVXVec.h:55
mathSSE::Vec4< double >::xy
Vec2< double > xy() const
Definition: AVXVec.h:84
hadd
mathSSE::Vec4< double > hadd(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:108
cmpeq
mathSSE::Vec4< double > cmpeq(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:100
mathSSE::Vec4< double >::Vec4
Vec4(Vec4< float > ivec)
Definition: AVXVec.h:24
mathSSE::Vec4< double >::set1
void set1(double f1)
Definition: AVXVec.h:63
andnot
mathSSE::Vec4< double > andnot(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:128
__attribute__
double __attribute__((always_inline)) __attribute__((pure)) dot(mathSSE
Definition: AVXVec.h:163
mathSSE::Vec4< double >::operator[]
double operator[](unsigned int n) const
Definition: AVXVec.h:80
operator&
mathSSE::Vec4< double > operator&(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:119
operator*
mathSSE::Vec4< double > operator*(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:141
mathSSE::Vec4< double >::set
void set(double f1, double f2, double f3, double f4=0)
Definition: AVXVec.h:59
operator+
mathSSE::Vec4< double > operator+(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:133
DeadROC_duringRun.f1
f1
Definition: DeadROC_duringRun.py:219
operator^
mathSSE::Vec4< double > operator^(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:125