comparison src/cpuinfo/SDL_cpuinfo.c @ 3499:4cf8a1423d57

Reduced the push/pop sequence to a single pair, and ported this fix over to the other architectures.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 30 Nov 2009 21:04:25 +0000
parents a4ce84c4f211
children d94e331e85fa
comparison
equal deleted inserted replaced
3498:a4ce84c4f211 3499:4cf8a1423d57
151 { 151 {
152 int features = 0; 152 int features = 0;
153 /* *INDENT-OFF* */ 153 /* *INDENT-OFF* */
154 #if defined(__GNUC__) && defined(i386) 154 #if defined(__GNUC__) && defined(i386)
155 __asm__ ( 155 __asm__ (
156 " pushl %%ebx\n"
157 " xorl %%eax,%%eax # Set up for CPUID instruction \n" 156 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
157 " pushl %%ebx \n"
158 " cpuid # Get and save vendor ID \n" 158 " cpuid # Get and save vendor ID \n"
159 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" 159 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
160 " jl 1f # We dont have the CPUID instruction\n" 160 " jl 1f # We dont have the CPUID instruction\n"
161 " xorl %%eax,%%eax \n" 161 " xorl %%eax,%%eax \n"
162 " incl %%eax \n" 162 " incl %%eax \n"
163 " cpuid # Get family/model/stepping/features\n" 163 " cpuid # Get family/model/stepping/features\n"
164 " popl %%ebx \n"
164 " movl %%edx,%0 \n" 165 " movl %%edx,%0 \n"
165 "1: \n" 166 "1: \n"
166 " popl %%ebx\n"
167 : "=m" (features) 167 : "=m" (features)
168 : 168 :
169 : "%eax", "%ecx", "%edx" 169 : "%eax", "%ecx", "%edx"
170 ); 170 );
171 #elif defined(__GNUC__) && defined(__x86_64__) 171 #elif defined(__GNUC__) && defined(__x86_64__)
172 __asm__ ( 172 __asm__ (
173 " xorl %%eax,%%eax # Set up for CPUID instruction \n" 173 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
174 " pushq %%rbx\n" 174 " pushq %%rbx\n"
175 " cpuid # Get and save vendor ID \n" 175 " cpuid # Get and save vendor ID \n"
176 " popq %%rbx\n"
177 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" 176 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
178 " jl 1f # We dont have the CPUID instruction\n" 177 " jl 1f # We dont have the CPUID instruction\n"
179 " xorl %%eax,%%eax \n" 178 " xorl %%eax,%%eax \n"
180 " incl %%eax \n" 179 " incl %%eax \n"
181 " pushq %%rbx\n"
182 " cpuid # Get family/model/stepping/features\n" 180 " cpuid # Get family/model/stepping/features\n"
183 " popq %%rbx\n" 181 " popq %%rbx\n"
184 " movl %%edx,%0 \n" 182 " movl %%edx,%0 \n"
185 "1: \n" 183 "1: \n"
186 : "=m" (features) 184 : "=m" (features)
188 : "%rax", "%rcx", "%rdx" 186 : "%rax", "%rcx", "%rdx"
189 ); 187 );
190 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 188 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
191 __asm { 189 __asm {
192 xor eax, eax ; Set up for CPUID instruction 190 xor eax, eax ; Set up for CPUID instruction
191 push ebx
193 cpuid ; Get and save vendor ID 192 cpuid ; Get and save vendor ID
194 cmp eax, 1 ; Make sure 1 is valid input for CPUID 193 cmp eax, 1 ; Make sure 1 is valid input for CPUID
195 jl done ; We dont have the CPUID instruction 194 jl done ; We dont have the CPUID instruction
196 xor eax, eax 195 xor eax, eax
197 inc eax 196 inc eax
198 cpuid ; Get family/model/stepping/features 197 cpuid ; Get family/model/stepping/features
198 pop ebx
199 mov features, edx 199 mov features, edx
200 done: 200 done:
201 } 201 }
202 #elif defined(__sun) && (defined(__i386) || defined(__amd64)) 202 #elif defined(__sun) && (defined(__i386) || defined(__amd64))
203 __asm( 203 __asm(
204 " movl %ebx,%edi\n"
205 " xorl %eax,%eax \n" 204 " xorl %eax,%eax \n"
205 " pushl %ebx \n"
206 " cpuid \n" 206 " cpuid \n"
207 " cmpl $1,%eax \n" 207 " cmpl $1,%eax \n"
208 " jl 1f \n" 208 " jl 1f \n"
209 " xorl %eax,%eax \n" 209 " xorl %eax,%eax \n"
210 " incl %eax \n" 210 " incl %eax \n"
211 " cpuid \n" 211 " cpuid \n"
212 " popl %ebx \n"
212 #ifdef __i386 213 #ifdef __i386
213 " movl %edx,-8(%ebp) \n" 214 " movl %edx,-8(%ebp) \n"
214 #else 215 #else
215 " movl %edx,-8(%rbp) \n" 216 " movl %edx,-8(%rbp) \n"
216 #endif 217 #endif
217 "1: \n" 218 "1: \n"
218 " movl %edi,%ebx\n" );
219 #endif 219 #endif
220 /* *INDENT-ON* */ 220 /* *INDENT-ON* */
221 return features; 221 return features;
222 } 222 }
223 223
226 { 226 {
227 int features = 0; 227 int features = 0;
228 /* *INDENT-OFF* */ 228 /* *INDENT-OFF* */
229 #if defined(__GNUC__) && defined(i386) 229 #if defined(__GNUC__) && defined(i386)
230 __asm__ ( 230 __asm__ (
231 " pushl %%ebx\n"
232 " movl $0x80000000,%%eax # Query for extended functions \n" 231 " movl $0x80000000,%%eax # Query for extended functions \n"
232 " pushl %%ebx \n"
233 " cpuid # Get extended function limit \n" 233 " cpuid # Get extended function limit \n"
234 " cmpl $0x80000001,%%eax \n" 234 " cmpl $0x80000001,%%eax \n"
235 " jl 1f # Nope, we dont have function 800000001h\n" 235 " jl 1f # Nope, we dont have function 800000001h\n"
236 " movl $0x80000001,%%eax # Setup extended function 800000001h\n" 236 " movl $0x80000001,%%eax # Setup extended function 800000001h\n"
237 " cpuid # and get the information \n" 237 " cpuid # and get the information \n"
238 " popl %%ebx \n"
238 " movl %%edx,%0 \n" 239 " movl %%edx,%0 \n"
239 "1: \n" 240 "1: \n"
240 " popl %%ebx\n"
241 : "=m" (features) 241 : "=m" (features)
242 : 242 :
243 : "%eax", "%ecx", "%edx" 243 : "%eax", "%ecx", "%edx"
244 ); 244 );
245 #elif defined(__GNUC__) && defined (__x86_64__) 245 #elif defined(__GNUC__) && defined (__x86_64__)
246 __asm__ ( 246 __asm__ (
247 " movl $0x80000000,%%eax # Query for extended functions \n" 247 " movl $0x80000000,%%eax # Query for extended functions \n"
248 " pushq %%rbx\n" 248 " pushq %%rbx \n"
249 " cpuid # Get extended function limit \n" 249 " cpuid # Get extended function limit \n"
250 " popq %%rbx\n"
251 " cmpl $0x80000001,%%eax \n" 250 " cmpl $0x80000001,%%eax \n"
252 " jl 1f # Nope, we dont have function 800000001h\n" 251 " jl 1f # Nope, we dont have function 800000001h\n"
253 " movl $0x80000001,%%eax # Setup extended function 800000001h\n" 252 " movl $0x80000001,%%eax # Setup extended function 800000001h\n"
254 " pushq %%rbx\n"
255 " cpuid # and get the information \n" 253 " cpuid # and get the information \n"
256 " popq %%rbx\n" 254 " popq %%rbx \n"
257 " movl %%edx,%0 \n" 255 " movl %%edx,%0 \n"
258 "1: \n" 256 "1: \n"
259 : "=m" (features) 257 : "=m" (features)
260 : 258 :
261 : "%rax", "%rcx", "%rdx" 259 : "%rax", "%rcx", "%rdx"
262 ); 260 );
263 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 261 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
264 __asm { 262 __asm {
265 mov eax,80000000h ; Query for extended functions 263 mov eax,80000000h ; Query for extended functions
264 push ebx
266 cpuid ; Get extended function limit 265 cpuid ; Get extended function limit
267 cmp eax,80000001h 266 cmp eax,80000001h
268 jl done ; Nope, we dont have function 800000001h 267 jl done ; Nope, we dont have function 800000001h
269 mov eax,80000001h ; Setup extended function 800000001h 268 mov eax,80000001h ; Setup extended function 800000001h
270 cpuid ; and get the information 269 cpuid ; and get the information
270 pop ebx
271 mov features,edx 271 mov features,edx
272 done: 272 done:
273 } 273 }
274 #elif defined(__sun) && ( defined(__i386) || defined(__amd64) ) 274 #elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
275 __asm ( 275 __asm (
276 " movl %ebx,%edi\n"
277 " movl $0x80000000,%eax \n" 276 " movl $0x80000000,%eax \n"
277 " pushl %ebx \n"
278 " cpuid \n" 278 " cpuid \n"
279 " cmpl $0x80000001,%eax \n" 279 " cmpl $0x80000001,%eax \n"
280 " jl 1f \n" 280 " jl 1f \n"
281 " movl $0x80000001,%eax \n" 281 " movl $0x80000001,%eax \n"
282 " cpuid \n" 282 " cpuid \n"
283 " popl %ebx \n"
283 #ifdef __i386 284 #ifdef __i386
284 " movl %edx,-8(%ebp) \n" 285 " movl %edx,-8(%ebp) \n"
285 #else 286 #else
286 " movl %edx,-8(%rbp) \n" 287 " movl %edx,-8(%rbp) \n"
287 #endif 288 #endif
288 "1: \n" 289 "1: \n"
289 " movl %edi,%ebx\n"
290 ); 290 );
291 #endif 291 #endif
292 /* *INDENT-ON* */ 292 /* *INDENT-ON* */
293 return features; 293 return features;
294 } 294 }