src/cpuinfo/SDL_cpuinfo.c
changeset 739 22dbf364c017
child 745 71ee03909f42
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Tue Nov 18 01:27:06 2003 +0000
     1.3 @@ -0,0 +1,96 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/* CPU feature detection for SDL */
    1.32 +
    1.33 +#include "SDL.h"
    1.34 +//#include "SDL_cpuinfo.h"
    1.35 +
    1.36 +#define CPU_HAS_MMX	0x00000001
    1.37 +#define CPU_HAS_3DNOW	0x00000002
    1.38 +#define CPU_HAS_SSE	0x00000004
    1.39 +
    1.40 +/* These functions come from SciTech's PM library */
    1.41 +extern int CPU_haveMMX();
    1.42 +extern int CPU_have3DNow();
    1.43 +extern int CPU_haveSSE();
    1.44 +
    1.45 +static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
    1.46 +
    1.47 +static Uint32 SDL_GetCPUFeatures()
    1.48 +{
    1.49 +	if ( SDL_CPUFeatures == 0xFFFFFFFF ) {
    1.50 +		SDL_CPUFeatures = 0;
    1.51 +		if ( CPU_haveMMX() ) {
    1.52 +			SDL_CPUFeatures |= CPU_HAS_MMX;
    1.53 +		}
    1.54 +		if ( CPU_have3DNow() ) {
    1.55 +			SDL_CPUFeatures |= CPU_HAS_3DNOW;
    1.56 +		}
    1.57 +		if ( CPU_haveSSE() ) {
    1.58 +			SDL_CPUFeatures |= CPU_HAS_SSE;
    1.59 +		}
    1.60 +	}
    1.61 +	return SDL_CPUFeatures;
    1.62 +}
    1.63 +
    1.64 +SDL_bool SDL_HasMMX()
    1.65 +{
    1.66 +	if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) {
    1.67 +		return SDL_TRUE;
    1.68 +	}
    1.69 +	return SDL_FALSE;
    1.70 +}
    1.71 +
    1.72 +SDL_bool SDL_Has3DNow()
    1.73 +{
    1.74 +	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) {
    1.75 +		return SDL_TRUE;
    1.76 +	}
    1.77 +	return SDL_FALSE;
    1.78 +}
    1.79 +
    1.80 +SDL_bool SDL_HasSSE()
    1.81 +{
    1.82 +	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) {
    1.83 +		return SDL_TRUE;
    1.84 +	}
    1.85 +	return SDL_FALSE;
    1.86 +}
    1.87 +
    1.88 +#ifdef TEST_MAIN
    1.89 +
    1.90 +#include <stdio.h>
    1.91 +
    1.92 +int main()
    1.93 +{
    1.94 +	printf("MMX: %d\n", SDL_HasMMX());
    1.95 +	printf("3DNow: %d\n", SDL_Has3DNow());
    1.96 +	printf("SSE: %d\n", SDL_HasSSE());
    1.97 +}
    1.98 +
    1.99 +#endif /* TEST_MAIN */