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