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