src/cpuinfo/SDL_cpuinfo.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 18 Jul 2012 13:08:19 -0700
branchSDL-1.2
changeset 6364 4a08ade5b4c9
parent 6137 4720145f848b
child 6908 8b9fcdd925d8
permissions -rw-r--r--
Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc

Brad Smith 2012-02-29 19:31:46 PST

The attached patch adds AltiVec detection for OpenBSD/powerpc. Please apply the
patch to both 2.0 and 1.2.
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"
slouken@745
   226
#endif
slouken@745
   227
	return features;
slouken@745
   228
}
slouken@745
   229
slouken@1426
   230
static __inline__ int CPU_getCPUIDFeaturesExt(void)
slouken@785
   231
{
slouken@785
   232
	int features = 0;
icculus@4180
   233
#if defined(__GNUC__) && defined(i386)
slouken@785
   234
	__asm__ (
slouken@785
   235
"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
slouken@4386
   236
"        pushl   %%ebx                                                 \n"
slouken@785
   237
"        cpuid                       # Get extended function limit     \n"
slouken@4387
   238
"        popl    %%ebx                                                 \n"
slouken@785
   239
"        cmpl    $0x80000001,%%eax                                     \n"
slouken@787
   240
"        jl      1f                  # Nope, we dont have function 800000001h\n"
slouken@785
   241
"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
slouken@4387
   242
"        pushl   %%ebx                                                 \n"
slouken@785
   243
"        cpuid                       # and get the information         \n"
slouken@4386
   244
"        popl    %%ebx                                                 \n"
slouken@785
   245
"        movl    %%edx,%0                                              \n"
slouken@785
   246
"1:                                                                    \n"
slouken@785
   247
	: "=m" (features)
slouken@785
   248
	:
icculus@4372
   249
	: "%eax", "%ecx", "%edx"
slouken@785
   250
	);
icculus@4180
   251
#elif defined(__GNUC__) && defined (__x86_64__)
icculus@4180
   252
	__asm__ (
icculus@4180
   253
"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
slouken@4386
   254
"        pushq   %%rbx                                                 \n"
icculus@4180
   255
"        cpuid                       # Get extended function limit     \n"
slouken@4387
   256
"        popq    %%rbx                                                 \n"
icculus@4180
   257
"        cmpl    $0x80000001,%%eax                                     \n"
icculus@4180
   258
"        jl      1f                  # Nope, we dont have function 800000001h\n"
icculus@4180
   259
"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
slouken@4387
   260
"        pushq   %%rbx                                                 \n"
icculus@4180
   261
"        cpuid                       # and get the information         \n"
slouken@4386
   262
"        popq    %%rbx                                                 \n"
icculus@4180
   263
"        movl    %%edx,%0                                              \n"
icculus@4180
   264
"1:                                                                    \n"
icculus@4180
   265
	: "=m" (features)
icculus@4180
   266
	:
icculus@4372
   267
	: "%rax", "%rcx", "%rdx"
icculus@4180
   268
	);
slouken@1442
   269
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
slouken@785
   270
	__asm {
slouken@785
   271
        mov     eax,80000000h       ; Query for extended functions
slouken@4386
   272
        push    ebx
slouken@785
   273
        cpuid                       ; Get extended function limit
slouken@4387
   274
        pop     ebx
slouken@785
   275
        cmp     eax,80000001h
slouken@787
   276
        jl      done                ; Nope, we dont have function 800000001h
slouken@785
   277
        mov     eax,80000001h       ; Setup extended function 800000001h
slouken@4387
   278
        push    ebx
slouken@785
   279
        cpuid                       ; and get the information
slouken@4386
   280
        pop     ebx
slouken@785
   281
        mov     features,edx
slouken@785
   282
done:
slouken@785
   283
	}
icculus@1229
   284
#elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
icculus@1229
   285
	    __asm (
icculus@1229
   286
"        movl    $0x80000000,%eax \n"
slouken@4386
   287
"        pushl   %ebx             \n"
icculus@1229
   288
"        cpuid                    \n"
slouken@4387
   289
"        popl    %ebx             \n"
icculus@1229
   290
"        cmpl    $0x80000001,%eax \n"
icculus@1229
   291
"        jl      1f               \n"
icculus@1229
   292
"        movl    $0x80000001,%eax \n"
slouken@4387
   293
"        pushl   %ebx             \n"
icculus@1229
   294
"        cpuid                    \n"
slouken@4386
   295
"        popl    %ebx             \n"
icculus@1229
   296
#ifdef __i386
icculus@1229
   297
"        movl    %edx,-8(%ebp)   \n"
icculus@1229
   298
#else
icculus@1229
   299
"        movl    %edx,-8(%rbp)   \n"
icculus@1229
   300
#endif
icculus@1229
   301
"1:                               \n"
icculus@1229
   302
	    );
slouken@785
   303
#endif
slouken@785
   304
	return features;
slouken@785
   305
}
slouken@785
   306
slouken@1426
   307
static __inline__ int CPU_haveRDTSC(void)
slouken@745
   308
{
slouken@745
   309
	if ( CPU_haveCPUID() ) {
slouken@745
   310
		return (CPU_getCPUIDFeatures() & 0x00000010);
slouken@745
   311
	}
slouken@745
   312
	return 0;
slouken@745
   313
}
slouken@745
   314
slouken@1426
   315
static __inline__ int CPU_haveMMX(void)
slouken@745
   316
{
slouken@745
   317
	if ( CPU_haveCPUID() ) {
slouken@745
   318
		return (CPU_getCPUIDFeatures() & 0x00800000);
slouken@745
   319
	}
slouken@745
   320
	return 0;
slouken@745
   321
}
slouken@745
   322
slouken@1426
   323
static __inline__ int CPU_haveMMXExt(void)
slouken@785
   324
{
slouken@785
   325
	if ( CPU_haveCPUID() ) {
slouken@785
   326
		return (CPU_getCPUIDFeaturesExt() & 0x00400000);
slouken@785
   327
	}
slouken@785
   328
	return 0;
slouken@785
   329
}
slouken@785
   330
slouken@1426
   331
static __inline__ int CPU_have3DNow(void)
slouken@745
   332
{
slouken@785
   333
	if ( CPU_haveCPUID() ) {
slouken@785
   334
		return (CPU_getCPUIDFeaturesExt() & 0x80000000);
slouken@747
   335
	}
slouken@785
   336
	return 0;
slouken@785
   337
}
slouken@785
   338
slouken@1426
   339
static __inline__ int CPU_have3DNowExt(void)
slouken@785
   340
{
slouken@785
   341
	if ( CPU_haveCPUID() ) {
slouken@785
   342
		return (CPU_getCPUIDFeaturesExt() & 0x40000000);
slouken@745
   343
	}
slouken@785
   344
	return 0;
slouken@745
   345
}
slouken@745
   346
slouken@1426
   347
static __inline__ int CPU_haveSSE(void)
slouken@745
   348
{
slouken@745
   349
	if ( CPU_haveCPUID() ) {
slouken@745
   350
		return (CPU_getCPUIDFeatures() & 0x02000000);
slouken@745
   351
	}
slouken@745
   352
	return 0;
slouken@745
   353
}
slouken@739
   354
slouken@1426
   355
static __inline__ int CPU_haveSSE2(void)
slouken@785
   356
{
slouken@785
   357
	if ( CPU_haveCPUID() ) {
slouken@785
   358
		return (CPU_getCPUIDFeatures() & 0x04000000);
slouken@785
   359
	}
slouken@785
   360
	return 0;
slouken@785
   361
}
slouken@785
   362
slouken@1426
   363
static __inline__ int CPU_haveAltiVec(void)
slouken@778
   364
{
slouken@796
   365
	volatile int altivec = 0;
slouken@6364
   366
#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
slouken@6364
   367
# ifdef __OpenBSD__
slouken@6364
   368
	int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
slouken@6364
   369
# else
slouken@6364
   370
	int selectors[2] = { CTL_HW, HW_VECTORUNIT };
slouken@6364
   371
# endif
slouken@778
   372
	int hasVectorUnit = 0; 
slouken@778
   373
	size_t length = sizeof(hasVectorUnit); 
slouken@778
   374
	int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); 
slouken@778
   375
	if( 0 == error )
slouken@793
   376
		altivec = (hasVectorUnit != 0); 
slouken@1361
   377
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
slouken@793
   378
	void (*handler)(int sig);
slouken@793
   379
	handler = signal(SIGILL, illegal_instruction);
slouken@793
   380
	if ( setjmp(jmpbuf) == 0 ) {
slouken@793
   381
		asm volatile ("mtspr 256, %0\n\t"
slouken@793
   382
			      "vand %%v0, %%v0, %%v0"
slouken@793
   383
			      :
slouken@793
   384
			      : "r" (-1));
slouken@793
   385
		altivec = 1;
slouken@793
   386
	}
slouken@793
   387
	signal(SIGILL, handler);
slouken@778
   388
#endif
slouken@793
   389
	return altivec; 
slouken@778
   390
}
slouken@778
   391
slouken@739
   392
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
slouken@739
   393
slouken@1426
   394
static Uint32 SDL_GetCPUFeatures(void)
slouken@739
   395
{
slouken@739
   396
	if ( SDL_CPUFeatures == 0xFFFFFFFF ) {
slouken@739
   397
		SDL_CPUFeatures = 0;
slouken@745
   398
		if ( CPU_haveRDTSC() ) {
slouken@745
   399
			SDL_CPUFeatures |= CPU_HAS_RDTSC;
slouken@745
   400
		}
slouken@739
   401
		if ( CPU_haveMMX() ) {
slouken@739
   402
			SDL_CPUFeatures |= CPU_HAS_MMX;
slouken@739
   403
		}
slouken@786
   404
		if ( CPU_haveMMXExt() ) {
slouken@786
   405
			SDL_CPUFeatures |= CPU_HAS_MMXEXT;
slouken@786
   406
		}
slouken@739
   407
		if ( CPU_have3DNow() ) {
slouken@739
   408
			SDL_CPUFeatures |= CPU_HAS_3DNOW;
slouken@739
   409
		}
slouken@786
   410
		if ( CPU_have3DNowExt() ) {
slouken@786
   411
			SDL_CPUFeatures |= CPU_HAS_3DNOWEXT;
slouken@786
   412
		}
slouken@739
   413
		if ( CPU_haveSSE() ) {
slouken@739
   414
			SDL_CPUFeatures |= CPU_HAS_SSE;
slouken@739
   415
		}
slouken@786
   416
		if ( CPU_haveSSE2() ) {
slouken@786
   417
			SDL_CPUFeatures |= CPU_HAS_SSE2;
slouken@786
   418
		}
slouken@778
   419
		if ( CPU_haveAltiVec() ) {
slouken@778
   420
			SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
slouken@778
   421
		}
slouken@739
   422
	}
slouken@739
   423
	return SDL_CPUFeatures;
slouken@739
   424
}
slouken@739
   425
slouken@1426
   426
SDL_bool SDL_HasRDTSC(void)
slouken@745
   427
{
slouken@745
   428
	if ( SDL_GetCPUFeatures() & CPU_HAS_RDTSC ) {
slouken@745
   429
		return SDL_TRUE;
slouken@745
   430
	}
slouken@745
   431
	return SDL_FALSE;
slouken@745
   432
}
slouken@745
   433
slouken@1426
   434
SDL_bool SDL_HasMMX(void)
slouken@739
   435
{
slouken@739
   436
	if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) {
slouken@739
   437
		return SDL_TRUE;
slouken@739
   438
	}
slouken@739
   439
	return SDL_FALSE;
slouken@739
   440
}
slouken@739
   441
slouken@1426
   442
SDL_bool SDL_HasMMXExt(void)
slouken@804
   443
{
slouken@804
   444
	if ( SDL_GetCPUFeatures() & CPU_HAS_MMXEXT ) {
slouken@804
   445
		return SDL_TRUE;
slouken@804
   446
	}
slouken@804
   447
	return SDL_FALSE;
slouken@804
   448
}
slouken@804
   449
slouken@1426
   450
SDL_bool SDL_Has3DNow(void)
slouken@739
   451
{
slouken@739
   452
	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) {
slouken@739
   453
		return SDL_TRUE;
slouken@739
   454
	}
slouken@739
   455
	return SDL_FALSE;
slouken@739
   456
}
slouken@739
   457
slouken@1426
   458
SDL_bool SDL_Has3DNowExt(void)
slouken@804
   459
{
slouken@804
   460
	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT ) {
slouken@804
   461
		return SDL_TRUE;
slouken@804
   462
	}
slouken@804
   463
	return SDL_FALSE;
slouken@804
   464
}
slouken@804
   465
slouken@1426
   466
SDL_bool SDL_HasSSE(void)
slouken@739
   467
{
slouken@739
   468
	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) {
slouken@739
   469
		return SDL_TRUE;
slouken@739
   470
	}
slouken@739
   471
	return SDL_FALSE;
slouken@739
   472
}
slouken@739
   473
slouken@1426
   474
SDL_bool SDL_HasSSE2(void)
slouken@804
   475
{
slouken@804
   476
	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE2 ) {
slouken@804
   477
		return SDL_TRUE;
slouken@804
   478
	}
slouken@804
   479
	return SDL_FALSE;
slouken@804
   480
}
slouken@804
   481
slouken@1426
   482
SDL_bool SDL_HasAltiVec(void)
slouken@778
   483
{
slouken@778
   484
	if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) {
slouken@778
   485
		return SDL_TRUE;
slouken@778
   486
	}
slouken@778
   487
	return SDL_FALSE;
slouken@778
   488
}
slouken@778
   489
slouken@739
   490
#ifdef TEST_MAIN
slouken@739
   491
slouken@739
   492
#include <stdio.h>
slouken@739
   493
slouken@739
   494
int main()
slouken@739
   495
{
slouken@778
   496
	printf("RDTSC: %d\n", SDL_HasRDTSC());
slouken@739
   497
	printf("MMX: %d\n", SDL_HasMMX());
slouken@785
   498
	printf("MMXExt: %d\n", SDL_HasMMXExt());
slouken@739
   499
	printf("3DNow: %d\n", SDL_Has3DNow());
slouken@785
   500
	printf("3DNowExt: %d\n", SDL_Has3DNowExt());
slouken@739
   501
	printf("SSE: %d\n", SDL_HasSSE());
slouken@785
   502
	printf("SSE2: %d\n", SDL_HasSSE2());
slouken@778
   503
	printf("AltiVec: %d\n", SDL_HasAltiVec());
slouken@745
   504
	return 0;
slouken@739
   505
}
slouken@739
   506
slouken@739
   507
#endif /* TEST_MAIN */