Mercurial > sdl-ios-xcode
comparison src/cpuinfo/SDL_cpuinfo.c @ 1361:19418e4422cb
New configure-based build system. Still work in progress, but much improved
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 16 Feb 2006 10:11:48 +0000 |
parents | c9b51268668f |
children | d910939febfa |
comparison
equal
deleted
inserted
replaced
1360:70a9cfb4cf1b | 1361:19418e4422cb |
---|---|
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 | 22 |
23 /* CPU feature detection for SDL */ | 23 /* CPU feature detection for SDL */ |
24 | 24 |
25 #ifdef unix /* FIXME: Better setjmp detection? */ | 25 #include "SDL.h" |
26 #define USE_SETJMP | 26 #include "SDL_cpuinfo.h" |
27 | |
28 #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP | |
27 #include <signal.h> | 29 #include <signal.h> |
28 #include <setjmp.h> | 30 #include <setjmp.h> |
29 #endif | 31 #endif |
30 | 32 |
31 #include "SDL.h" | 33 #if MACOSX |
32 #include "SDL_cpuinfo.h" | |
33 | |
34 #ifdef MACOSX | |
35 #include <sys/sysctl.h> /* For AltiVec check */ | 34 #include <sys/sysctl.h> /* For AltiVec check */ |
36 #endif | 35 #endif |
37 | 36 |
38 #define CPU_HAS_RDTSC 0x00000001 | 37 #define CPU_HAS_RDTSC 0x00000001 |
39 #define CPU_HAS_MMX 0x00000002 | 38 #define CPU_HAS_MMX 0x00000002 |
42 #define CPU_HAS_3DNOWEXT 0x00000020 | 41 #define CPU_HAS_3DNOWEXT 0x00000020 |
43 #define CPU_HAS_SSE 0x00000040 | 42 #define CPU_HAS_SSE 0x00000040 |
44 #define CPU_HAS_SSE2 0x00000080 | 43 #define CPU_HAS_SSE2 0x00000080 |
45 #define CPU_HAS_ALTIVEC 0x00000100 | 44 #define CPU_HAS_ALTIVEC 0x00000100 |
46 | 45 |
47 #if defined(USE_SETJMP) && defined(GCC_ALTIVEC) | 46 #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP |
48 /* This is the brute force way of detecting instruction sets... | 47 /* This is the brute force way of detecting instruction sets... |
49 the idea is borrowed from the libmpeg2 library - thanks! | 48 the idea is borrowed from the libmpeg2 library - thanks! |
50 */ | 49 */ |
51 static jmp_buf jmpbuf; | 50 static jmp_buf jmpbuf; |
52 static void illegal_instruction(int sig) | 51 static void illegal_instruction(int sig) |
53 { | 52 { |
54 longjmp(jmpbuf, 1); | 53 longjmp(jmpbuf, 1); |
55 } | 54 } |
56 #endif // USE_SETJMP | 55 #endif /* HAVE_SETJMP */ |
57 | 56 |
58 static __inline__ int CPU_haveCPUID() | 57 static __inline__ int CPU_haveCPUID() |
59 { | 58 { |
60 int has_CPUID = 0; | 59 int has_CPUID = 0; |
61 #if defined(__GNUC__) && defined(i386) | 60 #if defined(__GNUC__) && defined(i386) |
110 jz done ; Processor=80486 | 109 jz done ; Processor=80486 |
111 mov has_CPUID,1 ; We have CPUID support | 110 mov has_CPUID,1 ; We have CPUID support |
112 done: | 111 done: |
113 } | 112 } |
114 #elif defined(__sun) && defined(__x86) | 113 #elif defined(__sun) && defined(__x86) |
115 __asm ( | 114 __asm ( |
116 " pushfl \n" | 115 " pushfl \n" |
117 " popl %eax \n" | 116 " popl %eax \n" |
118 " movl %eax,%ecx \n" | 117 " movl %eax,%ecx \n" |
119 " xorl $0x200000,%eax \n" | 118 " xorl $0x200000,%eax \n" |
120 " pushl %eax \n" | 119 " pushl %eax \n" |
121 " popfl \n" | 120 " popfl \n" |
122 " pushfl \n" | 121 " pushfl \n" |
123 " popl %eax \n" | 122 " popl %eax \n" |
124 " xorl %ecx,%eax \n" | 123 " xorl %ecx,%eax \n" |
125 " jz 1f \n" | 124 " jz 1f \n" |
126 " movl $1,-8(%ebp) \n" | 125 " movl $1,-8(%ebp) \n" |
127 "1: \n" | 126 "1: \n" |
128 ); | 127 ); |
129 #elif defined(__sun) && defined(__amd64) | 128 #elif defined(__sun) && defined(__amd64) |
130 __asm ( | 129 __asm ( |
131 " pushfq \n" | 130 " pushfq \n" |
306 } | 305 } |
307 | 306 |
308 static __inline__ int CPU_haveAltiVec() | 307 static __inline__ int CPU_haveAltiVec() |
309 { | 308 { |
310 volatile int altivec = 0; | 309 volatile int altivec = 0; |
311 #ifdef MACOSX | 310 #if MACOSX |
312 int selectors[2] = { CTL_HW, HW_VECTORUNIT }; | 311 int selectors[2] = { CTL_HW, HW_VECTORUNIT }; |
313 int hasVectorUnit = 0; | 312 int hasVectorUnit = 0; |
314 size_t length = sizeof(hasVectorUnit); | 313 size_t length = sizeof(hasVectorUnit); |
315 int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); | 314 int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); |
316 if( 0 == error ) | 315 if( 0 == error ) |
317 altivec = (hasVectorUnit != 0); | 316 altivec = (hasVectorUnit != 0); |
318 #elif defined(USE_SETJMP) && defined(GCC_ALTIVEC) | 317 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP |
319 void (*handler)(int sig); | 318 void (*handler)(int sig); |
320 handler = signal(SIGILL, illegal_instruction); | 319 handler = signal(SIGILL, illegal_instruction); |
321 if ( setjmp(jmpbuf) == 0 ) { | 320 if ( setjmp(jmpbuf) == 0 ) { |
322 asm volatile ("mtspr 256, %0\n\t" | 321 asm volatile ("mtspr 256, %0\n\t" |
323 "vand %%v0, %%v0, %%v0" | 322 "vand %%v0, %%v0, %%v0" |