1 // Copyright 2017 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "cpuinfo_x86.h"
16
17 #include <cassert>
18 #include <cstdio>
19 #include <map>
20 #include <set>
21 #if defined(CPU_FEATURES_OS_WINDOWS)
22 #include <windows.h> // IsProcessorFeaturePresent
23 #endif // CPU_FEATURES_OS_WINDOWS
24
25 #include "filesystem_for_testing.h"
26 #include "gtest/gtest.h"
27 #include "internal/cpuid_x86.h"
28
29 namespace cpu_features {
30
31 class FakeCpu {
32 public:
GetCpuidLeaf(uint32_t leaf_id,int ecx) const33 Leaf GetCpuidLeaf(uint32_t leaf_id, int ecx) const {
34 const auto itr = cpuid_leaves_.find(std::make_pair(leaf_id, ecx));
35 if (itr != cpuid_leaves_.end()) {
36 return itr->second;
37 }
38 return {0, 0, 0, 0};
39 }
40
GetXCR0Eax() const41 uint32_t GetXCR0Eax() const { return xcr0_eax_; }
42
SetLeaves(std::map<std::pair<uint32_t,int>,Leaf> configuration)43 void SetLeaves(std::map<std::pair<uint32_t, int>, Leaf> configuration) {
44 cpuid_leaves_ = std::move(configuration);
45 }
46
SetOsBackupsExtendedRegisters(bool os_backups_extended_registers)47 void SetOsBackupsExtendedRegisters(bool os_backups_extended_registers) {
48 xcr0_eax_ = os_backups_extended_registers ? -1 : 0;
49 }
50
51 #if defined(CPU_FEATURES_OS_MACOS)
GetDarwinSysCtlByName(std::string name) const52 bool GetDarwinSysCtlByName(std::string name) const {
53 return darwin_sysctlbyname_.count(name);
54 }
55
SetDarwinSysCtlByName(std::string name)56 void SetDarwinSysCtlByName(std::string name) {
57 darwin_sysctlbyname_.insert(name);
58 }
59 #endif // CPU_FEATURES_OS_MACOS
60
61 #if defined(CPU_FEATURES_OS_WINDOWS)
GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature)62 bool GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature) {
63 return windows_isprocessorfeaturepresent_.count(ProcessorFeature);
64 }
65
SetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature)66 void SetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature) {
67 windows_isprocessorfeaturepresent_.insert(ProcessorFeature);
68 }
69 #endif // CPU_FEATURES_OS_WINDOWS
70
71 private:
72 std::map<std::pair<uint32_t, int>, Leaf> cpuid_leaves_;
73 #if defined(CPU_FEATURES_OS_MACOS)
74 std::set<std::string> darwin_sysctlbyname_;
75 #endif // CPU_FEATURES_OS_MACOS
76 #if defined(CPU_FEATURES_OS_WINDOWS)
77 std::set<DWORD> windows_isprocessorfeaturepresent_;
78 #endif // CPU_FEATURES_OS_WINDOWS
79 uint32_t xcr0_eax_;
80 };
81
82 static FakeCpu* g_fake_cpu_instance = nullptr;
83
cpu()84 static FakeCpu& cpu() {
85 assert(g_fake_cpu_instance != nullptr);
86 return *g_fake_cpu_instance;
87 }
88
GetCpuidLeaf(uint32_t leaf_id,int ecx)89 extern "C" Leaf GetCpuidLeaf(uint32_t leaf_id, int ecx) {
90 return cpu().GetCpuidLeaf(leaf_id, ecx);
91 }
92
GetXCR0Eax(void)93 extern "C" uint32_t GetXCR0Eax(void) { return cpu().GetXCR0Eax(); }
94
95 #if defined(CPU_FEATURES_OS_MACOS)
GetDarwinSysCtlByName(const char * name)96 extern "C" bool GetDarwinSysCtlByName(const char* name) {
97 return cpu().GetDarwinSysCtlByName(name);
98 }
99 #endif // CPU_FEATURES_OS_MACOS
100
101 #if defined(CPU_FEATURES_OS_WINDOWS)
GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature)102 extern "C" bool GetWindowsIsProcessorFeaturePresent(DWORD ProcessorFeature) {
103 return cpu().GetWindowsIsProcessorFeaturePresent(ProcessorFeature);
104 }
105 #endif // CPU_FEATURES_OS_WINDOWS
106
107 namespace {
108
109 class CpuidX86Test : public ::testing::Test {
110 protected:
SetUp()111 void SetUp() override {
112 assert(g_fake_cpu_instance == nullptr);
113 g_fake_cpu_instance = new FakeCpu();
114 }
TearDown()115 void TearDown() override {
116 delete g_fake_cpu_instance;
117 g_fake_cpu_instance = nullptr;
118 }
119 };
120
TEST_F(CpuidX86Test,SandyBridge)121 TEST_F(CpuidX86Test, SandyBridge) {
122 cpu().SetOsBackupsExtendedRegisters(true);
123 cpu().SetLeaves({
124 {{0x00000000, 0}, Leaf{0x0000000D, 0x756E6547, 0x6C65746E, 0x49656E69}},
125 {{0x00000001, 0}, Leaf{0x000206A6, 0x00100800, 0x1F9AE3BF, 0xBFEBFBFF}},
126 {{0x00000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
127 });
128 const auto info = GetX86Info();
129 EXPECT_STREQ(info.vendor, "GenuineIntel");
130 EXPECT_EQ(info.family, 0x06);
131 EXPECT_EQ(info.model, 0x02A);
132 EXPECT_EQ(info.stepping, 0x06);
133 // Leaf 7 is zeroed out so none of the Leaf 7 flags are set.
134 const auto features = info.features;
135 EXPECT_FALSE(features.erms);
136 EXPECT_FALSE(features.avx2);
137 EXPECT_FALSE(features.avx512f);
138 EXPECT_FALSE(features.avx512cd);
139 EXPECT_FALSE(features.avx512er);
140 EXPECT_FALSE(features.avx512pf);
141 EXPECT_FALSE(features.avx512bw);
142 EXPECT_FALSE(features.avx512dq);
143 EXPECT_FALSE(features.avx512vl);
144 EXPECT_FALSE(features.avx512ifma);
145 EXPECT_FALSE(features.avx512vbmi);
146 EXPECT_FALSE(features.avx512vbmi2);
147 EXPECT_FALSE(features.avx512vnni);
148 EXPECT_FALSE(features.avx512bitalg);
149 EXPECT_FALSE(features.avx512vpopcntdq);
150 EXPECT_FALSE(features.avx512_4vnniw);
151 EXPECT_FALSE(features.avx512_4fmaps);
152 // All old cpu features should be set.
153 EXPECT_TRUE(features.aes);
154 EXPECT_TRUE(features.ssse3);
155 EXPECT_TRUE(features.sse4_1);
156 EXPECT_TRUE(features.sse4_2);
157 EXPECT_TRUE(features.avx);
158 EXPECT_FALSE(features.sha);
159 EXPECT_TRUE(features.popcnt);
160 EXPECT_FALSE(features.movbe);
161 EXPECT_FALSE(features.rdrnd);
162 EXPECT_FALSE(features.adx);
163 }
164
165 const int UNDEF = -1;
166 const int KiB = 1024;
167 const int MiB = 1024 * KiB;
168
TEST_F(CpuidX86Test,SandyBridgeTestOsSupport)169 TEST_F(CpuidX86Test, SandyBridgeTestOsSupport) {
170 cpu().SetLeaves({
171 {{0x00000000, 0}, Leaf{0x0000000D, 0x756E6547, 0x6C65746E, 0x49656E69}},
172 {{0x00000001, 0}, Leaf{0x000206A6, 0x00100800, 0x1F9AE3BF, 0xBFEBFBFF}},
173 {{0x00000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
174 });
175 // avx is disabled if os does not support backing up ymm registers.
176 cpu().SetOsBackupsExtendedRegisters(false);
177 EXPECT_FALSE(GetX86Info().features.avx);
178 // avx is disabled if os does not support backing up ymm registers.
179 cpu().SetOsBackupsExtendedRegisters(true);
180 EXPECT_TRUE(GetX86Info().features.avx);
181 }
182
TEST_F(CpuidX86Test,SkyLake)183 TEST_F(CpuidX86Test, SkyLake) {
184 cpu().SetOsBackupsExtendedRegisters(true);
185 cpu().SetLeaves({
186 {{0x00000000, 0}, Leaf{0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69}},
187 {{0x00000001, 0}, Leaf{0x000406E3, 0x00100800, 0x7FFAFBBF, 0xBFEBFBFF}},
188 {{0x00000007, 0}, Leaf{0x00000000, 0x029C67AF, 0x00000000, 0x00000000}},
189 });
190 const auto info = GetX86Info();
191 EXPECT_STREQ(info.vendor, "GenuineIntel");
192 EXPECT_EQ(info.family, 0x06);
193 EXPECT_EQ(info.model, 0x04E);
194 EXPECT_EQ(info.stepping, 0x03);
195 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::INTEL_SKL);
196 }
197
TEST_F(CpuidX86Test,Branding)198 TEST_F(CpuidX86Test, Branding) {
199 cpu().SetLeaves({
200 {{0x00000000, 0}, Leaf{0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69}},
201 {{0x00000001, 0}, Leaf{0x000406E3, 0x00100800, 0x7FFAFBBF, 0xBFEBFBFF}},
202 {{0x00000007, 0}, Leaf{0x00000000, 0x029C67AF, 0x00000000, 0x00000000}},
203 {{0x80000000, 0}, Leaf{0x80000008, 0x00000000, 0x00000000, 0x00000000}},
204 {{0x80000001, 0}, Leaf{0x00000000, 0x00000000, 0x00000121, 0x2C100000}},
205 {{0x80000002, 0}, Leaf{0x65746E49, 0x2952286C, 0x726F4320, 0x4D542865}},
206 {{0x80000003, 0}, Leaf{0x37692029, 0x3035362D, 0x43205530, 0x40205550}},
207 {{0x80000004, 0}, Leaf{0x352E3220, 0x7A484730, 0x00000000, 0x00000000}},
208 });
209 char brand_string[49];
210 FillX86BrandString(brand_string);
211 EXPECT_STREQ(brand_string, "Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz");
212 }
213
TEST_F(CpuidX86Test,KabyLakeCache)214 TEST_F(CpuidX86Test, KabyLakeCache) {
215 cpu().SetLeaves({
216 {{0x00000000, 0}, Leaf{0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69}},
217 {{0x00000001, 0}, Leaf{0x000406E3, 0x00100800, 0x7FFAFBBF, 0xBFEBFBFF}},
218 {{0x00000004, 0}, Leaf{0x1C004121, 0x01C0003F, 0x0000003F, 0x00000000}},
219 {{0x00000004, 1}, Leaf{0x1C004122, 0x01C0003F, 0x0000003F, 0x00000000}},
220 {{0x00000004, 2}, Leaf{0x1C004143, 0x00C0003F, 0x000003FF, 0x00000000}},
221 {{0x00000004, 3}, Leaf{0x1C03C163, 0x02C0003F, 0x00001FFF, 0x00000002}},
222 {{0x00000007, 0}, Leaf{0x00000000, 0x029C67AF, 0x00000000, 0x00000000}},
223 {{0x80000000, 0}, Leaf{0x80000008, 0x00000000, 0x00000000, 0x00000000}},
224 {{0x80000001, 0}, Leaf{0x00000000, 0x00000000, 0x00000121, 0x2C100000}},
225 {{0x80000002, 0}, Leaf{0x65746E49, 0x2952286C, 0x726F4320, 0x4D542865}},
226 {{0x80000003, 0}, Leaf{0x37692029, 0x3035362D, 0x43205530, 0x40205550}},
227 });
228 const auto info = GetX86CacheInfo();
229 EXPECT_EQ(info.size, 4);
230 EXPECT_EQ(info.levels[0].level, 1);
231 EXPECT_EQ(info.levels[0].cache_type, 1);
232 EXPECT_EQ(info.levels[0].cache_size, 32 * KiB);
233 EXPECT_EQ(info.levels[0].ways, 8);
234 EXPECT_EQ(info.levels[0].line_size, 64);
235 EXPECT_EQ(info.levels[0].tlb_entries, 64);
236 EXPECT_EQ(info.levels[0].partitioning, 1);
237
238 EXPECT_EQ(info.levels[1].level, 1);
239 EXPECT_EQ(info.levels[1].cache_type, 2);
240 EXPECT_EQ(info.levels[1].cache_size, 32 * KiB);
241 EXPECT_EQ(info.levels[1].ways, 8);
242 EXPECT_EQ(info.levels[1].line_size, 64);
243 EXPECT_EQ(info.levels[1].tlb_entries, 64);
244 EXPECT_EQ(info.levels[1].partitioning, 1);
245
246 EXPECT_EQ(info.levels[2].level, 2);
247 EXPECT_EQ(info.levels[2].cache_type, 3);
248 EXPECT_EQ(info.levels[2].cache_size, 256 * KiB);
249 EXPECT_EQ(info.levels[2].ways, 4);
250 EXPECT_EQ(info.levels[2].line_size, 64);
251 EXPECT_EQ(info.levels[2].tlb_entries, 1024);
252 EXPECT_EQ(info.levels[2].partitioning, 1);
253
254 EXPECT_EQ(info.levels[3].level, 3);
255 EXPECT_EQ(info.levels[3].cache_type, 3);
256 EXPECT_EQ(info.levels[3].cache_size, 6 * MiB);
257 EXPECT_EQ(info.levels[3].ways, 12);
258 EXPECT_EQ(info.levels[3].line_size, 64);
259 EXPECT_EQ(info.levels[3].tlb_entries, 8192);
260 EXPECT_EQ(info.levels[3].partitioning, 1);
261 }
262
TEST_F(CpuidX86Test,HSWCache)263 TEST_F(CpuidX86Test, HSWCache) {
264 cpu().SetLeaves({
265 {{0x00000000, 0}, Leaf{0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69}},
266 {{0x00000001, 0}, Leaf{0x000406E3, 0x00100800, 0x7FFAFBBF, 0xBFEBFBFF}},
267 {{0x00000004, 0}, Leaf{0x1C004121, 0x01C0003F, 0x0000003F, 0x00000000}},
268 {{0x00000004, 1}, Leaf{0x1C004122, 0x01C0003F, 0x0000003F, 0x00000000}},
269 {{0x00000004, 2}, Leaf{0x1C004143, 0x01C0003F, 0x000001FF, 0x00000000}},
270 {{0x00000004, 3}, Leaf{0x1C03C163, 0x02C0003F, 0x00001FFF, 0x00000006}},
271 {{0x00000007, 0}, Leaf{0x00000000, 0x029C67AF, 0x00000000, 0x00000000}},
272 {{0x80000000, 0}, Leaf{0x80000008, 0x00000000, 0x00000000, 0x00000000}},
273 {{0x80000001, 0}, Leaf{0x00000000, 0x00000000, 0x00000121, 0x2C100000}},
274 {{0x80000002, 0}, Leaf{0x65746E49, 0x2952286C, 0x726F4320, 0x4D542865}},
275 {{0x80000003, 0}, Leaf{0x37692029, 0x3035362D, 0x43205530, 0x40205550}},
276 });
277 const auto info = GetX86CacheInfo();
278 EXPECT_EQ(info.size, 4);
279 EXPECT_EQ(info.levels[0].level, 1);
280 EXPECT_EQ(info.levels[0].cache_type, 1);
281 EXPECT_EQ(info.levels[0].cache_size, 32 * KiB);
282 EXPECT_EQ(info.levels[0].ways, 8);
283 EXPECT_EQ(info.levels[0].line_size, 64);
284 EXPECT_EQ(info.levels[0].tlb_entries, 64);
285 EXPECT_EQ(info.levels[0].partitioning, 1);
286
287 EXPECT_EQ(info.levels[1].level, 1);
288 EXPECT_EQ(info.levels[1].cache_type, 2);
289 EXPECT_EQ(info.levels[1].cache_size, 32 * KiB);
290 EXPECT_EQ(info.levels[1].ways, 8);
291 EXPECT_EQ(info.levels[1].line_size, 64);
292 EXPECT_EQ(info.levels[1].tlb_entries, 64);
293 EXPECT_EQ(info.levels[1].partitioning, 1);
294
295 EXPECT_EQ(info.levels[2].level, 2);
296 EXPECT_EQ(info.levels[2].cache_type, 3);
297 EXPECT_EQ(info.levels[2].cache_size, 256 * KiB);
298 EXPECT_EQ(info.levels[2].ways, 8);
299 EXPECT_EQ(info.levels[2].line_size, 64);
300 EXPECT_EQ(info.levels[2].tlb_entries, 512);
301 EXPECT_EQ(info.levels[2].partitioning, 1);
302
303 EXPECT_EQ(info.levels[3].level, 3);
304 EXPECT_EQ(info.levels[3].cache_type, 3);
305 EXPECT_EQ(info.levels[3].cache_size, 6 * MiB);
306 EXPECT_EQ(info.levels[3].ways, 12);
307 EXPECT_EQ(info.levels[3].line_size, 64);
308 EXPECT_EQ(info.levels[3].tlb_entries, 8192);
309 EXPECT_EQ(info.levels[3].partitioning, 1);
310 }
311
312 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0200F30_K11_Griffin_CPUID.txt
TEST_F(CpuidX86Test,AMD_K11_GRIFFIN)313 TEST_F(CpuidX86Test, AMD_K11_GRIFFIN) {
314 cpu().SetLeaves({
315 {{0x00000000, 0}, Leaf{0x00000001, 0x68747541, 0x444D4163, 0x69746E65}},
316 {{0x00000001, 0}, Leaf{0x00200F30, 0x00020800, 0x00002001, 0x178BFBFF}},
317 {{0x80000000, 0}, Leaf{0x8000001A, 0x68747541, 0x444D4163, 0x69746E65}},
318 {{0x80000001, 0}, Leaf{0x00200F30, 0x20000000, 0x0000131F, 0xEBD3FBFF}},
319 });
320 const auto info = GetX86Info();
321
322 EXPECT_STREQ(info.vendor, "AuthenticAMD");
323 EXPECT_EQ(info.family, 0x11);
324 EXPECT_EQ(info.model, 0x03);
325 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_K11);
326 }
327
328 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0300F10_K12_Llano_CPUID.txt
TEST_F(CpuidX86Test,AMD_K12_LLANO)329 TEST_F(CpuidX86Test, AMD_K12_LLANO) {
330 cpu().SetLeaves({
331 {{0x00000000, 0}, Leaf{0x00000006, 0x68747541, 0x444D4163, 0x69746E65}},
332 {{0x00000001, 0}, Leaf{0x00300F10, 0x00040800, 0x00802009, 0x178BFBFF}},
333 {{0x80000000, 0}, Leaf{0x8000001B, 0x68747541, 0x444D4163, 0x69746E65}},
334 {{0x80000001, 0}, Leaf{0x00300F10, 0x20002B31, 0x000037FF, 0xEFD3FBFF}},
335 });
336 const auto info = GetX86Info();
337
338 EXPECT_STREQ(info.vendor, "AuthenticAMD");
339 EXPECT_EQ(info.family, 0x12);
340 EXPECT_EQ(info.model, 0x01);
341 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_K12);
342 }
343
344 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0500F01_K14_Bobcat_CPUID.txt
TEST_F(CpuidX86Test,AMD_K14_BOBCAT_AMD0500F01)345 TEST_F(CpuidX86Test, AMD_K14_BOBCAT_AMD0500F01) {
346 cpu().SetLeaves({
347 {{0x00000000, 0}, Leaf{0x00000006, 0x68747541, 0x444D4163, 0x69746E65}},
348 {{0x00000001, 0}, Leaf{0x00500F01, 0x00020800, 0x00802209, 0x178BFBFF}},
349 {{0x80000000, 0}, Leaf{0x8000001B, 0x68747541, 0x444D4163, 0x69746E65}},
350 {{0x80000001, 0}, Leaf{0x00500F01, 0x00000000, 0x000035FF, 0x2FD3FBFF}},
351 });
352 const auto info = GetX86Info();
353
354 EXPECT_STREQ(info.vendor, "AuthenticAMD");
355 EXPECT_EQ(info.family, 0x14);
356 EXPECT_EQ(info.model, 0x00);
357 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_BOBCAT);
358 }
359
360 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0500F10_K14_Bobcat_CPUID.txt
TEST_F(CpuidX86Test,AMD_K14_BOBCAT_AMD0500F10)361 TEST_F(CpuidX86Test, AMD_K14_BOBCAT_AMD0500F10) {
362 cpu().SetLeaves({
363 {{0x00000000, 0}, Leaf{0x00000006, 0x68747541, 0x444D4163, 0x69746E65}},
364 {{0x00000001, 0}, Leaf{0x00500F10, 0x00020800, 0x00802209, 0x178BFBFF}},
365 {{0x00000002, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
366 {{0x00000003, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
367 {{0x00000005, 0}, Leaf{0x00000040, 0x00000040, 0x00000003, 0x00000000}},
368 {{0x00000006, 0}, Leaf{0x00000000, 0x00000000, 0x00000001, 0x00000000}},
369 {{0x80000000, 0}, Leaf{0x8000001B, 0x68747541, 0x444D4163, 0x69746E65}},
370 {{0x80000001, 0}, Leaf{0x00500F10, 0x00001242, 0x000035FF, 0x2FD3FBFF}},
371 {{0x80000002, 0}, Leaf{0x20444D41, 0x35332D45, 0x72502030, 0x7365636F}},
372 {{0x80000003, 0}, Leaf{0x00726F73, 0x00000000, 0x00000000, 0x00000000}},
373 {{0x80000004, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
374 {{0x80000005, 0}, Leaf{0xFF08FF08, 0xFF280000, 0x20080140, 0x20020140}},
375 });
376 const auto info = GetX86Info();
377
378 EXPECT_STREQ(info.vendor, "AuthenticAMD");
379 EXPECT_EQ(info.family, 0x14);
380 EXPECT_EQ(info.model, 0x01);
381 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_BOBCAT);
382 }
383
384 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0500F20_K14_Bobcat_CPUID.txt
TEST_F(CpuidX86Test,AMD_K14_BOBCAT_AMD0500F20)385 TEST_F(CpuidX86Test, AMD_K14_BOBCAT_AMD0500F20) {
386 cpu().SetLeaves({
387 {{0x00000000, 0}, Leaf{0x00000006, 0x68747541, 0x444D4163, 0x69746E65}},
388 {{0x00000001, 0}, Leaf{0x00500F20, 0x00020800, 0x00802209, 0x178BFBFF}},
389 {{0x80000000, 0}, Leaf{0x8000001B, 0x68747541, 0x444D4163, 0x69746E65}},
390 {{0x80000001, 0}, Leaf{0x00500F20, 0x000012E9, 0x000035FF, 0x2FD3FBFF}},
391 });
392 const auto info = GetX86Info();
393
394 EXPECT_STREQ(info.vendor, "AuthenticAMD");
395 EXPECT_EQ(info.family, 0x14);
396 EXPECT_EQ(info.model, 0x02);
397 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_BOBCAT);
398 }
399
400 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0670F00_K15_StoneyRidge_CPUID.txt
TEST_F(CpuidX86Test,AMD_K15_EXCAVATOR_STONEY_RIDGE)401 TEST_F(CpuidX86Test, AMD_K15_EXCAVATOR_STONEY_RIDGE) {
402 cpu().SetLeaves({
403 {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}},
404 {{0x00000001, 0}, Leaf{0x00670F00, 0x00020800, 0x7ED8320B, 0x178BFBFF}},
405 {{0x00000007, 0}, Leaf{0x00000000, 0x000001A9, 0x00000000, 0x00000000}},
406 {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}},
407 {{0x80000001, 0}, Leaf{0x00670F00, 0x00000000, 0x2FABBFFF, 0x2FD3FBFF}},
408 {{0x80000002, 0}, Leaf{0x20444D41, 0x392D3941, 0x20303134, 0x45444152}},
409 {{0x80000003, 0}, Leaf{0x52204E4F, 0x35202C35, 0x4D4F4320, 0x45545550}},
410 {{0x80000004, 0}, Leaf{0x524F4320, 0x32205345, 0x47332B43, 0x00202020}},
411 });
412 const auto info = GetX86Info();
413
414 EXPECT_STREQ(info.vendor, "AuthenticAMD");
415 EXPECT_EQ(info.family, 0x15);
416 EXPECT_EQ(info.model, 0x70);
417 EXPECT_STREQ(info.brand_string,
418 "AMD A9-9410 RADEON R5, 5 COMPUTE CORES 2C+3G ");
419 EXPECT_EQ(GetX86Microarchitecture(&info),
420 X86Microarchitecture::AMD_EXCAVATOR);
421
422 char brand_string[49];
423 FillX86BrandString(brand_string);
424 EXPECT_STREQ(brand_string, "AMD A9-9410 RADEON R5, 5 COMPUTE CORES 2C+3G ");
425 }
426
427 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0600F20_K15_AbuDhabi_CPUID0.txt
TEST_F(CpuidX86Test,AMD_K15_PILEDRIVER_ABU_DHABI)428 TEST_F(CpuidX86Test, AMD_K15_PILEDRIVER_ABU_DHABI) {
429 cpu().SetLeaves({
430 {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}},
431 {{0x00000001, 0}, Leaf{0x00600F20, 0x00100800, 0x3E98320B, 0x178BFBFF}},
432 {{0x00000007, 0}, Leaf{0x00000000, 0x00000008, 0x00000000, 0x00000000}},
433 {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}},
434 {{0x80000001, 0}, Leaf{0x00600F20, 0x30000000, 0x01EBBFFF, 0x2FD3FBFF}},
435 {{0x80000002, 0}, Leaf{0x20444D41, 0x6574704F, 0x286E6F72, 0x20296D74}},
436 {{0x80000003, 0}, Leaf{0x636F7250, 0x6F737365, 0x33362072, 0x20203637}},
437 {{0x80000004, 0}, Leaf{0x20202020, 0x20202020, 0x20202020, 0x00202020}},
438 });
439 const auto info = GetX86Info();
440
441 EXPECT_STREQ(info.vendor, "AuthenticAMD");
442 EXPECT_EQ(info.family, 0x15);
443 EXPECT_EQ(info.model, 0x02);
444 EXPECT_STREQ(info.brand_string,
445 "AMD Opteron(tm) Processor 6376 ");
446 EXPECT_EQ(GetX86Microarchitecture(&info),
447 X86Microarchitecture::AMD_PILEDRIVER);
448
449 char brand_string[49];
450 FillX86BrandString(brand_string);
451 EXPECT_STREQ(brand_string, "AMD Opteron(tm) Processor 6376 ");
452 }
453
454 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0600F20_K15_AbuDhabi_CPUID0.txt
TEST_F(CpuidX86Test,AMD_K15_PILEDRIVER_ABU_DHABI_CACHE_INFO)455 TEST_F(CpuidX86Test, AMD_K15_PILEDRIVER_ABU_DHABI_CACHE_INFO) {
456 cpu().SetLeaves({
457 {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}},
458 {{0x00000001, 0}, Leaf{0x00600F20, 0x00100800, 0x3E98320B, 0x178BFBFF}},
459 {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}},
460 {{0x80000001, 0}, Leaf{0x00600F20, 0x30000000, 0x01EBBFFF, 0x2FD3FBFF}},
461 {{0x8000001D, 0}, Leaf{0x00000121, 0x00C0003F, 0x0000003F, 0x00000000}},
462 {{0x8000001D, 1}, Leaf{0x00004122, 0x0040003F, 0x000001FF, 0x00000000}},
463 {{0x8000001D, 2}, Leaf{0x00004143, 0x03C0003F, 0x000007FF, 0x00000001}},
464 {{0x8000001D, 3}, Leaf{0x0001C163, 0x0BC0003F, 0x000007FF, 0x00000001}},
465 });
466 const auto info = GetX86CacheInfo();
467
468 EXPECT_EQ(info.size, 4);
469 EXPECT_EQ(info.levels[0].level, 1);
470 EXPECT_EQ(info.levels[0].cache_type, 1);
471 EXPECT_EQ(info.levels[0].cache_size, 16 * KiB);
472 EXPECT_EQ(info.levels[0].ways, 4);
473 EXPECT_EQ(info.levels[0].line_size, 64);
474 EXPECT_EQ(info.levels[0].tlb_entries, 64);
475 EXPECT_EQ(info.levels[0].partitioning, 1);
476
477 EXPECT_EQ(info.levels[1].level, 1);
478 EXPECT_EQ(info.levels[1].cache_type, 2);
479 EXPECT_EQ(info.levels[1].cache_size, 64 * KiB);
480 EXPECT_EQ(info.levels[1].ways, 2);
481 EXPECT_EQ(info.levels[1].line_size, 64);
482 EXPECT_EQ(info.levels[1].tlb_entries, 512);
483 EXPECT_EQ(info.levels[1].partitioning, 1);
484
485 EXPECT_EQ(info.levels[2].level, 2);
486 EXPECT_EQ(info.levels[2].cache_type, 3);
487 EXPECT_EQ(info.levels[2].cache_size, 2 * MiB);
488 EXPECT_EQ(info.levels[2].ways, 16);
489 EXPECT_EQ(info.levels[2].line_size, 64);
490 EXPECT_EQ(info.levels[2].tlb_entries, 2048);
491 EXPECT_EQ(info.levels[2].partitioning, 1);
492
493 EXPECT_EQ(info.levels[3].level, 3);
494 EXPECT_EQ(info.levels[3].cache_type, 3);
495 EXPECT_EQ(info.levels[3].cache_size, 6 * MiB);
496 EXPECT_EQ(info.levels[3].ways, 48);
497 EXPECT_EQ(info.levels[3].line_size, 64);
498 EXPECT_EQ(info.levels[3].tlb_entries, 2048);
499 EXPECT_EQ(info.levels[3].partitioning, 1);
500 }
501
502 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0600F12_K15_Interlagos_CPUID3.txt
TEST_F(CpuidX86Test,AMD_K15_BULLDOZER_INTERLAGOS)503 TEST_F(CpuidX86Test, AMD_K15_BULLDOZER_INTERLAGOS) {
504 cpu().SetLeaves({
505 {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}},
506 {{0x00000001, 0}, Leaf{0x00600F12, 0x000C0800, 0x1E98220B, 0x178BFBFF}},
507 {{0x00000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
508 {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}},
509 {{0x80000001, 0}, Leaf{0x00600F12, 0x30000000, 0x01C9BFFF, 0x2FD3FBFF}},
510 {{0x80000002, 0}, Leaf{0x20444D41, 0x6574704F, 0x286E6F72, 0x20294D54}},
511 {{0x80000003, 0}, Leaf{0x636F7250, 0x6F737365, 0x32362072, 0x20203833}},
512 {{0x80000004, 0}, Leaf{0x20202020, 0x20202020, 0x20202020, 0x00202020}},
513 });
514 const auto info = GetX86Info();
515
516 EXPECT_STREQ(info.vendor, "AuthenticAMD");
517 EXPECT_EQ(info.family, 0x15);
518 EXPECT_EQ(info.model, 0x01);
519 EXPECT_STREQ(info.brand_string,
520 "AMD Opteron(TM) Processor 6238 ");
521 EXPECT_EQ(GetX86Microarchitecture(&info),
522 X86Microarchitecture::AMD_BULLDOZER);
523
524 char brand_string[49];
525 FillX86BrandString(brand_string);
526 EXPECT_STREQ(brand_string, "AMD Opteron(TM) Processor 6238 ");
527 }
528
529 // http://users.atw.hu/instlatx64/AuthenticAMD0630F81_K15_Godavari_CPUID.txt
TEST_F(CpuidX86Test,AMD_K15_STREAMROLLER_GODAVARI)530 TEST_F(CpuidX86Test, AMD_K15_STREAMROLLER_GODAVARI) {
531 cpu().SetLeaves({
532 {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}},
533 {{0x00000001, 0}, Leaf{0x00630F81, 0x00040800, 0x3E98320B, 0x178BFBFF}},
534 {{0x00000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
535 {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}},
536 {{0x80000001, 0}, Leaf{0x00630F81, 0x10000000, 0x0FEBBFFF, 0x2FD3FBFF}},
537 {{0x80000002, 0}, Leaf{0x20444D41, 0x372D3841, 0x4B303736, 0x64615220}},
538 {{0x80000003, 0}, Leaf{0x206E6F65, 0x202C3752, 0x43203031, 0x75706D6F}},
539 {{0x80000004, 0}, Leaf{0x43206574, 0x7365726F, 0x2B433420, 0x00204736}},
540 {{0x80000005, 0}, Leaf{0xFF40FF18, 0xFF40FF30, 0x10040140, 0x60030140}},
541 });
542 const auto info = GetX86Info();
543
544 EXPECT_STREQ(info.vendor, "AuthenticAMD");
545 EXPECT_EQ(info.family, 0x15);
546 EXPECT_EQ(info.model, 0x38);
547 EXPECT_EQ(info.stepping, 0x01);
548 EXPECT_STREQ(info.brand_string,
549 "AMD A8-7670K Radeon R7, 10 Compute Cores 4C+6G ");
550 EXPECT_EQ(GetX86Microarchitecture(&info),
551 X86Microarchitecture::AMD_STREAMROLLER);
552
553 char brand_string[49];
554 FillX86BrandString(brand_string);
555 EXPECT_STREQ(brand_string, "AMD A8-7670K Radeon R7, 10 Compute Cores 4C+6G ");
556 }
557
558 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0700F01_K16_Kabini_CPUID.txt
TEST_F(CpuidX86Test,AMD_K16_JAGUAR_KABINI)559 TEST_F(CpuidX86Test, AMD_K16_JAGUAR_KABINI) {
560 cpu().SetLeaves({
561 {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}},
562 {{0x00000001, 0}, Leaf{0x00700F01, 0x00040800, 0x3ED8220B, 0x178BFBFF}},
563 {{0x00000007, 0}, Leaf{0x00000000, 0x00000008, 0x00000000, 0x00000000}},
564 {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}},
565 {{0x80000001, 0}, Leaf{0x00700F01, 0x00000000, 0x154037FF, 0x2FD3FBFF}},
566 {{0x80000002, 0}, Leaf{0x20444D41, 0x352D3441, 0x20303030, 0x20555041}},
567 {{0x80000003, 0}, Leaf{0x68746977, 0x64615220, 0x286E6F65, 0x20294D54}},
568 {{0x80000004, 0}, Leaf{0x47204448, 0x68706172, 0x20736369, 0x00202020}},
569 });
570 const auto info = GetX86Info();
571
572 EXPECT_STREQ(info.vendor, "AuthenticAMD");
573 EXPECT_EQ(info.family, 0x16);
574 EXPECT_EQ(info.model, 0x00);
575 EXPECT_STREQ(info.brand_string,
576 "AMD A4-5000 APU with Radeon(TM) HD Graphics ");
577 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_JAGUAR);
578
579 char brand_string[49];
580 FillX86BrandString(brand_string);
581 EXPECT_STREQ(brand_string, "AMD A4-5000 APU with Radeon(TM) HD Graphics ");
582 }
583
584 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0730F01_K16_Beema_CPUID2.txt
TEST_F(CpuidX86Test,AMD_K16_PUMA_BEEMA)585 TEST_F(CpuidX86Test, AMD_K16_PUMA_BEEMA) {
586 cpu().SetLeaves({
587 {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}},
588 {{0x00000001, 0}, Leaf{0x00730F01, 0x00040800, 0x7ED8220B, 0x178BFBFF}},
589 {{0x00000007, 0}, Leaf{0x00000000, 0x00000008, 0x00000000, 0x00000000}},
590 {{0x80000000, 0}, Leaf{0x8000001E, 0x68747541, 0x444D4163, 0x69746E65}},
591 {{0x80000001, 0}, Leaf{0x00730F01, 0x00000000, 0x1D4037FF, 0x2FD3FBFF}},
592 {{0x80000002, 0}, Leaf{0x20444D41, 0x362D3641, 0x20303133, 0x20555041}},
593 {{0x80000003, 0}, Leaf{0x68746977, 0x444D4120, 0x64615220, 0x206E6F65}},
594 {{0x80000004, 0}, Leaf{0x47203452, 0x68706172, 0x20736369, 0x00202020}},
595 });
596 const auto info = GetX86Info();
597
598 EXPECT_STREQ(info.vendor, "AuthenticAMD");
599 EXPECT_EQ(info.family, 0x16);
600 EXPECT_EQ(info.model, 0x30);
601 EXPECT_STREQ(info.brand_string,
602 "AMD A6-6310 APU with AMD Radeon R4 Graphics ");
603 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_PUMA);
604
605 char brand_string[49];
606 FillX86BrandString(brand_string);
607 EXPECT_STREQ(brand_string, "AMD A6-6310 APU with AMD Radeon R4 Graphics ");
608 }
609
610 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0820F01_K17_Dali_CPUID.txt
TEST_F(CpuidX86Test,AMD_K17_ZEN_DALI)611 TEST_F(CpuidX86Test, AMD_K17_ZEN_DALI) {
612 cpu().SetLeaves({
613 {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}},
614 {{0x00000001, 0}, Leaf{0x00820F01, 0x00020800, 0x7ED8320B, 0x178BFBFF}},
615 {{0x00000007, 0}, Leaf{0x00000000, 0x209C01A9, 0x00000000, 0x00000000}},
616 {{0x80000000, 0}, Leaf{0x8000001F, 0x68747541, 0x444D4163, 0x69746E65}},
617 {{0x80000001, 0}, Leaf{0x00820F01, 0x00000000, 0x35C233FF, 0x2FD3FBFF}},
618 {{0x80000002, 0}, Leaf{0x20444D41, 0x30323033, 0x69772065, 0x52206874}},
619 {{0x80000003, 0}, Leaf{0x6F656461, 0x7247206E, 0x69687061, 0x20207363}},
620 {{0x80000004, 0}, Leaf{0x20202020, 0x20202020, 0x20202020, 0x00202020}},
621 });
622 const auto info = GetX86Info();
623
624 EXPECT_STREQ(info.vendor, "AuthenticAMD");
625 EXPECT_EQ(info.family, 0x17);
626 EXPECT_EQ(info.model, 0x20);
627 EXPECT_STREQ(info.brand_string,
628 "AMD 3020e with Radeon Graphics ");
629 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN);
630
631 char brand_string[49];
632 FillX86BrandString(brand_string);
633 EXPECT_STREQ(brand_string, "AMD 3020e with Radeon Graphics ");
634 }
635
636 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0800F82_K17_ZenP_CPUID.txt
TEST_F(CpuidX86Test,AMD_K17_ZEN_PLUS_PINNACLE_RIDGE)637 TEST_F(CpuidX86Test, AMD_K17_ZEN_PLUS_PINNACLE_RIDGE) {
638 cpu().SetLeaves({
639 {{0x00000000, 0}, Leaf{0x0000000D, 0x68747541, 0x444D4163, 0x69746E65}},
640 {{0x00000001, 0}, Leaf{0x00800F82, 0x00100800, 0x7ED8320B, 0x178BFBFF}},
641 {{0x00000007, 0}, Leaf{0x00000000, 0x209C01A9, 0x00000000, 0x00000000}},
642 {{0x80000000, 0}, Leaf{0x8000001F, 0x68747541, 0x444D4163, 0x69746E65}},
643 {{0x80000001, 0}, Leaf{0x00800F82, 0x20000000, 0x35C233FF, 0x2FD3FBFF}},
644 {{0x80000002, 0}, Leaf{0x20444D41, 0x657A7952, 0x2037206E, 0x30303732}},
645 {{0x80000003, 0}, Leaf{0x69452058, 0x2D746867, 0x65726F43, 0x6F725020}},
646 {{0x80000004, 0}, Leaf{0x73736563, 0x2020726F, 0x20202020, 0x00202020}},
647 });
648 const auto info = GetX86Info();
649
650 EXPECT_STREQ(info.vendor, "AuthenticAMD");
651 EXPECT_EQ(info.family, 0x17);
652 EXPECT_EQ(info.model, 0x08);
653 EXPECT_STREQ(info.brand_string,
654 "AMD Ryzen 7 2700X Eight-Core Processor ");
655 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN_PLUS);
656
657 char brand_string[49];
658 FillX86BrandString(brand_string);
659 EXPECT_STREQ(brand_string, "AMD Ryzen 7 2700X Eight-Core Processor ");
660 }
661
662 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0840F70_K17_CPUID.txt
TEST_F(CpuidX86Test,AMD_K17_ZEN2_XBOX_SERIES_X)663 TEST_F(CpuidX86Test, AMD_K17_ZEN2_XBOX_SERIES_X) {
664 cpu().SetLeaves({
665 {{0x00000000, 0}, Leaf{0x00000010, 0x68747541, 0x444D4163, 0x69746E65}},
666 {{0x00000001, 0}, Leaf{0x00840F70, 0x00100800, 0x7ED8320B, 0x178BFBFF}},
667 {{0x00000007, 0}, Leaf{0x00000000, 0x219C91A9, 0x00400004, 0x00000000}},
668 {{0x80000000, 0}, Leaf{0x80000020, 0x68747541, 0x444D4163, 0x69746E65}},
669 {{0x80000001, 0}, Leaf{0x00840F70, 0x00000000, 0xF5C2B7FF, 0x2FD3FBFF}},
670 {{0x80000002, 0}, Leaf{0x20444D41, 0x30303734, 0x2D382053, 0x65726F43}},
671 {{0x80000003, 0}, Leaf{0x6F725020, 0x73736563, 0x4420726F, 0x746B7365}},
672 {{0x80000004, 0}, Leaf{0x4B20706F, 0x00007469, 0x00000000, 0x00000000}},
673 });
674 const auto info = GetX86Info();
675
676 EXPECT_STREQ(info.vendor, "AuthenticAMD");
677 EXPECT_EQ(info.family, 0x17);
678 EXPECT_EQ(info.model, 0x47);
679 EXPECT_STREQ(info.brand_string, "AMD 4700S 8-Core Processor Desktop Kit");
680 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN2);
681
682 char brand_string[49];
683 FillX86BrandString(brand_string);
684 EXPECT_STREQ(brand_string, "AMD 4700S 8-Core Processor Desktop Kit");
685 }
686
687 // http://users.atw.hu/instlatx64/HygonGenuine/HygonGenuine0900F02_Hygon_CPUID3.txt
TEST_F(CpuidX86Test,AMD_K18_ZEN_DHYANA)688 TEST_F(CpuidX86Test, AMD_K18_ZEN_DHYANA) {
689 cpu().SetLeaves({
690 {{0x00000000, 0}, Leaf{0x0000000D, 0x6F677948, 0x656E6975, 0x6E65476E}},
691 {{0x00000001, 0}, Leaf{0x00900F02, 0x00100800, 0x74D83209, 0x178BFBFF}},
692 {{0x00000007, 0}, Leaf{0x00000000, 0x009C01A9, 0x0040068C, 0x00000000}},
693 {{0x80000000, 0}, Leaf{0x8000001F, 0x6F677948, 0x656E6975, 0x6E65476E}},
694 {{0x80000001, 0}, Leaf{0x00900F02, 0x60000000, 0x35C233FF, 0x2FD3FBFF}},
695 {{0x80000002, 0}, Leaf{0x6F677948, 0x3843206E, 0x31332036, 0x20203538}},
696 {{0x80000003, 0}, Leaf{0x6F632D38, 0x50206572, 0x65636F72, 0x726F7373}},
697 {{0x80000004, 0}, Leaf{0x20202020, 0x20202020, 0x20202020, 0x00202020}},
698 });
699 const auto info = GetX86Info();
700
701 EXPECT_STREQ(info.vendor, "HygonGenuine");
702 EXPECT_EQ(info.family, 0x18);
703 EXPECT_EQ(info.model, 0x00);
704 EXPECT_STREQ(info.brand_string,
705 "Hygon C86 3185 8-core Processor ");
706 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN);
707
708 char brand_string[49];
709 FillX86BrandString(brand_string);
710 EXPECT_STREQ(brand_string, "Hygon C86 3185 8-core Processor ");
711 }
712
713 // http://users.atw.hu/instlatx64/HygonGenuine/HygonGenuine0900F02_Hygon_CPUID.txt
TEST_F(CpuidX86Test,AMD_K18_ZEN_DHYANA_CACHE_INFO)714 TEST_F(CpuidX86Test, AMD_K18_ZEN_DHYANA_CACHE_INFO) {
715 cpu().SetLeaves({
716 {{0x00000000, 0}, Leaf{0x0000000D, 0x6F677948, 0x656E6975, 0x6E65476E}},
717 {{0x00000001, 0}, Leaf{0x00900F02, 0x00100800, 0x74D83209, 0x178BFBFF}},
718 {{0x80000000, 0}, Leaf{0x8000001F, 0x6F677948, 0x656E6975, 0x6E65476E}},
719 {{0x80000001, 0}, Leaf{0x00900F02, 0x60000000, 0x35C233FF, 0x2FD3FBFF}},
720 {{0x8000001D, 0}, Leaf{0x00004121, 0x01C0003F, 0x0000003F, 0x00000000}},
721 {{0x8000001D, 1}, Leaf{0x00004122, 0x00C0003F, 0x000000FF, 0x00000000}},
722 {{0x8000001D, 2}, Leaf{0x00004143, 0x01C0003F, 0x000003FF, 0x00000002}},
723 {{0x8000001D, 3}, Leaf{0x0001C163, 0x03C0003F, 0x00001FFF, 0x00000001}},
724 });
725 const auto info = GetX86CacheInfo();
726
727 EXPECT_EQ(info.size, 4);
728 EXPECT_EQ(info.levels[0].level, 1);
729 EXPECT_EQ(info.levels[0].cache_type, 1);
730 EXPECT_EQ(info.levels[0].cache_size, 32 * KiB);
731 EXPECT_EQ(info.levels[0].ways, 8);
732 EXPECT_EQ(info.levels[0].line_size, 64);
733 EXPECT_EQ(info.levels[0].tlb_entries, 64);
734 EXPECT_EQ(info.levels[0].partitioning, 1);
735
736 EXPECT_EQ(info.levels[1].level, 1);
737 EXPECT_EQ(info.levels[1].cache_type, 2);
738 EXPECT_EQ(info.levels[1].cache_size, 64 * KiB);
739 EXPECT_EQ(info.levels[1].ways, 4);
740 EXPECT_EQ(info.levels[1].line_size, 64);
741 EXPECT_EQ(info.levels[1].tlb_entries, 256);
742 EXPECT_EQ(info.levels[1].partitioning, 1);
743
744 EXPECT_EQ(info.levels[2].level, 2);
745 EXPECT_EQ(info.levels[2].cache_type, 3);
746 EXPECT_EQ(info.levels[2].cache_size, 512 * KiB);
747 EXPECT_EQ(info.levels[2].ways, 8);
748 EXPECT_EQ(info.levels[2].line_size, 64);
749 EXPECT_EQ(info.levels[2].tlb_entries, 1024);
750 EXPECT_EQ(info.levels[2].partitioning, 1);
751
752 EXPECT_EQ(info.levels[3].level, 3);
753 EXPECT_EQ(info.levels[3].cache_type, 3);
754 EXPECT_EQ(info.levels[3].cache_size, 8 * MiB);
755 EXPECT_EQ(info.levels[3].ways, 16);
756 EXPECT_EQ(info.levels[3].line_size, 64);
757 EXPECT_EQ(info.levels[3].tlb_entries, 8192);
758 EXPECT_EQ(info.levels[3].partitioning, 1);
759 }
760
761 // http://users.atw.hu/instlatx64/AuthenticAMD/AuthenticAMD0A20F10_K19_Vermeer2_CPUID.txt
TEST_F(CpuidX86Test,AMD_K19_ZEN3_VERMEER)762 TEST_F(CpuidX86Test, AMD_K19_ZEN3_VERMEER) {
763 cpu().SetLeaves({
764 {{0x00000000, 0}, Leaf{0x00000010, 0x68747541, 0x444D4163, 0x69746E65}},
765 {{0x00000001, 0}, Leaf{0x00A20F10, 0x01180800, 0x7ED8320B, 0x178BFBFF}},
766 {{0x00000007, 0}, Leaf{0x00000000, 0x219C97A9, 0x0040068C, 0x00000000}},
767 {{0x80000000, 0}, Leaf{0x80000023, 0x68747541, 0x444D4163, 0x69746E65}},
768 {{0x80000001, 0}, Leaf{0x00A20F10, 0x20000000, 0x75C237FF, 0x2FD3FBFF}},
769 {{0x80000002, 0}, Leaf{0x20444D41, 0x657A7952, 0x2039206E, 0x30303935}},
770 {{0x80000003, 0}, Leaf{0x32312058, 0x726F432D, 0x72502065, 0x7365636F}},
771 {{0x80000004, 0}, Leaf{0x20726F73, 0x20202020, 0x20202020, 0x00202020}},
772 });
773 const auto info = GetX86Info();
774
775 EXPECT_STREQ(info.vendor, "AuthenticAMD");
776 EXPECT_EQ(info.family, 0x19);
777 EXPECT_EQ(info.model, 0x21);
778 EXPECT_STREQ(info.brand_string,
779 "AMD Ryzen 9 5900X 12-Core Processor ");
780 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::AMD_ZEN3);
781
782 char brand_string[49];
783 FillX86BrandString(brand_string);
784 EXPECT_STREQ(brand_string, "AMD Ryzen 9 5900X 12-Core Processor ");
785 }
786
787 // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel00106A1_Nehalem_CPUID.txt
TEST_F(CpuidX86Test,Nehalem)788 TEST_F(CpuidX86Test, Nehalem) {
789 // Pre AVX cpus don't have xsave
790 cpu().SetOsBackupsExtendedRegisters(false);
791 #if defined(CPU_FEATURES_OS_WINDOWS)
792 cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE);
793 cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
794 cpu().SetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE);
795 #elif defined(CPU_FEATURES_OS_MACOS)
796 cpu().SetDarwinSysCtlByName("hw.optional.sse");
797 cpu().SetDarwinSysCtlByName("hw.optional.sse2");
798 cpu().SetDarwinSysCtlByName("hw.optional.sse3");
799 cpu().SetDarwinSysCtlByName("hw.optional.supplementalsse3");
800 cpu().SetDarwinSysCtlByName("hw.optional.sse4_1");
801 cpu().SetDarwinSysCtlByName("hw.optional.sse4_2");
802 #elif defined(CPU_FEATURES_OS_FREEBSD)
803 auto& fs = GetEmptyFilesystem();
804 fs.CreateFile("/var/run/dmesg.boot", R"(
805 ---<<BOOT>>---
806 Copyright (c) 1992-2020 The FreeBSD Project.
807 FreeBSD is a registered trademark of The FreeBSD Foundation.
808 Features=0x1783fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SSE,SSE2,HTT>
809 Features2=0x5eda2203<SSE3,PCLMULQDQ,SSSE3,CX16,PCID,SSE4.1,SSE4.2,MOVBE,POPCNT,AESNI,XSAVE,OSXSAVE,RDRAND>
810 real memory = 2147418112 (2047 MB)
811 )");
812 #elif defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
813 auto& fs = GetEmptyFilesystem();
814 fs.CreateFile("/proc/cpuinfo", R"(processor :
815 flags : fpu mmx sse sse2 pni ssse3 sse4_1 sse4_2
816 )");
817 #endif
818 cpu().SetLeaves({
819 {{0x00000000, 0}, Leaf{0x0000000B, 0x756E6547, 0x6C65746E, 0x49656E69}},
820 {{0x00000001, 0}, Leaf{0x000106A2, 0x00100800, 0x00BCE3BD, 0xBFEBFBFF}},
821 {{0x00000002, 0}, Leaf{0x55035A01, 0x00F0B0E3, 0x00000000, 0x09CA212C}},
822 {{0x00000003, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
823 {{0x00000004, 0}, Leaf{0x1C004121, 0x01C0003F, 0x0000003F, 0x00000000}},
824 {{0x00000004, 0}, Leaf{0x1C004122, 0x00C0003F, 0x0000007F, 0x00000000}},
825 {{0x00000004, 0}, Leaf{0x1C004143, 0x01C0003F, 0x000001FF, 0x00000000}},
826 {{0x00000004, 0}, Leaf{0x1C03C163, 0x03C0003F, 0x00000FFF, 0x00000002}},
827 {{0x00000005, 0}, Leaf{0x00000040, 0x00000040, 0x00000003, 0x00021120}},
828 {{0x00000006, 0}, Leaf{0x00000001, 0x00000002, 0x00000001, 0x00000000}},
829 {{0x00000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
830 {{0x00000008, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
831 {{0x00000009, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
832 {{0x0000000A, 0}, Leaf{0x07300403, 0x00000000, 0x00000000, 0x00000603}},
833 {{0x0000000B, 0}, Leaf{0x00000001, 0x00000001, 0x00000100, 0x00000000}},
834 {{0x0000000B, 0}, Leaf{0x00000004, 0x00000002, 0x00000201, 0x00000000}},
835 {{0x80000000, 0}, Leaf{0x80000008, 0x00000000, 0x00000000, 0x00000000}},
836 {{0x80000001, 0}, Leaf{0x00000000, 0x00000000, 0x00000001, 0x28100000}},
837 {{0x80000002, 0}, Leaf{0x756E6547, 0x20656E69, 0x65746E49, 0x2952286C}},
838 {{0x80000003, 0}, Leaf{0x55504320, 0x20202020, 0x20202020, 0x40202020}},
839 {{0x80000004, 0}, Leaf{0x30303020, 0x20402030, 0x37382E31, 0x007A4847}},
840 {{0x80000005, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
841 {{0x80000006, 0}, Leaf{0x00000000, 0x00000000, 0x01006040, 0x00000000}},
842 {{0x80000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000100}},
843 {{0x80000008, 0}, Leaf{0x00003028, 0x00000000, 0x00000000, 0x00000000}},
844 });
845 const auto info = GetX86Info();
846
847 EXPECT_STREQ(info.vendor, "GenuineIntel");
848 EXPECT_EQ(info.family, 0x06);
849 EXPECT_EQ(info.model, 0x1A);
850 EXPECT_EQ(info.stepping, 0x02);
851 EXPECT_STREQ(info.brand_string,
852 "Genuine Intel(R) CPU @ 0000 @ 1.87GHz");
853 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::INTEL_NHM);
854
855 char brand_string[49];
856 FillX86BrandString(brand_string);
857 EXPECT_STREQ(brand_string, "Genuine Intel(R) CPU @ 0000 @ 1.87GHz");
858
859 EXPECT_TRUE(info.features.sse);
860 EXPECT_TRUE(info.features.sse2);
861 EXPECT_TRUE(info.features.sse3);
862 #if !defined(CPU_FEATURES_OS_WINDOWS)
863 // Currently disabled on Windows as IsProcessorFeaturePresent do not support
864 // feature detection > sse3.
865 EXPECT_TRUE(info.features.ssse3);
866 EXPECT_TRUE(info.features.sse4_1);
867 EXPECT_TRUE(info.features.sse4_2);
868 #endif // !defined(CPU_FEATURES_OS_WINDOWS)
869 }
870
871 // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0030673_Silvermont3_CPUID.txt
TEST_F(CpuidX86Test,Atom)872 TEST_F(CpuidX86Test, Atom) {
873 // Pre AVX cpus don't have xsave
874 cpu().SetOsBackupsExtendedRegisters(false);
875 #if defined(CPU_FEATURES_OS_WINDOWS)
876 cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE);
877 cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
878 cpu().SetWindowsIsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE);
879 #elif defined(CPU_FEATURES_OS_MACOS)
880 cpu().SetDarwinSysCtlByName("hw.optional.sse");
881 cpu().SetDarwinSysCtlByName("hw.optional.sse2");
882 cpu().SetDarwinSysCtlByName("hw.optional.sse3");
883 cpu().SetDarwinSysCtlByName("hw.optional.supplementalsse3");
884 cpu().SetDarwinSysCtlByName("hw.optional.sse4_1");
885 cpu().SetDarwinSysCtlByName("hw.optional.sse4_2");
886 #elif defined(CPU_FEATURES_OS_FREEBSD)
887 auto& fs = GetEmptyFilesystem();
888 fs.CreateFile("/var/run/dmesg.boot", R"(
889 ---<<BOOT>>---
890 Copyright (c) 1992-2020 The FreeBSD Project.
891 FreeBSD is a registered trademark of The FreeBSD Foundation.
892 Features=0x1783fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SSE,SSE2,HTT>
893 Features2=0x5eda2203<SSE3,PCLMULQDQ,SSSE3,CX16,PCID,SSE4.1,SSE4.2,MOVBE,POPCNT,AESNI,XSAVE,OSXSAVE,RDRAND>
894 real memory = 2147418112 (2047 MB)
895 )");
896 #elif defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
897 auto& fs = GetEmptyFilesystem();
898 fs.CreateFile("/proc/cpuinfo", R"(
899 flags : fpu mmx sse sse2 pni ssse3 sse4_1 sse4_2
900 )");
901 #endif
902 cpu().SetLeaves({
903 {{0x00000000, 0}, Leaf{0x0000000B, 0x756E6547, 0x6C65746E, 0x49656E69}},
904 {{0x00000001, 0}, Leaf{0x00030673, 0x00100800, 0x41D8E3BF, 0xBFEBFBFF}},
905 {{0x00000002, 0}, Leaf{0x61B3A001, 0x0000FFC2, 0x00000000, 0x00000000}},
906 {{0x00000003, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
907 {{0x00000004, 0}, Leaf{0x1C000121, 0x0140003F, 0x0000003F, 0x00000001}},
908 {{0x00000004, 1}, Leaf{0x1C000122, 0x01C0003F, 0x0000003F, 0x00000001}},
909 {{0x00000004, 2}, Leaf{0x1C00C143, 0x03C0003F, 0x000003FF, 0x00000001}},
910 {{0x00000005, 0}, Leaf{0x00000040, 0x00000040, 0x00000003, 0x33000020}},
911 {{0x00000006, 0}, Leaf{0x00000005, 0x00000002, 0x00000009, 0x00000000}},
912 {{0x00000007, 0}, Leaf{0x00000000, 0x00002282, 0x00000000, 0x00000000}},
913 {{0x00000008, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
914 {{0x00000009, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
915 {{0x0000000A, 0}, Leaf{0x07280203, 0x00000000, 0x00000000, 0x00004503}},
916 {{0x0000000B, 0}, Leaf{0x00000001, 0x00000001, 0x00000100, 0x00000000}},
917 {{0x0000000B, 1}, Leaf{0x00000004, 0x00000004, 0x00000201, 0x00000000}},
918 {{0x80000000, 0}, Leaf{0x80000008, 0x00000000, 0x00000000, 0x00000000}},
919 {{0x80000001, 0}, Leaf{0x00000000, 0x00000000, 0x00000101, 0x28100000}},
920 {{0x80000002, 0}, Leaf{0x20202020, 0x6E492020, 0x286C6574, 0x43202952}},
921 {{0x80000003, 0}, Leaf{0x72656C65, 0x52286E6F, 0x50432029, 0x4A202055}},
922 {{0x80000004, 0}, Leaf{0x30303931, 0x20402020, 0x39392E31, 0x007A4847}},
923 {{0x80000005, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000000}},
924 {{0x80000006, 0}, Leaf{0x00000000, 0x00000000, 0x04008040, 0x00000000}},
925 {{0x80000007, 0}, Leaf{0x00000000, 0x00000000, 0x00000000, 0x00000100}},
926 {{0x80000008, 0}, Leaf{0x00003024, 0x00000000, 0x00000000, 0x00000000}},
927 });
928 const auto info = GetX86Info();
929
930 EXPECT_STREQ(info.vendor, "GenuineIntel");
931 EXPECT_EQ(info.family, 0x06);
932 EXPECT_EQ(info.model, 0x37);
933 EXPECT_EQ(info.stepping, 0x03);
934 EXPECT_STREQ(info.brand_string,
935 " Intel(R) Celeron(R) CPU J1900 @ 1.99GHz");
936 EXPECT_EQ(GetX86Microarchitecture(&info),
937 X86Microarchitecture::INTEL_ATOM_SMT);
938
939 char brand_string[49];
940 FillX86BrandString(brand_string);
941 EXPECT_STREQ(brand_string, " Intel(R) Celeron(R) CPU J1900 @ 1.99GHz");
942
943 EXPECT_TRUE(info.features.sse);
944 EXPECT_TRUE(info.features.sse2);
945 EXPECT_TRUE(info.features.sse3);
946 #if !defined(CPU_FEATURES_OS_WINDOWS)
947 // Currently disabled on Windows as IsProcessorFeaturePresent do not support
948 // feature detection > sse3.
949 EXPECT_TRUE(info.features.ssse3);
950 EXPECT_TRUE(info.features.sse4_1);
951 EXPECT_TRUE(info.features.sse4_2);
952 #endif // !defined(CPU_FEATURES_OS_WINDOWS)
953 }
954
955 // https://www.felixcloutier.com/x86/cpuid#example-3-1--example-of-cache-and-tlb-interpretation
TEST_F(CpuidX86Test,P4_CacheInfo)956 TEST_F(CpuidX86Test, P4_CacheInfo) {
957 cpu().SetLeaves({
958 {{0x00000000, 0}, Leaf{0x00000002, 0x756E6547, 0x6C65746E, 0x49656E69}},
959 {{0x00000001, 0}, Leaf{0x00000F0A, 0x00010808, 0x00000000, 0x3FEBFBFF}},
960 {{0x00000002, 0}, Leaf{0x665B5001, 0x00000000, 0x00000000, 0x007A7000}},
961 });
962
963 const auto info = GetX86CacheInfo();
964 EXPECT_EQ(info.size, 5);
965
966 EXPECT_EQ(info.levels[0].level, UNDEF);
967 EXPECT_EQ(info.levels[0].cache_type, CPU_FEATURE_CACHE_TLB);
968 EXPECT_EQ(info.levels[0].cache_size, 4 * KiB);
969 EXPECT_EQ(info.levels[0].ways, UNDEF);
970 EXPECT_EQ(info.levels[0].line_size, UNDEF);
971 EXPECT_EQ(info.levels[0].tlb_entries, 64);
972 EXPECT_EQ(info.levels[0].partitioning, 0);
973
974 EXPECT_EQ(info.levels[1].level, UNDEF);
975 EXPECT_EQ(info.levels[1].cache_type, CPU_FEATURE_CACHE_TLB);
976 EXPECT_EQ(info.levels[1].cache_size, 4 * KiB);
977 EXPECT_EQ(info.levels[1].ways, UNDEF);
978 EXPECT_EQ(info.levels[1].line_size, UNDEF);
979 EXPECT_EQ(info.levels[1].tlb_entries, 64);
980 EXPECT_EQ(info.levels[1].partitioning, 0);
981
982 EXPECT_EQ(info.levels[2].level, 1);
983 EXPECT_EQ(info.levels[2].cache_type, CPU_FEATURE_CACHE_DATA);
984 EXPECT_EQ(info.levels[2].cache_size, 8 * KiB);
985 EXPECT_EQ(info.levels[2].ways, 4);
986 EXPECT_EQ(info.levels[2].line_size, 64);
987 EXPECT_EQ(info.levels[2].tlb_entries, UNDEF);
988 EXPECT_EQ(info.levels[2].partitioning, 0);
989
990 EXPECT_EQ(info.levels[3].level, 1);
991 EXPECT_EQ(info.levels[3].cache_type, CPU_FEATURE_CACHE_INSTRUCTION);
992 EXPECT_EQ(info.levels[3].cache_size, 12 * KiB);
993 EXPECT_EQ(info.levels[3].ways, 8);
994 EXPECT_EQ(info.levels[3].line_size, UNDEF);
995 EXPECT_EQ(info.levels[3].tlb_entries, UNDEF);
996 EXPECT_EQ(info.levels[3].partitioning, 0);
997
998 EXPECT_EQ(info.levels[4].level, 2);
999 EXPECT_EQ(info.levels[4].cache_type, CPU_FEATURE_CACHE_DATA);
1000 EXPECT_EQ(info.levels[4].cache_size, 256 * KiB);
1001 EXPECT_EQ(info.levels[4].ways, 8);
1002 EXPECT_EQ(info.levels[4].line_size, 64);
1003 EXPECT_EQ(info.levels[4].tlb_entries, UNDEF);
1004 EXPECT_EQ(info.levels[4].partitioning, 2);
1005 }
1006
1007 // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0000673_P3_KatmaiDP_CPUID.txt
TEST_F(CpuidX86Test,P3)1008 TEST_F(CpuidX86Test, P3) {
1009 // Pre AVX cpus don't have xsave
1010 cpu().SetOsBackupsExtendedRegisters(false);
1011 #if defined(CPU_FEATURES_OS_WINDOWS)
1012 cpu().SetWindowsIsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE);
1013 #elif defined(CPU_FEATURES_OS_MACOS)
1014 cpu().SetDarwinSysCtlByName("hw.optional.sse");
1015 #elif defined(CPU_FEATURES_OS_FREEBSD)
1016 auto& fs = GetEmptyFilesystem();
1017 fs.CreateFile("/var/run/dmesg.boot", R"(
1018 ---<<BOOT>>---
1019 Copyright (c) 1992-2020 The FreeBSD Project.
1020 FreeBSD is a registered trademark of The FreeBSD Foundation.
1021 Features=0x1783fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SSE>
1022 real memory = 2147418112 (2047 MB)
1023 )");
1024 #elif defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
1025 auto& fs = GetEmptyFilesystem();
1026 fs.CreateFile("/proc/cpuinfo", R"(
1027 flags : fpu mmx sse
1028 )");
1029 #endif
1030 cpu().SetLeaves({
1031 {{0x00000000, 0}, Leaf{0x00000003, 0x756E6547, 0x6C65746E, 0x49656E69}},
1032 {{0x00000001, 0}, Leaf{0x00000673, 0x00000000, 0x00000000, 0x0387FBFF}},
1033 {{0x00000002, 0}, Leaf{0x03020101, 0x00000000, 0x00000000, 0x0C040843}},
1034 {{0x00000003, 0}, Leaf{0x00000000, 0x00000000, 0x4CECC782, 0x00006778}},
1035 });
1036 const auto info = GetX86Info();
1037
1038 EXPECT_STREQ(info.vendor, "GenuineIntel");
1039 EXPECT_EQ(info.family, 0x06);
1040 EXPECT_EQ(info.model, 0x07);
1041 EXPECT_EQ(info.stepping, 0x03);
1042 EXPECT_STREQ(info.brand_string, "");
1043 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::X86_UNKNOWN);
1044
1045 char brand_string[49];
1046 FillX86BrandString(brand_string);
1047 EXPECT_STREQ(brand_string, "");
1048
1049 EXPECT_TRUE(info.features.mmx);
1050 EXPECT_TRUE(info.features.sse);
1051 EXPECT_FALSE(info.features.sse2);
1052 EXPECT_FALSE(info.features.sse3);
1053 #if !defined(CPU_FEATURES_OS_WINDOWS)
1054 // Currently disabled on Windows as IsProcessorFeaturePresent do not support
1055 // feature detection > sse3.
1056 EXPECT_FALSE(info.features.ssse3);
1057 EXPECT_FALSE(info.features.sse4_1);
1058 EXPECT_FALSE(info.features.sse4_2);
1059 #endif // !defined(CPU_FEATURES_OS_WINDOWS)
1060 }
1061
1062 // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0000480_486_CPUID.txt
TEST_F(CpuidX86Test,INTEL_80486)1063 TEST_F(CpuidX86Test, INTEL_80486) {
1064 cpu().SetLeaves({
1065 {{0x00000000, 0}, Leaf{0x00000001, 0x756E6547, 0x6C65746E, 0x49656E69}},
1066 {{0x00000001, 0}, Leaf{0x00000480, 0x00000000, 0x00000000, 0x00000003}},
1067 });
1068 const auto info = GetX86Info();
1069
1070 EXPECT_STREQ(info.vendor, "GenuineIntel");
1071 EXPECT_EQ(info.family, 0x04);
1072 EXPECT_EQ(info.model, 0x08);
1073 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::INTEL_80486);
1074 }
1075
1076 // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0000526_P54C_CPUID.txt
TEST_F(CpuidX86Test,INTEL_P54C)1077 TEST_F(CpuidX86Test, INTEL_P54C) {
1078 cpu().SetLeaves({
1079 {{0x00000000, 0}, Leaf{0x00000001, 0x756E6547, 0x6C65746E, 0x49656E69}},
1080 {{0x00000001, 0}, Leaf{0x00000525, 0x00000000, 0x00000000, 0x000001BF}},
1081 });
1082 const auto info = GetX86Info();
1083
1084 EXPECT_STREQ(info.vendor, "GenuineIntel");
1085 EXPECT_EQ(info.family, 0x05);
1086 EXPECT_EQ(info.model, 0x02);
1087 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::INTEL_P5);
1088 }
1089
1090 // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0000590_Lakemont_CPUID2.txt
TEST_F(CpuidX86Test,INTEL_LAKEMONT)1091 TEST_F(CpuidX86Test, INTEL_LAKEMONT) {
1092 cpu().SetLeaves({
1093 {{0x00000000, 0}, Leaf{0x00000002, 0x756E6547, 0x6c65746E, 0x49656E69}},
1094 {{0x00000001, 0}, Leaf{0x00000590, 0x00000000, 0x00010200, 0x8000237B}},
1095 });
1096 const auto info = GetX86Info();
1097
1098 EXPECT_STREQ(info.vendor, "GenuineIntel");
1099 EXPECT_EQ(info.family, 0x05);
1100 EXPECT_EQ(info.model, 0x09);
1101 EXPECT_EQ(GetX86Microarchitecture(&info),
1102 X86Microarchitecture::INTEL_LAKEMONT);
1103 }
1104
1105 // https://github.com/InstLatx64/InstLatx64/blob/master/GenuineIntel/GenuineIntel0050670_KnightsLanding_CPUID.txt
TEST_F(CpuidX86Test,INTEL_KNIGHTS_LANDING)1106 TEST_F(CpuidX86Test, INTEL_KNIGHTS_LANDING) {
1107 cpu().SetLeaves({
1108 {{0x00000000, 0}, Leaf{0x0000000D, 0x756E6547, 0x6C65746E, 0x49656E69}},
1109 {{0x00000001, 0}, Leaf{0x00050670, 0x02FF0800, 0x7FF8F3BF, 0xBFEBFBFF}},
1110 });
1111 const auto info = GetX86Info();
1112
1113 EXPECT_STREQ(info.vendor, "GenuineIntel");
1114 EXPECT_EQ(info.family, 0x06);
1115 EXPECT_EQ(info.model, 0x57);
1116 EXPECT_EQ(GetX86Microarchitecture(&info),
1117 X86Microarchitecture::INTEL_KNIGHTS_L);
1118 }
1119
1120 // https://github.com/google/cpu_features/issues/200
1121 // http://users.atw.hu/instlatx64/GenuineIntel/GenuineIntel00206F2_Eagleton_CPUID.txt
1122 #if defined(CPU_FEATURES_OS_WINDOWS)
TEST_F(CpuidX86Test,WIN_INTEL_WESTMERE_EX)1123 TEST_F(CpuidX86Test, WIN_INTEL_WESTMERE_EX) {
1124 cpu().SetLeaves({
1125 {{0x00000000, 0}, Leaf{0x0000000B, 0x756E6547, 0x6C65746E, 0x49656E69}},
1126 {{0x00000001, 0}, Leaf{0x000206F2, 0x00400800, 0x02BEE3FF, 0xBFEBFBFF}},
1127 });
1128 const auto info = GetX86Info();
1129
1130 EXPECT_EQ(info.family, 0x06);
1131 EXPECT_EQ(info.model, 0x2F);
1132 EXPECT_EQ(GetX86Microarchitecture(&info), X86Microarchitecture::INTEL_WSM);
1133
1134 #if (_WIN32_WINNT < 0x0601) // before Win7
1135 EXPECT_FALSE(info.features.ssse3);
1136 EXPECT_FALSE(info.features.sse4_1);
1137 EXPECT_FALSE(info.features.sse4_2);
1138 #else
1139 EXPECT_TRUE(info.features.ssse3);
1140 EXPECT_TRUE(info.features.sse4_1);
1141 EXPECT_TRUE(info.features.sse4_2);
1142 #endif
1143 }
1144 #endif // CPU_FEATURES_OS_WINDOWS
1145
1146 // TODO(user): test what happens when xsave/osxsave are not present.
1147 // TODO(user): test what happens when xmm/ymm/zmm os support are not
1148 // present.
1149
1150 } // namespace
1151 } // namespace cpu_features
1152