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() { vec = _mm256_setzero_pd(); }
20 
21  inline Vec4(Vec4<float> ivec) { vec = _mm256_cvtps_pd(ivec.vec); }
22 
23  explicit Vec4(double f1) { set1(f1); }
24 
25  Vec4(double f1, double f2, double f3, double f4 = 0) {
26  arr[0] = f1;
27  arr[1] = f2;
28  arr[2] = f3;
29  arr[3] = f4;
30  }
31 
32  Vec4(Vec2<double> ivec0, Vec2<double> ivec1) { vec = _mm256_set_m128d(ivec1.vec, ivec0.vec); }
33 
34  Vec4(Vec2<double> ivec0, double f3, double f4 = 0) {
35  vec = _mm256_insertf128_pd(vec, ivec0.vec, 0);
36  arr[2] = f3;
37  arr[3] = f4;
38  }
39 
40  Vec4(Vec2<double> ivec0) {
41  vec = _mm256_setzero_pd();
42  vec = _mm256_insertf128_pd(vec, ivec0.vec, 0);
43  }
44 
45  // for masking
46  void setMask(unsigned int m1, unsigned int m2, unsigned int m3, unsigned int m4) {
47  Mask4<double> mask(m1, m2, m3, m4);
48  vec = mask.vec;
49  }
50 
51  void set(double f1, double f2, double f3, double f4 = 0) { vec = _mm256_set_pd(f4, f3, f2, f1); }
52 
53  void set1(double f1) { vec = _mm256_set1_pd(f1); }
54 
55  template <int N>
56  Vec4 get1() const {
57  return _mm256_set1_pd(arr[N]); //FIXME
58  }
59  /*
60  Vec4 get1(unsigned int n) const {
61  return _mm256_set1_pd(arr[n]); //FIXME
62  }
63  */
64  double& operator[](unsigned int n) { return arr[n]; }
65 
66  double operator[](unsigned int n) const { return arr[n]; }
67 
68  Vec2<double> xy() const { return Vec2<double>(_mm256_castpd256_pd128(vec)); }
69  Vec2<double> zw() const { return Vec2<double>(_mm256_castpd256_pd128(_mm256_permute2f128_pd(vec, vec, 1))); }
70  };
71 
72  inline Vec4<float>::Vec4(Vec4<double> ivec) { vec = _mm256_cvtpd_ps(ivec.vec); }
73 } // namespace mathSSE
74 
76  return _mm256_movemask_pd(_mm256_cmp_pd(a.vec, b.vec, _CMP_EQ_OS)) == 0xf;
77 }
78 
80  return _mm256_cmp_pd(a.vec, b.vec, _CMP_EQ_OS);
81 }
82 
84  return _mm256_cmp_pd(a.vec, b.vec, _CMP_GT_OS);
85 }
86 
88  return _mm256_hadd_pd(a.vec, b.vec);
89 }
90 
92  const __m256d neg = _mm256_set_pd(-0.0, -0.0, -0.0, -0.0);
93  return _mm256_xor_pd(a.vec, neg);
94 }
95 
97  return _mm256_and_pd(a.vec, b.vec);
98 }
100  return _mm256_or_pd(a.vec, b.vec);
101 }
103  return _mm256_xor_pd(a.vec, b.vec);
104 }
106  return _mm256_andnot_pd(a.vec, b.vec);
107 }
108 
110  return _mm256_add_pd(a.vec, b.vec);
111 }
112 
114  return _mm256_sub_pd(a.vec, b.vec);
115 }
116 
118  return _mm256_mul_pd(a.vec, b.vec);
119 }
120 
122  return _mm256_div_pd(a.vec, b.vec);
123 }
124 
126  return _mm256_mul_pd(_mm256_set1_pd(a), b.vec);
127 }
128 
130  return _mm256_mul_pd(_mm256_set1_pd(a), b.vec);
131 }
132 
134  return _mm256_div_pd(b.vec, _mm256_set1_pd(a));
135 }
136 
137 inline double __attribute__((always_inline)) __attribute__((pure))
139  using mathSSE::_mm256_dot_pd;
141  ret.vec = _mm256_dot_pd(a.vec, b.vec);
142  return ret.arr[0];
143 }
144 
145 inline mathSSE::Vec4<double> __attribute__((always_inline)) __attribute__((pure))
147  using mathSSE::_mm256_cross_pd;
148  return _mm256_cross_pd(a.vec, b.vec);
149 }
150 
151 inline double __attribute__((always_inline)) __attribute__((pure))
153  mathSSE::Vec4<double> mul = a * b;
154  mul = hadd(mul, mul);
155  return mul.arr[0];
156 }
157 
158 #endif
Definition: AVXVec.h:6
void set1(float f1)
Definition: SSEVec.h:184
mathSSE::Vec4< double > andnot(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:105
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
mathSSE::Vec4< double > operator &(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:96
mathSSE::Vec4< double > operator|(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:99
Vec4(Vec4< float > ivec)
Definition: AVXVec.h:21
bool operator==(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:75
ret
prodAgent to be discontinued
void set1(double f1)
Definition: AVXVec.h:53
Vec2< double > xy() const
Definition: AVXVec.h:68
mathSSE::Vec4< double > cmpgt(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:83
OldVec< T > o
Definition: SSEVec.h:204
Vec2< double > zw() const
Definition: AVXVec.h:69
mathSSE::Vec4< double > operator/(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:121
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
mathSSE::Vec4< double > operator-(mathSSE::Vec4< double > a)
Definition: AVXVec.h:91
Vec4(double f1)
Definition: AVXVec.h:23
mathSSE::Vec4< double > operator*(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:117
double operator[](unsigned int n) const
Definition: AVXVec.h:66
mathSSE::Vec4< double > operator+(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:109
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:60
Vec4(double f1, double f2, double f3, double f4=0)
Definition: AVXVec.h:25
#define N
Definition: blowfish.cc:9
double __attribute__((always_inline)) __attribute__((pure)) dot(mathSSE
Definition: AVXVec.h:137
double b
Definition: hdecay.h:120
Vec4(Vec2< double > ivec0, Vec2< double > ivec1)
Definition: AVXVec.h:32
double a
Definition: hdecay.h:121
Vec4(OldVec< double > const &ivec)
Definition: AVXVec.h:17
mathSSE::Vec4< double > operator^(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:102
Vec4(Vec2< double > ivec0, double f3, double f4=0)
Definition: AVXVec.h:34
Vec4(Vec2< double > ivec0)
Definition: AVXVec.h:40
void setMask(unsigned int m1, unsigned int m2, unsigned int m3, unsigned int m4)
Definition: AVXVec.h:46
Vec4 get1() const
Definition: AVXVec.h:56
mathSSE::Vec4< double > hadd(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:87
mathSSE::Vec4< double > cmpeq(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:79
double & operator[](unsigned int n)
Definition: AVXVec.h:64
T __attribute__((aligned(16))) arr[4]