From 8175fe43e0d2a662bcc9c057e1e5b69a88d15b8f Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Mon, 28 Mar 2011 21:29:47 +0100 Subject: [PATCH] Evaluators: Make inner vectorization more similar to default traversal. --- Eigen/src/Core/AssignEvaluator.h | 7 ++- Eigen/src/Core/CoreEvaluators.h | 103 ++++++++++--------------------- 2 files changed, 38 insertions(+), 72 deletions(-) diff --git a/Eigen/src/Core/AssignEvaluator.h b/Eigen/src/Core/AssignEvaluator.h index 0b90ef70fe..78014c6f95 100644 --- a/Eigen/src/Core/AssignEvaluator.h +++ b/Eigen/src/Core/AssignEvaluator.h @@ -259,8 +259,11 @@ struct copy_using_evaluator_impl::size; for(Index outer = 0; outer < outerSize; ++outer) - for(Index inner = 0; inner < innerSize; inner+=packetSize) - dstEvaluator.template writePacketByOuterInner(outer, inner, srcEvaluator.template packetByOuterInner(outer, inner)); + for(Index inner = 0; inner < innerSize; inner+=packetSize) { + Index row = dst.rowIndexByOuterInner(outer, inner); + Index col = dst.colIndexByOuterInner(outer, inner); + dstEvaluator.template writePacket(row, col, srcEvaluator.template packet(row, col)); + } } }; diff --git a/Eigen/src/Core/CoreEvaluators.h b/Eigen/src/Core/CoreEvaluators.h index 734936681e..008285b4c2 100644 --- a/Eigen/src/Core/CoreEvaluators.h +++ b/Eigen/src/Core/CoreEvaluators.h @@ -75,18 +75,23 @@ struct evaluator_impl > return m_argImpl.coeffRef(index); } + // TODO: Difference between PacketScalar and PacketReturnType? + template + const typename ExpressionType::PacketScalar packet(Index row, Index col) const + { + return m_argImpl.template packet(col, row); + } + template const typename ExpressionType::PacketScalar packet(Index index) const { return m_argImpl.template packet(index); } - // TODO: Difference between PacketScalar and PacketReturnType? - // TODO: Get this function by inheriting from DenseCoeffBase? - template - const typename ExpressionType::PacketScalar packetByOuterInner(Index outer, Index inner) const + template + void writePacket(Index row, Index col, const typename ExpressionType::PacketScalar& x) { - return m_argImpl.template packetByOuterInner(outer, inner); + m_argImpl.template writePacket(col, row, x); } template @@ -95,12 +100,6 @@ struct evaluator_impl > m_argImpl.template writePacket(index, x); } - template - void writePacketByOuterInner(Index outer, Index inner, const typename ExpressionType::PacketScalar& x) - { - m_argImpl.template writePacketByOuterInner(outer, inner, x); - } - protected: typename evaluator::type m_argImpl; }; @@ -116,16 +115,6 @@ struct evaluator_impl > typedef typename MatrixType::Index Index; - Index colIndexByOuterInner(Index outer, Index inner) const - { - return m_matrix.colIndexByOuterInner(outer, inner); - } - - Index rowIndexByOuterInner(Index outer, Index inner) const - { - return m_matrix.rowIndexByOuterInner(outer, inner); - } - typename MatrixType::CoeffReturnType coeff(Index i, Index j) const { return m_matrix.coeff(i, j); @@ -146,13 +135,6 @@ struct evaluator_impl > return m_matrix.const_cast_derived().coeffRef(index); } - template - typename MatrixType::PacketReturnType packet(Index index) const - { - // eigen_internal_assert(index >= 0 && index < size()); - return m_matrix.template packet(index); - } - template typename MatrixType::PacketReturnType packet(Index row, Index col) const { @@ -160,9 +142,16 @@ struct evaluator_impl > } template - typename MatrixType::PacketReturnType packetByOuterInner(Index outer, Index inner) const + typename MatrixType::PacketReturnType packet(Index index) const { - return m_matrix.template packetByOuterInner(outer, inner); + // eigen_internal_assert(index >= 0 && index < size()); + return m_matrix.template packet(index); + } + + template + void writePacket(Index row, Index col, const typename MatrixType::PacketScalar& x) + { + m_matrix.const_cast_derived().template writePacket(row, col, x); } template @@ -172,12 +161,6 @@ struct evaluator_impl > m_matrix.const_cast_derived().template writePacket(index, x); } - template - void writePacketByOuterInner(Index outer, Index inner, const typename MatrixType::PacketScalar& x) - { - m_matrix.const_cast_derived().template writePacketByOuterInner(outer, inner, x); - } - protected: const MatrixType &m_matrix; }; @@ -195,16 +178,16 @@ struct evaluator_impl > typedef typename ArrayType::Index Index; - Index colIndexByOuterInner(Index outer, Index inner) const - { - return m_array.colIndexByOuterInner(outer, inner); - } - typename ArrayType::CoeffReturnType coeff(Index i, Index j) const { return m_array.coeff(i, j); } + typename ArrayType::CoeffReturnType coeff(Index index) const + { + return m_array.coeff(index); + } + typename ArrayType::Scalar& coeffRef(Index i, Index j) { return m_array.const_cast_derived().coeffRef(i, j); @@ -215,13 +198,6 @@ struct evaluator_impl > return m_array.const_cast_derived().coeffRef(index); } - template - typename ArrayType::PacketReturnType packet(Index index) const - { - // eigen_internal_assert(index >= 0 && index < size()); - return m_array.template packet(index); - } - template typename ArrayType::PacketReturnType packet(Index row, Index col) const { @@ -229,9 +205,16 @@ struct evaluator_impl > } template - typename ArrayType::PacketReturnType packetByOuterInner(Index outer, Index inner) const + typename ArrayType::PacketReturnType packet(Index index) const { - return m_array.template packetByOuterInner(outer, inner); + // eigen_internal_assert(index >= 0 && index < size()); + return m_array.template packet(index); + } + + template + void writePacket(Index row, Index col, const typename ArrayType::PacketScalar& x) + { + m_array.const_cast_derived().template writePacket(row, col, x); } template @@ -241,12 +224,6 @@ struct evaluator_impl > m_array.const_cast_derived().template writePacket(index, x); } - template - void writePacketByOuterInner(Index outer, Index inner, const typename ArrayType::PacketScalar& x) - { - m_array.const_cast_derived().template writePacketByOuterInner(outer, inner, x); - } - protected: const ArrayType &m_array; }; @@ -315,13 +292,6 @@ struct evaluator_impl > return m_unaryOp.functor().packetOp(m_argImpl.template packet(row, col)); } - template - typename UnaryOpType::PacketScalar packetByOuterInner(Index outer, Index inner) const - { - return packet(m_argImpl.rowIndexByOuterInner(outer, inner), - m_argImpl.colIndexByOuterInner(outer, inner)); - } - protected: const UnaryOpType& m_unaryOp; typename evaluator::type m_argImpl; @@ -362,13 +332,6 @@ struct evaluator_impl > m_rhsImpl.template packet(row, col)); } - template - typename BinaryOpType::PacketScalar packetByOuterInner(Index outer, Index inner) const - { - return packet(m_lhsImpl.rowIndexByOuterInner(outer, inner), - m_lhsImpl.colIndexByOuterInner(outer, inner)); - } - protected: const BinaryOpType& m_binaryOp; typename evaluator::type m_lhsImpl;