forked from OSchip/llvm-project
[X86] Cleanup some CPUID usage in getAvailableFeatures.
We should make sure leaf 1 is available before accessing it. Same with leaf 0x80000001. llvm-svn: 307462
This commit is contained in:
parent
433c2f0859
commit
bb8c799e1a
|
@ -987,8 +987,14 @@ static unsigned getAvailableFeatures(unsigned int ECX, unsigned int EDX,
|
|||
Features |= (HasAVX512Save << FEATURE_AVX512SAVE);
|
||||
Features |= (HasADX << FEATURE_ADX);
|
||||
|
||||
getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
|
||||
Features |= (((EDX >> 29) & 0x1) << FEATURE_EM64T);
|
||||
unsigned MaxExtLevel;
|
||||
getX86CpuIDAndInfo(0x80000000, &MaxExtLevel, &EBX, &ECX, &EDX);
|
||||
|
||||
bool HasExtLeaf1 = MaxExtLevel >= 0x80000001 &&
|
||||
!getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
|
||||
if (HasExtLeaf1)
|
||||
Features |= (((EDX >> 29) & 0x1) << FEATURE_EM64T);
|
||||
|
||||
return Features;
|
||||
}
|
||||
|
||||
|
@ -1004,10 +1010,9 @@ StringRef sys::getHostCPUName() {
|
|||
if(!isCpuIdSupported())
|
||||
return "generic";
|
||||
#endif
|
||||
if (getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX))
|
||||
return "generic";
|
||||
if (getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
|
||||
if (getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX) || MaxLeaf < 1)
|
||||
return "generic";
|
||||
getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
|
||||
|
||||
unsigned Brand_id = EBX & 0xff;
|
||||
unsigned Family = 0, Model = 0;
|
||||
|
|
Loading…
Reference in New Issue