10#if HI_COMPILER == HI_CC_MSVC
12#elif HI_COMPILER == HI_CC_GCC || HI_COMPILER == HI_CC_CLANG
15#error "Unsuported compiler for x64 cpu_id"
18namespace hi::inline
v1 {
20#if HI_COMPILER == HI_CC_MSVC
24 __cpuid(info.
data(),
static_cast<int>(cpu_id_leaf));
27 r[0] =
static_cast<uint32_t
> info[0];
28 r[1] =
static_cast<uint32_t
> info[1];
29 r[2] =
static_cast<uint32_t
> info[2];
30 r[3] =
static_cast<uint32_t
> info[3];
34#elif HI_COMPILER == HI_CC_GCC || HI_COMPILER == HI_CC_CLANG
38 __cpuid(cpu_id_leaf, r[0], r[1], r[2], r[3]);
43#error "Unsuported compiler for x64 cpu_id"
50bool cpu_id_leaf1_ecx()
52 constexpr uint32_t mask = 1 << Bit;
53 return (cpu_id_leaf1[2] & mask) != 0;
57bool cpu_id_leaf1_edx()
59 constexpr uint32_t mask = 1 << Bit;
60 return (cpu_id_leaf1[3] & mask) != 0;
64bool cpu_id_leaf7_ebx()
66 constexpr uint32_t mask = 1 << Bit;
67 return (cpu_id_leaf7[1] & mask) != 0;
71bool cpu_id_leaf7_ecx()
73 constexpr uint32_t mask = 1 << Bit;
74 return (cpu_id_leaf7[2] & mask) != 0;
78bool cpu_id_leaf7_edx()
80 constexpr uint32_t mask = 1 << Bit;
81 return (cpu_id_leaf7[3] & mask) != 0;
87 return cpu_id_leaf1_edx<0>();
91 return cpu_id_leaf1_edx<1>();
95 return cpu_id_leaf1_edx<2>();
99 return cpu_id_leaf1_edx<3>();
103 return cpu_id_leaf1_edx<4>();
107 return cpu_id_leaf1_edx<5>();
111 return cpu_id_leaf1_edx<6>();
115 return cpu_id_leaf1_edx<7>();
119 return cpu_id_leaf1_edx<8>();
123 return cpu_id_leaf1_edx<9>();
128 return cpu_id_leaf1_edx<11>();
132 return cpu_id_leaf1_edx<12>();
136 return cpu_id_leaf1_edx<13>();
140 return cpu_id_leaf1_edx<14>();
144 return cpu_id_leaf1_edx<15>();
148 return cpu_id_leaf1_edx<16>();
152 return cpu_id_leaf1_edx<17>();
156 return cpu_id_leaf1_edx<18>();
160 return cpu_id_leaf1_edx<19>();
165 return cpu_id_leaf1_edx<21>();
169 return cpu_id_leaf1_edx<22>();
173 return cpu_id_leaf1_edx<23>();
177 return cpu_id_leaf1_edx<24>();
181 return cpu_id_leaf1_edx<25>();
185 return cpu_id_leaf1_edx<26>();
189 return cpu_id_leaf1_edx<27>();
193 return cpu_id_leaf1_edx<28>();
197 return cpu_id_leaf1_edx<29>();
201 return cpu_id_leaf1_edx<30>();
205 return cpu_id_leaf1_edx<31>();
211 return cpu_id_leaf1_ecx<0>();
213bool cpu_has_pclmulqdq()
215 return cpu_id_leaf1_ecx<1>();
219 return cpu_id_leaf1_ecx<2>();
221bool cpu_has_monitor()
223 return cpu_id_leaf1_ecx<3>();
227 return cpu_id_leaf1_ecx<4>();
231 return cpu_id_leaf1_ecx<5>();
235 return cpu_id_leaf1_ecx<6>();
239 return cpu_id_leaf1_ecx<7>();
243 return cpu_id_leaf1_ecx<8>();
247 return cpu_id_leaf1_ecx<9>();
249bool cpu_has_cnxt_id()
251 return cpu_id_leaf1_ecx<10>();
255 return cpu_id_leaf1_ecx<11>();
259 return cpu_id_leaf1_ecx<12>();
263 return cpu_id_leaf1_ecx<13>();
267 return cpu_id_leaf1_ecx<14>();
271 return cpu_id_leaf1_ecx<15>();
276 return cpu_id_leaf1_ecx<17>();
280 return cpu_id_leaf1_ecx<18>();
284 return cpu_id_leaf1_ecx<19>();
288 return cpu_id_leaf1_ecx<20>();
292 return cpu_id_leaf1_ecx<21>();
296 return cpu_id_leaf1_ecx<22>();
300 return cpu_id_leaf1_ecx<23>();
302bool cpu_has_tsc_deadline()
304 return cpu_id_leaf1_ecx<24>();
308 return cpu_id_leaf1_ecx<25>();
312 return cpu_id_leaf1_ecx<26>();
314bool cpu_has_osxsave()
316 return cpu_id_leaf1_ecx<27>();
320 return cpu_id_leaf1_ecx<28>();
324 return cpu_id_leaf1_ecx<29>();
328 return cpu_id_leaf1_ecx<30>();
330bool cpu_has_hypervisor()
332 return cpu_id_leaf1_ecx<31>();
340 return cpu_id_leaf1[0] & 0xf;
344 uint32_t family_id = (cpu_id_leaf1[0] >> 8) & 0xf;
345 uint32_t model_id = (cpu_id_leaf1[0] >> 4) & 0xf;
346 if (family_id == 6 || family_id == 15) {
347 uint32_t extended_model_id = (cpu_id_leaf1[0] >> 16) & 0xf;
348 return (extended_model_id << 4) | model_id;
355 uint32_t family_id = (cpu_id_leaf1[0] >> 8) & 0xf;
356 if (family_id == 15) {
357 uint32_t extended_family_id = (cpu_id_leaf1[0] >> 20) & 0xff;
358 return family_id + extended_family_id;
360 return extended_family_id;
365bool cpu_has_fsgsbase()
367 return cpu_id_leaf7_ebx<0>();
369bool cpu_has_tsc_adjust()
371 return cpu_id_leaf7_ebx<1>();
375 return cpu_id_leaf7_ebx<2>();
379 return cpu_id_leaf7_ebx<3>();
383 return cpu_id_leaf7_ebx<4>();
387 return cpu_id_leaf7_ebx<5>();
392 return cpu_id_leaf7_ebx<7>();
396 return cpu_id_leaf7_ebx<8>();
400 return cpu_id_leaf7_ebx<9>();
402bool cpu_has_invpcid()
404 return cpu_id_leaf7_ebx<10>();
408 return cpu_id_leaf7_ebx<11>();
412 return cpu_id_leaf7_ebx<12>();
414bool cpu_has_deprecated_fpu_cs_ds()
416 return cpu_id_leaf7_ebx<13>();
420 return cpu_id_leaf7_ebx<14>();
424 return cpu_id_leaf7_ebx<15>();
426bool cpu_has_avx512_f()
428 return cpu_id_leaf7_ebx<16>();
430bool cpu_has_avx512_dq()
432 return cpu_id_leaf7_ebx<17>();
436 return cpu_id_leaf7_ebx<18>();
440 return cpu_id_leaf7_ebx<19>();
444 return cpu_id_leaf7_ebx<20>();
446bool cpu_has_avx512_ifma()
448 return cpu_id_leaf7_ebx<21>();
450bool cpu_has_pcommit()
452 return cpu_id_leaf7_ebx<22>();
454bool cpu_has_clflushopt()
456 return cpu_id_leaf7_ebx<23>();
460 return cpu_id_leaf7_ebx<24>();
462bool cpu_has_intelpt()
464 return cpu_id_leaf7_ebx<25>();
466bool cpu_has_avx512_pf()
468 return cpu_id_leaf7_ebx<26>();
470bool cpu_has_avx512_er()
472 return cpu_id_leaf7_ebx<27>();
474bool cpu_has_avx512_cd()
476 return cpu_id_leaf7_ebx<28>();
480 return cpu_id_leaf7_ebx<29>();
482bool cpu_has_avx512_bw()
484 return cpu_id_leaf7_ebx<30>();
486bool cpu_has_avx512_vl()
488 return cpu_id_leaf7_ebx<31>();
492bool cpu_has_prefetchwt1()
494 return cpu_id_leaf7_ecx<0>();
496bool cpu_has_avx512_vbmi()
498 return cpu_id_leaf7_ecx<1>();
502 return cpu_id_leaf7_ecx<2>();
506 return cpu_id_leaf7_ecx<3>();
510 return cpu_id_leaf7_ecx<4>();
512bool cpu_has_waitpkg()
514 return cpu_id_leaf7_ecx<5>();
516bool cpu_has_avx512_vmbi2()
518 return cpu_id_leaf7_ecx<6>();
522 return cpu_id_leaf7_ecx<7>();
526 return cpu_id_leaf7_ecx<8>();
530 return cpu_id_leaf7_ecx<9>();
532bool cpu_has_vpclmulqdq()
534 return cpu_id_leaf7_ecx<10>();
536bool cpu_has_avx512_vnni()
538 return cpu_id_leaf7_ecx<11>();
540bool cpu_has_avx512_bitalg()
542 return cpu_id_leaf7_ecx<12>();
545bool cpu_has_avx512_vpopcntdq()
547 return cpu_id_leaf7_ecx<14>();
550bool cpu_has_5level_paging()
552 return cpu_id_leaf7_ecx<16>();
554int cpu_has_mawau() {}
557 return cpu_id_leaf7_ecx<22>();
561bool cpu_has_cldemote()
563 return cpu_id_leaf7_ecx<25>();
568 return cpu_id_leaf7_ecx<27>();
570bool cpu_has_movdir64b()
572 return cpu_id_leaf7_ecx<28>();
577 return cpu_id_leaf7_ecx<30>();
584bool cpu_has_avx512_4vnniw()
586 return cpu_id_leaf7_edx<2>();
588bool cpu_has_avx512_4fmaps()
590 return cpu_id_leaf7_edx<3>();
594 return cpu_id_leaf7_edx<4>();
596bool cpu_has_pconfig()
598 return cpu_id_leaf7_edx<18>();
603 return cpu_id_leaf7_edx<20>();
606bool cpu_has_spec_ctrl()
608 return cpu_id_leaf7_edx<26>();
612 return cpu_id_leaf7_edx<27>();
615bool cpu_has_capabilities()
617 return cpu_id_leaf7_edx<29>();
622 return cpu_id_leaf7_edx<31>();
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
DOXYGEN BUG.
Definition algorithm.hpp:15