src/cpuinfo/SDL_cpuinfo.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1590 96d8c3fec479
child 1668 4da1ee79c9af
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -27,7 +27,7 @@
     1.4  #include "SDL_cpuinfo.h"
     1.5  
     1.6  #if defined(__MACOSX__) && defined(__ppc__)
     1.7 -#include <sys/sysctl.h> /* For AltiVec check */
     1.8 +#include <sys/sysctl.h>         /* For AltiVec check */
     1.9  #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
    1.10  #include <signal.h>
    1.11  #include <setjmp.h>
    1.12 @@ -47,400 +47,351 @@
    1.13     the idea is borrowed from the libmpeg2 library - thanks!
    1.14   */
    1.15  static jmp_buf jmpbuf;
    1.16 -static void illegal_instruction(int sig)
    1.17 +static void
    1.18 +illegal_instruction (int sig)
    1.19  {
    1.20 -	longjmp(jmpbuf, 1);
    1.21 +    longjmp (jmpbuf, 1);
    1.22  }
    1.23  #endif /* HAVE_SETJMP */
    1.24  
    1.25 -static __inline__ int CPU_haveCPUID(void)
    1.26 +static __inline__ int
    1.27 +CPU_haveCPUID (void)
    1.28  {
    1.29 -	int has_CPUID = 0;
    1.30 +    int has_CPUID = 0;
    1.31  #if defined(__GNUC__) && defined(i386)
    1.32 -	__asm__ (
    1.33 -"        pushfl                      # Get original EFLAGS             \n"
    1.34 -"        popl    %%eax                                                 \n"
    1.35 -"        movl    %%eax,%%ecx                                           \n"
    1.36 -"        xorl    $0x200000,%%eax     # Flip ID bit in EFLAGS           \n"
    1.37 -"        pushl   %%eax               # Save new EFLAGS value on stack  \n"
    1.38 -"        popfl                       # Replace current EFLAGS value    \n"
    1.39 -"        pushfl                      # Get new EFLAGS                  \n"
    1.40 -"        popl    %%eax               # Store new EFLAGS in EAX         \n"
    1.41 -"        xorl    %%ecx,%%eax         # Can not toggle ID bit,          \n"
    1.42 -"        jz      1f                  # Processor=80486                 \n"
    1.43 -"        movl    $1,%0               # We have CPUID support           \n"
    1.44 -"1:                                                                    \n"
    1.45 -	: "=m" (has_CPUID)
    1.46 -	:
    1.47 -	: "%eax", "%ecx"
    1.48 -	);
    1.49 +  __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):
    1.50 +  :"%eax", "%ecx");
    1.51  #elif defined(__GNUC__) && defined(__x86_64__)
    1.52  /* Technically, if this is being compiled under __x86_64__ then it has 
    1.53  CPUid by definition.  But it's nice to be able to prove it.  :)      */
    1.54 -	__asm__ (
    1.55 -"        pushfq                      # Get original EFLAGS             \n"
    1.56 -"        popq    %%rax                                                 \n"
    1.57 -"        movq    %%rax,%%rcx                                           \n"
    1.58 -"        xorl    $0x200000,%%eax     # Flip ID bit in EFLAGS           \n"
    1.59 -"        pushq   %%rax               # Save new EFLAGS value on stack  \n"
    1.60 -"        popfq                       # Replace current EFLAGS value    \n"
    1.61 -"        pushfq                      # Get new EFLAGS                  \n"
    1.62 -"        popq    %%rax               # Store new EFLAGS in EAX         \n"
    1.63 -"        xorl    %%ecx,%%eax         # Can not toggle ID bit,          \n"
    1.64 -"        jz      1f                  # Processor=80486                 \n"
    1.65 -"        movl    $1,%0               # We have CPUID support           \n"
    1.66 -"1:                                                                    \n"
    1.67 -	: "=m" (has_CPUID)
    1.68 -	:
    1.69 -	: "%rax", "%rcx"
    1.70 -	);
    1.71 +  __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):
    1.72 +  :"%rax", "%rcx");
    1.73  #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
    1.74 -	__asm {
    1.75 -        pushfd                      ; Get original EFLAGS
    1.76 -        pop     eax
    1.77 -        mov     ecx, eax
    1.78 -        xor     eax, 200000h        ; Flip ID bit in EFLAGS
    1.79 -        push    eax                 ; Save new EFLAGS value on stack
    1.80 -        popfd                       ; Replace current EFLAGS value
    1.81 -        pushfd                      ; Get new EFLAGS
    1.82 -        pop     eax                 ; Store new EFLAGS in EAX
    1.83 -        xor     eax, ecx            ; Can not toggle ID bit,
    1.84 -        jz      done                ; Processor=80486
    1.85 -        mov     has_CPUID,1         ; We have CPUID support
    1.86 -done:
    1.87 -	}
    1.88 +    __asm {
    1.89 +        pushfd;
    1.90 +        Get original EFLAGS pop eax mov ecx, eax xor eax, 200000 h;
    1.91 +        Flip ID bit in EFLAGS push eax;
    1.92 +        Save new EFLAGS value on stack popfd;
    1.93 +        Replace current EFLAGS value pushfd;
    1.94 +        Get new EFLAGS pop eax;
    1.95 +        Store new EFLAGS in EAX xor eax, ecx;
    1.96 +        Can not toggle ID bit, jz done;
    1.97 +        Processor = 80486 mov has_CPUID, 1;
    1.98 +    We have CPUID support done:}
    1.99  #elif defined(__sun) && defined(__x86)
   1.100 -	__asm (
   1.101 -"       pushfl                 \n"
   1.102 -"	popl    %eax           \n"
   1.103 -"	movl    %eax,%ecx      \n"
   1.104 -"	xorl    $0x200000,%eax \n"
   1.105 -"	pushl   %eax           \n"
   1.106 -"	popfl                  \n"
   1.107 -"	pushfl                 \n"
   1.108 -"	popl    %eax           \n"
   1.109 -"	xorl    %ecx,%eax      \n"
   1.110 -"	jz      1f             \n"
   1.111 -"	movl    $1,-8(%ebp)    \n"
   1.112 -"1:                            \n"
   1.113 -	);
   1.114 +    __asm ("       pushfl                 \n"
   1.115 +           "	popl    %eax           \n"
   1.116 +           "	movl    %eax,%ecx      \n"
   1.117 +           "	xorl    $0x200000,%eax \n"
   1.118 +           "	pushl   %eax           \n"
   1.119 +           "	popfl                  \n"
   1.120 +           "	pushfl                 \n"
   1.121 +           "	popl    %eax           \n"
   1.122 +           "	xorl    %ecx,%eax      \n"
   1.123 +           "	jz      1f             \n"
   1.124 +           "	movl    $1,-8(%ebp)    \n"
   1.125 +           "1:                            \n");
   1.126  #elif defined(__sun) && defined(__amd64)
   1.127 -	__asm (
   1.128 -"       pushfq                 \n"
   1.129 -"       popq    %rax           \n"
   1.130 -"       movq    %rax,%rcx      \n"
   1.131 -"       xorl    $0x200000,%eax \n"
   1.132 -"       pushq   %rax           \n"
   1.133 -"       popfq                  \n"
   1.134 -"       pushfq                 \n"
   1.135 -"       popq    %rax           \n"
   1.136 -"       xorl    %ecx,%eax      \n"
   1.137 -"       jz      1f             \n"
   1.138 -"       movl    $1,-8(%rbp)    \n"
   1.139 -"1:                            \n"
   1.140 -	);
   1.141 +    __asm ("       pushfq                 \n"
   1.142 +           "       popq    %rax           \n"
   1.143 +           "       movq    %rax,%rcx      \n"
   1.144 +           "       xorl    $0x200000,%eax \n"
   1.145 +           "       pushq   %rax           \n"
   1.146 +           "       popfq                  \n"
   1.147 +           "       pushfq                 \n"
   1.148 +           "       popq    %rax           \n"
   1.149 +           "       xorl    %ecx,%eax      \n"
   1.150 +           "       jz      1f             \n"
   1.151 +           "       movl    $1,-8(%rbp)    \n"
   1.152 +           "1:                            \n");
   1.153  #endif
   1.154 -	return has_CPUID;
   1.155 +    return has_CPUID;
   1.156  }
   1.157  
   1.158 -static __inline__ int CPU_getCPUIDFeatures(void)
   1.159 +static __inline__ int
   1.160 +CPU_getCPUIDFeatures (void)
   1.161  {
   1.162 -	int features = 0;
   1.163 +    int features = 0;
   1.164  #if defined(__GNUC__) && ( defined(i386) || defined(__x86_64__) )
   1.165 -	__asm__ (
   1.166 -"        movl    %%ebx,%%edi\n"
   1.167 -"        xorl    %%eax,%%eax         # Set up for CPUID instruction    \n"
   1.168 -"        cpuid                       # Get and save vendor ID          \n"
   1.169 -"        cmpl    $1,%%eax            # Make sure 1 is valid input for CPUID\n"
   1.170 -"        jl      1f                  # We dont have the CPUID instruction\n"
   1.171 -"        xorl    %%eax,%%eax                                           \n"
   1.172 -"        incl    %%eax                                                 \n"
   1.173 -"        cpuid                       # Get family/model/stepping/features\n"
   1.174 -"        movl    %%edx,%0                                              \n"
   1.175 -"1:                                                                    \n"
   1.176 -"        movl    %%edi,%%ebx\n"
   1.177 -	: "=m" (features)
   1.178 -	:
   1.179 -	: "%eax", "%ecx", "%edx", "%edi"
   1.180 -	);
   1.181 +  __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):
   1.182 +  :"%eax", "%ecx", "%edx", "%edi");
   1.183  #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
   1.184 -	__asm {
   1.185 -        xor     eax, eax            ; Set up for CPUID instruction
   1.186 -        cpuid                       ; Get and save vendor ID
   1.187 -        cmp     eax, 1              ; Make sure 1 is valid input for CPUID
   1.188 -        jl      done                ; We dont have the CPUID instruction
   1.189 -        xor     eax, eax
   1.190 -        inc     eax
   1.191 -        cpuid                       ; Get family/model/stepping/features
   1.192 -        mov     features, edx
   1.193 -done:
   1.194 -	}
   1.195 +    __asm {
   1.196 +        xor eax, eax;
   1.197 +    Set up for CPUID instruction
   1.198 +            cpuid; Get and save vendor ID
   1.199 +            cmp eax, 1; Make sure 1 is valid input for CPUID
   1.200 +            jl done; We dont have the CPUID instruction
   1.201 +            xor eax, eax
   1.202 +            inc eax
   1.203 +            cpuid; Get family / model / stepping / features
   1.204 +            mov features, edx done:}
   1.205  #elif defined(__sun) && (defined(__x86) || defined(__amd64))
   1.206 -	    __asm(
   1.207 -"        movl    %ebx,%edi\n"
   1.208 -"        xorl    %eax,%eax         \n"
   1.209 -"        cpuid                     \n"
   1.210 -"        cmpl    $1,%eax           \n"
   1.211 -"        jl      1f                \n"
   1.212 -"        xorl    %eax,%eax         \n"
   1.213 -"        incl    %eax              \n"
   1.214 -"        cpuid                     \n"
   1.215 +    __asm
   1.216 +        ("        movl    %ebx,%edi\n"
   1.217 +         "        xorl    %eax,%eax         \n"
   1.218 +         "        cpuid                     \n"
   1.219 +         "        cmpl    $1,%eax           \n"
   1.220 +         "        jl      1f                \n"
   1.221 +         "        xorl    %eax,%eax         \n"
   1.222 +         "        incl    %eax              \n"
   1.223 +         "        cpuid                     \n"
   1.224  #ifdef __i386
   1.225 -"        movl    %edx,-8(%ebp)     \n"
   1.226 +         "        movl    %edx,-8(%ebp)     \n"
   1.227  #else
   1.228 -"        movl    %edx,-8(%rbp)     \n"
   1.229 +         "        movl    %edx,-8(%rbp)     \n"
   1.230  #endif
   1.231 -"1:                                \n"
   1.232 -"        movl    %edi,%ebx\n" );
   1.233 +         "1:                                \n"
   1.234 +         "        movl    %edi,%ebx\n");
   1.235  #endif
   1.236 -	return features;
   1.237 +    return features;
   1.238  }
   1.239  
   1.240 -static __inline__ int CPU_getCPUIDFeaturesExt(void)
   1.241 +static __inline__ int
   1.242 +CPU_getCPUIDFeaturesExt (void)
   1.243  {
   1.244 -	int features = 0;
   1.245 +    int features = 0;
   1.246  #if defined(__GNUC__) && (defined(i386) || defined (__x86_64__) )
   1.247 -	__asm__ (
   1.248 -"        movl    %%ebx,%%edi\n"
   1.249 -"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
   1.250 -"        cpuid                       # Get extended function limit     \n"
   1.251 -"        cmpl    $0x80000001,%%eax                                     \n"
   1.252 -"        jl      1f                  # Nope, we dont have function 800000001h\n"
   1.253 -"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
   1.254 -"        cpuid                       # and get the information         \n"
   1.255 -"        movl    %%edx,%0                                              \n"
   1.256 -"1:                                                                    \n"
   1.257 -"        movl    %%edi,%%ebx\n"
   1.258 -	: "=m" (features)
   1.259 -	:
   1.260 -	: "%eax", "%ecx", "%edx", "%edi"
   1.261 -	);
   1.262 +  __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):
   1.263 +  :"%eax", "%ecx", "%edx", "%edi");
   1.264  #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
   1.265 -	__asm {
   1.266 -        mov     eax,80000000h       ; Query for extended functions
   1.267 -        cpuid                       ; Get extended function limit
   1.268 -        cmp     eax,80000001h
   1.269 -        jl      done                ; Nope, we dont have function 800000001h
   1.270 -        mov     eax,80000001h       ; Setup extended function 800000001h
   1.271 -        cpuid                       ; and get the information
   1.272 -        mov     features,edx
   1.273 -done:
   1.274 -	}
   1.275 +    __asm {
   1.276 +        mov eax, 80000000 h;
   1.277 +        Query for extended functions
   1.278 +            cpuid; Get extended function limit
   1.279 +            cmp eax, 80000001 h jl done; Nope
   1.280 +            , we dont have function 800000001 h mov eax, 80000001 h;
   1.281 +        Setup extended function 800000001 h cpuid;
   1.282 +    and get the information mov features, edx done:}
   1.283  #elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
   1.284 -	    __asm (
   1.285 -"        movl    %ebx,%edi\n"
   1.286 -"        movl    $0x80000000,%eax \n"
   1.287 -"        cpuid                    \n"
   1.288 -"        cmpl    $0x80000001,%eax \n"
   1.289 -"        jl      1f               \n"
   1.290 -"        movl    $0x80000001,%eax \n"
   1.291 -"        cpuid                    \n"
   1.292 +    __asm ("        movl    %ebx,%edi\n"
   1.293 +           "        movl    $0x80000000,%eax \n"
   1.294 +           "        cpuid                    \n"
   1.295 +           "        cmpl    $0x80000001,%eax \n"
   1.296 +           "        jl      1f               \n"
   1.297 +           "        movl    $0x80000001,%eax \n"
   1.298 +           "        cpuid                    \n"
   1.299  #ifdef __i386
   1.300 -"        movl    %edx,-8(%ebp)   \n"
   1.301 +           "        movl    %edx,-8(%ebp)   \n"
   1.302  #else
   1.303 -"        movl    %edx,-8(%rbp)   \n"
   1.304 +           "        movl    %edx,-8(%rbp)   \n"
   1.305  #endif
   1.306 -"1:                               \n"
   1.307 -"        movl    %edi,%ebx\n"
   1.308 -	    );
   1.309 +           "1:                               \n"
   1.310 +           "        movl    %edi,%ebx\n");
   1.311  #endif
   1.312 -	return features;
   1.313 +    return features;
   1.314  }
   1.315  
   1.316 -static __inline__ int CPU_haveRDTSC(void)
   1.317 +static __inline__ int
   1.318 +CPU_haveRDTSC (void)
   1.319  {
   1.320 -	if ( CPU_haveCPUID() ) {
   1.321 -		return (CPU_getCPUIDFeatures() & 0x00000010);
   1.322 -	}
   1.323 -	return 0;
   1.324 +    if (CPU_haveCPUID ()) {
   1.325 +        return (CPU_getCPUIDFeatures () & 0x00000010);
   1.326 +    }
   1.327 +    return 0;
   1.328  }
   1.329  
   1.330 -static __inline__ int CPU_haveMMX(void)
   1.331 +static __inline__ int
   1.332 +CPU_haveMMX (void)
   1.333  {
   1.334 -	if ( CPU_haveCPUID() ) {
   1.335 -		return (CPU_getCPUIDFeatures() & 0x00800000);
   1.336 -	}
   1.337 -	return 0;
   1.338 +    if (CPU_haveCPUID ()) {
   1.339 +        return (CPU_getCPUIDFeatures () & 0x00800000);
   1.340 +    }
   1.341 +    return 0;
   1.342  }
   1.343  
   1.344 -static __inline__ int CPU_haveMMXExt(void)
   1.345 +static __inline__ int
   1.346 +CPU_haveMMXExt (void)
   1.347  {
   1.348 -	if ( CPU_haveCPUID() ) {
   1.349 -		return (CPU_getCPUIDFeaturesExt() & 0x00400000);
   1.350 -	}
   1.351 -	return 0;
   1.352 +    if (CPU_haveCPUID ()) {
   1.353 +        return (CPU_getCPUIDFeaturesExt () & 0x00400000);
   1.354 +    }
   1.355 +    return 0;
   1.356  }
   1.357  
   1.358 -static __inline__ int CPU_have3DNow(void)
   1.359 +static __inline__ int
   1.360 +CPU_have3DNow (void)
   1.361  {
   1.362 -	if ( CPU_haveCPUID() ) {
   1.363 -		return (CPU_getCPUIDFeaturesExt() & 0x80000000);
   1.364 -	}
   1.365 -	return 0;
   1.366 +    if (CPU_haveCPUID ()) {
   1.367 +        return (CPU_getCPUIDFeaturesExt () & 0x80000000);
   1.368 +    }
   1.369 +    return 0;
   1.370  }
   1.371  
   1.372 -static __inline__ int CPU_have3DNowExt(void)
   1.373 +static __inline__ int
   1.374 +CPU_have3DNowExt (void)
   1.375  {
   1.376 -	if ( CPU_haveCPUID() ) {
   1.377 -		return (CPU_getCPUIDFeaturesExt() & 0x40000000);
   1.378 -	}
   1.379 -	return 0;
   1.380 +    if (CPU_haveCPUID ()) {
   1.381 +        return (CPU_getCPUIDFeaturesExt () & 0x40000000);
   1.382 +    }
   1.383 +    return 0;
   1.384  }
   1.385  
   1.386 -static __inline__ int CPU_haveSSE(void)
   1.387 +static __inline__ int
   1.388 +CPU_haveSSE (void)
   1.389  {
   1.390 -	if ( CPU_haveCPUID() ) {
   1.391 -		return (CPU_getCPUIDFeatures() & 0x02000000);
   1.392 -	}
   1.393 -	return 0;
   1.394 +    if (CPU_haveCPUID ()) {
   1.395 +        return (CPU_getCPUIDFeatures () & 0x02000000);
   1.396 +    }
   1.397 +    return 0;
   1.398  }
   1.399  
   1.400 -static __inline__ int CPU_haveSSE2(void)
   1.401 +static __inline__ int
   1.402 +CPU_haveSSE2 (void)
   1.403  {
   1.404 -	if ( CPU_haveCPUID() ) {
   1.405 -		return (CPU_getCPUIDFeatures() & 0x04000000);
   1.406 -	}
   1.407 -	return 0;
   1.408 +    if (CPU_haveCPUID ()) {
   1.409 +        return (CPU_getCPUIDFeatures () & 0x04000000);
   1.410 +    }
   1.411 +    return 0;
   1.412  }
   1.413  
   1.414 -static __inline__ int CPU_haveAltiVec(void)
   1.415 +static __inline__ int
   1.416 +CPU_haveAltiVec (void)
   1.417  {
   1.418 -	volatile int altivec = 0;
   1.419 +    volatile int altivec = 0;
   1.420  #if defined(__MACOSX__) && defined(__ppc__)
   1.421 -	int selectors[2] = { CTL_HW, HW_VECTORUNIT }; 
   1.422 -	int hasVectorUnit = 0; 
   1.423 -	size_t length = sizeof(hasVectorUnit); 
   1.424 -	int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); 
   1.425 -	if( 0 == error )
   1.426 -		altivec = (hasVectorUnit != 0); 
   1.427 +    int selectors[2] = { CTL_HW, HW_VECTORUNIT };
   1.428 +    int hasVectorUnit = 0;
   1.429 +    size_t length = sizeof (hasVectorUnit);
   1.430 +    int error = sysctl (selectors, 2, &hasVectorUnit, &length, NULL, 0);
   1.431 +    if (0 == error)
   1.432 +        altivec = (hasVectorUnit != 0);
   1.433  #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
   1.434 -	void (*handler)(int sig);
   1.435 -	handler = signal(SIGILL, illegal_instruction);
   1.436 -	if ( setjmp(jmpbuf) == 0 ) {
   1.437 -		asm volatile ("mtspr 256, %0\n\t"
   1.438 -			      "vand %%v0, %%v0, %%v0"
   1.439 -			      :
   1.440 -			      : "r" (-1));
   1.441 -		altivec = 1;
   1.442 -	}
   1.443 -	signal(SIGILL, handler);
   1.444 +    void (*handler) (int sig);
   1.445 +    handler = signal (SIGILL, illegal_instruction);
   1.446 +    if (setjmp (jmpbuf) == 0) {
   1.447 +        asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1));
   1.448 +        altivec = 1;
   1.449 +    }
   1.450 +    signal (SIGILL, handler);
   1.451  #endif
   1.452 -	return altivec; 
   1.453 +    return altivec;
   1.454  }
   1.455  
   1.456  static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
   1.457  
   1.458 -static Uint32 SDL_GetCPUFeatures(void)
   1.459 +static Uint32
   1.460 +SDL_GetCPUFeatures (void)
   1.461  {
   1.462 -	if ( SDL_CPUFeatures == 0xFFFFFFFF ) {
   1.463 -		SDL_CPUFeatures = 0;
   1.464 -		if ( CPU_haveRDTSC() ) {
   1.465 -			SDL_CPUFeatures |= CPU_HAS_RDTSC;
   1.466 -		}
   1.467 -		if ( CPU_haveMMX() ) {
   1.468 -			SDL_CPUFeatures |= CPU_HAS_MMX;
   1.469 -		}
   1.470 -		if ( CPU_haveMMXExt() ) {
   1.471 -			SDL_CPUFeatures |= CPU_HAS_MMXEXT;
   1.472 -		}
   1.473 -		if ( CPU_have3DNow() ) {
   1.474 -			SDL_CPUFeatures |= CPU_HAS_3DNOW;
   1.475 -		}
   1.476 -		if ( CPU_have3DNowExt() ) {
   1.477 -			SDL_CPUFeatures |= CPU_HAS_3DNOWEXT;
   1.478 -		}
   1.479 -		if ( CPU_haveSSE() ) {
   1.480 -			SDL_CPUFeatures |= CPU_HAS_SSE;
   1.481 -		}
   1.482 -		if ( CPU_haveSSE2() ) {
   1.483 -			SDL_CPUFeatures |= CPU_HAS_SSE2;
   1.484 -		}
   1.485 -		if ( CPU_haveAltiVec() ) {
   1.486 -			SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
   1.487 -		}
   1.488 -	}
   1.489 -	return SDL_CPUFeatures;
   1.490 +    if (SDL_CPUFeatures == 0xFFFFFFFF) {
   1.491 +        SDL_CPUFeatures = 0;
   1.492 +        if (CPU_haveRDTSC ()) {
   1.493 +            SDL_CPUFeatures |= CPU_HAS_RDTSC;
   1.494 +        }
   1.495 +        if (CPU_haveMMX ()) {
   1.496 +            SDL_CPUFeatures |= CPU_HAS_MMX;
   1.497 +        }
   1.498 +        if (CPU_haveMMXExt ()) {
   1.499 +            SDL_CPUFeatures |= CPU_HAS_MMXEXT;
   1.500 +        }
   1.501 +        if (CPU_have3DNow ()) {
   1.502 +            SDL_CPUFeatures |= CPU_HAS_3DNOW;
   1.503 +        }
   1.504 +        if (CPU_have3DNowExt ()) {
   1.505 +            SDL_CPUFeatures |= CPU_HAS_3DNOWEXT;
   1.506 +        }
   1.507 +        if (CPU_haveSSE ()) {
   1.508 +            SDL_CPUFeatures |= CPU_HAS_SSE;
   1.509 +        }
   1.510 +        if (CPU_haveSSE2 ()) {
   1.511 +            SDL_CPUFeatures |= CPU_HAS_SSE2;
   1.512 +        }
   1.513 +        if (CPU_haveAltiVec ()) {
   1.514 +            SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
   1.515 +        }
   1.516 +    }
   1.517 +    return SDL_CPUFeatures;
   1.518  }
   1.519  
   1.520 -SDL_bool SDL_HasRDTSC(void)
   1.521 +SDL_bool
   1.522 +SDL_HasRDTSC (void)
   1.523  {
   1.524 -	if ( SDL_GetCPUFeatures() & CPU_HAS_RDTSC ) {
   1.525 -		return SDL_TRUE;
   1.526 -	}
   1.527 -	return SDL_FALSE;
   1.528 +    if (SDL_GetCPUFeatures () & CPU_HAS_RDTSC) {
   1.529 +        return SDL_TRUE;
   1.530 +    }
   1.531 +    return SDL_FALSE;
   1.532  }
   1.533  
   1.534 -SDL_bool SDL_HasMMX(void)
   1.535 +SDL_bool
   1.536 +SDL_HasMMX (void)
   1.537  {
   1.538 -	if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) {
   1.539 -		return SDL_TRUE;
   1.540 -	}
   1.541 -	return SDL_FALSE;
   1.542 +    if (SDL_GetCPUFeatures () & CPU_HAS_MMX) {
   1.543 +        return SDL_TRUE;
   1.544 +    }
   1.545 +    return SDL_FALSE;
   1.546  }
   1.547  
   1.548 -SDL_bool SDL_HasMMXExt(void)
   1.549 +SDL_bool
   1.550 +SDL_HasMMXExt (void)
   1.551  {
   1.552 -	if ( SDL_GetCPUFeatures() & CPU_HAS_MMXEXT ) {
   1.553 -		return SDL_TRUE;
   1.554 -	}
   1.555 -	return SDL_FALSE;
   1.556 +    if (SDL_GetCPUFeatures () & CPU_HAS_MMXEXT) {
   1.557 +        return SDL_TRUE;
   1.558 +    }
   1.559 +    return SDL_FALSE;
   1.560  }
   1.561  
   1.562 -SDL_bool SDL_Has3DNow(void)
   1.563 +SDL_bool
   1.564 +SDL_Has3DNow (void)
   1.565  {
   1.566 -	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) {
   1.567 -		return SDL_TRUE;
   1.568 -	}
   1.569 -	return SDL_FALSE;
   1.570 +    if (SDL_GetCPUFeatures () & CPU_HAS_3DNOW) {
   1.571 +        return SDL_TRUE;
   1.572 +    }
   1.573 +    return SDL_FALSE;
   1.574  }
   1.575  
   1.576 -SDL_bool SDL_Has3DNowExt(void)
   1.577 +SDL_bool
   1.578 +SDL_Has3DNowExt (void)
   1.579  {
   1.580 -	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT ) {
   1.581 -		return SDL_TRUE;
   1.582 -	}
   1.583 -	return SDL_FALSE;
   1.584 +    if (SDL_GetCPUFeatures () & CPU_HAS_3DNOWEXT) {
   1.585 +        return SDL_TRUE;
   1.586 +    }
   1.587 +    return SDL_FALSE;
   1.588  }
   1.589  
   1.590 -SDL_bool SDL_HasSSE(void)
   1.591 +SDL_bool
   1.592 +SDL_HasSSE (void)
   1.593  {
   1.594 -	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) {
   1.595 -		return SDL_TRUE;
   1.596 -	}
   1.597 -	return SDL_FALSE;
   1.598 +    if (SDL_GetCPUFeatures () & CPU_HAS_SSE) {
   1.599 +        return SDL_TRUE;
   1.600 +    }
   1.601 +    return SDL_FALSE;
   1.602  }
   1.603  
   1.604 -SDL_bool SDL_HasSSE2(void)
   1.605 +SDL_bool
   1.606 +SDL_HasSSE2 (void)
   1.607  {
   1.608 -	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE2 ) {
   1.609 -		return SDL_TRUE;
   1.610 -	}
   1.611 -	return SDL_FALSE;
   1.612 +    if (SDL_GetCPUFeatures () & CPU_HAS_SSE2) {
   1.613 +        return SDL_TRUE;
   1.614 +    }
   1.615 +    return SDL_FALSE;
   1.616  }
   1.617  
   1.618 -SDL_bool SDL_HasAltiVec(void)
   1.619 +SDL_bool
   1.620 +SDL_HasAltiVec (void)
   1.621  {
   1.622 -	if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) {
   1.623 -		return SDL_TRUE;
   1.624 -	}
   1.625 -	return SDL_FALSE;
   1.626 +    if (SDL_GetCPUFeatures () & CPU_HAS_ALTIVEC) {
   1.627 +        return SDL_TRUE;
   1.628 +    }
   1.629 +    return SDL_FALSE;
   1.630  }
   1.631  
   1.632  #ifdef TEST_MAIN
   1.633  
   1.634  #include <stdio.h>
   1.635  
   1.636 -int main()
   1.637 +int
   1.638 +main ()
   1.639  {
   1.640 -	printf("RDTSC: %d\n", SDL_HasRDTSC());
   1.641 -	printf("MMX: %d\n", SDL_HasMMX());
   1.642 -	printf("MMXExt: %d\n", SDL_HasMMXExt());
   1.643 -	printf("3DNow: %d\n", SDL_Has3DNow());
   1.644 -	printf("3DNowExt: %d\n", SDL_Has3DNowExt());
   1.645 -	printf("SSE: %d\n", SDL_HasSSE());
   1.646 -	printf("SSE2: %d\n", SDL_HasSSE2());
   1.647 -	printf("AltiVec: %d\n", SDL_HasAltiVec());
   1.648 -	return 0;
   1.649 +    printf ("RDTSC: %d\n", SDL_HasRDTSC ());
   1.650 +    printf ("MMX: %d\n", SDL_HasMMX ());
   1.651 +    printf ("MMXExt: %d\n", SDL_HasMMXExt ());
   1.652 +    printf ("3DNow: %d\n", SDL_Has3DNow ());
   1.653 +    printf ("3DNowExt: %d\n", SDL_Has3DNowExt ());
   1.654 +    printf ("SSE: %d\n", SDL_HasSSE ());
   1.655 +    printf ("SSE2: %d\n", SDL_HasSSE2 ());
   1.656 +    printf ("AltiVec: %d\n", SDL_HasAltiVec ());
   1.657 +    return 0;
   1.658  }
   1.659  
   1.660  #endif /* TEST_MAIN */
   1.661 +/* vi: set ts=4 sw=4 expandtab: */