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