@@ -417,11 +417,6 @@ StringRef sys::detail::getHostCPUNameForBPF() {
417
417
#if defined(__i386__) || defined(_M_IX86) || \
418
418
defined (__x86_64__) || defined(_M_X64)
419
419
420
- enum VendorSignatures {
421
- SIG_INTEL = 0x756e6547 /* Genu */ ,
422
- SIG_AMD = 0x68747541 /* Auth */
423
- };
424
-
425
420
// The check below for i386 was copied from clang's cpuid.h (__get_cpuid_max).
426
421
// Check motivated by bug reports for OpenSSL crashing on CPUs without CPUID
427
422
// support. Consequently, for i386, the presence of CPUID is checked first
@@ -495,6 +490,42 @@ static bool getX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
495
490
#endif
496
491
}
497
492
493
+ namespace llvm {
494
+ namespace sys {
495
+ namespace detail {
496
+ namespace x86 {
497
+
498
+ VendorSignatures getVendorSignature (unsigned *MaxLeaf) {
499
+ unsigned EAX = 0 , EBX = 0 , ECX = 0 , EDX = 0 ;
500
+ if (MaxLeaf == nullptr )
501
+ MaxLeaf = &EAX;
502
+ else
503
+ *MaxLeaf = 0 ;
504
+
505
+ if (!isCpuIdSupported ())
506
+ return VendorSignatures::UNKNOWN;
507
+
508
+ if (getX86CpuIDAndInfo (0 , MaxLeaf, &EBX, &ECX, &EDX) || *MaxLeaf < 1 )
509
+ return VendorSignatures::UNKNOWN;
510
+
511
+ // "Genu ineI ntel"
512
+ if (EBX == 0x756e6547 && ECX == 0x6c65746e && EDX == 0x49656e69 )
513
+ return VendorSignatures::GENUINE_INTEL;
514
+
515
+ // "Auth enti cAMD"
516
+ if (EBX == 0x68747541 && ECX == 0x69746e65 && EDX == 0x444d4163 )
517
+ return VendorSignatures::AUTHENTIC_AMD;
518
+
519
+ return VendorSignatures::UNKNOWN;
520
+ }
521
+
522
+ } // namespace x86
523
+ } // namespace detail
524
+ } // namespace sys
525
+ } // namespace llvm
526
+
527
+ using namespace llvm ::sys::detail::x86;
528
+
498
529
// / getX86CpuIDAndInfoEx - Execute the specified cpuid with subleaf and return
499
530
// / the 4 values in the specified arguments. If we can't run cpuid on the host,
500
531
// / return true.
@@ -1092,14 +1123,12 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
1092
1123
}
1093
1124
1094
1125
StringRef sys::getHostCPUName () {
1095
- unsigned EAX = 0 , EBX = 0 , ECX = 0 , EDX = 0 ;
1096
- unsigned MaxLeaf, Vendor;
1097
-
1098
- if (!isCpuIdSupported ())
1126
+ unsigned MaxLeaf = 0 ;
1127
+ const VendorSignatures Vendor = getVendorSignature (&MaxLeaf);
1128
+ if (Vendor == VendorSignatures::UNKNOWN)
1099
1129
return " generic" ;
1100
1130
1101
- if (getX86CpuIDAndInfo (0 , &MaxLeaf, &Vendor, &ECX, &EDX) || MaxLeaf < 1 )
1102
- return " generic" ;
1131
+ unsigned EAX = 0 , EBX = 0 , ECX = 0 , EDX = 0 ;
1103
1132
getX86CpuIDAndInfo (0x1 , &EAX, &EBX, &ECX, &EDX);
1104
1133
1105
1134
unsigned Family = 0 , Model = 0 ;
@@ -1114,10 +1143,10 @@ StringRef sys::getHostCPUName() {
1114
1143
1115
1144
StringRef CPU;
1116
1145
1117
- if (Vendor == SIG_INTEL ) {
1146
+ if (Vendor == VendorSignatures::GENUINE_INTEL ) {
1118
1147
CPU = getIntelProcessorTypeAndSubtype (Family, Model, Features, &Type,
1119
1148
&Subtype);
1120
- } else if (Vendor == SIG_AMD ) {
1149
+ } else if (Vendor == VendorSignatures::AUTHENTIC_AMD ) {
1121
1150
CPU = getAMDProcessorTypeAndSubtype (Family, Model, Features, &Type,
1122
1151
&Subtype);
1123
1152
}
@@ -1219,6 +1248,19 @@ StringRef sys::getHostCPUName() {
1219
1248
}
1220
1249
#else
1221
1250
StringRef sys::getHostCPUName () { return " generic" ; }
1251
+ namespace llvm {
1252
+ namespace sys {
1253
+ namespace detail {
1254
+ namespace x86 {
1255
+
1256
+ VendorSignatures getVendorSignature (unsigned *MaxLeaf) {
1257
+ return VendorSignatures::UNKNOWN;
1258
+ }
1259
+
1260
+ } // namespace x86
1261
+ } // namespace detail
1262
+ } // namespace sys
1263
+ } // namespace llvm
1222
1264
#endif
1223
1265
1224
1266
#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
0 commit comments