2003-11-18 01:27:06 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2008-12-08 00:27:32 +00:00
|
|
|
Copyright (C) 1997-2009 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"
|
|
|
|
|
2006-03-22 22:29:44 +00:00
|
|
|
#if defined(__MACOSX__) && defined(__ppc__)
|
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
|
|
|
|
|
2003-11-24 09:16:52 +00:00
|
|
|
#define CPU_HAS_RDTSC 0x00000001
|
|
|
|
#define CPU_HAS_MMX 0x00000002
|
2004-01-24 05:47:19 +00:00
|
|
|
#define CPU_HAS_MMXEXT 0x00000004
|
|
|
|
#define CPU_HAS_3DNOW 0x00000010
|
|
|
|
#define CPU_HAS_3DNOWEXT 0x00000020
|
|
|
|
#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)
|
|
|
|
__asm__ (
|
|
|
|
" 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"
|
2004-01-17 20:37:06 +00:00
|
|
|
: "=m" (has_CPUID)
|
2003-11-24 09:16:52 +00:00
|
|
|
:
|
|
|
|
: "%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. :) */
|
|
|
|
__asm__ (
|
|
|
|
" 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"
|
|
|
|
: "=m" (has_CPUID)
|
|
|
|
:
|
|
|
|
: "%rax", "%rcx"
|
|
|
|
);
|
2006-02-26 19:30:21 +00:00
|
|
|
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
2003-11-24 19:58:29 +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:
|
|
|
|
}
|
2006-06-20 05:35:44 +00:00
|
|
|
#elif defined(__sun) && defined(__i386)
|
2006-02-16 10:11:48 +00:00
|
|
|
__asm (
|
2006-01-05 08:17:35 +00:00
|
|
|
" pushfl \n"
|
2006-02-16 10:11:48 +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"
|
|
|
|
);
|
|
|
|
#elif defined(__sun) && defined(__amd64)
|
|
|
|
__asm (
|
|
|
|
" 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"
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
/* *INDENT-OFF* */
|
2008-12-24 13:13:38 +00:00
|
|
|
#if defined(__GNUC__) && defined(i386)
|
2003-11-24 09:16:52 +00:00
|
|
|
__asm__ (
|
2004-01-24 05:47:19 +00:00
|
|
|
" movl %%ebx,%%edi\n"
|
2003-11-24 09:16:52 +00:00
|
|
|
" xorl %%eax,%%eax # Set up for CPUID instruction \n"
|
|
|
|
" cpuid # Get and save vendor ID \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"
|
|
|
|
" cpuid # Get family/model/stepping/features\n"
|
|
|
|
" movl %%edx,%0 \n"
|
|
|
|
"1: \n"
|
2004-01-24 05:47:19 +00:00
|
|
|
" movl %%edi,%%ebx\n"
|
2004-01-17 20:37:06 +00:00
|
|
|
: "=m" (features)
|
2003-11-24 09:16:52 +00:00
|
|
|
:
|
2004-05-16 17:19:48 +00:00
|
|
|
: "%eax", "%ecx", "%edx", "%edi"
|
2003-11-24 09:16:52 +00:00
|
|
|
);
|
2008-12-24 13:13:38 +00:00
|
|
|
#elif defined(__GNUC__) && defined(__x86_64__)
|
|
|
|
__asm__ (
|
|
|
|
" movq %%rbx,%%rdi\n"
|
|
|
|
" xorl %%eax,%%eax # Set up for CPUID instruction \n"
|
|
|
|
" cpuid # Get and save vendor ID \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"
|
|
|
|
" cpuid # Get family/model/stepping/features\n"
|
|
|
|
" movl %%edx,%0 \n"
|
|
|
|
"1: \n"
|
|
|
|
" movq %%rdi,%%rbx\n"
|
|
|
|
: "=m" (features)
|
|
|
|
:
|
|
|
|
: "%rax", "%rcx", "%rdx", "%rdi"
|
|
|
|
);
|
2006-02-26 19:30:21 +00:00
|
|
|
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
2003-11-24 19:58:29 +00:00
|
|
|
__asm {
|
2003-11-24 09:16:52 +00:00
|
|
|
xor eax, eax ; Set up for CPUID instruction
|
|
|
|
cpuid ; Get and save vendor ID
|
|
|
|
cmp eax, 1 ; Make sure 1 is valid input for CPUID
|
|
|
|
jl done ; We dont have the CPUID instruction
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
cpuid ; Get family/model/stepping/features
|
|
|
|
mov features, edx
|
|
|
|
done:
|
|
|
|
}
|
2006-06-20 05:35:44 +00:00
|
|
|
#elif defined(__sun) && (defined(__i386) || defined(__amd64))
|
2006-01-05 08:17:35 +00:00
|
|
|
__asm(
|
|
|
|
" movl %ebx,%edi\n"
|
|
|
|
" xorl %eax,%eax \n"
|
|
|
|
" cpuid \n"
|
|
|
|
" cmpl $1,%eax \n"
|
|
|
|
" jl 1f \n"
|
|
|
|
" xorl %eax,%eax \n"
|
|
|
|
" incl %eax \n"
|
|
|
|
" cpuid \n"
|
|
|
|
#ifdef __i386
|
|
|
|
" movl %edx,-8(%ebp) \n"
|
|
|
|
#else
|
|
|
|
" movl %edx,-8(%rbp) \n"
|
|
|
|
#endif
|
|
|
|
"1: \n"
|
|
|
|
" movl %edi,%ebx\n" );
|
2003-11-24 09:16:52 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
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;
|
|
|
|
/* *INDENT-OFF* */
|
2008-12-24 13:13:38 +00:00
|
|
|
#if defined(__GNUC__) && defined(i386)
|
2003-11-24 09:16:52 +00:00
|
|
|
__asm__ (
|
2004-01-24 05:47:19 +00:00
|
|
|
" movl %%ebx,%%edi\n"
|
2003-11-24 09:16:52 +00:00
|
|
|
" movl $0x80000000,%%eax # Query for extended functions \n"
|
|
|
|
" cpuid # Get extended function limit \n"
|
|
|
|
" cmpl $0x80000001,%%eax \n"
|
2004-01-24 15:55:00 +00:00
|
|
|
" jl 1f # Nope, we dont have function 800000001h\n"
|
2003-11-24 09:16:52 +00:00
|
|
|
" movl $0x80000001,%%eax # Setup extended function 800000001h\n"
|
|
|
|
" cpuid # and get the information \n"
|
2004-01-24 05:47:19 +00:00
|
|
|
" movl %%edx,%0 \n"
|
2003-11-24 09:16:52 +00:00
|
|
|
"1: \n"
|
2004-01-24 05:47:19 +00:00
|
|
|
" movl %%edi,%%ebx\n"
|
|
|
|
: "=m" (features)
|
2003-11-24 09:16:52 +00:00
|
|
|
:
|
2004-05-16 17:19:48 +00:00
|
|
|
: "%eax", "%ecx", "%edx", "%edi"
|
2003-11-24 09:16:52 +00:00
|
|
|
);
|
2008-12-24 13:13:38 +00:00
|
|
|
#elif defined(__GNUC__) && defined (__x86_64__)
|
|
|
|
__asm__ (
|
|
|
|
" movq %%rbx,%%rdi\n"
|
|
|
|
" movl $0x80000000,%%eax # Query for extended functions \n"
|
|
|
|
" cpuid # Get extended function limit \n"
|
|
|
|
" cmpl $0x80000001,%%eax \n"
|
|
|
|
" jl 1f # Nope, we dont have function 800000001h\n"
|
|
|
|
" movl $0x80000001,%%eax # Setup extended function 800000001h\n"
|
|
|
|
" cpuid # and get the information \n"
|
|
|
|
" movl %%edx,%0 \n"
|
|
|
|
"1: \n"
|
|
|
|
" movq %%rdi,%%rbx\n"
|
|
|
|
: "=m" (features)
|
|
|
|
:
|
|
|
|
: "%rax", "%rcx", "%rdx", "%rdi"
|
|
|
|
);
|
2006-02-26 19:30:21 +00:00
|
|
|
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
2003-11-24 19:58:29 +00:00
|
|
|
__asm {
|
2003-11-24 09:16:52 +00:00
|
|
|
mov eax,80000000h ; Query for extended functions
|
|
|
|
cpuid ; Get extended function limit
|
|
|
|
cmp eax,80000001h
|
2004-01-24 15:55:00 +00:00
|
|
|
jl done ; Nope, we dont have function 800000001h
|
2003-11-24 09:16:52 +00:00
|
|
|
mov eax,80000001h ; Setup extended function 800000001h
|
|
|
|
cpuid ; and get the information
|
2004-01-24 05:47:19 +00:00
|
|
|
mov features,edx
|
2003-11-24 09:16:52 +00:00
|
|
|
done:
|
|
|
|
}
|
2006-01-05 08:17:35 +00:00
|
|
|
#elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
|
|
|
|
__asm (
|
|
|
|
" movl %ebx,%edi\n"
|
|
|
|
" movl $0x80000000,%eax \n"
|
|
|
|
" cpuid \n"
|
|
|
|
" cmpl $0x80000001,%eax \n"
|
|
|
|
" jl 1f \n"
|
|
|
|
" movl $0x80000001,%eax \n"
|
|
|
|
" cpuid \n"
|
|
|
|
#ifdef __i386
|
|
|
|
" movl %edx,-8(%ebp) \n"
|
|
|
|
#else
|
|
|
|
" movl %edx,-8(%rbp) \n"
|
|
|
|
#endif
|
|
|
|
"1: \n"
|
|
|
|
" movl %edi,%ebx\n"
|
|
|
|
);
|
2003-11-24 09:16:52 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
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;
|
2006-03-22 22:29:44 +00:00
|
|
|
#if defined(__MACOSX__) && defined(__ppc__)
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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: */
|