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