Toplevel entrypoints for classes/traits/interfaces
[hiphop-php.git] / hphp / util / cpuid.h
blob6ed633192d8dce7dea15b86d6eb231800096c4a8
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #pragma once
18 namespace HPHP {
20 enum class ProcessorFamily {
21 Intel_SandyBridge,
22 Intel_IvyBridge,
23 Intel_Haswell,
24 Intel_Broadwell,
25 Intel_Skylake,
26 Intel_Cooperlake,
27 Unknown,
30 ProcessorFamily getProcessorFamily() {
31 ProcessorFamily f = ProcessorFamily::Unknown;
32 #ifdef __x86_64__
33 #define CPUID_FAMILY(x) ((((x) >> 8) & 0x0F) + (((x) >> 20) & 0xFF))
34 #define CPUID_MODEL(x) ((((x) >> 4) & 0x0F) | (((x) >> 12) & 0xF0))
35 unsigned long x;
36 asm volatile ("cpuid" : "=a"(x): "a"(1) : "ebx", "ecx", "edx");
37 // This recognizes only certain CPU microarchitecture. Anything predating
38 // SandyBridge is not recognized. Architecture for mobile processing are not
39 // recognized (eg. Atom). Any processor newer than Skylake is labeled as
40 // Skylake.
41 if (CPUID_FAMILY(x) == 6) {
42 switch (CPUID_MODEL(x)) {
43 case 0x2A:
44 case 0x2D:
45 f = ProcessorFamily::Intel_SandyBridge;
46 break;
47 case 0x3A:
48 case 0x3E:
49 f = ProcessorFamily::Intel_IvyBridge;
50 break;
51 case 0x3C:
52 case 0x3F:
53 case 0x45:
54 case 0x46:
55 f = ProcessorFamily::Intel_Haswell;
56 break;
57 case 0x3D:
58 case 0x47:
59 case 0x4F:
60 case 0x56:
61 f = ProcessorFamily::Intel_Broadwell;
62 break;
63 case 0x55:
64 f = ProcessorFamily::Intel_Cooperlake;
65 break;
66 default:
67 if (CPUID_MODEL(x) >= 0x5E) {
68 // Any newer processors. This is not correct. New processors may
69 // not fall into this case. Model numbers are not monotonically
70 // increasing.
71 f = ProcessorFamily::Intel_Skylake;
73 break;
76 #undef CPUID_FAMILY
77 #undef CPUID_MODEL
78 #endif
79 return f;