Skip to content

Commit

Permalink
Update uarch detection for Intel processors
Browse files Browse the repository at this point in the history
  • Loading branch information
toor1245 committed Oct 25, 2021
1 parent 769287c commit 5ac4bd0
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/cpuinfo_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ CacheInfo GetX86CacheInfo(void);

typedef enum {
X86_UNKNOWN,
INTEL_80486, // 80486
INTEL_P5, // P5
INTEL_LAKEMONT, // LAKEMONT
INTEL_CORE, // CORE
INTEL_PNR, // PENRYN
INTEL_NHM, // NEHALEM
Expand All @@ -137,6 +140,13 @@ typedef enum {
INTEL_ICL, // ICE LAKE
INTEL_TGL, // TIGER LAKE
INTEL_SPR, // SAPPHIRE RAPIDS
INTEL_ADL, // ALDER LAKE
INTEL_RCL, // ROCKET LAKE
INTEL_KNIGHTS_M, // KNIGHTS MILL
INTEL_KNIGHTS_L, // KNIGHTS LANDING
INTEL_KNIGHTS_F, // KNIGHTS FERRY
INTEL_KNIGHTS_C, // KNIGHTS CORNER
INTEL_NETBURST, // NETBURST
AMD_HAMMER, // K8 HAMMER
AMD_K10, // K10
AMD_K11, // K11
Expand Down
68 changes: 68 additions & 0 deletions src/cpuinfo_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "internal/bit_utils.h"
#include "internal/cpuid_x86.h"
#include "internal/string_view.h"

#if !defined(CPU_FEATURES_ARCH_X86)
#error "Cannot compile cpuinfo_x86 on a non x86 platform."
Expand Down Expand Up @@ -1477,6 +1478,27 @@ CacheInfo GetX86CacheInfo(void) {
X86Microarchitecture GetX86Microarchitecture(const X86Info* info) {
if (IsVendorByX86Info(info, CPU_FEATURES_VENDOR_GENUINE_INTEL)) {
switch (CPUID(info->family, info->model)) {
case CPUID(0x04, 0x01):
case CPUID(0x04, 0x02):
case CPUID(0x04, 0x03):
case CPUID(0x04, 0x04):
case CPUID(0x04, 0x05):
case CPUID(0x04, 0x07):
case CPUID(0x04, 0x08):
case CPUID(0x04, 0x09):
// https://en.wikichip.org/wiki/intel/microarchitectures/80486
return INTEL_80486;
case CPUID(0x05, 0x01):
case CPUID(0x05, 0x02):
case CPUID(0x05, 0x04):
case CPUID(0x05, 0x07):
case CPUID(0x05, 0x08):
// https://en.wikichip.org/wiki/intel/microarchitectures/p5
return INTEL_P5;
case CPUID(0x05, 0x09):
case CPUID(0x05, 0x0A):
// https://en.wikichip.org/wiki/intel/quark
return INTEL_LAKEMONT;
case CPUID(0x06, 0x1C): // Intel(R) Atom(TM) CPU 230 @ 1.60GHz
case CPUID(0x06, 0x35):
case CPUID(0x06, 0x36):
Expand Down Expand Up @@ -1570,6 +1592,32 @@ X86Microarchitecture GetX86Microarchitecture(const X86Info* info) {
// https://en.wikipedia.org/wiki/Kaby_Lake
return INTEL_KBL;
}
case CPUID(0x06, 0x97):
case CPUID(0x06, 0x9A):
// https://en.wikichip.org/wiki/intel/microarchitectures/alder_lake
return INTEL_ADL;
case CPUID(0x06, 0xA7):
// https://en.wikichip.org/wiki/intel/microarchitectures/rocket_lake
return INTEL_RCL;
case CPUID(0x06, 0x85):
// https://en.wikichip.org/wiki/intel/microarchitectures/knights_mill
return INTEL_KNIGHTS_M;
case CPUID(0x06, 0x57):
// https://en.wikichip.org/wiki/intel/microarchitectures/knights_landing
return INTEL_KNIGHTS_L;
case CPUID(0x0B, 0x00):
// https://en.wikichip.org/wiki/intel/microarchitectures/knights_ferry
return INTEL_KNIGHTS_F;
case CPUID(0x0B, 0x01):
// https://en.wikichip.org/wiki/intel/microarchitectures/knights_corner
return INTEL_KNIGHTS_C;
case CPUID(0x0F, 0x01):
case CPUID(0x0F, 0x02):
case CPUID(0x0F, 0x03):
case CPUID(0x0F, 0x04):
case CPUID(0x0F, 0x06):
// https://en.wikichip.org/wiki/intel/microarchitectures/netburst
return INTEL_NETBURST;
default:
return X86_UNKNOWN;
}
Expand Down Expand Up @@ -1724,6 +1772,12 @@ const char* GetX86MicroarchitectureName(X86Microarchitecture uarch) {
switch (uarch) {
case X86_UNKNOWN:
return "X86_UNKNOWN";
case INTEL_80486:
return "INTEL_80486";
case INTEL_P5:
return "INTEL_P5";
case INTEL_LAKEMONT:
return "INTEL_LAKEMONT";
case INTEL_CORE:
return "INTEL_CORE";
case INTEL_PNR:
Expand Down Expand Up @@ -1762,6 +1816,20 @@ const char* GetX86MicroarchitectureName(X86Microarchitecture uarch) {
return "INTEL_TGL";
case INTEL_SPR:
return "INTEL_SPR";
case INTEL_ADL:
return "INTEL_ADL";
case INTEL_RCL:
return "INTEL_RCL";
case INTEL_KNIGHTS_M:
return "INTEL_KNIGHTS_M";
case INTEL_KNIGHTS_L:
return "INTEL_KNIGHTS_L";
case INTEL_KNIGHTS_F:
return "INTEL_KNIGHTS_F";
case INTEL_KNIGHTS_C:
return "INTEL_KNIGHTS_C";
case INTEL_NETBURST:
return "INTEL_NETBURST";
case AMD_HAMMER:
return "AMD_HAMMER";
case AMD_K10:
Expand Down
58 changes: 58 additions & 0 deletions test/cpuinfo_x86_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,64 @@ flags : fpu mmx sse
#endif // !defined(CPU_FEATURES_OS_WINDOWS)
}

// https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0000480_486_CPUID.txt
TEST_F(CpuidX86Test, INTEL_80486) {
cpu().SetLeaves({
{{0x00000000, 0}, Leaf{0x00000001, 0x756E6547, 0x6C65746E, 0x49656E69}},
{{0x00000001, 0}, Leaf{0x00000480, 0x00000000, 0x00000000, 0x00000003}},
});
const auto info = GetX86Info();

EXPECT_STREQ(info.vendor, "GenuineIntel");
EXPECT_EQ(info.family, 0x04);
EXPECT_EQ(info.model, 0x08);
EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::INTEL_80486);
}

// https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0000526_P54C_CPUID.txt
TEST_F(CpuidX86Test, INTEL_P54C) {
cpu().SetLeaves({
{{0x00000000, 0}, Leaf{0x00000001, 0x756E6547, 0x6C65746E, 0x49656E69}},
{{0x00000001, 0}, Leaf{0x00000525, 0x00000000, 0x00000000, 0x000001BF}},
});
const auto info = GetX86Info();

EXPECT_STREQ(info.vendor, "GenuineIntel");
EXPECT_EQ(info.family, 0x05);
EXPECT_EQ(info.model, 0x02);
EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::INTEL_P5);
}

// https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0000590_Lakemont_CPUID2.txt
TEST_F(CpuidX86Test, INTEL_LAKEMONT) {
cpu().SetLeaves({
{{0x00000000, 0}, Leaf{0x00000002, 0x756E6547, 0x6c65746E, 0x49656E69}},
{{0x00000001, 0}, Leaf{0x00000590, 0x00000000, 0x00010200, 0x8000237B}},
});
const auto info = GetX86Info();

EXPECT_STREQ(info.vendor, "GenuineIntel");
EXPECT_EQ(info.family, 0x05);
EXPECT_EQ(info.model, 0x09);
EXPECT_EQ(GetX86Microarchitecture(&info),
X86Microarchitecture::INTEL_LAKEMONT);
}

// https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0050670_KnightsLanding_CPUID.txt
TEST_F(CpuidX86Test, INTEL_KNIGHTS_LANDING) {
cpu().SetLeaves({
{{0x00000000, 0}, Leaf{0x0000000D, 0x756E6547, 0x6C65746E, 0x49656E69}},
{{0x00000001, 0}, Leaf{0x00050670, 0x02FF0800, 0x7FF8F3BF, 0xBFEBFBFF}},
});
const auto info = GetX86Info();

EXPECT_STREQ(info.vendor, "GenuineIntel");
EXPECT_EQ(info.family, 0x06);
EXPECT_EQ(info.model, 0x57);
EXPECT_EQ(GetX86Microarchitecture(&info),
X86Microarchitecture::INTEL_KNIGHTS_L);
}

// TODO(user): test what happens when xsave/osxsave are not present.
// TODO(user): test what happens when xmm/ymm/zmm os support are not
// present.
Expand Down

0 comments on commit 5ac4bd0

Please sign in to comment.