SSE/Complex.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_COMPLEX_SSE_H
26 #define EIGEN_COMPLEX_SSE_H
27 
28 namespace Eigen {
29 
30 namespace internal {
31 
32 //---------- float ----------
33 struct Packet2cf
34 {
35  EIGEN_STRONG_INLINE Packet2cf() {}
36  EIGEN_STRONG_INLINE explicit Packet2cf(const __m128& a) : v(a) {}
37  __m128 v;
38 };
39 
40 template<> struct packet_traits<std::complex<float> > : default_packet_traits
41 {
42  typedef Packet2cf type;
43  enum {
44  Vectorizable = 1,
45  AlignedOnScalar = 1,
46  size = 2,
47 
48  HasAdd = 1,
49  HasSub = 1,
50  HasMul = 1,
51  HasDiv = 1,
52  HasNegate = 1,
53  HasAbs = 0,
54  HasAbs2 = 0,
55  HasMin = 0,
56  HasMax = 0,
57  HasSetLinear = 0
58  };
59 };
60 
61 template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2}; };
62 
63 template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_add_ps(a.v,b.v)); }
64 template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_sub_ps(a.v,b.v)); }
65 template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a)
66 {
67  const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000));
68  return Packet2cf(_mm_xor_ps(a.v,mask));
69 }
70 template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a)
71 {
72  const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
73  return Packet2cf(_mm_xor_ps(a.v,mask));
74 }
75 
76 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
77 {
78  // TODO optimize it for SSE3 and 4
79  #ifdef EIGEN_VECTORIZE_SSE3
80  return Packet2cf(_mm_addsub_ps(_mm_mul_ps(_mm_moveldup_ps(a.v), b.v),
81  _mm_mul_ps(_mm_movehdup_ps(a.v),
82  vec4f_swizzle1(b.v, 1, 0, 3, 2))));
83 // return Packet2cf(_mm_addsub_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
84 // _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
85 // vec4f_swizzle1(b.v, 1, 0, 3, 2))));
86  #else
87  const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x00000000,0x80000000,0x00000000));
88  return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
89  _mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
90  vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask)));
91  #endif
92 }
93 
94 template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_and_ps(a.v,b.v)); }
95 template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_or_ps(a.v,b.v)); }
96 template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_xor_ps(a.v,b.v)); }
97 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_andnot_ps(a.v,b.v)); }
98 
99 template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>(&real_ref(*from))); }
100 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>(&real_ref(*from))); }
101 
102 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
103 {
104  Packet2cf res;
105  #if EIGEN_GNUC_AT_MOST(4,2)
106  // workaround annoying "may be used uninitialized in this function" warning with gcc 4.2
107  res.v = _mm_loadl_pi(_mm_set1_ps(0.0f), reinterpret_cast<const __m64*>(&from));
108  #else
109  res.v = _mm_loadl_pi(res.v, (const __m64*)&from);
110  #endif
111  return Packet2cf(_mm_movelh_ps(res.v,res.v));
112 }
113 
114 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); }
115 
116 template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&real_ref(*to), from.v); }
117 template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&real_ref(*to), from.v); }
118 
119 template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
120 
121 template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a)
122 {
123  #if EIGEN_GNUC_AT_MOST(4,3)
124  // Workaround gcc 4.2 ICE - this is not performance wise ideal, but who cares...
125  // This workaround also fix invalid code generation with gcc 4.3
126  EIGEN_ALIGN16 std::complex<float> res[2];
127  _mm_store_ps((float*)res, a.v);
128  return res[0];
129  #else
130  std::complex<float> res;
131  _mm_storel_pi((__m64*)&res, a.v);
132  return res;
133  #endif
134 }
135 
136 template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) { return Packet2cf(_mm_castpd_ps(preverse(_mm_castps_pd(a.v)))); }
137 
138 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
139 {
140  return pfirst(Packet2cf(_mm_add_ps(a.v, _mm_movehl_ps(a.v,a.v))));
141 }
142 
143 template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs)
144 {
145  return Packet2cf(_mm_add_ps(_mm_movelh_ps(vecs[0].v,vecs[1].v), _mm_movehl_ps(vecs[1].v,vecs[0].v)));
146 }
147 
148 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
149 {
150  return pfirst(pmul(a, Packet2cf(_mm_movehl_ps(a.v,a.v))));
151 }
152 
153 template<int Offset>
154 struct palign_impl<Offset,Packet2cf>
155 {
156  static EIGEN_STRONG_INLINE void run(Packet2cf& first, const Packet2cf& second)
157  {
158  if (Offset==1)
159  {
160  first.v = _mm_movehl_ps(first.v, first.v);
161  first.v = _mm_movelh_ps(first.v, second.v);
162  }
163  }
164 };
165 
166 template<> struct conj_helper<Packet2cf, Packet2cf, false,true>
167 {
168  EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
169  { return padd(pmul(x,y),c); }
170 
171  EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
172  {
173  #ifdef EIGEN_VECTORIZE_SSE3
174  return internal::pmul(a, pconj(b));
175  #else
176  const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
177  return Packet2cf(_mm_add_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask),
178  _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
179  vec4f_swizzle1(b.v, 1, 0, 3, 2))));
180  #endif
181  }
182 };
183 
184 template<> struct conj_helper<Packet2cf, Packet2cf, true,false>
185 {
186  EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
187  { return padd(pmul(x,y),c); }
188 
189  EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
190  {
191  #ifdef EIGEN_VECTORIZE_SSE3
192  return internal::pmul(pconj(a), b);
193  #else
194  const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
195  return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
196  _mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
197  vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask)));
198  #endif
199  }
200 };
201 
202 template<> struct conj_helper<Packet2cf, Packet2cf, true,true>
203 {
204  EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
205  { return padd(pmul(x,y),c); }
206 
207  EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
208  {
209  #ifdef EIGEN_VECTORIZE_SSE3
210  return pconj(internal::pmul(a, b));
211  #else
212  const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
213  return Packet2cf(_mm_sub_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask),
214  _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
215  vec4f_swizzle1(b.v, 1, 0, 3, 2))));
216  #endif
217  }
218 };
219 
220 template<> struct conj_helper<Packet4f, Packet2cf, false,false>
221 {
222  EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet4f& x, const Packet2cf& y, const Packet2cf& c) const
223  { return padd(c, pmul(x,y)); }
224 
225  EIGEN_STRONG_INLINE Packet2cf pmul(const Packet4f& x, const Packet2cf& y) const
226  { return Packet2cf(Eigen::internal::pmul(x, y.v)); }
227 };
228 
229 template<> struct conj_helper<Packet2cf, Packet4f, false,false>
230 {
231  EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet4f& y, const Packet2cf& c) const
232  { return padd(c, pmul(x,y)); }
233 
234  EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& x, const Packet4f& y) const
235  { return Packet2cf(Eigen::internal::pmul(x.v, y)); }
236 };
237 
238 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
239 {
240  // TODO optimize it for SSE3 and 4
241  Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b);
242  __m128 s = _mm_mul_ps(b.v,b.v);
243  return Packet2cf(_mm_div_ps(res.v,_mm_add_ps(s,_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(s), 0xb1)))));
244 }
245 
246 EIGEN_STRONG_INLINE Packet2cf pcplxflip/*<Packet2cf>*/(const Packet2cf& x)
247 {
248  return Packet2cf(vec4f_swizzle1(x.v, 1, 0, 3, 2));
249 }
250 
251 
252 //---------- double ----------
253 struct Packet1cd
254 {
255  EIGEN_STRONG_INLINE Packet1cd() {}
256  EIGEN_STRONG_INLINE explicit Packet1cd(const __m128d& a) : v(a) {}
257  __m128d v;
258 };
259 
260 template<> struct packet_traits<std::complex<double> > : default_packet_traits
261 {
262  typedef Packet1cd type;
263  enum {
264  Vectorizable = 1,
265  AlignedOnScalar = 0,
266  size = 1,
267 
268  HasAdd = 1,
269  HasSub = 1,
270  HasMul = 1,
271  HasDiv = 1,
272  HasNegate = 1,
273  HasAbs = 0,
274  HasAbs2 = 0,
275  HasMin = 0,
276  HasMax = 0,
277  HasSetLinear = 0
278  };
279 };
280 
281 template<> struct unpacket_traits<Packet1cd> { typedef std::complex<double> type; enum {size=1}; };
282 
283 template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_add_pd(a.v,b.v)); }
284 template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_sub_pd(a.v,b.v)); }
285 template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(a.v)); }
286 template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a)
287 {
288  const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
289  return Packet1cd(_mm_xor_pd(a.v,mask));
290 }
291 
292 template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
293 {
294  // TODO optimize it for SSE3 and 4
295  #ifdef EIGEN_VECTORIZE_SSE3
296  return Packet1cd(_mm_addsub_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
297  _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
298  vec2d_swizzle1(b.v, 1, 0))));
299  #else
300  const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0));
301  return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
302  _mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
303  vec2d_swizzle1(b.v, 1, 0)), mask)));
304  #endif
305 }
306 
307 template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_and_pd(a.v,b.v)); }
308 template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_or_pd(a.v,b.v)); }
309 template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_xor_pd(a.v,b.v)); }
310 template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_andnot_pd(a.v,b.v)); }
311 
312 // FIXME force unaligned load, this is a temporary fix
313 template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from)
314 { EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>((const double*)from)); }
315 template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from)
316 { EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>((const double*)from)); }
317 template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from)
318 { /* here we really have to use unaligned loads :( */ return ploadu<Packet1cd>(&from); }
319 
320 template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); }
321 
322 // FIXME force unaligned store, this is a temporary fix
323 template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, from.v); }
324 template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, from.v); }
325 
326 template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> * addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
327 
328 template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a)
329 {
330  EIGEN_ALIGN16 double res[2];
331  _mm_store_pd(res, a.v);
332  return std::complex<double>(res[0],res[1]);
333 }
334 
335 template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; }
336 
337 template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a)
338 {
339  return pfirst(a);
340 }
341 
342 template<> EIGEN_STRONG_INLINE Packet1cd preduxp<Packet1cd>(const Packet1cd* vecs)
343 {
344  return vecs[0];
345 }
346 
347 template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a)
348 {
349  return pfirst(a);
350 }
351 
352 template<int Offset>
353 struct palign_impl<Offset,Packet1cd>
354 {
355  static EIGEN_STRONG_INLINE void run(Packet1cd& /*first*/, const Packet1cd& /*second*/)
356  {
357  // FIXME is it sure we never have to align a Packet1cd?
358  // Even though a std::complex<double> has 16 bytes, it is not necessarily aligned on a 16 bytes boundary...
359  }
360 };
361 
362 template<> struct conj_helper<Packet1cd, Packet1cd, false,true>
363 {
364  EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const
365  { return padd(pmul(x,y),c); }
366 
367  EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const
368  {
369  #ifdef EIGEN_VECTORIZE_SSE3
370  return internal::pmul(a, pconj(b));
371  #else
372  const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
373  return Packet1cd(_mm_add_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask),
374  _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
375  vec2d_swizzle1(b.v, 1, 0))));
376  #endif
377  }
378 };
379 
380 template<> struct conj_helper<Packet1cd, Packet1cd, true,false>
381 {
382  EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const
383  { return padd(pmul(x,y),c); }
384 
385  EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const
386  {
387  #ifdef EIGEN_VECTORIZE_SSE3
388  return internal::pmul(pconj(a), b);
389  #else
390  const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
391  return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
392  _mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
393  vec2d_swizzle1(b.v, 1, 0)), mask)));
394  #endif
395  }
396 };
397 
398 template<> struct conj_helper<Packet1cd, Packet1cd, true,true>
399 {
400  EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const
401  { return padd(pmul(x,y),c); }
402 
403  EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const
404  {
405  #ifdef EIGEN_VECTORIZE_SSE3
406  return pconj(internal::pmul(a, b));
407  #else
408  const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
409  return Packet1cd(_mm_sub_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask),
410  _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
411  vec2d_swizzle1(b.v, 1, 0))));
412  #endif
413  }
414 };
415 
416 template<> struct conj_helper<Packet2d, Packet1cd, false,false>
417 {
418  EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet2d& x, const Packet1cd& y, const Packet1cd& c) const
419  { return padd(c, pmul(x,y)); }
420 
421  EIGEN_STRONG_INLINE Packet1cd pmul(const Packet2d& x, const Packet1cd& y) const
422  { return Packet1cd(Eigen::internal::pmul(x, y.v)); }
423 };
424 
425 template<> struct conj_helper<Packet1cd, Packet2d, false,false>
426 {
427  EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet2d& y, const Packet1cd& c) const
428  { return padd(c, pmul(x,y)); }
429 
430  EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& x, const Packet2d& y) const
431  { return Packet1cd(Eigen::internal::pmul(x.v, y)); }
432 };
433 
434 template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
435 {
436  // TODO optimize it for SSE3 and 4
437  Packet1cd res = conj_helper<Packet1cd,Packet1cd,false,true>().pmul(a,b);
438  __m128d s = _mm_mul_pd(b.v,b.v);
439  return Packet1cd(_mm_div_pd(res.v, _mm_add_pd(s,_mm_shuffle_pd(s, s, 0x1))));
440 }
441 
442 EIGEN_STRONG_INLINE Packet1cd pcplxflip/*<Packet1cd>*/(const Packet1cd& x)
443 {
444  return Packet1cd(preverse(x.v));
445 }
446 
447 } // end namespace internal
448 
449 } // end namespace Eigen
450 
451 #endif // EIGEN_COMPLEX_SSE_H