Commit e4a0db29 authored by Sam Lantinga's avatar Sam Lantinga

Re-added the 3DNow! and AltiVec instruction support.

parent 92bf0fc2
......@@ -52,7 +52,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_WIN32_WINNT=0x0400;__MMX__;__3dNOW__;__SSE__;__SSE2__"
PreprocessorDefinitions="_DEBUG;_WINDOWS"
RuntimeLibrary="2"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
......@@ -231,7 +231,7 @@
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="false"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_WIN32_WINNT=0x0400;__MMX__;__3dNOW__;__SSE__;__SSE2__"
PreprocessorDefinitions="NDEBUG;_WINDOWS"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
......
......@@ -52,7 +52,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="_DEBUG;_WINDOWS;_WIN32_WINNT=0x0400;__MMX__;__3dNOW__;__SSE__;__SSE2__"
PreprocessorDefinitions="_DEBUG;_WINDOWS"
RuntimeLibrary="3"
BufferSecurityCheck="false"
WarningLevel="3"
......@@ -223,7 +223,7 @@
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="false"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="NDEBUG;_WINDOWS;_WIN32_WINNT=0x0400;__MMX__;__3dNOW__;__SSE__;__SSE2__"
PreprocessorDefinitions="NDEBUG;_WINDOWS"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
......
......@@ -83,7 +83,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_WIN32_WINNT=0x0400;__MMX__;__3dNOW__;__SSE__;__SSE2__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeader>
......@@ -152,7 +152,7 @@
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<IntrinsicFunctions>false</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_WIN32_WINNT=0x0400;__MMX__;__3dNOW__;__SSE__;__SSE2__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
......
This diff is collapsed.
......@@ -501,6 +501,33 @@ AC_HELP_STRING([--enable-mmx], [use MMX assembly routines [[default=yes]]]),
fi
fi
AC_ARG_ENABLE(3dnow,
AC_HELP_STRING([--enable-3dnow], [use MMX assembly routines [[default=yes]]]),
, enable_3dnow=yes)
if test x$enable_3dnow = xyes; then
save_CFLAGS="$CFLAGS"
have_gcc_3dnow=no
AC_MSG_CHECKING(for GCC -m3dnow option)
amd3dnow_CFLAGS="-m3dnow"
CFLAGS="$save_CFLAGS $amd3dnow_CFLAGS"
AC_TRY_COMPILE([
#include <mm3dnow.h>
#ifndef __3dNOW__
#error Assembler CPP flag not enabled
#endif
],[
],[
have_gcc_3dnow=yes
])
AC_MSG_RESULT($have_gcc_3dnow)
CFLAGS="$save_CFLAGS"
if test x$have_gcc_3dnow = xyes; then
EXTRA_CFLAGS="$EXTRA_CFLAGS $amd3dnow_CFLAGS"
fi
fi
AC_ARG_ENABLE(sse,
AC_HELP_STRING([--enable-sse], [use SSE assembly routines [[default=yes]]]),
, enable_sse=yes)
......@@ -572,6 +599,82 @@ AC_HELP_STRING([--enable-sse2], [use SSE2 assembly routines [[default=no]]]),
EXTRA_CFLAGS="$EXTRA_CFLAGS $sse2_CFLAGS"
fi
fi
AC_ARG_ENABLE(altivec,
AC_HELP_STRING([--enable-altivec], [use Altivec assembly routines [[default=yes]]]),
, enable_altivec=yes)
if test x$enable_altivec = xyes; then
save_CFLAGS="$CFLAGS"
have_gcc_altivec=no
have_altivec_h_hdr=no
altivec_CFLAGS="-maltivec"
CFLAGS="$save_CFLAGS $altivec_CFLAGS"
AC_MSG_CHECKING(for Altivec with GCC altivec.h and -maltivec option)
AC_TRY_COMPILE([
#include <altivec.h>
vector unsigned int vzero() {
return vec_splat_u32(0);
}
],[
],[
have_gcc_altivec=yes
have_altivec_h_hdr=yes
])
AC_MSG_RESULT($have_gcc_altivec)
if test x$have_gcc_altivec = xno; then
AC_MSG_CHECKING(for Altivec with GCC -maltivec option)
AC_TRY_COMPILE([
vector unsigned int vzero() {
return vec_splat_u32(0);
}
],[
],[
have_gcc_altivec=yes
])
AC_MSG_RESULT($have_gcc_altivec)
fi
if test x$have_gcc_altivec = xno; then
AC_MSG_CHECKING(for Altivec with GCC altivec.h and -faltivec option)
altivec_CFLAGS="-faltivec"
CFLAGS="$save_CFLAGS $altivec_CFLAGS"
AC_TRY_COMPILE([
#include <altivec.h>
vector unsigned int vzero() {
return vec_splat_u32(0);
}
],[
],[
have_gcc_altivec=yes
have_altivec_h_hdr=yes
])
AC_MSG_RESULT($have_gcc_altivec)
fi
if test x$have_gcc_altivec = xno; then
AC_MSG_CHECKING(for Altivec with GCC -faltivec option)
AC_TRY_COMPILE([
vector unsigned int vzero() {
return vec_splat_u32(0);
}
],[
],[
have_gcc_altivec=yes
])
AC_MSG_RESULT($have_gcc_altivec)
fi
CFLAGS="$save_CFLAGS"
if test x$have_gcc_altivec = xyes; then
AC_DEFINE(SDL_ALTIVEC_BLITTERS)
if test x$have_altivec_h_hdr = xyes; then
AC_DEFINE(HAVE_ALTIVEC_H)
fi
EXTRA_CFLAGS="$EXTRA_CFLAGS $altivec_CFLAGS"
fi
fi
fi
dnl See if the OSS audio interface is supported
......
......@@ -34,7 +34,7 @@
/* Make sure that this isn't included by Visual C++ */
#ifdef _MSC_VER
#error You should copy include/SDL_config.h.default to include/SDL_config.h
#error You should run hg revert SDL_config.h
#endif
/* C language features */
......@@ -82,6 +82,7 @@
#undef HAVE_MATH_H
#undef HAVE_ICONV_H
#undef HAVE_SIGNAL_H
#undef HAVE_ALTIVEC_H
/* C library functions */
#undef HAVE_MALLOC
......@@ -302,5 +303,6 @@
/* Enable assembly routines */
#undef SDL_ASSEMBLY_ROUTINES
#undef SDL_ALTIVEC_BLITTERS
#endif /* _SDL_config_h */
......@@ -168,5 +168,8 @@
/* Enable assembly routines */
#define SDL_ASSEMBLY_ROUTINES 1
#ifdef __ppc__
#define SDL_ALTIVEC_BLITTERS 1
#endif
#endif /* _SDL_config_macosx_h */
......@@ -31,6 +31,34 @@
#include "SDL_stdinc.h"
/* Need to do this here because intrin.h has C++ code in it */
/* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
#if defined(_MSC_VER) && (_MSC_VER >= 1500) && !defined(_WIN32_WCE)
#include <intrin.h>
#define __MMX__
#define __3dNOW__
#define __SSE__
#define __SSE2__
#elif defined(__MINGW64_VERSION_MAJOR)
#include <intrin.h>
#else
#ifdef __MMX__
#include <mmintrin.h>
#endif
#ifdef __3dNOW__
#include <mm3dnow.h>
#endif
#ifdef __SSE__
#include <xmmintrin.h>
#endif
#ifdef __SSE2__
#include <emmintrin.h>
#endif
#ifdef HAVE_ALTIVEC_H
#include <altivec.h>
#endif
#endif
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
......@@ -64,11 +92,21 @@ extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
*/
extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
/**
* This function returns true if the CPU has AltiVec features.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
/**
* This function returns true if the CPU has MMX features.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
/**
* This function returns true if the CPU has 3DNow! features.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
/**
* This function returns true if the CPU has SSE features.
*/
......
......@@ -32,18 +32,37 @@
#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
#include <signal.h>
#include <setjmp.h>
#endif
#ifdef __WIN32__
#include "../core/windows/SDL_windows.h"
#endif
#define CPU_HAS_RDTSC 0x00000001
#define CPU_HAS_MMX 0x00000002
#define CPU_HAS_ALTIVEC 0x00000002
#define CPU_HAS_MMX 0x00000004
#define CPU_HAS_3DNOW 0x00000008
#define CPU_HAS_SSE 0x00000010
#define CPU_HAS_SSE2 0x00000020
#define CPU_HAS_SSE3 0x00000040
#define CPU_HAS_SSE41 0x00000080
#define CPU_HAS_SSE42 0x00000100
#define CPU_HAS_SSE41 0x00000100
#define CPU_HAS_SSE42 0x00000200
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__
/* This is the brute force way of detecting instruction sets...
the idea is borrowed from the libmpeg2 library - thanks!
*/
static jmp_buf jmpbuf;
static void
illegal_instruction(int sig)
{
longjmp(jmpbuf, 1);
}
#endif /* HAVE_SETJMP */
static __inline__ int
CPU_haveCPUID(void)
......@@ -192,6 +211,29 @@ CPU_haveRDTSC(void)
return 0;
}
static __inline__ int
CPU_haveAltiVec(void)
{
volatile int altivec = 0;
#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
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);
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
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);
#endif
return altivec;
}
static __inline__ int
CPU_haveMMX(void)
{
......@@ -201,6 +243,21 @@ CPU_haveMMX(void)
return 0;
}
static __inline__ int
CPU_have3DNow(void)
{
if (CPU_haveCPUID()) {
int a, b, c, d;
cpuid(0x80000000, a, b, c, d);
if (a >= 0x80000001) {
cpuid(0x80000001, a, b, c, d);
return (d & 0x80000000);
}
}
return 0;
}
static __inline__ int
CPU_haveSSE(void)
{
......@@ -431,9 +488,15 @@ SDL_GetCPUFeatures(void)
if (CPU_haveRDTSC()) {
SDL_CPUFeatures |= CPU_HAS_RDTSC;
}
if (CPU_haveAltiVec()) {
SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
}
if (CPU_haveMMX()) {
SDL_CPUFeatures |= CPU_HAS_MMX;
}
if (CPU_have3DNow()) {
SDL_CPUFeatures |= CPU_HAS_3DNOW;
}
if (CPU_haveSSE()) {
SDL_CPUFeatures |= CPU_HAS_SSE;
}
......@@ -462,6 +525,15 @@ SDL_HasRDTSC(void)
return SDL_FALSE;
}
SDL_bool
SDL_HasAltiVec(void)
{
if (SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC) {
return SDL_TRUE;
}
return SDL_FALSE;
}
SDL_bool
SDL_HasMMX(void)
{
......@@ -471,6 +543,15 @@ SDL_HasMMX(void)
return SDL_FALSE;
}
SDL_bool
SDL_Has3DNow(void)
{
if (SDL_GetCPUFeatures() & CPU_HAS_3DNOW) {
return SDL_TRUE;
}
return SDL_FALSE;
}
SDL_bool
SDL_HasSSE(void)
{
......@@ -528,7 +609,9 @@ main()
printf("CPU name: %s\n", SDL_GetCPUName());
printf("CacheLine size: %d\n", SDL_GetCPUCacheLineSize());
printf("RDTSC: %d\n", SDL_HasRDTSC());
printf("Altivec: %d\n", SDL_HasAltiVec());
printf("MMX: %d\n", SDL_HasMMX());
printf("3DNow: %d\n", SDL_Has3DNow());
printf("SSE: %d\n", SDL_HasSSE());
printf("SSE2: %d\n", SDL_HasSSE2());
printf("SSE3: %d\n", SDL_HasSSE3());
......
......@@ -100,6 +100,30 @@ SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
return (okay ? 0 : -1);
}
#ifdef __MACOSX__
#include <sys/sysctl.h>
static SDL_bool
SDL_UseAltivecPrefetch()
{
const char key[] = "hw.l3cachesize";
u_int64_t result = 0;
size_t typeSize = sizeof(result);
if (sysctlbyname(key, &result, &typeSize, NULL, 0) == 0 && result > 0) {
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}
#else
static SDL_bool
SDL_UseAltivecPrefetch()
{
/* Just guess G4 */
return SDL_TRUE;
}
#endif /* __MACOSX__ */
static SDL_BlitFunc
SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
......@@ -121,12 +145,22 @@ SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
if (SDL_HasMMX()) {
features |= SDL_CPU_MMX;
}
if (SDL_Has3DNow()) {
features |= SDL_CPU_3DNOW;
}
if (SDL_HasSSE()) {
features |= SDL_CPU_SSE;
}
if (SDL_HasSSE2()) {
features |= SDL_CPU_SSE2;
}
if (SDL_HasAltiVec()) {
if (SDL_UseAltivecPrefetch()) {
features |= SDL_CPU_ALTIVEC_PREFETCH;
} else {
features |= SDL_CPU_ALTIVEC_NOPREFETCH;
}
}
}
}
......
......@@ -24,24 +24,6 @@
#ifndef _SDL_blit_h
#define _SDL_blit_h
#ifdef __MINGW32__
#include <_mingw.h>
#endif
#if defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)
#include <intrin.h>
#else
#ifdef __MMX__
#include <mmintrin.h>
#endif
#ifdef __SSE__
#include <xmmintrin.h>
#endif
#ifdef __SSE2__
#include <emmintrin.h>
#endif
#endif
#include "SDL_cpuinfo.h"
#include "SDL_endian.h"
#include "SDL_surface.h"
......@@ -62,8 +44,11 @@
/* SDL blit CPU flags */
#define SDL_CPU_ANY 0x00000000
#define SDL_CPU_MMX 0x00000001
#define SDL_CPU_3DNOW 0x00000002
#define SDL_CPU_SSE 0x00000004
#define SDL_CPU_SSE2 0x00000008
#define SDL_CPU_ALTIVEC_PREFETCH 0x00000010
#define SDL_CPU_ALTIVEC_NOPREFETCH 0x00000020
typedef struct
{
......
This diff is collapsed.
This diff is collapsed.
......@@ -158,7 +158,9 @@ int test_platform (void)
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, " AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " MMX %s\n", SDL_HasMMX()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " 3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " SSE %s\n", SDL_HasSSE()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected" );
......
......@@ -142,7 +142,9 @@ TestCPUInfo(SDL_bool verbose)
printf("CPU count: %d\n", SDL_GetCPUCount());
printf("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
printf("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
printf("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
printf("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment