0123ddbe494aa2cda80ee342c1f2186021648c48
[iec.git] / src / type3_AndroidCloud / anbox-master / external / cpu_features / include / cpuinfo_x86.h
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef CPU_FEATURES_INCLUDE_CPUINFO_X86_H_
16 #define CPU_FEATURES_INCLUDE_CPUINFO_X86_H_
17
18 #include "cpu_features_macros.h"
19
20 CPU_FEATURES_START_CPP_NAMESPACE
21
22 // See https://en.wikipedia.org/wiki/CPUID for a list of x86 cpu features.
23 typedef struct {
24   int aes : 1;
25   int erms : 1;
26   int f16c : 1;
27   int fma3 : 1;
28   int vpclmulqdq : 1;
29   int bmi1 : 1;
30   int bmi2 : 1;
31
32   int ssse3 : 1;
33   int sse4_1 : 1;
34   int sse4_2 : 1;
35
36   int avx : 1;
37   int avx2 : 1;
38
39   int avx512f : 1;
40   int avx512cd : 1;
41   int avx512er : 1;
42   int avx512pf : 1;
43   int avx512bw : 1;
44   int avx512dq : 1;
45   int avx512vl : 1;
46   int avx512ifma : 1;
47   int avx512vbmi : 1;
48   int avx512vbmi2 : 1;
49   int avx512vnni : 1;
50   int avx512bitalg : 1;
51   int avx512vpopcntdq : 1;
52   int avx512_4vnniw : 1;
53   int avx512_4vbmi2 : 1;
54
55   int smx : 1;
56   int sgx : 1;
57   int cx16 : 1;  // aka. CMPXCHG16B
58
59   // Make sure to update X86FeaturesEnum below if you add a field here.
60 } X86Features;
61
62 typedef struct {
63   X86Features features;
64   int family;
65   int model;
66   int stepping;
67   char vendor[13];  // 0 terminated string
68 } X86Info;
69
70 // Calls cpuid and returns an initialized X86info.
71 // This function is guaranteed to be malloc, memset and memcpy free.
72 X86Info GetX86Info(void);
73
74 typedef enum {
75   X86_UNKNOWN,
76   INTEL_CORE,      // CORE
77   INTEL_PNR,       // PENRYN
78   INTEL_NHM,       // NEHALEM
79   INTEL_ATOM_BNL,  // BONNELL
80   INTEL_WSM,       // WESTMERE
81   INTEL_SNB,       // SANDYBRIDGE
82   INTEL_IVB,       // IVYBRIDGE
83   INTEL_ATOM_SMT,  // SILVERMONT
84   INTEL_HSW,       // HASWELL
85   INTEL_BDW,       // BROADWELL
86   INTEL_SKL,       // SKYLAKE
87   INTEL_ATOM_GMT,  // GOLDMONT
88   INTEL_KBL,       // KABY LAKE
89   INTEL_CFL,       // COFFEE LAKE
90   INTEL_CNL,       // CANNON LAKE
91   AMD_HAMMER,      // K8
92   AMD_K10,         // K10
93   AMD_BOBCAT,      // K14
94   AMD_BULLDOZER,   // K15
95   AMD_JAGUAR,      // K16
96   AMD_ZEN,         // K17
97 } X86Microarchitecture;
98
99 // Returns the underlying microarchitecture by looking at X86Info's vendor,
100 // family and model.
101 X86Microarchitecture GetX86Microarchitecture(const X86Info* info);
102
103 // Calls cpuid and fills the brand_string.
104 // - brand_string *must* be of size 49 (beware of array decaying).
105 // - brand_string will be zero terminated.
106 // - This function calls memcpy.
107 void FillX86BrandString(char brand_string[49]);
108
109 ////////////////////////////////////////////////////////////////////////////////
110 // Introspection functions
111
112 typedef enum {
113   X86_AES,
114   X86_ERMS,
115   X86_F16C,
116   X86_FMA3,
117   X86_VPCLMULQDQ,
118   X86_BMI1,
119   X86_BMI2,
120   X86_SSSE3,
121   X86_SSE4_1,
122   X86_SSE4_2,
123   X86_AVX,
124   X86_AVX2,
125   X86_AVX512F,
126   X86_AVX512CD,
127   X86_AVX512ER,
128   X86_AVX512PF,
129   X86_AVX512BW,
130   X86_AVX512DQ,
131   X86_AVX512VL,
132   X86_AVX512IFMA,
133   X86_AVX512VBMI,
134   X86_AVX512VBMI2,
135   X86_AVX512VNNI,
136   X86_AVX512BITALG,
137   X86_AVX512VPOPCNTDQ,
138   X86_AVX512_4VNNIW,
139   X86_AVX512_4VBMI2,
140   X86_SMX,
141   X86_SGX,
142   X86_CX16,
143   X86_LAST_,
144 } X86FeaturesEnum;
145
146 int GetX86FeaturesEnumValue(const X86Features* features, X86FeaturesEnum value);
147
148 const char* GetX86FeaturesEnumName(X86FeaturesEnum);
149
150 const char* GetX86MicroarchitectureName(X86Microarchitecture);
151
152 CPU_FEATURES_END_CPP_NAMESPACE
153
154 #endif  // CPU_FEATURES_INCLUDE_CPUINFO_X86_H_