Path: blob/master/tools/android-sdk/renderscript/clang-include/cpuid.h
496 views
/*===---- cpuid.h - X86 cpu model detection --------------------------------===1*2* Permission is hereby granted, free of charge, to any person obtaining a copy3* of this software and associated documentation files (the "Software"), to deal4* in the Software without restriction, including without limitation the rights5* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell6* copies of the Software, and to permit persons to whom the Software is7* furnished to do so, subject to the following conditions:8*9* The above copyright notice and this permission notice shall be included in10* all copies or substantial portions of the Software.11*12* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE15* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER16* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,17* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN18* THE SOFTWARE.19*20*===-----------------------------------------------------------------------===21*/2223#if !(__x86_64__ || __i386__)24#error this header is for x86 only25#endif2627/* Responses identification request with %eax 0 */28/* AMD: "AuthenticAMD" */29#define signature_AMD_ebx 0x6874754130#define signature_AMD_edx 0x69746e6531#define signature_AMD_ecx 0x444d416332/* CENTAUR: "CentaurHauls" */33#define signature_CENTAUR_ebx 0x746e654334#define signature_CENTAUR_edx 0x4872756135#define signature_CENTAUR_ecx 0x736c756136/* CYRIX: "CyrixInstead" */37#define signature_CYRIX_ebx 0x6972794338#define signature_CYRIX_edx 0x736e497839#define signature_CYRIX_ecx 0x6461657440/* INTEL: "GenuineIntel" */41#define signature_INTEL_ebx 0x756e654742#define signature_INTEL_edx 0x49656e6943#define signature_INTEL_ecx 0x6c65746e44/* TM1: "TransmetaCPU" */45#define signature_TM1_ebx 0x6e61725446#define signature_TM1_edx 0x74656d7347#define signature_TM1_ecx 0x5550436148/* TM2: "GenuineTMx86" */49#define signature_TM2_ebx 0x756e654750#define signature_TM2_edx 0x54656e6951#define signature_TM2_ecx 0x3638784d52/* NSC: "Geode by NSC" */53#define signature_NSC_ebx 0x646f654754#define signature_NSC_edx 0x43534e2055#define signature_NSC_ecx 0x7962206556/* NEXGEN: "NexGenDriven" */57#define signature_NEXGEN_ebx 0x4778654e58#define signature_NEXGEN_edx 0x72446e6559#define signature_NEXGEN_ecx 0x6e65766960/* RISE: "RiseRiseRise" */61#define signature_RISE_ebx 0x6573695262#define signature_RISE_edx 0x6573695263#define signature_RISE_ecx 0x6573695264/* SIS: "SiS SiS SiS " */65#define signature_SIS_ebx 0x2053695366#define signature_SIS_edx 0x2053695367#define signature_SIS_ecx 0x2053695368/* UMC: "UMC UMC UMC " */69#define signature_UMC_ebx 0x20434d5570#define signature_UMC_edx 0x20434d5571#define signature_UMC_ecx 0x20434d5572/* VIA: "VIA VIA VIA " */73#define signature_VIA_ebx 0x2041495674#define signature_VIA_edx 0x2041495675#define signature_VIA_ecx 0x2041495676/* VORTEX: "Vortex86 SoC" */77#define signature_VORTEX_ebx 0x74726f5678#define signature_VORTEX_edx 0x3638786579#define signature_VORTEX_ecx 0x436f53208081/* Features in %ecx for level 1 */82#define bit_SSE3 0x0000000183#define bit_PCLMULQDQ 0x0000000284#define bit_DTES64 0x0000000485#define bit_MONITOR 0x0000000886#define bit_DSCPL 0x0000001087#define bit_VMX 0x0000002088#define bit_SMX 0x0000004089#define bit_EIST 0x0000008090#define bit_TM2 0x0000010091#define bit_SSSE3 0x0000020092#define bit_CNXTID 0x0000040093#define bit_FMA 0x0000100094#define bit_CMPXCHG16B 0x0000200095#define bit_xTPR 0x0000400096#define bit_PDCM 0x0000800097#define bit_PCID 0x0002000098#define bit_DCA 0x0004000099#define bit_SSE41 0x00080000100#define bit_SSE42 0x00100000101#define bit_x2APIC 0x00200000102#define bit_MOVBE 0x00400000103#define bit_POPCNT 0x00800000104#define bit_TSCDeadline 0x01000000105#define bit_AESNI 0x02000000106#define bit_XSAVE 0x04000000107#define bit_OSXSAVE 0x08000000108#define bit_AVX 0x10000000109#define bit_RDRND 0x40000000110111/* Features in %edx for level 1 */112#define bit_FPU 0x00000001113#define bit_VME 0x00000002114#define bit_DE 0x00000004115#define bit_PSE 0x00000008116#define bit_TSC 0x00000010117#define bit_MSR 0x00000020118#define bit_PAE 0x00000040119#define bit_MCE 0x00000080120#define bit_CX8 0x00000100121#define bit_APIC 0x00000200122#define bit_SEP 0x00000800123#define bit_MTRR 0x00001000124#define bit_PGE 0x00002000125#define bit_MCA 0x00004000126#define bit_CMOV 0x00008000127#define bit_PAT 0x00010000128#define bit_PSE36 0x00020000129#define bit_PSN 0x00040000130#define bit_CLFSH 0x00080000131#define bit_DS 0x00200000132#define bit_ACPI 0x00400000133#define bit_MMX 0x00800000134#define bit_FXSR 0x01000000135#define bit_FXSAVE bit_FXSR /* for gcc compat */136#define bit_SSE 0x02000000137#define bit_SSE2 0x04000000138#define bit_SS 0x08000000139#define bit_HTT 0x10000000140#define bit_TM 0x20000000141#define bit_PBE 0x80000000142143/* Features in %ebx for level 7 sub-leaf 0 */144#define bit_FSGSBASE 0x00000001145#define bit_SMEP 0x00000080146#define bit_ENH_MOVSB 0x00000200147148#if __i386__149#define __cpuid(__level, __eax, __ebx, __ecx, __edx) \150__asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \151: "0"(__level))152153#define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \154__asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \155: "0"(__level), "2"(__count))156#else157/* x86-64 uses %rbx as the base register, so preserve it. */158#define __cpuid(__level, __eax, __ebx, __ecx, __edx) \159__asm(" xchgq %%rbx,%q1\n" \160" cpuid\n" \161" xchgq %%rbx,%q1" \162: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \163: "0"(__level))164165#define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \166__asm(" xchgq %%rbx,%q1\n" \167" cpuid\n" \168" xchgq %%rbx,%q1" \169: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \170: "0"(__level), "2"(__count))171#endif172173static __inline int __get_cpuid (unsigned int __level, unsigned int *__eax,174unsigned int *__ebx, unsigned int *__ecx,175unsigned int *__edx) {176__cpuid(__level, *__eax, *__ebx, *__ecx, *__edx);177return 1;178}179180static __inline int __get_cpuid_max (unsigned int __level, unsigned int *__sig)181{182unsigned int __eax, __ebx, __ecx, __edx;183#if __i386__184int __cpuid_supported;185186__asm(" pushfl\n"187" popl %%eax\n"188" movl %%eax,%%ecx\n"189" xorl $0x00200000,%%eax\n"190" pushl %%eax\n"191" popfl\n"192" pushfl\n"193" popl %%eax\n"194" movl $0,%0\n"195" cmpl %%eax,%%ecx\n"196" je 1f\n"197" movl $1,%0\n"198"1:"199: "=r" (__cpuid_supported) : : "eax", "ecx");200if (!__cpuid_supported)201return 0;202#endif203204__cpuid(__level, __eax, __ebx, __ecx, __edx);205if (__sig)206*__sig = __ebx;207return __eax;208}209210211