2 * Copyright 2015 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef FOLLY_CPUID_H_
18 #define FOLLY_CPUID_H_
21 #include <folly/Portability.h>
26 * Identification of an Intel CPU.
27 * Supports CPUID feature flags (EAX=1) and extended features (EAX=7, ECX=0).
28 * Values from http://www.intel.com/content/www/us/en/processors/processor-identification-cpuid-instruction-note.html
35 __cpuid(static_cast<int*>(reg), 0);
38 __cpuid(static_cast<int*>(reg), 1);
43 __cpuidex(static_cast<int*>(reg), 7, 0);
47 #elif FOLLY_X64 || defined(__i386__)
49 __asm__("cpuid" : "=a"(n) : "a"(0) : "ebx", "edx", "ecx");
51 __asm__("cpuid" : "=c"(f1c_), "=d"(f1d_) : "a"(1) : "ebx");
54 __asm__("cpuid" : "=b"(f7b_), "=c"(f7c_) : "a"(7), "c"(0) : "edx");
59 #define X(name, r, bit) bool name() const { return (r) & (1U << bit); }
61 // cpuid(1): Processor Info and Feature Bits.
62 #define C(name, bit) X(name, f1c_, bit)
93 #define D(name, bit) X(name, f1d_, bit)
125 // cpuid(7): Extended Features.
126 #define B(name, bit) X(name, f7b_, bit)
152 #define C(name, bit) X(name, f7c_, bit)
168 #endif /* FOLLY_CPUID_H_ */