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