26 constexpr static uint32_t processor_type_OEM = 0;
27 constexpr static uint32_t processor_type_Intel_overdrive = 1;
28 constexpr static uint32_t processor_type_dual_processor = 2;
33 uint32_t stepping_id:4 = 0;
34 uint32_t model_id:8 = 0;
35 uint32_t family_id:9 = 0;
36 uint32_t processor_type:2 = 0;
38 uint64_t features = 0;
41 size_t cache_flush_size = 0;
47 cpu_id(cpu_id
const &)
noexcept =
default;
48 cpu_id(cpu_id &&) noexcept = default;
49 cpu_id &operator=(cpu_id const &) noexcept = default;
50 cpu_id &operator=(cpu_id &&) noexcept = default;
54 hilet leaf0 = get_leaf(0);
55 hilet max_leaf = leaf0.a;
63 size_t brand_index = 0;
65 hilet leaf1 = get_leaf(1);
67 stepping_id = leaf1.a & 0xf;
68 model_id = (leaf1.a >> 4) & 0xf;
69 family_id = (leaf1.a >> 8) & 0xf;
70 processor_type = (leaf1.a >> 12) & 0x3;
72 if (family_id == 0x6 or family_id == 0xf) {
74 model_id |= ((leaf1.a >> 16) & 0xf) << 4;
76 if (family_id == 0xf) {
78 family_id += (leaf1.a >> 20) & 0xff;
81 brand_index = leaf1.b & 0xff;
82 cache_flush_size = ((leaf1.b >> 8) & 0xff) * 8;
83 APIC_id = (leaf1.b >> 24) & 0xff;
91 [[nodiscard]]
bool has_aesni() const noexcept
93 return to_bool(instruction_set & instruction_set_aesni);
96 [[nodiscard]]
bool has_avx() const noexcept
98 return to_bool(instruction_set & instruction_set_avx);
101 [[nodiscard]]
bool has_cmpxchg16b() const noexcept
103 return to_bool(instruction_set & instruction_set_cmpxchg16b);
106 [[nodiscard]]
bool has_clfsh() const noexcept
108 return to_bool(instruction_set & instruction_set_clfsh);
111 [[nodiscard]]
bool has_cmov() const noexcept
113 return to_bool(instruction_set & instruction_set_cmov);
116 [[nodiscard]]
bool has_cx8() const noexcept
118 return to_bool(instruction_set & instruction_set_cx8);
121 [[nodiscard]]
bool has_fma() const noexcept
123 return to_bool(instruction_set & instruction_set_fma);
126 [[nodiscard]]
bool has_f16c() const noexcept
128 return to_bool(instruction_set & instruction_set_f16c);
131 [[nodiscard]]
bool has_fxsr() const noexcept
133 return to_bool(instruction_set & instruction_set_fxsr);
136 [[nodiscard]]
bool has_sse() const noexcept
138 return to_bool(instruction_set & instruction_set_sse);
141 [[nodiscard]]
bool has_sse2() const noexcept
143 return to_bool(instruction_set & instruction_set_sse2);
146 [[nodiscard]]
bool has_sse3() const noexcept
148 return to_bool(instruction_set & instruction_set_sse3);
151 [[nodiscard]]
bool has_ssse3() const noexcept
153 return to_bool(instruction_set & instruction_set_ssse3);
156 [[nodiscard]]
bool has_sse4_1() const noexcept
158 return to_bool(instruction_set & instruction_set_sse4_1);
161 [[nodiscard]]
bool has_sse4_2() const noexcept
163 return to_bool(instruction_set & instruction_set_sse4_2);
166 [[nodiscard]]
bool has_movbe() const noexcept
168 return to_bool(instruction_set & instruction_set_movbe);
171 [[nodiscard]]
bool has_mmx() const noexcept
173 return to_bool(instruction_set & instruction_set_mmx);
176 [[nodiscard]]
bool has_msr() const noexcept
178 return to_bool(instruction_set & instruction_set_msr);
181 [[nodiscard]]
bool has_osxsave() const noexcept
183 return to_bool(instruction_set & instruction_set_osxsave);
186 [[nodiscard]]
bool has_pclmulqdq() const noexcept
188 return to_bool(instruction_set & instruction_set_pclmulqdq);
191 [[nodiscard]]
bool has_popcnt() const noexcept
193 return to_bool(instruction_set & instruction_set_popcnt);
196 [[nodiscard]]
bool has_rdrand() const noexcept
198 return to_bool(instruction_set & instruction_set_rdrand);
201 [[nodiscard]]
bool has_sep() const noexcept
203 return to_bool(instruction_set & instruction_set_sep);
206 [[nodiscard]]
bool has_tsc() const noexcept
208 return to_bool(instruction_set & instruction_set_tsc);
211 [[nodiscard]]
bool has_xsave() const noexcept
213 return to_bool(instruction_set & instruction_set_xsave);
216 [[nodiscard]]
bool has_acpi() const noexcept
218 return to_bool(features & features_acpi);
221 [[nodiscard]]
bool has_apic() const noexcept
223 return to_bool(features & features_apic);
226 [[nodiscard]]
bool has_cnxt_id() const noexcept
228 return to_bool(features & features_cnxt_id);
231 [[nodiscard]]
bool has_dca() const noexcept
233 return to_bool(features & features_dca);
236 [[nodiscard]]
bool has_de() const noexcept
238 return to_bool(features & features_de);
241 [[nodiscard]]
bool has_ds() const noexcept
243 return to_bool(features & features_ds);
246 [[nodiscard]]
bool has_ds_cpl() const noexcept
248 return to_bool(features & features_ds_cpl);
251 [[nodiscard]]
bool has_dtes64() const noexcept
253 return to_bool(features & features_dtes64);
256 [[nodiscard]]
bool has_eist() const noexcept
258 return to_bool(features & features_eist);
261 [[nodiscard]]
bool has_fpu() const noexcept
263 return to_bool(features & features_fpu);
266 [[nodiscard]]
bool has_htt() const noexcept
268 return to_bool(features & features_htt);
271 [[nodiscard]]
bool has_mca() const noexcept
273 return to_bool(features & features_mca);
276 [[nodiscard]]
bool has_mce() const noexcept
278 return to_bool(features & features_mce);
281 [[nodiscard]]
bool has_monitor() const noexcept
283 return to_bool(features & features_monitor);
286 [[nodiscard]]
bool has_mttr() const noexcept
288 return to_bool(features & features_mttr);
291 [[nodiscard]]
bool has_pae() const noexcept
293 return to_bool(features & features_pae);
296 [[nodiscard]]
bool has_pat() const noexcept
298 return to_bool(features & features_pat);
301 [[nodiscard]]
bool has_pbe() const noexcept
303 return to_bool(features & features_pbe);
306 [[nodiscard]]
bool has_pcid() const noexcept
308 return to_bool(features & features_pcid);
311 [[nodiscard]]
bool has_pdcm() const noexcept
313 return to_bool(features & features_pdcm);
316 [[nodiscard]]
bool has_pge() const noexcept
318 return to_bool(features & features_pge);
321 [[nodiscard]]
bool has_pse() const noexcept
323 return to_bool(features & features_pse);
326 [[nodiscard]]
bool has_pse_36() const noexcept
328 return to_bool(features & features_pse_36);
331 [[nodiscard]]
bool has_psn() const noexcept
333 return to_bool(features & features_psm);
336 [[nodiscard]]
bool has_sdbg() const noexcept
338 return to_bool(features & features_sdbg);
341 [[nodiscard]]
bool has_smx() const noexcept
343 return to_bool(features & features_smx);
346 [[nodiscard]]
bool has_ss() const noexcept
348 return to_bool(features & features_ss);
351 [[nodiscard]]
bool has_tm() const noexcept
353 return to_bool(features & features_tm);
356 [[nodiscard]]
bool has_tm2() const noexcept
358 return to_bool(features & features_tm2);
361 [[nodiscard]]
bool has_tsc_deadline() const noexcept
363 return to_bool(features & features_tsc_deadline);
366 [[nodiscard]]
bool has_vme() const noexcept
368 return to_bool(features & features_vme);
371 [[nodiscard]]
bool has_vmx() const noexcept
373 return to_bool(features & features_vmx);
376 [[nodiscard]]
bool has_x2apic() const noexcept
378 return to_bool(features & features_x2apic);
381 [[nodiscard]]
bool has_xtpr() const noexcept
383 return to_bool(features & features_xtpr);
388 constexpr static uint64_t instruction_set_aesni = 0x0000'0000'0000'0001;
389 constexpr static uint64_t instruction_set_avx = 0x0000'0000'0000'0002;
390 constexpr static uint64_t instruction_set_cmpxchg16b = 0x0000'0000'0000'0004;
391 constexpr static uint64_t instruction_set_clfsh = 0x0000'0000'0000'0008;
392 constexpr static uint64_t instruction_set_cmov = 0x0000'0000'0000'0010;
393 constexpr static uint64_t instruction_set_cx8 = 0x0000'0000'0000'0020;
394 constexpr static uint64_t instruction_set_fma = 0x0000'0000'0000'0040;
395 constexpr static uint64_t instruction_set_f16c = 0x0000'0000'0000'0080;
396 constexpr static uint64_t instruction_set_fxsr = 0x0000'0000'0000'0100;
397 constexpr static uint64_t instruction_set_sse = 0x0000'0000'0000'0200;
398 constexpr static uint64_t instruction_set_sse2 = 0x0000'0000'0000'0300;
399 constexpr static uint64_t instruction_set_sse3 = 0x0000'0000'0000'0800;
400 constexpr static uint64_t instruction_set_ssse3 = 0x0000'0000'0000'1000;
401 constexpr static uint64_t instruction_set_sse4_1 = 0x0000'0000'0000'2000;
402 constexpr static uint64_t instruction_set_sse4_2 = 0x0000'0000'0000'4000;
403 constexpr static uint64_t instruction_set_movbe = 0x0000'0000'0000'8000;
404 constexpr static uint64_t instruction_set_mmx = 0x0000'0000'0001'0000;
405 constexpr static uint64_t instruction_set_msr = 0x0000'0000'0002'0000;
406 constexpr static uint64_t instruction_set_osxsave = 0x0000'0000'0004'0000;
407 constexpr static uint64_t instruction_set_pclmulqdq = 0x0000'0000'0008'0000;
408 constexpr static uint64_t instruction_set_popcnt = 0x0000'0000'0010'0000;
409 constexpr static uint64_t instruction_set_rdrand = 0x0000'0000'0020'0000;
410 constexpr static uint64_t instruction_set_sep = 0x0000'0000'0040'0000;
411 constexpr static uint64_t instruction_set_tsc = 0x0000'0000'0080'0000;
412 constexpr static uint64_t instruction_set_xsave = 0x0000'0000'0100'0000;
414 constexpr static uint64_t features_acpi = 0x0000'0000'0000'0001;
415 constexpr static uint64_t features_apic = 0x0000'0000'0000'0002;
416 constexpr static uint64_t features_cnxt_id = 0x0000'0000'0000'0004;
417 constexpr static uint64_t features_dca = 0x0000'0000'0000'0008;
418 constexpr static uint64_t features_de = 0x0000'0000'0000'0010;
419 constexpr static uint64_t features_ds = 0x0000'0000'0000'0020;
420 constexpr static uint64_t features_ds_cpl = 0x0000'0000'0000'0040;
421 constexpr static uint64_t features_dtes64 = 0x0000'0000'0000'0080;
422 constexpr static uint64_t features_eist = 0x0000'0000'0000'0100;
423 constexpr static uint64_t features_fpu = 0x0000'0000'0000'0200;
424 constexpr static uint64_t features_htt = 0x0000'0000'0000'0400;
425 constexpr static uint64_t features_mca = 0x0000'0000'0000'0800;
426 constexpr static uint64_t features_mce = 0x0000'0000'0000'1000;
427 constexpr static uint64_t features_monitor = 0x0000'0000'0000'2000;
428 constexpr static uint64_t features_mttr = 0x0000'0000'0000'4000;
429 constexpr static uint64_t features_pae = 0x0000'0000'0000'8000;
430 constexpr static uint64_t features_pat = 0x0000'0000'0001'0000;
431 constexpr static uint64_t features_pbe = 0x0000'0000'0002'0000;
432 constexpr static uint64_t features_pcid = 0x0000'0000'0004'0000;
433 constexpr static uint64_t features_pdcm = 0x0000'0000'0008'0000;
434 constexpr static uint64_t features_pge = 0x0000'0000'0010'0000;
435 constexpr static uint64_t features_pse = 0x0000'0000'0020'0000;
436 constexpr static uint64_t features_pse_36 = 0x0000'0000'0040'0000;
437 constexpr static uint64_t features_psn = 0x0000'0000'0080'0000;
438 constexpr static uint64_t features_sdbg = 0x0000'0000'0100'0000;
439 constexpr static uint64_t features_smx = 0x0000'0000'0200'0000;
440 constexpr static uint64_t features_ss = 0x0000'0000'0400'0000;
441 constexpr static uint64_t features_tm = 0x0000'0000'0800'0000;
442 constexpr static uint64_t features_tm2 = 0x0000'0000'1000'0000;
443 constexpr static uint64_t features_tsc_deadline = 0x0000'0000'2000'0000;
444 constexpr static uint64_t features_vme = 0x0000'0000'4000'0000;
445 constexpr static uint64_t features_vmx = 0x0000'0000'8000'0000;
446 constexpr static uint64_t features_x2apic = 0x0000'0001'0000'0000;
447 constexpr static uint64_t features_xtpr = 0x0000'0002'0000'0000;
450 uint32_t instruction_set = 0;
451 uint64_t features = 0;
460#if HI_COMPILER == HI_CC_MSVC
462 [[nodiscard]]
static leaf_type get_leaf(uint32_t leaf_id, uint32_t index = 0) noexcept
473#elif HI_COMPILER == HI_CC_GCC || HI_COMPILER == HI_CC_CLANG
475 [[nodiscard]]
static leaf_type get_leaf(uint32_t leaf_id, uint32_t index = 0) noexcept
478 __cpuid_count(leaf_id, index, r.a, r.b, r.c, r.d);
483#error "Unsuported compiler for x64 cpu_id"