Replaced all instances of internal::(U)IntPtr with std::(u)intptr_t. Remove ICC workaround.

This commit is contained in:
Colin Broderick
2023-03-21 16:50:23 +00:00
committed by Rasmus Munk Larsen
parent 2c8011c2dd
commit 8f9b8e3630
19 changed files with 52 additions and 68 deletions

View File

@@ -26,7 +26,7 @@ void check_handmade_aligned_malloc()
for(int i = 1; i < 1000; i++)
{
char *p = (char*)internal::handmade_aligned_malloc(i, alignment);
VERIFY(internal::UIntPtr(p)%ALIGNMENT==0);
VERIFY(std::uintptr_t(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;
internal::handmade_aligned_free(p);
@@ -38,7 +38,7 @@ void check_aligned_malloc()
for(int i = ALIGNMENT; i < 1000; i++)
{
char *p = (char*)internal::aligned_malloc(i);
VERIFY(internal::UIntPtr(p)%ALIGNMENT==0);
VERIFY(std::uintptr_t(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;
internal::aligned_free(p);
@@ -50,7 +50,7 @@ void check_aligned_new()
for(int i = ALIGNMENT; i < 1000; i++)
{
float *p = internal::aligned_new<float>(i);
VERIFY(internal::UIntPtr(p)%ALIGNMENT==0);
VERIFY(std::uintptr_t(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;
internal::aligned_delete(p,i);
@@ -62,7 +62,7 @@ void check_aligned_stack_alloc()
for(int i = ALIGNMENT; i < 400; i++)
{
ei_declare_aligned_stack_constructed_variable(float,p,i,0);
VERIFY(internal::UIntPtr(p)%ALIGNMENT==0);
VERIFY(std::uintptr_t(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;
}
@@ -92,7 +92,7 @@ template<typename T> void check_dynaligned()
{
T* obj = new T;
VERIFY(T::NeedsToAlign==1);
VERIFY(internal::UIntPtr(obj)%ALIGNMENT==0);
VERIFY(std::uintptr_t(obj)%ALIGNMENT==0);
delete obj;
}
}
@@ -153,15 +153,15 @@ EIGEN_DECLARE_TEST(dynalloc)
}
{
MyStruct foo0; VERIFY(internal::UIntPtr(foo0.avec.data())%ALIGNMENT==0);
MyClassA fooA; VERIFY(internal::UIntPtr(fooA.avec.data())%ALIGNMENT==0);
MyStruct foo0; VERIFY(std::uintptr_t(foo0.avec.data())%ALIGNMENT==0);
MyClassA fooA; VERIFY(std::uintptr_t(fooA.avec.data())%ALIGNMENT==0);
}
// dynamic allocation, single object
for (int i=0; i<g_repeat*100; ++i)
{
MyStruct *foo0 = new MyStruct(); VERIFY(internal::UIntPtr(foo0->avec.data())%ALIGNMENT==0);
MyClassA *fooA = new MyClassA(); VERIFY(internal::UIntPtr(fooA->avec.data())%ALIGNMENT==0);
MyStruct *foo0 = new MyStruct(); VERIFY(std::uintptr_t(foo0->avec.data())%ALIGNMENT==0);
MyClassA *fooA = new MyClassA(); VERIFY(std::uintptr_t(fooA->avec.data())%ALIGNMENT==0);
delete foo0;
delete fooA;
}
@@ -170,8 +170,8 @@ EIGEN_DECLARE_TEST(dynalloc)
const int N = 10;
for (int i=0; i<g_repeat*100; ++i)
{
MyStruct *foo0 = new MyStruct[N]; VERIFY(internal::UIntPtr(foo0->avec.data())%ALIGNMENT==0);
MyClassA *fooA = new MyClassA[N]; VERIFY(internal::UIntPtr(fooA->avec.data())%ALIGNMENT==0);
MyStruct *foo0 = new MyStruct[N]; VERIFY(std::uintptr_t(foo0->avec.data())%ALIGNMENT==0);
MyClassA *fooA = new MyClassA[N]; VERIFY(std::uintptr_t(fooA->avec.data())%ALIGNMENT==0);
delete[] foo0;
delete[] fooA;
}

View File

@@ -512,7 +512,7 @@ EIGEN_DECLARE_TEST(evaluators)
float *destMem = new float[(M*N) + 1];
// 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;
float *dest = (std::uintptr_t(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

@@ -41,7 +41,7 @@ EIGEN_DECLARE_TEST(first_aligned)
test_first_aligned_helper(array_double+1, 50);
test_first_aligned_helper(array_double+2, 50);
double *array_double_plus_4_bytes = (double*)(internal::UIntPtr(array_double)+4);
double *array_double_plus_4_bytes = (double*)(std::uintptr_t(array_double)+4);
test_none_aligned_helper(array_double_plus_4_bytes, 50);
test_none_aligned_helper(array_double_plus_4_bytes+1, 50);

View File

@@ -22,7 +22,7 @@ template<typename VectorType> void map_class_vector(const VectorType& m)
Scalar* array3 = new Scalar[size+1];
// 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* array3unaligned = (std::uintptr_t(array3)%alignment) == 0 ? array3+1 : array3;
Scalar array4[EIGEN_TESTMAP_MAX_SIZE];
Map<VectorType, AlignedMax>(array1, size) = VectorType::Random(size);
@@ -64,7 +64,7 @@ template<typename MatrixType> void map_class_matrix(const MatrixType& m)
for(Index i = 0; i < sizep1; i++) array3[i] = Scalar(1);
// 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* array3unaligned = (std::uintptr_t(array3)%alignment) == 0 ? array3+1 : array3;
Scalar array4[256];
if(size<=256)
for(int i = 0; i < size; i++) array4[i] = Scalar(1);
@@ -129,7 +129,7 @@ template<typename VectorType> void map_static_methods(const VectorType& m)
Scalar* array3 = new Scalar[size+1];
// 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* array3unaligned = (std::uintptr_t(array3)%alignment) == 0 ? array3+1 : array3;
VectorType::MapAligned(array1, size) = VectorType::Random(size);
VectorType::Map(array2, size) = VectorType::Map(array1, size);

View File

@@ -22,7 +22,7 @@ template<int Alignment,typename VectorType> void map_class_vector(const VectorTy
Scalar* a_array = internal::aligned_new<Scalar>(arraysize+1);
Scalar* array = a_array;
if(Alignment!=Aligned)
array = (Scalar*)(internal::IntPtr(a_array) + (internal::packet_traits<Scalar>::AlignedOnScalar?sizeof(Scalar):sizeof(typename NumTraits<Scalar>::Real)));
array = (Scalar*)(std::intptr_t(a_array) + (internal::packet_traits<Scalar>::AlignedOnScalar?sizeof(Scalar):sizeof(typename NumTraits<Scalar>::Real)));
{
Map<VectorType, Alignment, InnerStride<3> > map(array, size);
@@ -61,16 +61,16 @@ template<int Alignment,typename MatrixType> void map_class_matrix(const MatrixTy
Scalar* a_array1 = internal::aligned_new<Scalar>(arraysize+1);
Scalar* array1 = a_array1;
if(Alignment!=Aligned)
array1 = (Scalar*)(internal::IntPtr(a_array1) + (internal::packet_traits<Scalar>::AlignedOnScalar?sizeof(Scalar):sizeof(typename NumTraits<Scalar>::Real)));
array1 = (Scalar*)(std::intptr_t(a_array1) + (internal::packet_traits<Scalar>::AlignedOnScalar?sizeof(Scalar):sizeof(typename NumTraits<Scalar>::Real)));
Scalar a_array2[256];
Scalar* array2 = a_array2;
if(Alignment!=Aligned) {
array2 = (Scalar*)(internal::IntPtr(a_array2) + (internal::packet_traits<Scalar>::AlignedOnScalar?sizeof(Scalar):sizeof(typename NumTraits<Scalar>::Real)));
array2 = (Scalar*)(std::intptr_t(a_array2) + (internal::packet_traits<Scalar>::AlignedOnScalar?sizeof(Scalar):sizeof(typename NumTraits<Scalar>::Real)));
} 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);
array2 = (Scalar*)(((std::uintptr_t(a_array2)+alignment-1)/alignment)*alignment);
}
Index maxsize2 = a_array2 - array2 + 256;

View File

@@ -15,8 +15,6 @@
#include <Eigen/Core>
using internal::UIntPtr;
template <typename MatrixType>
void rvalue_copyassign(const MatrixType& m)
{
@@ -25,18 +23,18 @@ void rvalue_copyassign(const MatrixType& m)
// create a temporary which we are about to destroy by moving
MatrixType tmp = m;
UIntPtr src_address = reinterpret_cast<UIntPtr>(tmp.data());
std::uintptr_t src_address = reinterpret_cast<std::uintptr_t>(tmp.data());
Eigen::internal::set_is_malloc_allowed(false); // moving from an rvalue reference shall never allocate
// move the temporary to n
MatrixType n = std::move(tmp);
UIntPtr dst_address = reinterpret_cast<UIntPtr>(n.data());
std::uintptr_t dst_address = reinterpret_cast<std::uintptr_t>(n.data());
if (MatrixType::RowsAtCompileTime==Dynamic|| MatrixType::ColsAtCompileTime==Dynamic)
{
// verify that we actually moved the guts
VERIFY_IS_EQUAL(src_address, dst_address);
VERIFY_IS_EQUAL(tmp.size(), 0);
VERIFY_IS_EQUAL(reinterpret_cast<UIntPtr>(tmp.data()), UIntPtr(0));
VERIFY_IS_EQUAL(reinterpret_cast<std::uintptr_t>(tmp.data()), std::uintptr_t(0));
}
// verify that the content did not change
@@ -55,24 +53,24 @@ void rvalue_transpositions(Index rows)
Eigen::internal::set_is_malloc_allowed(false); // moving from an rvalue reference shall never allocate
UIntPtr t0_address = reinterpret_cast<UIntPtr>(t0.indices().data());
std::uintptr_t t0_address = reinterpret_cast<std::uintptr_t>(t0.indices().data());
// Move constructors:
TranspositionsType t1 = std::move(t0);
UIntPtr t1_address = reinterpret_cast<UIntPtr>(t1.indices().data());
std::uintptr_t t1_address = reinterpret_cast<std::uintptr_t>(t1.indices().data());
VERIFY_IS_EQUAL(t0_address, t1_address);
// t0 must be de-allocated:
VERIFY_IS_EQUAL(t0.size(), 0);
VERIFY_IS_EQUAL(reinterpret_cast<UIntPtr>(t0.indices().data()), UIntPtr(0));
VERIFY_IS_EQUAL(reinterpret_cast<std::uintptr_t>(t0.indices().data()), std::uintptr_t(0));
// Move assignment:
t0 = std::move(t1);
t0_address = reinterpret_cast<UIntPtr>(t0.indices().data());
t0_address = reinterpret_cast<std::uintptr_t>(t0.indices().data());
VERIFY_IS_EQUAL(t0_address, t1_address);
// t1 must be de-allocated:
VERIFY_IS_EQUAL(t1.size(), 0);
VERIFY_IS_EQUAL(reinterpret_cast<UIntPtr>(t1.indices().data()), UIntPtr(0));
VERIFY_IS_EQUAL(reinterpret_cast<std::uintptr_t>(t1.indices().data()), std::uintptr_t(0));
Eigen::internal::set_is_malloc_allowed(true);
}

View File

@@ -34,7 +34,7 @@ void check_stdvector_matrix(const MatrixType& m)
VERIFY_IS_APPROX(v[21], y);
v.push_back(x);
VERIFY_IS_APPROX(v[22], x);
VERIFY((internal::UIntPtr)&(v[22]) == (internal::UIntPtr)&(v[21]) + sizeof(MatrixType));
VERIFY((std::uintptr_t)&(v[22]) == (std::uintptr_t)&(v[21]) + sizeof(MatrixType));
// do a lot of push_back such that the vector gets internally resized
// (with memory reallocation)
@@ -69,7 +69,7 @@ void check_stdvector_transform(const TransformType&)
VERIFY_IS_APPROX(v[21], y);
v.push_back(x);
VERIFY_IS_APPROX(v[22], x);
VERIFY((internal::UIntPtr)&(v[22]) == (internal::UIntPtr)&(v[21]) + sizeof(TransformType));
VERIFY((std::uintptr_t)&(v[22]) == (std::uintptr_t)&(v[21]) + sizeof(TransformType));
// do a lot of push_back such that the vector gets internally resized
// (with memory reallocation)
@@ -104,7 +104,7 @@ void check_stdvector_quaternion(const QuaternionType&)
VERIFY_IS_APPROX(v[21], y);
v.push_back(x);
VERIFY_IS_APPROX(v[22], x);
VERIFY((internal::UIntPtr)&(v[22]) == (internal::UIntPtr)&(v[21]) + sizeof(QuaternionType));
VERIFY((std::uintptr_t)&(v[22]) == (std::uintptr_t)&(v[21]) + sizeof(QuaternionType));
// do a lot of push_back such that the vector gets internally resized
// (with memory reallocation)

View File

@@ -48,7 +48,7 @@ void check_stdvector_matrix(const MatrixType& m)
VERIFY_IS_APPROX(v[21], y);
v.push_back(x);
VERIFY_IS_APPROX(v[22], x);
VERIFY((internal::UIntPtr)&(v[22]) == (internal::UIntPtr)&(v[21]) + sizeof(MatrixType));
VERIFY((std::uintptr_t)&(v[22]) == (std::uintptr_t)&(v[21]) + sizeof(MatrixType));
// do a lot of push_back such that the vector gets internally resized
// (with memory reallocation)
@@ -83,7 +83,7 @@ void check_stdvector_transform(const TransformType&)
VERIFY_IS_APPROX(v[21], y);
v.push_back(x);
VERIFY_IS_APPROX(v[22], x);
VERIFY((internal::UIntPtr)&(v[22]) == (internal::UIntPtr)&(v[21]) + sizeof(TransformType));
VERIFY((std::uintptr_t)&(v[22]) == (std::uintptr_t)&(v[21]) + sizeof(TransformType));
// do a lot of push_back such that the vector gets internally resized
// (with memory reallocation)
@@ -118,7 +118,7 @@ void check_stdvector_quaternion(const QuaternionType&)
VERIFY_IS_APPROX(v[21], y);
v.push_back(x);
VERIFY_IS_APPROX(v[22], x);
VERIFY((internal::UIntPtr)&(v[22]) == (internal::UIntPtr)&(v[21]) + sizeof(QuaternionType));
VERIFY((std::uintptr_t)&(v[22]) == (std::uintptr_t)&(v[21]) + sizeof(QuaternionType));
// do a lot of push_back such that the vector gets internally resized
// (with memory reallocation)