Allow all tests to pass with EIGEN_TEST_NO_EXPLICIT_VECTORIZATION

This commit is contained in:
Antonio Sánchez 2022-04-12 14:48:22 +00:00
parent efb08e0bb5
commit 3342fc7e4d
5 changed files with 28 additions and 13 deletions

View File

@ -100,11 +100,12 @@ void dense_storage_alignment()
VERIFY_IS_EQUAL( (std::alignment_of<internal::plain_array<T,Size,AutoAlign,Alignment> >::value), Alignment);
const std::size_t default_alignment = internal::compute_default_alignment<T,Size>::value;
if (default_alignment > 0) {
VERIFY_IS_EQUAL( (std::alignment_of<DenseStorage<T,Size,1,1,AutoAlign> >::value), default_alignment);
VERIFY_IS_EQUAL( (std::alignment_of<Matrix<T,Size,1,AutoAlign> >::value), default_alignment);
struct Nested2 { Matrix<T,Size,1,AutoAlign> mat; };
VERIFY_IS_EQUAL(std::alignment_of<Nested2>::value, default_alignment);
}
}
template<typename T>

View File

@ -20,9 +20,12 @@ typedef Matrix<float,8,1> Vector8f;
void check_handmade_aligned_malloc()
{
// Hand-make alignment needs at least sizeof(void*) to store the offset.
constexpr int alignment = (std::max<int>)(EIGEN_DEFAULT_ALIGN_BYTES, sizeof(void*));
for(int i = 1; i < 1000; i++)
{
char *p = (char*)internal::handmade_aligned_malloc(i);
char *p = (char*)internal::handmade_aligned_malloc(i, alignment);
VERIFY(internal::UIntPtr(p)%ALIGNMENT==0);
// if the buffer is wrongly allocated this will give a bad write --> check with valgrind
for(int j = 0; j < i; j++) p[j]=0;

View File

@ -510,7 +510,9 @@ EIGEN_DECLARE_TEST(evaluators)
const size_t K = 2;
const size_t N = 5;
float *destMem = new float[(M*N) + 1];
float *dest = (internal::UIntPtr(destMem)%EIGEN_MAX_ALIGN_BYTES) == 0 ? destMem+1 : destMem;
// In case of no alignment, avoid division by zero.
constexpr int alignment = (std::max<int>)(EIGEN_MAX_ALIGN_BYTES, 1);
float *dest = (internal::UIntPtr(destMem)%alignment) == 0 ? destMem+1 : destMem;
const Matrix<float, Dynamic, Dynamic, RowMajor> a = Matrix<float, Dynamic, Dynamic, RowMajor>::Random(M, K);
const Matrix<float, Dynamic, Dynamic, RowMajor> b = Matrix<float, Dynamic, Dynamic, RowMajor>::Random(K, N);

View File

@ -20,7 +20,9 @@ template<typename VectorType> void map_class_vector(const VectorType& m)
Scalar* array1 = internal::aligned_new<Scalar>(size);
Scalar* array2 = internal::aligned_new<Scalar>(size);
Scalar* array3 = new Scalar[size+1];
Scalar* array3unaligned = (internal::UIntPtr(array3)%EIGEN_MAX_ALIGN_BYTES) == 0 ? array3+1 : array3;
// In case of no alignment, avoid division by zero.
constexpr int alignment = (std::max<int>)(EIGEN_MAX_ALIGN_BYTES, 1);
Scalar* array3unaligned = (internal::UIntPtr(array3)%alignment) == 0 ? array3+1 : array3;
Scalar array4[EIGEN_TESTMAP_MAX_SIZE];
Map<VectorType, AlignedMax>(array1, size) = VectorType::Random(size);
@ -60,7 +62,9 @@ template<typename MatrixType> void map_class_matrix(const MatrixType& m)
Scalar* array3 = new Scalar[size+1];
Index sizep1 = size + 1; // <- without this temporary MSVC 2103 generates bad code
for(Index i = 0; i < sizep1; i++) array3[i] = Scalar(1);
Scalar* array3unaligned = (internal::UIntPtr(array3)%EIGEN_MAX_ALIGN_BYTES) == 0 ? array3+1 : array3;
// In case of no alignment, avoid division by zero.
constexpr int alignment = (std::max<int>)(EIGEN_MAX_ALIGN_BYTES, 1);
Scalar* array3unaligned = (internal::UIntPtr(array3)%alignment) == 0 ? array3+1 : array3;
Scalar array4[256];
if(size<=256)
for(int i = 0; i < size; i++) array4[i] = Scalar(1);
@ -123,7 +127,9 @@ template<typename VectorType> void map_static_methods(const VectorType& m)
Scalar* array1 = internal::aligned_new<Scalar>(size);
Scalar* array2 = internal::aligned_new<Scalar>(size);
Scalar* array3 = new Scalar[size+1];
Scalar* array3unaligned = internal::UIntPtr(array3)%EIGEN_MAX_ALIGN_BYTES == 0 ? array3+1 : array3;
// In case of no alignment, avoid division by zero.
constexpr int alignment = (std::max<int>)(EIGEN_MAX_ALIGN_BYTES, 1);
Scalar* array3unaligned = (internal::UIntPtr(array3)%alignment) == 0 ? array3+1 : array3;
VectorType::MapAligned(array1, size) = VectorType::Random(size);
VectorType::Map(array2, size) = VectorType::Map(array1, size);

View File

@ -65,10 +65,13 @@ template<int Alignment,typename MatrixType> void map_class_matrix(const MatrixTy
Scalar a_array2[256];
Scalar* array2 = a_array2;
if(Alignment!=Aligned)
if(Alignment!=Aligned) {
array2 = (Scalar*)(internal::IntPtr(a_array2) + (internal::packet_traits<Scalar>::AlignedOnScalar?sizeof(Scalar):sizeof(typename NumTraits<Scalar>::Real)));
else
array2 = (Scalar*)(((internal::UIntPtr(a_array2)+EIGEN_MAX_ALIGN_BYTES-1)/EIGEN_MAX_ALIGN_BYTES)*EIGEN_MAX_ALIGN_BYTES);
} else {
// In case there is no alignment, default to pointing to the start.
constexpr int alignment = (std::max<int>)(EIGEN_MAX_ALIGN_BYTES, 1);
array2 = (Scalar*)(((internal::UIntPtr(a_array2)+alignment-1)/alignment)*alignment);
}
Index maxsize2 = a_array2 - array2 + 256;
// test no inner stride and some dynamic outer stride