src/cpuinfo/SDL_cpuinfo.c
author Shawn Walker <eviltypeguy@icculus.org>
Tue, 19 Feb 2013 22:04:50 +0000
branchSDL-1.2
changeset 6908 8b9fcdd925d8
parent 6364 4a08ade5b4c9
permissions -rw-r--r--
Fix syntax error causing Solaris build failures.
slouken@739
     1
/*
slouken@739
     2
    SDL - Simple DirectMedia Layer
slouken@6137
     3
    Copyright (C) 1997-2012 Sam Lantinga
slouken@739
     4
slouken@739
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@739
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@739
     9
slouken@739
    10
    This library is distributed in the hope that it will be useful,
slouken@739
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@739
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@739
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@739
    18
slouken@739
    19
    Sam Lantinga
slouken@739
    20
    slouken@libsdl.org
slouken@739
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@739
    23
slouken@739
    24
/* CPU feature detection for SDL */
slouken@739
    25
slouken@1361
    26
#include "SDL.h"
slouken@1361
    27
#include "SDL_cpuinfo.h"
slouken@1361
    28
slouken@4386
    29
#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
slouken@1487
    30
#include <sys/sysctl.h> /* For AltiVec check */
slouken@6364
    31
#elif defined(__OpenBSD__) && defined(__powerpc__)
slouken@6364
    32
#include <sys/param.h>
slouken@6364
    33
#include <sys/sysctl.h> /* For AltiVec check */
slouken@6364
    34
#include <machine/cpu.h>
slouken@1487
    35
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
slouken@793
    36
#include <signal.h>
slouken@793
    37
#include <setjmp.h>
slouken@793
    38
#endif
slouken@793
    39
slouken@745
    40
#define CPU_HAS_RDTSC	0x00000001
slouken@745
    41
#define CPU_HAS_MMX	0x00000002
slouken@785
    42
#define CPU_HAS_MMXEXT	0x00000004
slouken@785
    43
#define CPU_HAS_3DNOW	0x00000010
slouken@785
    44
#define CPU_HAS_3DNOWEXT 0x00000020
slouken@785
    45
#define CPU_HAS_SSE	0x00000040
slouken@785
    46
#define CPU_HAS_SSE2	0x00000080
slouken@785
    47
#define CPU_HAS_ALTIVEC	0x00000100
slouken@739
    48
slouken@6364
    49
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
slouken@793
    50
/* This is the brute force way of detecting instruction sets...
slouken@793
    51
   the idea is borrowed from the libmpeg2 library - thanks!
slouken@793
    52
 */
slouken@793
    53
static jmp_buf jmpbuf;
slouken@793
    54
static void illegal_instruction(int sig)
slouken@793
    55
{
slouken@793
    56
	longjmp(jmpbuf, 1);
slouken@793
    57
}
slouken@1361
    58
#endif /* HAVE_SETJMP */
slouken@793
    59
slouken@1426
    60
static __inline__ int CPU_haveCPUID(void)
slouken@745
    61
{
slouken@745
    62
	int has_CPUID = 0;
slouken@745
    63
#if defined(__GNUC__) && defined(i386)
slouken@745
    64
	__asm__ (
slouken@745
    65
"        pushfl                      # Get original EFLAGS             \n"
slouken@745
    66
"        popl    %%eax                                                 \n"
slouken@745
    67
"        movl    %%eax,%%ecx                                           \n"
slouken@745
    68
"        xorl    $0x200000,%%eax     # Flip ID bit in EFLAGS           \n"
slouken@745
    69
"        pushl   %%eax               # Save new EFLAGS value on stack  \n"
slouken@745
    70
"        popfl                       # Replace current EFLAGS value    \n"
slouken@745
    71
"        pushfl                      # Get new EFLAGS                  \n"
slouken@745
    72
"        popl    %%eax               # Store new EFLAGS in EAX         \n"
slouken@745
    73
"        xorl    %%ecx,%%eax         # Can not toggle ID bit,          \n"
slouken@745
    74
"        jz      1f                  # Processor=80486                 \n"
slouken@745
    75
"        movl    $1,%0               # We have CPUID support           \n"
slouken@745
    76
"1:                                                                    \n"
slouken@784
    77
	: "=m" (has_CPUID)
slouken@745
    78
	:
slouken@745
    79
	: "%eax", "%ecx"
slouken@745
    80
	);
slouken@881
    81
#elif defined(__GNUC__) && defined(__x86_64__)
slouken@881
    82
/* Technically, if this is being compiled under __x86_64__ then it has 
slouken@881
    83
CPUid by definition.  But it's nice to be able to prove it.  :)      */
slouken@881
    84
	__asm__ (
slouken@881
    85
"        pushfq                      # Get original EFLAGS             \n"
slouken@881
    86
"        popq    %%rax                                                 \n"
slouken@881
    87
"        movq    %%rax,%%rcx                                           \n"
slouken@881
    88
"        xorl    $0x200000,%%eax     # Flip ID bit in EFLAGS           \n"
slouken@881
    89
"        pushq   %%rax               # Save new EFLAGS value on stack  \n"
slouken@881
    90
"        popfq                       # Replace current EFLAGS value    \n"
slouken@881
    91
"        pushfq                      # Get new EFLAGS                  \n"
slouken@881
    92
"        popq    %%rax               # Store new EFLAGS in EAX         \n"
slouken@881
    93
"        xorl    %%ecx,%%eax         # Can not toggle ID bit,          \n"
slouken@881
    94
"        jz      1f                  # Processor=80486                 \n"
slouken@881
    95
"        movl    $1,%0               # We have CPUID support           \n"
slouken@881
    96
"1:                                                                    \n"
slouken@881
    97
	: "=m" (has_CPUID)
slouken@881
    98
	:
slouken@881
    99
	: "%rax", "%rcx"
slouken@881
   100
	);
slouken@1442
   101
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
slouken@749
   102
	__asm {
slouken@745
   103
        pushfd                      ; Get original EFLAGS
slouken@745
   104
        pop     eax
slouken@745
   105
        mov     ecx, eax
slouken@745
   106
        xor     eax, 200000h        ; Flip ID bit in EFLAGS
slouken@745
   107
        push    eax                 ; Save new EFLAGS value on stack
slouken@745
   108
        popfd                       ; Replace current EFLAGS value
slouken@745
   109
        pushfd                      ; Get new EFLAGS
slouken@745
   110
        pop     eax                 ; Store new EFLAGS in EAX
slouken@745
   111
        xor     eax, ecx            ; Can not toggle ID bit,
slouken@745
   112
        jz      done                ; Processor=80486
slouken@745
   113
        mov     has_CPUID,1         ; We have CPUID support
slouken@745
   114
done:
slouken@745
   115
	}
slouken@1864
   116
#elif defined(__sun) && defined(__i386)
slouken@1361
   117
	__asm (
icculus@1229
   118
"       pushfl                 \n"
slouken@1361
   119
"	popl    %eax           \n"
slouken@1361
   120
"	movl    %eax,%ecx      \n"
slouken@1361
   121
"	xorl    $0x200000,%eax \n"
slouken@1361
   122
"	pushl   %eax           \n"
slouken@1361
   123
"	popfl                  \n"
slouken@1361
   124
"	pushfl                 \n"
slouken@1361
   125
"	popl    %eax           \n"
slouken@1361
   126
"	xorl    %ecx,%eax      \n"
slouken@1361
   127
"	jz      1f             \n"
slouken@1361
   128
"	movl    $1,-8(%ebp)    \n"
icculus@1229
   129
"1:                            \n"
icculus@1229
   130
	);
icculus@1229
   131
#elif defined(__sun) && defined(__amd64)
icculus@1229
   132
	__asm (
icculus@1229
   133
"       pushfq                 \n"
icculus@1229
   134
"       popq    %rax           \n"
icculus@1229
   135
"       movq    %rax,%rcx      \n"
icculus@1229
   136
"       xorl    $0x200000,%eax \n"
icculus@1229
   137
"       pushq   %rax           \n"
icculus@1229
   138
"       popfq                  \n"
icculus@1229
   139
"       pushfq                 \n"
icculus@1229
   140
"       popq    %rax           \n"
icculus@1229
   141
"       xorl    %ecx,%eax      \n"
icculus@1229
   142
"       jz      1f             \n"
icculus@1229
   143
"       movl    $1,-8(%rbp)    \n"
icculus@1229
   144
"1:                            \n"
icculus@1229
   145
	);
slouken@745
   146
#endif
slouken@745
   147
	return has_CPUID;
slouken@745
   148
}
slouken@745
   149
slouken@1426
   150
static __inline__ int CPU_getCPUIDFeatures(void)
slouken@745
   151
{
slouken@745
   152
	int features = 0;
icculus@4180
   153
#if defined(__GNUC__) && defined(i386)
slouken@745
   154
	__asm__ (
slouken@745
   155
"        xorl    %%eax,%%eax         # Set up for CPUID instruction    \n"
slouken@4386
   156
"        pushl   %%ebx                                                 \n"
slouken@745
   157
"        cpuid                       # Get and save vendor ID          \n"
slouken@4387
   158
"        popl    %%ebx                                                 \n"
slouken@745
   159
"        cmpl    $1,%%eax            # Make sure 1 is valid input for CPUID\n"
slouken@745
   160
"        jl      1f                  # We dont have the CPUID instruction\n"
slouken@745
   161
"        xorl    %%eax,%%eax                                           \n"
slouken@745
   162
"        incl    %%eax                                                 \n"
slouken@4387
   163
"        pushl   %%ebx                                                 \n"
slouken@745
   164
"        cpuid                       # Get family/model/stepping/features\n"
slouken@4386
   165
"        popl    %%ebx                                                 \n"
slouken@745
   166
"        movl    %%edx,%0                                              \n"
slouken@745
   167
"1:                                                                    \n"
slouken@784
   168
	: "=m" (features)
slouken@745
   169
	:
icculus@4372
   170
	: "%eax", "%ecx", "%edx"
slouken@745
   171
	);
icculus@4180
   172
#elif defined(__GNUC__) && defined(__x86_64__)
icculus@4180
   173
	__asm__ (
slouken@4386
   174
"        xorl    %%eax,%%eax         # Set up for CPUID instruction    \n"
slouken@4387
   175
"        pushq   %%rbx                                                 \n"
icculus@4180
   176
"        cpuid                       # Get and save vendor ID          \n"
slouken@4387
   177
"        popq    %%rbx                                                 \n"
icculus@4180
   178
"        cmpl    $1,%%eax            # Make sure 1 is valid input for CPUID\n"
icculus@4180
   179
"        jl      1f                  # We dont have the CPUID instruction\n"
icculus@4180
   180
"        xorl    %%eax,%%eax                                           \n"
icculus@4180
   181
"        incl    %%eax                                                 \n"
slouken@4387
   182
"        pushq   %%rbx                                                 \n"
icculus@4180
   183
"        cpuid                       # Get family/model/stepping/features\n"
slouken@4387
   184
"        popq    %%rbx                                                 \n"
icculus@4180
   185
"        movl    %%edx,%0                                              \n"
icculus@4180
   186
"1:                                                                    \n"
icculus@4180
   187
	: "=m" (features)
icculus@4180
   188
	:
icculus@4372
   189
	: "%rax", "%rcx", "%rdx"
icculus@4180
   190
	);
slouken@1442
   191
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
slouken@749
   192
	__asm {
slouken@745
   193
        xor     eax, eax            ; Set up for CPUID instruction
slouken@4386
   194
        push    ebx
slouken@745
   195
        cpuid                       ; Get and save vendor ID
slouken@4387
   196
        pop     ebx
slouken@745
   197
        cmp     eax, 1              ; Make sure 1 is valid input for CPUID
slouken@745
   198
        jl      done                ; We dont have the CPUID instruction
slouken@745
   199
        xor     eax, eax
slouken@745
   200
        inc     eax
slouken@4387
   201
        push    ebx
slouken@745
   202
        cpuid                       ; Get family/model/stepping/features
slouken@4386
   203
        pop     ebx
slouken@745
   204
        mov     features, edx
slouken@745
   205
done:
slouken@745
   206
	}
slouken@1864
   207
#elif defined(__sun) && (defined(__i386) || defined(__amd64))
icculus@1229
   208
	    __asm(
icculus@1229
   209
"        xorl    %eax,%eax         \n"
slouken@4386
   210
"        pushl   %ebx              \n"
icculus@1229
   211
"        cpuid                     \n"
slouken@4387
   212
"        popl    %ebx              \n"
icculus@1229
   213
"        cmpl    $1,%eax           \n"
icculus@1229
   214
"        jl      1f                \n"
icculus@1229
   215
"        xorl    %eax,%eax         \n"
icculus@1229
   216
"        incl    %eax              \n"
slouken@4387
   217
"        pushl   %ebx              \n"
icculus@1229
   218
"        cpuid                     \n"
slouken@4386
   219
"        popl    %ebx              \n"
icculus@1229
   220
#ifdef __i386
icculus@1229
   221
"        movl    %edx,-8(%ebp)     \n"
icculus@1229
   222
#else
icculus@1229
   223
"        movl    %edx,-8(%rbp)     \n"
icculus@1229
   224
#endif
icculus@1229
   225
"1:                                \n"
eviltypeguy@6908
   226
	    );
slouken@745
   227
#endif
slouken@745
   228
	return features;
slouken@745
   229
}
slouken@745
   230
slouken@1426
   231
static __inline__ int CPU_getCPUIDFeaturesExt(void)
slouken@785
   232
{
slouken@785
   233
	int features = 0;
icculus@4180
   234
#if defined(__GNUC__) && defined(i386)
slouken@785
   235
	__asm__ (
slouken@785
   236
"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
slouken@4386
   237
"        pushl   %%ebx                                                 \n"
slouken@785
   238
"        cpuid                       # Get extended function limit     \n"
slouken@4387
   239
"        popl    %%ebx                                                 \n"
slouken@785
   240
"        cmpl    $0x80000001,%%eax                                     \n"
slouken@787
   241
"        jl      1f                  # Nope, we dont have function 800000001h\n"
slouken@785
   242
"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
slouken@4387
   243
"        pushl   %%ebx                                                 \n"
slouken@785
   244
"        cpuid                       # and get the information         \n"
slouken@4386
   245
"        popl    %%ebx                                                 \n"
slouken@785
   246
"        movl    %%edx,%0                                              \n"
slouken@785
   247
"1:                                                                    \n"
slouken@785
   248
	: "=m" (features)
slouken@785
   249
	:
icculus@4372
   250
	: "%eax", "%ecx", "%edx"
slouken@785
   251
	);
icculus@4180
   252
#elif defined(__GNUC__) && defined (__x86_64__)
icculus@4180
   253
	__asm__ (
icculus@4180
   254
"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
slouken@4386
   255
"        pushq   %%rbx                                                 \n"
icculus@4180
   256
"        cpuid                       # Get extended function limit     \n"
slouken@4387
   257
"        popq    %%rbx                                                 \n"
icculus@4180
   258
"        cmpl    $0x80000001,%%eax                                     \n"
icculus@4180
   259
"        jl      1f                  # Nope, we dont have function 800000001h\n"
icculus@4180
   260
"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
slouken@4387
   261
"        pushq   %%rbx                                                 \n"
icculus@4180
   262
"        cpuid                       # and get the information         \n"
slouken@4386
   263
"        popq    %%rbx                                                 \n"
icculus@4180
   264
"        movl    %%edx,%0                                              \n"
icculus@4180
   265
"1:                                                                    \n"
icculus@4180
   266
	: "=m" (features)
icculus@4180
   267
	:
icculus@4372
   268
	: "%rax", "%rcx", "%rdx"
icculus@4180
   269
	);
slouken@1442
   270
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
slouken@785
   271
	__asm {
slouken@785
   272
        mov     eax,80000000h       ; Query for extended functions
slouken@4386
   273
        push    ebx
slouken@785
   274
        cpuid                       ; Get extended function limit
slouken@4387
   275
        pop     ebx
slouken@785
   276
        cmp     eax,80000001h
slouken@787
   277
        jl      done                ; Nope, we dont have function 800000001h
slouken@785
   278
        mov     eax,80000001h       ; Setup extended function 800000001h
slouken@4387
   279
        push    ebx
slouken@785
   280
        cpuid                       ; and get the information
slouken@4386
   281
        pop     ebx
slouken@785
   282
        mov     features,edx
slouken@785
   283
done:
slouken@785
   284
	}
icculus@1229
   285
#elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
icculus@1229
   286
	    __asm (
icculus@1229
   287
"        movl    $0x80000000,%eax \n"
slouken@4386
   288
"        pushl   %ebx             \n"
icculus@1229
   289
"        cpuid                    \n"
slouken@4387
   290
"        popl    %ebx             \n"
icculus@1229
   291
"        cmpl    $0x80000001,%eax \n"
icculus@1229
   292
"        jl      1f               \n"
icculus@1229
   293
"        movl    $0x80000001,%eax \n"
slouken@4387
   294
"        pushl   %ebx             \n"
icculus@1229
   295
"        cpuid                    \n"
slouken@4386
   296
"        popl    %ebx             \n"
icculus@1229
   297
#ifdef __i386
icculus@1229
   298
"        movl    %edx,-8(%ebp)   \n"
icculus@1229
   299
#else
icculus@1229
   300
"        movl    %edx,-8(%rbp)   \n"
icculus@1229
   301
#endif
icculus@1229
   302
"1:                               \n"
icculus@1229
   303
	    );
slouken@785
   304
#endif
slouken@785
   305
	return features;
slouken@785
   306
}
slouken@785
   307
slouken@1426
   308
static __inline__ int CPU_haveRDTSC(void)
slouken@745
   309
{
slouken@745
   310
	if ( CPU_haveCPUID() ) {
slouken@745
   311
		return (CPU_getCPUIDFeatures() & 0x00000010);
slouken@745
   312
	}
slouken@745
   313
	return 0;
slouken@745
   314
}
slouken@745
   315
slouken@1426
   316
static __inline__ int CPU_haveMMX(void)
slouken@745
   317
{
slouken@745
   318
	if ( CPU_haveCPUID() ) {
slouken@745
   319
		return (CPU_getCPUIDFeatures() & 0x00800000);
slouken@745
   320
	}
slouken@745
   321
	return 0;
slouken@745
   322
}
slouken@745
   323
slouken@1426
   324
static __inline__ int CPU_haveMMXExt(void)
slouken@785
   325
{
slouken@785
   326
	if ( CPU_haveCPUID() ) {
slouken@785
   327
		return (CPU_getCPUIDFeaturesExt() & 0x00400000);
slouken@785
   328
	}
slouken@785
   329
	return 0;
slouken@785
   330
}
slouken@785
   331
slouken@1426
   332
static __inline__ int CPU_have3DNow(void)
slouken@745
   333
{
slouken@785
   334
	if ( CPU_haveCPUID() ) {
slouken@785
   335
		return (CPU_getCPUIDFeaturesExt() & 0x80000000);
slouken@747
   336
	}
slouken@785
   337
	return 0;
slouken@785
   338
}
slouken@785
   339
slouken@1426
   340
static __inline__ int CPU_have3DNowExt(void)
slouken@785
   341
{
slouken@785
   342
	if ( CPU_haveCPUID() ) {
slouken@785
   343
		return (CPU_getCPUIDFeaturesExt() & 0x40000000);
slouken@745
   344
	}
slouken@785
   345
	return 0;
slouken@745
   346
}
slouken@745
   347
slouken@1426
   348
static __inline__ int CPU_haveSSE(void)
slouken@745
   349
{
slouken@745
   350
	if ( CPU_haveCPUID() ) {
slouken@745
   351
		return (CPU_getCPUIDFeatures() & 0x02000000);
slouken@745
   352
	}
slouken@745
   353
	return 0;
slouken@745
   354
}
slouken@739
   355
slouken@1426
   356
static __inline__ int CPU_haveSSE2(void)
slouken@785
   357
{
slouken@785
   358
	if ( CPU_haveCPUID() ) {
slouken@785
   359
		return (CPU_getCPUIDFeatures() & 0x04000000);
slouken@785
   360
	}
slouken@785
   361
	return 0;
slouken@785
   362
}
slouken@785
   363
slouken@1426
   364
static __inline__ int CPU_haveAltiVec(void)
slouken@778
   365
{
slouken@796
   366
	volatile int altivec = 0;
slouken@6364
   367
#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
slouken@6364
   368
# ifdef __OpenBSD__
slouken@6364
   369
	int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
slouken@6364
   370
# else
slouken@6364
   371
	int selectors[2] = { CTL_HW, HW_VECTORUNIT };
slouken@6364
   372
# endif
slouken@778
   373
	int hasVectorUnit = 0; 
slouken@778
   374
	size_t length = sizeof(hasVectorUnit); 
slouken@778
   375
	int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); 
slouken@778
   376
	if( 0 == error )
slouken@793
   377
		altivec = (hasVectorUnit != 0); 
slouken@1361
   378
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
slouken@793
   379
	void (*handler)(int sig);
slouken@793
   380
	handler = signal(SIGILL, illegal_instruction);
slouken@793
   381
	if ( setjmp(jmpbuf) == 0 ) {
slouken@793
   382
		asm volatile ("mtspr 256, %0\n\t"
slouken@793
   383
			      "vand %%v0, %%v0, %%v0"
slouken@793
   384
			      :
slouken@793
   385
			      : "r" (-1));
slouken@793
   386
		altivec = 1;
slouken@793
   387
	}
slouken@793
   388
	signal(SIGILL, handler);
slouken@778
   389
#endif
slouken@793
   390
	return altivec; 
slouken@778
   391
}
slouken@778
   392
slouken@739
   393
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
slouken@739
   394
slouken@1426
   395
static Uint32 SDL_GetCPUFeatures(void)
slouken@739
   396
{
slouken@739
   397
	if ( SDL_CPUFeatures == 0xFFFFFFFF ) {
slouken@739
   398
		SDL_CPUFeatures = 0;
slouken@745
   399
		if ( CPU_haveRDTSC() ) {
slouken@745
   400
			SDL_CPUFeatures |= CPU_HAS_RDTSC;
slouken@745
   401
		}
slouken@739
   402
		if ( CPU_haveMMX() ) {
slouken@739
   403
			SDL_CPUFeatures |= CPU_HAS_MMX;
slouken@739
   404
		}
slouken@786
   405
		if ( CPU_haveMMXExt() ) {
slouken@786
   406
			SDL_CPUFeatures |= CPU_HAS_MMXEXT;
slouken@786
   407
		}
slouken@739
   408
		if ( CPU_have3DNow() ) {
slouken@739
   409
			SDL_CPUFeatures |= CPU_HAS_3DNOW;
slouken@739
   410
		}
slouken@786
   411
		if ( CPU_have3DNowExt() ) {
slouken@786
   412
			SDL_CPUFeatures |= CPU_HAS_3DNOWEXT;
slouken@786
   413
		}
slouken@739
   414
		if ( CPU_haveSSE() ) {
slouken@739
   415
			SDL_CPUFeatures |= CPU_HAS_SSE;
slouken@739
   416
		}
slouken@786
   417
		if ( CPU_haveSSE2() ) {
slouken@786
   418
			SDL_CPUFeatures |= CPU_HAS_SSE2;
slouken@786
   419
		}
slouken@778
   420
		if ( CPU_haveAltiVec() ) {
slouken@778
   421
			SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
slouken@778
   422
		}
slouken@739
   423
	}
slouken@739
   424
	return SDL_CPUFeatures;
slouken@739
   425
}
slouken@739
   426
slouken@1426
   427
SDL_bool SDL_HasRDTSC(void)
slouken@745
   428
{
slouken@745
   429
	if ( SDL_GetCPUFeatures() & CPU_HAS_RDTSC ) {
slouken@745
   430
		return SDL_TRUE;
slouken@745
   431
	}
slouken@745
   432
	return SDL_FALSE;
slouken@745
   433
}
slouken@745
   434
slouken@1426
   435
SDL_bool SDL_HasMMX(void)
slouken@739
   436
{
slouken@739
   437
	if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) {
slouken@739
   438
		return SDL_TRUE;
slouken@739
   439
	}
slouken@739
   440
	return SDL_FALSE;
slouken@739
   441
}
slouken@739
   442
slouken@1426
   443
SDL_bool SDL_HasMMXExt(void)
slouken@804
   444
{
slouken@804
   445
	if ( SDL_GetCPUFeatures() & CPU_HAS_MMXEXT ) {
slouken@804
   446
		return SDL_TRUE;
slouken@804
   447
	}
slouken@804
   448
	return SDL_FALSE;
slouken@804
   449
}
slouken@804
   450
slouken@1426
   451
SDL_bool SDL_Has3DNow(void)
slouken@739
   452
{
slouken@739
   453
	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) {
slouken@739
   454
		return SDL_TRUE;
slouken@739
   455
	}
slouken@739
   456
	return SDL_FALSE;
slouken@739
   457
}
slouken@739
   458
slouken@1426
   459
SDL_bool SDL_Has3DNowExt(void)
slouken@804
   460
{
slouken@804
   461
	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT ) {
slouken@804
   462
		return SDL_TRUE;
slouken@804
   463
	}
slouken@804
   464
	return SDL_FALSE;
slouken@804
   465
}
slouken@804
   466
slouken@1426
   467
SDL_bool SDL_HasSSE(void)
slouken@739
   468
{
slouken@739
   469
	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) {
slouken@739
   470
		return SDL_TRUE;
slouken@739
   471
	}
slouken@739
   472
	return SDL_FALSE;
slouken@739
   473
}
slouken@739
   474
slouken@1426
   475
SDL_bool SDL_HasSSE2(void)
slouken@804
   476
{
slouken@804
   477
	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE2 ) {
slouken@804
   478
		return SDL_TRUE;
slouken@804
   479
	}
slouken@804
   480
	return SDL_FALSE;
slouken@804
   481
}
slouken@804
   482
slouken@1426
   483
SDL_bool SDL_HasAltiVec(void)
slouken@778
   484
{
slouken@778
   485
	if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) {
slouken@778
   486
		return SDL_TRUE;
slouken@778
   487
	}
slouken@778
   488
	return SDL_FALSE;
slouken@778
   489
}
slouken@778
   490
slouken@739
   491
#ifdef TEST_MAIN
slouken@739
   492
slouken@739
   493
#include <stdio.h>
slouken@739
   494
slouken@739
   495
int main()
slouken@739
   496
{
slouken@778
   497
	printf("RDTSC: %d\n", SDL_HasRDTSC());
slouken@739
   498
	printf("MMX: %d\n", SDL_HasMMX());
slouken@785
   499
	printf("MMXExt: %d\n", SDL_HasMMXExt());
slouken@739
   500
	printf("3DNow: %d\n", SDL_Has3DNow());
slouken@785
   501
	printf("3DNowExt: %d\n", SDL_Has3DNowExt());
slouken@739
   502
	printf("SSE: %d\n", SDL_HasSSE());
slouken@785
   503
	printf("SSE2: %d\n", SDL_HasSSE2());
slouken@778
   504
	printf("AltiVec: %d\n", SDL_HasAltiVec());
slouken@745
   505
	return 0;
slouken@739
   506
}
slouken@739
   507
slouken@739
   508
#endif /* TEST_MAIN */