include/SDL_cpuinfo.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 22 Feb 2011 21:44:36 -0800
changeset 5389 24903690f48a
parent 5263 e1122f31fec5
child 5390 fefd4f7b5214
permissions -rw-r--r--
Re-added the 3DNow! and AltiVec instruction support.
     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 #define __MMX__
    39 #define __3dNOW__
    40 #define __SSE__
    41 #define __SSE2__
    42 #elif defined(__MINGW64_VERSION_MAJOR)
    43 #include <intrin.h>
    44 #else
    45 #ifdef __MMX__
    46 #include <mmintrin.h>
    47 #endif
    48 #ifdef __3dNOW__
    49 #include <mm3dnow.h>
    50 #endif
    51 #ifdef __SSE__
    52 #include <xmmintrin.h>
    53 #endif
    54 #ifdef __SSE2__
    55 #include <emmintrin.h>
    56 #endif
    57 #ifdef HAVE_ALTIVEC_H
    58 #include <altivec.h>
    59 #endif
    60 #endif
    61 
    62 #include "begin_code.h"
    63 /* Set up for C function definitions, even when using C++ */
    64 #ifdef __cplusplus
    65 /* *INDENT-OFF* */
    66 extern "C" {
    67 /* *INDENT-ON* */
    68 #endif
    69 
    70 /* This is a guess for the cacheline size used for padding.
    71  * Most x86 processors have a 64 byte cache line.
    72  * The 64-bit PowerPC processors have a 128 byte cache line.
    73  * We'll use the larger value to be generally safe.
    74  */
    75 #define SDL_CACHELINE_SIZE  128
    76 
    77 /**
    78  *  This function returns the number of CPU cores available.
    79  */
    80 extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
    81 
    82 /**
    83  *  This function returns the L1 cache line size of the CPU
    84  *
    85  *  This is useful for determining multi-threaded structure padding
    86  *  or SIMD prefetch sizes.
    87  */
    88 extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
    89 
    90 /**
    91  *  This function returns true if the CPU has the RDTSC instruction.
    92  */
    93 extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
    94 
    95 /**
    96  *  This function returns true if the CPU has AltiVec features.
    97  */
    98 extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
    99 
   100 /**
   101  *  This function returns true if the CPU has MMX features.
   102  */
   103 extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
   104 
   105 /**
   106  *  This function returns true if the CPU has 3DNow! features.
   107  */
   108 extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
   109 
   110 /**
   111  *  This function returns true if the CPU has SSE features.
   112  */
   113 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
   114 
   115 /**
   116  *  This function returns true if the CPU has SSE2 features.
   117  */
   118 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
   119 
   120 /**
   121  *  This function returns true if the CPU has SSE3 features.
   122  */
   123 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
   124 
   125 /**
   126  *  This function returns true if the CPU has SSE4.1 features.
   127  */
   128 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
   129 
   130 /**
   131  *  This function returns true if the CPU has SSE4.2 features.
   132  */
   133 extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
   134 
   135 
   136 /* Ends C function definitions when using C++ */
   137 #ifdef __cplusplus
   138 /* *INDENT-OFF* */
   139 }
   140 /* *INDENT-ON* */
   141 #endif
   142 #include "close_code.h"
   143 
   144 #endif /* _SDL_cpuinfo_h */
   145 
   146 /* vi: set ts=4 sw=4 expandtab: */