From 3c98677376fb33f11fe2f786a49bc97b07743711 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 10 Oct 2007 06:33:09 +0000 Subject: fix big bug in loop unrolling --- src/Core/Dot.h | 10 +++++----- src/Core/MatrixOps.h | 18 +++++------------- src/Core/Trace.h | 13 ++++--------- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/Core/Dot.h b/src/Core/Dot.h index 0d000ea70..ea9653f8a 100644 --- a/src/Core/Dot.h +++ b/src/Core/Dot.h @@ -32,12 +32,12 @@ struct EiDotUnroller static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot) { EiDotUnroller::run(v1, v2, dot); - dot += v1[Index-1] * EiConj(v2[Index-1]); + dot += v1[Index] * EiConj(v2[Index]); } }; template -struct EiDotUnroller<1, Size, Derived1, Derived2> +struct EiDotUnroller<0, Size, Derived1, Derived2> { static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot) { @@ -45,8 +45,8 @@ struct EiDotUnroller<1, Size, Derived1, Derived2> } }; -template -struct EiDotUnroller +template +struct EiDotUnroller { static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot) { @@ -63,7 +63,7 @@ Scalar EiObject::dot(const OtherDerived& other) const assert(IsVector && OtherDerived::IsVector && size() == other.size()); Scalar res; if(SizeAtCompileTime != EiDynamic && SizeAtCompileTime <= 16) - EiDotUnroller + EiDotUnroller ::run(*static_cast(this), other, res); else { diff --git a/src/Core/MatrixOps.h b/src/Core/MatrixOps.h index eb1682ab0..1449a3923 100644 --- a/src/Core/MatrixOps.h +++ b/src/Core/MatrixOps.h @@ -111,12 +111,8 @@ struct EiMatrixProductUnroller static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, typename Lhs::Scalar &res) { - const int i = Index - 1; EiMatrixProductUnroller::run(row, col, lhs, rhs, res); - if(i == Size - 1) - res = lhs.read(row, i) * rhs.read(i, col); - else - res += lhs.read(row, i) * rhs.read(i, col); + res += lhs.read(row, Index) * rhs.read(Index, col); } }; @@ -126,16 +122,12 @@ struct EiMatrixProductUnroller<0, Size, Lhs, Rhs> static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, typename Lhs::Scalar &res) { - EI_UNUSED(row); - EI_UNUSED(col); - EI_UNUSED(lhs); - EI_UNUSED(rhs); - EI_UNUSED(res); + res = lhs.read(row, 0) * rhs.read(0, col); } }; -template -struct EiMatrixProductUnroller +template +struct EiMatrixProductUnroller { static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, typename Lhs::Scalar &res) @@ -181,7 +173,7 @@ template class EiMatrixProduct { Scalar res; if(Lhs::ColsAtCompileTime != EiDynamic && Lhs::ColsAtCompileTime <= 16) - EiMatrixProductUnroller + EiMatrixProductUnroller ::run(row, col, m_lhs, m_rhs, res); else { diff --git a/src/Core/Trace.h b/src/Core/Trace.h index df62118e1..80c5dbed1 100644 --- a/src/Core/Trace.h +++ b/src/Core/Trace.h @@ -30,12 +30,8 @@ template struct EiTraceUnroller { static void run(const Derived &mat, typename Derived::Scalar &trace) { - const int i = Index - 1; EiTraceUnroller::run(mat, trace); - if(i == Rows - 1) - trace = mat(i, i); - else - trace += mat(i, i); + trace += mat(Index, Index); } }; @@ -43,12 +39,11 @@ template struct EiTraceUnroller<0, Rows, Derived> { static void run(const Derived &mat, typename Derived::Scalar &trace) { - EI_UNUSED(mat); - EI_UNUSED(trace); + trace = mat(0, 0); } }; -template struct EiTraceUnroller +template struct EiTraceUnroller { static void run(const Derived &mat, typename Derived::Scalar &trace) { @@ -63,7 +58,7 @@ Scalar EiObject::trace() const assert(rows() == cols()); Scalar res; if(RowsAtCompileTime != EiDynamic && RowsAtCompileTime <= 16) - EiTraceUnroller + EiTraceUnroller ::run(*static_cast(this), res); else { -- cgit v1.2.3