Complex.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_COMPLEX_SSE_H
00011 #define EIGEN_COMPLEX_SSE_H
00012 
00013 namespace Eigen {
00014 
00015 namespace internal {
00016 
00017 //---------- float ----------
00018 struct Packet2cf
00019 {
00020   EIGEN_STRONG_INLINE Packet2cf() {}
00021   EIGEN_STRONG_INLINE explicit Packet2cf(const __m128& a) : v(a) {}
00022   __m128  v;
00023 };
00024 
00025 template<> struct packet_traits<std::complex<float> >  : default_packet_traits
00026 {
00027   typedef Packet2cf type;
00028   enum {
00029     Vectorizable = 1,
00030     AlignedOnScalar = 1,
00031     size = 2,
00032 
00033     HasAdd    = 1,
00034     HasSub    = 1,
00035     HasMul    = 1,
00036     HasDiv    = 1,
00037     HasNegate = 1,
00038     HasAbs    = 0,
00039     HasAbs2   = 0,
00040     HasMin    = 0,
00041     HasMax    = 0,
00042     HasSetLinear = 0
00043   };
00044 };
00045 
00046 template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2}; };
00047 
00048 template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_add_ps(a.v,b.v)); }
00049 template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_sub_ps(a.v,b.v)); }
00050 template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a)
00051 {
00052   const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000));
00053   return Packet2cf(_mm_xor_ps(a.v,mask));
00054 }
00055 template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a)
00056 {
00057   const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
00058   return Packet2cf(_mm_xor_ps(a.v,mask));
00059 }
00060 
00061 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00062 {
00063   // TODO optimize it for SSE3 and 4
00064   #ifdef EIGEN_VECTORIZE_SSE3
00065   return Packet2cf(_mm_addsub_ps(_mm_mul_ps(_mm_moveldup_ps(a.v), b.v),
00066                                  _mm_mul_ps(_mm_movehdup_ps(a.v),
00067                                             vec4f_swizzle1(b.v, 1, 0, 3, 2))));
00068 //   return Packet2cf(_mm_addsub_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
00069 //                                  _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
00070 //                                             vec4f_swizzle1(b.v, 1, 0, 3, 2))));
00071   #else
00072   const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x00000000,0x80000000,0x00000000));
00073   return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
00074                               _mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
00075                                                     vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask)));
00076   #endif
00077 }
00078 
00079 template<> EIGEN_STRONG_INLINE Packet2cf pand   <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_and_ps(a.v,b.v)); }
00080 template<> EIGEN_STRONG_INLINE Packet2cf por    <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_or_ps(a.v,b.v)); }
00081 template<> EIGEN_STRONG_INLINE Packet2cf pxor   <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_xor_ps(a.v,b.v)); }
00082 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_andnot_ps(a.v,b.v)); }
00083 
00084 template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>(&numext::real_ref(*from))); }
00085 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>(&numext::real_ref(*from))); }
00086 
00087 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>&  from)
00088 {
00089   Packet2cf res;
00090 #if EIGEN_GNUC_AT_MOST(4,2)
00091   // Workaround annoying "may be used uninitialized in this function" warning with gcc 4.2
00092   res.v = _mm_loadl_pi(_mm_set1_ps(0.0f), reinterpret_cast<const __m64*>(&from));
00093 #elif EIGEN_GNUC_AT_LEAST(4,6)
00094   // Suppress annoying "may be used uninitialized in this function" warning with gcc >= 4.6
00095   #pragma GCC diagnostic push
00096   #pragma GCC diagnostic ignored "-Wuninitialized"
00097   res.v = _mm_loadl_pi(res.v, (const __m64*)&from);
00098   #pragma GCC diagnostic pop
00099 #else
00100   res.v = _mm_loadl_pi(res.v, (const __m64*)&from);
00101 #endif
00102   return Packet2cf(_mm_movelh_ps(res.v,res.v));
00103 }
00104 
00105 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); }
00106 
00107 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); }
00108 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); }
00109 
00110 template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> *   addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
00111 
00112 template<> EIGEN_STRONG_INLINE std::complex<float>  pfirst<Packet2cf>(const Packet2cf& a)
00113 {
00114   #if EIGEN_GNUC_AT_MOST(4,3)
00115   // Workaround gcc 4.2 ICE - this is not performance wise ideal, but who cares...
00116   // This workaround also fix invalid code generation with gcc 4.3
00117   EIGEN_ALIGN16 std::complex<float> res[2];
00118   _mm_store_ps((float*)res, a.v);
00119   return res[0];
00120   #else
00121   std::complex<float> res;
00122   _mm_storel_pi((__m64*)&res, a.v);
00123   return res;
00124   #endif
00125 }
00126 
00127 template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) { return Packet2cf(_mm_castpd_ps(preverse(_mm_castps_pd(a.v)))); }
00128 
00129 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
00130 {
00131   return pfirst(Packet2cf(_mm_add_ps(a.v, _mm_movehl_ps(a.v,a.v))));
00132 }
00133 
00134 template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs)
00135 {
00136   return Packet2cf(_mm_add_ps(_mm_movelh_ps(vecs[0].v,vecs[1].v), _mm_movehl_ps(vecs[1].v,vecs[0].v)));
00137 }
00138 
00139 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
00140 {
00141   return pfirst(pmul(a, Packet2cf(_mm_movehl_ps(a.v,a.v))));
00142 }
00143 
00144 template<int Offset>
00145 struct palign_impl<Offset,Packet2cf>
00146 {
00147   static EIGEN_STRONG_INLINE void run(Packet2cf& first, const Packet2cf& second)
00148   {
00149     if (Offset==1)
00150     {
00151       first.v = _mm_movehl_ps(first.v, first.v);
00152       first.v = _mm_movelh_ps(first.v, second.v);
00153     }
00154   }
00155 };
00156 
00157 template<> struct conj_helper<Packet2cf, Packet2cf, false,true>
00158 {
00159   EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
00160   { return padd(pmul(x,y),c); }
00161 
00162   EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
00163   {
00164     #ifdef EIGEN_VECTORIZE_SSE3
00165     return internal::pmul(a, pconj(b));
00166     #else
00167     const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
00168     return Packet2cf(_mm_add_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask),
00169                                 _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
00170                                            vec4f_swizzle1(b.v, 1, 0, 3, 2))));
00171     #endif
00172   }
00173 };
00174 
00175 template<> struct conj_helper<Packet2cf, Packet2cf, true,false>
00176 {
00177   EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
00178   { return padd(pmul(x,y),c); }
00179 
00180   EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
00181   {
00182     #ifdef EIGEN_VECTORIZE_SSE3
00183     return internal::pmul(pconj(a), b);
00184     #else
00185     const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
00186     return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
00187                                 _mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
00188                                                       vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask)));
00189     #endif
00190   }
00191 };
00192 
00193 template<> struct conj_helper<Packet2cf, Packet2cf, true,true>
00194 {
00195   EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
00196   { return padd(pmul(x,y),c); }
00197 
00198   EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
00199   {
00200     #ifdef EIGEN_VECTORIZE_SSE3
00201     return pconj(internal::pmul(a, b));
00202     #else
00203     const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
00204     return Packet2cf(_mm_sub_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask),
00205                                 _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
00206                                            vec4f_swizzle1(b.v, 1, 0, 3, 2))));
00207     #endif
00208   }
00209 };
00210 
00211 template<> struct conj_helper<Packet4f, Packet2cf, false,false>
00212 {
00213   EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet4f& x, const Packet2cf& y, const Packet2cf& c) const
00214   { return padd(c, pmul(x,y)); }
00215 
00216   EIGEN_STRONG_INLINE Packet2cf pmul(const Packet4f& x, const Packet2cf& y) const
00217   { return Packet2cf(Eigen::internal::pmul(x, y.v)); }
00218 };
00219 
00220 template<> struct conj_helper<Packet2cf, Packet4f, false,false>
00221 {
00222   EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet4f& y, const Packet2cf& c) const
00223   { return padd(c, pmul(x,y)); }
00224 
00225   EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& x, const Packet4f& y) const
00226   { return Packet2cf(Eigen::internal::pmul(x.v, y)); }
00227 };
00228 
00229 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00230 {
00231   // TODO optimize it for SSE3 and 4
00232   Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b);
00233   __m128 s = _mm_mul_ps(b.v,b.v);
00234   return Packet2cf(_mm_div_ps(res.v,_mm_add_ps(s,_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(s), 0xb1)))));
00235 }
00236 
00237 EIGEN_STRONG_INLINE Packet2cf pcplxflip/*<Packet2cf>*/(const Packet2cf& x)
00238 {
00239   return Packet2cf(vec4f_swizzle1(x.v, 1, 0, 3, 2));
00240 }
00241 
00242 
00243 //---------- double ----------
00244 struct Packet1cd
00245 {
00246   EIGEN_STRONG_INLINE Packet1cd() {}
00247   EIGEN_STRONG_INLINE explicit Packet1cd(const __m128d& a) : v(a) {}
00248   __m128d  v;
00249 };
00250 
00251 template<> struct packet_traits<std::complex<double> >  : default_packet_traits
00252 {
00253   typedef Packet1cd type;
00254   enum {
00255     Vectorizable = 1,
00256     AlignedOnScalar = 0,
00257     size = 1,
00258 
00259     HasAdd    = 1,
00260     HasSub    = 1,
00261     HasMul    = 1,
00262     HasDiv    = 1,
00263     HasNegate = 1,
00264     HasAbs    = 0,
00265     HasAbs2   = 0,
00266     HasMin    = 0,
00267     HasMax    = 0,
00268     HasSetLinear = 0
00269   };
00270 };
00271 
00272 template<> struct unpacket_traits<Packet1cd> { typedef std::complex<double> type; enum {size=1}; };
00273 
00274 template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_add_pd(a.v,b.v)); }
00275 template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_sub_pd(a.v,b.v)); }
00276 template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(a.v)); }
00277 template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a)
00278 {
00279   const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
00280   return Packet1cd(_mm_xor_pd(a.v,mask));
00281 }
00282 
00283 template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
00284 {
00285   // TODO optimize it for SSE3 and 4
00286   #ifdef EIGEN_VECTORIZE_SSE3
00287   return Packet1cd(_mm_addsub_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
00288                                  _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
00289                                             vec2d_swizzle1(b.v, 1, 0))));
00290   #else
00291   const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0));
00292   return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
00293                               _mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
00294                                                     vec2d_swizzle1(b.v, 1, 0)), mask)));
00295   #endif
00296 }
00297 
00298 template<> EIGEN_STRONG_INLINE Packet1cd pand   <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_and_pd(a.v,b.v)); }
00299 template<> EIGEN_STRONG_INLINE Packet1cd por    <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_or_pd(a.v,b.v)); }
00300 template<> EIGEN_STRONG_INLINE Packet1cd pxor   <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_xor_pd(a.v,b.v)); }
00301 template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_andnot_pd(a.v,b.v)); }
00302 
00303 // FIXME force unaligned load, this is a temporary fix
00304 template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from)
00305 { EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>((const double*)from)); }
00306 template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from)
00307 { EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>((const double*)from)); }
00308 template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>&  from)
00309 { /* here we really have to use unaligned loads :( */ return ploadu<Packet1cd>(&from); }
00310 
00311 template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); }
00312 
00313 // FIXME force unaligned store, this is a temporary fix
00314 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); }
00315 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); }
00316 
00317 template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> *   addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
00318 
00319 template<> EIGEN_STRONG_INLINE std::complex<double>  pfirst<Packet1cd>(const Packet1cd& a)
00320 {
00321   EIGEN_ALIGN16 double res[2];
00322   _mm_store_pd(res, a.v);
00323   return std::complex<double>(res[0],res[1]);
00324 }
00325 
00326 template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; }
00327 
00328 template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a)
00329 {
00330   return pfirst(a);
00331 }
00332 
00333 template<> EIGEN_STRONG_INLINE Packet1cd preduxp<Packet1cd>(const Packet1cd* vecs)
00334 {
00335   return vecs[0];
00336 }
00337 
00338 template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a)
00339 {
00340   return pfirst(a);
00341 }
00342 
00343 template<int Offset>
00344 struct palign_impl<Offset,Packet1cd>
00345 {
00346   static EIGEN_STRONG_INLINE void run(Packet1cd& /*first*/, const Packet1cd& /*second*/)
00347   {
00348     // FIXME is it sure we never have to align a Packet1cd?
00349     // Even though a std::complex<double> has 16 bytes, it is not necessarily aligned on a 16 bytes boundary...
00350   }
00351 };
00352 
00353 template<> struct conj_helper<Packet1cd, Packet1cd, false,true>
00354 {
00355   EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const
00356   { return padd(pmul(x,y),c); }
00357 
00358   EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const
00359   {
00360     #ifdef EIGEN_VECTORIZE_SSE3
00361     return internal::pmul(a, pconj(b));
00362     #else
00363     const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
00364     return Packet1cd(_mm_add_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask),
00365                                 _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
00366                                            vec2d_swizzle1(b.v, 1, 0))));
00367     #endif
00368   }
00369 };
00370 
00371 template<> struct conj_helper<Packet1cd, Packet1cd, true,false>
00372 {
00373   EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const
00374   { return padd(pmul(x,y),c); }
00375 
00376   EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const
00377   {
00378     #ifdef EIGEN_VECTORIZE_SSE3
00379     return internal::pmul(pconj(a), b);
00380     #else
00381     const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
00382     return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
00383                                 _mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
00384                                                       vec2d_swizzle1(b.v, 1, 0)), mask)));
00385     #endif
00386   }
00387 };
00388 
00389 template<> struct conj_helper<Packet1cd, Packet1cd, true,true>
00390 {
00391   EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const
00392   { return padd(pmul(x,y),c); }
00393 
00394   EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const
00395   {
00396     #ifdef EIGEN_VECTORIZE_SSE3
00397     return pconj(internal::pmul(a, b));
00398     #else
00399     const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
00400     return Packet1cd(_mm_sub_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask),
00401                                 _mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
00402                                            vec2d_swizzle1(b.v, 1, 0))));
00403     #endif
00404   }
00405 };
00406 
00407 template<> struct conj_helper<Packet2d, Packet1cd, false,false>
00408 {
00409   EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet2d& x, const Packet1cd& y, const Packet1cd& c) const
00410   { return padd(c, pmul(x,y)); }
00411 
00412   EIGEN_STRONG_INLINE Packet1cd pmul(const Packet2d& x, const Packet1cd& y) const
00413   { return Packet1cd(Eigen::internal::pmul(x, y.v)); }
00414 };
00415 
00416 template<> struct conj_helper<Packet1cd, Packet2d, false,false>
00417 {
00418   EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet2d& y, const Packet1cd& c) const
00419   { return padd(c, pmul(x,y)); }
00420 
00421   EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& x, const Packet2d& y) const
00422   { return Packet1cd(Eigen::internal::pmul(x.v, y)); }
00423 };
00424 
00425 template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
00426 {
00427   // TODO optimize it for SSE3 and 4
00428   Packet1cd res = conj_helper<Packet1cd,Packet1cd,false,true>().pmul(a,b);
00429   __m128d s = _mm_mul_pd(b.v,b.v);
00430   return Packet1cd(_mm_div_pd(res.v, _mm_add_pd(s,_mm_shuffle_pd(s, s, 0x1))));
00431 }
00432 
00433 EIGEN_STRONG_INLINE Packet1cd pcplxflip/*<Packet1cd>*/(const Packet1cd& x)
00434 {
00435   return Packet1cd(preverse(x.v));
00436 }
00437 
00438 } // end namespace internal
00439 
00440 } // end namespace Eigen
00441 
00442 #endif // EIGEN_COMPLEX_SSE_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:36:53