include/SDL_cpuinfo.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 19 Nov 2018 21:28:52 -0800
changeset 12423 6da95eef84a2
parent 11992 08c415f14810
child 12449 17cb4ff70507
permissions -rw-r--r--
Fixed bug 4392 - SDL_cpuinfo.h breaks compilation with C bool type

Luke Dashjr

Bug 3993 was "fixed" by #undef'ing bool. But this breaks C99's stdbool.h bool too.

For example, mpv's build fails with:

../audio/out/ao_sdl.c:35:5: error: unknown type name ‘bool’

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