Skip to content

Commit 938d3f4

Browse files
committed
[X86] Add 'znver2' and 'cascadelake' support to __cpu_indicator_init.
For 'cascadelake' this is adding a 'avx512vnni' feature check to the 0x55 skylake-avx512 model check. These CPUs use the same model number and only differ in the stepping number. But the feature flag is simpler than collecting all the stepping numbers. For 'znver2' this is just syncing with LLVM's Host.cpp. llvm-svn: 354927
1 parent da1628e commit 938d3f4

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

compiler-rt/lib/builtins/cpu_model.c

+20-6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ enum ProcessorSubtypes {
8080
INTEL_COREI7_CANNONLAKE,
8181
INTEL_COREI7_ICELAKE_CLIENT,
8282
INTEL_COREI7_ICELAKE_SERVER,
83+
AMDFAM17H_ZNVER2,
84+
INTEL_COREI7_CASCADELAKE,
8385
CPU_SUBTYPE_MAX
8486
};
8587

@@ -268,7 +270,8 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,
268270
static void
269271
getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
270272
unsigned Brand_id, unsigned Features,
271-
unsigned *Type, unsigned *Subtype) {
273+
unsigned Features2, unsigned *Type,
274+
unsigned *Subtype) {
272275
if (Brand_id != 0)
273276
return;
274277
switch (Family) {
@@ -347,7 +350,10 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
347350
// Skylake Xeon:
348351
case 0x55:
349352
*Type = INTEL_COREI7;
350-
*Subtype = INTEL_COREI7_SKYLAKE_AVX512; // "skylake-avx512"
353+
if (Features2 & (1 << (FEATURE_AVX512VNNI - 32)))
354+
*Subtype = INTEL_COREI7_CASCADELAKE; // "cascadelake"
355+
else
356+
*Subtype = INTEL_COREI7_SKYLAKE_AVX512; // "skylake-avx512"
351357
break;
352358

353359
// Cannonlake:
@@ -400,8 +406,8 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
400406
}
401407

402408
static void getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
403-
unsigned Features, unsigned *Type,
404-
unsigned *Subtype) {
409+
unsigned Features, unsigned Features2,
410+
unsigned *Type, unsigned *Subtype) {
405411
// FIXME: this poorly matches the generated SubtargetFeatureKV table. There
406412
// appears to be no way to generate the wide variety of AMD-specific targets
407413
// from the information returned from CPUID.
@@ -447,7 +453,14 @@ static void getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
447453
break; // "btver2"
448454
case 23:
449455
*Type = AMDFAM17H;
450-
*Subtype = AMDFAM17H_ZNVER1;
456+
if (Model >= 0x30 && Model <= 0x3f) {
457+
*Subtype = AMDFAM17H_ZNVER2;
458+
break; // "znver2"; 30h-3fh: Zen2
459+
}
460+
if (Model <= 0x0f) {
461+
*Subtype = AMDFAM17H_ZNVER1;
462+
break; // "znver1"; 00h-0Fh: Zen1
463+
}
451464
break;
452465
default:
453466
break; // "generic"
@@ -628,12 +641,13 @@ __cpu_indicator_init(void) {
628641
if (Vendor == SIG_INTEL) {
629642
/* Get CPU type. */
630643
getIntelProcessorTypeAndSubtype(Family, Model, Brand_id, Features,
644+
Features2,
631645
&(__cpu_model.__cpu_type),
632646
&(__cpu_model.__cpu_subtype));
633647
__cpu_model.__cpu_vendor = VENDOR_INTEL;
634648
} else if (Vendor == SIG_AMD) {
635649
/* Get CPU type. */
636-
getAMDProcessorTypeAndSubtype(Family, Model, Features,
650+
getAMDProcessorTypeAndSubtype(Family, Model, Features, Features2,
637651
&(__cpu_model.__cpu_type),
638652
&(__cpu_model.__cpu_subtype));
639653
__cpu_model.__cpu_vendor = VENDOR_AMD;

0 commit comments

Comments
 (0)