mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
fix in case we don't know how to query the L1/L2 cache sizes
This commit is contained in:
@@ -35,8 +35,8 @@ inline void ei_manage_caching_sizes(Action action, std::ptrdiff_t* l1=0, std::pt
|
||||
m_l1CacheSize = ei_queryL1CacheSize();
|
||||
m_l2CacheSize = ei_queryTopLevelCacheSize();
|
||||
|
||||
if(m_l1CacheSize==0) m_l1CacheSize = 8 * 1024;
|
||||
if(m_l2CacheSize==0) m_l2CacheSize = 1 * 1024 * 1024;
|
||||
if(m_l1CacheSize<=0) m_l1CacheSize = 8 * 1024;
|
||||
if(m_l2CacheSize<=0) m_l2CacheSize = 1 * 1024 * 1024;
|
||||
}
|
||||
|
||||
if(action==SetAction)
|
||||
|
||||
@@ -603,6 +603,7 @@ public:
|
||||
* \returns the size in Bytes of the L1 data cache */
|
||||
inline std::ptrdiff_t ei_queryL1CacheSize()
|
||||
{
|
||||
#ifdef EIGEN_CPUID
|
||||
int abcd[4];
|
||||
|
||||
// try the direct method using extended level
|
||||
@@ -640,17 +641,24 @@ inline std::ptrdiff_t ei_queryL1CacheSize()
|
||||
}
|
||||
|
||||
return l1*1024;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** \internal
|
||||
* \returns the size in Bytes of the L2 or L3 cache if this later is present */
|
||||
inline std::ptrdiff_t ei_queryTopLevelCacheSize()
|
||||
{
|
||||
#ifdef EIGEN_CPUID
|
||||
int abcd[4];
|
||||
EIGEN_CPUID(abcd,0x80000006);
|
||||
std::ptrdiff_t l2 = std::ptrdiff_t(abcd[2] >> 16) * 1024;
|
||||
std::ptrdiff_t l3 = std::ptrdiff_t((abcd[3] & 0xFFFC000) >> 18) * 512 * 1024;
|
||||
return std::max(l2,l3);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // EIGEN_MEMORY_H
|
||||
|
||||
Reference in New Issue
Block a user