2 +----------------------------------------------------------------------+
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 +----------------------------------------------------------------------+
20 enum class ProcessorFamily
{
30 ProcessorFamily
getProcessorFamily() {
31 ProcessorFamily f
= ProcessorFamily::Unknown
;
33 #define CPUID_FAMILY(x) ((((x) >> 8) & 0x0F) + (((x) >> 20) & 0xFF))
34 #define CPUID_MODEL(x) ((((x) >> 4) & 0x0F) | (((x) >> 12) & 0xF0))
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
41 if (CPUID_FAMILY(x
) == 6) {
42 switch (CPUID_MODEL(x
)) {
45 f
= ProcessorFamily::Intel_SandyBridge
;
49 f
= ProcessorFamily::Intel_IvyBridge
;
55 f
= ProcessorFamily::Intel_Haswell
;
61 f
= ProcessorFamily::Intel_Broadwell
;
64 f
= ProcessorFamily::Intel_Cooperlake
;
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
71 f
= ProcessorFamily::Intel_Skylake
;