src/cpuinfo/SDL_cpuinfo.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 02 Dec 2009 16:24:21 +0000
branchSDL-1.2
changeset 4386 dcb26ac38e6b
parent 4372 ca91f36ef3de
child 4387 72d3b4fd918b
permissions -rw-r--r--
Fixed crash - need to save and restore rbx around cpuid, since the compiler may be assuming the stack pointer isn't being modified when filling in %0.

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