Renamed allowAligned() => forceAligned() and added the constants ForceAligned

and AsRequested for the PacketAccess parameter of MapBase. Updated respective
documentation.
This commit is contained in:
Gael Guennebaud 2008-08-09 21:57:50 +00:00
parent b13148c358
commit 55e8d670ce
5 changed files with 44 additions and 30 deletions

View File

@ -33,7 +33,10 @@
* \param MatrixType the type of the object in which we are taking a block * \param MatrixType the type of the object in which we are taking a block
* \param BlockRows the number of rows of the block we are taking at compile time (optional) * \param BlockRows the number of rows of the block we are taking at compile time (optional)
* \param BlockCols the number of columns of the block we are taking at compile time (optional) * \param BlockCols the number of columns of the block we are taking at compile time (optional)
* \param _PacketAccess * \param _PacketAccess allows to enforce aligned loads and stores if set to ForceAligned.
* The default is AsRequested. This parameter is internaly used by Eigen
* in expressions such as \code mat.block() += other; \endcode and most of
* the time this is the only way it is used.
* \param _DirectAccessStatus \internal used for partial specialization * \param _DirectAccessStatus \internal used for partial specialization
* *
* This class represents an expression of either a fixed-size or dynamic-size block. It is the return * This class represents an expression of either a fixed-size or dynamic-size block. It is the return
@ -84,9 +87,9 @@ struct ei_traits<Block<MatrixType, BlockRows, BlockCols, _PacketAccess, _DirectA
CoeffReadCost = MatrixType::CoeffReadCost, CoeffReadCost = MatrixType::CoeffReadCost,
PacketAccess = _PacketAccess PacketAccess = _PacketAccess
}; };
typedef typename ei_meta_if<int(PacketAccess)==Aligned, typedef typename ei_meta_if<int(PacketAccess)==ForceAligned,
Block<MatrixType, BlockRows, BlockCols, _PacketAccess, _DirectAccessStatus>&, Block<MatrixType, BlockRows, BlockCols, _PacketAccess, _DirectAccessStatus>&,
Block<MatrixType, BlockRows, BlockCols, Aligned, _DirectAccessStatus> >::ret AlignedDerivedType; Block<MatrixType, BlockRows, BlockCols, ForceAligned, _DirectAccessStatus> >::ret AlignedDerivedType;
}; };
template<typename MatrixType, int BlockRows, int BlockCols, int PacketAccess, int _DirectAccessStatus> class Block template<typename MatrixType, int BlockRows, int BlockCols, int PacketAccess, int _DirectAccessStatus> class Block
@ -223,12 +226,12 @@ class Block<MatrixType,BlockRows,BlockCols,PacketAccess,HasDirectAccess>
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
AlignedDerivedType allowAligned() AlignedDerivedType forceAligned()
{ {
if (PacketAccess==Aligned) if (PacketAccess==ForceAligned)
return *this; return *this;
else else
return Block<MatrixType,BlockRows,BlockCols,Aligned,HasDirectAccess> return Block<MatrixType,BlockRows,BlockCols,ForceAligned,HasDirectAccess>
(m_matrix, Base::m_data, Base::m_rows.value(), Base::m_cols.value()); (m_matrix, Base::m_data, Base::m_rows.value(), Base::m_cols.value());
} }

View File

@ -30,8 +30,11 @@
* *
* \brief A matrix or vector expression mapping an existing array of data. * \brief A matrix or vector expression mapping an existing array of data.
* *
* \param _PacketAccess controls whether vectorized aligned loads or stores are allowed (Aligned) * \param MatrixType the equivalent matrix type of the mapped data
* or forced to unaligned (Unaligned). Defaults to Unaligned. * \param _PacketAccess allows to enforce aligned loads and stores if set to ForceAligned.
* The default is AsRequested. This parameter is internaly used by Eigen
* in expressions such as \code Map<...>(...) += other; \endcode and most
* of the time this is the only way it is used.
* *
* This class represents a matrix or vector expression mapping an existing array of data. * This class represents a matrix or vector expression mapping an existing array of data.
* It can be used to let Eigen interface without any overhead with non-Eigen data structures, * It can be used to let Eigen interface without any overhead with non-Eigen data structures,
@ -48,9 +51,9 @@ struct ei_traits<Map<MatrixType, _PacketAccess> > : public ei_traits<MatrixType>
PacketAccess = _PacketAccess, PacketAccess = _PacketAccess,
Flags = ei_traits<MatrixType>::Flags & ~AlignedBit Flags = ei_traits<MatrixType>::Flags & ~AlignedBit
}; };
typedef typename ei_meta_if<int(PacketAccess)==Aligned, typedef typename ei_meta_if<int(PacketAccess)==ForceAligned,
Map<MatrixType, _PacketAccess>&, Map<MatrixType, _PacketAccess>&,
Map<MatrixType, Aligned> >::ret AlignedDerivedType; Map<MatrixType, ForceAligned> >::ret AlignedDerivedType;
}; };
template<typename MatrixType, int PacketAccess> class Map template<typename MatrixType, int PacketAccess> class Map
@ -63,12 +66,12 @@ template<typename MatrixType, int PacketAccess> class Map
inline int stride() const { return this->innerSize(); } inline int stride() const { return this->innerSize(); }
AlignedDerivedType allowAligned() AlignedDerivedType forceAligned()
{ {
if (PacketAccess==Aligned) if (PacketAccess==ForceAligned)
return *this; return *this;
else else
return Map<MatrixType,Aligned>(Base::m_data, Base::m_rows.value(), Base::m_cols.value()); return Map<MatrixType,ForceAligned>(Base::m_data, Base::m_rows.value(), Base::m_cols.value());
} }
inline Map(const Scalar* data) : Base(data) {} inline Map(const Scalar* data) : Base(data) {}

View File

@ -26,12 +26,18 @@
#ifndef EIGEN_MAPBASE_H #ifndef EIGEN_MAPBASE_H
#define EIGEN_MAPBASE_H #define EIGEN_MAPBASE_H
/** \internal /** \class MapBase
*
* \class MapBase
* *
* \brief Base class for Map and Block expression with direct access * \brief Base class for Map and Block expression with direct access
* *
* Expression classes inheriting MapBase must define the constant \c PacketAccess,
* and type \c AlignedDerivedType in their respective ei_traits<> specialization structure.
* The value of \c PacketAccess can be either:
* - \b ForceAligned which enforces both aligned loads and stores
* - \b AsRequested which is the default behavior
* The type \c AlignedDerivedType should correspond to the equivalent expression type
* with \c PacketAccess being \c ForceAligned.
*
* \sa class Map, class Block * \sa class Map, class Block
*/ */
template<typename Derived> class MapBase template<typename Derived> class MapBase
@ -57,7 +63,10 @@ template<typename Derived> class MapBase
inline int cols() const { return m_cols.value(); } inline int cols() const { return m_cols.value(); }
inline int stride() const { return derived().stride(); } inline int stride() const { return derived().stride(); }
AlignedDerivedType allowAligned() { return derived().allowAligned(); }
/** \Returns an expression equivalent to \c *this but having the \c PacketAccess constant
* set to \c ForceAligned. Must be reimplemented by the derived class. */
AlignedDerivedType forceAligned() { return derived().forceAligned(); }
inline const Scalar& coeff(int row, int col) const inline const Scalar& coeff(int row, int col) const
{ {
@ -92,7 +101,7 @@ template<typename Derived> class MapBase
template<int LoadMode> template<int LoadMode>
inline PacketScalar packet(int row, int col) const inline PacketScalar packet(int row, int col) const
{ {
return ei_ploadt<Scalar, int(PacketAccess) == Aligned ? Aligned : LoadMode> return ei_ploadt<Scalar, int(PacketAccess) == ForceAligned ? Aligned : LoadMode>
(m_data + (IsRowMajor ? col + row * stride() (m_data + (IsRowMajor ? col + row * stride()
: row + col * stride())); : row + col * stride()));
} }
@ -100,13 +109,13 @@ template<typename Derived> class MapBase
template<int LoadMode> template<int LoadMode>
inline PacketScalar packet(int index) const inline PacketScalar packet(int index) const
{ {
return ei_ploadt<Scalar, int(PacketAccess) == Aligned ? Aligned : LoadMode>(m_data + index); return ei_ploadt<Scalar, int(PacketAccess) == ForceAligned ? Aligned : LoadMode>(m_data + index);
} }
template<int StoreMode> template<int StoreMode>
inline void writePacket(int row, int col, const PacketScalar& x) inline void writePacket(int row, int col, const PacketScalar& x)
{ {
ei_pstoret<Scalar, PacketScalar, int(PacketAccess) == Aligned ? Aligned : StoreMode> ei_pstoret<Scalar, PacketScalar, int(PacketAccess) == ForceAligned ? Aligned : StoreMode>
(const_cast<Scalar*>(m_data) + (IsRowMajor ? col + row * stride() (const_cast<Scalar*>(m_data) + (IsRowMajor ? col + row * stride()
: row + col * stride()), x); : row + col * stride()), x);
} }
@ -114,7 +123,7 @@ template<typename Derived> class MapBase
template<int StoreMode> template<int StoreMode>
inline void writePacket(int index, const PacketScalar& x) inline void writePacket(int index, const PacketScalar& x)
{ {
ei_pstoret<Scalar, PacketScalar, int(PacketAccess) == Aligned ? Aligned : StoreMode> ei_pstoret<Scalar, PacketScalar, int(PacketAccess) == ForceAligned ? Aligned : StoreMode>
(const_cast<Scalar*>(m_data) + index, x); (const_cast<Scalar*>(m_data) + index, x);
} }
@ -142,21 +151,19 @@ template<typename Derived> class MapBase
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MapBase) EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MapBase)
// EIGEN_INHERIT_ASSIGNMENT_OPERATOR(MapBase, =)
template<typename OtherDerived> template<typename OtherDerived>
Derived& operator+=(const MatrixBase<OtherDerived>& other) Derived& operator+=(const MatrixBase<OtherDerived>& other)
{ return derived() = allowAligned() + other; } { return derived() = forceAligned() + other; }
template<typename OtherDerived> template<typename OtherDerived>
Derived& operator-=(const MatrixBase<OtherDerived>& other) Derived& operator-=(const MatrixBase<OtherDerived>& other)
{ return derived() = allowAligned() - other; } { return derived() = forceAligned() - other; }
Derived& operator*=(const Scalar& other) Derived& operator*=(const Scalar& other)
{ return derived() = allowAligned() * other; } { return derived() = forceAligned() * other; }
Derived& operator/=(const Scalar& other) Derived& operator/=(const Scalar& other)
{ return derived() = allowAligned() / other; } { return derived() = forceAligned() / other; }
protected: protected:
const Scalar* __restrict__ m_data; const Scalar* __restrict__ m_data;

View File

@ -180,7 +180,8 @@ const unsigned int UnitUpper = UpperTriangularBit | UnitDiagBit;
const unsigned int UnitLower = LowerTriangularBit | UnitDiagBit; const unsigned int UnitLower = LowerTriangularBit | UnitDiagBit;
const unsigned int Diagonal = Upper | Lower; const unsigned int Diagonal = Upper | Lower;
enum { Aligned=0, Unaligned=1, Unknown=2 }; enum { Aligned, Unaligned };
enum { ForceAligned, AsRequested };
enum { ConditionalJumpCost = 5 }; enum { ConditionalJumpCost = 5 };
enum CornerType { TopLeft, TopRight, BottomLeft, BottomRight }; enum CornerType { TopLeft, TopRight, BottomLeft, BottomRight };
enum DirectionType { Vertical, Horizontal }; enum DirectionType { Vertical, Horizontal };

View File

@ -43,7 +43,7 @@ template<typename ExpressionType, unsigned int Added, unsigned int Removed> clas
template<typename ExpressionType> class NestByValue; template<typename ExpressionType> class NestByValue;
template<typename ExpressionType> class SwapWrapper; template<typename ExpressionType> class SwapWrapper;
template<typename MatrixType> class Minor; template<typename MatrixType> class Minor;
template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic, int PacketAccess=Unaligned, template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic, int PacketAccess=AsRequested,
int _DirectAccessStatus = ei_traits<MatrixType>::Flags&DirectAccessBit> class Block; int _DirectAccessStatus = ei_traits<MatrixType>::Flags&DirectAccessBit> class Block;
template<typename MatrixType> class Transpose; template<typename MatrixType> class Transpose;
template<typename MatrixType> class Conjugate; template<typename MatrixType> class Conjugate;
@ -53,7 +53,7 @@ template<typename BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOp;
template<typename Lhs, typename Rhs, int ProductMode> class Product; template<typename Lhs, typename Rhs, int ProductMode> class Product;
template<typename CoeffsVectorType> class DiagonalMatrix; template<typename CoeffsVectorType> class DiagonalMatrix;
template<typename MatrixType> class DiagonalCoeffs; template<typename MatrixType> class DiagonalCoeffs;
template<typename MatrixType, int PacketAccess = Unaligned> class Map; template<typename MatrixType, int PacketAccess = AsRequested> class Map;
template<typename MatrixType, unsigned int Mode> class Part; template<typename MatrixType, unsigned int Mode> class Part;
template<typename MatrixType, unsigned int Mode> class Extract; template<typename MatrixType, unsigned int Mode> class Extract;
template<typename ExpressionType> class Cwise; template<typename ExpressionType> class Cwise;