Codemod: use #include angle brackets in folly and thrift
[folly.git] / folly / CpuId.h
1 /*
2  * Copyright 2014 Facebook, Inc.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef FOLLY_CPUID_H_
18 #define FOLLY_CPUID_H_
19
20 #include <cstdint>
21 #include <folly/Portability.h>
22
23 namespace folly {
24
25 /**
26  * Identification of an Intel CPU.
27  * Supports CPUID (EAX=1) feature flags.
28  * Values from http://www.intel.com/content/www/us/en/processors/processor-identification-cpuid-instruction-note.html
29  */
30 class CpuId {
31  public:
32   CpuId() {
33 #if FOLLY_X64 || defined(__i386__)
34     __asm__("cpuid" : "=c"(c_), "=d"(d_) : "a"(1) : "ebx");
35 #else
36     // On non-Intel, none of these features exist; at least not in the same form
37     // as they do on Intel
38     c_ = 0;
39     d_ = 0;
40 #endif
41   }
42 #define X(name, r, bit) bool name() const { return r & (1U << bit); }
43 #define C(name, bit) X(name, c_, bit)
44 #define D(name, bit) X(name, d_, bit)
45   C(sse3, 0)
46   C(pclmuldq, 1)
47   C(dtes64, 2)
48   C(monitor, 3)
49   C(dscpl, 4)
50   C(vmx, 5)
51   C(smx, 6)
52   C(eist, 7)
53   C(tm2, 8)
54   C(ssse3, 9)
55   C(cnxtid, 10)
56   // 11 is reserved
57   C(fma, 12)
58   C(cx16, 13)
59   C(xtpr, 14)
60   C(pdcm, 15)
61   // 16 is reserved
62   C(pcid, 17)
63   C(dca, 18)
64   C(sse41, 19)
65   C(sse42, 20)
66   C(x2apic, 21)
67   C(movbe, 22)
68   C(popcnt, 23)
69   C(tscdeadline, 24)
70   C(aes, 25)
71   C(xsave, 26)
72   C(osxsave, 27)
73   C(avx, 28)
74   C(f16c, 29)
75   C(rdrand, 30)
76   // 31 is not used
77   D(fpu, 0)
78   D(vme, 1)
79   D(de, 2)
80   D(pse, 3)
81   D(tsc, 4)
82   D(msr, 5)
83   D(pae, 6)
84   D(mce, 7)
85   D(cx8, 8)
86   D(apic, 9)
87   // 10 is reserved
88   D(sep, 11)
89   D(mtrr, 12)
90   D(pge, 13)
91   D(mca, 14)
92   D(cmov, 15)
93   D(pat, 16)
94   D(pse36, 17)
95   D(psn, 18)
96   D(clfsh, 19)
97   // 20 is reserved
98   D(ds, 21)
99   D(acpi, 22)
100   D(mmx, 23)
101   D(fxsr, 24)
102   D(sse, 25)
103   D(sse2, 26)
104   D(ss, 27)
105   D(htt, 28)
106   D(tm, 29)
107   // 30 is reserved
108   D(pbe, 31)
109 #undef D
110 #undef C
111 #undef X
112  private:
113   uint32_t c_;  // ECX
114   uint32_t d_;  // EDX
115 };
116
117 }  // namespace folly
118
119 #endif /* FOLLY_CPUID_H_ */
120