Fix semdiff syntactic output
[hiphop-php.git] / hphp / util / cpuid.h
blob00b6f9217f4e702ae420553980c379145a6a3ecf
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2016 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 #ifndef incl_HPHP_CPUID_H_
17 #define incl_HPHP_CPUID_H_
19 namespace HPHP {
21 enum class ProcessorFamily {
22 Intel_SandyBridge,
23 Intel_IvyBridge,
24 Intel_Haswell,
25 Intel_Broadwell,
26 Intel_Skylake,
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 default:
64 if (CPUID_MODEL(x) >= 0x5E) {
65 // Any newer processors.
66 f = ProcessorFamily::Intel_Skylake;
68 break;
71 #undef CPUID_FAMILY
72 #undef CPUID_MODEL
73 #endif
74 return f;
79 #endif