Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.5/simd-support/x86-cpuid.h @ 42:2cd0e3b3e1fd
Current fftw source
author | Chris Cannam |
---|---|
date | Tue, 18 Oct 2016 13:40:26 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
41:481f5f8c5634 | 42:2cd0e3b3e1fd |
---|---|
1 /* | |
2 * Copyright (c) 2003, 2007-14 Matteo Frigo | |
3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; either version 2 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 * | |
19 */ | |
20 | |
21 | |
22 /* this code was kindly donated by Eric J. Korpela */ | |
23 | |
24 #ifdef _MSC_VER | |
25 #ifndef inline | |
26 #define inline __inline | |
27 #endif | |
28 #endif | |
29 | |
30 static inline int is_386() | |
31 { | |
32 #ifdef _MSC_VER | |
33 unsigned int result,tst; | |
34 _asm { | |
35 pushfd | |
36 pop eax | |
37 mov edx,eax | |
38 xor eax,40000h | |
39 push eax | |
40 popfd | |
41 pushfd | |
42 pop eax | |
43 push edx | |
44 popfd | |
45 mov tst,edx | |
46 mov result,eax | |
47 } | |
48 #else | |
49 register unsigned int result,tst; | |
50 __asm__ ( | |
51 "pushfl\n\t" | |
52 "popl %0\n\t" | |
53 "movl %0,%1\n\t" | |
54 "xorl $0x40000,%0\n\t" | |
55 "pushl %0\n\t" | |
56 "popfl\n\t" | |
57 "pushfl\n\t" | |
58 "popl %0\n\t" | |
59 "pushl %1\n\t" | |
60 "popfl" | |
61 : "=r" (result), "=r" (tst) /* output */ | |
62 : /* no inputs */ | |
63 ); | |
64 #endif | |
65 return (result == tst); | |
66 } | |
67 | |
68 static inline int has_cpuid() | |
69 { | |
70 #ifdef _MSC_VER | |
71 unsigned int result,tst; | |
72 _asm { | |
73 pushfd | |
74 pop eax | |
75 mov edx,eax | |
76 xor eax,200000h | |
77 push eax | |
78 popfd | |
79 pushfd | |
80 pop eax | |
81 push edx | |
82 popfd | |
83 mov tst,edx | |
84 mov result,eax | |
85 } | |
86 #else | |
87 register unsigned int result,tst; | |
88 __asm__ ( | |
89 "pushfl\n\t" | |
90 "pop %0\n\t" | |
91 "movl %0,%1\n\t" | |
92 "xorl $0x200000,%0\n\t" | |
93 "pushl %0\n\t" | |
94 "popfl\n\t" | |
95 "pushfl\n\t" | |
96 "popl %0\n\t" | |
97 "pushl %1\n\t" | |
98 "popfl" | |
99 : "=r" (result), "=r" (tst) /* output */ | |
100 : /* no inputs */ | |
101 ); | |
102 #endif | |
103 return (result != tst); | |
104 } | |
105 | |
106 /* cpuid version to get all registers. Donated by Erik Lindahl from Gromacs. */ | |
107 static inline void | |
108 cpuid_all(int level, int ecxval, int *eax, int *ebx, int *ecx, int *edx) | |
109 { | |
110 #if (defined _MSC_VER) | |
111 int CPUInfo[4]; | |
112 | |
113 # if (_MSC_VER > 1500) || (_MSC_VER == 1500 & _MSC_FULL_VER >= 150030729) | |
114 /* MSVC 9.0 SP1 or later */ | |
115 __cpuidex(CPUInfo, level, ecxval); | |
116 rc = 0; | |
117 # else | |
118 __cpuid(CPUInfo, level); | |
119 /* Set an error code if the user wanted a non-zero ecxval, since we did not have cpuidex */ | |
120 rc = (ecxval > 0) ? -1 : 0; | |
121 # endif | |
122 *eax = CPUInfo[0]; | |
123 *ebx = CPUInfo[1]; | |
124 *ecx = CPUInfo[2]; | |
125 *edx = CPUInfo[3]; | |
126 | |
127 #else | |
128 /* Not MSVC */ | |
129 *eax = level; | |
130 *ecx = ecxval; | |
131 *ebx = 0; | |
132 *edx = 0; | |
133 /* Avoid clobbering global offset table in 32-bit pic code (ebx) */ | |
134 # if defined(__PIC__) | |
135 __asm__ ("xchgl %%ebx, %1 \n\t" | |
136 "cpuid \n\t" | |
137 "xchgl %%ebx, %1 \n\t" | |
138 : "+a" (*eax), "+r" (*ebx), "+c" (*ecx), "+d" (*edx)); | |
139 # else | |
140 /* No need to save ebx if we are not in pic mode */ | |
141 __asm__ ("cpuid \n\t" | |
142 : "+a" (*eax), "+b" (*ebx), "+c" (*ecx), "+d" (*edx)); | |
143 # endif | |
144 #endif | |
145 } | |
146 | |
147 static inline int cpuid_edx(int op) | |
148 { | |
149 # ifdef _MSC_VER | |
150 int result; | |
151 _asm { | |
152 push ebx | |
153 mov eax,op | |
154 cpuid | |
155 mov result,edx | |
156 pop ebx | |
157 } | |
158 return result; | |
159 # else | |
160 int eax, ecx, edx; | |
161 | |
162 __asm__("push %%ebx\n\tcpuid\n\tpop %%ebx" | |
163 : "=a" (eax), "=c" (ecx), "=d" (edx) | |
164 : "a" (op)); | |
165 return edx; | |
166 # endif | |
167 } | |
168 | |
169 static inline int cpuid_ecx(int op) | |
170 { | |
171 # ifdef _MSC_VER | |
172 int result; | |
173 _asm { | |
174 push ebx | |
175 mov eax,op | |
176 cpuid | |
177 mov result,ecx | |
178 pop ebx | |
179 } | |
180 return result; | |
181 # else | |
182 int eax, ecx, edx; | |
183 | |
184 __asm__("push %%ebx\n\tcpuid\n\tpop %%ebx" | |
185 : "=a" (eax), "=c" (ecx), "=d" (edx) | |
186 : "a" (op)); | |
187 return ecx; | |
188 # endif | |
189 } | |
190 | |
191 static inline int xgetbv_eax(int op) | |
192 { | |
193 # ifdef _MSC_VER | |
194 int veax, vedx; | |
195 _asm { | |
196 mov ecx,op | |
197 # if defined(__INTEL_COMPILER) || (_MSC_VER >= 1600) | |
198 xgetbv | |
199 # else | |
200 __emit 15 | |
201 __emit 1 | |
202 __emit 208 | |
203 # endif | |
204 mov veax,eax | |
205 mov vedx,edx | |
206 } | |
207 return veax; | |
208 # else | |
209 int eax, edx; | |
210 __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c" (op)); | |
211 return eax; | |
212 #endif | |
213 } |