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