Skip to content

Commit 87e914d

Browse files
[compiler-rt][X86] Unify getAMDProcessorTypeAndSubType (#97863)
This patch unifies the implementation of getAMDProcessorTypeAndSubtype between compiler-rt and LLVM. This patch is intended to be a step towards pulling these functions out into identical .inc files to better facilitate code sharing between LLVM and compiler-rt.
1 parent 2039e13 commit 87e914d

File tree

2 files changed

+57
-23
lines changed
  • compiler-rt/lib/builtins/cpu_model
  • llvm/lib/TargetParser

2 files changed

+57
-23
lines changed

compiler-rt/lib/builtins/cpu_model/x86.c

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,
367367
}
368368
}
369369

370+
#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
371+
370372
static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
371373
unsigned Model,
372374
const unsigned *Features,
373375
unsigned *Type,
374376
unsigned *Subtype) {
375-
#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
376-
377377
// We select CPU strings to match the code in Host.cpp, but we don't use them
378378
// in compiler-rt.
379379
const char *CPU = 0;
@@ -662,14 +662,48 @@ static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
662662
const unsigned *Features,
663663
unsigned *Type,
664664
unsigned *Subtype) {
665-
// We select CPU strings to match the code in Host.cpp, but we don't use them
666-
// in compiler-rt.
667665
const char *CPU = 0;
668666

669667
switch (Family) {
668+
case 4:
669+
CPU = "i486";
670+
break;
671+
case 5:
672+
CPU = "pentium";
673+
switch (Model) {
674+
case 6:
675+
case 7:
676+
CPU = "k6";
677+
break;
678+
case 8:
679+
CPU = "k6-2";
680+
break;
681+
case 9:
682+
case 13:
683+
CPU = "k6-3";
684+
break;
685+
case 10:
686+
CPU = "geode";
687+
break;
688+
}
689+
break;
690+
case 6:
691+
if (testFeature(FEATURE_SSE)) {
692+
CPU = "athlon-xp";
693+
break;
694+
}
695+
CPU = "athlon";
696+
break;
697+
case 15:
698+
if (testFeature(FEATURE_SSE3)) {
699+
CPU = "k8-sse3";
700+
break;
701+
}
702+
CPU = "k8";
703+
break;
670704
case 16:
671705
CPU = "amdfam10";
672-
*Type = AMDFAM10H;
706+
*Type = AMDFAM10H; // "amdfam10"
673707
switch (Model) {
674708
case 2:
675709
*Subtype = AMDFAM10H_BARCELONA;
@@ -745,7 +779,7 @@ static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
745779
case 25:
746780
CPU = "znver3";
747781
*Type = AMDFAM19H;
748-
if ((Model <= 0x0f) || (Model >= 0x20 && Model <= 0x2f) ||
782+
if (Model <= 0x0f || (Model >= 0x20 && Model <= 0x2f) ||
749783
(Model >= 0x30 && Model <= 0x3f) || (Model >= 0x40 && Model <= 0x4f) ||
750784
(Model >= 0x50 && Model <= 0x5f)) {
751785
// Family 19h Models 00h-0Fh (Genesis, Chagall) Zen 3
@@ -776,6 +810,8 @@ static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
776810
return CPU;
777811
}
778812

813+
#undef testFeature
814+
779815
static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
780816
unsigned *Features) {
781817
unsigned EAX = 0, EBX = 0;

llvm/lib/TargetParser/Host.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,13 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,
703703
}
704704
}
705705

706-
static StringRef
707-
getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
708-
const unsigned *Features,
709-
unsigned *Type, unsigned *Subtype) {
710-
auto testFeature = [&](unsigned F) {
711-
return (Features[F / 32] & (1U << (F % 32))) != 0;
712-
};
706+
#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
713707

708+
static StringRef getIntelProcessorTypeAndSubtype(unsigned Family,
709+
unsigned Model,
710+
const unsigned *Features,
711+
unsigned *Type,
712+
unsigned *Subtype) {
714713
StringRef CPU;
715714

716715
switch (Family) {
@@ -1067,15 +1066,12 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
10671066
return CPU;
10681067
}
10691068

1070-
static StringRef
1071-
getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
1072-
const unsigned *Features,
1073-
unsigned *Type, unsigned *Subtype) {
1074-
auto testFeature = [&](unsigned F) {
1075-
return (Features[F / 32] & (1U << (F % 32))) != 0;
1076-
};
1077-
1078-
StringRef CPU;
1069+
static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
1070+
unsigned Model,
1071+
const unsigned *Features,
1072+
unsigned *Type,
1073+
unsigned *Subtype) {
1074+
const char *CPU = 0;
10791075

10801076
switch (Family) {
10811077
case 4:
@@ -1215,14 +1211,16 @@ getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
12151211
*Subtype = X86::AMDFAM19H_ZNVER4;
12161212
break; // "znver4"
12171213
}
1218-
break;
1214+
break; // family 19h
12191215
default:
12201216
break; // Unknown AMD CPU.
12211217
}
12221218

12231219
return CPU;
12241220
}
12251221

1222+
#undef testFeature;
1223+
12261224
static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
12271225
unsigned *Features) {
12281226
unsigned EAX, EBX;

0 commit comments

Comments
 (0)