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


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:30:58