include/SDL_cpuinfo.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 11 Dec 2017 12:00:12 -0800
changeset 11762 c4900725a75a
parent 11699 afe271f50c70
child 11770 58a69c196061
permissions -rw-r--r--
Check for immintrin.h before using it in SDL_cpuinfo.h
slouken@739
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@739
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@739
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@739
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@739
    20
*/
slouken@739
    21
slouken@1895
    22
/**
slouken@3407
    23
 *  \file SDL_cpuinfo.h
slouken@7191
    24
 *
slouken@3407
    25
 *  CPU feature detection for SDL.
slouken@1895
    26
 */
slouken@739
    27
slouken@10638
    28
#ifndef SDL_cpuinfo_h_
slouken@10638
    29
#define SDL_cpuinfo_h_
slouken@739
    30
slouken@1402
    31
#include "SDL_stdinc.h"
slouken@1402
    32
slouken@5389
    33
/* Need to do this here because intrin.h has C++ code in it */
slouken@5389
    34
/* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
dludwig@8320
    35
#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_IX86) || defined(_M_X64))
slouken@11330
    36
#ifdef __clang__
slouken@11330
    37
/* Many of the intrinsics SDL uses are not implemented by clang with Visual Studio */
slouken@11330
    38
#undef __MMX__
slouken@11330
    39
#undef __SSE__
slouken@11330
    40
#undef __SSE2__
slouken@11330
    41
#else
slouken@5389
    42
#include <intrin.h>
slouken@5450
    43
#ifndef _WIN64
slouken@5389
    44
#define __MMX__
slouken@5389
    45
#define __3dNOW__
slouken@5450
    46
#endif
slouken@5389
    47
#define __SSE__
slouken@5389
    48
#define __SSE2__
slouken@11330
    49
#endif /* __clang__ */
slouken@5389
    50
#elif defined(__MINGW64_VERSION_MAJOR)
slouken@5389
    51
#include <intrin.h>
slouken@5389
    52
#else
slouken@5390
    53
#ifdef __ALTIVEC__
slouken@5390
    54
#if HAVE_ALTIVEC_H && !defined(__APPLE_ALTIVEC__)
slouken@5390
    55
#include <altivec.h>
slouken@5390
    56
#undef pixel
slouken@5390
    57
#endif
slouken@5390
    58
#endif
slouken@5389
    59
#ifdef __3dNOW__
slouken@5389
    60
#include <mm3dnow.h>
slouken@5389
    61
#endif
slouken@11762
    62
#if HAVE_IMMINTRIN_H
slouken@11698
    63
#include <immintrin.h>
slouken@11762
    64
#else
slouken@11762
    65
#ifdef __MMX__
slouken@11762
    66
#include <mmintrin.h>
slouken@5389
    67
#endif
slouken@11762
    68
#ifdef __3dNOW__
slouken@11762
    69
#include <mm3dnow.h>
slouken@11699
    70
#endif
slouken@11762
    71
#ifdef __SSE__
slouken@11762
    72
#include <xmmintrin.h>
slouken@11762
    73
#endif
slouken@11762
    74
#ifdef __SSE2__
slouken@11762
    75
#include <emmintrin.h>
slouken@11762
    76
#endif
slouken@11762
    77
#ifdef __SSE3__
slouken@11762
    78
#include <pmmintrin.h>
slouken@11762
    79
#endif
slouken@11762
    80
#endif /* HAVE_IMMINTRIN_H */
slouken@11762
    81
#endif /* compiler version */
slouken@5389
    82
slouken@739
    83
#include "begin_code.h"
slouken@739
    84
/* Set up for C function definitions, even when using C++ */
slouken@739
    85
#ifdef __cplusplus
slouken@739
    86
extern "C" {
slouken@739
    87
#endif
slouken@739
    88
slouken@5116
    89
/* This is a guess for the cacheline size used for padding.
slouken@5116
    90
 * Most x86 processors have a 64 byte cache line.
slouken@5116
    91
 * The 64-bit PowerPC processors have a 128 byte cache line.
slouken@5116
    92
 * We'll use the larger value to be generally safe.
slouken@5115
    93
 */
slouken@5116
    94
#define SDL_CACHELINE_SIZE  128
slouken@5115
    95
slouken@3407
    96
/**
slouken@3579
    97
 *  This function returns the number of CPU cores available.
slouken@3579
    98
 */
slouken@3579
    99
extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
slouken@3579
   100
slouken@3579
   101
/**
slouken@5120
   102
 *  This function returns the L1 cache line size of the CPU
slouken@5120
   103
 *
slouken@5120
   104
 *  This is useful for determining multi-threaded structure padding
slouken@5120
   105
 *  or SIMD prefetch sizes.
slouken@5120
   106
 */
slouken@5120
   107
extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
slouken@5120
   108
slouken@5120
   109
/**
slouken@3407
   110
 *  This function returns true if the CPU has the RDTSC instruction.
slouken@745
   111
 */
slouken@1426
   112
extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
slouken@745
   113
slouken@3407
   114
/**
slouken@5389
   115
 *  This function returns true if the CPU has AltiVec features.
slouken@5389
   116
 */
slouken@5389
   117
extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
slouken@5389
   118
slouken@5389
   119
/**
slouken@3407
   120
 *  This function returns true if the CPU has MMX features.
slouken@739
   121
 */
slouken@1426
   122
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
slouken@739
   123
slouken@3407
   124
/**
slouken@5389
   125
 *  This function returns true if the CPU has 3DNow! features.
slouken@5389
   126
 */
slouken@5389
   127
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
slouken@5389
   128
slouken@5389
   129
/**
slouken@3407
   130
 *  This function returns true if the CPU has SSE features.
slouken@739
   131
 */
slouken@1426
   132
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
slouken@739
   133
slouken@3407
   134
/**
slouken@3407
   135
 *  This function returns true if the CPU has SSE2 features.
slouken@785
   136
 */
slouken@1426
   137
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
slouken@785
   138
slouken@3407
   139
/**
slouken@5259
   140
 *  This function returns true if the CPU has SSE3 features.
slouken@778
   141
 */
slouken@5259
   142
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
slouken@5259
   143
slouken@5259
   144
/**
slouken@5263
   145
 *  This function returns true if the CPU has SSE4.1 features.
slouken@5259
   146
 */
slouken@5263
   147
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
slouken@5263
   148
slouken@5263
   149
/**
slouken@5263
   150
 *  This function returns true if the CPU has SSE4.2 features.
slouken@5263
   151
 */
slouken@5263
   152
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
slouken@5259
   153
slouken@7821
   154
/**
slouken@8148
   155
 *  This function returns true if the CPU has AVX features.
slouken@8148
   156
 */
slouken@8148
   157
extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
slouken@8148
   158
slouken@8148
   159
/**
slouken@9003
   160
 *  This function returns true if the CPU has AVX2 features.
slouken@9003
   161
 */
slouken@9003
   162
extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
slouken@9003
   163
slouken@9003
   164
/**
icculus@10620
   165
 *  This function returns true if the CPU has NEON (ARM SIMD) features.
icculus@10620
   166
 */
icculus@10620
   167
extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
icculus@10620
   168
icculus@10620
   169
/**
slouken@7821
   170
 *  This function returns the amount of RAM configured in the system, in MB.
slouken@7821
   171
 */
slouken@7821
   172
extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
slouken@7821
   173
slouken@778
   174
slouken@739
   175
/* Ends C function definitions when using C++ */
slouken@739
   176
#ifdef __cplusplus
slouken@739
   177
}
slouken@739
   178
#endif
slouken@739
   179
#include "close_code.h"
slouken@739
   180
slouken@10638
   181
#endif /* SDL_cpuinfo_h_ */
slouken@1895
   182
slouken@1895
   183
/* vi: set ts=4 sw=4 expandtab: */