diff options
author | Gael Guennebaud <g.gael@free.fr> | 2014-04-18 21:14:40 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2014-04-18 21:14:40 +0200 |
commit | 2606abed535744fcaa41b923c71338a06b8ed3fa (patch) | |
tree | cafa7c6567e2982d1395e2db63b692f34cdb1e1d /test | |
parent | a7d20038df1dc160e282e824052ff5bcf5ba2c9a (diff) |
Fix 128bit packet size assumptions in unit tests.
Diffstat (limited to 'test')
-rw-r--r-- | test/dynalloc.cpp | 21 | ||||
-rw-r--r-- | test/unalignedassert.cpp | 37 | ||||
-rw-r--r-- | test/vectorization_logic.cpp | 23 |
3 files changed, 49 insertions, 32 deletions
diff --git a/test/dynalloc.cpp b/test/dynalloc.cpp index 8bbda1c94..c98cc80f0 100644 --- a/test/dynalloc.cpp +++ b/test/dynalloc.cpp @@ -10,11 +10,13 @@ #include "main.h" #if EIGEN_ALIGN -#define ALIGNMENT 16 +#define ALIGNMENT EIGEN_ALIGN_BYTES #else #define ALIGNMENT 1 #endif +typedef Matrix<float,8,1> Vector8f; + void check_handmade_aligned_malloc() { for(int i = 1; i < 1000; i++) @@ -68,7 +70,7 @@ struct MyStruct { EIGEN_MAKE_ALIGNED_OPERATOR_NEW char dummychar; - Vector4f avec; + Vector8f avec; }; class MyClassA @@ -76,15 +78,19 @@ class MyClassA public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW char dummychar; - Vector4f avec; + Vector8f avec; }; template<typename T> void check_dynaligned() { - T* obj = new T; - VERIFY(T::NeedsToAlign==1); - VERIFY(size_t(obj)%ALIGNMENT==0); - delete obj; + // TODO have to be updated once we support multiple alignment values + if(T::SizeAtCompileTime % ALIGNMENT == 0) + { + T* obj = new T; + VERIFY(T::NeedsToAlign==1); + VERIFY(size_t(obj)%ALIGNMENT==0); + delete obj; + } } void test_dynalloc() @@ -102,6 +108,7 @@ void test_dynalloc() CALL_SUBTEST(check_dynaligned<Matrix4f>() ); CALL_SUBTEST(check_dynaligned<Vector4d>() ); CALL_SUBTEST(check_dynaligned<Vector4i>() ); + CALL_SUBTEST(check_dynaligned<Vector8f>() ); } // check static allocation, who knows ? diff --git a/test/unalignedassert.cpp b/test/unalignedassert.cpp index 601dbf214..d8815263a 100644 --- a/test/unalignedassert.cpp +++ b/test/unalignedassert.cpp @@ -9,6 +9,8 @@ #include "main.h" +typedef Matrix<float,8,1> Vector8f; + struct TestNew1 { MatrixXd m; // good: m will allocate its own array, taking care of alignment. @@ -69,7 +71,7 @@ void construct_at_boundary(int boundary) { char buf[sizeof(T)+256]; size_t _buf = reinterpret_cast<size_t>(buf); - _buf += (16 - (_buf % 16)); // make 16-byte aligned + _buf += (EIGEN_ALIGN_BYTES - (_buf % EIGEN_ALIGN_BYTES)); // make 16/32-byte aligned _buf += boundary; // make exact boundary-aligned T *x = ::new(reinterpret_cast<void*>(_buf)) T; x[0].setZero(); // just in order to silence warnings @@ -85,18 +87,18 @@ void unalignedassert() construct_at_boundary<Vector4f>(16); construct_at_boundary<Matrix2f>(16); construct_at_boundary<Matrix3f>(4); - construct_at_boundary<Matrix4f>(16); + construct_at_boundary<Matrix4f>(EIGEN_ALIGN_BYTES); construct_at_boundary<Vector2d>(16); construct_at_boundary<Vector3d>(4); - construct_at_boundary<Vector4d>(16); - construct_at_boundary<Matrix2d>(16); + construct_at_boundary<Vector4d>(EIGEN_ALIGN_BYTES); + construct_at_boundary<Matrix2d>(EIGEN_ALIGN_BYTES); construct_at_boundary<Matrix3d>(4); - construct_at_boundary<Matrix4d>(16); + construct_at_boundary<Matrix4d>(EIGEN_ALIGN_BYTES); construct_at_boundary<Vector2cf>(16); construct_at_boundary<Vector3cf>(4); - construct_at_boundary<Vector2cd>(16); + construct_at_boundary<Vector2cd>(EIGEN_ALIGN_BYTES); construct_at_boundary<Vector3cd>(16); #endif @@ -110,14 +112,21 @@ void unalignedassert() check_unalignedassert_good<Depends<true> >(); #if EIGEN_ALIGN_STATICALLY - VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4f>(8)); - VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4f>(8)); - VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2d>(8)); - VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4d>(8)); - VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix2d>(8)); - VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4d>(8)); - VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cf>(8)); - VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cd>(8)); + if(EIGEN_ALIGN_BYTES==16) + { + VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4f>(8)); + VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2d>(8)); + VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cf>(8)); + } + for(int b=8; b<EIGEN_ALIGN_BYTES; b+=8) + { + VERIFY_RAISES_ASSERT(construct_at_boundary<Vector8f>(b)); + VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4f>(b)); + VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4d>(b)); + VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix2d>(b)); + VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4d>(b)); + VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cd>(b)); + } #endif } diff --git a/test/vectorization_logic.cpp b/test/vectorization_logic.cpp index aee68a87f..09b46660b 100644 --- a/test/vectorization_logic.cpp +++ b/test/vectorization_logic.cpp @@ -90,8 +90,8 @@ template<typename Scalar, bool Enable = internal::packet_traits<Scalar>::Vectori typedef Matrix<Scalar,2*PacketSize,2*PacketSize> Matrix22; typedef Matrix<Scalar,(Matrix11::Flags&RowMajorBit)?16:4*PacketSize,(Matrix11::Flags&RowMajorBit)?4*PacketSize:16> Matrix44; typedef Matrix<Scalar,(Matrix11::Flags&RowMajorBit)?16:4*PacketSize,(Matrix11::Flags&RowMajorBit)?4*PacketSize:16,DontAlign|EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION> Matrix44u; - typedef Matrix<Scalar,4*PacketSize,16,ColMajor> Matrix44c; - typedef Matrix<Scalar,4*PacketSize,16,RowMajor> Matrix44r; + typedef Matrix<Scalar,4*PacketSize,4*PacketSize,ColMajor> Matrix44c; + typedef Matrix<Scalar,4*PacketSize,4*PacketSize,RowMajor> Matrix44r; typedef Matrix<Scalar, (PacketSize==8 ? 4 : PacketSize==4 ? 2 : PacketSize==2 ? 1 : /*PacketSize==1 ?*/ 1), @@ -149,15 +149,15 @@ template<typename Scalar, bool Enable = internal::packet_traits<Scalar>::Vectori LinearTraversal,CompleteUnrolling)); VERIFY(test_assign(Matrix33c().col(0),Matrix33c().col(1)+Matrix33c().col(1), LinearTraversal,CompleteUnrolling)); - + VERIFY(test_assign(Matrix3(),Matrix3().cwiseQuotient(Matrix3()), LinearVectorizedTraversal,CompleteUnrolling)); - + VERIFY(test_assign(Matrix<Scalar,17,17>(),Matrix<Scalar,17,17>()+Matrix<Scalar,17,17>(), LinearTraversal,NoUnrolling)); - - VERIFY(test_assign(Matrix11(),Matrix<Scalar,17,17>().template block<PacketSize,PacketSize>(2,3)+Matrix<Scalar,17,17>().template block<PacketSize,PacketSize>(10,4), - DefaultTraversal,CompleteUnrolling)); + + VERIFY(test_assign(Matrix11(),Matrix<Scalar,17,17>().template block<PacketSize,PacketSize>(2,3)+Matrix<Scalar,17,17>().template block<PacketSize,PacketSize>(8,4), + DefaultTraversal,PacketSize>4?InnerUnrolling:CompleteUnrolling)); } VERIFY(test_redux(Matrix3(), @@ -174,18 +174,19 @@ template<typename Scalar, bool Enable = internal::packet_traits<Scalar>::Vectori VERIFY(test_redux(Matrix44r().template block<1,2*PacketSize>(2,1), LinearVectorizedTraversal,CompleteUnrolling)); - + VERIFY((test_assign< Map<Matrix22, Aligned, OuterStride<3*PacketSize> >, Matrix22 >(InnerVectorizedTraversal,CompleteUnrolling))); VERIFY((test_assign< - Map<Matrix22, Aligned, InnerStride<3*PacketSize> >, - Matrix22 + Map<Matrix<Scalar,EIGEN_PLAIN_ENUM_MAX(2,PacketSize),EIGEN_PLAIN_ENUM_MAX(2,PacketSize)>, Aligned, InnerStride<3*PacketSize> >, + Matrix<Scalar,EIGEN_PLAIN_ENUM_MAX(2,PacketSize),EIGEN_PLAIN_ENUM_MAX(2,PacketSize)> >(DefaultTraversal,CompleteUnrolling))); - VERIFY((test_assign(Matrix11(), Matrix11()*Matrix11(), InnerVectorizedTraversal, CompleteUnrolling))); + VERIFY((test_assign(Matrix11(), Matrix<Scalar,PacketSize,EIGEN_PLAIN_ENUM_MIN(2,PacketSize)>()*Matrix<Scalar,EIGEN_PLAIN_ENUM_MIN(2,PacketSize),PacketSize>(), + PacketSize>=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD?DefaultTraversal:InnerVectorizedTraversal, CompleteUnrolling))); #endif VERIFY(test_assign(MatrixXX(10,10),MatrixXX(20,20).block(10,10,2,3), |