xref: /aosp_15_r20/prebuilts/sdk/renderscript/clang-include/cpuid.h (revision 344a7f5ef16c479e7a7f54ee6567a9d112f9e72b)
1*344a7f5eSAndroid Build Coastguard Worker /*===---- cpuid.h - X86 cpu model detection --------------------------------===
2*344a7f5eSAndroid Build Coastguard Worker  *
3*344a7f5eSAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a copy
4*344a7f5eSAndroid Build Coastguard Worker  * of this software and associated documentation files (the "Software"), to deal
5*344a7f5eSAndroid Build Coastguard Worker  * in the Software without restriction, including without limitation the rights
6*344a7f5eSAndroid Build Coastguard Worker  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*344a7f5eSAndroid Build Coastguard Worker  * copies of the Software, and to permit persons to whom the Software is
8*344a7f5eSAndroid Build Coastguard Worker  * furnished to do so, subject to the following conditions:
9*344a7f5eSAndroid Build Coastguard Worker  *
10*344a7f5eSAndroid Build Coastguard Worker  * The above copyright notice and this permission notice shall be included in
11*344a7f5eSAndroid Build Coastguard Worker  * all copies or substantial portions of the Software.
12*344a7f5eSAndroid Build Coastguard Worker  *
13*344a7f5eSAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*344a7f5eSAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*344a7f5eSAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16*344a7f5eSAndroid Build Coastguard Worker  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17*344a7f5eSAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18*344a7f5eSAndroid Build Coastguard Worker  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19*344a7f5eSAndroid Build Coastguard Worker  * THE SOFTWARE.
20*344a7f5eSAndroid Build Coastguard Worker  *
21*344a7f5eSAndroid Build Coastguard Worker  *===-----------------------------------------------------------------------===
22*344a7f5eSAndroid Build Coastguard Worker  */
23*344a7f5eSAndroid Build Coastguard Worker 
24*344a7f5eSAndroid Build Coastguard Worker #if !(__x86_64__ || __i386__)
25*344a7f5eSAndroid Build Coastguard Worker #error this header is for x86 only
26*344a7f5eSAndroid Build Coastguard Worker #endif
27*344a7f5eSAndroid Build Coastguard Worker 
28*344a7f5eSAndroid Build Coastguard Worker /* Responses identification request with %eax 0 */
29*344a7f5eSAndroid Build Coastguard Worker /* AMD:     "AuthenticAMD" */
30*344a7f5eSAndroid Build Coastguard Worker #define signature_AMD_ebx 0x68747541
31*344a7f5eSAndroid Build Coastguard Worker #define signature_AMD_edx 0x69746e65
32*344a7f5eSAndroid Build Coastguard Worker #define signature_AMD_ecx 0x444d4163
33*344a7f5eSAndroid Build Coastguard Worker /* CENTAUR: "CentaurHauls" */
34*344a7f5eSAndroid Build Coastguard Worker #define signature_CENTAUR_ebx 0x746e6543
35*344a7f5eSAndroid Build Coastguard Worker #define signature_CENTAUR_edx 0x48727561
36*344a7f5eSAndroid Build Coastguard Worker #define signature_CENTAUR_ecx 0x736c7561
37*344a7f5eSAndroid Build Coastguard Worker /* CYRIX:   "CyrixInstead" */
38*344a7f5eSAndroid Build Coastguard Worker #define signature_CYRIX_ebx 0x69727943
39*344a7f5eSAndroid Build Coastguard Worker #define signature_CYRIX_edx 0x736e4978
40*344a7f5eSAndroid Build Coastguard Worker #define signature_CYRIX_ecx 0x64616574
41*344a7f5eSAndroid Build Coastguard Worker /* INTEL:   "GenuineIntel" */
42*344a7f5eSAndroid Build Coastguard Worker #define signature_INTEL_ebx 0x756e6547
43*344a7f5eSAndroid Build Coastguard Worker #define signature_INTEL_edx 0x49656e69
44*344a7f5eSAndroid Build Coastguard Worker #define signature_INTEL_ecx 0x6c65746e
45*344a7f5eSAndroid Build Coastguard Worker /* TM1:     "TransmetaCPU" */
46*344a7f5eSAndroid Build Coastguard Worker #define signature_TM1_ebx 0x6e617254
47*344a7f5eSAndroid Build Coastguard Worker #define signature_TM1_edx 0x74656d73
48*344a7f5eSAndroid Build Coastguard Worker #define signature_TM1_ecx 0x55504361
49*344a7f5eSAndroid Build Coastguard Worker /* TM2:     "GenuineTMx86" */
50*344a7f5eSAndroid Build Coastguard Worker #define signature_TM2_ebx 0x756e6547
51*344a7f5eSAndroid Build Coastguard Worker #define signature_TM2_edx 0x54656e69
52*344a7f5eSAndroid Build Coastguard Worker #define signature_TM2_ecx 0x3638784d
53*344a7f5eSAndroid Build Coastguard Worker /* NSC:     "Geode by NSC" */
54*344a7f5eSAndroid Build Coastguard Worker #define signature_NSC_ebx 0x646f6547
55*344a7f5eSAndroid Build Coastguard Worker #define signature_NSC_edx 0x43534e20
56*344a7f5eSAndroid Build Coastguard Worker #define signature_NSC_ecx 0x79622065
57*344a7f5eSAndroid Build Coastguard Worker /* NEXGEN:  "NexGenDriven" */
58*344a7f5eSAndroid Build Coastguard Worker #define signature_NEXGEN_ebx 0x4778654e
59*344a7f5eSAndroid Build Coastguard Worker #define signature_NEXGEN_edx 0x72446e65
60*344a7f5eSAndroid Build Coastguard Worker #define signature_NEXGEN_ecx 0x6e657669
61*344a7f5eSAndroid Build Coastguard Worker /* RISE:    "RiseRiseRise" */
62*344a7f5eSAndroid Build Coastguard Worker #define signature_RISE_ebx 0x65736952
63*344a7f5eSAndroid Build Coastguard Worker #define signature_RISE_edx 0x65736952
64*344a7f5eSAndroid Build Coastguard Worker #define signature_RISE_ecx 0x65736952
65*344a7f5eSAndroid Build Coastguard Worker /* SIS:     "SiS SiS SiS " */
66*344a7f5eSAndroid Build Coastguard Worker #define signature_SIS_ebx 0x20536953
67*344a7f5eSAndroid Build Coastguard Worker #define signature_SIS_edx 0x20536953
68*344a7f5eSAndroid Build Coastguard Worker #define signature_SIS_ecx 0x20536953
69*344a7f5eSAndroid Build Coastguard Worker /* UMC:     "UMC UMC UMC " */
70*344a7f5eSAndroid Build Coastguard Worker #define signature_UMC_ebx 0x20434d55
71*344a7f5eSAndroid Build Coastguard Worker #define signature_UMC_edx 0x20434d55
72*344a7f5eSAndroid Build Coastguard Worker #define signature_UMC_ecx 0x20434d55
73*344a7f5eSAndroid Build Coastguard Worker /* VIA:     "VIA VIA VIA " */
74*344a7f5eSAndroid Build Coastguard Worker #define signature_VIA_ebx 0x20414956
75*344a7f5eSAndroid Build Coastguard Worker #define signature_VIA_edx 0x20414956
76*344a7f5eSAndroid Build Coastguard Worker #define signature_VIA_ecx 0x20414956
77*344a7f5eSAndroid Build Coastguard Worker /* VORTEX:  "Vortex86 SoC" */
78*344a7f5eSAndroid Build Coastguard Worker #define signature_VORTEX_ebx 0x74726f56
79*344a7f5eSAndroid Build Coastguard Worker #define signature_VORTEX_edx 0x36387865
80*344a7f5eSAndroid Build Coastguard Worker #define signature_VORTEX_ecx 0x436f5320
81*344a7f5eSAndroid Build Coastguard Worker 
82*344a7f5eSAndroid Build Coastguard Worker /* Features in %ecx for level 1 */
83*344a7f5eSAndroid Build Coastguard Worker #define bit_SSE3        0x00000001
84*344a7f5eSAndroid Build Coastguard Worker #define bit_PCLMULQDQ   0x00000002
85*344a7f5eSAndroid Build Coastguard Worker #define bit_DTES64      0x00000004
86*344a7f5eSAndroid Build Coastguard Worker #define bit_MONITOR     0x00000008
87*344a7f5eSAndroid Build Coastguard Worker #define bit_DSCPL       0x00000010
88*344a7f5eSAndroid Build Coastguard Worker #define bit_VMX         0x00000020
89*344a7f5eSAndroid Build Coastguard Worker #define bit_SMX         0x00000040
90*344a7f5eSAndroid Build Coastguard Worker #define bit_EIST        0x00000080
91*344a7f5eSAndroid Build Coastguard Worker #define bit_TM2         0x00000100
92*344a7f5eSAndroid Build Coastguard Worker #define bit_SSSE3       0x00000200
93*344a7f5eSAndroid Build Coastguard Worker #define bit_CNXTID      0x00000400
94*344a7f5eSAndroid Build Coastguard Worker #define bit_FMA         0x00001000
95*344a7f5eSAndroid Build Coastguard Worker #define bit_CMPXCHG16B  0x00002000
96*344a7f5eSAndroid Build Coastguard Worker #define bit_xTPR        0x00004000
97*344a7f5eSAndroid Build Coastguard Worker #define bit_PDCM        0x00008000
98*344a7f5eSAndroid Build Coastguard Worker #define bit_PCID        0x00020000
99*344a7f5eSAndroid Build Coastguard Worker #define bit_DCA         0x00040000
100*344a7f5eSAndroid Build Coastguard Worker #define bit_SSE41       0x00080000
101*344a7f5eSAndroid Build Coastguard Worker #define bit_SSE42       0x00100000
102*344a7f5eSAndroid Build Coastguard Worker #define bit_x2APIC      0x00200000
103*344a7f5eSAndroid Build Coastguard Worker #define bit_MOVBE       0x00400000
104*344a7f5eSAndroid Build Coastguard Worker #define bit_POPCNT      0x00800000
105*344a7f5eSAndroid Build Coastguard Worker #define bit_TSCDeadline 0x01000000
106*344a7f5eSAndroid Build Coastguard Worker #define bit_AESNI       0x02000000
107*344a7f5eSAndroid Build Coastguard Worker #define bit_XSAVE       0x04000000
108*344a7f5eSAndroid Build Coastguard Worker #define bit_OSXSAVE     0x08000000
109*344a7f5eSAndroid Build Coastguard Worker #define bit_AVX         0x10000000
110*344a7f5eSAndroid Build Coastguard Worker #define bit_RDRND       0x40000000
111*344a7f5eSAndroid Build Coastguard Worker 
112*344a7f5eSAndroid Build Coastguard Worker /* Features in %edx for level 1 */
113*344a7f5eSAndroid Build Coastguard Worker #define bit_FPU         0x00000001
114*344a7f5eSAndroid Build Coastguard Worker #define bit_VME         0x00000002
115*344a7f5eSAndroid Build Coastguard Worker #define bit_DE          0x00000004
116*344a7f5eSAndroid Build Coastguard Worker #define bit_PSE         0x00000008
117*344a7f5eSAndroid Build Coastguard Worker #define bit_TSC         0x00000010
118*344a7f5eSAndroid Build Coastguard Worker #define bit_MSR         0x00000020
119*344a7f5eSAndroid Build Coastguard Worker #define bit_PAE         0x00000040
120*344a7f5eSAndroid Build Coastguard Worker #define bit_MCE         0x00000080
121*344a7f5eSAndroid Build Coastguard Worker #define bit_CX8         0x00000100
122*344a7f5eSAndroid Build Coastguard Worker #define bit_APIC        0x00000200
123*344a7f5eSAndroid Build Coastguard Worker #define bit_SEP         0x00000800
124*344a7f5eSAndroid Build Coastguard Worker #define bit_MTRR        0x00001000
125*344a7f5eSAndroid Build Coastguard Worker #define bit_PGE         0x00002000
126*344a7f5eSAndroid Build Coastguard Worker #define bit_MCA         0x00004000
127*344a7f5eSAndroid Build Coastguard Worker #define bit_CMOV        0x00008000
128*344a7f5eSAndroid Build Coastguard Worker #define bit_PAT         0x00010000
129*344a7f5eSAndroid Build Coastguard Worker #define bit_PSE36       0x00020000
130*344a7f5eSAndroid Build Coastguard Worker #define bit_PSN         0x00040000
131*344a7f5eSAndroid Build Coastguard Worker #define bit_CLFSH       0x00080000
132*344a7f5eSAndroid Build Coastguard Worker #define bit_DS          0x00200000
133*344a7f5eSAndroid Build Coastguard Worker #define bit_ACPI        0x00400000
134*344a7f5eSAndroid Build Coastguard Worker #define bit_MMX         0x00800000
135*344a7f5eSAndroid Build Coastguard Worker #define bit_FXSR        0x01000000
136*344a7f5eSAndroid Build Coastguard Worker #define bit_FXSAVE      bit_FXSR    /* for gcc compat */
137*344a7f5eSAndroid Build Coastguard Worker #define bit_SSE         0x02000000
138*344a7f5eSAndroid Build Coastguard Worker #define bit_SSE2        0x04000000
139*344a7f5eSAndroid Build Coastguard Worker #define bit_SS          0x08000000
140*344a7f5eSAndroid Build Coastguard Worker #define bit_HTT         0x10000000
141*344a7f5eSAndroid Build Coastguard Worker #define bit_TM          0x20000000
142*344a7f5eSAndroid Build Coastguard Worker #define bit_PBE         0x80000000
143*344a7f5eSAndroid Build Coastguard Worker 
144*344a7f5eSAndroid Build Coastguard Worker /* Features in %ebx for level 7 sub-leaf 0 */
145*344a7f5eSAndroid Build Coastguard Worker #define bit_FSGSBASE    0x00000001
146*344a7f5eSAndroid Build Coastguard Worker #define bit_SMEP        0x00000080
147*344a7f5eSAndroid Build Coastguard Worker #define bit_ENH_MOVSB   0x00000200
148*344a7f5eSAndroid Build Coastguard Worker 
149*344a7f5eSAndroid Build Coastguard Worker #if __i386__
150*344a7f5eSAndroid Build Coastguard Worker #define __cpuid(__level, __eax, __ebx, __ecx, __edx) \
151*344a7f5eSAndroid Build Coastguard Worker     __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \
152*344a7f5eSAndroid Build Coastguard Worker                   : "0"(__level))
153*344a7f5eSAndroid Build Coastguard Worker 
154*344a7f5eSAndroid Build Coastguard Worker #define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \
155*344a7f5eSAndroid Build Coastguard Worker     __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \
156*344a7f5eSAndroid Build Coastguard Worker                   : "0"(__level), "2"(__count))
157*344a7f5eSAndroid Build Coastguard Worker #else
158*344a7f5eSAndroid Build Coastguard Worker /* x86-64 uses %rbx as the base register, so preserve it. */
159*344a7f5eSAndroid Build Coastguard Worker #define __cpuid(__level, __eax, __ebx, __ecx, __edx) \
160*344a7f5eSAndroid Build Coastguard Worker     __asm("  xchgq  %%rbx,%q1\n" \
161*344a7f5eSAndroid Build Coastguard Worker           "  cpuid\n" \
162*344a7f5eSAndroid Build Coastguard Worker           "  xchgq  %%rbx,%q1" \
163*344a7f5eSAndroid Build Coastguard Worker         : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
164*344a7f5eSAndroid Build Coastguard Worker         : "0"(__level))
165*344a7f5eSAndroid Build Coastguard Worker 
166*344a7f5eSAndroid Build Coastguard Worker #define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \
167*344a7f5eSAndroid Build Coastguard Worker     __asm("  xchgq  %%rbx,%q1\n" \
168*344a7f5eSAndroid Build Coastguard Worker           "  cpuid\n" \
169*344a7f5eSAndroid Build Coastguard Worker           "  xchgq  %%rbx,%q1" \
170*344a7f5eSAndroid Build Coastguard Worker         : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
171*344a7f5eSAndroid Build Coastguard Worker         : "0"(__level), "2"(__count))
172*344a7f5eSAndroid Build Coastguard Worker #endif
173*344a7f5eSAndroid Build Coastguard Worker 
__get_cpuid(unsigned int __level,unsigned int * __eax,unsigned int * __ebx,unsigned int * __ecx,unsigned int * __edx)174*344a7f5eSAndroid Build Coastguard Worker static __inline int __get_cpuid (unsigned int __level, unsigned int *__eax,
175*344a7f5eSAndroid Build Coastguard Worker                                  unsigned int *__ebx, unsigned int *__ecx,
176*344a7f5eSAndroid Build Coastguard Worker                                  unsigned int *__edx) {
177*344a7f5eSAndroid Build Coastguard Worker     __cpuid(__level, *__eax, *__ebx, *__ecx, *__edx);
178*344a7f5eSAndroid Build Coastguard Worker     return 1;
179*344a7f5eSAndroid Build Coastguard Worker }
180*344a7f5eSAndroid Build Coastguard Worker 
__get_cpuid_max(unsigned int __level,unsigned int * __sig)181*344a7f5eSAndroid Build Coastguard Worker static __inline int __get_cpuid_max (unsigned int __level, unsigned int *__sig)
182*344a7f5eSAndroid Build Coastguard Worker {
183*344a7f5eSAndroid Build Coastguard Worker     unsigned int __eax, __ebx, __ecx, __edx;
184*344a7f5eSAndroid Build Coastguard Worker #if __i386__
185*344a7f5eSAndroid Build Coastguard Worker     int __cpuid_supported;
186*344a7f5eSAndroid Build Coastguard Worker 
187*344a7f5eSAndroid Build Coastguard Worker     __asm("  pushfl\n"
188*344a7f5eSAndroid Build Coastguard Worker           "  popl   %%eax\n"
189*344a7f5eSAndroid Build Coastguard Worker           "  movl   %%eax,%%ecx\n"
190*344a7f5eSAndroid Build Coastguard Worker           "  xorl   $0x00200000,%%eax\n"
191*344a7f5eSAndroid Build Coastguard Worker           "  pushl  %%eax\n"
192*344a7f5eSAndroid Build Coastguard Worker           "  popfl\n"
193*344a7f5eSAndroid Build Coastguard Worker           "  pushfl\n"
194*344a7f5eSAndroid Build Coastguard Worker           "  popl   %%eax\n"
195*344a7f5eSAndroid Build Coastguard Worker           "  movl   $0,%0\n"
196*344a7f5eSAndroid Build Coastguard Worker           "  cmpl   %%eax,%%ecx\n"
197*344a7f5eSAndroid Build Coastguard Worker           "  je     1f\n"
198*344a7f5eSAndroid Build Coastguard Worker           "  movl   $1,%0\n"
199*344a7f5eSAndroid Build Coastguard Worker           "1:"
200*344a7f5eSAndroid Build Coastguard Worker         : "=r" (__cpuid_supported) : : "eax", "ecx");
201*344a7f5eSAndroid Build Coastguard Worker     if (!__cpuid_supported)
202*344a7f5eSAndroid Build Coastguard Worker         return 0;
203*344a7f5eSAndroid Build Coastguard Worker #endif
204*344a7f5eSAndroid Build Coastguard Worker 
205*344a7f5eSAndroid Build Coastguard Worker     __cpuid(__level, __eax, __ebx, __ecx, __edx);
206*344a7f5eSAndroid Build Coastguard Worker     if (__sig)
207*344a7f5eSAndroid Build Coastguard Worker         *__sig = __ebx;
208*344a7f5eSAndroid Build Coastguard Worker     return __eax;
209*344a7f5eSAndroid Build Coastguard Worker }
210