diff options
author | 2008-08-18 16:36:47 +0000 | |
---|---|---|
committer | 2008-08-18 16:36:47 +0000 | |
commit | e778ae2559a37b65e9bdd6df687032e33c505cc4 (patch) | |
tree | d2d92879fc67d775d53d6e320fe5f22a6b90cd2c /Eigen | |
parent | baf0cffedd8774b49708eeb8b0f2c2c2b1ce51ea (diff) |
only use alloca on linux. Use malloc on other platforms. Needed for mingw
compatibility.
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Core/CacheFriendlyProduct.h | 13 | ||||
-rw-r--r-- | Eigen/src/Core/Product.h | 16 | ||||
-rw-r--r-- | Eigen/src/Core/util/Macros.h | 12 |
3 files changed, 30 insertions, 11 deletions
diff --git a/Eigen/src/Core/CacheFriendlyProduct.h b/Eigen/src/Core/CacheFriendlyProduct.h index bd9f4d0d9..782fabc88 100644 --- a/Eigen/src/Core/CacheFriendlyProduct.h +++ b/Eigen/src/Core/CacheFriendlyProduct.h @@ -90,11 +90,10 @@ static void ei_cache_friendly_product( const bool needRhsCopy = (PacketSize>1) && ((rhsStride%PacketSize!=0) || (size_t(rhs)%16!=0)); Scalar* __restrict__ block = 0; const int allocBlockSize = sizeof(Scalar)*l2BlockRows*size; - if (allocBlockSize>16000000) - block = (Scalar*)malloc(allocBlockSize); - else - block = (Scalar*)alloca(allocBlockSize); - Scalar* __restrict__ rhsCopy = (Scalar*)alloca(sizeof(Scalar)*l2BlockSizeAligned*l2BlockSizeAligned); + const bool allocBlockUsingAlloca = EIGEN_USE_ALLOCA && allocBlockSize<=16000000; + block = (Scalar*)ei_alloca_or_malloc(allocBlockUsingAlloca, allocBlockSize); + Scalar* __restrict__ rhsCopy + = (Scalar*)ei_alloca_or_malloc(true, sizeof(Scalar)*l2BlockSizeAligned*l2BlockSizeAligned); // loops on each L2 cache friendly blocks of the result for(int l2i=0; l2i<rows; l2i+=l2BlockRows) @@ -341,8 +340,10 @@ static void ei_cache_friendly_product( } } - if (allocBlockSize>16000000) + if (!allocBlockUsingAlloca) free(block); + if (!EIGEN_USE_ALLOCA) + free(rhsCopy); } #endif // EIGEN_EXTERN_INSTANTIATIONS diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index d57c9d241..9bdbe3f26 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -548,7 +548,7 @@ struct ei_cache_friendly_product_selector<ProductType,LhsRows,ColMajor,HasDirect _res = &res.coeffRef(0); else { - _res = (Scalar*)alloca(sizeof(Scalar)*res.size()); + _res = (Scalar*)ei_alloca_or_malloc(true, sizeof(Scalar)*res.size()); Map<Matrix<Scalar,DestDerived::RowsAtCompileTime,1> >(_res, res.size()) = res; } ei_cache_friendly_product_colmajor_times_vector(res.size(), @@ -557,6 +557,8 @@ struct ei_cache_friendly_product_selector<ProductType,LhsRows,ColMajor,HasDirect if (!EvalToRes) res = Map<Matrix<Scalar,DestDerived::SizeAtCompileTime,1> >(_res, res.size()); + + if(!EIGEN_USE_ALLOCA) free(_res); } }; @@ -591,7 +593,7 @@ struct ei_cache_friendly_product_selector<ProductType,1,LhsOrder,LhsAccess,RhsCo _res = &res.coeffRef(0); else { - _res = (Scalar*)alloca(sizeof(Scalar)*res.size()); + _res = (Scalar*)ei_alloca_or_malloc(true, sizeof(Scalar)*res.size()); Map<Matrix<Scalar,DestDerived::SizeAtCompileTime,1> >(_res, res.size()) = res; } ei_cache_friendly_product_colmajor_times_vector(res.size(), @@ -600,6 +602,8 @@ struct ei_cache_friendly_product_selector<ProductType,1,LhsOrder,LhsAccess,RhsCo if (!EvalToRes) res = Map<Matrix<Scalar,DestDerived::SizeAtCompileTime,1> >(_res, res.size()); + + if(!EIGEN_USE_ALLOCA) free(_res); } }; @@ -621,11 +625,13 @@ struct ei_cache_friendly_product_selector<ProductType,LhsRows,RowMajor,HasDirect _rhs = &product.rhs().const_cast_derived().coeffRef(0); else { - _rhs = (Scalar*)alloca(sizeof(Scalar)*product.rhs().size()); + _rhs = (Scalar*)ei_alloca_or_malloc(true, sizeof(Scalar)*product.rhs().size()); Map<Matrix<Scalar,Rhs::SizeAtCompileTime,1> >(_rhs, product.rhs().size()) = product.rhs(); } ei_cache_friendly_product_rowmajor_times_vector(&product.lhs().const_cast_derived().coeffRef(0,0), product.lhs().stride(), _rhs, product.rhs().size(), res); + + if(!EIGEN_USE_ALLOCA) free(_rhs); } }; @@ -647,11 +653,13 @@ struct ei_cache_friendly_product_selector<ProductType,1,LhsOrder,LhsAccess,RhsCo _lhs = &product.lhs().const_cast_derived().coeffRef(0); else { - _lhs = (Scalar*)alloca(sizeof(Scalar)*product.lhs().size()); + _lhs = (Scalar*)ei_alloca_or_malloc(true, sizeof(Scalar)*product.lhs().size()); Map<Matrix<Scalar,Lhs::SizeAtCompileTime,1> >(_lhs, product.lhs().size()) = product.lhs(); } ei_cache_friendly_product_rowmajor_times_vector(&product.rhs().const_cast_derived().coeffRef(0,0), product.rhs().stride(), _lhs, product.lhs().size(), res); + + if(!EIGEN_USE_ALLOCA) free(_lhs); } }; diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 647cfcbfa..51b7a8669 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -52,7 +52,9 @@ using Eigen::Matrix; \ using Eigen::MatrixBase; #ifdef NDEBUG -#define EIGEN_NO_DEBUG +# ifndef EIGEN_NO_DEBUG +# define EIGEN_NO_DEBUG +# endif #endif #ifndef ei_assert @@ -146,4 +148,12 @@ friend class Eigen::MatrixBase<Derived>; #define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) #define EIGEN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b) +#ifdef __linux__ +# define EIGEN_USE_ALLOCA 1 +# define ei_alloca_or_malloc(condition, size) (condition?alloca(size):malloc(size)) +#else +# define EIGEN_USE_ALLOCA 0 +# define ei_alloca_or_malloc(condition, size) malloc(size) +#endif + #endif // EIGEN_MACROS_H |