10b57cec5SDimitry Andric /*===---- cpuid.h - X86 cpu model detection --------------------------------=== 20b57cec5SDimitry Andric * 30b57cec5SDimitry Andric * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric * See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric * 70b57cec5SDimitry Andric *===-----------------------------------------------------------------------=== 80b57cec5SDimitry Andric */ 90b57cec5SDimitry Andric 10e8d8bef9SDimitry Andric #ifndef __CPUID_H 11e8d8bef9SDimitry Andric #define __CPUID_H 12e8d8bef9SDimitry Andric 13*0fca6ea1SDimitry Andric #if !defined(__x86_64__) && !defined(__i386__) 140b57cec5SDimitry Andric #error this header is for x86 only 150b57cec5SDimitry Andric #endif 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric /* Responses identification request with %eax 0 */ 180b57cec5SDimitry Andric /* AMD: "AuthenticAMD" */ 190b57cec5SDimitry Andric #define signature_AMD_ebx 0x68747541 200b57cec5SDimitry Andric #define signature_AMD_edx 0x69746e65 210b57cec5SDimitry Andric #define signature_AMD_ecx 0x444d4163 220b57cec5SDimitry Andric /* CENTAUR: "CentaurHauls" */ 230b57cec5SDimitry Andric #define signature_CENTAUR_ebx 0x746e6543 240b57cec5SDimitry Andric #define signature_CENTAUR_edx 0x48727561 250b57cec5SDimitry Andric #define signature_CENTAUR_ecx 0x736c7561 260b57cec5SDimitry Andric /* CYRIX: "CyrixInstead" */ 270b57cec5SDimitry Andric #define signature_CYRIX_ebx 0x69727943 280b57cec5SDimitry Andric #define signature_CYRIX_edx 0x736e4978 290b57cec5SDimitry Andric #define signature_CYRIX_ecx 0x64616574 305ffd83dbSDimitry Andric /* HYGON: "HygonGenuine" */ 315ffd83dbSDimitry Andric #define signature_HYGON_ebx 0x6f677948 325ffd83dbSDimitry Andric #define signature_HYGON_edx 0x6e65476e 335ffd83dbSDimitry Andric #define signature_HYGON_ecx 0x656e6975 340b57cec5SDimitry Andric /* INTEL: "GenuineIntel" */ 350b57cec5SDimitry Andric #define signature_INTEL_ebx 0x756e6547 360b57cec5SDimitry Andric #define signature_INTEL_edx 0x49656e69 370b57cec5SDimitry Andric #define signature_INTEL_ecx 0x6c65746e 380b57cec5SDimitry Andric /* TM1: "TransmetaCPU" */ 390b57cec5SDimitry Andric #define signature_TM1_ebx 0x6e617254 400b57cec5SDimitry Andric #define signature_TM1_edx 0x74656d73 410b57cec5SDimitry Andric #define signature_TM1_ecx 0x55504361 420b57cec5SDimitry Andric /* TM2: "GenuineTMx86" */ 430b57cec5SDimitry Andric #define signature_TM2_ebx 0x756e6547 440b57cec5SDimitry Andric #define signature_TM2_edx 0x54656e69 450b57cec5SDimitry Andric #define signature_TM2_ecx 0x3638784d 460b57cec5SDimitry Andric /* NSC: "Geode by NSC" */ 470b57cec5SDimitry Andric #define signature_NSC_ebx 0x646f6547 48a7dea167SDimitry Andric #define signature_NSC_edx 0x79622065 49a7dea167SDimitry Andric #define signature_NSC_ecx 0x43534e20 500b57cec5SDimitry Andric /* NEXGEN: "NexGenDriven" */ 510b57cec5SDimitry Andric #define signature_NEXGEN_ebx 0x4778654e 520b57cec5SDimitry Andric #define signature_NEXGEN_edx 0x72446e65 530b57cec5SDimitry Andric #define signature_NEXGEN_ecx 0x6e657669 540b57cec5SDimitry Andric /* RISE: "RiseRiseRise" */ 550b57cec5SDimitry Andric #define signature_RISE_ebx 0x65736952 560b57cec5SDimitry Andric #define signature_RISE_edx 0x65736952 570b57cec5SDimitry Andric #define signature_RISE_ecx 0x65736952 580b57cec5SDimitry Andric /* SIS: "SiS SiS SiS " */ 590b57cec5SDimitry Andric #define signature_SIS_ebx 0x20536953 600b57cec5SDimitry Andric #define signature_SIS_edx 0x20536953 610b57cec5SDimitry Andric #define signature_SIS_ecx 0x20536953 620b57cec5SDimitry Andric /* UMC: "UMC UMC UMC " */ 630b57cec5SDimitry Andric #define signature_UMC_ebx 0x20434d55 640b57cec5SDimitry Andric #define signature_UMC_edx 0x20434d55 650b57cec5SDimitry Andric #define signature_UMC_ecx 0x20434d55 660b57cec5SDimitry Andric /* VIA: "VIA VIA VIA " */ 670b57cec5SDimitry Andric #define signature_VIA_ebx 0x20414956 680b57cec5SDimitry Andric #define signature_VIA_edx 0x20414956 690b57cec5SDimitry Andric #define signature_VIA_ecx 0x20414956 700b57cec5SDimitry Andric /* VORTEX: "Vortex86 SoC" */ 710b57cec5SDimitry Andric #define signature_VORTEX_ebx 0x74726f56 720b57cec5SDimitry Andric #define signature_VORTEX_edx 0x36387865 730b57cec5SDimitry Andric #define signature_VORTEX_ecx 0x436f5320 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric /* Features in %ecx for leaf 1 */ 760b57cec5SDimitry Andric #define bit_SSE3 0x00000001 770b57cec5SDimitry Andric #define bit_PCLMULQDQ 0x00000002 780b57cec5SDimitry Andric #define bit_PCLMUL bit_PCLMULQDQ /* for gcc compat */ 790b57cec5SDimitry Andric #define bit_DTES64 0x00000004 800b57cec5SDimitry Andric #define bit_MONITOR 0x00000008 810b57cec5SDimitry Andric #define bit_DSCPL 0x00000010 820b57cec5SDimitry Andric #define bit_VMX 0x00000020 830b57cec5SDimitry Andric #define bit_SMX 0x00000040 840b57cec5SDimitry Andric #define bit_EIST 0x00000080 850b57cec5SDimitry Andric #define bit_TM2 0x00000100 860b57cec5SDimitry Andric #define bit_SSSE3 0x00000200 870b57cec5SDimitry Andric #define bit_CNXTID 0x00000400 880b57cec5SDimitry Andric #define bit_FMA 0x00001000 890b57cec5SDimitry Andric #define bit_CMPXCHG16B 0x00002000 900b57cec5SDimitry Andric #define bit_xTPR 0x00004000 910b57cec5SDimitry Andric #define bit_PDCM 0x00008000 920b57cec5SDimitry Andric #define bit_PCID 0x00020000 930b57cec5SDimitry Andric #define bit_DCA 0x00040000 940b57cec5SDimitry Andric #define bit_SSE41 0x00080000 950b57cec5SDimitry Andric #define bit_SSE4_1 bit_SSE41 /* for gcc compat */ 960b57cec5SDimitry Andric #define bit_SSE42 0x00100000 970b57cec5SDimitry Andric #define bit_SSE4_2 bit_SSE42 /* for gcc compat */ 980b57cec5SDimitry Andric #define bit_x2APIC 0x00200000 990b57cec5SDimitry Andric #define bit_MOVBE 0x00400000 1000b57cec5SDimitry Andric #define bit_POPCNT 0x00800000 1010b57cec5SDimitry Andric #define bit_TSCDeadline 0x01000000 1020b57cec5SDimitry Andric #define bit_AESNI 0x02000000 1030b57cec5SDimitry Andric #define bit_AES bit_AESNI /* for gcc compat */ 1040b57cec5SDimitry Andric #define bit_XSAVE 0x04000000 1050b57cec5SDimitry Andric #define bit_OSXSAVE 0x08000000 1060b57cec5SDimitry Andric #define bit_AVX 0x10000000 1070b57cec5SDimitry Andric #define bit_F16C 0x20000000 1080b57cec5SDimitry Andric #define bit_RDRND 0x40000000 1090b57cec5SDimitry Andric 1100b57cec5SDimitry Andric /* Features in %edx for leaf 1 */ 1110b57cec5SDimitry Andric #define bit_FPU 0x00000001 1120b57cec5SDimitry Andric #define bit_VME 0x00000002 1130b57cec5SDimitry Andric #define bit_DE 0x00000004 1140b57cec5SDimitry Andric #define bit_PSE 0x00000008 1150b57cec5SDimitry Andric #define bit_TSC 0x00000010 1160b57cec5SDimitry Andric #define bit_MSR 0x00000020 1170b57cec5SDimitry Andric #define bit_PAE 0x00000040 1180b57cec5SDimitry Andric #define bit_MCE 0x00000080 1190b57cec5SDimitry Andric #define bit_CX8 0x00000100 1200b57cec5SDimitry Andric #define bit_CMPXCHG8B bit_CX8 /* for gcc compat */ 1210b57cec5SDimitry Andric #define bit_APIC 0x00000200 1220b57cec5SDimitry Andric #define bit_SEP 0x00000800 1230b57cec5SDimitry Andric #define bit_MTRR 0x00001000 1240b57cec5SDimitry Andric #define bit_PGE 0x00002000 1250b57cec5SDimitry Andric #define bit_MCA 0x00004000 1260b57cec5SDimitry Andric #define bit_CMOV 0x00008000 1270b57cec5SDimitry Andric #define bit_PAT 0x00010000 1280b57cec5SDimitry Andric #define bit_PSE36 0x00020000 1290b57cec5SDimitry Andric #define bit_PSN 0x00040000 1300b57cec5SDimitry Andric #define bit_CLFSH 0x00080000 1310b57cec5SDimitry Andric #define bit_DS 0x00200000 1320b57cec5SDimitry Andric #define bit_ACPI 0x00400000 1330b57cec5SDimitry Andric #define bit_MMX 0x00800000 1340b57cec5SDimitry Andric #define bit_FXSR 0x01000000 1350b57cec5SDimitry Andric #define bit_FXSAVE bit_FXSR /* for gcc compat */ 1360b57cec5SDimitry Andric #define bit_SSE 0x02000000 1370b57cec5SDimitry Andric #define bit_SSE2 0x04000000 1380b57cec5SDimitry Andric #define bit_SS 0x08000000 1390b57cec5SDimitry Andric #define bit_HTT 0x10000000 1400b57cec5SDimitry Andric #define bit_TM 0x20000000 1410b57cec5SDimitry Andric #define bit_PBE 0x80000000 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andric /* Features in %ebx for leaf 7 sub-leaf 0 */ 1440b57cec5SDimitry Andric #define bit_FSGSBASE 0x00000001 1450b57cec5SDimitry Andric #define bit_SGX 0x00000004 1460b57cec5SDimitry Andric #define bit_BMI 0x00000008 1470b57cec5SDimitry Andric #define bit_HLE 0x00000010 1480b57cec5SDimitry Andric #define bit_AVX2 0x00000020 1490b57cec5SDimitry Andric #define bit_SMEP 0x00000080 1500b57cec5SDimitry Andric #define bit_BMI2 0x00000100 1510b57cec5SDimitry Andric #define bit_ENH_MOVSB 0x00000200 1520b57cec5SDimitry Andric #define bit_INVPCID 0x00000400 1530b57cec5SDimitry Andric #define bit_RTM 0x00000800 1540b57cec5SDimitry Andric #define bit_MPX 0x00004000 1550b57cec5SDimitry Andric #define bit_AVX512F 0x00010000 1560b57cec5SDimitry Andric #define bit_AVX512DQ 0x00020000 1570b57cec5SDimitry Andric #define bit_RDSEED 0x00040000 1580b57cec5SDimitry Andric #define bit_ADX 0x00080000 1590b57cec5SDimitry Andric #define bit_AVX512IFMA 0x00200000 1600b57cec5SDimitry Andric #define bit_CLFLUSHOPT 0x00800000 1610b57cec5SDimitry Andric #define bit_CLWB 0x01000000 1620b57cec5SDimitry Andric #define bit_AVX512PF 0x04000000 1630b57cec5SDimitry Andric #define bit_AVX512ER 0x08000000 1640b57cec5SDimitry Andric #define bit_AVX512CD 0x10000000 1650b57cec5SDimitry Andric #define bit_SHA 0x20000000 1660b57cec5SDimitry Andric #define bit_AVX512BW 0x40000000 1670b57cec5SDimitry Andric #define bit_AVX512VL 0x80000000 1680b57cec5SDimitry Andric 1690b57cec5SDimitry Andric /* Features in %ecx for leaf 7 sub-leaf 0 */ 1700b57cec5SDimitry Andric #define bit_PREFTCHWT1 0x00000001 1710b57cec5SDimitry Andric #define bit_AVX512VBMI 0x00000002 1720b57cec5SDimitry Andric #define bit_PKU 0x00000004 1730b57cec5SDimitry Andric #define bit_OSPKE 0x00000010 1740b57cec5SDimitry Andric #define bit_WAITPKG 0x00000020 1750b57cec5SDimitry Andric #define bit_AVX512VBMI2 0x00000040 1760b57cec5SDimitry Andric #define bit_SHSTK 0x00000080 1770b57cec5SDimitry Andric #define bit_GFNI 0x00000100 1780b57cec5SDimitry Andric #define bit_VAES 0x00000200 1790b57cec5SDimitry Andric #define bit_VPCLMULQDQ 0x00000400 1800b57cec5SDimitry Andric #define bit_AVX512VNNI 0x00000800 1810b57cec5SDimitry Andric #define bit_AVX512BITALG 0x00001000 1820b57cec5SDimitry Andric #define bit_AVX512VPOPCNTDQ 0x00004000 1830b57cec5SDimitry Andric #define bit_RDPID 0x00400000 1840b57cec5SDimitry Andric #define bit_CLDEMOTE 0x02000000 1850b57cec5SDimitry Andric #define bit_MOVDIRI 0x08000000 1860b57cec5SDimitry Andric #define bit_MOVDIR64B 0x10000000 1870b57cec5SDimitry Andric #define bit_ENQCMD 0x20000000 1880b57cec5SDimitry Andric 1890b57cec5SDimitry Andric /* Features in %edx for leaf 7 sub-leaf 0 */ 1900b57cec5SDimitry Andric #define bit_AVX5124VNNIW 0x00000004 1910b57cec5SDimitry Andric #define bit_AVX5124FMAPS 0x00000008 192e8d8bef9SDimitry Andric #define bit_UINTR 0x00000020 1935ffd83dbSDimitry Andric #define bit_SERIALIZE 0x00004000 1945ffd83dbSDimitry Andric #define bit_TSXLDTRK 0x00010000 1950b57cec5SDimitry Andric #define bit_PCONFIG 0x00040000 1960b57cec5SDimitry Andric #define bit_IBT 0x00100000 1975ffd83dbSDimitry Andric #define bit_AMXBF16 0x00400000 198349cc55cSDimitry Andric #define bit_AVX512FP16 0x00800000 1995ffd83dbSDimitry Andric #define bit_AMXTILE 0x01000000 2005ffd83dbSDimitry Andric #define bit_AMXINT8 0x02000000 2010b57cec5SDimitry Andric 2020b57cec5SDimitry Andric /* Features in %eax for leaf 7 sub-leaf 1 */ 203*0fca6ea1SDimitry Andric #define bit_SHA512 0x00000001 204*0fca6ea1SDimitry Andric #define bit_SM3 0x00000002 205*0fca6ea1SDimitry Andric #define bit_SM4 0x00000004 206bdd1243dSDimitry Andric #define bit_RAOINT 0x00000008 20704eeddc0SDimitry Andric #define bit_AVXVNNI 0x00000010 2080b57cec5SDimitry Andric #define bit_AVX512BF16 0x00000020 209bdd1243dSDimitry Andric #define bit_CMPCCXADD 0x00000080 210bdd1243dSDimitry Andric #define bit_AMXFP16 0x00200000 211e8d8bef9SDimitry Andric #define bit_HRESET 0x00400000 212bdd1243dSDimitry Andric #define bit_AVXIFMA 0x00800000 213bdd1243dSDimitry Andric 214bdd1243dSDimitry Andric /* Features in %edx for leaf 7 sub-leaf 1 */ 215bdd1243dSDimitry Andric #define bit_AVXVNNIINT8 0x00000010 216bdd1243dSDimitry Andric #define bit_AVXNECONVERT 0x00000020 217*0fca6ea1SDimitry Andric #define bit_AMXCOMPLEX 0x00000100 218*0fca6ea1SDimitry Andric #define bit_AVXVNNIINT16 0x00000400 219bdd1243dSDimitry Andric #define bit_PREFETCHI 0x00004000 220*0fca6ea1SDimitry Andric #define bit_USERMSR 0x00008000 221*0fca6ea1SDimitry Andric #define bit_AVX10 0x00080000 222*0fca6ea1SDimitry Andric #define bit_APXF 0x00200000 2230b57cec5SDimitry Andric 2240b57cec5SDimitry Andric /* Features in %eax for leaf 13 sub-leaf 1 */ 2250b57cec5SDimitry Andric #define bit_XSAVEOPT 0x00000001 2260b57cec5SDimitry Andric #define bit_XSAVEC 0x00000002 2270b57cec5SDimitry Andric #define bit_XSAVES 0x00000008 2280b57cec5SDimitry Andric 2290b57cec5SDimitry Andric /* Features in %eax for leaf 0x14 sub-leaf 0 */ 2300b57cec5SDimitry Andric #define bit_PTWRITE 0x00000010 2310b57cec5SDimitry Andric 2320b57cec5SDimitry Andric /* Features in %ecx for leaf 0x80000001 */ 2330b57cec5SDimitry Andric #define bit_LAHF_LM 0x00000001 2340b57cec5SDimitry Andric #define bit_ABM 0x00000020 2350b57cec5SDimitry Andric #define bit_LZCNT bit_ABM /* for gcc compat */ 2360b57cec5SDimitry Andric #define bit_SSE4a 0x00000040 2370b57cec5SDimitry Andric #define bit_PRFCHW 0x00000100 2380b57cec5SDimitry Andric #define bit_XOP 0x00000800 2390b57cec5SDimitry Andric #define bit_LWP 0x00008000 2400b57cec5SDimitry Andric #define bit_FMA4 0x00010000 2410b57cec5SDimitry Andric #define bit_TBM 0x00200000 2420b57cec5SDimitry Andric #define bit_MWAITX 0x20000000 2430b57cec5SDimitry Andric 2440b57cec5SDimitry Andric /* Features in %edx for leaf 0x80000001 */ 2450b57cec5SDimitry Andric #define bit_MMXEXT 0x00400000 2460b57cec5SDimitry Andric #define bit_LM 0x20000000 2470b57cec5SDimitry Andric #define bit_3DNOWP 0x40000000 2480b57cec5SDimitry Andric #define bit_3DNOW 0x80000000 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andric /* Features in %ebx for leaf 0x80000008 */ 2510b57cec5SDimitry Andric #define bit_CLZERO 0x00000001 252a4a491e2SDimitry Andric #define bit_RDPRU 0x00000010 2530b57cec5SDimitry Andric #define bit_WBNOINVD 0x00000200 2540b57cec5SDimitry Andric 255*0fca6ea1SDimitry Andric /* Features in %ebx for leaf 0x24 */ 256*0fca6ea1SDimitry Andric #define bit_AVX10_256 0x00020000 257*0fca6ea1SDimitry Andric #define bit_AVX10_512 0x00040000 2580b57cec5SDimitry Andric 259*0fca6ea1SDimitry Andric #ifdef __i386__ 2600b57cec5SDimitry Andric #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \ 2610b57cec5SDimitry Andric __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \ 2620b57cec5SDimitry Andric : "0"(__leaf)) 2630b57cec5SDimitry Andric 2640b57cec5SDimitry Andric #define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) \ 2650b57cec5SDimitry Andric __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \ 2660b57cec5SDimitry Andric : "0"(__leaf), "2"(__count)) 2670b57cec5SDimitry Andric #else 2680b57cec5SDimitry Andric /* x86-64 uses %rbx as the base register, so preserve it. */ 2690b57cec5SDimitry Andric #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \ 2700b57cec5SDimitry Andric __asm(" xchgq %%rbx,%q1\n" \ 2710b57cec5SDimitry Andric " cpuid\n" \ 2720b57cec5SDimitry Andric " xchgq %%rbx,%q1" \ 2730b57cec5SDimitry Andric : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \ 2740b57cec5SDimitry Andric : "0"(__leaf)) 2750b57cec5SDimitry Andric 2760b57cec5SDimitry Andric #define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) \ 2770b57cec5SDimitry Andric __asm(" xchgq %%rbx,%q1\n" \ 2780b57cec5SDimitry Andric " cpuid\n" \ 2790b57cec5SDimitry Andric " xchgq %%rbx,%q1" \ 2800b57cec5SDimitry Andric : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \ 2810b57cec5SDimitry Andric : "0"(__leaf), "2"(__count)) 2820b57cec5SDimitry Andric #endif 2830b57cec5SDimitry Andric 284bdd1243dSDimitry Andric static __inline unsigned int __get_cpuid_max (unsigned int __leaf, 285bdd1243dSDimitry Andric unsigned int *__sig) 2860b57cec5SDimitry Andric { 2870b57cec5SDimitry Andric unsigned int __eax, __ebx, __ecx, __edx; 288*0fca6ea1SDimitry Andric #ifdef __i386__ 2890b57cec5SDimitry Andric int __cpuid_supported; 2900b57cec5SDimitry Andric 2910b57cec5SDimitry Andric __asm(" pushfl\n" 2920b57cec5SDimitry Andric " popl %%eax\n" 2930b57cec5SDimitry Andric " movl %%eax,%%ecx\n" 2940b57cec5SDimitry Andric " xorl $0x00200000,%%eax\n" 2950b57cec5SDimitry Andric " pushl %%eax\n" 2960b57cec5SDimitry Andric " popfl\n" 2970b57cec5SDimitry Andric " pushfl\n" 2980b57cec5SDimitry Andric " popl %%eax\n" 2990b57cec5SDimitry Andric " movl $0,%0\n" 3000b57cec5SDimitry Andric " cmpl %%eax,%%ecx\n" 3010b57cec5SDimitry Andric " je 1f\n" 3020b57cec5SDimitry Andric " movl $1,%0\n" 3030b57cec5SDimitry Andric "1:" 3040b57cec5SDimitry Andric : "=r" (__cpuid_supported) : : "eax", "ecx"); 3050b57cec5SDimitry Andric if (!__cpuid_supported) 3060b57cec5SDimitry Andric return 0; 3070b57cec5SDimitry Andric #endif 3080b57cec5SDimitry Andric 3090b57cec5SDimitry Andric __cpuid(__leaf, __eax, __ebx, __ecx, __edx); 3100b57cec5SDimitry Andric if (__sig) 3110b57cec5SDimitry Andric *__sig = __ebx; 3120b57cec5SDimitry Andric return __eax; 3130b57cec5SDimitry Andric } 3140b57cec5SDimitry Andric 3150b57cec5SDimitry Andric static __inline int __get_cpuid (unsigned int __leaf, unsigned int *__eax, 3160b57cec5SDimitry Andric unsigned int *__ebx, unsigned int *__ecx, 3170b57cec5SDimitry Andric unsigned int *__edx) 3180b57cec5SDimitry Andric { 3190b57cec5SDimitry Andric unsigned int __max_leaf = __get_cpuid_max(__leaf & 0x80000000, 0); 3200b57cec5SDimitry Andric 3210b57cec5SDimitry Andric if (__max_leaf == 0 || __max_leaf < __leaf) 3220b57cec5SDimitry Andric return 0; 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andric __cpuid(__leaf, *__eax, *__ebx, *__ecx, *__edx); 3250b57cec5SDimitry Andric return 1; 3260b57cec5SDimitry Andric } 3270b57cec5SDimitry Andric 3280b57cec5SDimitry Andric static __inline int __get_cpuid_count (unsigned int __leaf, 3290b57cec5SDimitry Andric unsigned int __subleaf, 3300b57cec5SDimitry Andric unsigned int *__eax, unsigned int *__ebx, 3310b57cec5SDimitry Andric unsigned int *__ecx, unsigned int *__edx) 3320b57cec5SDimitry Andric { 3330b57cec5SDimitry Andric unsigned int __max_leaf = __get_cpuid_max(__leaf & 0x80000000, 0); 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andric if (__max_leaf == 0 || __max_leaf < __leaf) 3360b57cec5SDimitry Andric return 0; 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric __cpuid_count(__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx); 3390b57cec5SDimitry Andric return 1; 3400b57cec5SDimitry Andric } 341e8d8bef9SDimitry Andric 342*0fca6ea1SDimitry Andric // In some configurations, __cpuidex is defined as a builtin (primarily 343*0fca6ea1SDimitry Andric // -fms-extensions) which will conflict with the __cpuidex definition below. 344*0fca6ea1SDimitry Andric #if !(__has_builtin(__cpuidex)) 345*0fca6ea1SDimitry Andric static __inline void __cpuidex(int __cpu_info[4], int __leaf, int __subleaf) { 346*0fca6ea1SDimitry Andric __cpuid_count(__leaf, __subleaf, __cpu_info[0], __cpu_info[1], __cpu_info[2], 347*0fca6ea1SDimitry Andric __cpu_info[3]); 348*0fca6ea1SDimitry Andric } 349*0fca6ea1SDimitry Andric #endif 350*0fca6ea1SDimitry Andric 351e8d8bef9SDimitry Andric #endif /* __CPUID_H */ 352