include/SDL_cpuinfo.h
author Sylvain Becker <sylvain.becker@gmail.com>
Tue, 04 Dec 2018 16:50:31 +0100
changeset 12450 1055156e99f3
parent 12449 17cb4ff70507
child 12452 983247abc7e5
permissions -rw-r--r--
Windows: NEON detection and intrinsic includes on Visual Studio

Visual Studio doesn't define __ARM_ARCH nor _ARM_NEON, but _M_ARM and _M_ARM64,
so SDL_HasNEON() was bypassed.

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