Mercurial > sdl-ios-xcode
comparison src/cpuinfo/SDL_cpuinfo.c @ 4372:ca91f36ef3de SDL-1.2
1.2 branch: fixed assembly code register clobbering.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 01 Nov 2009 17:51:39 +0000 |
parents | 0319c84d274d |
children | dcb26ac38e6b |
comparison
equal
deleted
inserted
replaced
4371:6f74b80cca1d | 4372:ca91f36ef3de |
---|---|
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) | 149 #if defined(__GNUC__) && defined(i386) |
150 __asm__ ( | 150 __asm__ ( |
151 " movl %%ebx,%%edi\n" | 151 " pushl %%ebx\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" |
155 " jl 1f # We dont have the CPUID instruction\n" | 155 " jl 1f # We dont have the CPUID instruction\n" |
156 " xorl %%eax,%%eax \n" | 156 " xorl %%eax,%%eax \n" |
157 " incl %%eax \n" | 157 " incl %%eax \n" |
158 " cpuid # Get family/model/stepping/features\n" | 158 " cpuid # Get family/model/stepping/features\n" |
159 " movl %%edx,%0 \n" | 159 " movl %%edx,%0 \n" |
160 "1: \n" | 160 "1: \n" |
161 " movl %%edi,%%ebx\n" | 161 " popl %%ebx\n" |
162 : "=m" (features) | 162 : "=m" (features) |
163 : | 163 : |
164 : "%eax", "%ecx", "%edx", "%edi" | 164 : "%eax", "%ecx", "%edx" |
165 ); | 165 ); |
166 #elif defined(__GNUC__) && defined(__x86_64__) | 166 #elif defined(__GNUC__) && defined(__x86_64__) |
167 __asm__ ( | 167 __asm__ ( |
168 " movq %%rbx,%%rdi\n" | 168 " pushq %%rbx\n" |
169 " xorl %%eax,%%eax # Set up for CPUID instruction \n" | 169 " xorl %%eax,%%eax # Set up for CPUID instruction \n" |
170 " cpuid # Get and save vendor ID \n" | 170 " cpuid # Get and save vendor ID \n" |
171 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" | 171 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" |
172 " jl 1f # We dont have the CPUID instruction\n" | 172 " jl 1f # We dont have the CPUID instruction\n" |
173 " xorl %%eax,%%eax \n" | 173 " xorl %%eax,%%eax \n" |
174 " incl %%eax \n" | 174 " incl %%eax \n" |
175 " cpuid # Get family/model/stepping/features\n" | 175 " cpuid # Get family/model/stepping/features\n" |
176 " movl %%edx,%0 \n" | 176 " movl %%edx,%0 \n" |
177 "1: \n" | 177 "1: \n" |
178 " movq %%rdi,%%rbx\n" | 178 " popq %%rbx\n" |
179 : "=m" (features) | 179 : "=m" (features) |
180 : | 180 : |
181 : "%rax", "%rbx", "%rcx", "%rdx", "%rdi" | 181 : "%rax", "%rcx", "%rdx" |
182 ); | 182 ); |
183 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) | 183 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) |
184 __asm { | 184 __asm { |
185 xor eax, eax ; Set up for CPUID instruction | 185 xor eax, eax ; Set up for CPUID instruction |
186 cpuid ; Get and save vendor ID | 186 cpuid ; Get and save vendor ID |
192 mov features, edx | 192 mov features, edx |
193 done: | 193 done: |
194 } | 194 } |
195 #elif defined(__sun) && (defined(__i386) || defined(__amd64)) | 195 #elif defined(__sun) && (defined(__i386) || defined(__amd64)) |
196 __asm( | 196 __asm( |
197 " movl %ebx,%edi\n" | 197 " pushl %ebx\n" |
198 " xorl %eax,%eax \n" | 198 " xorl %eax,%eax \n" |
199 " cpuid \n" | 199 " cpuid \n" |
200 " cmpl $1,%eax \n" | 200 " cmpl $1,%eax \n" |
201 " jl 1f \n" | 201 " jl 1f \n" |
202 " xorl %eax,%eax \n" | 202 " xorl %eax,%eax \n" |
206 " movl %edx,-8(%ebp) \n" | 206 " movl %edx,-8(%ebp) \n" |
207 #else | 207 #else |
208 " movl %edx,-8(%rbp) \n" | 208 " movl %edx,-8(%rbp) \n" |
209 #endif | 209 #endif |
210 "1: \n" | 210 "1: \n" |
211 " movl %edi,%ebx\n" ); | 211 " popl %ebx\n" ); |
212 #endif | 212 #endif |
213 return features; | 213 return features; |
214 } | 214 } |
215 | 215 |
216 static __inline__ int CPU_getCPUIDFeaturesExt(void) | 216 static __inline__ int CPU_getCPUIDFeaturesExt(void) |
217 { | 217 { |
218 int features = 0; | 218 int features = 0; |
219 #if defined(__GNUC__) && defined(i386) | 219 #if defined(__GNUC__) && defined(i386) |
220 __asm__ ( | 220 __asm__ ( |
221 " movl %%ebx,%%edi\n" | 221 " pushl %%ebx\n" |
222 " movl $0x80000000,%%eax # Query for extended functions \n" | 222 " movl $0x80000000,%%eax # Query for extended functions \n" |
223 " cpuid # Get extended function limit \n" | 223 " cpuid # Get extended function limit \n" |
224 " cmpl $0x80000001,%%eax \n" | 224 " cmpl $0x80000001,%%eax \n" |
225 " jl 1f # Nope, we dont have function 800000001h\n" | 225 " jl 1f # Nope, we dont have function 800000001h\n" |
226 " movl $0x80000001,%%eax # Setup extended function 800000001h\n" | 226 " movl $0x80000001,%%eax # Setup extended function 800000001h\n" |
227 " cpuid # and get the information \n" | 227 " cpuid # and get the information \n" |
228 " movl %%edx,%0 \n" | 228 " movl %%edx,%0 \n" |
229 "1: \n" | 229 "1: \n" |
230 " movl %%edi,%%ebx\n" | 230 " popl %%ebx\n" |
231 : "=m" (features) | 231 : "=m" (features) |
232 : | 232 : |
233 : "%eax", "%ecx", "%edx", "%edi" | 233 : "%eax", "%ecx", "%edx" |
234 ); | 234 ); |
235 #elif defined(__GNUC__) && defined (__x86_64__) | 235 #elif defined(__GNUC__) && defined (__x86_64__) |
236 __asm__ ( | 236 __asm__ ( |
237 " movq %%rbx,%%rdi\n" | 237 " pushq %%rbx\n" |
238 " movl $0x80000000,%%eax # Query for extended functions \n" | 238 " movl $0x80000000,%%eax # Query for extended functions \n" |
239 " cpuid # Get extended function limit \n" | 239 " cpuid # Get extended function limit \n" |
240 " cmpl $0x80000001,%%eax \n" | 240 " cmpl $0x80000001,%%eax \n" |
241 " jl 1f # Nope, we dont have function 800000001h\n" | 241 " jl 1f # Nope, we dont have function 800000001h\n" |
242 " movl $0x80000001,%%eax # Setup extended function 800000001h\n" | 242 " movl $0x80000001,%%eax # Setup extended function 800000001h\n" |
243 " cpuid # and get the information \n" | 243 " cpuid # and get the information \n" |
244 " movl %%edx,%0 \n" | 244 " movl %%edx,%0 \n" |
245 "1: \n" | 245 "1: \n" |
246 " movq %%rdi,%%rbx\n" | 246 " popq %%rbx\n" |
247 : "=m" (features) | 247 : "=m" (features) |
248 : | 248 : |
249 : "%rax", "%rbx", "%rcx", "%rdx", "%rdi" | 249 : "%rax", "%rcx", "%rdx" |
250 ); | 250 ); |
251 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) | 251 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) |
252 __asm { | 252 __asm { |
253 mov eax,80000000h ; Query for extended functions | 253 mov eax,80000000h ; Query for extended functions |
254 cpuid ; Get extended function limit | 254 cpuid ; Get extended function limit |
259 mov features,edx | 259 mov features,edx |
260 done: | 260 done: |
261 } | 261 } |
262 #elif defined(__sun) && ( defined(__i386) || defined(__amd64) ) | 262 #elif defined(__sun) && ( defined(__i386) || defined(__amd64) ) |
263 __asm ( | 263 __asm ( |
264 " movl %ebx,%edi\n" | 264 " pushl %ebx\n" |
265 " movl $0x80000000,%eax \n" | 265 " movl $0x80000000,%eax \n" |
266 " cpuid \n" | 266 " cpuid \n" |
267 " cmpl $0x80000001,%eax \n" | 267 " cmpl $0x80000001,%eax \n" |
268 " jl 1f \n" | 268 " jl 1f \n" |
269 " movl $0x80000001,%eax \n" | 269 " movl $0x80000001,%eax \n" |
272 " movl %edx,-8(%ebp) \n" | 272 " movl %edx,-8(%ebp) \n" |
273 #else | 273 #else |
274 " movl %edx,-8(%rbp) \n" | 274 " movl %edx,-8(%rbp) \n" |
275 #endif | 275 #endif |
276 "1: \n" | 276 "1: \n" |
277 " movl %edi,%ebx\n" | 277 " popl %ebx\n" |
278 ); | 278 ); |
279 #endif | 279 #endif |
280 return features; | 280 return features; |
281 } | 281 } |
282 | 282 |