comparison src/cpuinfo/SDL_cpuinfo.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 96d8c3fec479
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
25 25
26 #include "SDL.h" 26 #include "SDL.h"
27 #include "SDL_cpuinfo.h" 27 #include "SDL_cpuinfo.h"
28 28
29 #if defined(__MACOSX__) && defined(__ppc__) 29 #if defined(__MACOSX__) && defined(__ppc__)
30 #include <sys/sysctl.h> /* For AltiVec check */ 30 #include <sys/sysctl.h> /* For AltiVec check */
31 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP 31 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
32 #include <signal.h> 32 #include <signal.h>
33 #include <setjmp.h> 33 #include <setjmp.h>
34 #endif 34 #endif
35 35
45 #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ 45 #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__
46 /* This is the brute force way of detecting instruction sets... 46 /* This is the brute force way of detecting instruction sets...
47 the idea is borrowed from the libmpeg2 library - thanks! 47 the idea is borrowed from the libmpeg2 library - thanks!
48 */ 48 */
49 static jmp_buf jmpbuf; 49 static jmp_buf jmpbuf;
50 static void illegal_instruction(int sig) 50 static void
51 { 51 illegal_instruction (int sig)
52 longjmp(jmpbuf, 1); 52 {
53 longjmp (jmpbuf, 1);
53 } 54 }
54 #endif /* HAVE_SETJMP */ 55 #endif /* HAVE_SETJMP */
55 56
56 static __inline__ int CPU_haveCPUID(void) 57 static __inline__ int
57 { 58 CPU_haveCPUID (void)
58 int has_CPUID = 0; 59 {
60 int has_CPUID = 0;
59 #if defined(__GNUC__) && defined(i386) 61 #if defined(__GNUC__) && defined(i386)
60 __asm__ ( 62 __asm__ (" pushfl # Get original EFLAGS \n" " popl %%eax \n" " movl %%eax,%%ecx \n" " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n" " pushl %%eax # Save new EFLAGS value on stack \n" " popfl # Replace current EFLAGS value \n" " pushfl # Get new EFLAGS \n" " popl %%eax # Store new EFLAGS in EAX \n" " xorl %%ecx,%%eax # Can not toggle ID bit, \n" " jz 1f # Processor=80486 \n" " movl $1,%0 # We have CPUID support \n" "1: \n": "=m" (has_CPUID):
61 " pushfl # Get original EFLAGS \n" 63 :"%eax", "%ecx");
62 " popl %%eax \n"
63 " movl %%eax,%%ecx \n"
64 " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
65 " pushl %%eax # Save new EFLAGS value on stack \n"
66 " popfl # Replace current EFLAGS value \n"
67 " pushfl # Get new EFLAGS \n"
68 " popl %%eax # Store new EFLAGS in EAX \n"
69 " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
70 " jz 1f # Processor=80486 \n"
71 " movl $1,%0 # We have CPUID support \n"
72 "1: \n"
73 : "=m" (has_CPUID)
74 :
75 : "%eax", "%ecx"
76 );
77 #elif defined(__GNUC__) && defined(__x86_64__) 64 #elif defined(__GNUC__) && defined(__x86_64__)
78 /* Technically, if this is being compiled under __x86_64__ then it has 65 /* Technically, if this is being compiled under __x86_64__ then it has
79 CPUid by definition. But it's nice to be able to prove it. :) */ 66 CPUid by definition. But it's nice to be able to prove it. :) */
80 __asm__ ( 67 __asm__ (" pushfq # Get original EFLAGS \n" " popq %%rax \n" " movq %%rax,%%rcx \n" " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n" " pushq %%rax # Save new EFLAGS value on stack \n" " popfq # Replace current EFLAGS value \n" " pushfq # Get new EFLAGS \n" " popq %%rax # Store new EFLAGS in EAX \n" " xorl %%ecx,%%eax # Can not toggle ID bit, \n" " jz 1f # Processor=80486 \n" " movl $1,%0 # We have CPUID support \n" "1: \n": "=m" (has_CPUID):
81 " pushfq # Get original EFLAGS \n" 68 :"%rax", "%rcx");
82 " popq %%rax \n"
83 " movq %%rax,%%rcx \n"
84 " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
85 " pushq %%rax # Save new EFLAGS value on stack \n"
86 " popfq # Replace current EFLAGS value \n"
87 " pushfq # Get new EFLAGS \n"
88 " popq %%rax # Store new EFLAGS in EAX \n"
89 " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
90 " jz 1f # Processor=80486 \n"
91 " movl $1,%0 # We have CPUID support \n"
92 "1: \n"
93 : "=m" (has_CPUID)
94 :
95 : "%rax", "%rcx"
96 );
97 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 69 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
98 __asm { 70 __asm {
99 pushfd ; Get original EFLAGS 71 pushfd;
100 pop eax 72 Get original EFLAGS pop eax mov ecx, eax xor eax, 200000 h;
101 mov ecx, eax 73 Flip ID bit in EFLAGS push eax;
102 xor eax, 200000h ; Flip ID bit in EFLAGS 74 Save new EFLAGS value on stack popfd;
103 push eax ; Save new EFLAGS value on stack 75 Replace current EFLAGS value pushfd;
104 popfd ; Replace current EFLAGS value 76 Get new EFLAGS pop eax;
105 pushfd ; Get new EFLAGS 77 Store new EFLAGS in EAX xor eax, ecx;
106 pop eax ; Store new EFLAGS in EAX 78 Can not toggle ID bit, jz done;
107 xor eax, ecx ; Can not toggle ID bit, 79 Processor = 80486 mov has_CPUID, 1;
108 jz done ; Processor=80486 80 We have CPUID support done:}
109 mov has_CPUID,1 ; We have CPUID support
110 done:
111 }
112 #elif defined(__sun) && defined(__x86) 81 #elif defined(__sun) && defined(__x86)
113 __asm ( 82 __asm (" pushfl \n"
114 " pushfl \n" 83 " popl %eax \n"
115 " popl %eax \n" 84 " movl %eax,%ecx \n"
116 " movl %eax,%ecx \n" 85 " xorl $0x200000,%eax \n"
117 " xorl $0x200000,%eax \n" 86 " pushl %eax \n"
118 " pushl %eax \n" 87 " popfl \n"
119 " popfl \n" 88 " pushfl \n"
120 " pushfl \n" 89 " popl %eax \n"
121 " popl %eax \n" 90 " xorl %ecx,%eax \n"
122 " xorl %ecx,%eax \n" 91 " jz 1f \n"
123 " jz 1f \n" 92 " movl $1,-8(%ebp) \n"
124 " movl $1,-8(%ebp) \n" 93 "1: \n");
125 "1: \n"
126 );
127 #elif defined(__sun) && defined(__amd64) 94 #elif defined(__sun) && defined(__amd64)
128 __asm ( 95 __asm (" pushfq \n"
129 " pushfq \n" 96 " popq %rax \n"
130 " popq %rax \n" 97 " movq %rax,%rcx \n"
131 " movq %rax,%rcx \n" 98 " xorl $0x200000,%eax \n"
132 " xorl $0x200000,%eax \n" 99 " pushq %rax \n"
133 " pushq %rax \n" 100 " popfq \n"
134 " popfq \n" 101 " pushfq \n"
135 " pushfq \n" 102 " popq %rax \n"
136 " popq %rax \n" 103 " xorl %ecx,%eax \n"
137 " xorl %ecx,%eax \n" 104 " jz 1f \n"
138 " jz 1f \n" 105 " movl $1,-8(%rbp) \n"
139 " movl $1,-8(%rbp) \n" 106 "1: \n");
140 "1: \n" 107 #endif
141 ); 108 return has_CPUID;
142 #endif 109 }
143 return has_CPUID; 110
144 } 111 static __inline__ int
145 112 CPU_getCPUIDFeatures (void)
146 static __inline__ int CPU_getCPUIDFeatures(void) 113 {
147 { 114 int features = 0;
148 int features = 0;
149 #if defined(__GNUC__) && ( defined(i386) || defined(__x86_64__) ) 115 #if defined(__GNUC__) && ( defined(i386) || defined(__x86_64__) )
150 __asm__ ( 116 __asm__ (" movl %%ebx,%%edi\n" " xorl %%eax,%%eax # Set up for CPUID instruction \n" " cpuid # Get and save vendor ID \n" " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" " jl 1f # We dont have the CPUID instruction\n" " xorl %%eax,%%eax \n" " incl %%eax \n" " cpuid # Get family/model/stepping/features\n" " movl %%edx,%0 \n" "1: \n" " movl %%edi,%%ebx\n": "=m" (features):
151 " movl %%ebx,%%edi\n" 117 :"%eax", "%ecx", "%edx", "%edi");
152 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
153 " cpuid # Get and save vendor ID \n"
154 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
155 " jl 1f # We dont have the CPUID instruction\n"
156 " xorl %%eax,%%eax \n"
157 " incl %%eax \n"
158 " cpuid # Get family/model/stepping/features\n"
159 " movl %%edx,%0 \n"
160 "1: \n"
161 " movl %%edi,%%ebx\n"
162 : "=m" (features)
163 :
164 : "%eax", "%ecx", "%edx", "%edi"
165 );
166 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 118 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
167 __asm { 119 __asm {
168 xor eax, eax ; Set up for CPUID instruction 120 xor eax, eax;
169 cpuid ; Get and save vendor ID 121 Set up for CPUID instruction
170 cmp eax, 1 ; Make sure 1 is valid input for CPUID 122 cpuid; Get and save vendor ID
171 jl done ; We dont have the CPUID instruction 123 cmp eax, 1; Make sure 1 is valid input for CPUID
172 xor eax, eax 124 jl done; We dont have the CPUID instruction
173 inc eax 125 xor eax, eax
174 cpuid ; Get family/model/stepping/features 126 inc eax
175 mov features, edx 127 cpuid; Get family / model / stepping / features
176 done: 128 mov features, edx done:}
177 }
178 #elif defined(__sun) && (defined(__x86) || defined(__amd64)) 129 #elif defined(__sun) && (defined(__x86) || defined(__amd64))
179 __asm( 130 __asm
180 " movl %ebx,%edi\n" 131 (" movl %ebx,%edi\n"
181 " xorl %eax,%eax \n" 132 " xorl %eax,%eax \n"
182 " cpuid \n" 133 " cpuid \n"
183 " cmpl $1,%eax \n" 134 " cmpl $1,%eax \n"
184 " jl 1f \n" 135 " jl 1f \n"
185 " xorl %eax,%eax \n" 136 " xorl %eax,%eax \n"
186 " incl %eax \n" 137 " incl %eax \n"
187 " cpuid \n" 138 " cpuid \n"
188 #ifdef __i386 139 #ifdef __i386
189 " movl %edx,-8(%ebp) \n" 140 " movl %edx,-8(%ebp) \n"
190 #else 141 #else
191 " movl %edx,-8(%rbp) \n" 142 " movl %edx,-8(%rbp) \n"
192 #endif 143 #endif
193 "1: \n" 144 "1: \n"
194 " movl %edi,%ebx\n" ); 145 " movl %edi,%ebx\n");
195 #endif 146 #endif
196 return features; 147 return features;
197 } 148 }
198 149
199 static __inline__ int CPU_getCPUIDFeaturesExt(void) 150 static __inline__ int
200 { 151 CPU_getCPUIDFeaturesExt (void)
201 int features = 0; 152 {
153 int features = 0;
202 #if defined(__GNUC__) && (defined(i386) || defined (__x86_64__) ) 154 #if defined(__GNUC__) && (defined(i386) || defined (__x86_64__) )
203 __asm__ ( 155 __asm__ (" movl %%ebx,%%edi\n" " movl $0x80000000,%%eax # Query for extended functions \n" " cpuid # Get extended function limit \n" " cmpl $0x80000001,%%eax \n" " jl 1f # Nope, we dont have function 800000001h\n" " movl $0x80000001,%%eax # Setup extended function 800000001h\n" " cpuid # and get the information \n" " movl %%edx,%0 \n" "1: \n" " movl %%edi,%%ebx\n": "=m" (features):
204 " movl %%ebx,%%edi\n" 156 :"%eax", "%ecx", "%edx", "%edi");
205 " movl $0x80000000,%%eax # Query for extended functions \n"
206 " cpuid # Get extended function limit \n"
207 " cmpl $0x80000001,%%eax \n"
208 " jl 1f # Nope, we dont have function 800000001h\n"
209 " movl $0x80000001,%%eax # Setup extended function 800000001h\n"
210 " cpuid # and get the information \n"
211 " movl %%edx,%0 \n"
212 "1: \n"
213 " movl %%edi,%%ebx\n"
214 : "=m" (features)
215 :
216 : "%eax", "%ecx", "%edx", "%edi"
217 );
218 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 157 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
219 __asm { 158 __asm {
220 mov eax,80000000h ; Query for extended functions 159 mov eax, 80000000 h;
221 cpuid ; Get extended function limit 160 Query for extended functions
222 cmp eax,80000001h 161 cpuid; Get extended function limit
223 jl done ; Nope, we dont have function 800000001h 162 cmp eax, 80000001 h jl done; Nope
224 mov eax,80000001h ; Setup extended function 800000001h 163 , we dont have function 800000001 h mov eax, 80000001 h;
225 cpuid ; and get the information 164 Setup extended function 800000001 h cpuid;
226 mov features,edx 165 and get the information mov features, edx done:}
227 done:
228 }
229 #elif defined(__sun) && ( defined(__i386) || defined(__amd64) ) 166 #elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
230 __asm ( 167 __asm (" movl %ebx,%edi\n"
231 " movl %ebx,%edi\n" 168 " movl $0x80000000,%eax \n"
232 " movl $0x80000000,%eax \n" 169 " cpuid \n"
233 " cpuid \n" 170 " cmpl $0x80000001,%eax \n"
234 " cmpl $0x80000001,%eax \n" 171 " jl 1f \n"
235 " jl 1f \n" 172 " movl $0x80000001,%eax \n"
236 " movl $0x80000001,%eax \n" 173 " cpuid \n"
237 " cpuid \n"
238 #ifdef __i386 174 #ifdef __i386
239 " movl %edx,-8(%ebp) \n" 175 " movl %edx,-8(%ebp) \n"
240 #else 176 #else
241 " movl %edx,-8(%rbp) \n" 177 " movl %edx,-8(%rbp) \n"
242 #endif 178 #endif
243 "1: \n" 179 "1: \n"
244 " movl %edi,%ebx\n" 180 " movl %edi,%ebx\n");
245 ); 181 #endif
246 #endif 182 return features;
247 return features; 183 }
248 } 184
249 185 static __inline__ int
250 static __inline__ int CPU_haveRDTSC(void) 186 CPU_haveRDTSC (void)
251 { 187 {
252 if ( CPU_haveCPUID() ) { 188 if (CPU_haveCPUID ()) {
253 return (CPU_getCPUIDFeatures() & 0x00000010); 189 return (CPU_getCPUIDFeatures () & 0x00000010);
254 } 190 }
255 return 0; 191 return 0;
256 } 192 }
257 193
258 static __inline__ int CPU_haveMMX(void) 194 static __inline__ int
259 { 195 CPU_haveMMX (void)
260 if ( CPU_haveCPUID() ) { 196 {
261 return (CPU_getCPUIDFeatures() & 0x00800000); 197 if (CPU_haveCPUID ()) {
262 } 198 return (CPU_getCPUIDFeatures () & 0x00800000);
263 return 0; 199 }
264 } 200 return 0;
265 201 }
266 static __inline__ int CPU_haveMMXExt(void) 202
267 { 203 static __inline__ int
268 if ( CPU_haveCPUID() ) { 204 CPU_haveMMXExt (void)
269 return (CPU_getCPUIDFeaturesExt() & 0x00400000); 205 {
270 } 206 if (CPU_haveCPUID ()) {
271 return 0; 207 return (CPU_getCPUIDFeaturesExt () & 0x00400000);
272 } 208 }
273 209 return 0;
274 static __inline__ int CPU_have3DNow(void) 210 }
275 { 211
276 if ( CPU_haveCPUID() ) { 212 static __inline__ int
277 return (CPU_getCPUIDFeaturesExt() & 0x80000000); 213 CPU_have3DNow (void)
278 } 214 {
279 return 0; 215 if (CPU_haveCPUID ()) {
280 } 216 return (CPU_getCPUIDFeaturesExt () & 0x80000000);
281 217 }
282 static __inline__ int CPU_have3DNowExt(void) 218 return 0;
283 { 219 }
284 if ( CPU_haveCPUID() ) { 220
285 return (CPU_getCPUIDFeaturesExt() & 0x40000000); 221 static __inline__ int
286 } 222 CPU_have3DNowExt (void)
287 return 0; 223 {
288 } 224 if (CPU_haveCPUID ()) {
289 225 return (CPU_getCPUIDFeaturesExt () & 0x40000000);
290 static __inline__ int CPU_haveSSE(void) 226 }
291 { 227 return 0;
292 if ( CPU_haveCPUID() ) { 228 }
293 return (CPU_getCPUIDFeatures() & 0x02000000); 229
294 } 230 static __inline__ int
295 return 0; 231 CPU_haveSSE (void)
296 } 232 {
297 233 if (CPU_haveCPUID ()) {
298 static __inline__ int CPU_haveSSE2(void) 234 return (CPU_getCPUIDFeatures () & 0x02000000);
299 { 235 }
300 if ( CPU_haveCPUID() ) { 236 return 0;
301 return (CPU_getCPUIDFeatures() & 0x04000000); 237 }
302 } 238
303 return 0; 239 static __inline__ int
304 } 240 CPU_haveSSE2 (void)
305 241 {
306 static __inline__ int CPU_haveAltiVec(void) 242 if (CPU_haveCPUID ()) {
307 { 243 return (CPU_getCPUIDFeatures () & 0x04000000);
308 volatile int altivec = 0; 244 }
245 return 0;
246 }
247
248 static __inline__ int
249 CPU_haveAltiVec (void)
250 {
251 volatile int altivec = 0;
309 #if defined(__MACOSX__) && defined(__ppc__) 252 #if defined(__MACOSX__) && defined(__ppc__)
310 int selectors[2] = { CTL_HW, HW_VECTORUNIT }; 253 int selectors[2] = { CTL_HW, HW_VECTORUNIT };
311 int hasVectorUnit = 0; 254 int hasVectorUnit = 0;
312 size_t length = sizeof(hasVectorUnit); 255 size_t length = sizeof (hasVectorUnit);
313 int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); 256 int error = sysctl (selectors, 2, &hasVectorUnit, &length, NULL, 0);
314 if( 0 == error ) 257 if (0 == error)
315 altivec = (hasVectorUnit != 0); 258 altivec = (hasVectorUnit != 0);
316 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP 259 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
317 void (*handler)(int sig); 260 void (*handler) (int sig);
318 handler = signal(SIGILL, illegal_instruction); 261 handler = signal (SIGILL, illegal_instruction);
319 if ( setjmp(jmpbuf) == 0 ) { 262 if (setjmp (jmpbuf) == 0) {
320 asm volatile ("mtspr 256, %0\n\t" 263 asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1));
321 "vand %%v0, %%v0, %%v0" 264 altivec = 1;
322 : 265 }
323 : "r" (-1)); 266 signal (SIGILL, handler);
324 altivec = 1; 267 #endif
325 } 268 return altivec;
326 signal(SIGILL, handler);
327 #endif
328 return altivec;
329 } 269 }
330 270
331 static Uint32 SDL_CPUFeatures = 0xFFFFFFFF; 271 static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
332 272
333 static Uint32 SDL_GetCPUFeatures(void) 273 static Uint32
334 { 274 SDL_GetCPUFeatures (void)
335 if ( SDL_CPUFeatures == 0xFFFFFFFF ) { 275 {
336 SDL_CPUFeatures = 0; 276 if (SDL_CPUFeatures == 0xFFFFFFFF) {
337 if ( CPU_haveRDTSC() ) { 277 SDL_CPUFeatures = 0;
338 SDL_CPUFeatures |= CPU_HAS_RDTSC; 278 if (CPU_haveRDTSC ()) {
339 } 279 SDL_CPUFeatures |= CPU_HAS_RDTSC;
340 if ( CPU_haveMMX() ) { 280 }
341 SDL_CPUFeatures |= CPU_HAS_MMX; 281 if (CPU_haveMMX ()) {
342 } 282 SDL_CPUFeatures |= CPU_HAS_MMX;
343 if ( CPU_haveMMXExt() ) { 283 }
344 SDL_CPUFeatures |= CPU_HAS_MMXEXT; 284 if (CPU_haveMMXExt ()) {
345 } 285 SDL_CPUFeatures |= CPU_HAS_MMXEXT;
346 if ( CPU_have3DNow() ) { 286 }
347 SDL_CPUFeatures |= CPU_HAS_3DNOW; 287 if (CPU_have3DNow ()) {
348 } 288 SDL_CPUFeatures |= CPU_HAS_3DNOW;
349 if ( CPU_have3DNowExt() ) { 289 }
350 SDL_CPUFeatures |= CPU_HAS_3DNOWEXT; 290 if (CPU_have3DNowExt ()) {
351 } 291 SDL_CPUFeatures |= CPU_HAS_3DNOWEXT;
352 if ( CPU_haveSSE() ) { 292 }
353 SDL_CPUFeatures |= CPU_HAS_SSE; 293 if (CPU_haveSSE ()) {
354 } 294 SDL_CPUFeatures |= CPU_HAS_SSE;
355 if ( CPU_haveSSE2() ) { 295 }
356 SDL_CPUFeatures |= CPU_HAS_SSE2; 296 if (CPU_haveSSE2 ()) {
357 } 297 SDL_CPUFeatures |= CPU_HAS_SSE2;
358 if ( CPU_haveAltiVec() ) { 298 }
359 SDL_CPUFeatures |= CPU_HAS_ALTIVEC; 299 if (CPU_haveAltiVec ()) {
360 } 300 SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
361 } 301 }
362 return SDL_CPUFeatures; 302 }
363 } 303 return SDL_CPUFeatures;
364 304 }
365 SDL_bool SDL_HasRDTSC(void) 305
366 { 306 SDL_bool
367 if ( SDL_GetCPUFeatures() & CPU_HAS_RDTSC ) { 307 SDL_HasRDTSC (void)
368 return SDL_TRUE; 308 {
369 } 309 if (SDL_GetCPUFeatures () & CPU_HAS_RDTSC) {
370 return SDL_FALSE; 310 return SDL_TRUE;
371 } 311 }
372 312 return SDL_FALSE;
373 SDL_bool SDL_HasMMX(void) 313 }
374 { 314
375 if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) { 315 SDL_bool
376 return SDL_TRUE; 316 SDL_HasMMX (void)
377 } 317 {
378 return SDL_FALSE; 318 if (SDL_GetCPUFeatures () & CPU_HAS_MMX) {
379 } 319 return SDL_TRUE;
380 320 }
381 SDL_bool SDL_HasMMXExt(void) 321 return SDL_FALSE;
382 { 322 }
383 if ( SDL_GetCPUFeatures() & CPU_HAS_MMXEXT ) { 323
384 return SDL_TRUE; 324 SDL_bool
385 } 325 SDL_HasMMXExt (void)
386 return SDL_FALSE; 326 {
387 } 327 if (SDL_GetCPUFeatures () & CPU_HAS_MMXEXT) {
388 328 return SDL_TRUE;
389 SDL_bool SDL_Has3DNow(void) 329 }
390 { 330 return SDL_FALSE;
391 if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) { 331 }
392 return SDL_TRUE; 332
393 } 333 SDL_bool
394 return SDL_FALSE; 334 SDL_Has3DNow (void)
395 } 335 {
396 336 if (SDL_GetCPUFeatures () & CPU_HAS_3DNOW) {
397 SDL_bool SDL_Has3DNowExt(void) 337 return SDL_TRUE;
398 { 338 }
399 if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT ) { 339 return SDL_FALSE;
400 return SDL_TRUE; 340 }
401 } 341
402 return SDL_FALSE; 342 SDL_bool
403 } 343 SDL_Has3DNowExt (void)
404 344 {
405 SDL_bool SDL_HasSSE(void) 345 if (SDL_GetCPUFeatures () & CPU_HAS_3DNOWEXT) {
406 { 346 return SDL_TRUE;
407 if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) { 347 }
408 return SDL_TRUE; 348 return SDL_FALSE;
409 } 349 }
410 return SDL_FALSE; 350
411 } 351 SDL_bool
412 352 SDL_HasSSE (void)
413 SDL_bool SDL_HasSSE2(void) 353 {
414 { 354 if (SDL_GetCPUFeatures () & CPU_HAS_SSE) {
415 if ( SDL_GetCPUFeatures() & CPU_HAS_SSE2 ) { 355 return SDL_TRUE;
416 return SDL_TRUE; 356 }
417 } 357 return SDL_FALSE;
418 return SDL_FALSE; 358 }
419 } 359
420 360 SDL_bool
421 SDL_bool SDL_HasAltiVec(void) 361 SDL_HasSSE2 (void)
422 { 362 {
423 if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) { 363 if (SDL_GetCPUFeatures () & CPU_HAS_SSE2) {
424 return SDL_TRUE; 364 return SDL_TRUE;
425 } 365 }
426 return SDL_FALSE; 366 return SDL_FALSE;
367 }
368
369 SDL_bool
370 SDL_HasAltiVec (void)
371 {
372 if (SDL_GetCPUFeatures () & CPU_HAS_ALTIVEC) {
373 return SDL_TRUE;
374 }
375 return SDL_FALSE;
427 } 376 }
428 377
429 #ifdef TEST_MAIN 378 #ifdef TEST_MAIN
430 379
431 #include <stdio.h> 380 #include <stdio.h>
432 381
433 int main() 382 int
434 { 383 main ()
435 printf("RDTSC: %d\n", SDL_HasRDTSC()); 384 {
436 printf("MMX: %d\n", SDL_HasMMX()); 385 printf ("RDTSC: %d\n", SDL_HasRDTSC ());
437 printf("MMXExt: %d\n", SDL_HasMMXExt()); 386 printf ("MMX: %d\n", SDL_HasMMX ());
438 printf("3DNow: %d\n", SDL_Has3DNow()); 387 printf ("MMXExt: %d\n", SDL_HasMMXExt ());
439 printf("3DNowExt: %d\n", SDL_Has3DNowExt()); 388 printf ("3DNow: %d\n", SDL_Has3DNow ());
440 printf("SSE: %d\n", SDL_HasSSE()); 389 printf ("3DNowExt: %d\n", SDL_Has3DNowExt ());
441 printf("SSE2: %d\n", SDL_HasSSE2()); 390 printf ("SSE: %d\n", SDL_HasSSE ());
442 printf("AltiVec: %d\n", SDL_HasAltiVec()); 391 printf ("SSE2: %d\n", SDL_HasSSE2 ());
443 return 0; 392 printf ("AltiVec: %d\n", SDL_HasAltiVec ());
393 return 0;
444 } 394 }
445 395
446 #endif /* TEST_MAIN */ 396 #endif /* TEST_MAIN */
397 /* vi: set ts=4 sw=4 expandtab: */