include/SDL_cpuinfo.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 11 Nov 2017 16:20:00 -0800
changeset 11699 afe271f50c70
parent 11698 c5ae532b96d0
child 11762 c4900725a75a
permissions -rw-r--r--
Only include Intel intrinsics header on x86 and x64
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@11699
    62
#if defined(__i386__) || defined(__x86_64__)
slouken@11698
    63
#include <immintrin.h>
slouken@5389
    64
#endif
slouken@11699
    65
#endif
slouken@5389
    66
slouken@739
    67
#include "begin_code.h"
slouken@739
    68
/* Set up for C function definitions, even when using C++ */
slouken@739
    69
#ifdef __cplusplus
slouken@739
    70
extern "C" {
slouken@739
    71
#endif
slouken@739
    72
slouken@5116
    73
/* This is a guess for the cacheline size used for padding.
slouken@5116
    74
 * Most x86 processors have a 64 byte cache line.
slouken@5116
    75
 * The 64-bit PowerPC processors have a 128 byte cache line.
slouken@5116
    76
 * We'll use the larger value to be generally safe.
slouken@5115
    77
 */
slouken@5116
    78
#define SDL_CACHELINE_SIZE  128
slouken@5115
    79
slouken@3407
    80
/**
slouken@3579
    81
 *  This function returns the number of CPU cores available.
slouken@3579
    82
 */
slouken@3579
    83
extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
slouken@3579
    84
slouken@3579
    85
/**
slouken@5120
    86
 *  This function returns the L1 cache line size of the CPU
slouken@5120
    87
 *
slouken@5120
    88
 *  This is useful for determining multi-threaded structure padding
slouken@5120
    89
 *  or SIMD prefetch sizes.
slouken@5120
    90
 */
slouken@5120
    91
extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
slouken@5120
    92
slouken@5120
    93
/**
slouken@3407
    94
 *  This function returns true if the CPU has the RDTSC instruction.
slouken@745
    95
 */
slouken@1426
    96
extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
slouken@745
    97
slouken@3407
    98
/**
slouken@5389
    99
 *  This function returns true if the CPU has AltiVec features.
slouken@5389
   100
 */
slouken@5389
   101
extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
slouken@5389
   102
slouken@5389
   103
/**
slouken@3407
   104
 *  This function returns true if the CPU has MMX features.
slouken@739
   105
 */
slouken@1426
   106
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
slouken@739
   107
slouken@3407
   108
/**
slouken@5389
   109
 *  This function returns true if the CPU has 3DNow! features.
slouken@5389
   110
 */
slouken@5389
   111
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
slouken@5389
   112
slouken@5389
   113
/**
slouken@3407
   114
 *  This function returns true if the CPU has SSE features.
slouken@739
   115
 */
slouken@1426
   116
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
slouken@739
   117
slouken@3407
   118
/**
slouken@3407
   119
 *  This function returns true if the CPU has SSE2 features.
slouken@785
   120
 */
slouken@1426
   121
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
slouken@785
   122
slouken@3407
   123
/**
slouken@5259
   124
 *  This function returns true if the CPU has SSE3 features.
slouken@778
   125
 */
slouken@5259
   126
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
slouken@5259
   127
slouken@5259
   128
/**
slouken@5263
   129
 *  This function returns true if the CPU has SSE4.1 features.
slouken@5259
   130
 */
slouken@5263
   131
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
slouken@5263
   132
slouken@5263
   133
/**
slouken@5263
   134
 *  This function returns true if the CPU has SSE4.2 features.
slouken@5263
   135
 */
slouken@5263
   136
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
slouken@5259
   137
slouken@7821
   138
/**
slouken@8148
   139
 *  This function returns true if the CPU has AVX features.
slouken@8148
   140
 */
slouken@8148
   141
extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
slouken@8148
   142
slouken@8148
   143
/**
slouken@9003
   144
 *  This function returns true if the CPU has AVX2 features.
slouken@9003
   145
 */
slouken@9003
   146
extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
slouken@9003
   147
slouken@9003
   148
/**
icculus@10620
   149
 *  This function returns true if the CPU has NEON (ARM SIMD) features.
icculus@10620
   150
 */
icculus@10620
   151
extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
icculus@10620
   152
icculus@10620
   153
/**
slouken@7821
   154
 *  This function returns the amount of RAM configured in the system, in MB.
slouken@7821
   155
 */
slouken@7821
   156
extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
slouken@7821
   157
slouken@778
   158
slouken@739
   159
/* Ends C function definitions when using C++ */
slouken@739
   160
#ifdef __cplusplus
slouken@739
   161
}
slouken@739
   162
#endif
slouken@739
   163
#include "close_code.h"
slouken@739
   164
slouken@10638
   165
#endif /* SDL_cpuinfo_h_ */
slouken@1895
   166
slouken@1895
   167
/* vi: set ts=4 sw=4 expandtab: */