include/SDL_cpuinfo.h
author Ryan C. Gordon <icculus@icculus.org>
Wed, 16 May 2018 02:03:06 -0400
changeset 11992 08c415f14810
parent 11986 e307b74aa643
child 12423 6da95eef84a2
permissions -rw-r--r--
audio: Added ARM NEON versions of audio converters.

These are _much_ faster than the scalar equivalents on the Raspberry Pi that
I tested on. Often 3x to 4x as fast!
slouken@739
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 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@11928
    54
#if defined(HAVE_ALTIVEC_H) && !defined(__APPLE_ALTIVEC__) && !defined(SDL_DISABLE_ALTIVEC_H)
slouken@5390
    55
#include <altivec.h>
slouken@5390
    56
#undef pixel
slouken@11770
    57
#undef bool
slouken@5390
    58
#endif
slouken@5390
    59
#endif
icculus@11992
    60
#if defined(__ARM_NEON__) && !defined(SDL_DISABLE_ARM_NEON_H)
icculus@11992
    61
#include <arm_neon.h>
icculus@11992
    62
#endif
slouken@11770
    63
#if defined(__3dNOW__) && !defined(SDL_DISABLE_MM3DNOW_H)
slouken@5389
    64
#include <mm3dnow.h>
slouken@5389
    65
#endif
slouken@11928
    66
#if defined(HAVE_IMMINTRIN_H) && !defined(SDL_DISABLE_IMMINTRIN_H)
slouken@11698
    67
#include <immintrin.h>
slouken@11762
    68
#else
slouken@11770
    69
#if defined(__MMX__) && !defined(SDL_DISABLE_MMINTRIN_H)
slouken@11762
    70
#include <mmintrin.h>
slouken@5389
    71
#endif
slouken@11770
    72
#if defined(__SSE__) && !defined(SDL_DISABLE_XMMINTRIN_H)
slouken@11762
    73
#include <xmmintrin.h>
slouken@11762
    74
#endif
slouken@11770
    75
#if defined(__SSE2__) && !defined(SDL_DISABLE_EMMINTRIN_H)
slouken@11762
    76
#include <emmintrin.h>
slouken@11762
    77
#endif
slouken@11770
    78
#if defined(__SSE3__) && !defined(SDL_DISABLE_PMMINTRIN_H)
slouken@11762
    79
#include <pmmintrin.h>
slouken@11762
    80
#endif
slouken@11762
    81
#endif /* HAVE_IMMINTRIN_H */
slouken@11762
    82
#endif /* compiler version */
slouken@5389
    83
slouken@739
    84
#include "begin_code.h"
slouken@739
    85
/* Set up for C function definitions, even when using C++ */
slouken@739
    86
#ifdef __cplusplus
slouken@739
    87
extern "C" {
slouken@739
    88
#endif
slouken@739
    89
slouken@5116
    90
/* This is a guess for the cacheline size used for padding.
slouken@5116
    91
 * Most x86 processors have a 64 byte cache line.
slouken@5116
    92
 * The 64-bit PowerPC processors have a 128 byte cache line.
slouken@5116
    93
 * We'll use the larger value to be generally safe.
slouken@5115
    94
 */
slouken@5116
    95
#define SDL_CACHELINE_SIZE  128
slouken@5115
    96
slouken@3407
    97
/**
slouken@3579
    98
 *  This function returns the number of CPU cores available.
slouken@3579
    99
 */
slouken@3579
   100
extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
slouken@3579
   101
slouken@3579
   102
/**
slouken@5120
   103
 *  This function returns the L1 cache line size of the CPU
slouken@5120
   104
 *
slouken@5120
   105
 *  This is useful for determining multi-threaded structure padding
slouken@5120
   106
 *  or SIMD prefetch sizes.
slouken@5120
   107
 */
slouken@5120
   108
extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
slouken@5120
   109
slouken@5120
   110
/**
slouken@3407
   111
 *  This function returns true if the CPU has the RDTSC instruction.
slouken@745
   112
 */
slouken@1426
   113
extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
slouken@745
   114
slouken@3407
   115
/**
slouken@5389
   116
 *  This function returns true if the CPU has AltiVec features.
slouken@5389
   117
 */
slouken@5389
   118
extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
slouken@5389
   119
slouken@5389
   120
/**
slouken@3407
   121
 *  This function returns true if the CPU has MMX features.
slouken@739
   122
 */
slouken@1426
   123
extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
slouken@739
   124
slouken@3407
   125
/**
slouken@5389
   126
 *  This function returns true if the CPU has 3DNow! features.
slouken@5389
   127
 */
slouken@5389
   128
extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
slouken@5389
   129
slouken@5389
   130
/**
slouken@3407
   131
 *  This function returns true if the CPU has SSE features.
slouken@739
   132
 */
slouken@1426
   133
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
slouken@739
   134
slouken@3407
   135
/**
slouken@3407
   136
 *  This function returns true if the CPU has SSE2 features.
slouken@785
   137
 */
slouken@1426
   138
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
slouken@785
   139
slouken@3407
   140
/**
slouken@5259
   141
 *  This function returns true if the CPU has SSE3 features.
slouken@778
   142
 */
slouken@5259
   143
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
slouken@5259
   144
slouken@5259
   145
/**
slouken@5263
   146
 *  This function returns true if the CPU has SSE4.1 features.
slouken@5259
   147
 */
slouken@5263
   148
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
slouken@5263
   149
slouken@5263
   150
/**
slouken@5263
   151
 *  This function returns true if the CPU has SSE4.2 features.
slouken@5263
   152
 */
slouken@5263
   153
extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
slouken@5259
   154
slouken@7821
   155
/**
slouken@8148
   156
 *  This function returns true if the CPU has AVX features.
slouken@8148
   157
 */
slouken@8148
   158
extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
slouken@8148
   159
slouken@8148
   160
/**
slouken@9003
   161
 *  This function returns true if the CPU has AVX2 features.
slouken@9003
   162
 */
slouken@9003
   163
extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
slouken@9003
   164
slouken@9003
   165
/**
icculus@11986
   166
 *  This function returns true if the CPU has AVX-512F (foundation) features.
icculus@11986
   167
 */
icculus@11986
   168
extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void);
icculus@11986
   169
icculus@11986
   170
/**
icculus@10620
   171
 *  This function returns true if the CPU has NEON (ARM SIMD) features.
icculus@10620
   172
 */
icculus@10620
   173
extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
icculus@10620
   174
icculus@10620
   175
/**
slouken@7821
   176
 *  This function returns the amount of RAM configured in the system, in MB.
slouken@7821
   177
 */
slouken@7821
   178
extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
slouken@7821
   179
slouken@739
   180
/* Ends C function definitions when using C++ */
slouken@739
   181
#ifdef __cplusplus
slouken@739
   182
}
slouken@739
   183
#endif
slouken@739
   184
#include "close_code.h"
slouken@739
   185
slouken@10638
   186
#endif /* SDL_cpuinfo_h_ */
slouken@1895
   187
slouken@1895
   188
/* vi: set ts=4 sw=4 expandtab: */