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