From 65186ef18d6212b3d09b1d619f1cf1019c2ae0fb Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 6 Aug 2015 14:07:59 +0200 Subject: [PATCH] Fix logic in compute_default_alignment, extend it to Dynamic size, and move it to XprHelper.h file. --- Eigen/src/Core/DenseStorage.h | 27 +++-------------------- Eigen/src/Core/util/XprHelper.h | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/Eigen/src/Core/DenseStorage.h b/Eigen/src/Core/DenseStorage.h index 5edf8a4ee..340484610 100644 --- a/Eigen/src/Core/DenseStorage.h +++ b/Eigen/src/Core/DenseStorage.h @@ -34,34 +34,13 @@ void check_static_allocation_size() #endif } -templateEIGEN_MIN_ALIGN_BYTES) > -struct compute_default_alignment -{ - enum { value = 0 }; -}; - -template -struct compute_default_alignment // Match -{ - enum { value = AlignmentBytes }; -}; - -template -struct compute_default_alignment // Try-half -{ - // current packet too large, try with an half-packet - enum { value = compute_default_alignment::value }; -}; - /** \internal * Static array. If the MatrixOrArrayOptions require auto-alignment, the array will be automatically aligned: * to 16 bytes boundary if the total size is a multiple of 16 bytes. */ template ::size*sizeof(T), EIGEN_MAX_STATIC_ALIGN_BYTES) >::value > + : compute_default_alignment::value > struct plain_array { T array[Size]; @@ -107,7 +86,7 @@ struct plain_array EIGEN_DEVICE_FUNC plain_array() - { + { EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7); check_static_allocation_size(); } @@ -145,7 +124,7 @@ struct plain_array EIGEN_DEVICE_FUNC plain_array() - { + { EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31); check_static_allocation_size(); } diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 433e816af..6dc1f6e3f 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -122,6 +122,45 @@ template struct unpacket_traits enum {size=1}; }; +#if EIGEN_MAX_STATIC_ALIGN_BYTES>0 +templateEIGEN_MIN_ALIGN_BYTES) > +struct compute_default_alignment_helper +{ + enum { value = 0 }; +}; + +template +struct compute_default_alignment_helper // Match +{ + enum { value = AlignmentBytes }; +}; + +template +struct compute_default_alignment_helper // Try-half +{ + // current packet too large, try with an half-packet + enum { value = compute_default_alignment_helper::value }; +}; +#else +// If static alignment is disabled, no need to bother. +// This also avoids a division by zero in "bool Match = bool((ArrayBytes%AlignmentBytes)==0)" +template +struct compute_default_alignment_helper +{ + enum { value = 0 }; +}; +#endif + +template struct compute_default_alignment { + enum { value = compute_default_alignment_helper::value }; +}; + +template struct compute_default_alignment { + enum { value = EIGEN_MAX_ALIGN_BYTES }; +}; + template