1 // Copyright 2017 Google LLC 2 // Copyright 2020 Intel Corporation 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 #ifndef CPU_FEATURES_INCLUDE_CPUINFO_X86_H_ 17 #define CPU_FEATURES_INCLUDE_CPUINFO_X86_H_ 18 19 #include "cpu_features_cache_info.h" 20 #include "cpu_features_macros.h" 21 22 CPU_FEATURES_START_CPP_NAMESPACE 23 24 // CPUID Vendors 25 #define CPU_FEATURES_VENDOR_GENUINE_INTEL "GenuineIntel" 26 #define CPU_FEATURES_VENDOR_AUTHENTIC_AMD "AuthenticAMD" 27 #define CPU_FEATURES_VENDOR_HYGON_GENUINE "HygonGenuine" 28 #define CPU_FEATURES_VENDOR_CENTAUR_HAULS "CentaurHauls" 29 #define CPU_FEATURES_VENDOR_SHANGHAI " Shanghai " 30 31 // See https://en.wikipedia.org/wiki/CPUID for a list of x86 cpu features. 32 // The field names are based on the short name provided in the wikipedia tables. 33 typedef struct { 34 int fpu : 1; 35 int tsc : 1; 36 int cx8 : 1; 37 int clfsh : 1; 38 int mmx : 1; 39 int aes : 1; 40 int erms : 1; 41 int f16c : 1; 42 int fma4 : 1; 43 int fma3 : 1; 44 int vaes : 1; 45 int vpclmulqdq : 1; 46 int bmi1 : 1; 47 int hle : 1; 48 int bmi2 : 1; 49 int rtm : 1; 50 int rdseed : 1; 51 int clflushopt : 1; 52 int clwb : 1; 53 54 int sse : 1; 55 int sse2 : 1; 56 int sse3 : 1; 57 int ssse3 : 1; 58 int sse4_1 : 1; 59 int sse4_2 : 1; 60 int sse4a : 1; 61 62 int avx : 1; 63 int avx_vnni : 1; 64 int avx2 : 1; 65 66 int avx512f : 1; 67 int avx512cd : 1; 68 int avx512er : 1; 69 int avx512pf : 1; 70 int avx512bw : 1; 71 int avx512dq : 1; 72 int avx512vl : 1; 73 int avx512ifma : 1; 74 int avx512vbmi : 1; 75 int avx512vbmi2 : 1; 76 int avx512vnni : 1; 77 int avx512bitalg : 1; 78 int avx512vpopcntdq : 1; 79 int avx512_4vnniw : 1; 80 int avx512_4vbmi2 : 1; // Note: this is an alias to avx512_4fmaps. 81 int avx512_second_fma : 1; 82 int avx512_4fmaps : 1; 83 int avx512_bf16 : 1; 84 int avx512_vp2intersect : 1; 85 int avx512_fp16 : 1; 86 int amx_bf16 : 1; 87 int amx_tile : 1; 88 int amx_int8 : 1; 89 90 int pclmulqdq : 1; 91 int smx : 1; 92 int sgx : 1; 93 int cx16 : 1; // aka. CMPXCHG16B 94 int sha : 1; 95 int popcnt : 1; 96 int movbe : 1; 97 int rdrnd : 1; 98 99 int dca : 1; 100 int ss : 1; 101 int adx : 1; 102 int lzcnt : 1; // Note: this flag is called ABM for AMD, LZCNT for Intel. 103 int gfni : 1; 104 int movdiri : 1; 105 int movdir64b : 1; 106 int fs_rep_mov : 1; // Fast short REP MOV 107 int fz_rep_movsb : 1; // Fast zero-length REP MOVSB 108 int fs_rep_stosb : 1; // Fast short REP STOSB 109 int fs_rep_cmpsb_scasb : 1; // Fast short REP CMPSB/SCASB 110 // Make sure to update X86FeaturesEnum below if you add a field here. 111 } X86Features; 112 113 typedef struct { 114 X86Features features; 115 int family; 116 int model; 117 int stepping; 118 char vendor[13]; // 0 terminated string 119 char brand_string[49]; // 0 terminated string 120 } X86Info; 121 122 // Calls cpuid and returns an initialized X86info. 123 X86Info GetX86Info(void); 124 125 // Returns cache hierarchy informations. 126 // Can call cpuid multiple times. 127 CacheInfo GetX86CacheInfo(void); 128 129 typedef enum { 130 X86_UNKNOWN, 131 ZHAOXIN_ZHANGJIANG, // ZhangJiang 132 ZHAOXIN_WUDAOKOU, // WuDaoKou 133 ZHAOXIN_LUJIAZUI, // LuJiaZui 134 ZHAOXIN_YONGFENG, // YongFeng 135 INTEL_80486, // 80486 136 INTEL_P5, // P5 137 INTEL_LAKEMONT, // LAKEMONT 138 INTEL_CORE, // CORE 139 INTEL_PNR, // PENRYN 140 INTEL_NHM, // NEHALEM 141 INTEL_ATOM_BNL, // BONNELL 142 INTEL_WSM, // WESTMERE 143 INTEL_SNB, // SANDYBRIDGE 144 INTEL_IVB, // IVYBRIDGE 145 INTEL_ATOM_SMT, // SILVERMONT 146 INTEL_HSW, // HASWELL 147 INTEL_BDW, // BROADWELL 148 INTEL_SKL, // SKYLAKE 149 INTEL_CCL, // CASCADELAKE 150 INTEL_ATOM_GMT, // GOLDMONT 151 INTEL_ATOM_GMT_PLUS, // GOLDMONT+ 152 INTEL_ATOM_TMT, // TREMONT 153 INTEL_KBL, // KABY LAKE 154 INTEL_CFL, // COFFEE LAKE 155 INTEL_WHL, // WHISKEY LAKE 156 INTEL_CML, // COMET LAKE 157 INTEL_CNL, // CANNON LAKE 158 INTEL_ICL, // ICE LAKE 159 INTEL_TGL, // TIGER LAKE 160 INTEL_SPR, // SAPPHIRE RAPIDS 161 INTEL_ADL, // ALDER LAKE 162 INTEL_RCL, // ROCKET LAKE 163 INTEL_RPL, // RAPTOR LAKE 164 INTEL_KNIGHTS_M, // KNIGHTS MILL 165 INTEL_KNIGHTS_L, // KNIGHTS LANDING 166 INTEL_KNIGHTS_F, // KNIGHTS FERRY 167 INTEL_KNIGHTS_C, // KNIGHTS CORNER 168 INTEL_NETBURST, // NETBURST 169 AMD_HAMMER, // K8 HAMMER 170 AMD_K10, // K10 171 AMD_K11, // K11 172 AMD_K12, // K12 LLANO 173 AMD_BOBCAT, // K14 BOBCAT 174 AMD_PILEDRIVER, // K15 PILEDRIVER 175 AMD_STREAMROLLER, // K15 STREAMROLLER 176 AMD_EXCAVATOR, // K15 EXCAVATOR 177 AMD_BULLDOZER, // K15 BULLDOZER 178 AMD_JAGUAR, // K16 JAGUAR 179 AMD_PUMA, // K16 PUMA 180 AMD_ZEN, // K17 ZEN 181 AMD_ZEN_PLUS, // K17 ZEN+ 182 AMD_ZEN2, // K17 ZEN 2 183 AMD_ZEN3, // K19 ZEN 3 184 AMD_ZEN4, // K19 ZEN 4 185 X86_MICROARCHITECTURE_LAST_, 186 } X86Microarchitecture; 187 188 // Returns the underlying microarchitecture by looking at X86Info's vendor, 189 // family and model. 190 X86Microarchitecture GetX86Microarchitecture(const X86Info* info); 191 192 // Calls cpuid and fills the brand_string. 193 // - brand_string *must* be of size 49 (beware of array decaying). 194 // - brand_string will be zero terminated. 195 CPU_FEATURES_DEPRECATED("brand_string is now embedded in X86Info by default") 196 void FillX86BrandString(char brand_string[49]); 197 198 //////////////////////////////////////////////////////////////////////////////// 199 // Introspection functions 200 201 typedef enum { 202 X86_FPU, 203 X86_TSC, 204 X86_CX8, 205 X86_CLFSH, 206 X86_MMX, 207 X86_AES, 208 X86_ERMS, 209 X86_F16C, 210 X86_FMA4, 211 X86_FMA3, 212 X86_VAES, 213 X86_VPCLMULQDQ, 214 X86_BMI1, 215 X86_HLE, 216 X86_BMI2, 217 X86_RTM, 218 X86_RDSEED, 219 X86_CLFLUSHOPT, 220 X86_CLWB, 221 X86_SSE, 222 X86_SSE2, 223 X86_SSE3, 224 X86_SSSE3, 225 X86_SSE4_1, 226 X86_SSE4_2, 227 X86_SSE4A, 228 X86_AVX, 229 X86_AVX_VNNI, 230 X86_AVX2, 231 X86_AVX512F, 232 X86_AVX512CD, 233 X86_AVX512ER, 234 X86_AVX512PF, 235 X86_AVX512BW, 236 X86_AVX512DQ, 237 X86_AVX512VL, 238 X86_AVX512IFMA, 239 X86_AVX512VBMI, 240 X86_AVX512VBMI2, 241 X86_AVX512VNNI, 242 X86_AVX512BITALG, 243 X86_AVX512VPOPCNTDQ, 244 X86_AVX512_4VNNIW, 245 X86_AVX512_4VBMI2, // Note: this is an alias to X86_AVX512_4FMAPS. 246 X86_AVX512_SECOND_FMA, 247 X86_AVX512_4FMAPS, 248 X86_AVX512_BF16, 249 X86_AVX512_VP2INTERSECT, 250 X86_AVX512_FP16, 251 X86_AMX_BF16, 252 X86_AMX_TILE, 253 X86_AMX_INT8, 254 X86_PCLMULQDQ, 255 X86_SMX, 256 X86_SGX, 257 X86_CX16, 258 X86_SHA, 259 X86_POPCNT, 260 X86_MOVBE, 261 X86_RDRND, 262 X86_DCA, 263 X86_SS, 264 X86_ADX, 265 X86_LZCNT, 266 X86_GFNI, 267 X86_MOVDIRI, 268 X86_MOVDIR64B, 269 X86_FS_REP_MOV, 270 X86_FZ_REP_MOVSB, 271 X86_FS_REP_STOSB, 272 X86_FS_REP_CMPSB_SCASB, 273 X86_LAST_, 274 } X86FeaturesEnum; 275 276 int GetX86FeaturesEnumValue(const X86Features* features, X86FeaturesEnum value); 277 278 const char* GetX86FeaturesEnumName(X86FeaturesEnum); 279 280 const char* GetX86MicroarchitectureName(X86Microarchitecture); 281 282 CPU_FEATURES_END_CPP_NAMESPACE 283 284 #if !defined(CPU_FEATURES_ARCH_X86) 285 #error "Including cpuinfo_x86.h from a non-x86 target." 286 #endif 287 288 #endif // CPU_FEATURES_INCLUDE_CPUINFO_X86_H_ 289