comparison src/cpuinfo/SDL_cpuinfo.c @ 4180:0a9a29fc00c2 SDL-1.2

Patch from Fedora project to fix crashes with SDL_HasSSE() on amd64. Fixes Bugzilla #760. (...and bugzilla.redhat.com #487720).
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 01 Jul 2009 19:06:31 +0000
parents a1b03ba2fcd0
children fa62bede8038
comparison
equal deleted inserted replaced
4179:d7294b7c732d 4180:0a9a29fc00c2
144 } 144 }
145 145
146 static __inline__ int CPU_getCPUIDFeatures(void) 146 static __inline__ int CPU_getCPUIDFeatures(void)
147 { 147 {
148 int features = 0; 148 int features = 0;
149 #if defined(__GNUC__) && ( defined(i386) || defined(__x86_64__) ) 149 #if defined(__GNUC__) && defined(i386)
150 __asm__ ( 150 __asm__ (
151 " movl %%ebx,%%edi\n" 151 " movl %%ebx,%%edi\n"
152 " xorl %%eax,%%eax # Set up for CPUID instruction \n" 152 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
153 " cpuid # Get and save vendor ID \n" 153 " cpuid # Get and save vendor ID \n"
154 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" 154 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
160 "1: \n" 160 "1: \n"
161 " movl %%edi,%%ebx\n" 161 " movl %%edi,%%ebx\n"
162 : "=m" (features) 162 : "=m" (features)
163 : 163 :
164 : "%eax", "%ecx", "%edx", "%edi" 164 : "%eax", "%ecx", "%edx", "%edi"
165 );
166 #elif defined(__GNUC__) && defined(__x86_64__)
167 __asm__ (
168 " movq %%rbx,%%rdi\n"
169 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
170 " cpuid # Get and save vendor ID \n"
171 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
172 " jl 1f # We dont have the CPUID instruction\n"
173 " xorl %%eax,%%eax \n"
174 " incl %%eax \n"
175 " cpuid # Get family/model/stepping/features\n"
176 " movl %%edx,%0 \n"
177 "1: \n"
178 " movq %%rdi,%%rbx\n"
179 : "=m" (features)
180 :
181 : "%rax", "%rcx", "%rdx", "%rdi"
165 ); 182 );
166 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 183 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
167 __asm { 184 __asm {
168 xor eax, eax ; Set up for CPUID instruction 185 xor eax, eax ; Set up for CPUID instruction
169 cpuid ; Get and save vendor ID 186 cpuid ; Get and save vendor ID
197 } 214 }
198 215
199 static __inline__ int CPU_getCPUIDFeaturesExt(void) 216 static __inline__ int CPU_getCPUIDFeaturesExt(void)
200 { 217 {
201 int features = 0; 218 int features = 0;
202 #if defined(__GNUC__) && (defined(i386) || defined (__x86_64__) ) 219 #if defined(__GNUC__) && defined(i386)
203 __asm__ ( 220 __asm__ (
204 " movl %%ebx,%%edi\n" 221 " movl %%ebx,%%edi\n"
205 " movl $0x80000000,%%eax # Query for extended functions \n" 222 " movl $0x80000000,%%eax # Query for extended functions \n"
206 " cpuid # Get extended function limit \n" 223 " cpuid # Get extended function limit \n"
207 " cmpl $0x80000001,%%eax \n" 224 " cmpl $0x80000001,%%eax \n"
212 "1: \n" 229 "1: \n"
213 " movl %%edi,%%ebx\n" 230 " movl %%edi,%%ebx\n"
214 : "=m" (features) 231 : "=m" (features)
215 : 232 :
216 : "%eax", "%ecx", "%edx", "%edi" 233 : "%eax", "%ecx", "%edx", "%edi"
234 );
235 #elif defined(__GNUC__) && defined (__x86_64__)
236 __asm__ (
237 " movq %%rbx,%%rdi\n"
238 " movl $0x80000000,%%eax # Query for extended functions \n"
239 " cpuid # Get extended function limit \n"
240 " cmpl $0x80000001,%%eax \n"
241 " jl 1f # Nope, we dont have function 800000001h\n"
242 " movl $0x80000001,%%eax # Setup extended function 800000001h\n"
243 " cpuid # and get the information \n"
244 " movl %%edx,%0 \n"
245 "1: \n"
246 " movq %%rdi,%%rbx\n"
247 : "=m" (features)
248 :
249 : "%rax", "%rcx", "%rdx", "%rdi"
217 ); 250 );
218 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 251 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
219 __asm { 252 __asm {
220 mov eax,80000000h ; Query for extended functions 253 mov eax,80000000h ; Query for extended functions
221 cpuid ; Get extended function limit 254 cpuid ; Get extended function limit