src/cpuinfo/SDL_cpuinfo.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 22 Feb 2014 18:01:18 -0800
changeset 8240 334257cd613d
parent 8149 681eb46b8ac4
child 8241 b6d5a589ce3f
permissions -rw-r--r--
Fixed bug 2335 - Fails to build on Debian GNU/kFreeBSD Felix Geyer Starting from version 2.0.1 libsdl fails to build on Debian GNU/kFreeBSD in SDL_cpuinfo.c. GNU/kFreeBSD defines __FreeBSD_kernel__ but not __FreeBSD__. The #ifdef __FreeBSD__ check should be extended for __FreeBSD_kernel__, see the attached patch. Build log: libtool: compile: gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -DUSING_GENERATED_CONFIG_H -Iinclude -I/«BUILDDIR»/libsdl2-2.0.1+dfsg1/include -mmmx -m3dnow -msse -msse2 -fvisibility=hidden -D_REENTRANT -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-kfreebsd-gnu/dbus-1.0/include -DHAVE_USBHID_H -DUSBHID_NEW -D_REENTRANT -Wall -c /«BUILDDIR»/libsdl2-2.0.1+dfsg1/src/cpuinfo/SDL_cpuinfo.c -fPIC -DPIC -o build/.libs/SDL_cpuinfo.o /«BUILDDIR»/libsdl2-2.0.1+dfsg1/src/cpuinfo/SDL_cpuinfo.c: In function 'SDL_GetSystemRAM': /«BUILDDIR»/libsdl2-2.0.1+dfsg1/src/cpuinfo/SDL_cpuinfo.c:632:35: error: 'HW_MEMSIZE' undeclared (first use in this function) int mib[2] = {CTL_HW, HW_MEMSIZE}; ^ /«BUILDDIR»/libsdl2-2.0.1+dfsg1/src/cpuinfo/SDL_cpuinfo.c:632:35: note: each undeclared identifier is reported only once for each function it appears in make[2]: *** [build/SDL_cpuinfo.lo] Error 1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8148
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
     7
  arising from the use of this software.
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
    11
  freely, subject to the following restrictions:
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8148
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
    21
#ifdef TEST_MAIN
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
    22
#include "SDL_config.h"
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
    23
#else
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7889
diff changeset
    24
#include "../SDL_internal.h"
8148
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
    25
#endif
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
7828
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7826
diff changeset
    27
#if defined(__WIN32__)
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7826
diff changeset
    28
#include "../core/windows/SDL_windows.h"
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7826
diff changeset
    29
#endif
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7826
diff changeset
    30
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
/* CPU feature detection for SDL */
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    33
#include "SDL_cpuinfo.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    34
3586
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
    35
#ifdef HAVE_SYSCONF
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
    36
#include <unistd.h>
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
    37
#endif
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    38
#ifdef HAVE_SYSCTLBYNAME
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    39
#include <sys/types.h>
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    40
#include <sys/sysctl.h>
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    41
#endif
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    42
#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    43
#include <sys/sysctl.h>         /* For AltiVec check */
6363
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    44
#elif defined(__OpenBSD__) && defined(__powerpc__)
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    45
#include <sys/param.h>
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    46
#include <sys/sysctl.h> /* For AltiVec check */
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    47
#include <machine/cpu.h>
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    48
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    49
#include <signal.h>
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    50
#include <setjmp.h>
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    51
#endif
793
c20f08c4f437 Altivec detection on non-MacOS X systems
Sam Lantinga <slouken@libsdl.org>
parents: 787
diff changeset
    52
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    53
#define CPU_HAS_RDTSC   0x00000001
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    54
#define CPU_HAS_ALTIVEC 0x00000002
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    55
#define CPU_HAS_MMX     0x00000004
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    56
#define CPU_HAS_3DNOW   0x00000008
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
    57
#define CPU_HAS_SSE     0x00000010
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
    58
#define CPU_HAS_SSE2    0x00000020
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
    59
#define CPU_HAS_SSE3    0x00000040
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    60
#define CPU_HAS_SSE41   0x00000100
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    61
#define CPU_HAS_SSE42   0x00000200
8148
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
    62
#define CPU_HAS_AVX     0x00000400
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    63
6363
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    64
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    65
/* This is the brute force way of detecting instruction sets...
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    66
   the idea is borrowed from the libmpeg2 library - thanks!
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    67
 */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    68
static jmp_buf jmpbuf;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    69
static void
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    70
illegal_instruction(int sig)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    71
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    72
    longjmp(jmpbuf, 1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    73
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
    74
#endif /* HAVE_SETJMP */
793
c20f08c4f437 Altivec detection on non-MacOS X systems
Sam Lantinga <slouken@libsdl.org>
parents: 787
diff changeset
    75
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
    76
static SDL_INLINE int
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
    77
CPU_haveCPUID(void)
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    78
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
    79
    int has_CPUID = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
    80
/* *INDENT-OFF* */
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    81
#if defined(__GNUC__) && defined(i386)
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    82
    __asm__ (
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    83
"        pushfl                      # Get original EFLAGS             \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    84
"        popl    %%eax                                                 \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    85
"        movl    %%eax,%%ecx                                           \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    86
"        xorl    $0x200000,%%eax     # Flip ID bit in EFLAGS           \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    87
"        pushl   %%eax               # Save new EFLAGS value on stack  \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    88
"        popfl                       # Replace current EFLAGS value    \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    89
"        pushfl                      # Get new EFLAGS                  \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    90
"        popl    %%eax               # Store new EFLAGS in EAX         \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    91
"        xorl    %%ecx,%%eax         # Can not toggle ID bit,          \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    92
"        jz      1f                  # Processor=80486                 \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    93
"        movl    $1,%0               # We have CPUID support           \n"
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
    94
"1:                                                                    \n"
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    95
    : "=m" (has_CPUID)
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    96
    :
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    97
    : "%eax", "%ecx"
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
    98
    );
881
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
    99
#elif defined(__GNUC__) && defined(__x86_64__)
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   100
/* Technically, if this is being compiled under __x86_64__ then it has 
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   101
CPUid by definition.  But it's nice to be able to prove it.  :)      */
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   102
    __asm__ (
881
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   103
"        pushfq                      # Get original EFLAGS             \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   104
"        popq    %%rax                                                 \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   105
"        movq    %%rax,%%rcx                                           \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   106
"        xorl    $0x200000,%%eax     # Flip ID bit in EFLAGS           \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   107
"        pushq   %%rax               # Save new EFLAGS value on stack  \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   108
"        popfq                       # Replace current EFLAGS value    \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   109
"        pushfq                      # Get new EFLAGS                  \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   110
"        popq    %%rax               # Store new EFLAGS in EAX         \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   111
"        xorl    %%ecx,%%eax         # Can not toggle ID bit,          \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   112
"        jz      1f                  # Processor=80486                 \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   113
"        movl    $1,%0               # We have CPUID support           \n"
9eb85a211abd Date: Tue, 30 Mar 2004 18:18:13 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 804
diff changeset
   114
"1:                                                                    \n"
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   115
    : "=m" (has_CPUID)
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   116
    :
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   117
    : "%rax", "%rcx"
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   118
    );
1442
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1426
diff changeset
   119
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   120
    __asm {
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   121
        pushfd                      ; Get original EFLAGS
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   122
        pop     eax
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   123
        mov     ecx, eax
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   124
        xor     eax, 200000h        ; Flip ID bit in EFLAGS
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   125
        push    eax                 ; Save new EFLAGS value on stack
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   126
        popfd                       ; Replace current EFLAGS value
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   127
        pushfd                      ; Get new EFLAGS
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   128
        pop     eax                 ; Store new EFLAGS in EAX
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   129
        xor     eax, ecx            ; Can not toggle ID bit,
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   130
        jz      done                ; Processor=80486
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   131
        mov     has_CPUID,1         ; We have CPUID support
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   132
done:
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   133
    }
1864
7bea26ad3130 I think this fixes bug #244
Sam Lantinga <slouken@libsdl.org>
parents: 1590
diff changeset
   134
#elif defined(__sun) && defined(__i386)
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   135
    __asm (
1229
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   136
"       pushfl                 \n"
3584
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   137
"       popl    %eax           \n"
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   138
"       movl    %eax,%ecx      \n"
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   139
"       xorl    $0x200000,%eax \n"
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   140
"       pushl   %eax           \n"
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   141
"       popfl                  \n"
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   142
"       pushfl                 \n"
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   143
"       popl    %eax           \n"
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   144
"       xorl    %ecx,%eax      \n"
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   145
"       jz      1f             \n"
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   146
"       movl    $1,-8(%ebp)    \n"
1229
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   147
"1:                            \n"
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   148
    );
1229
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   149
#elif defined(__sun) && defined(__amd64)
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   150
    __asm (
1229
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   151
"       pushfq                 \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   152
"       popq    %rax           \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   153
"       movq    %rax,%rcx      \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   154
"       xorl    $0x200000,%eax \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   155
"       pushq   %rax           \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   156
"       popfq                  \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   157
"       pushfq                 \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   158
"       popq    %rax           \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   159
"       xorl    %ecx,%eax      \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   160
"       jz      1f             \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   161
"       movl    $1,-8(%rbp)    \n"
1430f5fe092a Patch from Michael Bonfils to add CPUID support for x86 Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 1198
diff changeset
   162
"1:                            \n"
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   163
    );
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   164
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   165
/* *INDENT-ON* */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   166
    return has_CPUID;
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   167
}
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
3587
2080e8d75ac6 Implemented 64-bit version of cpuid code
Sam Lantinga <slouken@libsdl.org>
parents: 3586
diff changeset
   169
#if defined(__GNUC__) && defined(i386)
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   170
#define cpuid(func, a, b, c, d) \
3584
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   171
    __asm__ __volatile__ ( \
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   172
"        pushl %%ebx        \n" \
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   173
"        cpuid              \n" \
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   174
"        movl %%ebx, %%esi  \n" \
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   175
"        popl %%ebx         \n" : \
41d01d70659c Fixed cpuid assembly to work on PIC code
Sam Lantinga <slouken@libsdl.org>
parents: 3580
diff changeset
   176
            "=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
3587
2080e8d75ac6 Implemented 64-bit version of cpuid code
Sam Lantinga <slouken@libsdl.org>
parents: 3586
diff changeset
   177
#elif defined(__GNUC__) && defined(__x86_64__)
2080e8d75ac6 Implemented 64-bit version of cpuid code
Sam Lantinga <slouken@libsdl.org>
parents: 3586
diff changeset
   178
#define cpuid(func, a, b, c, d) \
2080e8d75ac6 Implemented 64-bit version of cpuid code
Sam Lantinga <slouken@libsdl.org>
parents: 3586
diff changeset
   179
    __asm__ __volatile__ ( \
2080e8d75ac6 Implemented 64-bit version of cpuid code
Sam Lantinga <slouken@libsdl.org>
parents: 3586
diff changeset
   180
"        pushq %%rbx        \n" \
2080e8d75ac6 Implemented 64-bit version of cpuid code
Sam Lantinga <slouken@libsdl.org>
parents: 3586
diff changeset
   181
"        cpuid              \n" \
2080e8d75ac6 Implemented 64-bit version of cpuid code
Sam Lantinga <slouken@libsdl.org>
parents: 3586
diff changeset
   182
"        movq %%rbx, %%rsi  \n" \
2080e8d75ac6 Implemented 64-bit version of cpuid code
Sam Lantinga <slouken@libsdl.org>
parents: 3586
diff changeset
   183
"        popq %%rbx         \n" : \
2080e8d75ac6 Implemented 64-bit version of cpuid code
Sam Lantinga <slouken@libsdl.org>
parents: 3586
diff changeset
   184
            "=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   185
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   186
#define cpuid(func, a, b, c, d) \
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   187
    __asm { \
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   188
        __asm mov eax, func \
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   189
        __asm cpuid \
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   190
        __asm mov a, eax \
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   191
        __asm mov b, ebx \
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   192
        __asm mov c, ecx \
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   193
        __asm mov d, edx \
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   194
    }
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   195
#else
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   196
#define cpuid(func, a, b, c, d) \
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   197
    a = b = c = d = 0
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   198
#endif
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   199
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   200
static SDL_INLINE int
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   201
CPU_getCPUIDFeatures(void)
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   202
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   203
    int features = 0;
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   204
    int a, b, c, d;
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   205
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   206
    cpuid(0, a, b, c, d);
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   207
    if (a >= 1) {
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   208
        cpuid(1, a, b, c, d);
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   209
        features = d;
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   210
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   211
    return features;
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   212
}
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   213
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   214
static SDL_INLINE int
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   215
CPU_haveRDTSC(void)
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   216
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   217
    if (CPU_haveCPUID()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   218
        return (CPU_getCPUIDFeatures() & 0x00000010);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   219
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   220
    return 0;
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   221
}
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   223
static SDL_INLINE int
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   224
CPU_haveAltiVec(void)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   225
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   226
    volatile int altivec = 0;
6363
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   227
#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   228
#ifdef __OpenBSD__
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   229
    int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   230
#else
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   231
    int selectors[2] = { CTL_HW, HW_VECTORUNIT };
6363
8506dd64e859 Fixed bug 1434 - Add AltiVec detection for OpenBSD/powerpc
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   232
#endif
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   233
    int hasVectorUnit = 0;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   234
    size_t length = sizeof(hasVectorUnit);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   235
    int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   236
    if (0 == error)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   237
        altivec = (hasVectorUnit != 0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   238
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   239
    void (*handler) (int sig);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   240
    handler = signal(SIGILL, illegal_instruction);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   241
    if (setjmp(jmpbuf) == 0) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   242
        asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1));
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   243
        altivec = 1;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   244
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   245
    signal(SIGILL, handler);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   246
#endif
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   247
    return altivec;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   248
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   249
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   250
static SDL_INLINE int
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   251
CPU_haveMMX(void)
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   252
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   253
    if (CPU_haveCPUID()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   254
        return (CPU_getCPUIDFeatures() & 0x00800000);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   255
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   256
    return 0;
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   257
}
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   258
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   259
static SDL_INLINE int
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   260
CPU_have3DNow(void)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   261
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   262
    if (CPU_haveCPUID()) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   263
        int a, b, c, d;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   264
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   265
        cpuid(0x80000000, a, b, c, d);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   266
        if (a >= 0x80000001) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   267
            cpuid(0x80000001, a, b, c, d);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   268
            return (d & 0x80000000);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   269
        }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   270
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   271
    return 0;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   272
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   273
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   274
static SDL_INLINE int
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   275
CPU_haveSSE(void)
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   276
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   277
    if (CPU_haveCPUID()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   278
        return (CPU_getCPUIDFeatures() & 0x02000000);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   279
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   280
    return 0;
785
ca06a994f03c Fixed bugs in CPU feature detection and added extended feature detection
Sam Lantinga <slouken@libsdl.org>
parents: 784
diff changeset
   281
}
ca06a994f03c Fixed bugs in CPU feature detection and added extended feature detection
Sam Lantinga <slouken@libsdl.org>
parents: 784
diff changeset
   282
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   283
static SDL_INLINE int
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   284
CPU_haveSSE2(void)
778
8ac3f46f9d09 Date: Tue, 6 Jan 2004 12:42:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   285
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   286
    if (CPU_haveCPUID()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   287
        return (CPU_getCPUIDFeatures() & 0x04000000);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   288
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   289
    return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   290
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   291
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   292
static SDL_INLINE int
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   293
CPU_haveSSE3(void)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   294
{
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   295
    if (CPU_haveCPUID()) {
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   296
        int a, b, c, d;
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   297
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   298
        cpuid(0, a, b, c, d);
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   299
        if (a >= 1) {
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   300
            cpuid(1, a, b, c, d);
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   301
            return (c & 0x00000001);
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   302
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   303
    }
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   304
    return 0;
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   305
}
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   306
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   307
static SDL_INLINE int
5263
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   308
CPU_haveSSE41(void)
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   309
{
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   310
    if (CPU_haveCPUID()) {
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   311
        int a, b, c, d;
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   312
5263
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   313
        cpuid(1, a, b, c, d);
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   314
        if (a >= 1) {
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   315
            cpuid(1, a, b, c, d);
5263
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   316
            return (c & 0x00080000);
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   317
        }
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   318
    }
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   319
    return 0;
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   320
}
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   321
7860
2b0bcdea3a79 Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   322
static SDL_INLINE int
5263
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   323
CPU_haveSSE42(void)
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   324
{
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   325
    if (CPU_haveCPUID()) {
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   326
        int a, b, c, d;
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   327
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   328
        cpuid(1, a, b, c, d);
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   329
        if (a >= 1) {
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   330
            cpuid(1, a, b, c, d);
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   331
            return (c & 0x00100000);
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   332
        }
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   333
    }
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   334
    return 0;
778
8ac3f46f9d09 Date: Tue, 6 Jan 2004 12:42:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   335
}
8ac3f46f9d09 Date: Tue, 6 Jan 2004 12:42:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   336
8148
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   337
static SDL_INLINE int
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   338
CPU_haveAVX(void)
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   339
{
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   340
    if (CPU_haveCPUID()) {
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   341
        int a, b, c, d;
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   342
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   343
        cpuid(1, a, b, c, d);
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   344
        if (a >= 1) {
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   345
            cpuid(1, a, b, c, d);
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   346
            return (c & 0x10000000);
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   347
        }
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   348
    }
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   349
    return 0;
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   350
}
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   351
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   352
static int SDL_CPUCount = 0;
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   353
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   354
int
5120
b3f075368b1f Added API function to get CPU cache line size.
Sam Lantinga <slouken@libsdl.org>
parents: 5115
diff changeset
   355
SDL_GetCPUCount(void)
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   356
{
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   357
    if (!SDL_CPUCount) {
3606
1a4456a01995 Fixed bug #924
Sam Lantinga <slouken@libsdl.org>
parents: 3587
diff changeset
   358
#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
3586
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
   359
        if (SDL_CPUCount <= 0) {
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
   360
            SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
   361
        }
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
   362
#endif
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   363
#ifdef HAVE_SYSCTLBYNAME
3586
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
   364
        if (SDL_CPUCount <= 0) {
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   365
            size_t size = sizeof(SDL_CPUCount);
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   366
            sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   367
        }
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   368
#endif
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   369
#ifdef __WIN32__
3586
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
   370
        if (SDL_CPUCount <= 0) {
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   371
            SYSTEM_INFO info;
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   372
            GetSystemInfo(&info);
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   373
            SDL_CPUCount = info.dwNumberOfProcessors;
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   374
        }
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   375
#endif
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   376
        /* There has to be at least 1, right? :) */
3586
b6758aee0dd4 Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 3584
diff changeset
   377
        if (SDL_CPUCount <= 0) {
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   378
            SDL_CPUCount = 1;
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   379
        }
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   380
    }
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   381
    return SDL_CPUCount;
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   382
}
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   383
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   384
/* Oh, such a sweet sweet trick, just not very useful. :) */
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   385
static const char *
5120
b3f075368b1f Added API function to get CPU cache line size.
Sam Lantinga <slouken@libsdl.org>
parents: 5115
diff changeset
   386
SDL_GetCPUType(void)
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   387
{
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   388
    static char SDL_CPUType[13];
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   389
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   390
    if (!SDL_CPUType[0]) {
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   391
        int i = 0;
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   392
        int a, b, c, d;
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   393
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   394
        if (CPU_haveCPUID()) {
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   395
            cpuid(0x00000000, a, b, c, d);
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   396
            SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   397
            SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   398
            SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   399
            SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   400
            SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   401
            SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   402
            SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   403
            SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   404
            SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   405
            SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   406
            SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   407
            SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   408
        }
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   409
        if (!SDL_CPUType[0]) {
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   410
            SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   411
        }
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   412
    }
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   413
    return SDL_CPUType;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   414
}
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   415
5981
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   416
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   417
#ifdef TEST_MAIN  /* !!! FIXME: only used for test at the moment. */
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   418
static const char *
5120
b3f075368b1f Added API function to get CPU cache line size.
Sam Lantinga <slouken@libsdl.org>
parents: 5115
diff changeset
   419
SDL_GetCPUName(void)
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   420
{
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   421
    static char SDL_CPUName[48];
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   422
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   423
    if (!SDL_CPUName[0]) {
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   424
        int i = 0;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   425
        int a, b, c, d;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   426
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   427
        if (CPU_haveCPUID()) {
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   428
            cpuid(0x80000000, a, b, c, d);
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   429
            if (a >= 0x80000004) {
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   430
                cpuid(0x80000002, a, b, c, d);
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   431
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   432
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   433
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   434
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   435
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   436
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   437
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   438
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   439
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   440
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   441
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   442
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   443
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   444
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   445
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   446
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   447
                cpuid(0x80000003, a, b, c, d);
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   448
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   449
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   450
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   451
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   452
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   453
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   454
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   455
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   456
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   457
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   458
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   459
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   460
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   461
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   462
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   463
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
3580
951dd6a5d1a2 Implemented Windows version of SDL_GetCPUCount()
Sam Lantinga <slouken@libsdl.org>
parents: 3579
diff changeset
   464
                cpuid(0x80000004, a, b, c, d);
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   465
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   466
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   467
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   468
                SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   469
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   470
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   471
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   472
                SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   473
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   474
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   475
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   476
                SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   477
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   478
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   479
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   480
                SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   481
            }
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   482
        }
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   483
        if (!SDL_CPUName[0]) {
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   484
            SDL_strlcpy(SDL_CPUName, "Unknown", sizeof(SDL_CPUName));
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   485
        }
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   486
    }
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   487
    return SDL_CPUName;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   488
}
5981
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   489
#endif
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   490
5120
b3f075368b1f Added API function to get CPU cache line size.
Sam Lantinga <slouken@libsdl.org>
parents: 5115
diff changeset
   491
int
b3f075368b1f Added API function to get CPU cache line size.
Sam Lantinga <slouken@libsdl.org>
parents: 5115
diff changeset
   492
SDL_GetCPUCacheLineSize(void)
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   493
{
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   494
    const char *cpuType = SDL_GetCPUType();
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   495
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   496
    if (SDL_strcmp(cpuType, "GenuineIntel") == 0) {
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   497
        int a, b, c, d;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   498
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   499
        cpuid(0x00000001, a, b, c, d);
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   500
        return (((b >> 8) & 0xff) * 8);
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   501
    } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) {
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   502
        int a, b, c, d;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   503
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   504
        cpuid(0x80000005, a, b, c, d);
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   505
        return (c & 0xff);
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   506
    } else {
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   507
        /* Just make a guess here... */
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   508
        return SDL_CACHELINE_SIZE;
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   509
    }
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   510
}
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   511
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   512
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   514
static Uint32
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   515
SDL_GetCPUFeatures(void)
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   517
    if (SDL_CPUFeatures == 0xFFFFFFFF) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   518
        SDL_CPUFeatures = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   519
        if (CPU_haveRDTSC()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   520
            SDL_CPUFeatures |= CPU_HAS_RDTSC;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   521
        }
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   522
        if (CPU_haveAltiVec()) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   523
            SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   524
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   525
        if (CPU_haveMMX()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   526
            SDL_CPUFeatures |= CPU_HAS_MMX;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   527
        }
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   528
        if (CPU_have3DNow()) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   529
            SDL_CPUFeatures |= CPU_HAS_3DNOW;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   530
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   531
        if (CPU_haveSSE()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   532
            SDL_CPUFeatures |= CPU_HAS_SSE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   533
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   534
        if (CPU_haveSSE2()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   535
            SDL_CPUFeatures |= CPU_HAS_SSE2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   536
        }
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   537
        if (CPU_haveSSE3()) {
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   538
            SDL_CPUFeatures |= CPU_HAS_SSE3;
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   539
        }
5263
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   540
        if (CPU_haveSSE41()) {
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   541
            SDL_CPUFeatures |= CPU_HAS_SSE41;
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   542
        }
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   543
        if (CPU_haveSSE42()) {
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   544
            SDL_CPUFeatures |= CPU_HAS_SSE42;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   545
        }
8148
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   546
        if (CPU_haveAVX()) {
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   547
            SDL_CPUFeatures |= CPU_HAS_AVX;
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   548
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   549
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   550
    return SDL_CPUFeatures;
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
}
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   553
SDL_bool
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   554
SDL_HasRDTSC(void)
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   555
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   556
    if (SDL_GetCPUFeatures() & CPU_HAS_RDTSC) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   557
        return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   558
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   559
    return SDL_FALSE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   560
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   561
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   562
SDL_bool
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   563
SDL_HasAltiVec(void)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   564
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   565
    if (SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   566
        return SDL_TRUE;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   567
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   568
    return SDL_FALSE;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   569
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   570
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   571
SDL_bool
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   572
SDL_HasMMX(void)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   573
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   574
    if (SDL_GetCPUFeatures() & CPU_HAS_MMX) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   575
        return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   576
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   577
    return SDL_FALSE;
745
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   578
}
71ee03909f42 Greatly simplified the SDL CPU info code
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
   579
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   580
SDL_bool
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   581
SDL_Has3DNow(void)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   582
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   583
    if (SDL_GetCPUFeatures() & CPU_HAS_3DNOW) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   584
        return SDL_TRUE;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   585
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   586
    return SDL_FALSE;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   587
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   588
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   589
SDL_bool
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   590
SDL_HasSSE(void)
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   592
    if (SDL_GetCPUFeatures() & CPU_HAS_SSE) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   593
        return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   594
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   595
    return SDL_FALSE;
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
}
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   598
SDL_bool
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   599
SDL_HasSSE2(void)
804
b2fda076b02e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 796
diff changeset
   600
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   601
    if (SDL_GetCPUFeatures() & CPU_HAS_SSE2) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   602
        return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   603
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   604
    return SDL_FALSE;
804
b2fda076b02e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 796
diff changeset
   605
}
b2fda076b02e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 796
diff changeset
   606
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   607
SDL_bool
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   608
SDL_HasSSE3(void)
778
8ac3f46f9d09 Date: Tue, 6 Jan 2004 12:42:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   609
{
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   610
    if (SDL_GetCPUFeatures() & CPU_HAS_SSE3) {
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   611
        return SDL_TRUE;
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   612
    }
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   613
    return SDL_FALSE;
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   614
}
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   615
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   616
SDL_bool
5263
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   617
SDL_HasSSE41(void)
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   618
{
5263
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   619
    if (SDL_GetCPUFeatures() & CPU_HAS_SSE41) {
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   620
        return SDL_TRUE;
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   621
    }
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   622
    return SDL_FALSE;
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   623
}
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   624
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   625
SDL_bool
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   626
SDL_HasSSE42(void)
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   627
{
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   628
    if (SDL_GetCPUFeatures() & CPU_HAS_SSE42) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   629
        return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   630
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   631
    return SDL_FALSE;
778
8ac3f46f9d09 Date: Tue, 6 Jan 2004 12:42:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   632
}
8ac3f46f9d09 Date: Tue, 6 Jan 2004 12:42:19 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   633
8148
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   634
SDL_bool
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   635
SDL_HasAVX(void)
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   636
{
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   637
    if (SDL_GetCPUFeatures() & CPU_HAS_AVX) {
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   638
        return SDL_TRUE;
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   639
    }
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   640
    return SDL_FALSE;
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   641
}
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   642
7821
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   643
static int SDL_SystemRAM = 0;
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   644
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   645
int
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   646
SDL_GetSystemRAM(void)
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   647
{
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   648
    if (!SDL_SystemRAM) {
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   649
#if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   650
        if (SDL_SystemRAM <= 0) {
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   651
            SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024*1024));
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   652
        }
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   653
#endif
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   654
#ifdef HAVE_SYSCTLBYNAME
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   655
        if (SDL_SystemRAM <= 0) {
8240
334257cd613d Fixed bug 2335 - Fails to build on Debian GNU/kFreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   656
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
7826
a87057441d01 Fix to unbreak SDL_GetSystemRAM() on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 7823
diff changeset
   657
#ifdef HW_REALMEM
a87057441d01 Fix to unbreak SDL_GetSystemRAM() on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 7823
diff changeset
   658
            int mib[2] = {CTL_HW, HW_REALMEM};
a87057441d01 Fix to unbreak SDL_GetSystemRAM() on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 7823
diff changeset
   659
#else
a87057441d01 Fix to unbreak SDL_GetSystemRAM() on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 7823
diff changeset
   660
            /* might only report up to 2 GiB */
a87057441d01 Fix to unbreak SDL_GetSystemRAM() on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 7823
diff changeset
   661
            int mib[2] = {CTL_HW, HW_PHYSMEM};
a87057441d01 Fix to unbreak SDL_GetSystemRAM() on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 7823
diff changeset
   662
#endif /* HW_REALMEM */
a87057441d01 Fix to unbreak SDL_GetSystemRAM() on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 7823
diff changeset
   663
#else
7821
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   664
            int mib[2] = {CTL_HW, HW_MEMSIZE};
8240
334257cd613d Fixed bug 2335 - Fails to build on Debian GNU/kFreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   665
#endif /* __FreeBSD__ || __FreeBSD_kernel__ */
7823
4ab3a5ee041d Fixed compiling on Mac OS X, added a system RAM test
Sam Lantinga <slouken@libsdl.org>
parents: 7822
diff changeset
   666
            Uint64 memsize = 0;
7821
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   667
            size_t len = sizeof(memsize);
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   668
            
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   669
            if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   670
                SDL_SystemRAM = (int)(memsize / (1024*1024));
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   671
            }
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   672
        }
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   673
#endif
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   674
#ifdef __WIN32__
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   675
        if (SDL_SystemRAM <= 0) {
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   676
            MEMORYSTATUSEX stat;
7889
9ec71e56071c Initialize MEMORYSTATUSEX size before GlobalMemoryStatusEx() (thanks, Justin!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7860
diff changeset
   677
            stat.dwLength = sizeof(stat);
7821
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   678
            if (GlobalMemoryStatusEx(&stat)) {
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   679
                SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   680
            }
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   681
        }
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   682
#endif
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   683
    }
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   684
    return SDL_SystemRAM;
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   685
}
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   686
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   687
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   688
#ifdef TEST_MAIN
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   689
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   690
#include <stdio.h>
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   691
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   692
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   693
main()
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   694
{
3579
3427271a2d75 Added SDL_GetCPUCount() to see how many cores are available.
Sam Lantinga <slouken@libsdl.org>
parents: 3515
diff changeset
   695
    printf("CPU count: %d\n", SDL_GetCPUCount());
5115
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   696
    printf("CPU type: %s\n", SDL_GetCPUType());
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   697
    printf("CPU name: %s\n", SDL_GetCPUName());
427998ff3bcf Added cache line size info in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 5090
diff changeset
   698
    printf("CacheLine size: %d\n", SDL_GetCPUCacheLineSize());
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   699
    printf("RDTSC: %d\n", SDL_HasRDTSC());
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   700
    printf("Altivec: %d\n", SDL_HasAltiVec());
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   701
    printf("MMX: %d\n", SDL_HasMMX());
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5263
diff changeset
   702
    printf("3DNow: %d\n", SDL_Has3DNow());
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   703
    printf("SSE: %d\n", SDL_HasSSE());
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   704
    printf("SSE2: %d\n", SDL_HasSSE2());
5259
6a65c1fc07af Updated CPU detection code for SSE3 and SSE4 and removed obsolete 3DNow! and Altivec support.
Sam Lantinga <slouken@libsdl.org>
parents: 5120
diff changeset
   705
    printf("SSE3: %d\n", SDL_HasSSE3());
5263
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   706
    printf("SSE4.1: %d\n", SDL_HasSSE41());
e1122f31fec5 Fixed SSE4 detection, and split it into SSE 4.1 and 4.2
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   707
    printf("SSE4.2: %d\n", SDL_HasSSE42());
8148
56ba41ac64fe Fixed bug 2376 - no SDL_HasAVX
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   708
    printf("AVX: %d\n", SDL_HasAVX());
7821
c47ae79f0de8 Added an API to get the amount of system RAM
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   709
    printf("RAM: %d MB\n", SDL_GetSystemRAM());
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   710
    return 0;
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   711
}
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   712
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   713
#endif /* TEST_MAIN */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   714
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1864
diff changeset
   715
/* vi: set ts=4 sw=4 expandtab: */