2003-11-18 01:27:06 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2010-01-24 21:10:53 +00:00
|
|
|
Copyright (C) 1997-2010 Sam Lantinga
|
2003-11-18 01:27:06 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2003-11-18 01:27:06 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2003-11-18 01:27:06 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2003-11-18 01:27:06 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-11-18 01:27:06 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
|
|
|
slouken@libsdl.org
|
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2003-11-18 01:27:06 +00:00
|
|
|
|
|
|
|
/* CPU feature detection for SDL */
|
|
|
|
|
2006-02-16 10:11:48 +00:00
|
|
|
#include "SDL_cpuinfo.h"
|
|
|
|
|
2009-12-17 03:04:04 +00:00
|
|
|
#ifdef HAVE_SYSCONF
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2009-12-16 06:53:53 +00:00
|
|
|
#ifdef HAVE_SYSCTLBYNAME
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
2009-09-05 10:39:18 +00:00
|
|
|
#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
|
2006-07-10 21:04:37 +00:00
|
|
|
#include <sys/sysctl.h> /* For AltiVec check */
|
2006-03-09 06:33:21 +00:00
|
|
|
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
|
|
|
|
#include <signal.h>
|
|
|
|
#include <setjmp.h>
|
2004-01-06 17:18:38 +00:00
|
|
|
#endif
|
2011-01-20 18:04:05 -08:00
|
|
|
#ifdef __WINDOWS__
|
2009-12-16 08:17:05 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2004-01-06 17:18:38 +00:00
|
|
|
|
2009-12-16 06:53:53 +00:00
|
|
|
#define CPU_HAS_RDTSC 0x00000001
|
|
|
|
#define CPU_HAS_MMX 0x00000002
|
|
|
|
#define CPU_HAS_MMXEXT 0x00000004
|
|
|
|
#define CPU_HAS_3DNOW 0x00000010
|
2004-01-24 05:47:19 +00:00
|
|
|
#define CPU_HAS_3DNOWEXT 0x00000020
|
2009-12-16 06:53:53 +00:00
|
|
|
#define CPU_HAS_SSE 0x00000040
|
|
|
|
#define CPU_HAS_SSE2 0x00000080
|
|
|
|
#define CPU_HAS_ALTIVEC 0x00000100
|
2003-11-18 01:27:06 +00:00
|
|
|
|
2006-03-09 06:33:21 +00:00
|
|
|
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__
|
2004-01-29 05:22:23 +00:00
|
|
|
/* This is the brute force way of detecting instruction sets...
|
|
|
|
the idea is borrowed from the libmpeg2 library - thanks!
|
|
|
|
*/
|
|
|
|
static jmp_buf jmpbuf;
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
|
|
|
illegal_instruction(int sig)
|
2004-01-29 05:22:23 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
longjmp(jmpbuf, 1);
|
2004-01-29 05:22:23 +00:00
|
|
|
}
|
2006-02-16 10:11:48 +00:00
|
|
|
#endif /* HAVE_SETJMP */
|
2004-01-29 05:22:23 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_haveCPUID(void)
|
2003-11-24 09:16:52 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
int has_CPUID = 0;
|
|
|
|
/* *INDENT-OFF* */
|
2003-11-24 09:16:52 +00:00
|
|
|
#if defined(__GNUC__) && defined(i386)
|
2009-12-16 06:53:53 +00:00
|
|
|
__asm__ (
|
2003-11-24 09:16:52 +00:00
|
|
|
" pushfl # Get original EFLAGS \n"
|
|
|
|
" popl %%eax \n"
|
|
|
|
" movl %%eax,%%ecx \n"
|
|
|
|
" xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
|
|
|
|
" pushl %%eax # Save new EFLAGS value on stack \n"
|
|
|
|
" popfl # Replace current EFLAGS value \n"
|
|
|
|
" pushfl # Get new EFLAGS \n"
|
|
|
|
" popl %%eax # Store new EFLAGS in EAX \n"
|
|
|
|
" xorl %%ecx,%%eax # Can not toggle ID bit, \n"
|
|
|
|
" jz 1f # Processor=80486 \n"
|
|
|
|
" movl $1,%0 # We have CPUID support \n"
|
|
|
|
"1: \n"
|
2009-12-16 06:53:53 +00:00
|
|
|
: "=m" (has_CPUID)
|
|
|
|
:
|
|
|
|
: "%eax", "%ecx"
|
|
|
|
);
|
2004-04-11 19:49:34 +00:00
|
|
|
#elif defined(__GNUC__) && defined(__x86_64__)
|
|
|
|
/* Technically, if this is being compiled under __x86_64__ then it has
|
|
|
|
CPUid by definition. But it's nice to be able to prove it. :) */
|
2009-12-16 06:53:53 +00:00
|
|
|
__asm__ (
|
2004-04-11 19:49:34 +00:00
|
|
|
" pushfq # Get original EFLAGS \n"
|
|
|
|
" popq %%rax \n"
|
|
|
|
" movq %%rax,%%rcx \n"
|
|
|
|
" xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
|
|
|
|
" pushq %%rax # Save new EFLAGS value on stack \n"
|
|
|
|
" popfq # Replace current EFLAGS value \n"
|
|
|
|
" pushfq # Get new EFLAGS \n"
|
|
|
|
" popq %%rax # Store new EFLAGS in EAX \n"
|
|
|
|
" xorl %%ecx,%%eax # Can not toggle ID bit, \n"
|
|
|
|
" jz 1f # Processor=80486 \n"
|
|
|
|
" movl $1,%0 # We have CPUID support \n"
|
|
|
|
"1: \n"
|
2009-12-16 06:53:53 +00:00
|
|
|
: "=m" (has_CPUID)
|
|
|
|
:
|
|
|
|
: "%rax", "%rcx"
|
|
|
|
);
|
2006-02-26 19:30:21 +00:00
|
|
|
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
2009-12-16 06:53:53 +00:00
|
|
|
__asm {
|
2003-11-24 09:16:52 +00:00
|
|
|
pushfd ; Get original EFLAGS
|
|
|
|
pop eax
|
|
|
|
mov ecx, eax
|
|
|
|
xor eax, 200000h ; Flip ID bit in EFLAGS
|
|
|
|
push eax ; Save new EFLAGS value on stack
|
|
|
|
popfd ; Replace current EFLAGS value
|
|
|
|
pushfd ; Get new EFLAGS
|
|
|
|
pop eax ; Store new EFLAGS in EAX
|
|
|
|
xor eax, ecx ; Can not toggle ID bit,
|
|
|
|
jz done ; Processor=80486
|
|
|
|
mov has_CPUID,1 ; We have CPUID support
|
|
|
|
done:
|
2009-12-16 06:53:53 +00:00
|
|
|
}
|
2006-06-20 05:35:44 +00:00
|
|
|
#elif defined(__sun) && defined(__i386)
|
2009-12-16 06:53:53 +00:00
|
|
|
__asm (
|
2006-01-05 08:17:35 +00:00
|
|
|
" pushfl \n"
|
2009-12-16 16:42:04 +00:00
|
|
|
" popl %eax \n"
|
|
|
|
" movl %eax,%ecx \n"
|
|
|
|
" xorl $0x200000,%eax \n"
|
|
|
|
" pushl %eax \n"
|
|
|
|
" popfl \n"
|
|
|
|
" pushfl \n"
|
|
|
|
" popl %eax \n"
|
|
|
|
" xorl %ecx,%eax \n"
|
|
|
|
" jz 1f \n"
|
|
|
|
" movl $1,-8(%ebp) \n"
|
2006-01-05 08:17:35 +00:00
|
|
|
"1: \n"
|
2009-12-16 06:53:53 +00:00
|
|
|
);
|
2006-01-05 08:17:35 +00:00
|
|
|
#elif defined(__sun) && defined(__amd64)
|
2009-12-16 06:53:53 +00:00
|
|
|
__asm (
|
2006-01-05 08:17:35 +00:00
|
|
|
" pushfq \n"
|
|
|
|
" popq %rax \n"
|
|
|
|
" movq %rax,%rcx \n"
|
|
|
|
" xorl $0x200000,%eax \n"
|
|
|
|
" pushq %rax \n"
|
|
|
|
" popfq \n"
|
|
|
|
" pushfq \n"
|
|
|
|
" popq %rax \n"
|
|
|
|
" xorl %ecx,%eax \n"
|
|
|
|
" jz 1f \n"
|
|
|
|
" movl $1,-8(%rbp) \n"
|
|
|
|
"1: \n"
|
2009-12-16 06:53:53 +00:00
|
|
|
);
|
2003-11-24 09:16:52 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
return has_CPUID;
|
2003-11-24 09:16:52 +00:00
|
|
|
}
|
|
|
|
|
2009-12-17 04:01:29 +00:00
|
|
|
#if defined(__GNUC__) && defined(i386)
|
2009-12-16 08:17:05 +00:00
|
|
|
#define cpuid(func, a, b, c, d) \
|
2009-12-16 16:42:04 +00:00
|
|
|
__asm__ __volatile__ ( \
|
|
|
|
" pushl %%ebx \n" \
|
|
|
|
" cpuid \n" \
|
|
|
|
" movl %%ebx, %%esi \n" \
|
|
|
|
" popl %%ebx \n" : \
|
|
|
|
"=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
|
2009-12-17 04:01:29 +00:00
|
|
|
#elif defined(__GNUC__) && defined(__x86_64__)
|
|
|
|
#define cpuid(func, a, b, c, d) \
|
|
|
|
__asm__ __volatile__ ( \
|
|
|
|
" pushq %%rbx \n" \
|
|
|
|
" cpuid \n" \
|
|
|
|
" movq %%rbx, %%rsi \n" \
|
|
|
|
" popq %%rbx \n" : \
|
|
|
|
"=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
|
2009-12-16 06:53:53 +00:00
|
|
|
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
2009-12-16 08:17:05 +00:00
|
|
|
#define cpuid(func, a, b, c, d) \
|
|
|
|
__asm { \
|
|
|
|
__asm mov eax, func \
|
|
|
|
__asm cpuid \
|
|
|
|
__asm mov a, eax \
|
|
|
|
__asm mov b, ebx \
|
|
|
|
__asm mov c, ecx \
|
|
|
|
__asm mov d, edx \
|
2009-12-16 06:53:53 +00:00
|
|
|
}
|
|
|
|
#else
|
2009-12-16 08:17:05 +00:00
|
|
|
#define cpuid(func, a, b, c, d) \
|
|
|
|
a = b = c = d = 0
|
2009-12-16 06:53:53 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_getCPUIDFeatures(void)
|
2003-11-24 09:16:52 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
int features = 0;
|
2009-12-16 08:17:05 +00:00
|
|
|
int a, b, c, d;
|
2009-12-16 06:53:53 +00:00
|
|
|
|
2009-12-16 08:17:05 +00:00
|
|
|
cpuid(0, a, b, c, d);
|
|
|
|
if (a >= 1) {
|
|
|
|
cpuid(1, a, b, c, d);
|
|
|
|
features = d;
|
2009-12-16 06:53:53 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
return features;
|
2003-11-24 09:16:52 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_getCPUIDFeaturesExt(void)
|
2003-11-24 09:16:52 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
int features = 0;
|
2009-12-16 08:17:05 +00:00
|
|
|
int a, b, c, d;
|
2009-12-16 06:53:53 +00:00
|
|
|
|
2009-12-16 08:17:05 +00:00
|
|
|
cpuid(0x80000000, a, b, c, d);
|
|
|
|
if (a >= 0x80000001) {
|
|
|
|
cpuid(0x80000001, a, b, c, d);
|
|
|
|
features = d;
|
2009-12-16 06:53:53 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
return features;
|
2004-01-24 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_haveRDTSC(void)
|
2004-01-24 05:47:19 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (CPU_haveCPUID()) {
|
|
|
|
return (CPU_getCPUIDFeatures() & 0x00000010);
|
|
|
|
}
|
|
|
|
return 0;
|
2004-01-24 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_haveMMX(void)
|
2004-01-24 05:47:19 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (CPU_haveCPUID()) {
|
|
|
|
return (CPU_getCPUIDFeatures() & 0x00800000);
|
|
|
|
}
|
|
|
|
return 0;
|
2004-01-24 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_haveMMXExt(void)
|
2004-01-24 05:47:19 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (CPU_haveCPUID()) {
|
|
|
|
return (CPU_getCPUIDFeaturesExt() & 0x00400000);
|
|
|
|
}
|
|
|
|
return 0;
|
2004-01-24 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_have3DNow(void)
|
2004-01-24 05:47:19 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (CPU_haveCPUID()) {
|
|
|
|
return (CPU_getCPUIDFeaturesExt() & 0x80000000);
|
|
|
|
}
|
|
|
|
return 0;
|
2004-01-24 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_have3DNowExt(void)
|
2004-01-24 05:47:19 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (CPU_haveCPUID()) {
|
|
|
|
return (CPU_getCPUIDFeaturesExt() & 0x40000000);
|
|
|
|
}
|
|
|
|
return 0;
|
2003-11-24 09:16:52 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_haveSSE(void)
|
2003-11-24 09:16:52 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (CPU_haveCPUID()) {
|
|
|
|
return (CPU_getCPUIDFeatures() & 0x02000000);
|
|
|
|
}
|
|
|
|
return 0;
|
2003-11-24 09:16:52 +00:00
|
|
|
}
|
2003-11-18 01:27:06 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_haveSSE2(void)
|
2004-01-24 05:47:19 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (CPU_haveCPUID()) {
|
|
|
|
return (CPU_getCPUIDFeatures() & 0x04000000);
|
|
|
|
}
|
|
|
|
return 0;
|
2004-01-24 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static __inline__ int
|
|
|
|
CPU_haveAltiVec(void)
|
2004-01-06 17:18:38 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
volatile int altivec = 0;
|
2009-09-05 10:39:18 +00:00
|
|
|
#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
|
2006-07-10 21:04:37 +00:00
|
|
|
int selectors[2] = { CTL_HW, HW_VECTORUNIT };
|
|
|
|
int hasVectorUnit = 0;
|
|
|
|
size_t length = sizeof(hasVectorUnit);
|
|
|
|
int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
|
|
|
|
if (0 == error)
|
|
|
|
altivec = (hasVectorUnit != 0);
|
2006-02-16 10:11:48 +00:00
|
|
|
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
|
2006-07-10 21:04:37 +00:00
|
|
|
void (*handler) (int sig);
|
|
|
|
handler = signal(SIGILL, illegal_instruction);
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1));
|
|
|
|
altivec = 1;
|
|
|
|
}
|
|
|
|
signal(SIGILL, handler);
|
2004-01-06 17:18:38 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
return altivec;
|
2004-01-06 17:18:38 +00:00
|
|
|
}
|
|
|
|
|
2009-12-16 06:53:53 +00:00
|
|
|
static int SDL_CPUCount = 0;
|
|
|
|
|
|
|
|
int
|
|
|
|
SDL_GetCPUCount()
|
|
|
|
{
|
|
|
|
if (!SDL_CPUCount) {
|
2010-01-06 04:33:31 +00:00
|
|
|
#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
|
2009-12-17 03:04:04 +00:00
|
|
|
if (SDL_CPUCount <= 0) {
|
|
|
|
SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
|
}
|
|
|
|
#endif
|
2009-12-16 06:53:53 +00:00
|
|
|
#ifdef HAVE_SYSCTLBYNAME
|
2009-12-17 03:04:04 +00:00
|
|
|
if (SDL_CPUCount <= 0) {
|
2009-12-16 08:17:05 +00:00
|
|
|
size_t size = sizeof(SDL_CPUCount);
|
|
|
|
sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
|
|
|
|
}
|
|
|
|
#endif
|
2011-01-20 18:04:05 -08:00
|
|
|
#ifdef __WINDOWS__
|
2009-12-17 03:04:04 +00:00
|
|
|
if (SDL_CPUCount <= 0) {
|
2009-12-16 08:17:05 +00:00
|
|
|
SYSTEM_INFO info;
|
|
|
|
GetSystemInfo(&info);
|
|
|
|
SDL_CPUCount = info.dwNumberOfProcessors;
|
|
|
|
}
|
2009-12-16 06:53:53 +00:00
|
|
|
#endif
|
|
|
|
/* There has to be at least 1, right? :) */
|
2009-12-17 03:04:04 +00:00
|
|
|
if (SDL_CPUCount <= 0) {
|
2009-12-16 06:53:53 +00:00
|
|
|
SDL_CPUCount = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SDL_CPUCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Oh, such a sweet sweet trick, just not very useful. :) */
|
2010-06-26 08:56:48 -07:00
|
|
|
static const char *
|
2009-12-16 06:53:53 +00:00
|
|
|
SDL_GetCPUType()
|
|
|
|
{
|
|
|
|
static char SDL_CPUType[48];
|
|
|
|
|
|
|
|
if (!SDL_CPUType[0]) {
|
|
|
|
int i = 0;
|
2009-12-16 08:17:05 +00:00
|
|
|
int a, b, c, d;
|
2009-12-16 06:53:53 +00:00
|
|
|
|
|
|
|
if (CPU_haveCPUID()) {
|
2009-12-16 08:17:05 +00:00
|
|
|
cpuid(0x80000000, a, b, c, d);
|
|
|
|
if (a >= 0x80000004) {
|
|
|
|
cpuid(0x80000002, a, b, c, d);
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
cpuid(0x80000003, a, b, c, d);
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
cpuid(0x80000004, a, b, c, d);
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(a & 0xff); a >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
|
|
|
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
|
2009-12-16 06:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!SDL_CPUType[0]) {
|
|
|
|
SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SDL_CPUType;
|
|
|
|
}
|
|
|
|
|
2003-11-18 01:27:06 +00:00
|
|
|
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static Uint32
|
|
|
|
SDL_GetCPUFeatures(void)
|
2003-11-18 01:27:06 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_CPUFeatures == 0xFFFFFFFF) {
|
|
|
|
SDL_CPUFeatures = 0;
|
|
|
|
if (CPU_haveRDTSC()) {
|
|
|
|
SDL_CPUFeatures |= CPU_HAS_RDTSC;
|
|
|
|
}
|
|
|
|
if (CPU_haveMMX()) {
|
|
|
|
SDL_CPUFeatures |= CPU_HAS_MMX;
|
|
|
|
}
|
|
|
|
if (CPU_haveMMXExt()) {
|
|
|
|
SDL_CPUFeatures |= CPU_HAS_MMXEXT;
|
|
|
|
}
|
|
|
|
if (CPU_have3DNow()) {
|
|
|
|
SDL_CPUFeatures |= CPU_HAS_3DNOW;
|
|
|
|
}
|
|
|
|
if (CPU_have3DNowExt()) {
|
|
|
|
SDL_CPUFeatures |= CPU_HAS_3DNOWEXT;
|
|
|
|
}
|
|
|
|
if (CPU_haveSSE()) {
|
|
|
|
SDL_CPUFeatures |= CPU_HAS_SSE;
|
|
|
|
}
|
|
|
|
if (CPU_haveSSE2()) {
|
|
|
|
SDL_CPUFeatures |= CPU_HAS_SSE2;
|
|
|
|
}
|
|
|
|
if (CPU_haveAltiVec()) {
|
|
|
|
SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SDL_CPUFeatures;
|
2003-11-18 01:27:06 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_HasRDTSC(void)
|
2003-11-24 09:16:52 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_GetCPUFeatures() & CPU_HAS_RDTSC) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2003-11-24 09:16:52 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_HasMMX(void)
|
2003-11-18 01:27:06 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_GetCPUFeatures() & CPU_HAS_MMX) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2003-11-18 01:27:06 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_HasMMXExt(void)
|
2003-11-18 01:27:06 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_GetCPUFeatures() & CPU_HAS_MMXEXT) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2003-11-18 01:27:06 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_Has3DNow(void)
|
2003-11-18 01:27:06 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_GetCPUFeatures() & CPU_HAS_3DNOW) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2003-11-18 01:27:06 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_Has3DNowExt(void)
|
2004-01-06 17:18:38 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2004-01-06 17:18:38 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_HasSSE(void)
|
2004-01-24 05:47:19 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_GetCPUFeatures() & CPU_HAS_SSE) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2004-01-24 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_HasSSE2(void)
|
2004-01-24 05:47:19 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_GetCPUFeatures() & CPU_HAS_SSE2) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2004-01-24 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_bool
|
|
|
|
SDL_HasAltiVec(void)
|
2004-01-24 05:47:19 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
2004-01-24 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2003-11-18 01:27:06 +00:00
|
|
|
#ifdef TEST_MAIN
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
int
|
|
|
|
main()
|
2003-11-18 01:27:06 +00:00
|
|
|
{
|
2009-12-16 06:53:53 +00:00
|
|
|
printf("CPU count: %d\n", SDL_GetCPUCount());
|
|
|
|
printf("CPU name: %s\n", SDL_GetCPUType());
|
2006-07-10 21:04:37 +00:00
|
|
|
printf("RDTSC: %d\n", SDL_HasRDTSC());
|
|
|
|
printf("MMX: %d\n", SDL_HasMMX());
|
|
|
|
printf("MMXExt: %d\n", SDL_HasMMXExt());
|
|
|
|
printf("3DNow: %d\n", SDL_Has3DNow());
|
|
|
|
printf("3DNowExt: %d\n", SDL_Has3DNowExt());
|
|
|
|
printf("SSE: %d\n", SDL_HasSSE());
|
|
|
|
printf("SSE2: %d\n", SDL_HasSSE2());
|
|
|
|
printf("AltiVec: %d\n", SDL_HasAltiVec());
|
|
|
|
return 0;
|
2003-11-18 01:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TEST_MAIN */
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|