default to Intel's API by default

This commit is contained in:
Gael Guennebaud 2010-06-23 17:14:06 +02:00
parent e1a6bad087
commit 546587c7d3

View File

@ -599,24 +599,14 @@ public:
# define EIGEN_CPUID(abcd,func) __cpuid((int*)abcd,func)
#endif
/** \internal
* Queries and returns the cache sizes in Bytes of the L1, L2, and L3 data caches respectively */
inline void ei_queryCacheSizes(int& l1, int& l2, int& l3)
inline bool ei_cpuid_is_vendor(int abcd[4], const char* vendor)
{
return abcd[1]==((int*)(vendor))[0] && abcd[3]==((int*)(vendor))[1] && abcd[2]==((int*)(vendor))[2];
}
inline void ei_queryCacheSizes_intel(int& l1, int& l2, int& l3)
{
#ifdef EIGEN_CPUID
int abcd[4];
const char GenuineIntel_char[] = "GenuntelineI";
const int* GenuineIntel = (int*)GenuineIntel_char;
const char AuthenticAMD_char[] = "AuthcAMDenti";
const int* AuthenticAMD = (int*)AuthenticAMD_char;
// Step 1: identify the CPU model
EIGEN_CPUID(abcd,0x0,0);
if(abcd[1]==GenuineIntel[0] && abcd[2]==GenuineIntel[1] && abcd[3]==GenuineIntel[2])
{
// use Intel's cpuid API
l1 = l2 = l3 = 0;
int cache_id = 0;
int cache_type = 0;
@ -644,16 +634,48 @@ inline void ei_queryCacheSizes(int& l1, int& l2, int& l3)
cache_id++;
} while(cache_type>0);
}
else if(abcd[1]==AuthenticAMD[0] && abcd[2]==AuthenticAMD[1] && abcd[3]==AuthenticAMD[2])
inline void ei_queryCacheSizes_amd(int& l1, int& l2, int& l3)
{
// use AMD's cpuid API
int abcd[4];
EIGEN_CPUID(abcd,0x80000005,0);
l1 = (abcd[2] >> 24) * 1024; // C[31:24] = L1 size in KB
EIGEN_CPUID(abcd,0x80000006,0);
l2 = (abcd[2] >> 16) * 1024; // C[31;16] = l2 cache size in KB
l3 = ((abcd[3] & 0xFFFC000) >> 18) * 512 * 1024; // D[31;18] = l3 cache size in 512KB
}
// TODO support other vendors
/** \internal
* Queries and returns the cache sizes in Bytes of the L1, L2, and L3 data caches respectively */
inline void ei_queryCacheSizes(int& l1, int& l2, int& l3)
{
#ifdef EIGEN_CPUID
int abcd[4];
// identify the CPU vendor
EIGEN_CPUID(abcd,0x0,0);
//if(abcd[1]==GenuineIntel[0] && abcd[2]==GenuineIntel[1] && abcd[3]==GenuineIntel[2])
if(ei_cpuid_is_vendor(abcd,"GenuineIntel"))
ei_queryCacheSizes_intel(l1,l2,l3);
else if(ei_cpuid_is_vendor(abcd,"AuthenticAMD") || ei_cpuid_is_vendor(abcd,"AMDisbetter!"))
ei_queryCacheSizes_amd(l1,l2,l3);
else
// by default let's use Intel's API
ei_queryCacheSizes_intel(l1,l2,l3);
// here is the list of other vendors:
// ||ei_cpuid_is_vendor(abcd,"VIA VIA VIA ")
// ||ei_cpuid_is_vendor(abcd,"CyrixInstead")
// ||ei_cpuid_is_vendor(abcd,"CentaurHauls")
// ||ei_cpuid_is_vendor(abcd,"GenuineTMx86")
// ||ei_cpuid_is_vendor(abcd,"TransmetaCPU")
// ||ei_cpuid_is_vendor(abcd,"RiseRiseRise")
// ||ei_cpuid_is_vendor(abcd,"Geode by NSC")
// ||ei_cpuid_is_vendor(abcd,"SiS SiS SiS ")
// ||ei_cpuid_is_vendor(abcd,"UMC UMC UMC ")
// ||ei_cpuid_is_vendor(abcd,"NexGenDriven")
// ||ei_cpuid_is_vendor(abcd,"CentaurHauls")
// ||ei_cpuid_is_vendor(abcd,"CentaurHauls")
#endif
}