src/cpuinfo/SDL_cpuinfo.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 01 Jul 2009 19:06:31 +0000
branchSDL-1.2
changeset 4180 0a9a29fc00c2
parent 4159 a1b03ba2fcd0
child 4242 fa62bede8038
permissions -rw-r--r--
Patch from Fedora project to fix crashes with SDL_HasSSE() on amd64.

Fixes Bugzilla #760. (...and bugzilla.redhat.com #487720).
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@1590
    29
#if defined(__MACOSX__) && defined(__ppc__)
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@785
   151
"        movl    %%ebx,%%edi\n"
slouken@745
   152
"        xorl    %%eax,%%eax         # Set up for CPUID instruction    \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@745
   159
"        movl    %%edx,%0                                              \n"
slouken@745
   160
"1:                                                                    \n"
slouken@785
   161
"        movl    %%edi,%%ebx\n"
slouken@784
   162
	: "=m" (features)
slouken@745
   163
	:
slouken@887
   164
	: "%eax", "%ecx", "%edx", "%edi"
slouken@745
   165
	);
icculus@4180
   166
#elif defined(__GNUC__) && defined(__x86_64__)
icculus@4180
   167
	__asm__ (
icculus@4180
   168
"        movq    %%rbx,%%rdi\n"
icculus@4180
   169
"        xorl    %%eax,%%eax         # Set up for CPUID instruction    \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"
icculus@4180
   176
"        movl    %%edx,%0                                              \n"
icculus@4180
   177
"1:                                                                    \n"
icculus@4180
   178
"        movq    %%rdi,%%rbx\n"
icculus@4180
   179
	: "=m" (features)
icculus@4180
   180
	:
icculus@4180
   181
	: "%rax", "%rcx", "%rdx", "%rdi"
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@745
   186
        cpuid                       ; Get and save vendor ID
slouken@745
   187
        cmp     eax, 1              ; Make sure 1 is valid input for CPUID
slouken@745
   188
        jl      done                ; We dont have the CPUID instruction
slouken@745
   189
        xor     eax, eax
slouken@745
   190
        inc     eax
slouken@745
   191
        cpuid                       ; Get family/model/stepping/features
slouken@745
   192
        mov     features, edx
slouken@745
   193
done:
slouken@745
   194
	}
slouken@1864
   195
#elif defined(__sun) && (defined(__i386) || defined(__amd64))
icculus@1229
   196
	    __asm(
icculus@1229
   197
"        movl    %ebx,%edi\n"
icculus@1229
   198
"        xorl    %eax,%eax         \n"
icculus@1229
   199
"        cpuid                     \n"
icculus@1229
   200
"        cmpl    $1,%eax           \n"
icculus@1229
   201
"        jl      1f                \n"
icculus@1229
   202
"        xorl    %eax,%eax         \n"
icculus@1229
   203
"        incl    %eax              \n"
icculus@1229
   204
"        cpuid                     \n"
icculus@1229
   205
#ifdef __i386
icculus@1229
   206
"        movl    %edx,-8(%ebp)     \n"
icculus@1229
   207
#else
icculus@1229
   208
"        movl    %edx,-8(%rbp)     \n"
icculus@1229
   209
#endif
icculus@1229
   210
"1:                                \n"
icculus@1229
   211
"        movl    %edi,%ebx\n" );
slouken@745
   212
#endif
slouken@745
   213
	return features;
slouken@745
   214
}
slouken@745
   215
slouken@1426
   216
static __inline__ int CPU_getCPUIDFeaturesExt(void)
slouken@785
   217
{
slouken@785
   218
	int features = 0;
icculus@4180
   219
#if defined(__GNUC__) && defined(i386)
slouken@785
   220
	__asm__ (
slouken@785
   221
"        movl    %%ebx,%%edi\n"
slouken@785
   222
"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
slouken@785
   223
"        cpuid                       # Get extended function limit     \n"
slouken@785
   224
"        cmpl    $0x80000001,%%eax                                     \n"
slouken@787
   225
"        jl      1f                  # Nope, we dont have function 800000001h\n"
slouken@785
   226
"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
slouken@785
   227
"        cpuid                       # and get the information         \n"
slouken@785
   228
"        movl    %%edx,%0                                              \n"
slouken@785
   229
"1:                                                                    \n"
slouken@785
   230
"        movl    %%edi,%%ebx\n"
slouken@785
   231
	: "=m" (features)
slouken@785
   232
	:
slouken@887
   233
	: "%eax", "%ecx", "%edx", "%edi"
slouken@785
   234
	);
icculus@4180
   235
#elif defined(__GNUC__) && defined (__x86_64__)
icculus@4180
   236
	__asm__ (
icculus@4180
   237
"        movq    %%rbx,%%rdi\n"
icculus@4180
   238
"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
icculus@4180
   239
"        cpuid                       # Get extended function limit     \n"
icculus@4180
   240
"        cmpl    $0x80000001,%%eax                                     \n"
icculus@4180
   241
"        jl      1f                  # Nope, we dont have function 800000001h\n"
icculus@4180
   242
"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
icculus@4180
   243
"        cpuid                       # and get the information         \n"
icculus@4180
   244
"        movl    %%edx,%0                                              \n"
icculus@4180
   245
"1:                                                                    \n"
icculus@4180
   246
"        movq    %%rdi,%%rbx\n"
icculus@4180
   247
	: "=m" (features)
icculus@4180
   248
	:
icculus@4180
   249
	: "%rax", "%rcx", "%rdx", "%rdi"
icculus@4180
   250
	);
slouken@1442
   251
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
slouken@785
   252
	__asm {
slouken@785
   253
        mov     eax,80000000h       ; Query for extended functions
slouken@785
   254
        cpuid                       ; Get extended function limit
slouken@785
   255
        cmp     eax,80000001h
slouken@787
   256
        jl      done                ; Nope, we dont have function 800000001h
slouken@785
   257
        mov     eax,80000001h       ; Setup extended function 800000001h
slouken@785
   258
        cpuid                       ; and get the information
slouken@785
   259
        mov     features,edx
slouken@785
   260
done:
slouken@785
   261
	}
icculus@1229
   262
#elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
icculus@1229
   263
	    __asm (
icculus@1229
   264
"        movl    %ebx,%edi\n"
icculus@1229
   265
"        movl    $0x80000000,%eax \n"
icculus@1229
   266
"        cpuid                    \n"
icculus@1229
   267
"        cmpl    $0x80000001,%eax \n"
icculus@1229
   268
"        jl      1f               \n"
icculus@1229
   269
"        movl    $0x80000001,%eax \n"
icculus@1229
   270
"        cpuid                    \n"
icculus@1229
   271
#ifdef __i386
icculus@1229
   272
"        movl    %edx,-8(%ebp)   \n"
icculus@1229
   273
#else
icculus@1229
   274
"        movl    %edx,-8(%rbp)   \n"
icculus@1229
   275
#endif
icculus@1229
   276
"1:                               \n"
icculus@1229
   277
"        movl    %edi,%ebx\n"
icculus@1229
   278
	    );
slouken@785
   279
#endif
slouken@785
   280
	return features;
slouken@785
   281
}
slouken@785
   282
slouken@1426
   283
static __inline__ int CPU_haveRDTSC(void)
slouken@745
   284
{
slouken@745
   285
	if ( CPU_haveCPUID() ) {
slouken@745
   286
		return (CPU_getCPUIDFeatures() & 0x00000010);
slouken@745
   287
	}
slouken@745
   288
	return 0;
slouken@745
   289
}
slouken@745
   290
slouken@1426
   291
static __inline__ int CPU_haveMMX(void)
slouken@745
   292
{
slouken@745
   293
	if ( CPU_haveCPUID() ) {
slouken@745
   294
		return (CPU_getCPUIDFeatures() & 0x00800000);
slouken@745
   295
	}
slouken@745
   296
	return 0;
slouken@745
   297
}
slouken@745
   298
slouken@1426
   299
static __inline__ int CPU_haveMMXExt(void)
slouken@785
   300
{
slouken@785
   301
	if ( CPU_haveCPUID() ) {
slouken@785
   302
		return (CPU_getCPUIDFeaturesExt() & 0x00400000);
slouken@785
   303
	}
slouken@785
   304
	return 0;
slouken@785
   305
}
slouken@785
   306
slouken@1426
   307
static __inline__ int CPU_have3DNow(void)
slouken@745
   308
{
slouken@785
   309
	if ( CPU_haveCPUID() ) {
slouken@785
   310
		return (CPU_getCPUIDFeaturesExt() & 0x80000000);
slouken@747
   311
	}
slouken@785
   312
	return 0;
slouken@785
   313
}
slouken@785
   314
slouken@1426
   315
static __inline__ int CPU_have3DNowExt(void)
slouken@785
   316
{
slouken@785
   317
	if ( CPU_haveCPUID() ) {
slouken@785
   318
		return (CPU_getCPUIDFeaturesExt() & 0x40000000);
slouken@745
   319
	}
slouken@785
   320
	return 0;
slouken@745
   321
}
slouken@745
   322
slouken@1426
   323
static __inline__ int CPU_haveSSE(void)
slouken@745
   324
{
slouken@745
   325
	if ( CPU_haveCPUID() ) {
slouken@745
   326
		return (CPU_getCPUIDFeatures() & 0x02000000);
slouken@745
   327
	}
slouken@745
   328
	return 0;
slouken@745
   329
}
slouken@739
   330
slouken@1426
   331
static __inline__ int CPU_haveSSE2(void)
slouken@785
   332
{
slouken@785
   333
	if ( CPU_haveCPUID() ) {
slouken@785
   334
		return (CPU_getCPUIDFeatures() & 0x04000000);
slouken@785
   335
	}
slouken@785
   336
	return 0;
slouken@785
   337
}
slouken@785
   338
slouken@1426
   339
static __inline__ int CPU_haveAltiVec(void)
slouken@778
   340
{
slouken@796
   341
	volatile int altivec = 0;
slouken@1590
   342
#if defined(__MACOSX__) && defined(__ppc__)
slouken@778
   343
	int selectors[2] = { CTL_HW, HW_VECTORUNIT }; 
slouken@778
   344
	int hasVectorUnit = 0; 
slouken@778
   345
	size_t length = sizeof(hasVectorUnit); 
slouken@778
   346
	int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); 
slouken@778
   347
	if( 0 == error )
slouken@793
   348
		altivec = (hasVectorUnit != 0); 
slouken@1361
   349
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
slouken@793
   350
	void (*handler)(int sig);
slouken@793
   351
	handler = signal(SIGILL, illegal_instruction);
slouken@793
   352
	if ( setjmp(jmpbuf) == 0 ) {
slouken@793
   353
		asm volatile ("mtspr 256, %0\n\t"
slouken@793
   354
			      "vand %%v0, %%v0, %%v0"
slouken@793
   355
			      :
slouken@793
   356
			      : "r" (-1));
slouken@793
   357
		altivec = 1;
slouken@793
   358
	}
slouken@793
   359
	signal(SIGILL, handler);
slouken@778
   360
#endif
slouken@793
   361
	return altivec; 
slouken@778
   362
}
slouken@778
   363
slouken@739
   364
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
slouken@739
   365
slouken@1426
   366
static Uint32 SDL_GetCPUFeatures(void)
slouken@739
   367
{
slouken@739
   368
	if ( SDL_CPUFeatures == 0xFFFFFFFF ) {
slouken@739
   369
		SDL_CPUFeatures = 0;
slouken@745
   370
		if ( CPU_haveRDTSC() ) {
slouken@745
   371
			SDL_CPUFeatures |= CPU_HAS_RDTSC;
slouken@745
   372
		}
slouken@739
   373
		if ( CPU_haveMMX() ) {
slouken@739
   374
			SDL_CPUFeatures |= CPU_HAS_MMX;
slouken@739
   375
		}
slouken@786
   376
		if ( CPU_haveMMXExt() ) {
slouken@786
   377
			SDL_CPUFeatures |= CPU_HAS_MMXEXT;
slouken@786
   378
		}
slouken@739
   379
		if ( CPU_have3DNow() ) {
slouken@739
   380
			SDL_CPUFeatures |= CPU_HAS_3DNOW;
slouken@739
   381
		}
slouken@786
   382
		if ( CPU_have3DNowExt() ) {
slouken@786
   383
			SDL_CPUFeatures |= CPU_HAS_3DNOWEXT;
slouken@786
   384
		}
slouken@739
   385
		if ( CPU_haveSSE() ) {
slouken@739
   386
			SDL_CPUFeatures |= CPU_HAS_SSE;
slouken@739
   387
		}
slouken@786
   388
		if ( CPU_haveSSE2() ) {
slouken@786
   389
			SDL_CPUFeatures |= CPU_HAS_SSE2;
slouken@786
   390
		}
slouken@778
   391
		if ( CPU_haveAltiVec() ) {
slouken@778
   392
			SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
slouken@778
   393
		}
slouken@739
   394
	}
slouken@739
   395
	return SDL_CPUFeatures;
slouken@739
   396
}
slouken@739
   397
slouken@1426
   398
SDL_bool SDL_HasRDTSC(void)
slouken@745
   399
{
slouken@745
   400
	if ( SDL_GetCPUFeatures() & CPU_HAS_RDTSC ) {
slouken@745
   401
		return SDL_TRUE;
slouken@745
   402
	}
slouken@745
   403
	return SDL_FALSE;
slouken@745
   404
}
slouken@745
   405
slouken@1426
   406
SDL_bool SDL_HasMMX(void)
slouken@739
   407
{
slouken@739
   408
	if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) {
slouken@739
   409
		return SDL_TRUE;
slouken@739
   410
	}
slouken@739
   411
	return SDL_FALSE;
slouken@739
   412
}
slouken@739
   413
slouken@1426
   414
SDL_bool SDL_HasMMXExt(void)
slouken@804
   415
{
slouken@804
   416
	if ( SDL_GetCPUFeatures() & CPU_HAS_MMXEXT ) {
slouken@804
   417
		return SDL_TRUE;
slouken@804
   418
	}
slouken@804
   419
	return SDL_FALSE;
slouken@804
   420
}
slouken@804
   421
slouken@1426
   422
SDL_bool SDL_Has3DNow(void)
slouken@739
   423
{
slouken@739
   424
	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) {
slouken@739
   425
		return SDL_TRUE;
slouken@739
   426
	}
slouken@739
   427
	return SDL_FALSE;
slouken@739
   428
}
slouken@739
   429
slouken@1426
   430
SDL_bool SDL_Has3DNowExt(void)
slouken@804
   431
{
slouken@804
   432
	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT ) {
slouken@804
   433
		return SDL_TRUE;
slouken@804
   434
	}
slouken@804
   435
	return SDL_FALSE;
slouken@804
   436
}
slouken@804
   437
slouken@1426
   438
SDL_bool SDL_HasSSE(void)
slouken@739
   439
{
slouken@739
   440
	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) {
slouken@739
   441
		return SDL_TRUE;
slouken@739
   442
	}
slouken@739
   443
	return SDL_FALSE;
slouken@739
   444
}
slouken@739
   445
slouken@1426
   446
SDL_bool SDL_HasSSE2(void)
slouken@804
   447
{
slouken@804
   448
	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE2 ) {
slouken@804
   449
		return SDL_TRUE;
slouken@804
   450
	}
slouken@804
   451
	return SDL_FALSE;
slouken@804
   452
}
slouken@804
   453
slouken@1426
   454
SDL_bool SDL_HasAltiVec(void)
slouken@778
   455
{
slouken@778
   456
	if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) {
slouken@778
   457
		return SDL_TRUE;
slouken@778
   458
	}
slouken@778
   459
	return SDL_FALSE;
slouken@778
   460
}
slouken@778
   461
slouken@739
   462
#ifdef TEST_MAIN
slouken@739
   463
slouken@739
   464
#include <stdio.h>
slouken@739
   465
slouken@739
   466
int main()
slouken@739
   467
{
slouken@778
   468
	printf("RDTSC: %d\n", SDL_HasRDTSC());
slouken@739
   469
	printf("MMX: %d\n", SDL_HasMMX());
slouken@785
   470
	printf("MMXExt: %d\n", SDL_HasMMXExt());
slouken@739
   471
	printf("3DNow: %d\n", SDL_Has3DNow());
slouken@785
   472
	printf("3DNowExt: %d\n", SDL_Has3DNowExt());
slouken@739
   473
	printf("SSE: %d\n", SDL_HasSSE());
slouken@785
   474
	printf("SSE2: %d\n", SDL_HasSSE2());
slouken@778
   475
	printf("AltiVec: %d\n", SDL_HasAltiVec());
slouken@745
   476
	return 0;
slouken@739
   477
}
slouken@739
   478
slouken@739
   479
#endif /* TEST_MAIN */