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_NEON_H
00011 #define EIGEN_COMPLEX_NEON_H
00012 
00013 namespace Eigen {
00014 
00015 namespace internal {
00016 
00017 static uint32x4_t p4ui_CONJ_XOR = EIGEN_INIT_NEON_PACKET4(0x00000000, 0x80000000, 0x00000000, 0x80000000);
00018 static uint32x2_t p2ui_CONJ_XOR = EIGEN_INIT_NEON_PACKET2(0x00000000, 0x80000000);
00019 
00020 //---------- float ----------
00021 struct Packet2cf
00022 {
00023   EIGEN_STRONG_INLINE Packet2cf() {}
00024   EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {}
00025   Packet4f  v;
00026 };
00027 
00028 template<> struct packet_traits<std::complex<float> >  : default_packet_traits
00029 {
00030   typedef Packet2cf type;
00031   enum {
00032     Vectorizable = 1,
00033     AlignedOnScalar = 1,
00034     size = 2,
00035 
00036     HasAdd    = 1,
00037     HasSub    = 1,
00038     HasMul    = 1,
00039     HasDiv    = 1,
00040     HasNegate = 1,
00041     HasAbs    = 0,
00042     HasAbs2   = 0,
00043     HasMin    = 0,
00044     HasMax    = 0,
00045     HasSetLinear = 0
00046   };
00047 };
00048 
00049 template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2}; };
00050 
00051 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>&  from)
00052 {
00053   float32x2_t r64;
00054   r64 = vld1_f32((float *)&from);
00055 
00056   return Packet2cf(vcombine_f32(r64, r64));
00057 }
00058 
00059 template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(padd<Packet4f>(a.v,b.v)); }
00060 template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(psub<Packet4f>(a.v,b.v)); }
00061 template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate<Packet4f>(a.v)); }
00062 template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a)
00063 {
00064   Packet4ui b = vreinterpretq_u32_f32(a.v);
00065   return Packet2cf(vreinterpretq_f32_u32(veorq_u32(b, p4ui_CONJ_XOR)));
00066 }
00067 
00068 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00069 {
00070   Packet4f v1, v2;
00071 
00072   // Get the real values of a | a1_re | a1_re | a2_re | a2_re |
00073   v1 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 0), vdup_lane_f32(vget_high_f32(a.v), 0));
00074   // Get the real values of a | a1_im | a1_im | a2_im | a2_im |
00075   v2 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 1), vdup_lane_f32(vget_high_f32(a.v), 1));
00076   // Multiply the real a with b
00077   v1 = vmulq_f32(v1, b.v);
00078   // Multiply the imag a with b
00079   v2 = vmulq_f32(v2, b.v);
00080   // Conjugate v2 
00081   v2 = vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(v2), p4ui_CONJ_XOR));
00082   // Swap real/imag elements in v2.
00083   v2 = vrev64q_f32(v2);
00084   // Add and return the result
00085   return Packet2cf(vaddq_f32(v1, v2));
00086 }
00087 
00088 template<> EIGEN_STRONG_INLINE Packet2cf pand   <Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00089 {
00090   return Packet2cf(vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
00091 }
00092 template<> EIGEN_STRONG_INLINE Packet2cf por    <Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00093 {
00094   return Packet2cf(vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
00095 }
00096 template<> EIGEN_STRONG_INLINE Packet2cf pxor   <Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00097 {
00098   return Packet2cf(vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
00099 }
00100 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00101 {
00102   return Packet2cf(vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
00103 }
00104 
00105 template<> EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>((const float*)from)); }
00106 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>((const float*)from)); }
00107 
00108 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); }
00109 
00110 template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> *   to, const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((float*)to, from.v); }
00111 template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> *   to, const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((float*)to, from.v); }
00112 
00113 template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> *   addr) { EIGEN_ARM_PREFETCH((float *)addr); }
00114 
00115 template<> EIGEN_STRONG_INLINE std::complex<float>  pfirst<Packet2cf>(const Packet2cf& a)
00116 {
00117   std::complex<float> EIGEN_ALIGN16 x[2];
00118   vst1q_f32((float *)x, a.v);
00119   return x[0];
00120 }
00121 
00122 template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a)
00123 {
00124   float32x2_t a_lo, a_hi;
00125   Packet4f a_r128;
00126 
00127   a_lo = vget_low_f32(a.v);
00128   a_hi = vget_high_f32(a.v);
00129   a_r128 = vcombine_f32(a_hi, a_lo);
00130 
00131   return Packet2cf(a_r128);
00132 }
00133 
00134 template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& a)
00135 {
00136   return Packet2cf(vrev64q_f32(a.v));
00137 }
00138 
00139 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
00140 {
00141   float32x2_t a1, a2;
00142   std::complex<float> s;
00143 
00144   a1 = vget_low_f32(a.v);
00145   a2 = vget_high_f32(a.v);
00146   a2 = vadd_f32(a1, a2);
00147   vst1_f32((float *)&s, a2);
00148 
00149   return s;
00150 }
00151 
00152 template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs)
00153 {
00154   Packet4f sum1, sum2, sum;
00155 
00156   // Add the first two 64-bit float32x2_t of vecs[0]
00157   sum1 = vcombine_f32(vget_low_f32(vecs[0].v), vget_low_f32(vecs[1].v));
00158   sum2 = vcombine_f32(vget_high_f32(vecs[0].v), vget_high_f32(vecs[1].v));
00159   sum = vaddq_f32(sum1, sum2);
00160 
00161   return Packet2cf(sum);
00162 }
00163 
00164 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
00165 {
00166   float32x2_t a1, a2, v1, v2, prod;
00167   std::complex<float> s;
00168 
00169   a1 = vget_low_f32(a.v);
00170   a2 = vget_high_f32(a.v);
00171    // Get the real values of a | a1_re | a1_re | a2_re | a2_re |
00172   v1 = vdup_lane_f32(a1, 0);
00173   // Get the real values of a | a1_im | a1_im | a2_im | a2_im |
00174   v2 = vdup_lane_f32(a1, 1);
00175   // Multiply the real a with b
00176   v1 = vmul_f32(v1, a2);
00177   // Multiply the imag a with b
00178   v2 = vmul_f32(v2, a2);
00179   // Conjugate v2 
00180   v2 = vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(v2), p2ui_CONJ_XOR));
00181   // Swap real/imag elements in v2.
00182   v2 = vrev64_f32(v2);
00183   // Add v1, v2
00184   prod = vadd_f32(v1, v2);
00185 
00186   vst1_f32((float *)&s, prod);
00187 
00188   return s;
00189 }
00190 
00191 template<int Offset>
00192 struct palign_impl<Offset,Packet2cf>
00193 {
00194   EIGEN_STRONG_INLINE static void run(Packet2cf& first, const Packet2cf& second)
00195   {
00196     if (Offset==1)
00197     {
00198       first.v = vextq_f32(first.v, second.v, 2);
00199     }
00200   }
00201 };
00202 
00203 template<> struct conj_helper<Packet2cf, Packet2cf, false,true>
00204 {
00205   EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
00206   { return padd(pmul(x,y),c); }
00207 
00208   EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
00209   {
00210     return internal::pmul(a, pconj(b));
00211   }
00212 };
00213 
00214 template<> struct conj_helper<Packet2cf, Packet2cf, true,false>
00215 {
00216   EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
00217   { return padd(pmul(x,y),c); }
00218 
00219   EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
00220   {
00221     return internal::pmul(pconj(a), b);
00222   }
00223 };
00224 
00225 template<> struct conj_helper<Packet2cf, Packet2cf, true,true>
00226 {
00227   EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
00228   { return padd(pmul(x,y),c); }
00229 
00230   EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
00231   {
00232     return pconj(internal::pmul(a, b));
00233   }
00234 };
00235 
00236 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00237 {
00238   // TODO optimize it for AltiVec
00239   Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b);
00240   Packet4f s, rev_s;
00241 
00242   // this computes the norm
00243   s = vmulq_f32(b.v, b.v);
00244   rev_s = vrev64q_f32(s);
00245 
00246   return Packet2cf(pdiv(res.v, vaddq_f32(s,rev_s)));
00247 }
00248 
00249 } // end namespace internal
00250 
00251 } // end namespace Eigen
00252 
00253 #endif // EIGEN_COMPLEX_NEON_H


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 20:57:55