AssignmentFunctors.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-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_ASSIGNMENT_FUNCTORS_H
11 #define EIGEN_ASSIGNMENT_FUNCTORS_H
12 
13 #include "../InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 namespace internal {
18 
23 template<typename DstScalar,typename SrcScalar> struct assign_op {
24 
25  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a = b; }
26 
27  template<int Alignment, typename Packet>
28  EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
29  { internal::pstoret<DstScalar,Packet,Alignment>(a,b); }
30 };
31 
32 // Empty overload for void type (used by PermutationMatrix)
33 template<typename DstScalar> struct assign_op<DstScalar,void> {};
34 
35 template<typename DstScalar,typename SrcScalar>
36 struct functor_traits<assign_op<DstScalar,SrcScalar> > {
37  enum {
39  PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::Vectorizable && packet_traits<SrcScalar>::Vectorizable
40  };
41 };
42 
47 template<typename DstScalar,typename SrcScalar> struct add_assign_op {
48 
49  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a += b; }
50 
51  template<int Alignment, typename Packet>
52  EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
53  { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::padd(internal::ploadt<Packet,Alignment>(a),b)); }
54 };
55 template<typename DstScalar,typename SrcScalar>
56 struct functor_traits<add_assign_op<DstScalar,SrcScalar> > {
57  enum {
59  PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasAdd
60  };
61 };
62 
67 template<typename DstScalar,typename SrcScalar> struct sub_assign_op {
68 
69  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a -= b; }
70 
71  template<int Alignment, typename Packet>
72  EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
73  { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::psub(internal::ploadt<Packet,Alignment>(a),b)); }
74 };
75 template<typename DstScalar,typename SrcScalar>
76 struct functor_traits<sub_assign_op<DstScalar,SrcScalar> > {
77  enum {
79  PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasSub
80  };
81 };
82 
87 template<typename DstScalar, typename SrcScalar=DstScalar>
88 struct mul_assign_op {
89 
90  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a *= b; }
91 
92  template<int Alignment, typename Packet>
93  EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
94  { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::pmul(internal::ploadt<Packet,Alignment>(a),b)); }
95 };
96 template<typename DstScalar, typename SrcScalar>
97 struct functor_traits<mul_assign_op<DstScalar,SrcScalar> > {
98  enum {
100  PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasMul
101  };
102 };
103 
108 template<typename DstScalar, typename SrcScalar=DstScalar> struct div_assign_op {
109 
110  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a /= b; }
111 
112  template<int Alignment, typename Packet>
113  EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
114  { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::pdiv(internal::ploadt<Packet,Alignment>(a),b)); }
115 };
116 template<typename DstScalar, typename SrcScalar>
117 struct functor_traits<div_assign_op<DstScalar,SrcScalar> > {
118  enum {
120  PacketAccess = is_same<DstScalar,SrcScalar>::value && packet_traits<DstScalar>::HasDiv
121  };
122 };
123 
139 template<typename Scalar> struct swap_assign_op {
140 
141  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Scalar& a, const Scalar& b) const
142  {
143 #ifdef EIGEN_GPUCC
144  // FIXME is there some kind of cuda::swap?
145  Scalar t=b; const_cast<Scalar&>(b)=a; a=t;
146 #else
147  using std::swap;
148  swap(a,const_cast<Scalar&>(b));
149 #endif
150  }
151 };
152 template<typename Scalar>
153 struct functor_traits<swap_assign_op<Scalar> > {
154  enum {
155  Cost = 3 * NumTraits<Scalar>::ReadCost,
156  PacketAccess =
157  #if defined(EIGEN_VECTORIZE_AVX) && (EIGEN_CLANG_STRICT_LESS_THAN(8,0,0) || EIGEN_COMP_CLANGAPPLE)
158  // This is a partial workaround for a bug in clang generating bad code
159  // when mixing 256/512 bits loads and 128 bits moves.
160  // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1684
161  // https://bugs.llvm.org/show_bug.cgi?id=40815
162  0
163  #else
164  packet_traits<Scalar>::Vectorizable
165  #endif
166  };
167 };
168 
169 } // namespace internal
170 
171 } // namespace Eigen
172 
173 #endif // EIGEN_ASSIGNMENT_FUNCTORS_H
Array< int, 3, 1 > b
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
Packet padd(const Packet &a, const Packet &b)
Packet pmul(const Packet &a, const Packet &b)
Packet psub(const Packet &a, const Packet &b)
Packet pdiv(const Packet &a, const Packet &b)
void swap(scoped_array< T > &a, scoped_array< T > &b)
Definition: Memory.h:788
: InteropHeaders
Definition: Core:139