67 #define CPUID_C(leaf, _ecx_) \ 70 __cpuidex(out, leaf, _ecx_); \ 76 #elif defined(__i386__) && defined(__PIC__) 78 static inline void _Vc_cpuid(
int leaf,
unsigned int &eax,
unsigned int &ebx,
unsigned int &ecx,
unsigned int &edx)
81 asm(
"mov %%ebx, %[tmpb]\n\t" 83 "mov %%ebx, %[ebx]\n\t" 84 "mov %[tmpb], %%ebx\n\t" 85 : [tmpb]
"=m"(tmpb),
"=a"(eax), [ebx]
"=m"(ebx),
"+c"(ecx),
"=d"(edx)
91 _Vc_cpuid(leaf, eax, ebx, ecx, edx) 92 #define CPUID_C(leaf, _ecx_) \ 94 _Vc_cpuid(leaf, eax, ebx, ecx, edx) 97 __asm__("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(leaf)) 98 #define CPUID_C(leaf, _ecx_) \ 99 __asm__("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(leaf), "c"(_ecx_)) 114 case 0xE:
return 128;
115 case 0xF:
return 0xff;
123 static bool done =
false;
127 uint eax, ebx, ecx, edx;
133 s_processorFeaturesC = ecx;
134 s_processorFeaturesD = edx;
135 s_processorModel = (eax & 0x000000f0) >> 4;
136 s_processorFamily = (eax & 0x00000f00) >> 8;
138 if (s_processorFamily >= 0xf) {
139 const uchar processorFamilyExt = (eax & 0x0ff00000) >> 20;
140 s_processorFamily += processorFamilyExt;
141 const uchar processorModelExt = (eax & 0x000f0000) >> 12;
142 s_processorModel += processorModelExt;
144 }
else if (s_processorFamily == 0xf) {
145 const uchar processorFamilyExt = (eax & 0x0ff00000) >> 20;
146 s_processorFamily += processorFamilyExt;
147 const uchar processorModelExt = (eax & 0x000f0000) >> 12;
148 s_processorModel += processorModelExt;
149 }
else if (s_processorFamily == 0x6) {
150 const uchar processorModelExt = (eax & 0x000f0000) >> 12;
151 s_processorModel += processorModelExt;
153 s_processorType =
static_cast<ProcessorType>((eax & 0x00003000) >> 12);
155 s_brandIndex = ebx & 0xff;
157 s_cacheLineSize = ebx & 0xff;
159 s_logicalProcessors = ebx & 0xff;
162 s_processorFeatures8C = ecx;
163 s_processorFeatures8D = edx;
166 s_prefetch = cacheLineSize();
169 s_L1DataLineSize = ecx & 0xff;
170 s_L1Data = (ecx >> 24) * 1024;
171 s_L1Associativity = (ecx >> 16) & 0xff;
172 s_L1InstructionLineSize = edx & 0xff;
173 s_L1Instruction = (edx >> 24) * 1024;
176 s_L2DataLineSize = ecx & 0xff;
177 s_L2Data = (ecx >> 16) * 1024;
179 s_L3DataLineSize = edx & 0xff;
180 s_L3Data = (edx >> 18) * 512 * 1024;
187 bool checkLeaf4 =
false;
193 if (0 == (0x80000000u & eax)) {
194 for (
int i = 0; i < 3; ++i) {
196 interpret(eax & 0xff, &checkLeaf4);
199 if (0 == (0x80000000u & ebx)) {
200 for (
int i = 0; i < 4; ++i) {
201 interpret(ebx & 0xff, &checkLeaf4);
205 if (0 == (0x80000000u & ecx)) {
206 for (
int i = 0; i < 4; ++i) {
207 interpret(ecx & 0xff, &checkLeaf4);
211 if (0 == (0x80000000u & edx)) {
212 for (
int i = 0; i < 4; ++i) {
213 interpret(edx & 0xff, &checkLeaf4);
217 }
while (--repeat > 0);
219 s_prefetch = cacheLineSize();
220 if (s_prefetch == 0) {
224 for (
int i = 0; eax & 0x1f; ++i) {
226 const int cacheLevel = (eax >> 5) & 7;
228 const int linesize = 1 + (ebx & 0xfff); ebx >>= 12;
229 const int partitions = 1 + (ebx & 0x3ff); ebx >>= 10;
230 const int ways = 1 + (ebx & 0x3ff);
231 const int sets = 1 + ecx;
232 const int size = ways * partitions * linesize * sets;
233 switch (eax & 0x1f) {
235 switch (cacheLevel) {
238 s_L1DataLineSize = linesize;
239 s_L1Associativity = ways;
243 s_L2DataLineSize = linesize;
244 s_L2Associativity = ways;
248 s_L3DataLineSize = linesize;
249 s_L3Associativity = ways;
254 switch (cacheLevel) {
256 s_L1Instruction = size;
257 s_L1InstructionLineSize = linesize;
262 switch (cacheLevel) {
265 s_L1DataLineSize = linesize;
266 s_L1Associativity = ways;
270 s_L2DataLineSize = linesize;
271 s_L2Associativity = ways;
275 s_L3DataLineSize = linesize;
276 s_L3Associativity = ways;
293 s_L1Instruction = 8 * 1024;
294 s_L1InstructionLineSize = 32;
295 s_L1Associativity = 4;
298 s_L1Instruction = 16 * 1024;
299 s_L1InstructionLineSize = 32;
300 s_L1Associativity = 4;
303 s_L1Instruction = 32 * 1024;
304 s_L1InstructionLineSize = 64;
305 s_L1Associativity = 4;
309 s_L1DataLineSize = 32;
310 s_L1Associativity = 2;
313 s_L1Data = 16 * 1024;
314 s_L1DataLineSize = 32;
315 s_L1Associativity = 4;
318 s_L1Data = 16 * 1024;
319 s_L1DataLineSize = 64;
320 s_L1Associativity = 4;
323 s_L1Data = 24 * 1024;
324 s_L1DataLineSize = 64;
325 s_L1Associativity = 6;
328 s_L2Data = 256 * 1024;
329 s_L2DataLineSize = 64;
330 s_L2Associativity = 8;
333 s_L3Data = 512 * 1024;
334 s_L3DataLineSize = 64;
335 s_L3Associativity = 4;
338 s_L3Data = 1024 * 1024;
339 s_L3DataLineSize = 64;
340 s_L3Associativity = 8;
343 s_L3Data = 2 * 1024 * 1024;
344 s_L3DataLineSize = 64;
345 s_L3Associativity = 8;
348 s_L3Data = 4 * 1024 * 1024;
349 s_L3DataLineSize = 64;
350 s_L3Associativity = 8;
353 s_L1Data = 32 * 1024;
354 s_L1DataLineSize = 64;
355 s_L1Associativity = 8;
358 s_L1Data = 32 * 1024;
359 s_L1DataLineSize = 64;
360 s_L1Associativity = 8;
366 s_L2Data = 128 * 1024;
367 s_L2DataLineSize = 32;
368 s_L2Associativity = 4;
371 s_L2Data = 256 * 1024;
372 s_L2DataLineSize = 32;
373 s_L2Associativity = 4;
376 s_L2Data = 512 * 1024;
377 s_L2DataLineSize = 32;
378 s_L2Associativity = 4;
381 s_L2Data = 1024 * 1024;
382 s_L2DataLineSize = 32;
383 s_L2Associativity = 4;
386 s_L2Data = 2 * 1024 * 1024;
387 s_L2DataLineSize = 32;
388 s_L2Associativity = 4;
391 s_L3Data = 4 * 1024 * 1024;
392 s_L3DataLineSize = 64;
393 s_L3Associativity = 4;
396 s_L3Data = 8 * 1024 * 1024;
397 s_L3DataLineSize = 64;
398 s_L3Associativity = 8;
401 s_L2Data = 3 * 1024 * 1024;
402 s_L2DataLineSize = 64;
403 s_L2Associativity = 12;
406 if (s_processorFamily == 0xf && s_processorModel == 0x6) {
407 s_L3Data = 4 * 1024 * 1024;
408 s_L3DataLineSize = 64;
409 s_L3Associativity = 16;
411 s_L2Data = 4 * 1024 * 1024;
412 s_L2DataLineSize = 64;
413 s_L2Associativity = 16;
417 s_L3Data = 6 * 1024 * 1024;
418 s_L3DataLineSize = 64;
419 s_L3Associativity = 12;
422 s_L3Data = 8 * 1024 * 1024;
423 s_L3DataLineSize = 64;
424 s_L3Associativity = 16;
427 s_L3Data = 12 * 1024 * 1024;
428 s_L3DataLineSize = 64;
429 s_L3Associativity = 12;
432 s_L3Data = 16 * 1024 * 1024;
433 s_L3DataLineSize = 64;
434 s_L3Associativity = 16;
437 s_L2Data = 6 * 1024 * 1024;
438 s_L2DataLineSize = 64;
439 s_L2Associativity = 24;
442 s_L1Data = 16 * 1024;
443 s_L1DataLineSize = 64;
444 s_L1Associativity = 8;
448 s_L1DataLineSize = 64;
449 s_L1Associativity = 4;
452 s_L1Data = 16 * 1024;
453 s_L1DataLineSize = 64;
454 s_L1Associativity = 4;
457 s_L1Data = 32 * 1024;
458 s_L1DataLineSize = 64;
459 s_L1Associativity = 4;
462 s_L2Data = 1024 * 1024;
463 s_L2DataLineSize = 64;
464 s_L2Associativity = 4;
467 s_L2Data = 128 * 1024;
468 s_L2DataLineSize = 64;
469 s_L2Associativity = 8;
472 s_L2Data = 256 * 1024;
473 s_L2DataLineSize = 64;
474 s_L2Associativity = 8;
477 s_L2Data = 512 * 1024;
478 s_L2DataLineSize = 64;
479 s_L2Associativity = 8;
482 s_L2Data = 1024 * 1024;
483 s_L2DataLineSize = 64;
484 s_L2Associativity = 8;
487 s_L2Data = 2 * 1024 * 1024;
488 s_L2DataLineSize = 64;
489 s_L2Associativity = 8;
492 s_L2Data = 512 * 1024;
493 s_L2DataLineSize = 64;
494 s_L2Associativity = 2;
497 s_L2Data = 512 * 1024;
498 s_L2DataLineSize = 64;
499 s_L2Associativity = 8;
502 s_L2Data = 256 * 1024;
503 s_L2DataLineSize = 32;
504 s_L2Associativity = 8;
507 s_L2Data = 512 * 1024;
508 s_L2DataLineSize = 32;
509 s_L2Associativity = 8;
512 s_L2Data = 1024 * 1024;
513 s_L2DataLineSize = 32;
514 s_L2Associativity = 8;
517 s_L2Data = 2 * 1024 * 1024;
518 s_L2DataLineSize = 32;
519 s_L2Associativity = 8;
522 s_L2Data = 512 * 1024;
523 s_L2DataLineSize = 64;
524 s_L2Associativity = 4;
527 s_L2Data = 1024 * 1024;
528 s_L2DataLineSize = 64;
529 s_L2Associativity = 8;
532 s_L3Data = 512 * 1024;
533 s_L3DataLineSize = 64;
534 s_L3Associativity = 4;
537 s_L3Data = 1024 * 1024;
538 s_L3DataLineSize = 64;
539 s_L3Associativity = 4;
542 s_L3Data = 2 * 1024 * 1024;
543 s_L3DataLineSize = 64;
544 s_L3Associativity = 4;
547 s_L3Data = 1024 * 1024;
548 s_L3DataLineSize = 64;
549 s_L3Associativity = 8;
552 s_L3Data = 2 * 1024 * 1024;
553 s_L3DataLineSize = 64;
554 s_L3Associativity = 8;
557 s_L3Data = 4 * 1024 * 1024;
558 s_L3DataLineSize = 64;
559 s_L3Associativity = 8;
562 s_L3Data = 3 * 512 * 1024;
563 s_L3DataLineSize = 64;
564 s_L3Associativity = 12;
567 s_L3Data = 3 * 1024 * 1024;
568 s_L3DataLineSize = 64;
569 s_L3Associativity = 12;
572 s_L3Data = 6 * 1024 * 1024;
573 s_L3DataLineSize = 64;
574 s_L3Associativity = 12;
577 s_L3Data = 2 * 1024 * 1024;
578 s_L3DataLineSize = 64;
579 s_L3Associativity = 16;
582 s_L3Data = 4 * 1024 * 1024;
583 s_L3DataLineSize = 64;
584 s_L3Associativity = 16;
587 s_L3Data = 8 * 1024 * 1024;
588 s_L3DataLineSize = 64;
589 s_L3Associativity = 16;
592 s_L3Data = 12 * 1024 * 1024;
593 s_L3DataLineSize = 64;
594 s_L3Associativity = 24;
597 s_L3Data = 18 * 1024 * 1024;
598 s_L3DataLineSize = 64;
599 s_L3Associativity = 24;
602 s_L3Data = 24 * 1024 * 1024;
603 s_L3DataLineSize = 64;
604 s_L3Associativity = 24;
static uint s_processorFeaturesD
static uint s_logicalProcessors
Namespace for new ROOT classes and functions.
static ushort s_L3DataLineSize
static uint s_processorFeatures8C
#define CPUID_C(leaf, _ecx_)
static uchar s_cacheLineSize
static uint s_L1Instruction
static uint s_L1Associativity
static ushort s_L1InstructionLineSize
static uint s_L2Associativity
static void init()
Reads the CPU capabilities and stores them for faster subsequent access.
static void interpret(uchar byte, bool *checkLeaf4)
static unsigned int CpuIdAmdAssociativityTable(int bits)
static uint s_processorFeaturesC
static uint s_L3Associativity
static uchar s_processorModel
static uint s_processorFeatures8D
static ushort s_L2DataLineSize
static ushort s_L1DataLineSize
static ProcessorType s_processorType
static uchar s_processorFamily
static uchar s_brandIndex