00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef EIGEN_GENERIC_PACKET_MATH_H
00012 #define EIGEN_GENERIC_PACKET_MATH_H
00013
00014 namespace Eigen {
00015
00016 namespace internal {
00017
00026 #ifndef EIGEN_DEBUG_ALIGNED_LOAD
00027 #define EIGEN_DEBUG_ALIGNED_LOAD
00028 #endif
00029
00030 #ifndef EIGEN_DEBUG_UNALIGNED_LOAD
00031 #define EIGEN_DEBUG_UNALIGNED_LOAD
00032 #endif
00033
00034 #ifndef EIGEN_DEBUG_ALIGNED_STORE
00035 #define EIGEN_DEBUG_ALIGNED_STORE
00036 #endif
00037
00038 #ifndef EIGEN_DEBUG_UNALIGNED_STORE
00039 #define EIGEN_DEBUG_UNALIGNED_STORE
00040 #endif
00041
00042 struct default_packet_traits
00043 {
00044 enum {
00045 HasAdd = 1,
00046 HasSub = 1,
00047 HasMul = 1,
00048 HasNegate = 1,
00049 HasAbs = 1,
00050 HasAbs2 = 1,
00051 HasMin = 1,
00052 HasMax = 1,
00053 HasConj = 1,
00054 HasSetLinear = 1,
00055
00056 HasDiv = 0,
00057 HasSqrt = 0,
00058 HasExp = 0,
00059 HasLog = 0,
00060 HasPow = 0,
00061
00062 HasSin = 0,
00063 HasCos = 0,
00064 HasTan = 0,
00065 HasASin = 0,
00066 HasACos = 0,
00067 HasATan = 0
00068 };
00069 };
00070
00071 template<typename T> struct packet_traits : default_packet_traits
00072 {
00073 typedef T type;
00074 enum {
00075 Vectorizable = 0,
00076 size = 1,
00077 AlignedOnScalar = 0
00078 };
00079 enum {
00080 HasAdd = 0,
00081 HasSub = 0,
00082 HasMul = 0,
00083 HasNegate = 0,
00084 HasAbs = 0,
00085 HasAbs2 = 0,
00086 HasMin = 0,
00087 HasMax = 0,
00088 HasConj = 0,
00089 HasSetLinear = 0
00090 };
00091 };
00092
00094 template<typename Packet> inline Packet
00095 padd(const Packet& a,
00096 const Packet& b) { return a+b; }
00097
00099 template<typename Packet> inline Packet
00100 psub(const Packet& a,
00101 const Packet& b) { return a-b; }
00102
00104 template<typename Packet> inline Packet
00105 pnegate(const Packet& a) { return -a; }
00106
00108 template<typename Packet> inline Packet
00109 pconj(const Packet& a) { return conj(a); }
00110
00112 template<typename Packet> inline Packet
00113 pmul(const Packet& a,
00114 const Packet& b) { return a*b; }
00115
00117 template<typename Packet> inline Packet
00118 pdiv(const Packet& a,
00119 const Packet& b) { return a/b; }
00120
00122 template<typename Packet> inline Packet
00123 pmin(const Packet& a,
00124 const Packet& b) { using std::min; return (min)(a, b); }
00125
00127 template<typename Packet> inline Packet
00128 pmax(const Packet& a,
00129 const Packet& b) { using std::max; return (max)(a, b); }
00130
00132 template<typename Packet> inline Packet
00133 pabs(const Packet& a) { return abs(a); }
00134
00136 template<typename Packet> inline Packet
00137 pand(const Packet& a, const Packet& b) { return a & b; }
00138
00140 template<typename Packet> inline Packet
00141 por(const Packet& a, const Packet& b) { return a | b; }
00142
00144 template<typename Packet> inline Packet
00145 pxor(const Packet& a, const Packet& b) { return a ^ b; }
00146
00148 template<typename Packet> inline Packet
00149 pandnot(const Packet& a, const Packet& b) { return a & (!b); }
00150
00152 template<typename Packet> inline Packet
00153 pload(const typename unpacket_traits<Packet>::type* from) { return *from; }
00154
00156 template<typename Packet> inline Packet
00157 ploadu(const typename unpacket_traits<Packet>::type* from) { return *from; }
00158
00160 template<typename Packet> inline Packet
00161 ploaddup(const typename unpacket_traits<Packet>::type* from) { return *from; }
00162
00164 template<typename Packet> inline Packet
00165 pset1(const typename unpacket_traits<Packet>::type& a) { return a; }
00166
00168 template<typename Scalar> inline typename packet_traits<Scalar>::type
00169 plset(const Scalar& a) { return a; }
00170
00172 template<typename Scalar, typename Packet> inline void pstore(Scalar* to, const Packet& from)
00173 { (*to) = from; }
00174
00176 template<typename Scalar, typename Packet> inline void pstoreu(Scalar* to, const Packet& from)
00177 { (*to) = from; }
00178
00180 template<typename Scalar> inline void prefetch(const Scalar* addr)
00181 {
00182 #if !defined(_MSC_VER)
00183 __builtin_prefetch(addr);
00184 #endif
00185 }
00186
00188 template<typename Packet> inline typename unpacket_traits<Packet>::type pfirst(const Packet& a)
00189 { return a; }
00190
00192 template<typename Packet> inline Packet
00193 preduxp(const Packet* vecs) { return vecs[0]; }
00194
00196 template<typename Packet> inline typename unpacket_traits<Packet>::type predux(const Packet& a)
00197 { return a; }
00198
00200 template<typename Packet> inline typename unpacket_traits<Packet>::type predux_mul(const Packet& a)
00201 { return a; }
00202
00204 template<typename Packet> inline typename unpacket_traits<Packet>::type predux_min(const Packet& a)
00205 { return a; }
00206
00208 template<typename Packet> inline typename unpacket_traits<Packet>::type predux_max(const Packet& a)
00209 { return a; }
00210
00212 template<typename Packet> inline Packet preverse(const Packet& a)
00213 { return a; }
00214
00215
00217 template<typename Packet> inline Packet pcplxflip(const Packet& a)
00218 { return Packet(imag(a),real(a)); }
00219
00220
00221
00222
00223
00225 template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00226 Packet psin(const Packet& a) { return sin(a); }
00227
00229 template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00230 Packet pcos(const Packet& a) { return cos(a); }
00231
00233 template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00234 Packet ptan(const Packet& a) { return tan(a); }
00235
00237 template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00238 Packet pasin(const Packet& a) { return asin(a); }
00239
00241 template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00242 Packet pacos(const Packet& a) { return acos(a); }
00243
00245 template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00246 Packet pexp(const Packet& a) { return exp(a); }
00247
00249 template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00250 Packet plog(const Packet& a) { return log(a); }
00251
00253 template<typename Packet> EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00254 Packet psqrt(const Packet& a) { return sqrt(a); }
00255
00256
00257
00258
00259
00261
00262 template<typename Packet>
00263 inline void pstore1(typename unpacket_traits<Packet>::type* to, const typename unpacket_traits<Packet>::type& a)
00264 {
00265 pstore(to, pset1<Packet>(a));
00266 }
00267
00269 template<typename Packet> inline Packet
00270 pmadd(const Packet& a,
00271 const Packet& b,
00272 const Packet& c)
00273 { return padd(pmul(a, b),c); }
00274
00277 template<typename Packet, int LoadMode>
00278 inline Packet ploadt(const typename unpacket_traits<Packet>::type* from)
00279 {
00280 if(LoadMode == Aligned)
00281 return pload<Packet>(from);
00282 else
00283 return ploadu<Packet>(from);
00284 }
00285
00288 template<typename Scalar, typename Packet, int LoadMode>
00289 inline void pstoret(Scalar* to, const Packet& from)
00290 {
00291 if(LoadMode == Aligned)
00292 pstore(to, from);
00293 else
00294 pstoreu(to, from);
00295 }
00296
00298 template<int Offset,typename PacketType>
00299 struct palign_impl
00300 {
00301
00302 static inline void run(PacketType&, const PacketType&) {}
00303 };
00304
00307 template<int Offset,typename PacketType>
00308 inline void palign(PacketType& first, const PacketType& second)
00309 {
00310 palign_impl<Offset,PacketType>::run(first,second);
00311 }
00312
00313
00314
00315
00316
00317 template<> inline std::complex<float> pmul(const std::complex<float>& a, const std::complex<float>& b)
00318 { return std::complex<float>(real(a)*real(b) - imag(a)*imag(b), imag(a)*real(b) + real(a)*imag(b)); }
00319
00320 template<> inline std::complex<double> pmul(const std::complex<double>& a, const std::complex<double>& b)
00321 { return std::complex<double>(real(a)*real(b) - imag(a)*imag(b), imag(a)*real(b) + real(a)*imag(b)); }
00322
00323 }
00324
00325 }
00326
00327 #endif // EIGEN_GENERIC_PACKET_MATH_H
00328