mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-16 14:49:39 +08:00
Fix 128bit packet size assumptions in unit tests.
This commit is contained in:
parent
a7d20038df
commit
2606abed53
@ -105,6 +105,8 @@ public:
|
||||
EIGEN_DEBUG_VAR(DstIsAligned)
|
||||
EIGEN_DEBUG_VAR(SrcIsAligned)
|
||||
EIGEN_DEBUG_VAR(JointAlignment)
|
||||
EIGEN_DEBUG_VAR(Derived::SizeAtCompileTime)
|
||||
EIGEN_DEBUG_VAR(OtherDerived::CoeffReadCost)
|
||||
EIGEN_DEBUG_VAR(InnerSize)
|
||||
EIGEN_DEBUG_VAR(InnerMaxSize)
|
||||
EIGEN_DEBUG_VAR(PacketSize)
|
||||
|
@ -66,8 +66,7 @@ template<typename Lhs, typename Rhs> struct product_type
|
||||
MaxDepth = EIGEN_SIZE_MIN_PREFER_FIXED(_Lhs::MaxColsAtCompileTime,
|
||||
_Rhs::MaxRowsAtCompileTime),
|
||||
Depth = EIGEN_SIZE_MIN_PREFER_FIXED(_Lhs::ColsAtCompileTime,
|
||||
_Rhs::RowsAtCompileTime),
|
||||
LargeThreshold = EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
|
||||
_Rhs::RowsAtCompileTime)
|
||||
};
|
||||
|
||||
// the splitting into different lines of code here, introducing the _select enums and the typedef below,
|
||||
|
@ -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 ?
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user