18#include "llvm/Config/llvm-config.h"
40#include <mach/host_info.h>
42#include <mach/mach_host.h>
43#include <mach/machine.h>
45#include <sys/sysctl.h>
48#include <sys/systemcfg.h>
50#if defined(__sun__) && defined(__svr4__)
53#if defined(__GNUC__) || defined(__clang__)
54#if (defined(__i386__) || defined(__x86_64__)) && !defined(_MSC_VER)
59#define DEBUG_TYPE "host-detection"
69static std::unique_ptr<llvm::MemoryBuffer>
73 if (std::error_code EC = Text.getError()) {
75 <<
"/proc/cpuinfo: " << EC.message() <<
"\n";
78 return std::move(*Text);
85 const char *
generic =
"generic";
99 while (CIP < CPUInfoEnd && CPUStart ==
nullptr) {
100 if (CIP < CPUInfoEnd && *CIP ==
'\n')
103 if (CIP < CPUInfoEnd && *CIP ==
'c') {
105 if (CIP < CPUInfoEnd && *CIP ==
'p') {
107 if (CIP < CPUInfoEnd && *CIP ==
'u') {
109 while (CIP < CPUInfoEnd && (*CIP ==
' ' || *CIP ==
'\t'))
112 if (CIP < CPUInfoEnd && *CIP ==
':') {
114 while (CIP < CPUInfoEnd && (*CIP ==
' ' || *CIP ==
'\t'))
117 if (CIP < CPUInfoEnd) {
119 while (CIP < CPUInfoEnd && (*CIP !=
' ' && *CIP !=
'\t' &&
120 *CIP !=
',' && *CIP !=
'\n'))
122 CPULen = CIP - CPUStart;
129 if (CPUStart ==
nullptr)
130 while (CIP < CPUInfoEnd && *CIP !=
'\n')
134 if (CPUStart ==
nullptr)
138 .
Case(
"604e",
"604e")
140 .
Case(
"7400",
"7400")
141 .
Case(
"7410",
"7400")
142 .
Case(
"7447",
"7400")
143 .
Case(
"7455",
"7450")
145 .
Case(
"POWER4",
"970")
146 .
Case(
"PPC970FX",
"970")
147 .
Case(
"PPC970MP",
"970")
149 .
Case(
"POWER5",
"g5")
151 .
Case(
"POWER6",
"pwr6")
152 .
Case(
"POWER7",
"pwr7")
153 .
Case(
"POWER8",
"pwr8")
154 .
Case(
"POWER8E",
"pwr8")
155 .
Case(
"POWER8NVL",
"pwr8")
156 .
Case(
"POWER9",
"pwr9")
157 .
Case(
"POWER10",
"pwr10")
158 .
Case(
"POWER11",
"pwr11")
172 ProcCpuinfoContent.
split(Lines,
"\n");
178 for (
unsigned I = 0, E = Lines.size();
I != E; ++
I) {
180 Implementer = Lines[
I].substr(15).ltrim(
"\t :");
182 Hardware = Lines[
I].substr(8).ltrim(
"\t :");
184 Part = Lines[
I].substr(8).ltrim(
"\t :");
187 if (Implementer ==
"0x41") {
200 .
Case(
"0x926",
"arm926ej-s")
201 .
Case(
"0xb02",
"mpcore")
202 .
Case(
"0xb36",
"arm1136j-s")
203 .
Case(
"0xb56",
"arm1156t2-s")
204 .
Case(
"0xb76",
"arm1176jz-s")
205 .
Case(
"0xc05",
"cortex-a5")
206 .
Case(
"0xc07",
"cortex-a7")
207 .
Case(
"0xc08",
"cortex-a8")
208 .
Case(
"0xc09",
"cortex-a9")
209 .
Case(
"0xc0f",
"cortex-a15")
210 .
Case(
"0xc0e",
"cortex-a17")
211 .
Case(
"0xc20",
"cortex-m0")
212 .
Case(
"0xc23",
"cortex-m3")
213 .
Case(
"0xc24",
"cortex-m4")
214 .
Case(
"0xc27",
"cortex-m7")
215 .
Case(
"0xd20",
"cortex-m23")
216 .
Case(
"0xd21",
"cortex-m33")
217 .
Case(
"0xd24",
"cortex-m52")
218 .
Case(
"0xd22",
"cortex-m55")
219 .
Case(
"0xd23",
"cortex-m85")
220 .
Case(
"0xc18",
"cortex-r8")
221 .
Case(
"0xd13",
"cortex-r52")
222 .
Case(
"0xd16",
"cortex-r52plus")
223 .
Case(
"0xd15",
"cortex-r82")
224 .
Case(
"0xd14",
"cortex-r82ae")
225 .
Case(
"0xd02",
"cortex-a34")
226 .
Case(
"0xd04",
"cortex-a35")
227 .
Case(
"0xd03",
"cortex-a53")
228 .
Case(
"0xd05",
"cortex-a55")
229 .
Case(
"0xd46",
"cortex-a510")
230 .
Case(
"0xd80",
"cortex-a520")
231 .
Case(
"0xd88",
"cortex-a520ae")
232 .
Case(
"0xd07",
"cortex-a57")
233 .
Case(
"0xd06",
"cortex-a65")
234 .
Case(
"0xd43",
"cortex-a65ae")
235 .
Case(
"0xd08",
"cortex-a72")
236 .
Case(
"0xd09",
"cortex-a73")
237 .
Case(
"0xd0a",
"cortex-a75")
238 .
Case(
"0xd0b",
"cortex-a76")
239 .
Case(
"0xd0e",
"cortex-a76ae")
240 .
Case(
"0xd0d",
"cortex-a77")
241 .
Case(
"0xd41",
"cortex-a78")
242 .
Case(
"0xd42",
"cortex-a78ae")
243 .
Case(
"0xd4b",
"cortex-a78c")
244 .
Case(
"0xd47",
"cortex-a710")
245 .
Case(
"0xd4d",
"cortex-a715")
246 .
Case(
"0xd81",
"cortex-a720")
247 .
Case(
"0xd89",
"cortex-a720ae")
248 .
Case(
"0xd87",
"cortex-a725")
249 .
Case(
"0xd44",
"cortex-x1")
250 .
Case(
"0xd4c",
"cortex-x1c")
251 .
Case(
"0xd48",
"cortex-x2")
252 .
Case(
"0xd4e",
"cortex-x3")
253 .
Case(
"0xd82",
"cortex-x4")
254 .
Case(
"0xd85",
"cortex-x925")
255 .
Case(
"0xd4a",
"neoverse-e1")
256 .
Case(
"0xd0c",
"neoverse-n1")
257 .
Case(
"0xd49",
"neoverse-n2")
258 .
Case(
"0xd8e",
"neoverse-n3")
259 .
Case(
"0xd40",
"neoverse-v1")
260 .
Case(
"0xd4f",
"neoverse-v2")
261 .
Case(
"0xd84",
"neoverse-v3")
262 .
Case(
"0xd83",
"neoverse-v3ae")
266 if (Implementer ==
"0x42" || Implementer ==
"0x43") {
268 .
Case(
"0x516",
"thunderx2t99")
269 .
Case(
"0x0516",
"thunderx2t99")
270 .
Case(
"0xaf",
"thunderx2t99")
271 .
Case(
"0x0af",
"thunderx2t99")
272 .
Case(
"0xa1",
"thunderxt88")
273 .
Case(
"0x0a1",
"thunderxt88")
277 if (Implementer ==
"0x46") {
279 .
Case(
"0x001",
"a64fx")
283 if (Implementer ==
"0x4e") {
285 .
Case(
"0x004",
"carmel")
289 if (Implementer ==
"0x48")
294 .
Case(
"0xd01",
"tsv110")
297 if (Implementer ==
"0x51")
302 .
Case(
"0x06f",
"krait")
303 .
Case(
"0x201",
"kryo")
304 .
Case(
"0x205",
"kryo")
305 .
Case(
"0x211",
"kryo")
306 .
Case(
"0x800",
"cortex-a73")
307 .
Case(
"0x801",
"cortex-a73")
308 .
Case(
"0x802",
"cortex-a75")
309 .
Case(
"0x803",
"cortex-a75")
310 .
Case(
"0x804",
"cortex-a76")
311 .
Case(
"0x805",
"cortex-a76")
312 .
Case(
"0xc00",
"falkor")
313 .
Case(
"0xc01",
"saphira")
314 .
Case(
"0x001",
"oryon-1")
316 if (Implementer ==
"0x53") {
319 unsigned Variant = 0, Part = 0;
324 if (
I.consume_front(
"CPU variant"))
325 I.ltrim(
"\t :").getAsInteger(0, Variant);
330 if (
I.consume_front(
"CPU part"))
331 I.ltrim(
"\t :").getAsInteger(0, Part);
333 unsigned Exynos = (Variant << 12) | Part;
345 if (Implementer ==
"0x6d") {
348 .
Case(
"0xd49",
"neoverse-n2")
352 if (Implementer ==
"0xc0") {
354 .
Case(
"0xac3",
"ampere1")
355 .
Case(
"0xac4",
"ampere1a")
356 .
Case(
"0xac5",
"ampere1b")
364StringRef getCPUNameFromS390Model(
unsigned int Id,
bool HaveVectorSupport) {
384 return HaveVectorSupport?
"z13" :
"zEC12";
387 return HaveVectorSupport?
"z14" :
"zEC12";
390 return HaveVectorSupport?
"z15" :
"zEC12";
394 return HaveVectorSupport?
"z16" :
"zEC12";
405 ProcCpuinfoContent.
split(Lines,
"\n");
409 for (
unsigned I = 0, E = Lines.size();
I != E; ++
I)
411 size_t Pos = Lines[
I].find(
':');
413 Lines[
I].drop_front(Pos + 1).split(CPUFeatures,
' ');
421 bool HaveVectorSupport =
false;
422 for (
unsigned I = 0, E = CPUFeatures.
size();
I != E; ++
I) {
423 if (CPUFeatures[
I] ==
"vx")
424 HaveVectorSupport =
true;
428 for (
unsigned I = 0, E = Lines.size();
I != E; ++
I) {
430 size_t Pos = Lines[
I].find(
"machine = ");
432 Pos +=
sizeof(
"machine = ") - 1;
434 if (!Lines[
I].drop_front(Pos).getAsInteger(10, Id))
435 return getCPUNameFromS390Model(Id, HaveVectorSupport);
447 ProcCpuinfoContent.
split(Lines,
"\n");
451 for (
unsigned I = 0, E = Lines.size();
I != E; ++
I) {
453 UArch = Lines[
I].substr(5).ltrim(
"\t :");
459 .
Case(
"sifive,u74-mc",
"sifive-u74")
460 .
Case(
"sifive,bullet0",
"sifive-u74")
465#if !defined(__linux__) || !defined(__x86_64__)
468 uint8_t v3_insns[40] __attribute__ ((aligned (8))) =
470 { 0xb7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
472 0xb7, 0x2, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0,
474 0xae, 0x20, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0,
476 0xb7, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0,
478 0x95, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
480 uint8_t v2_insns[40] __attribute__ ((aligned (8))) =
482 { 0xb7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
484 0xb7, 0x2, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0,
486 0xad, 0x20, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0,
488 0xb7, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0,
490 0x95, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
492 struct bpf_prog_load_attr {
508 int fd = syscall(321 , 5 , &attr,
516 memset(&attr, 0,
sizeof(attr));
521 fd = syscall(321 , 5 , &attr,
sizeof(attr));
530#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || \
535static bool getX86CpuIDAndInfo(
unsigned value,
unsigned *rEAX,
unsigned *rEBX,
536 unsigned *rECX,
unsigned *rEDX) {
537#if (defined(__i386__) || defined(__x86_64__)) && !defined(_MSC_VER)
538 return !__get_cpuid(
value, rEAX, rEBX, rECX, rEDX);
539#elif defined(_MSC_VER)
542 __cpuid(registers,
value);
543 *rEAX = registers[0];
544 *rEBX = registers[1];
545 *rECX = registers[2];
546 *rEDX = registers[3];
558VendorSignatures getVendorSignature(
unsigned *MaxLeaf) {
559 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
560 if (MaxLeaf ==
nullptr)
565 if (getX86CpuIDAndInfo(0, MaxLeaf, &EBX, &ECX, &EDX) || *MaxLeaf < 1)
566 return VendorSignatures::UNKNOWN;
569 if (EBX == 0x756e6547 && EDX == 0x49656e69 && ECX == 0x6c65746e)
570 return VendorSignatures::GENUINE_INTEL;
573 if (EBX == 0x68747541 && EDX == 0x69746e65 && ECX == 0x444d4163)
574 return VendorSignatures::AUTHENTIC_AMD;
576 return VendorSignatures::UNKNOWN;
589static bool getX86CpuIDAndInfoEx(
unsigned value,
unsigned subleaf,
590 unsigned *rEAX,
unsigned *rEBX,
unsigned *rECX,
596#if (defined(__i386__) || defined(__x86_64__)) && !defined(_MSC_VER)
597 return !__get_cpuid_count(
value, subleaf, rEAX, rEBX, rECX, rEDX);
598#elif defined(_MSC_VER)
600 __cpuidex(registers,
value, subleaf);
601 *rEAX = registers[0];
602 *rEBX = registers[1];
603 *rECX = registers[2];
604 *rEDX = registers[3];
612static bool getX86XCR0(
unsigned *rEAX,
unsigned *rEDX) {
616#if defined(__GNUC__) || defined(__clang__)
620 __asm__(
".byte 0x0f, 0x01, 0xd0" :
"=a"(*rEAX),
"=d"(*rEDX) :
"c"(0));
622#elif defined(_MSC_FULL_VER) && defined(_XCR_XFEATURE_ENABLED_MASK)
623 unsigned long long Result = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
632static void detectX86FamilyModel(
unsigned EAX,
unsigned *Family,
634 *Family = (
EAX >> 8) & 0xf;
636 if (*Family == 6 || *Family == 0xf) {
639 *Family += (
EAX >> 20) & 0xff;
645#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
647static StringRef getIntelProcessorTypeAndSubtype(
unsigned Family,
649 const unsigned *Features,
662 if (testFeature(X86::FEATURE_MMX)) {
678 *
Type = X86::INTEL_CORE2;
687 *
Type = X86::INTEL_CORE2;
696 *
Type = X86::INTEL_COREI7;
697 *Subtype = X86::INTEL_COREI7_NEHALEM;
704 *
Type = X86::INTEL_COREI7;
705 *Subtype = X86::INTEL_COREI7_WESTMERE;
711 *
Type = X86::INTEL_COREI7;
712 *Subtype = X86::INTEL_COREI7_SANDYBRIDGE;
717 *
Type = X86::INTEL_COREI7;
718 *Subtype = X86::INTEL_COREI7_IVYBRIDGE;
727 *
Type = X86::INTEL_COREI7;
728 *Subtype = X86::INTEL_COREI7_HASWELL;
737 *
Type = X86::INTEL_COREI7;
738 *Subtype = X86::INTEL_COREI7_BROADWELL;
749 *
Type = X86::INTEL_COREI7;
750 *Subtype = X86::INTEL_COREI7_SKYLAKE;
756 *
Type = X86::INTEL_COREI7;
757 *Subtype = X86::INTEL_COREI7_ROCKETLAKE;
762 *
Type = X86::INTEL_COREI7;
763 if (testFeature(X86::FEATURE_AVX512BF16)) {
765 *Subtype = X86::INTEL_COREI7_COOPERLAKE;
766 }
else if (testFeature(X86::FEATURE_AVX512VNNI)) {
768 *Subtype = X86::INTEL_COREI7_CASCADELAKE;
770 CPU =
"skylake-avx512";
771 *Subtype = X86::INTEL_COREI7_SKYLAKE_AVX512;
778 *
Type = X86::INTEL_COREI7;
779 *Subtype = X86::INTEL_COREI7_CANNONLAKE;
785 CPU =
"icelake-client";
786 *
Type = X86::INTEL_COREI7;
787 *Subtype = X86::INTEL_COREI7_ICELAKE_CLIENT;
794 *
Type = X86::INTEL_COREI7;
795 *Subtype = X86::INTEL_COREI7_TIGERLAKE;
811 *
Type = X86::INTEL_COREI7;
812 *Subtype = X86::INTEL_COREI7_ALDERLAKE;
818 *
Type = X86::INTEL_COREI7;
819 *Subtype = X86::INTEL_COREI7_ARROWLAKE;
827 *
Type = X86::INTEL_COREI7;
828 *Subtype = X86::INTEL_COREI7_ARROWLAKE_S;
834 *
Type = X86::INTEL_COREI7;
835 *Subtype = X86::INTEL_COREI7_PANTHERLAKE;
840 CPU =
"graniterapids";
841 *
Type = X86::INTEL_COREI7;
842 *Subtype = X86::INTEL_COREI7_GRANITERAPIDS;
847 CPU =
"graniterapids-d";
848 *
Type = X86::INTEL_COREI7;
849 *Subtype = X86::INTEL_COREI7_GRANITERAPIDS_D;
855 CPU =
"icelake-server";
856 *
Type = X86::INTEL_COREI7;
857 *Subtype = X86::INTEL_COREI7_ICELAKE_SERVER;
864 CPU =
"sapphirerapids";
865 *
Type = X86::INTEL_COREI7;
866 *Subtype = X86::INTEL_COREI7_SAPPHIRERAPIDS;
875 *
Type = X86::INTEL_BONNELL;
886 *
Type = X86::INTEL_SILVERMONT;
892 *
Type = X86::INTEL_GOLDMONT;
895 CPU =
"goldmont-plus";
896 *
Type = X86::INTEL_GOLDMONT_PLUS;
903 *
Type = X86::INTEL_TREMONT;
908 CPU =
"sierraforest";
909 *
Type = X86::INTEL_SIERRAFOREST;
915 *
Type = X86::INTEL_GRANDRIDGE;
920 CPU =
"clearwaterforest";
921 *
Type = X86::INTEL_CLEARWATERFOREST;
927 *
Type = X86::INTEL_KNL;
931 *
Type = X86::INTEL_KNM;
938 if (testFeature(X86::FEATURE_AVX512VP2INTERSECT)) {
940 }
else if (testFeature(X86::FEATURE_AVX512VBMI2)) {
941 CPU =
"icelake-client";
942 }
else if (testFeature(X86::FEATURE_AVX512VBMI)) {
944 }
else if (testFeature(X86::FEATURE_AVX512BF16)) {
946 }
else if (testFeature(X86::FEATURE_AVX512VNNI)) {
948 }
else if (testFeature(X86::FEATURE_AVX512VL)) {
949 CPU =
"skylake-avx512";
950 }
else if (testFeature(X86::FEATURE_CLFLUSHOPT)) {
951 if (testFeature(X86::FEATURE_SHA))
955 }
else if (testFeature(X86::FEATURE_ADX)) {
957 }
else if (testFeature(X86::FEATURE_AVX2)) {
959 }
else if (testFeature(X86::FEATURE_AVX)) {
961 }
else if (testFeature(X86::FEATURE_SSE4_2)) {
962 if (testFeature(X86::FEATURE_MOVBE))
966 }
else if (testFeature(X86::FEATURE_SSE4_1)) {
968 }
else if (testFeature(X86::FEATURE_SSSE3)) {
969 if (testFeature(X86::FEATURE_MOVBE))
973 }
else if (testFeature(X86::FEATURE_64BIT)) {
975 }
else if (testFeature(X86::FEATURE_SSE3)) {
977 }
else if (testFeature(X86::FEATURE_SSE2)) {
979 }
else if (testFeature(X86::FEATURE_SSE)) {
981 }
else if (testFeature(X86::FEATURE_MMX)) {
990 if (testFeature(X86::FEATURE_64BIT)) {
994 if (testFeature(X86::FEATURE_SSE3)) {
1008static const char *getAMDProcessorTypeAndSubtype(
unsigned Family,
1010 const unsigned *Features,
1012 unsigned *Subtype) {
1013 const char *CPU = 0;
1039 if (testFeature(X86::FEATURE_SSE)) {
1046 if (testFeature(X86::FEATURE_SSE3)) {
1054 *
Type = X86::AMDFAM10H;
1057 *Subtype = X86::AMDFAM10H_BARCELONA;
1060 *Subtype = X86::AMDFAM10H_SHANGHAI;
1063 *Subtype = X86::AMDFAM10H_ISTANBUL;
1069 *
Type = X86::AMD_BTVER1;
1073 *
Type = X86::AMDFAM15H;
1074 if (Model >= 0x60 && Model <= 0x7f) {
1076 *Subtype = X86::AMDFAM15H_BDVER4;
1079 if (Model >= 0x30 && Model <= 0x3f) {
1081 *Subtype = X86::AMDFAM15H_BDVER3;
1084 if ((Model >= 0x10 && Model <= 0x1f) || Model == 0x02) {
1086 *Subtype = X86::AMDFAM15H_BDVER2;
1089 if (Model <= 0x0f) {
1090 *Subtype = X86::AMDFAM15H_BDVER1;
1096 *
Type = X86::AMD_BTVER2;
1100 *
Type = X86::AMDFAM17H;
1101 if ((Model >= 0x30 && Model <= 0x3f) || (Model == 0x47) ||
1102 (Model >= 0x60 && Model <= 0x67) || (Model >= 0x68 && Model <= 0x6f) ||
1103 (Model >= 0x70 && Model <= 0x7f) || (Model >= 0x84 && Model <= 0x87) ||
1104 (Model >= 0x90 && Model <= 0x97) || (Model >= 0x98 && Model <= 0x9f) ||
1105 (Model >= 0xa0 && Model <= 0xaf)) {
1116 *Subtype = X86::AMDFAM17H_ZNVER2;
1119 if ((Model >= 0x10 && Model <= 0x1f) || (Model >= 0x20 && Model <= 0x2f)) {
1123 *Subtype = X86::AMDFAM17H_ZNVER1;
1129 *
Type = X86::AMDFAM19H;
1130 if (Model <= 0x0f || (Model >= 0x20 && Model <= 0x2f) ||
1131 (Model >= 0x30 && Model <= 0x3f) || (Model >= 0x40 && Model <= 0x4f) ||
1132 (Model >= 0x50 && Model <= 0x5f)) {
1138 *Subtype = X86::AMDFAM19H_ZNVER3;
1141 if ((Model >= 0x10 && Model <= 0x1f) || (Model >= 0x60 && Model <= 0x6f) ||
1142 (Model >= 0x70 && Model <= 0x77) || (Model >= 0x78 && Model <= 0x7f) ||
1143 (Model >= 0xa0 && Model <= 0xaf)) {
1150 *Subtype = X86::AMDFAM19H_ZNVER4;
1163static void getAvailableFeatures(
unsigned ECX,
unsigned EDX,
unsigned MaxLeaf,
1164 unsigned *Features) {
1167 auto setFeature = [&](
unsigned F) {
1168 Features[
F / 32] |= 1U << (
F % 32);
1171 if ((EDX >> 15) & 1)
1172 setFeature(X86::FEATURE_CMOV);
1173 if ((EDX >> 23) & 1)
1174 setFeature(X86::FEATURE_MMX);
1175 if ((EDX >> 25) & 1)
1176 setFeature(X86::FEATURE_SSE);
1177 if ((EDX >> 26) & 1)
1178 setFeature(X86::FEATURE_SSE2);
1181 setFeature(X86::FEATURE_SSE3);
1183 setFeature(X86::FEATURE_PCLMUL);
1185 setFeature(X86::FEATURE_SSSE3);
1186 if ((ECX >> 12) & 1)
1187 setFeature(X86::FEATURE_FMA);
1188 if ((ECX >> 19) & 1)
1189 setFeature(X86::FEATURE_SSE4_1);
1190 if ((ECX >> 20) & 1) {
1191 setFeature(X86::FEATURE_SSE4_2);
1192 setFeature(X86::FEATURE_CRC32);
1194 if ((ECX >> 23) & 1)
1195 setFeature(X86::FEATURE_POPCNT);
1196 if ((ECX >> 25) & 1)
1197 setFeature(X86::FEATURE_AES);
1199 if ((ECX >> 22) & 1)
1200 setFeature(X86::FEATURE_MOVBE);
1205 const unsigned AVXBits = (1 << 27) | (1 << 28);
1206 bool HasAVX = ((
ECX & AVXBits) == AVXBits) && !getX86XCR0(&EAX, &EDX) &&
1207 ((
EAX & 0x6) == 0x6);
1208#if defined(__APPLE__)
1212 bool HasAVX512Save =
true;
1215 bool HasAVX512Save = HasAVX && ((
EAX & 0xe0) == 0xe0);
1219 setFeature(X86::FEATURE_AVX);
1222 MaxLeaf >= 0x7 && !getX86CpuIDAndInfoEx(0x7, 0x0, &EAX, &EBX, &ECX, &EDX);
1224 if (HasLeaf7 && ((EBX >> 3) & 1))
1225 setFeature(X86::FEATURE_BMI);
1226 if (HasLeaf7 && ((EBX >> 5) & 1) && HasAVX)
1227 setFeature(X86::FEATURE_AVX2);
1228 if (HasLeaf7 && ((EBX >> 8) & 1))
1229 setFeature(X86::FEATURE_BMI2);
1230 if (HasLeaf7 && ((EBX >> 16) & 1) && HasAVX512Save) {
1231 setFeature(X86::FEATURE_AVX512F);
1232 setFeature(X86::FEATURE_EVEX512);
1234 if (HasLeaf7 && ((EBX >> 17) & 1) && HasAVX512Save)
1235 setFeature(X86::FEATURE_AVX512DQ);
1236 if (HasLeaf7 && ((EBX >> 19) & 1))
1237 setFeature(X86::FEATURE_ADX);
1238 if (HasLeaf7 && ((EBX >> 21) & 1) && HasAVX512Save)
1239 setFeature(X86::FEATURE_AVX512IFMA);
1240 if (HasLeaf7 && ((EBX >> 23) & 1))
1241 setFeature(X86::FEATURE_CLFLUSHOPT);
1242 if (HasLeaf7 && ((EBX >> 28) & 1) && HasAVX512Save)
1243 setFeature(X86::FEATURE_AVX512CD);
1244 if (HasLeaf7 && ((EBX >> 29) & 1))
1245 setFeature(X86::FEATURE_SHA);
1246 if (HasLeaf7 && ((EBX >> 30) & 1) && HasAVX512Save)
1247 setFeature(X86::FEATURE_AVX512BW);
1248 if (HasLeaf7 && ((EBX >> 31) & 1) && HasAVX512Save)
1249 setFeature(X86::FEATURE_AVX512VL);
1251 if (HasLeaf7 && ((ECX >> 1) & 1) && HasAVX512Save)
1252 setFeature(X86::FEATURE_AVX512VBMI);
1253 if (HasLeaf7 && ((ECX >> 6) & 1) && HasAVX512Save)
1254 setFeature(X86::FEATURE_AVX512VBMI2);
1255 if (HasLeaf7 && ((ECX >> 8) & 1))
1256 setFeature(X86::FEATURE_GFNI);
1257 if (HasLeaf7 && ((ECX >> 10) & 1) && HasAVX)
1258 setFeature(X86::FEATURE_VPCLMULQDQ);
1259 if (HasLeaf7 && ((ECX >> 11) & 1) && HasAVX512Save)
1260 setFeature(X86::FEATURE_AVX512VNNI);
1261 if (HasLeaf7 && ((ECX >> 12) & 1) && HasAVX512Save)
1262 setFeature(X86::FEATURE_AVX512BITALG);
1263 if (HasLeaf7 && ((ECX >> 14) & 1) && HasAVX512Save)
1264 setFeature(X86::FEATURE_AVX512VPOPCNTDQ);
1266 if (HasLeaf7 && ((EDX >> 2) & 1) && HasAVX512Save)
1267 setFeature(X86::FEATURE_AVX5124VNNIW);
1268 if (HasLeaf7 && ((EDX >> 3) & 1) && HasAVX512Save)
1269 setFeature(X86::FEATURE_AVX5124FMAPS);
1270 if (HasLeaf7 && ((EDX >> 8) & 1) && HasAVX512Save)
1271 setFeature(X86::FEATURE_AVX512VP2INTERSECT);
1275 bool HasLeaf7Subleaf1 =
1276 HasLeaf7 &&
EAX >= 1 &&
1277 !getX86CpuIDAndInfoEx(0x7, 0x1, &EAX, &EBX, &ECX, &EDX);
1278 if (HasLeaf7Subleaf1 && ((EAX >> 5) & 1) && HasAVX512Save)
1279 setFeature(X86::FEATURE_AVX512BF16);
1281 unsigned MaxExtLevel;
1282 getX86CpuIDAndInfo(0x80000000, &MaxExtLevel, &EBX, &ECX, &EDX);
1284 bool HasExtLeaf1 = MaxExtLevel >= 0x80000001 &&
1285 !getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
1286 if (HasExtLeaf1 && ((ECX >> 6) & 1))
1287 setFeature(X86::FEATURE_SSE4_A);
1288 if (HasExtLeaf1 && ((ECX >> 11) & 1))
1289 setFeature(X86::FEATURE_XOP);
1290 if (HasExtLeaf1 && ((ECX >> 16) & 1))
1291 setFeature(X86::FEATURE_FMA4);
1293 if (HasExtLeaf1 && ((EDX >> 29) & 1))
1294 setFeature(X86::FEATURE_64BIT);
1298 unsigned MaxLeaf = 0;
1300 if (Vendor == VendorSignatures::UNKNOWN)
1304 getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
1306 unsigned Family = 0,
Model = 0;
1308 detectX86FamilyModel(EAX, &Family, &Model);
1309 getAvailableFeatures(ECX, EDX, MaxLeaf, Features);
1314 unsigned Subtype = 0;
1318 if (Vendor == VendorSignatures::GENUINE_INTEL) {
1319 CPU = getIntelProcessorTypeAndSubtype(Family, Model, Features, &
Type,
1321 }
else if (Vendor == VendorSignatures::AUTHENTIC_AMD) {
1322 CPU = getAMDProcessorTypeAndSubtype(Family, Model, Features, &
Type,
1332#elif defined(__APPLE__) && defined(__powerpc__)
1334 host_basic_info_data_t hostInfo;
1335 mach_msg_type_number_t infoCount;
1337 infoCount = HOST_BASIC_INFO_COUNT;
1338 mach_port_t hostPort = mach_host_self();
1339 host_info(hostPort, HOST_BASIC_INFO, (host_info_t)&hostInfo,
1341 mach_port_deallocate(mach_task_self(), hostPort);
1343 if (hostInfo.cpu_type != CPU_TYPE_POWERPC)
1346 switch (hostInfo.cpu_subtype) {
1376#elif defined(__linux__) && defined(__powerpc__)
1380 return detail::getHostCPUNameForPowerPC(
Content);
1382#elif defined(__linux__) && (defined(__arm__) || defined(__aarch64__))
1386 return detail::getHostCPUNameForARM(
Content);
1388#elif defined(__linux__) && defined(__s390x__)
1392 return detail::getHostCPUNameForS390x(
Content);
1394#elif defined(__MVS__)
1399 int *StartToCVTOffset =
reinterpret_cast<int *
>(0x10);
1402 int ReadValue = *StartToCVTOffset;
1404 ReadValue = (ReadValue & 0x7FFFFFFF);
1405 char *CVT =
reinterpret_cast<char *
>(ReadValue);
1410 Id = decodePackedBCD<uint16_t>(Id,
false);
1414 bool HaveVectorSupport = CVT[244] & 0x80;
1415 return getCPUNameFromS390Model(Id, HaveVectorSupport);
1417#elif defined(__APPLE__) && (defined(__arm__) || defined(__aarch64__))
1418#define CPUFAMILY_ARM_SWIFT 0x1e2d6381
1419#define CPUFAMILY_ARM_CYCLONE 0x37a09642
1420#define CPUFAMILY_ARM_TYPHOON 0x2c91a47e
1421#define CPUFAMILY_ARM_TWISTER 0x92fb37c8
1422#define CPUFAMILY_ARM_HURRICANE 0x67ceee93
1423#define CPUFAMILY_ARM_MONSOON_MISTRAL 0xe81e7ef6
1424#define CPUFAMILY_ARM_VORTEX_TEMPEST 0x07d34b9f
1425#define CPUFAMILY_ARM_LIGHTNING_THUNDER 0x462504d2
1426#define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1b588bb3
1427#define CPUFAMILY_ARM_BLIZZARD_AVALANCHE 0xda33d83d
1428#define CPUFAMILY_ARM_EVEREST_SAWTOOTH 0x8765edea
1432 size_t Length =
sizeof(Family);
1433 sysctlbyname(
"hw.cpufamily", &Family, &
Length, NULL, 0);
1436 case CPUFAMILY_ARM_SWIFT:
1438 case CPUFAMILY_ARM_CYCLONE:
1440 case CPUFAMILY_ARM_TYPHOON:
1442 case CPUFAMILY_ARM_TWISTER:
1444 case CPUFAMILY_ARM_HURRICANE:
1446 case CPUFAMILY_ARM_MONSOON_MISTRAL:
1448 case CPUFAMILY_ARM_VORTEX_TEMPEST:
1450 case CPUFAMILY_ARM_LIGHTNING_THUNDER:
1452 case CPUFAMILY_ARM_FIRESTORM_ICESTORM:
1454 case CPUFAMILY_ARM_BLIZZARD_AVALANCHE:
1456 case CPUFAMILY_ARM_EVEREST_SAWTOOTH:
1465 switch (_system_configuration.implementation) {
1467 if (_system_configuration.version == PV_4_3)
1471 if (_system_configuration.version == PV_5)
1475 if (_system_configuration.version == PV_6_Compat)
1501#elif defined(__loongarch__)
1505 __asm__(
"cpucfg %[prid], $zero\n\t" : [prid]
"=r"(processor_id));
1507 switch (processor_id & 0xf000) {
1518#elif defined(__riscv)
1520#if defined(__linux__)
1527#if __riscv_xlen == 64
1528 return "generic-rv64";
1529#elif __riscv_xlen == 32
1530 return "generic-rv32";
1532#error "Unhandled value of __riscv_xlen"
1535#elif defined(__sparc__)
1536#if defined(__linux__)
1539 ProcCpuinfoContent.
split(Lines,
"\n");
1543 for (
unsigned I = 0, E =
Lines.size();
I != E; ++
I) {
1545 Cpu =
Lines[
I].substr(5).ltrim(
"\t :");
1577#if defined(__linux__)
1580 return detail::getHostCPUNameForSPARC(
Content);
1581#elif defined(__sun__) && defined(__svr4__)
1585 kstat_named_t *brand = NULL;
1589 ksp = kstat_lookup(kc,
const_cast<char *
>(
"cpu_info"), -1, NULL);
1590 if (ksp != NULL && kstat_read(kc, ksp, NULL) != -1 &&
1591 ksp->ks_type == KSTAT_TYPE_NAMED)
1593 (kstat_named_t *)kstat_data_lookup(ksp,
const_cast<char *
>(
"brand"));
1594 if (brand != NULL && brand->data_type == KSTAT_DATA_STRING)
1595 buf = KSTAT_NAMED_STR_PTR(brand);
1600 .
Case(
"TMS390S10",
"supersparc")
1601 .
Case(
"TMS390Z50",
"supersparc")
1604 .
Case(
"MB86904",
"supersparc")
1605 .
Case(
"MB86907",
"supersparc")
1606 .
Case(
"RT623",
"hypersparc")
1607 .
Case(
"RT625",
"hypersparc")
1608 .
Case(
"RT626",
"hypersparc")
1609 .
Case(
"UltraSPARC-I",
"ultrasparc")
1610 .
Case(
"UltraSPARC-II",
"ultrasparc")
1611 .
Case(
"UltraSPARC-IIe",
"ultrasparc")
1612 .
Case(
"UltraSPARC-IIi",
"ultrasparc")
1613 .
Case(
"SPARC64-III",
"ultrasparc")
1614 .
Case(
"SPARC64-IV",
"ultrasparc")
1615 .
Case(
"UltraSPARC-III",
"ultrasparc3")
1616 .
Case(
"UltraSPARC-III+",
"ultrasparc3")
1617 .
Case(
"UltraSPARC-IIIi",
"ultrasparc3")
1618 .
Case(
"UltraSPARC-IIIi+",
"ultrasparc3")
1619 .
Case(
"UltraSPARC-IV",
"ultrasparc3")
1620 .
Case(
"UltraSPARC-IV+",
"ultrasparc3")
1621 .
Case(
"SPARC64-V",
"ultrasparc3")
1622 .
Case(
"SPARC64-VI",
"ultrasparc3")
1623 .
Case(
"SPARC64-VII",
"ultrasparc3")
1624 .
Case(
"UltraSPARC-T1",
"niagara")
1625 .
Case(
"UltraSPARC-T2",
"niagara2")
1626 .
Case(
"UltraSPARC-T2",
"niagara2")
1627 .
Case(
"UltraSPARC-T2+",
"niagara2")
1628 .
Case(
"SPARC-T3",
"niagara3")
1629 .
Case(
"SPARC-T4",
"niagara4")
1630 .
Case(
"SPARC-T5",
"niagara4")
1632 .
Case(
"SPARC-M7",
"niagara4" )
1633 .
Case(
"SPARC-S7",
"niagara4" )
1634 .
Case(
"SPARC-M8",
"niagara4" )
1657#if defined(__i386__) || defined(_M_IX86) || \
1658 defined(__x86_64__) || defined(_M_X64)
1664 if (getX86CpuIDAndInfo(0, &MaxLevel, &EBX, &ECX, &EDX) || MaxLevel < 1)
1667 getX86CpuIDAndInfo(1, &EAX, &EBX, &ECX, &EDX);
1669 Features[
"cx8"] = (
EDX >> 8) & 1;
1670 Features[
"cmov"] = (
EDX >> 15) & 1;
1671 Features[
"mmx"] = (
EDX >> 23) & 1;
1672 Features[
"fxsr"] = (
EDX >> 24) & 1;
1673 Features[
"sse"] = (
EDX >> 25) & 1;
1674 Features[
"sse2"] = (
EDX >> 26) & 1;
1676 Features[
"sse3"] = (
ECX >> 0) & 1;
1677 Features[
"pclmul"] = (
ECX >> 1) & 1;
1678 Features[
"ssse3"] = (
ECX >> 9) & 1;
1679 Features[
"cx16"] = (
ECX >> 13) & 1;
1680 Features[
"sse4.1"] = (
ECX >> 19) & 1;
1681 Features[
"sse4.2"] = (
ECX >> 20) & 1;
1682 Features[
"crc32"] = Features[
"sse4.2"];
1683 Features[
"movbe"] = (
ECX >> 22) & 1;
1684 Features[
"popcnt"] = (
ECX >> 23) & 1;
1685 Features[
"aes"] = (
ECX >> 25) & 1;
1686 Features[
"rdrnd"] = (
ECX >> 30) & 1;
1691 bool HasXSave = ((
ECX >> 27) & 1) && !getX86XCR0(&EAX, &EDX);
1692 bool HasAVXSave = HasXSave && ((
ECX >> 28) & 1) && ((
EAX & 0x6) == 0x6);
1693#if defined(__APPLE__)
1697 bool HasAVX512Save =
true;
1700 bool HasAVX512Save = HasAVXSave && ((
EAX & 0xe0) == 0xe0);
1703 const unsigned AMXBits = (1 << 17) | (1 << 18);
1704 bool HasAMXSave = HasXSave && ((
EAX & AMXBits) == AMXBits);
1706 Features[
"avx"] = HasAVXSave;
1707 Features[
"fma"] = ((
ECX >> 12) & 1) && HasAVXSave;
1709 Features[
"xsave"] = ((
ECX >> 26) & 1) && HasAVXSave;
1710 Features[
"f16c"] = ((
ECX >> 29) & 1) && HasAVXSave;
1712 unsigned MaxExtLevel;
1713 getX86CpuIDAndInfo(0x80000000, &MaxExtLevel, &EBX, &ECX, &EDX);
1715 bool HasExtLeaf1 = MaxExtLevel >= 0x80000001 &&
1716 !getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
1717 Features[
"sahf"] = HasExtLeaf1 && ((
ECX >> 0) & 1);
1718 Features[
"lzcnt"] = HasExtLeaf1 && ((
ECX >> 5) & 1);
1719 Features[
"sse4a"] = HasExtLeaf1 && ((
ECX >> 6) & 1);
1720 Features[
"prfchw"] = HasExtLeaf1 && ((
ECX >> 8) & 1);
1721 Features[
"xop"] = HasExtLeaf1 && ((
ECX >> 11) & 1) && HasAVXSave;
1722 Features[
"lwp"] = HasExtLeaf1 && ((
ECX >> 15) & 1);
1723 Features[
"fma4"] = HasExtLeaf1 && ((
ECX >> 16) & 1) && HasAVXSave;
1724 Features[
"tbm"] = HasExtLeaf1 && ((
ECX >> 21) & 1);
1725 Features[
"mwaitx"] = HasExtLeaf1 && ((
ECX >> 29) & 1);
1727 Features[
"64bit"] = HasExtLeaf1 && ((
EDX >> 29) & 1);
1731 bool HasExtLeaf8 = MaxExtLevel >= 0x80000008 &&
1732 !getX86CpuIDAndInfo(0x80000008, &EAX, &EBX, &ECX, &EDX);
1733 Features[
"clzero"] = HasExtLeaf8 && ((
EBX >> 0) & 1);
1734 Features[
"rdpru"] = HasExtLeaf8 && ((
EBX >> 4) & 1);
1735 Features[
"wbnoinvd"] = HasExtLeaf8 && ((
EBX >> 9) & 1);
1738 MaxLevel >= 7 && !getX86CpuIDAndInfoEx(0x7, 0x0, &EAX, &EBX, &ECX, &EDX);
1740 Features[
"fsgsbase"] = HasLeaf7 && ((
EBX >> 0) & 1);
1741 Features[
"sgx"] = HasLeaf7 && ((
EBX >> 2) & 1);
1742 Features[
"bmi"] = HasLeaf7 && ((
EBX >> 3) & 1);
1744 Features[
"avx2"] = HasLeaf7 && ((
EBX >> 5) & 1) && HasAVXSave;
1745 Features[
"bmi2"] = HasLeaf7 && ((
EBX >> 8) & 1);
1746 Features[
"invpcid"] = HasLeaf7 && ((
EBX >> 10) & 1);
1747 Features[
"rtm"] = HasLeaf7 && ((
EBX >> 11) & 1);
1749 Features[
"avx512f"] = HasLeaf7 && ((
EBX >> 16) & 1) && HasAVX512Save;
1750 if (Features[
"avx512f"])
1751 Features[
"evex512"] =
true;
1752 Features[
"avx512dq"] = HasLeaf7 && ((
EBX >> 17) & 1) && HasAVX512Save;
1753 Features[
"rdseed"] = HasLeaf7 && ((
EBX >> 18) & 1);
1754 Features[
"adx"] = HasLeaf7 && ((
EBX >> 19) & 1);
1755 Features[
"avx512ifma"] = HasLeaf7 && ((
EBX >> 21) & 1) && HasAVX512Save;
1756 Features[
"clflushopt"] = HasLeaf7 && ((
EBX >> 23) & 1);
1757 Features[
"clwb"] = HasLeaf7 && ((
EBX >> 24) & 1);
1758 Features[
"avx512cd"] = HasLeaf7 && ((
EBX >> 28) & 1) && HasAVX512Save;
1759 Features[
"sha"] = HasLeaf7 && ((
EBX >> 29) & 1);
1760 Features[
"avx512bw"] = HasLeaf7 && ((
EBX >> 30) & 1) && HasAVX512Save;
1761 Features[
"avx512vl"] = HasLeaf7 && ((
EBX >> 31) & 1) && HasAVX512Save;
1763 Features[
"avx512vbmi"] = HasLeaf7 && ((
ECX >> 1) & 1) && HasAVX512Save;
1764 Features[
"pku"] = HasLeaf7 && ((
ECX >> 4) & 1);
1765 Features[
"waitpkg"] = HasLeaf7 && ((
ECX >> 5) & 1);
1766 Features[
"avx512vbmi2"] = HasLeaf7 && ((
ECX >> 6) & 1) && HasAVX512Save;
1767 Features[
"shstk"] = HasLeaf7 && ((
ECX >> 7) & 1);
1768 Features[
"gfni"] = HasLeaf7 && ((
ECX >> 8) & 1);
1769 Features[
"vaes"] = HasLeaf7 && ((
ECX >> 9) & 1) && HasAVXSave;
1770 Features[
"vpclmulqdq"] = HasLeaf7 && ((
ECX >> 10) & 1) && HasAVXSave;
1771 Features[
"avx512vnni"] = HasLeaf7 && ((
ECX >> 11) & 1) && HasAVX512Save;
1772 Features[
"avx512bitalg"] = HasLeaf7 && ((
ECX >> 12) & 1) && HasAVX512Save;
1773 Features[
"avx512vpopcntdq"] = HasLeaf7 && ((
ECX >> 14) & 1) && HasAVX512Save;
1774 Features[
"rdpid"] = HasLeaf7 && ((
ECX >> 22) & 1);
1775 Features[
"kl"] = HasLeaf7 && ((
ECX >> 23) & 1);
1776 Features[
"cldemote"] = HasLeaf7 && ((
ECX >> 25) & 1);
1777 Features[
"movdiri"] = HasLeaf7 && ((
ECX >> 27) & 1);
1778 Features[
"movdir64b"] = HasLeaf7 && ((
ECX >> 28) & 1);
1779 Features[
"enqcmd"] = HasLeaf7 && ((
ECX >> 29) & 1);
1781 Features[
"uintr"] = HasLeaf7 && ((
EDX >> 5) & 1);
1782 Features[
"avx512vp2intersect"] =
1783 HasLeaf7 && ((
EDX >> 8) & 1) && HasAVX512Save;
1784 Features[
"serialize"] = HasLeaf7 && ((
EDX >> 14) & 1);
1785 Features[
"tsxldtrk"] = HasLeaf7 && ((
EDX >> 16) & 1);
1796 Features[
"pconfig"] = HasLeaf7 && ((
EDX >> 18) & 1);
1797 Features[
"amx-bf16"] = HasLeaf7 && ((
EDX >> 22) & 1) && HasAMXSave;
1798 Features[
"avx512fp16"] = HasLeaf7 && ((
EDX >> 23) & 1) && HasAVX512Save;
1799 Features[
"amx-tile"] = HasLeaf7 && ((
EDX >> 24) & 1) && HasAMXSave;
1800 Features[
"amx-int8"] = HasLeaf7 && ((
EDX >> 25) & 1) && HasAMXSave;
1803 bool HasLeaf7Subleaf1 =
1804 HasLeaf7 &&
EAX >= 1 &&
1805 !getX86CpuIDAndInfoEx(0x7, 0x1, &EAX, &EBX, &ECX, &EDX);
1806 Features[
"sha512"] = HasLeaf7Subleaf1 && ((
EAX >> 0) & 1);
1807 Features[
"sm3"] = HasLeaf7Subleaf1 && ((
EAX >> 1) & 1);
1808 Features[
"sm4"] = HasLeaf7Subleaf1 && ((
EAX >> 2) & 1);
1809 Features[
"raoint"] = HasLeaf7Subleaf1 && ((
EAX >> 3) & 1);
1810 Features[
"avxvnni"] = HasLeaf7Subleaf1 && ((
EAX >> 4) & 1) && HasAVXSave;
1811 Features[
"avx512bf16"] = HasLeaf7Subleaf1 && ((
EAX >> 5) & 1) && HasAVX512Save;
1812 Features[
"amx-fp16"] = HasLeaf7Subleaf1 && ((
EAX >> 21) & 1) && HasAMXSave;
1813 Features[
"cmpccxadd"] = HasLeaf7Subleaf1 && ((
EAX >> 7) & 1);
1814 Features[
"hreset"] = HasLeaf7Subleaf1 && ((
EAX >> 22) & 1);
1815 Features[
"avxifma"] = HasLeaf7Subleaf1 && ((
EAX >> 23) & 1) && HasAVXSave;
1816 Features[
"avxvnniint8"] = HasLeaf7Subleaf1 && ((
EDX >> 4) & 1) && HasAVXSave;
1817 Features[
"avxneconvert"] = HasLeaf7Subleaf1 && ((
EDX >> 5) & 1) && HasAVXSave;
1818 Features[
"amx-complex"] = HasLeaf7Subleaf1 && ((
EDX >> 8) & 1) && HasAMXSave;
1819 Features[
"avxvnniint16"] = HasLeaf7Subleaf1 && ((
EDX >> 10) & 1) && HasAVXSave;
1820 Features[
"prefetchi"] = HasLeaf7Subleaf1 && ((
EDX >> 14) & 1);
1821 Features[
"usermsr"] = HasLeaf7Subleaf1 && ((
EDX >> 15) & 1);
1822 bool HasAVX10 = HasLeaf7Subleaf1 && ((
EDX >> 19) & 1);
1823 bool HasAPXF = HasLeaf7Subleaf1 && ((
EDX >> 21) & 1);
1824 Features[
"egpr"] = HasAPXF;
1825 Features[
"push2pop2"] = HasAPXF;
1826 Features[
"ppx"] = HasAPXF;
1827 Features[
"ndd"] = HasAPXF;
1828 Features[
"ccmp"] = HasAPXF;
1829 Features[
"nf"] = HasAPXF;
1830 Features[
"cf"] = HasAPXF;
1831 Features[
"zu"] = HasAPXF;
1833 bool HasLeafD = MaxLevel >= 0xd &&
1834 !getX86CpuIDAndInfoEx(0xd, 0x1, &EAX, &EBX, &ECX, &EDX);
1837 Features[
"xsaveopt"] = HasLeafD && ((
EAX >> 0) & 1) && HasAVXSave;
1838 Features[
"xsavec"] = HasLeafD && ((
EAX >> 1) & 1) && HasAVXSave;
1839 Features[
"xsaves"] = HasLeafD && ((
EAX >> 3) & 1) && HasAVXSave;
1841 bool HasLeaf14 = MaxLevel >= 0x14 &&
1842 !getX86CpuIDAndInfoEx(0x14, 0x0, &EAX, &EBX, &ECX, &EDX);
1844 Features[
"ptwrite"] = HasLeaf14 && ((
EBX >> 4) & 1);
1847 MaxLevel >= 0x19 && !getX86CpuIDAndInfo(0x19, &EAX, &EBX, &ECX, &EDX);
1848 Features[
"widekl"] = HasLeaf7 && HasLeaf19 && ((
EBX >> 2) & 1);
1851 MaxLevel >= 0x24 && !getX86CpuIDAndInfo(0x24, &EAX, &EBX, &ECX, &EDX);
1853 int AVX10Ver = HasLeaf24 && (
EBX & 0xff);
1854 int Has512Len = HasLeaf24 && ((
EBX >> 18) & 1);
1855 Features[
"avx10.1-256"] = HasAVX10 && AVX10Ver >= 1;
1856 Features[
"avx10.1-512"] = HasAVX10 && AVX10Ver >= 1 && Has512Len;
1857 Features[
"avx10.2-256"] = HasAVX10 && AVX10Ver >= 2;
1858 Features[
"avx10.2-512"] = HasAVX10 && AVX10Ver >= 2 && Has512Len;
1862#elif defined(__linux__) && (defined(__arm__) || defined(__aarch64__))
1870 P->getBuffer().split(Lines,
"\n");
1875 for (
unsigned I = 0, E =
Lines.size();
I != E; ++
I)
1877 Lines[
I].split(CPUFeatures,
' ');
1881#if defined(__aarch64__)
1883 enum { CAP_AES = 0x1, CAP_PMULL = 0x2, CAP_SHA1 = 0x4, CAP_SHA2 = 0x8 };
1887 for (
unsigned I = 0, E = CPUFeatures.
size();
I != E; ++
I) {
1889#if defined(__aarch64__)
1890 .
Case(
"asimd",
"neon")
1891 .
Case(
"fp",
"fp-armv8")
1892 .
Case(
"crc32",
"crc")
1893 .
Case(
"atomics",
"lse")
1895 .
Case(
"sve2",
"sve2")
1897 .
Case(
"half",
"fp16")
1898 .
Case(
"neon",
"neon")
1899 .
Case(
"vfpv3",
"vfp3")
1900 .
Case(
"vfpv3d16",
"vfp3d16")
1901 .
Case(
"vfpv4",
"vfp4")
1902 .
Case(
"idiva",
"hwdiv-arm")
1903 .
Case(
"idivt",
"hwdiv")
1907#if defined(__aarch64__)
1910 if (CPUFeatures[
I] ==
"aes")
1912 else if (CPUFeatures[
I] ==
"pmull")
1913 crypto |= CAP_PMULL;
1914 else if (CPUFeatures[
I] ==
"sha1")
1916 else if (CPUFeatures[
I] ==
"sha2")
1920 if (LLVMFeatureStr !=
"")
1921 Features[LLVMFeatureStr] =
true;
1924#if defined(__aarch64__)
1926 if (crypto == (CAP_AES | CAP_PMULL | CAP_SHA1 | CAP_SHA2))
1927 Features[
"crypto"] =
true;
1932#elif defined(_WIN32) && (defined(__aarch64__) || defined(_M_ARM64))
1936 if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE))
1937 Features[
"neon"] =
true;
1938 if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE))
1939 Features[
"crc"] =
true;
1940 if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE))
1941 Features[
"crypto"] =
true;
1945#elif defined(__linux__) && defined(__loongarch__)
1946#include <sys/auxv.h>
1948 unsigned long hwcap = getauxval(AT_HWCAP);
1949 bool HasFPU = hwcap & (1UL << 3);
1951 __asm__(
"cpucfg %[cpucfg2], %[cpucfg2]\n\t" : [cpucfg2]
"+r"(cpucfg2));
1955 Features[
"f"] = HasFPU && (cpucfg2 & (1U << 1));
1956 Features[
"d"] = HasFPU && (cpucfg2 & (1U << 2));
1958 Features[
"lsx"] = hwcap & (1UL << 4);
1959 Features[
"lasx"] = hwcap & (1UL << 5);
1960 Features[
"lvz"] = hwcap & (1UL << 9);
1964#elif defined(__linux__) && defined(__riscv)
1966struct RISCVHwProbe {
1971 RISCVHwProbe Query[]{{3, 0},
1973 int Ret = syscall(258, Query,
1974 std::size(Query), 0,
1980 uint64_t BaseMask = Query[0].Value;
1983 Features[
"i"] =
true;
1984 Features[
"m"] =
true;
1985 Features[
"a"] =
true;
1989 Features[
"f"] = ExtMask & (1 << 0);
1990 Features[
"d"] = ExtMask & (1 << 0);
1991 Features[
"c"] = ExtMask & (1 << 1);
1992 Features[
"v"] = ExtMask & (1 << 2);
1993 Features[
"zba"] = ExtMask & (1 << 3);
1994 Features[
"zbb"] = ExtMask & (1 << 4);
1995 Features[
"zbs"] = ExtMask & (1 << 5);
1996 Features[
"zicboz"] = ExtMask & (1 << 6);
1997 Features[
"zbc"] = ExtMask & (1 << 7);
1998 Features[
"zbkb"] = ExtMask & (1 << 8);
1999 Features[
"zbkc"] = ExtMask & (1 << 9);
2000 Features[
"zbkx"] = ExtMask & (1 << 10);
2001 Features[
"zknd"] = ExtMask & (1 << 11);
2002 Features[
"zkne"] = ExtMask & (1 << 12);
2003 Features[
"zknh"] = ExtMask & (1 << 13);
2004 Features[
"zksed"] = ExtMask & (1 << 14);
2005 Features[
"zksh"] = ExtMask & (1 << 15);
2006 Features[
"zkt"] = ExtMask & (1 << 16);
2007 Features[
"zvbb"] = ExtMask & (1 << 17);
2008 Features[
"zvbc"] = ExtMask & (1 << 18);
2009 Features[
"zvkb"] = ExtMask & (1 << 19);
2010 Features[
"zvkg"] = ExtMask & (1 << 20);
2011 Features[
"zvkned"] = ExtMask & (1 << 21);
2012 Features[
"zvknha"] = ExtMask & (1 << 22);
2013 Features[
"zvknhb"] = ExtMask & (1 << 23);
2014 Features[
"zvksed"] = ExtMask & (1 << 24);
2015 Features[
"zvksh"] = ExtMask & (1 << 25);
2016 Features[
"zvkt"] = ExtMask & (1 << 26);
2017 Features[
"zfh"] = ExtMask & (1 << 27);
2018 Features[
"zfhmin"] = ExtMask & (1 << 28);
2019 Features[
"zihintntl"] = ExtMask & (1 << 29);
2020 Features[
"zvfh"] = ExtMask & (1 << 30);
2021 Features[
"zvfhmin"] = ExtMask & (1ULL << 31);
2022 Features[
"zfa"] = ExtMask & (1ULL << 32);
2023 Features[
"ztso"] = ExtMask & (1ULL << 33);
2026 Features[
"zicond"] = ExtMask & (1ULL << 35);
2027 Features[
"zihintpause"] =
2028 ExtMask & (1ULL << 36);
2044 T.setArchName(
"arm");
2045#elif defined(__arm64e__)
2047 T.setArchName(
"arm64e");
2048#elif defined(__aarch64__)
2050 T.setArchName(
"arm64");
2051#elif defined(__x86_64h__)
2053 T.setArchName(
"x86_64h");
2054#elif defined(__x86_64__)
2056 T.setArchName(
"x86_64");
2057#elif defined(__i386__)
2059 T.setArchName(
"i386");
2060#elif defined(__powerpc__)
2062 T.setArchName(
"powerpc");
2064# error "Unimplemented host arch fixup"
2071 std::string TargetTripleString = updateTripleOSVersion(LLVM_HOST_TRIPLE);
2077 PT = withHostArch(PT);
2089#if LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO
2091 if (CPU ==
"generic")
2094 <<
" Host CPU: " << CPU <<
'\n';
This file defines the StringMap class.
#define LLVM_ATTRIBUTE_UNUSED
Given that RA is a live value
static std::unique_ptr< llvm::MemoryBuffer > LLVM_ATTRIBUTE_UNUSED getProcCpuinfoContent()
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Represents either an error or a value T.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileAsStream(const Twine &Filename)
Read all of the specified file into a MemoryBuffer as a stream (i.e.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr bool empty() const
empty - Check if the string is empty.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
static constexpr size_t npos
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & StartsWith(StringLiteral S, T Value)
Triple - Helper class for working with autoconf configuration names.
llvm::Triple get32BitArchVariant() const
Form a triple with a 32-bit variant of the current architecture.
std::string normalize() const
Return the normalized form of this triple's string.
llvm::Triple get64BitArchVariant() const
Form a triple with a 64-bit variant of the current architecture.
const std::string & str() const
bool isArch64Bit() const
Test whether the architecture is 64-bit.
bool isArch32Bit() const
Test whether the architecture is 32-bit.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ CPU_SUBTYPE_POWERPC_970
@ CPU_SUBTYPE_POWERPC_604e
@ CPU_SUBTYPE_POWERPC_603e
@ CPU_SUBTYPE_POWERPC_7400
@ CPU_SUBTYPE_POWERPC_604
@ CPU_SUBTYPE_POWERPC_750
@ CPU_SUBTYPE_POWERPC_601
@ CPU_SUBTYPE_POWERPC_620
@ CPU_SUBTYPE_POWERPC_603ev
@ CPU_SUBTYPE_POWERPC_603
@ CPU_SUBTYPE_POWERPC_7450
@ CPU_SUBTYPE_POWERPC_602
Helper functions to extract CPU details from CPUID on x86.
VendorSignatures getVendorSignature(unsigned *MaxLeaf=nullptr)
Returns the host CPU's vendor.
StringRef getHostCPUNameForS390x(StringRef ProcCpuinfoContent)
StringRef getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent)
Helper functions to extract HostCPUName from /proc/cpuinfo on linux.
StringRef getHostCPUNameForBPF()
StringRef getHostCPUNameForARM(StringRef ProcCpuinfoContent)
StringRef getHostCPUNameForRISCV(StringRef ProcCpuinfoContent)
StringRef getHostCPUNameForSPARC(StringRef ProcCpuinfoContent)
const StringMap< bool, MallocAllocator > getHostCPUFeatures()
getHostCPUFeatures - Get the LLVM names for the host CPU features.
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
void printDefaultTargetAndDetectedCPU(raw_ostream &OS)
This is a function compatible with cl::AddExtraVersionPrinter, which adds info about the current targ...
std::string getProcessTriple()
getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
This is an optimization pass for GlobalISel generic memory operations.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.