GenericPacketMath.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_GENERIC_PACKET_MATH_H
12 #define EIGEN_GENERIC_PACKET_MATH_H
13 
14 namespace Eigen {
15 
16 namespace internal {
17 
26 #ifndef EIGEN_DEBUG_ALIGNED_LOAD
27 #define EIGEN_DEBUG_ALIGNED_LOAD
28 #endif
29 
30 #ifndef EIGEN_DEBUG_UNALIGNED_LOAD
31 #define EIGEN_DEBUG_UNALIGNED_LOAD
32 #endif
33 
34 #ifndef EIGEN_DEBUG_ALIGNED_STORE
35 #define EIGEN_DEBUG_ALIGNED_STORE
36 #endif
37 
38 #ifndef EIGEN_DEBUG_UNALIGNED_STORE
39 #define EIGEN_DEBUG_UNALIGNED_STORE
40 #endif
41 
43 {
44  enum {
45  HasAdd = 1,
46  HasSub = 1,
47  HasMul = 1,
48  HasNegate = 1,
49  HasAbs = 1,
50  HasAbs2 = 1,
51  HasMin = 1,
52  HasMax = 1,
53  HasConj = 1,
55 
56  HasDiv = 0,
57  HasSqrt = 0,
58  HasExp = 0,
59  HasLog = 0,
60  HasPow = 0,
61 
62  HasSin = 0,
63  HasCos = 0,
64  HasTan = 0,
65  HasASin = 0,
66  HasACos = 0,
67  HasATan = 0
68  };
69 };
70 
71 template<typename T> struct packet_traits : default_packet_traits
72 {
73  typedef T type;
74  enum {
75  Vectorizable = 0,
76  size = 1,
77  AlignedOnScalar = 0
78  };
79  enum {
80  HasAdd = 0,
81  HasSub = 0,
82  HasMul = 0,
83  HasNegate = 0,
84  HasAbs = 0,
85  HasAbs2 = 0,
86  HasMin = 0,
87  HasMax = 0,
88  HasConj = 0,
90  };
91 };
92 
94 template<typename Packet> inline Packet
95 padd(const Packet& a,
96  const Packet& b) { return a+b; }
97 
99 template<typename Packet> inline Packet
100 psub(const Packet& a,
101  const Packet& b) { return a-b; }
102 
104 template<typename Packet> inline Packet
105 pnegate(const Packet& a) { return -a; }
106 
108 template<typename Packet> inline Packet
109 pconj(const Packet& a) { return numext::conj(a); }
110 
112 template<typename Packet> inline Packet
113 pmul(const Packet& a,
114  const Packet& b) { return a*b; }
115 
117 template<typename Packet> inline Packet
118 pdiv(const Packet& a,
119  const Packet& b) { return a/b; }
120 
122 template<typename Packet> inline Packet
123 pmin(const Packet& a,
124  const Packet& b) { using std::min; return (min)(a, b); }
125 
127 template<typename Packet> inline Packet
128 pmax(const Packet& a,
129  const Packet& b) { using std::max; return (max)(a, b); }
130 
132 template<typename Packet> inline Packet
133 pabs(const Packet& a) { using std::abs; return abs(a); }
134 
136 template<typename Packet> inline Packet
137 pand(const Packet& a, const Packet& b) { return a & b; }
138 
140 template<typename Packet> inline Packet
141 por(const Packet& a, const Packet& b) { return a | b; }
142 
144 template<typename Packet> inline Packet
145 pxor(const Packet& a, const Packet& b) { return a ^ b; }
146 
148 template<typename Packet> inline Packet
149 pandnot(const Packet& a, const Packet& b) { return a & (!b); }
150 
152 template<typename Packet> inline Packet
153 pload(const typename unpacket_traits<Packet>::type* from) { return *from; }
154 
156 template<typename Packet> inline Packet
157 ploadu(const typename unpacket_traits<Packet>::type* from) { return *from; }
158 
164 template<typename Packet> inline Packet
165 ploaddup(const typename unpacket_traits<Packet>::type* from) { return *from; }
166 
168 template<typename Packet> inline Packet
169 pset1(const typename unpacket_traits<Packet>::type& a) { return a; }
170 
172 template<typename Scalar> inline typename packet_traits<Scalar>::type
173 plset(const Scalar& a) { return a; }
174 
176 template<typename Scalar, typename Packet> inline void pstore(Scalar* to, const Packet& from)
177 { (*to) = from; }
178 
180 template<typename Scalar, typename Packet> inline void pstoreu(Scalar* to, const Packet& from)
181 { (*to) = from; }
182 
184 template<typename Scalar> inline void prefetch(const Scalar* addr)
185 {
186 #if !defined(_MSC_VER)
187 __builtin_prefetch(addr);
188 #endif
189 }
190 
192 template<typename Packet> inline typename unpacket_traits<Packet>::type pfirst(const Packet& a)
193 { return a; }
194 
196 template<typename Packet> inline Packet
197 preduxp(const Packet* vecs) { return vecs[0]; }
198 
200 template<typename Packet> inline typename unpacket_traits<Packet>::type predux(const Packet& a)
201 { return a; }
202 
204 template<typename Packet> inline typename unpacket_traits<Packet>::type predux_mul(const Packet& a)
205 { return a; }
206 
208 template<typename Packet> inline typename unpacket_traits<Packet>::type predux_min(const Packet& a)
209 { return a; }
210 
212 template<typename Packet> inline typename unpacket_traits<Packet>::type predux_max(const Packet& a)
213 { return a; }
214 
216 template<typename Packet> inline Packet preverse(const Packet& a)
217 { return a; }
218 
219 
221 template<typename Packet> inline Packet pcplxflip(const Packet& a)
222 {
223  // FIXME: uncomment the following in case we drop the internal imag and real functions.
224 // using std::imag;
225 // using std::real;
226  return Packet(imag(a),real(a));
227 }
228 
229 /**************************
230 * Special math functions
231 ***************************/
232 
235 Packet psin(const Packet& a) { using std::sin; return sin(a); }
236 
239 Packet pcos(const Packet& a) { using std::cos; return cos(a); }
240 
243 Packet ptan(const Packet& a) { using std::tan; return tan(a); }
244 
247 Packet pasin(const Packet& a) { using std::asin; return asin(a); }
248 
251 Packet pacos(const Packet& a) { using std::acos; return acos(a); }
252 
255 Packet pexp(const Packet& a) { using std::exp; return exp(a); }
256 
259 Packet plog(const Packet& a) { using std::log; return log(a); }
260 
263 Packet psqrt(const Packet& a) { using std::sqrt; return sqrt(a); }
264 
265 /***************************************************************************
266 * The following functions might not have to be overwritten for vectorized types
267 ***************************************************************************/
268 
270 // NOTE: this function must really be templated on the packet type (think about different packet types for the same scalar type)
271 template<typename Packet>
272 inline void pstore1(typename unpacket_traits<Packet>::type* to, const typename unpacket_traits<Packet>::type& a)
273 {
274  pstore(to, pset1<Packet>(a));
275 }
276 
278 template<typename Packet> inline Packet
279 pmadd(const Packet& a,
280  const Packet& b,
281  const Packet& c)
282 { return padd(pmul(a, b),c); }
283 
286 template<typename Packet, int LoadMode>
287 inline Packet ploadt(const typename unpacket_traits<Packet>::type* from)
288 {
289  if(LoadMode == Aligned)
290  return pload<Packet>(from);
291  else
292  return ploadu<Packet>(from);
293 }
294 
297 template<typename Scalar, typename Packet, int LoadMode>
298 inline void pstoret(Scalar* to, const Packet& from)
299 {
300  if(LoadMode == Aligned)
301  pstore(to, from);
302  else
303  pstoreu(to, from);
304 }
305 
307 template<int Offset,typename PacketType>
309 {
310  // by default data are aligned, so there is nothing to be done :)
311  static inline void run(PacketType&, const PacketType&) {}
312 };
313 
329 template<int Offset,typename PacketType>
330 inline void palign(PacketType& first, const PacketType& second)
331 {
333 }
334 
335 /***************************************************************************
336 * Fast complex products (GCC generates a function call which is very slow)
337 ***************************************************************************/
338 
339 template<> inline std::complex<float> pmul(const std::complex<float>& a, const std::complex<float>& b)
340 { return std::complex<float>(real(a)*real(b) - imag(a)*imag(b), imag(a)*real(b) + real(a)*imag(b)); }
341 
342 template<> inline std::complex<double> pmul(const std::complex<double>& a, const std::complex<double>& b)
343 { return std::complex<double>(real(a)*real(b) - imag(a)*imag(b), imag(a)*real(b) + real(a)*imag(b)); }
344 
345 } // end namespace internal
346 
347 } // end namespace Eigen
348 
349 #endif // EIGEN_GENERIC_PACKET_MATH_H
350 
unpacket_traits< Packet >::type predux_min(const Packet &a)
void palign(PacketType &first, const PacketType &second)
unpacket_traits< Packet >::type predux_mul(const Packet &a)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pasin(const Packet &a)
Packet pload(const typename unpacket_traits< Packet >::type *from)
Packet ploaddup(const typename unpacket_traits< Packet >::type *from)
#define EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Definition: LDLT.h:16
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psqrt(const Packet &a)
Packet preduxp(const Packet *vecs)
const ImagReturnType imag() const
Packet pand(const Packet &a, const Packet &b)
EIGEN_STRONG_INLINE Packet2cf pcplxflip(const Packet2cf &x)
Definition: SSE/Complex.h:237
void pstore(Scalar *to, const Packet &from)
Packet pmax(const Packet &a, const Packet &b)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp(const Packet &a)
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > abs() const
RealReturnType real() const
void pstoret(Scalar *to, const Packet &from)
void pstoreu(Scalar *to, const Packet &from)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptan(const Packet &a)
void prefetch(const Scalar *addr)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pacos(const Packet &a)
const CwiseUnaryOp< internal::scalar_tan_op< Scalar >, Derived > tan() const
Packet psub(const Packet &a, const Packet &b)
void pstore1(typename unpacket_traits< Packet >::type *to, const typename unpacket_traits< Packet >::type &a)
Packet pmin(const Packet &a, const Packet &b)
unpacket_traits< Packet >::type pfirst(const Packet &a)
const CwiseUnaryOp< internal::scalar_log_op< Scalar >, const Derived > log() const
unpacket_traits< Packet >::type predux(const Packet &a)
EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf &a)
const CwiseUnaryOp< internal::scalar_sin_op< Scalar >, const Derived > sin() const
Packet por(const Packet &a, const Packet &b)
Packet pxor(const Packet &a, const Packet &b)
Packet pdiv(const Packet &a, const Packet &b)
unpacket_traits< Packet >::type predux_max(const Packet &a)
EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf &a)
Packet ploadu(const typename unpacket_traits< Packet >::type *from)
int min(int a, int b)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog(const Packet &a)
Packet pset1(const typename unpacket_traits< Packet >::type &a)
EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
Packet pmul(const Packet &a, const Packet &b)
Packet ploadt(const typename unpacket_traits< Packet >::type *from)
const CwiseUnaryOp< internal::scalar_cos_op< Scalar >, const Derived > cos() const
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcos(const Packet &a)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin(const Packet &a)
const CwiseUnaryOp< internal::scalar_sqrt_op< Scalar >, const Derived > sqrt() const
const CwiseUnaryOp< internal::scalar_exp_op< Scalar >, const Derived > exp() const
const CwiseUnaryOp< internal::scalar_asin_op< Scalar >, const Derived > asin() const
static void run(PacketType &, const PacketType &)
const CwiseUnaryOp< internal::scalar_acos_op< Scalar >, const Derived > acos() const
Packet pandnot(const Packet &a, const Packet &b)
Packet padd(const Packet &a, const Packet &b)
packet_traits< Scalar >::type plset(const Scalar &a)
EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf &a)
EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f &a)


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:50