include/SDL_cpuinfo.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 07 Mar 2011 22:04:10 -0800
changeset 5450 58630b98eb63
parent 5407 40c9d744e595
child 5535 96594ac5fd1a
permissions -rw-r--r--
The MMX and 3DNow! instructions can't be compiled by 64-bit Visual Studio.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2011 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 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     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /**
    24  *  \file SDL_cpuinfo.h
    25  *  
    26  *  CPU feature detection for SDL.
    27  */
    28 
    29 #ifndef _SDL_cpuinfo_h
    30 #define _SDL_cpuinfo_h
    31 
    32 #include "SDL_stdinc.h"
    33 
    34 /* Need to do this here because intrin.h has C++ code in it */
    35 /* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
    36 #if defined(_MSC_VER) && (_MSC_VER >= 1500) && !defined(_WIN32_WCE)
    37 #include <intrin.h>
    38 #ifndef _WIN64
    39 #define __MMX__
    40 #define __3dNOW__
    41 #endif
    42 #define __SSE__
    43 #define __SSE2__
    44 #elif defined(__MINGW64_VERSION_MAJOR)
    45 #include <intrin.h>
    46 #else
    47 #ifdef __ALTIVEC__
    48 #if HAVE_ALTIVEC_H && !defined(__APPLE_ALTIVEC__)
    49 #include <altivec.h>
    50 #undef pixel
    51 #endif
    52 #endif
    53 #ifdef __MMX__
    54 #include <mmintrin.h>
    55 #endif
    56 #ifdef __3dNOW__
    57 #include <mm3dnow.h>
    58 #endif
    59 #ifdef __SSE__
    60 #include <xmmintrin.h>
    61 #endif
    62 #ifdef __SSE2__
    63 #include <emmintrin.h>
    64 #endif
    65 #endif
    66 
    67 #include "begin_code.h"
    68 /* Set up for C function definitions, even when using C++ */
    69 #ifdef __cplusplus
    70 /* *INDENT-OFF* */
    71 extern "C" {
    72 /* *INDENT-ON* */
    73 #endif
    74 
    75 /* This is a guess for the cacheline size used for padding.
    76  * Most x86 processors have a 64 byte cache line.
    77  * The 64-bit PowerPC processors have a 128 byte cache line.
    78  * We'll use the larger value to be generally safe.
    79  */
    80 #define SDL_CACHELINE_SIZE  128
    81 
    82 /**
    83  *  This function returns the number of CPU cores available.
    84  */
    85 extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
    86 
    87 /**
    88  *  This function returns the L1 cache line size of the CPU
    89  *
    90  *  This is useful for determining multi-threaded structure padding
    91  *  or SIMD prefetch sizes.
    92  */
    93 extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
    94 
    95 /**
    96  *  This function returns true if the CPU has the RDTSC instruction.
    97  */
    98 extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
    99 
   100 /**
   101  *  This function returns true if the CPU has AltiVec features.
   102  */
   103 extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
   104 
   105 /**
   106  *  This function returns true if the CPU has MMX features.
   107  */
   108 extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
   109 
   110 /**
   111  *  This function returns true if the CPU has 3DNow! features.
   112  */
   113 extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
   114 
   115 /**
   116  *  This function returns true if the CPU has SSE features.
   117  */
   118 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
   119 
   120 /**
   121  *  This function returns true if the CPU has SSE2 features.
   122  */
   123 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
   124 
   125 /**
   126  *  This function returns true if the CPU has SSE3 features.
   127  */
   128 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
   129 
   130 /**
   131  *  This function returns true if the CPU has SSE4.1 features.
   132  */
   133 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
   134 
   135 /**
   136  *  This function returns true if the CPU has SSE4.2 features.
   137  */
   138 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
   139 
   140 
   141 /* Ends C function definitions when using C++ */
   142 #ifdef __cplusplus
   143 /* *INDENT-OFF* */
   144 }
   145 /* *INDENT-ON* */
   146 #endif
   147 #include "close_code.h"
   148 
   149 #endif /* _SDL_cpuinfo_h */
   150 
   151 /* vi: set ts=4 sw=4 expandtab: */