aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2015-08-06 14:07:59 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2015-08-06 14:07:59 +0200
commit65186ef18d6212b3d09b1d619f1cf1019c2ae0fb (patch)
treef1757aa9d9d12d1abe2874885f055d6eba9ac916 /Eigen/src
parentbecd89df294a91ee3e6fefe7f5fc4e0c83dd7895 (diff)
Fix logic in compute_default_alignment, extend it to Dynamic size, and move it to XprHelper.h file.
Diffstat (limited to 'Eigen/src')
-rw-r--r--Eigen/src/Core/DenseStorage.h27
-rw-r--r--Eigen/src/Core/util/XprHelper.h39
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
}
-template<int ArrayBytes, int AlignmentBytes,
- bool Match = bool((ArrayBytes%AlignmentBytes)==0),
- bool TryHalf = bool(AlignmentBytes>EIGEN_MIN_ALIGN_BYTES) >
-struct compute_default_alignment
-{
- enum { value = 0 };
-};
-
-template<int ArrayBytes, int AlignmentBytes, bool TryHalf>
-struct compute_default_alignment<ArrayBytes, AlignmentBytes, true, TryHalf> // Match
-{
- enum { value = AlignmentBytes };
-};
-
-template<int ArrayBytes, int AlignmentBytes>
-struct compute_default_alignment<ArrayBytes, AlignmentBytes, false, true> // Try-half
-{
- // current packet too large, try with an half-packet
- enum { value = compute_default_alignment<ArrayBytes, AlignmentBytes/2>::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 <typename T, int Size, int MatrixOrArrayOptions,
int Alignment = (MatrixOrArrayOptions&DontAlign) ? 0
- : compute_default_alignment<Size*sizeof(T), EIGEN_PLAIN_ENUM_MAX(packet_traits<T>::size*sizeof(T), EIGEN_MAX_STATIC_ALIGN_BYTES) >::value >
+ : compute_default_alignment<T,Size>::value >
struct plain_array
{
T array[Size];
@@ -107,7 +86,7 @@ struct plain_array<T, Size, MatrixOrArrayOptions, 8>
EIGEN_DEVICE_FUNC
plain_array()
- {
+ {
EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7);
check_static_allocation_size<T,Size>();
}
@@ -145,7 +124,7 @@ struct plain_array<T, Size, MatrixOrArrayOptions, 32>
EIGEN_DEVICE_FUNC
plain_array()
- {
+ {
EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31);
check_static_allocation_size<T,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<typename T> struct unpacket_traits
enum {size=1};
};
+#if EIGEN_MAX_STATIC_ALIGN_BYTES>0
+template<int ArrayBytes, int AlignmentBytes,
+ bool Match = bool((ArrayBytes%AlignmentBytes)==0),
+ bool TryHalf = bool(AlignmentBytes>EIGEN_MIN_ALIGN_BYTES) >
+struct compute_default_alignment_helper
+{
+ enum { value = 0 };
+};
+
+template<int ArrayBytes, int AlignmentBytes, bool TryHalf>
+struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, true, TryHalf> // Match
+{
+ enum { value = AlignmentBytes };
+};
+
+template<int ArrayBytes, int AlignmentBytes>
+struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, false, true> // Try-half
+{
+ // current packet too large, try with an half-packet
+ enum { value = compute_default_alignment_helper<ArrayBytes, AlignmentBytes/2>::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<int ArrayBytes, int AlignmentBytes>
+struct compute_default_alignment_helper
+{
+ enum { value = 0 };
+};
+#endif
+
+template<typename T, int Size> struct compute_default_alignment {
+ enum { value = compute_default_alignment_helper<Size*sizeof(T),EIGEN_MAX_STATIC_ALIGN_BYTES>::value };
+};
+
+template<typename T> struct compute_default_alignment<T,Dynamic> {
+ enum { value = EIGEN_MAX_ALIGN_BYTES };
+};
+
template<typename _Scalar, int _Rows, int _Cols,
int _Options = AutoAlign |
( (_Rows==1 && _Cols!=1) ? RowMajor