Added SDL_GetCPUCount() to see how many cores are available.
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404328
This commit is contained in:
parent
3f0f9188ed
commit
29601c280b
9 changed files with 175 additions and 183 deletions
|
@ -207,7 +207,7 @@ if test x$enable_libc = xyes; then
|
|||
AC_DEFINE(HAVE_MPROTECT)
|
||||
]),
|
||||
)
|
||||
AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep)
|
||||
AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep sysctlbyname)
|
||||
|
||||
AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
|
||||
AC_CHECK_FUNCS(ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt)
|
||||
|
|
|
@ -150,6 +150,7 @@
|
|||
#undef HAVE_SIGACTION
|
||||
#undef HAVE_SETJMP
|
||||
#undef HAVE_NANOSLEEP
|
||||
#undef HAVE_SYSCTLBYNAME
|
||||
#undef HAVE_CLOCK_GETTIME
|
||||
#undef HAVE_GETPAGESIZE
|
||||
#undef HAVE_MPROTECT
|
||||
|
|
|
@ -106,6 +106,7 @@ typedef unsigned long uintptr_t;
|
|||
#define HAVE_SIGACTION 1
|
||||
#define HAVE_SETJMP 1
|
||||
#define HAVE_NANOSLEEP 1
|
||||
#define HAVE_SYSCTLBYNAME 1
|
||||
|
||||
/* enable iPhone version of Core Audio driver */
|
||||
#define SDL_AUDIO_DRIVER_COREAUDIOIPHONE 1
|
||||
|
|
|
@ -105,6 +105,7 @@
|
|||
#define HAVE_SIGACTION 1
|
||||
#define HAVE_SETJMP 1
|
||||
#define HAVE_NANOSLEEP 1
|
||||
#define HAVE_SYSCTLBYNAME 1
|
||||
|
||||
/* Enable various audio drivers */
|
||||
#define SDL_AUDIO_DRIVER_COREAUDIO 1
|
||||
|
|
|
@ -39,6 +39,11 @@ extern "C" {
|
|||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function returns the number of CPU cores available.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
|
||||
|
||||
/**
|
||||
* This function returns true if the CPU has the RDTSC instruction.
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
|
||||
#include "SDL_cpuinfo.h"
|
||||
|
||||
#ifdef HAVE_SYSCTLBYNAME
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
|
||||
#include <sys/sysctl.h> /* For AltiVec check */
|
||||
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
|
||||
|
@ -146,86 +150,36 @@ done:
|
|||
return has_CPUID;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && (defined(i386) || defined(__x86_64__))
|
||||
#define cpuid(func, ax, bx, cx, dx) \
|
||||
__asm__ __volatile__ ("cpuid": \
|
||||
"=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func))
|
||||
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
||||
#define cpuid(func, ax, bx, cx, dx) \
|
||||
asm { \
|
||||
mov eax, func \
|
||||
cpuid
|
||||
mov ax, eax \
|
||||
mov bx, ebx \
|
||||
mov cx, ecx \
|
||||
mov dx, edx \
|
||||
}
|
||||
#else
|
||||
#define cpuid(func, ax, bx, cx, dx) \
|
||||
ax = bx = cx = dx = 0
|
||||
#endif
|
||||
|
||||
static __inline__ int
|
||||
CPU_getCPUIDFeatures(void)
|
||||
{
|
||||
int features = 0;
|
||||
/* *INDENT-OFF* */
|
||||
#if defined(__GNUC__) && defined(i386)
|
||||
__asm__ (
|
||||
" xorl %%eax,%%eax # Set up for CPUID instruction \n"
|
||||
" pushl %%ebx \n"
|
||||
" cpuid # Get and save vendor ID \n"
|
||||
" popl %%ebx \n"
|
||||
" cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
|
||||
" jl 1f # We dont have the CPUID instruction\n"
|
||||
" xorl %%eax,%%eax \n"
|
||||
" incl %%eax \n"
|
||||
" pushl %%ebx \n"
|
||||
" cpuid # Get family/model/stepping/features\n"
|
||||
" popl %%ebx \n"
|
||||
" movl %%edx,%0 \n"
|
||||
"1: \n"
|
||||
: "=m" (features)
|
||||
:
|
||||
: "%eax", "%ecx", "%edx"
|
||||
);
|
||||
#elif defined(__GNUC__) && defined(__x86_64__)
|
||||
__asm__ (
|
||||
" xorl %%eax,%%eax # Set up for CPUID instruction \n"
|
||||
" pushq %%rbx \n"
|
||||
" cpuid # Get and save vendor ID \n"
|
||||
" popq %%rbx \n"
|
||||
" cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
|
||||
" jl 1f # We dont have the CPUID instruction\n"
|
||||
" xorl %%eax,%%eax \n"
|
||||
" incl %%eax \n"
|
||||
" pushq %%rbx \n"
|
||||
" cpuid # Get family/model/stepping/features\n"
|
||||
" popq %%rbx \n"
|
||||
" movl %%edx,%0 \n"
|
||||
"1: \n"
|
||||
: "=m" (features)
|
||||
:
|
||||
: "%rax", "%rcx", "%rdx"
|
||||
);
|
||||
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
||||
__asm {
|
||||
xor eax, eax ; Set up for CPUID instruction
|
||||
push ebx
|
||||
cpuid ; Get and save vendor ID
|
||||
pop ebx
|
||||
cmp eax, 1 ; Make sure 1 is valid input for CPUID
|
||||
jl done ; We dont have the CPUID instruction
|
||||
xor eax, eax
|
||||
inc eax
|
||||
push ebx
|
||||
cpuid ; Get family/model/stepping/features
|
||||
pop ebx
|
||||
mov features, edx
|
||||
done:
|
||||
int ax, bx, cx, dx;
|
||||
|
||||
cpuid(0, ax, bx, cx, dx);
|
||||
if (ax >= 1) {
|
||||
cpuid(1, ax, bx, cx, dx);
|
||||
features = dx;
|
||||
}
|
||||
#elif defined(__sun) && (defined(__i386) || defined(__amd64))
|
||||
__asm(
|
||||
" xorl %eax,%eax \n"
|
||||
" pushl %ebx \n"
|
||||
" cpuid \n"
|
||||
" popl %ebx \n"
|
||||
" cmpl $1,%eax \n"
|
||||
" jl 1f \n"
|
||||
" xorl %eax,%eax \n"
|
||||
" incl %eax \n"
|
||||
" pushl %ebx \n"
|
||||
" cpuid \n"
|
||||
" popl %ebx \n"
|
||||
#ifdef __i386
|
||||
" movl %edx,-8(%ebp) \n"
|
||||
#else
|
||||
" movl %edx,-8(%rbp) \n"
|
||||
#endif
|
||||
"1: \n"
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
return features;
|
||||
}
|
||||
|
||||
|
@ -233,79 +187,13 @@ static __inline__ int
|
|||
CPU_getCPUIDFeaturesExt(void)
|
||||
{
|
||||
int features = 0;
|
||||
/* *INDENT-OFF* */
|
||||
#if defined(__GNUC__) && defined(i386)
|
||||
__asm__ (
|
||||
" movl $0x80000000,%%eax # Query for extended functions \n"
|
||||
" pushl %%ebx \n"
|
||||
" cpuid # Get extended function limit \n"
|
||||
" popl %%ebx \n"
|
||||
" cmpl $0x80000001,%%eax \n"
|
||||
" jl 1f # Nope, we dont have function 800000001h\n"
|
||||
" movl $0x80000001,%%eax # Setup extended function 800000001h\n"
|
||||
" pushl %%ebx \n"
|
||||
" cpuid # and get the information \n"
|
||||
" popl %%ebx \n"
|
||||
" movl %%edx,%0 \n"
|
||||
"1: \n"
|
||||
: "=m" (features)
|
||||
:
|
||||
: "%eax", "%ecx", "%edx"
|
||||
);
|
||||
#elif defined(__GNUC__) && defined (__x86_64__)
|
||||
__asm__ (
|
||||
" movl $0x80000000,%%eax # Query for extended functions \n"
|
||||
" pushq %%rbx \n"
|
||||
" cpuid # Get extended function limit \n"
|
||||
" popq %%rbx \n"
|
||||
" cmpl $0x80000001,%%eax \n"
|
||||
" jl 1f # Nope, we dont have function 800000001h\n"
|
||||
" movl $0x80000001,%%eax # Setup extended function 800000001h\n"
|
||||
" pushq %%rbx \n"
|
||||
" cpuid # and get the information \n"
|
||||
" popq %%rbx \n"
|
||||
" movl %%edx,%0 \n"
|
||||
"1: \n"
|
||||
: "=m" (features)
|
||||
:
|
||||
: "%rax", "%rcx", "%rdx"
|
||||
);
|
||||
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
||||
__asm {
|
||||
mov eax,80000000h ; Query for extended functions
|
||||
push ebx
|
||||
cpuid ; Get extended function limit
|
||||
pop ebx
|
||||
cmp eax,80000001h
|
||||
jl done ; Nope, we dont have function 800000001h
|
||||
mov eax,80000001h ; Setup extended function 800000001h
|
||||
push ebx
|
||||
cpuid ; and get the information
|
||||
pop ebx
|
||||
mov features,edx
|
||||
done:
|
||||
int ax, bx, cx, dx;
|
||||
|
||||
cpuid(0x80000000, ax, bx, cx, dx);
|
||||
if (ax >= 0x80000001) {
|
||||
cpuid(0x80000001, ax, bx, cx, dx);
|
||||
features = dx;
|
||||
}
|
||||
#elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
|
||||
__asm (
|
||||
" movl $0x80000000,%eax \n"
|
||||
" pushl %ebx \n"
|
||||
" cpuid \n"
|
||||
" popl %ebx \n"
|
||||
" cmpl $0x80000001,%eax \n"
|
||||
" jl 1f \n"
|
||||
" movl $0x80000001,%eax \n"
|
||||
" pushl %ebx \n"
|
||||
" cpuid \n"
|
||||
" popl %ebx \n"
|
||||
#ifdef __i386
|
||||
" movl %edx,-8(%ebp) \n"
|
||||
#else
|
||||
" movl %edx,-8(%rbp) \n"
|
||||
#endif
|
||||
"1: \n"
|
||||
);
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
return features;
|
||||
}
|
||||
|
||||
|
@ -395,6 +283,97 @@ CPU_haveAltiVec(void)
|
|||
return altivec;
|
||||
}
|
||||
|
||||
static int SDL_CPUCount = 0;
|
||||
|
||||
int
|
||||
SDL_GetCPUCount()
|
||||
{
|
||||
if (!SDL_CPUCount) {
|
||||
#ifdef HAVE_SYSCTLBYNAME
|
||||
size_t size = sizeof(SDL_CPUCount);
|
||||
sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
|
||||
#endif
|
||||
/* There has to be at least 1, right? :) */
|
||||
if (!SDL_CPUCount) {
|
||||
SDL_CPUCount = 1;
|
||||
}
|
||||
}
|
||||
return SDL_CPUCount;
|
||||
}
|
||||
|
||||
/* Oh, such a sweet sweet trick, just not very useful. :) */
|
||||
const char *
|
||||
SDL_GetCPUType()
|
||||
{
|
||||
static char SDL_CPUType[48];
|
||||
|
||||
if (!SDL_CPUType[0]) {
|
||||
int i = 0;
|
||||
int ax, bx, cx, dx;
|
||||
|
||||
if (CPU_haveCPUID()) {
|
||||
cpuid(0x80000000, ax, bx, cx, dx);
|
||||
if (ax >= 0x80000004) {
|
||||
cpuid(0x80000002, ax, bx, cx, dx);
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
cpuid(0x80000003, ax, bx, cx, dx);
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
cpuid(0x80000004, ax, bx, cx, dx);
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(ax & 0xff); ax >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(bx & 0xff); bx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(cx & 0xff); cx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
SDL_CPUType[i++] = (char)(dx & 0xff); dx >>= 8;
|
||||
}
|
||||
}
|
||||
if (!SDL_CPUType[0]) {
|
||||
SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
|
||||
}
|
||||
}
|
||||
return SDL_CPUType;
|
||||
}
|
||||
|
||||
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
|
||||
|
||||
static Uint32
|
||||
|
@ -509,6 +488,8 @@ SDL_HasAltiVec(void)
|
|||
int
|
||||
main()
|
||||
{
|
||||
printf("CPU count: %d\n", SDL_GetCPUCount());
|
||||
printf("CPU name: %s\n", SDL_GetCPUType());
|
||||
printf("RDTSC: %d\n", SDL_HasRDTSC());
|
||||
printf("MMX: %d\n", SDL_HasMMX());
|
||||
printf("MMXExt: %d\n", SDL_HasMMXExt());
|
||||
|
|
|
@ -49,4 +49,5 @@ extern void SDL_SYS_SetupThread(void);
|
|||
extern void SDL_SYS_WaitThread(SDL_Thread * thread);
|
||||
|
||||
#endif /* _SDL_systhread_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -155,6 +155,7 @@ int test_platform (void)
|
|||
"big"
|
||||
#endif
|
||||
);
|
||||
SDL_ATprintVerbose( 1, "CPU count: %d\n", SDL_GetCPUCount());
|
||||
SDL_ATprintVerbose( 1, "Available extensions:\n" );
|
||||
SDL_ATprintVerbose( 1, " RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected" );
|
||||
SDL_ATprintVerbose( 1, " MMX %s\n", SDL_HasMMX()? "detected" : "not detected" );
|
||||
|
|
|
@ -134,6 +134,7 @@ int
|
|||
TestCPUInfo(SDL_bool verbose)
|
||||
{
|
||||
if (verbose) {
|
||||
printf("CPU count: %d\n", SDL_GetCPUCount());
|
||||
printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
|
||||
printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
|
||||
printf("MMX Ext %s\n", SDL_HasMMXExt()? "detected" : "not detected");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue