src/cpuinfo/SDL_cpuinfo.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 18 Nov 2003 01:27:06 +0000
changeset 739 22dbf364c017
child 745 71ee03909f42
permissions -rw-r--r--
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
slouken@739
     1
/*
slouken@739
     2
    SDL - Simple DirectMedia Layer
slouken@739
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
slouken@739
     4
slouken@739
     5
    This library is free software; you can redistribute it and/or
slouken@739
     6
    modify it under the terms of the GNU Library General Public
slouken@739
     7
    License as published by the Free Software Foundation; either
slouken@739
     8
    version 2 of the License, or (at your option) any later version.
slouken@739
     9
slouken@739
    10
    This library is distributed in the hope that it will be useful,
slouken@739
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@739
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@739
    13
    Library General Public License for more details.
slouken@739
    14
slouken@739
    15
    You should have received a copy of the GNU Library General Public
slouken@739
    16
    License along with this library; if not, write to the Free
slouken@739
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@739
    18
slouken@739
    19
    Sam Lantinga
slouken@739
    20
    slouken@libsdl.org
slouken@739
    21
*/
slouken@739
    22
slouken@739
    23
#ifdef SAVE_RCSID
slouken@739
    24
static char rcsid =
slouken@739
    25
 "@(#) $Id$";
slouken@739
    26
#endif
slouken@739
    27
slouken@739
    28
/* CPU feature detection for SDL */
slouken@739
    29
slouken@739
    30
#include "SDL.h"
slouken@739
    31
//#include "SDL_cpuinfo.h"
slouken@739
    32
slouken@739
    33
#define CPU_HAS_MMX	0x00000001
slouken@739
    34
#define CPU_HAS_3DNOW	0x00000002
slouken@739
    35
#define CPU_HAS_SSE	0x00000004
slouken@739
    36
slouken@739
    37
/* These functions come from SciTech's PM library */
slouken@739
    38
extern int CPU_haveMMX();
slouken@739
    39
extern int CPU_have3DNow();
slouken@739
    40
extern int CPU_haveSSE();
slouken@739
    41
slouken@739
    42
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
slouken@739
    43
slouken@739
    44
static Uint32 SDL_GetCPUFeatures()
slouken@739
    45
{
slouken@739
    46
	if ( SDL_CPUFeatures == 0xFFFFFFFF ) {
slouken@739
    47
		SDL_CPUFeatures = 0;
slouken@739
    48
		if ( CPU_haveMMX() ) {
slouken@739
    49
			SDL_CPUFeatures |= CPU_HAS_MMX;
slouken@739
    50
		}
slouken@739
    51
		if ( CPU_have3DNow() ) {
slouken@739
    52
			SDL_CPUFeatures |= CPU_HAS_3DNOW;
slouken@739
    53
		}
slouken@739
    54
		if ( CPU_haveSSE() ) {
slouken@739
    55
			SDL_CPUFeatures |= CPU_HAS_SSE;
slouken@739
    56
		}
slouken@739
    57
	}
slouken@739
    58
	return SDL_CPUFeatures;
slouken@739
    59
}
slouken@739
    60
slouken@739
    61
SDL_bool SDL_HasMMX()
slouken@739
    62
{
slouken@739
    63
	if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) {
slouken@739
    64
		return SDL_TRUE;
slouken@739
    65
	}
slouken@739
    66
	return SDL_FALSE;
slouken@739
    67
}
slouken@739
    68
slouken@739
    69
SDL_bool SDL_Has3DNow()
slouken@739
    70
{
slouken@739
    71
	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) {
slouken@739
    72
		return SDL_TRUE;
slouken@739
    73
	}
slouken@739
    74
	return SDL_FALSE;
slouken@739
    75
}
slouken@739
    76
slouken@739
    77
SDL_bool SDL_HasSSE()
slouken@739
    78
{
slouken@739
    79
	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) {
slouken@739
    80
		return SDL_TRUE;
slouken@739
    81
	}
slouken@739
    82
	return SDL_FALSE;
slouken@739
    83
}
slouken@739
    84
slouken@739
    85
#ifdef TEST_MAIN
slouken@739
    86
slouken@739
    87
#include <stdio.h>
slouken@739
    88
slouken@739
    89
int main()
slouken@739
    90
{
slouken@739
    91
	printf("MMX: %d\n", SDL_HasMMX());
slouken@739
    92
	printf("3DNow: %d\n", SDL_Has3DNow());
slouken@739
    93
	printf("SSE: %d\n", SDL_HasSSE());
slouken@739
    94
}
slouken@739
    95
slouken@739
    96
#endif /* TEST_MAIN */