20 #ifndef EIGEN_MEMORY_H
21 #define EIGEN_MEMORY_H
23 #ifndef EIGEN_MALLOC_ALREADY_ALIGNED
34 #if defined(__GLIBC__) && ((__GLIBC__>=2 && __GLIBC_MINOR__ >= 8) || __GLIBC__>2) \
35 && defined(__LP64__) && ! defined( __SANITIZE_ADDRESS__ ) && (EIGEN_DEFAULT_ALIGN_BYTES == 16)
36 #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 1
38 #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 0
45 #if defined(__FreeBSD__) && !(EIGEN_ARCH_ARM || EIGEN_ARCH_MIPS) && (EIGEN_DEFAULT_ALIGN_BYTES == 16)
46 #define EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED 1
48 #define EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED 0
51 #if (EIGEN_OS_MAC && (EIGEN_DEFAULT_ALIGN_BYTES == 16)) \
52 || (EIGEN_OS_WIN64 && (EIGEN_DEFAULT_ALIGN_BYTES == 16)) \
53 || EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED \
54 || EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED
55 #define EIGEN_MALLOC_ALREADY_ALIGNED 1
57 #define EIGEN_MALLOC_ALREADY_ALIGNED 0
62 #ifndef EIGEN_MALLOC_CHECK_THREAD_LOCAL
67 #ifndef EIGEN_AVOID_THREAD_LOCAL
69 #if ((EIGEN_COMP_GNUC) || __has_feature(cxx_thread_local) || EIGEN_COMP_MSVC >= 1900) && !defined(EIGEN_GPU_COMPILE_PHASE)
70 #define EIGEN_MALLOC_CHECK_THREAD_LOCAL thread_local
72 #define EIGEN_MALLOC_CHECK_THREAD_LOCAL
76 #define EIGEN_MALLOC_CHECK_THREAD_LOCAL
81 #include "../InternalHeaderCheck.h"
91 #ifdef EIGEN_NO_MALLOC
94 eigen_assert(
false &&
"heap allocation is forbidden (EIGEN_NO_MALLOC is defined)");
96 #elif defined EIGEN_RUNTIME_NO_MALLOC
97 EIGEN_DEVICE_FUNC inline bool is_malloc_allowed_impl(
bool update,
bool new_value =
false)
104 EIGEN_DEVICE_FUNC inline bool is_malloc_allowed() {
return is_malloc_allowed_impl(
false); }
105 EIGEN_DEVICE_FUNC inline bool set_is_malloc_allowed(
bool new_value) {
return is_malloc_allowed_impl(
true, new_value); }
108 eigen_assert(is_malloc_allowed() &&
"heap allocation is forbidden (EIGEN_RUNTIME_NO_MALLOC is defined and g_is_malloc_allowed is false)");
119 #ifdef EIGEN_EXCEPTIONS
120 throw std::bad_alloc();
122 std::size_t huge =
static_cast<std::size_t
>(-1);
123 #if defined(EIGEN_HIPCC)
135 void* unused = ::operator
new(huge);
152 eigen_assert(alignment >=
sizeof(
void*) && alignment <= 128 && (alignment & (alignment-1)) == 0 &&
"Alignment must be at least sizeof(void*), less than or equal to 128, and a power of 2");
156 void* original = malloc(
size + alignment);
157 if (original == 0)
return 0;
158 uint8_t offset =
static_cast<uint8_t>(alignment - (
reinterpret_cast<std::size_t
>(original) & (alignment - 1)));
159 void* aligned =
static_cast<void*
>(
static_cast<uint8_t*
>(original) + offset);
160 *(
static_cast<uint8_t*
>(aligned) - 1) = offset;
169 void* original =
static_cast<void*
>(
static_cast<uint8_t*
>(ptr) - offset);
186 void* old_original =
static_cast<uint8_t*
>(ptr) - old_offset;
190 void* original = realloc(old_original, new_size + alignment);
191 if (original ==
nullptr)
return nullptr;
192 if (original == old_original)
return ptr;
193 uint8_t offset =
static_cast<uint8_t>(alignment - (
reinterpret_cast<std::size_t
>(original) & (alignment - 1)));
194 void* aligned =
static_cast<void*
>(
static_cast<uint8_t*
>(original) + offset);
195 if (offset != old_offset) {
196 const void* src =
static_cast<const void*
>(
static_cast<uint8_t*
>(original) + old_offset);
197 std::size_t count = (
std::min)(new_size, old_size);
198 std::memmove(aligned, src, count);
200 *(
static_cast<uint8_t*
>(aligned) - 1) = offset;
209 if (
size == 0)
return nullptr;
212 #if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED
216 result = malloc(
size);
218 #if EIGEN_DEFAULT_ALIGN_BYTES==16
219 eigen_assert((
size<16 || (std::size_t(result)%16)==0) &&
"System's malloc returned an unaligned pointer. Compile with EIGEN_MALLOC_ALREADY_ALIGNED=0 to fallback to handmade aligned memory allocator.");
234 #if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED
254 if (old_size == new_size)
return ptr;
255 if (new_size == 0) {
aligned_free(ptr);
return nullptr; }
258 #if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED
263 result = realloc(ptr,new_size);
268 if (!result && new_size)
288 if (
size == 0)
return nullptr;
292 void *result = malloc(
size);
321 if (old_size == new_size)
return ptr;
326 return realloc(ptr, new_size);
351 for (
i = 0;
i <
size; ++
i) ::
new (ptr +
i)
T;
369 for (
i = 0;
i <
size; ++
i) ::
new (ptr +
i)
T(*(src +
i));
387 for (
i = 0;
i <
size; ++
i) ::
new (ptr +
i)
T(std::move(*(src +
i)));
404 if(
size > std::size_t(-1) /
sizeof(
T))
414 check_size_for_overflow<T>(
size);
430 check_size_for_overflow<T>(
size);
431 T *result =
static_cast<T*
>(conditional_aligned_malloc<Align>(
sizeof(
T)*
size));
438 conditional_aligned_free<Align>(result);
449 destruct_elements_of_array<T>(ptr,
size);
458 destruct_elements_of_array<T>(ptr,
size);
459 conditional_aligned_free<Align>(ptr);
464 check_size_for_overflow<T>(new_size);
465 check_size_for_overflow<T>(old_size);
471 T* result =
static_cast<T*
>(conditional_aligned_malloc<Align>(
sizeof(
T)*new_size));
475 std::size_t copy_size = (
std::min)(old_size, new_size);
479 if (new_size > old_size) {
484 conditional_aligned_delete<T, Align>(pts, old_size);
488 conditional_aligned_free<Align>(result);
500 check_size_for_overflow<T>(
size);
501 T *result =
static_cast<T*
>(conditional_aligned_malloc<Align>(
sizeof(
T)*
size));
510 conditional_aligned_free<Align>(result);
520 return conditional_aligned_realloc_new<T, Align>(pts, new_size, old_size);
523 check_size_for_overflow<T>(new_size);
524 check_size_for_overflow<T>(old_size);
525 return static_cast<T*
>(conditional_aligned_realloc<Align>(
static_cast<void*
>(pts),
sizeof(
T)*new_size,
sizeof(
T)*old_size));
531 destruct_elements_of_array<T>(ptr,
size);
532 conditional_aligned_free<Align>(ptr);
554 template<
int Alignment,
typename Scalar,
typename Index>
557 const Index ScalarSize =
sizeof(Scalar);
558 const Index AlignmentSize = Alignment / ScalarSize;
559 const Index AlignmentMask = AlignmentSize-1;
567 else if( (std::uintptr_t(
array) & (
sizeof(Scalar)-1)) || (Alignment%ScalarSize)!=0)
575 Index first = (AlignmentSize - (
Index((std::uintptr_t(
array)/
sizeof(Scalar))) & AlignmentMask)) & AlignmentMask;
582 template<
typename Scalar,
typename Index>
585 typedef typename packet_traits<Scalar>::type DefaultPacketType;
586 return first_aligned<unpacket_traits<DefaultPacketType>::alignment>(
array,
size);
591 template<
typename Index>
594 return ((
size+base-1)/base)*base;
599 template<
typename T,
bool UseMemcpy>
struct smart_copy_helper;
603 smart_copy_helper<T,!NumTraits<T>::RequireInitialization>::run(start,
end, target);
606 template<
typename T>
struct smart_copy_helper<
T,true> {
609 std::intptr_t
size = std::intptr_t(
end)-std::intptr_t(start);
613 memcpy(target, start,
size);
617 template<
typename T>
struct smart_copy_helper<
T,false> {
619 { std::copy(start,
end, target); }
623 template<
typename T,
bool UseMemmove>
struct smart_memmove_helper;
627 smart_memmove_helper<T,!NumTraits<T>::RequireInitialization>::run(start,
end, target);
630 template<
typename T>
struct smart_memmove_helper<
T,true> {
631 static inline void run(
const T* start,
const T*
end,
T* target)
633 std::intptr_t
size = std::intptr_t(
end)-std::intptr_t(start);
636 std::memmove(target, start,
size);
640 template<
typename T>
struct smart_memmove_helper<
T,false> {
641 static inline void run(
const T* start,
const T*
end,
T* target)
643 if (std::uintptr_t(target) < std::uintptr_t(start))
645 std::copy(start,
end, target);
649 std::ptrdiff_t count = (std::ptrdiff_t(
end)-std::ptrdiff_t(start)) /
sizeof(
T);
650 std::copy_backward(start,
end, target + count);
657 return std::move(start,
end, target);
666 #if ! defined EIGEN_ALLOCA && ! defined EIGEN_GPU_COMPILE_PHASE
667 #if EIGEN_OS_LINUX || EIGEN_OS_MAC || (defined alloca)
668 #define EIGEN_ALLOCA alloca
669 #elif EIGEN_COMP_MSVC
670 #define EIGEN_ALLOCA _alloca
679 #if defined(__clang__) && defined(__thumb__)
685 template<
typename T>
class aligned_stack_memory_handler : noncopyable
695 aligned_stack_memory_handler(
T* ptr, std::size_t
size,
bool dealloc)
696 : m_ptr(ptr), m_size(
size), m_deallocate(dealloc)
702 ~aligned_stack_memory_handler()
705 Eigen::internal::destruct_elements_of_array<T>(m_ptr, m_size);
717 template<
typename Xpr,
int NbEvaluations,
718 bool MapExternalBuffer = nested_eval<Xpr,NbEvaluations>::Evaluate && Xpr::MaxSizeAtCompileTime==
Dynamic
720 struct local_nested_eval_wrapper
722 static constexpr
bool NeedExternalBuffer =
false;
723 typedef typename Xpr::Scalar Scalar;
724 typedef typename nested_eval<Xpr,NbEvaluations>::type ObjectType;
728 local_nested_eval_wrapper(
const Xpr& xpr, Scalar* ptr) : object(xpr)
735 template<
typename Xpr,
int NbEvaluations>
736 struct local_nested_eval_wrapper<Xpr,NbEvaluations,true>
738 static constexpr
bool NeedExternalBuffer =
true;
739 typedef typename Xpr::Scalar Scalar;
740 typedef typename plain_object_eval<Xpr>::type PlainObject;
741 typedef Map<PlainObject,EIGEN_DEFAULT_ALIGN_BYTES> ObjectType;
745 local_nested_eval_wrapper(
const Xpr& xpr, Scalar* ptr)
755 ~local_nested_eval_wrapper()
769 template<
typename T>
class scoped_array : noncopyable
773 explicit scoped_array(std::ptrdiff_t
size)
781 T& operator[](std::ptrdiff_t
i) {
return m_ptr[
i]; }
782 const T& operator[](std::ptrdiff_t
i)
const {
return m_ptr[
i]; }
783 T* &ptr() {
return m_ptr; }
784 const T* ptr()
const {
return m_ptr; }
785 operator const T*()
const {
return m_ptr; }
788 template<
typename T>
void swap(scoped_array<T> &
a,scoped_array<T> &
b)
822 #if EIGEN_DEFAULT_ALIGN_BYTES>0
825 #define EIGEN_ALIGNED_ALLOCA(SIZE) reinterpret_cast<void*>((std::uintptr_t(EIGEN_ALLOCA(SIZE+EIGEN_DEFAULT_ALIGN_BYTES-1)) + EIGEN_DEFAULT_ALIGN_BYTES-1) & ~(std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1)))
827 #define EIGEN_ALIGNED_ALLOCA(SIZE) EIGEN_ALLOCA(SIZE)
830 #define ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) \
831 Eigen::internal::check_size_for_overflow<TYPE>(SIZE); \
832 TYPE* NAME = (BUFFER)!=0 ? (BUFFER) \
833 : reinterpret_cast<TYPE*>( \
834 (sizeof(TYPE)*SIZE<=EIGEN_STACK_ALLOCATION_LIMIT) ? EIGEN_ALIGNED_ALLOCA(sizeof(TYPE)*SIZE) \
835 : Eigen::internal::aligned_malloc(sizeof(TYPE)*SIZE) ); \
836 Eigen::internal::aligned_stack_memory_handler<TYPE> EIGEN_CAT(NAME,_stack_memory_destructor)((BUFFER)==0 ? NAME : 0,SIZE,sizeof(TYPE)*SIZE>EIGEN_STACK_ALLOCATION_LIMIT)
839 #define ei_declare_local_nested_eval(XPR_T,XPR,N,NAME) \
840 Eigen::internal::local_nested_eval_wrapper<XPR_T,N> EIGEN_CAT(NAME,_wrapper)(XPR, reinterpret_cast<typename XPR_T::Scalar*>( \
841 ( (Eigen::internal::local_nested_eval_wrapper<XPR_T,N>::NeedExternalBuffer) && ((sizeof(typename XPR_T::Scalar)*XPR.size())<=EIGEN_STACK_ALLOCATION_LIMIT) ) \
842 ? EIGEN_ALIGNED_ALLOCA( sizeof(typename XPR_T::Scalar)*XPR.size() ) : 0 ) ) ; \
843 typename Eigen::internal::local_nested_eval_wrapper<XPR_T,N>::ObjectType NAME(EIGEN_CAT(NAME,_wrapper).object)
847 #define ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) \
848 Eigen::internal::check_size_for_overflow<TYPE>(SIZE); \
849 TYPE* NAME = (BUFFER)!=0 ? BUFFER : reinterpret_cast<TYPE*>(Eigen::internal::aligned_malloc(sizeof(TYPE)*SIZE)); \
850 Eigen::internal::aligned_stack_memory_handler<TYPE> EIGEN_CAT(NAME,_stack_memory_destructor)((BUFFER)==0 ? NAME : 0,SIZE,true)
853 #define ei_declare_local_nested_eval(XPR_T,XPR,N,NAME) typename Eigen::internal::nested_eval<XPR_T,N>::type NAME(XPR)
862 #if EIGEN_HAS_CXX17_OVERALIGN
866 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign)
867 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
868 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
869 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size)
874 #if EIGEN_MAX_ALIGN_BYTES!=0 && !defined(EIGEN_HIP_DEVICE_COMPILE)
875 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
877 void* operator new(std::size_t size, const std::nothrow_t&) EIGEN_NO_THROW { \
878 EIGEN_TRY { return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); } \
879 EIGEN_CATCH (...) { return 0; } \
881 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
883 void *operator new(std::size_t size) { \
884 return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
887 void *operator new[](std::size_t size) { \
888 return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
891 void operator delete(void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
893 void operator delete[](void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
895 void operator delete(void * ptr, std::size_t ) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
897 void operator delete[](void * ptr, std::size_t ) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
902 static void *operator new(std::size_t size, void *ptr) { return ::operator new(size,ptr); } \
904 static void *operator new[](std::size_t size, void* ptr) { return ::operator new[](size,ptr); } \
906 void operator delete(void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete(memory,ptr); } \
908 void operator delete[](void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete[](memory,ptr); } \
910 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
912 void operator delete(void *ptr, const std::nothrow_t&) EIGEN_NO_THROW { \
913 Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); \
915 typedef void eigen_aligned_operator_new_marker_type;
917 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
920 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(true)
921 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size) \
922 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(bool( \
923 ((Size)!=Eigen::Dynamic) && \
924 (((EIGEN_MAX_ALIGN_BYTES>=16) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES )==0)) || \
925 ((EIGEN_MAX_ALIGN_BYTES>=32) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES/2)==0)) || \
926 ((EIGEN_MAX_ALIGN_BYTES>=64) && ((sizeof(Scalar)*(Size))%(EIGEN_MAX_ALIGN_BYTES/4)==0)) )))
983 #if EIGEN_COMP_GNUC_STRICT && EIGEN_GNUC_STRICT_AT_LEAST(7,0,0)
994 internal::check_size_for_overflow<T>(num);
1006 #if !defined(EIGEN_NO_CPUID)
1007 # if EIGEN_COMP_GNUC && EIGEN_ARCH_i386_OR_x86_64
1008 # if defined(__PIC__) && EIGEN_ARCH_i386
1010 # define EIGEN_CPUID(abcd,func,id) \
1011 __asm__ __volatile__ ("xchgl %%ebx, %k1;cpuid; xchgl %%ebx,%k1": "=a" (abcd[0]), "=&r" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "a" (func), "c" (id));
1012 # elif defined(__PIC__) && EIGEN_ARCH_x86_64
1015 # define EIGEN_CPUID(abcd,func,id) \
1016 __asm__ __volatile__ ("xchg{q}\t{%%}rbx, %q1; cpuid; xchg{q}\t{%%}rbx, %q1": "=a" (abcd[0]), "=&r" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "0" (func), "2" (id));
1019 # define EIGEN_CPUID(abcd,func,id) \
1020 __asm__ __volatile__ ("cpuid": "=a" (abcd[0]), "=b" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "0" (func), "2" (id) );
1022 # elif EIGEN_COMP_MSVC
1023 # if EIGEN_ARCH_i386_OR_x86_64
1024 # define EIGEN_CPUID(abcd,func,id) __cpuidex((int*)abcd,func,id)
1033 inline bool cpuid_is_vendor(
int abcd[4],
const int vendor[3])
1035 return abcd[1]==vendor[0] && abcd[3]==vendor[1] && abcd[2]==vendor[2];
1038 inline void queryCacheSizes_intel_direct(
int& l1,
int& l2,
int& l3)
1045 abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
1046 EIGEN_CPUID(abcd,0x4,cache_id);
1047 cache_type = (abcd[0] & 0x0F) >> 0;
1048 if(cache_type==1||cache_type==3)
1050 int cache_level = (abcd[0] & 0xE0) >> 5;
1051 int ways = (abcd[1] & 0xFFC00000) >> 22;
1052 int partitions = (abcd[1] & 0x003FF000) >> 12;
1053 int line_size = (abcd[1] & 0x00000FFF) >> 0;
1054 int sets = (abcd[2]);
1056 int cache_size = (ways+1) * (partitions+1) * (line_size+1) * (sets+1);
1060 case 1: l1 = cache_size;
break;
1061 case 2: l2 = cache_size;
break;
1062 case 3: l3 = cache_size;
break;
1067 }
while(cache_type>0 && cache_id<16);
1070 inline void queryCacheSizes_intel_codes(
int& l1,
int& l2,
int& l3)
1073 abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
1075 EIGEN_CPUID(abcd,0x00000002,0);
1076 unsigned char * bytes =
reinterpret_cast<unsigned char *
>(abcd)+2;
1077 bool check_for_p2_core2 =
false;
1078 for(
int i=0;
i<14; ++
i)
1082 case 0x0A: l1 = 8;
break;
1083 case 0x0C: l1 = 16;
break;
1084 case 0x0E: l1 = 24;
break;
1085 case 0x10: l1 = 16;
break;
1086 case 0x15: l1 = 16;
break;
1087 case 0x2C: l1 = 32;
break;
1088 case 0x30: l1 = 32;
break;
1089 case 0x60: l1 = 16;
break;
1090 case 0x66: l1 = 8;
break;
1091 case 0x67: l1 = 16;
break;
1092 case 0x68: l1 = 32;
break;
1093 case 0x1A: l2 = 96;
break;
1094 case 0x22: l3 = 512;
break;
1095 case 0x23: l3 = 1024;
break;
1096 case 0x25: l3 = 2048;
break;
1097 case 0x29: l3 = 4096;
break;
1098 case 0x39: l2 = 128;
break;
1099 case 0x3A: l2 = 192;
break;
1100 case 0x3B: l2 = 128;
break;
1101 case 0x3C: l2 = 256;
break;
1102 case 0x3D: l2 = 384;
break;
1103 case 0x3E: l2 = 512;
break;
1104 case 0x40: l2 = 0;
break;
1105 case 0x41: l2 = 128;
break;
1106 case 0x42: l2 = 256;
break;
1107 case 0x43: l2 = 512;
break;
1108 case 0x44: l2 = 1024;
break;
1109 case 0x45: l2 = 2048;
break;
1110 case 0x46: l3 = 4096;
break;
1111 case 0x47: l3 = 8192;
break;
1112 case 0x48: l2 = 3072;
break;
1113 case 0x49:
if(l2!=0) l3 = 4096;
else {check_for_p2_core2=
true; l3 = l2 = 4096;}
break;
1114 case 0x4A: l3 = 6144;
break;
1115 case 0x4B: l3 = 8192;
break;
1116 case 0x4C: l3 = 12288;
break;
1117 case 0x4D: l3 = 16384;
break;
1118 case 0x4E: l2 = 6144;
break;
1119 case 0x78: l2 = 1024;
break;
1120 case 0x79: l2 = 128;
break;
1121 case 0x7A: l2 = 256;
break;
1122 case 0x7B: l2 = 512;
break;
1123 case 0x7C: l2 = 1024;
break;
1124 case 0x7D: l2 = 2048;
break;
1125 case 0x7E: l2 = 256;
break;
1126 case 0x7F: l2 = 512;
break;
1127 case 0x80: l2 = 512;
break;
1128 case 0x81: l2 = 128;
break;
1129 case 0x82: l2 = 256;
break;
1130 case 0x83: l2 = 512;
break;
1131 case 0x84: l2 = 1024;
break;
1132 case 0x85: l2 = 2048;
break;
1133 case 0x86: l2 = 512;
break;
1134 case 0x87: l2 = 1024;
break;
1135 case 0x88: l3 = 2048;
break;
1136 case 0x89: l3 = 4096;
break;
1137 case 0x8A: l3 = 8192;
break;
1138 case 0x8D: l3 = 3072;
break;
1143 if(check_for_p2_core2 && l2 == l3)
1150 inline void queryCacheSizes_intel(
int& l1,
int& l2,
int& l3,
int max_std_funcs)
1152 if(max_std_funcs>=4)
1153 queryCacheSizes_intel_direct(l1,l2,l3);
1154 else if(max_std_funcs>=2)
1155 queryCacheSizes_intel_codes(l1,l2,l3);
1160 inline void queryCacheSizes_amd(
int& l1,
int& l2,
int& l3)
1163 abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
1166 EIGEN_CPUID(abcd,0x80000000,0);
1169 EIGEN_CPUID(abcd,0x80000005,0);
1170 l1 = (abcd[2] >> 24) * 1024;
1171 abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
1172 EIGEN_CPUID(abcd,0x80000006,0);
1173 l2 = (abcd[2] >> 16) * 1024;
1174 l3 = ((abcd[3] & 0xFFFC000) >> 18) * 512 * 1024;
1189 const int GenuineIntel[] = {0x756e6547, 0x49656e69, 0x6c65746e};
1190 const int AuthenticAMD[] = {0x68747541, 0x69746e65, 0x444d4163};
1191 const int AMDisbetter_[] = {0x69444d41, 0x74656273, 0x21726574};
1194 EIGEN_CPUID(abcd,0x0,0);
1195 int max_std_funcs = abcd[0];
1196 if(cpuid_is_vendor(abcd,GenuineIntel))
1197 queryCacheSizes_intel(l1,l2,l3,max_std_funcs);
1198 else if(cpuid_is_vendor(abcd,AuthenticAMD) || cpuid_is_vendor(abcd,AMDisbetter_))
1199 queryCacheSizes_amd(l1,l2,l3);
1202 queryCacheSizes_intel(l1,l2,l3,max_std_funcs);
1233 int l1, l2(-1), l3(-1);
1244 #if EIGEN_COMP_CXXVER >= 20
1247 template<
class T,
class... Args>
1250 return ::new (
const_cast<void*
>(
static_cast<const volatile void*
>(
p)))
1251 T(std::forward<Args>(args)...);
1260 #if EIGEN_COMP_CXXVER >= 17
#define EIGEN_ALWAYS_INLINE
#define EIGEN_USING_STD(FUNC)
#define eigen_internal_assert(x)
#define EIGEN_UNUSED_VARIABLE(var)
#define EIGEN_DEVICE_FUNC
#define EIGEN_MALLOC_CHECK_THREAD_LOCAL
Eigen::Triplet< double > T
STL compatible allocator to use with types requiring a non-standard alignment.
pointer allocate(size_type num, const void *=0)
aligned_allocator(const aligned_allocator< U > &other)
const T & const_reference
std::ptrdiff_t difference_type
aligned_allocator(const aligned_allocator &other)
void deallocate(pointer p, size_type)
static const lastp1_t end
bfloat16() max(const bfloat16 &a, const bfloat16 &b)
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
void * conditional_aligned_malloc< false >(std::size_t size)
void * handmade_aligned_realloc(void *ptr, std::size_t new_size, std::size_t old_size, std::size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
T * aligned_new(std::size_t size)
void conditional_aligned_free< false >(void *ptr)
void handmade_aligned_free(void *ptr)
void queryCacheSizes(int &l1, int &l2, int &l3)
T * default_construct_elements_of_array(T *ptr, std::size_t size)
T * copy_construct_elements_of_array(T *ptr, const T *src, std::size_t size)
void destruct_elements_of_array(T *ptr, std::size_t size)
T * conditional_aligned_new_auto(std::size_t size)
void conditional_aligned_free(void *ptr)
void check_that_malloc_is_allowed()
Index first_multiple(Index size, Index base)
void conditional_aligned_delete(T *ptr, std::size_t size)
void aligned_delete(T *ptr, std::size_t size)
void * aligned_malloc(std::size_t size)
T * move_construct_elements_of_array(T *ptr, T *src, std::size_t size)
void * conditional_aligned_realloc(void *ptr, std::size_t new_size, std::size_t old_size)
static Index first_default_aligned(const DenseBase< Derived > &m)
void throw_std_bad_alloc()
void * aligned_realloc(void *ptr, std::size_t new_size, std::size_t old_size)
void * handmade_aligned_malloc(std::size_t size, std::size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
void * conditional_aligned_malloc(std::size_t size)
T * construct_at(T *p, Args &&... args)
void conditional_aligned_delete_auto(T *ptr, std::size_t size)
T * conditional_aligned_new(std::size_t size)
void aligned_free(void *ptr)
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
int queryTopLevelCacheSize()
void smart_memmove(const T *start, const T *end, T *target)
static Index first_aligned(const DenseBase< Derived > &m)
T * smart_move(T *start, T *end, T *target)
EIGEN_ALWAYS_INLINE void check_size_for_overflow(std::size_t size)
void smart_copy(const T *start, const T *end, T *target)
T * conditional_aligned_realloc_new_auto(T *pts, std::size_t new_size, std::size_t old_size)
void * conditional_aligned_realloc< false >(void *ptr, std::size_t new_size, std::size_t old_size)
T * conditional_aligned_realloc_new(T *pts, std::size_t new_size, std::size_t old_size)
void swap(scoped_array< T > &a, scoped_array< T > &b)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
aligned_allocator< U > other