My Project
Loading...
Searching...
No Matches
SDL_cpuinfo.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
28#ifndef SDL_cpuinfo_h_
29#define SDL_cpuinfo_h_
30
31#include "SDL_stdinc.h"
32
33/* Need to do this here because intrin.h has C++ code in it */
34/* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
35#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_IX86) || defined(_M_X64))
36#ifdef __clang__
37/* As of Clang 11, '_m_prefetchw' is conflicting with the winnt.h's version,
38 so we define the needed '_m_prefetch' here as a pseudo-header, until the issue is fixed. */
39
40#ifndef __PRFCHWINTRIN_H
41#define __PRFCHWINTRIN_H
42
43static __inline__ void __attribute__((__always_inline__, __nodebug__))
44_m_prefetch(void *__P)
45{
46 __builtin_prefetch (__P, 0, 3 /* _MM_HINT_T0 */);
47}
48
49#endif /* __PRFCHWINTRIN_H */
50#endif /* __clang__ */
51#include <intrin.h>
52#ifndef _WIN64
53#ifndef __MMX__
54#define __MMX__
55#endif
56#ifndef __3dNOW__
57#define __3dNOW__
58#endif
59#endif
60#ifndef __SSE__
61#define __SSE__
62#endif
63#ifndef __SSE2__
64#define __SSE2__
65#endif
66#ifndef __SSE3__
67#define __SSE3__
68#endif
69#elif defined(__MINGW64_VERSION_MAJOR)
70#include <intrin.h>
71#if !defined(SDL_DISABLE_ARM_NEON_H) && defined(__ARM_NEON)
72# include <arm_neon.h>
73#endif
74#else
75/* 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. */
76#if defined(HAVE_ALTIVEC_H) && defined(__ALTIVEC__) && !defined(__APPLE_ALTIVEC__) && defined(SDL_ENABLE_ALTIVEC_H)
77#include <altivec.h>
78#endif
79#if !defined(SDL_DISABLE_ARM_NEON_H)
80# if defined(__ARM_NEON)
81# include <arm_neon.h>
82# elif defined(__WINDOWS__) || defined(__WINRT__) || defined(__GDK__)
83/* Visual Studio doesn't define __ARM_ARCH, but _M_ARM (if set, always 7), and _M_ARM64 (if set, always 1). */
84# if defined(_M_ARM)
85# include <armintr.h>
86# include <arm_neon.h>
87# define __ARM_NEON 1 /* Set __ARM_NEON so that it can be used elsewhere, at compile time */
88# endif
89# if defined (_M_ARM64)
90# include <arm64intr.h>
91# include <arm64_neon.h>
92# define __ARM_NEON 1 /* Set __ARM_NEON so that it can be used elsewhere, at compile time */
93# define __ARM_ARCH 8
94# endif
95# endif
96#endif
97#endif /* compiler version */
98
99#if defined(__3dNOW__) && !defined(SDL_DISABLE_MM3DNOW_H)
100#include <mm3dnow.h>
101#endif
102#if defined(__loongarch_sx) && !defined(SDL_DISABLE_LSX_H)
103#include <lsxintrin.h>
104#define __LSX__
105#endif
106#if defined(__loongarch_asx) && !defined(SDL_DISABLE_LASX_H)
107#include <lasxintrin.h>
108#define __LASX__
109#endif
110#if defined(HAVE_IMMINTRIN_H) && !defined(SDL_DISABLE_IMMINTRIN_H)
111#include <immintrin.h>
112#else
113#if defined(__MMX__) && !defined(SDL_DISABLE_MMINTRIN_H)
114#include <mmintrin.h>
115#endif
116#if defined(__SSE__) && !defined(SDL_DISABLE_XMMINTRIN_H)
117#include <xmmintrin.h>
118#endif
119#if defined(__SSE2__) && !defined(SDL_DISABLE_EMMINTRIN_H)
120#include <emmintrin.h>
121#endif
122#if defined(__SSE3__) && !defined(SDL_DISABLE_PMMINTRIN_H)
123#include <pmmintrin.h>
124#endif
125#endif /* HAVE_IMMINTRIN_H */
126
127#include "begin_code.h"
128/* Set up for C function definitions, even when using C++ */
129#ifdef __cplusplus
130extern "C" {
131#endif
132
133/* This is a guess for the cacheline size used for padding.
134 * Most x86 processors have a 64 byte cache line.
135 * The 64-bit PowerPC processors have a 128 byte cache line.
136 * We'll use the larger value to be generally safe.
137 */
138#define SDL_CACHELINE_SIZE 128
139
149extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
150
161extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
162
183extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
184
206extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
207
228extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
229
250extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
251
272extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
273
294extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
295
316extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
317
338extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
339
360extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
361
382extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
383
404extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
405
417extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void);
418
432extern DECLSPEC SDL_bool SDLCALL SDL_HasARMSIMD(void);
433
443extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
444
456extern DECLSPEC SDL_bool SDLCALL SDL_HasLSX(void);
457
469extern DECLSPEC SDL_bool SDLCALL SDL_HasLASX(void);
470
478extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
479
497extern DECLSPEC size_t SDLCALL SDL_SIMDGetAlignment(void);
498
536extern DECLSPEC void * SDLCALL SDL_SIMDAlloc(const size_t len);
537
560extern DECLSPEC void * SDLCALL SDL_SIMDRealloc(void *mem, const size_t len);
561
584extern DECLSPEC void SDLCALL SDL_SIMDFree(void *ptr);
585
586/* Ends C function definitions when using C++ */
587#ifdef __cplusplus
588}
589#endif
590#include "close_code.h"
591
592#endif /* SDL_cpuinfo_h_ */
593
594/* vi: set ts=4 sw=4 expandtab: */
DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void)
DECLSPEC SDL_bool SDLCALL SDL_HasLASX(void)
DECLSPEC SDL_bool SDLCALL SDL_HasAVX512F(void)
DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void)
DECLSPEC void SDLCALL SDL_SIMDFree(void *ptr)
DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void)
DECLSPEC void *SDLCALL SDL_SIMDRealloc(void *mem, const size_t len)
DECLSPEC int SDLCALL SDL_GetCPUCount(void)
DECLSPEC size_t SDLCALL SDL_SIMDGetAlignment(void)
DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void)
DECLSPEC SDL_bool SDLCALL SDL_HasLSX(void)
DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void)
DECLSPEC SDL_bool SDLCALL SDL_HasARMSIMD(void)
DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void)
DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void)
DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void)
DECLSPEC void *SDLCALL SDL_SIMDAlloc(const size_t len)
DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void)
DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void)
DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void)
DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void)
DECLSPEC int SDLCALL SDL_GetSystemRAM(void)
DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void)