SDL
3.0
SDL_cpuinfo.h
Go to the documentation of this file.
1
/*
2
Simple DirectMedia Layer
3
Copyright (C) 1997-2024 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
22
/* WIKI CATEGORY: CPUInfo */
23
24
/**
25
* # CategoryCPUInfo
26
*
27
* CPU feature detection for SDL.
28
*
29
* These functions are largely concerned with reporting if the system has
30
* access to various SIMD instruction sets, but also has other important info
31
* to share, such as system RAM size and number of logical CPU cores.
32
*/
33
34
#ifndef SDL_cpuinfo_h_
35
#define SDL_cpuinfo_h_
36
37
#include <
SDL3/SDL_stdinc.h
>
38
39
#include <
SDL3/SDL_begin_code.h
>
40
/* Set up for C function definitions, even when using C++ */
41
#ifdef __cplusplus
42
extern
"C"
{
43
#endif
44
45
/**
46
* A guess for the cacheline size used for padding.
47
*
48
* Most x86 processors have a 64 byte cache line. The 64-bit PowerPC
49
* processors have a 128 byte cache line. We use the larger value to be
50
* generally safe.
51
*
52
* \since This macro is available since SDL 3.0.0.
53
*/
54
#define SDL_CACHELINE_SIZE 128
55
56
/**
57
* Get the number of logical CPU cores available.
58
*
59
* \returns the total number of logical CPU cores. On CPUs that include
60
* technologies such as hyperthreading, the number of logical cores
61
* may be more than the number of physical cores.
62
*
63
* \since This function is available since SDL 3.0.0.
64
*/
65
extern
SDL_DECLSPEC
int
SDLCALL
SDL_GetNumLogicalCPUCores
(
void
);
66
67
/**
68
* Determine the L1 cache line size of the CPU.
69
*
70
* This is useful for determining multi-threaded structure padding or SIMD
71
* prefetch sizes.
72
*
73
* \returns the L1 cache line size of the CPU, in bytes.
74
*
75
* \since This function is available since SDL 3.0.0.
76
*/
77
extern
SDL_DECLSPEC
int
SDLCALL
SDL_GetCPUCacheLineSize
(
void
);
78
79
/**
80
* Determine whether the CPU has AltiVec features.
81
*
82
* This always returns false on CPUs that aren't using PowerPC instruction
83
* sets.
84
*
85
* \returns true if the CPU has AltiVec features or false if not.
86
*
87
* \since This function is available since SDL 3.0.0.
88
*/
89
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasAltiVec
(
void
);
90
91
/**
92
* Determine whether the CPU has MMX features.
93
*
94
* This always returns false on CPUs that aren't using Intel instruction sets.
95
*
96
* \returns true if the CPU has MMX features or false if not.
97
*
98
* \since This function is available since SDL 3.0.0.
99
*/
100
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasMMX
(
void
);
101
102
/**
103
* Determine whether the CPU has SSE features.
104
*
105
* This always returns false on CPUs that aren't using Intel instruction sets.
106
*
107
* \returns true if the CPU has SSE features or false if not.
108
*
109
* \since This function is available since SDL 3.0.0.
110
*
111
* \sa SDL_HasSSE2
112
* \sa SDL_HasSSE3
113
* \sa SDL_HasSSE41
114
* \sa SDL_HasSSE42
115
*/
116
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasSSE
(
void
);
117
118
/**
119
* Determine whether the CPU has SSE2 features.
120
*
121
* This always returns false on CPUs that aren't using Intel instruction sets.
122
*
123
* \returns true if the CPU has SSE2 features or false if not.
124
*
125
* \since This function is available since SDL 3.0.0.
126
*
127
* \sa SDL_HasSSE
128
* \sa SDL_HasSSE3
129
* \sa SDL_HasSSE41
130
* \sa SDL_HasSSE42
131
*/
132
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasSSE2
(
void
);
133
134
/**
135
* Determine whether the CPU has SSE3 features.
136
*
137
* This always returns false on CPUs that aren't using Intel instruction sets.
138
*
139
* \returns true if the CPU has SSE3 features or false if not.
140
*
141
* \since This function is available since SDL 3.0.0.
142
*
143
* \sa SDL_HasSSE
144
* \sa SDL_HasSSE2
145
* \sa SDL_HasSSE41
146
* \sa SDL_HasSSE42
147
*/
148
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasSSE3
(
void
);
149
150
/**
151
* Determine whether the CPU has SSE4.1 features.
152
*
153
* This always returns false on CPUs that aren't using Intel instruction sets.
154
*
155
* \returns true if the CPU has SSE4.1 features or false if not.
156
*
157
* \since This function is available since SDL 3.0.0.
158
*
159
* \sa SDL_HasSSE
160
* \sa SDL_HasSSE2
161
* \sa SDL_HasSSE3
162
* \sa SDL_HasSSE42
163
*/
164
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasSSE41
(
void
);
165
166
/**
167
* Determine whether the CPU has SSE4.2 features.
168
*
169
* This always returns false on CPUs that aren't using Intel instruction sets.
170
*
171
* \returns true if the CPU has SSE4.2 features or false if not.
172
*
173
* \since This function is available since SDL 3.0.0.
174
*
175
* \sa SDL_HasSSE
176
* \sa SDL_HasSSE2
177
* \sa SDL_HasSSE3
178
* \sa SDL_HasSSE41
179
*/
180
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasSSE42
(
void
);
181
182
/**
183
* Determine whether the CPU has AVX features.
184
*
185
* This always returns false on CPUs that aren't using Intel instruction sets.
186
*
187
* \returns true if the CPU has AVX features or false if not.
188
*
189
* \since This function is available since SDL 3.0.0.
190
*
191
* \sa SDL_HasAVX2
192
* \sa SDL_HasAVX512F
193
*/
194
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasAVX
(
void
);
195
196
/**
197
* Determine whether the CPU has AVX2 features.
198
*
199
* This always returns false on CPUs that aren't using Intel instruction sets.
200
*
201
* \returns true if the CPU has AVX2 features or false if not.
202
*
203
* \since This function is available since SDL 3.0.0.
204
*
205
* \sa SDL_HasAVX
206
* \sa SDL_HasAVX512F
207
*/
208
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasAVX2
(
void
);
209
210
/**
211
* Determine whether the CPU has AVX-512F (foundation) features.
212
*
213
* This always returns false on CPUs that aren't using Intel instruction sets.
214
*
215
* \returns true if the CPU has AVX-512F features or false if not.
216
*
217
* \since This function is available since SDL 3.0.0.
218
*
219
* \sa SDL_HasAVX
220
* \sa SDL_HasAVX2
221
*/
222
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasAVX512F
(
void
);
223
224
/**
225
* Determine whether the CPU has ARM SIMD (ARMv6) features.
226
*
227
* This is different from ARM NEON, which is a different instruction set.
228
*
229
* This always returns false on CPUs that aren't using ARM instruction sets.
230
*
231
* \returns true if the CPU has ARM SIMD features or false if not.
232
*
233
* \since This function is available since SDL 3.0.0.
234
*
235
* \sa SDL_HasNEON
236
*/
237
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasARMSIMD
(
void
);
238
239
/**
240
* Determine whether the CPU has NEON (ARM SIMD) features.
241
*
242
* This always returns false on CPUs that aren't using ARM instruction sets.
243
*
244
* \returns true if the CPU has ARM NEON features or false if not.
245
*
246
* \since This function is available since SDL 3.0.0.
247
*/
248
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasNEON
(
void
);
249
250
/**
251
* Determine whether the CPU has LSX (LOONGARCH SIMD) features.
252
*
253
* This always returns false on CPUs that aren't using LOONGARCH instruction
254
* sets.
255
*
256
* \returns true if the CPU has LOONGARCH LSX features or false if not.
257
*
258
* \since This function is available since SDL 3.0.0.
259
*/
260
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasLSX
(
void
);
261
262
/**
263
* Determine whether the CPU has LASX (LOONGARCH SIMD) features.
264
*
265
* This always returns false on CPUs that aren't using LOONGARCH instruction
266
* sets.
267
*
268
* \returns true if the CPU has LOONGARCH LASX features or false if not.
269
*
270
* \since This function is available since SDL 3.0.0.
271
*/
272
extern
SDL_DECLSPEC
bool
SDLCALL
SDL_HasLASX
(
void
);
273
274
/**
275
* Get the amount of RAM configured in the system.
276
*
277
* \returns the amount of RAM configured in the system in MiB.
278
*
279
* \since This function is available since SDL 3.0.0.
280
*/
281
extern
SDL_DECLSPEC
int
SDLCALL
SDL_GetSystemRAM
(
void
);
282
283
/**
284
* Report the alignment this system needs for SIMD allocations.
285
*
286
* This will return the minimum number of bytes to which a pointer must be
287
* aligned to be compatible with SIMD instructions on the current machine. For
288
* example, if the machine supports SSE only, it will return 16, but if it
289
* supports AVX-512F, it'll return 64 (etc). This only reports values for
290
* instruction sets SDL knows about, so if your SDL build doesn't have
291
* SDL_HasAVX512F(), then it might return 16 for the SSE support it sees and
292
* not 64 for the AVX-512 instructions that exist but SDL doesn't know about.
293
* Plan accordingly.
294
*
295
* \returns the alignment in bytes needed for available, known SIMD
296
* instructions.
297
*
298
* \since This function is available since SDL 3.0.0.
299
*
300
* \sa SDL_aligned_alloc
301
* \sa SDL_aligned_free
302
*/
303
extern
SDL_DECLSPEC
size_t
SDLCALL
SDL_GetSIMDAlignment
(
void
);
304
305
/* Ends C function definitions when using C++ */
306
#ifdef __cplusplus
307
}
308
#endif
309
#include <
SDL3/SDL_close_code.h
>
310
311
#endif
/* SDL_cpuinfo_h_ */
SDL_begin_code.h
SDL_close_code.h
SDL_HasSSE2
bool SDL_HasSSE2(void)
SDL_HasSSE42
bool SDL_HasSSE42(void)
SDL_HasAltiVec
bool SDL_HasAltiVec(void)
SDL_HasAVX512F
bool SDL_HasAVX512F(void)
SDL_GetSystemRAM
int SDL_GetSystemRAM(void)
SDL_HasSSE
bool SDL_HasSSE(void)
SDL_HasARMSIMD
bool SDL_HasARMSIMD(void)
SDL_HasLSX
bool SDL_HasLSX(void)
SDL_HasNEON
bool SDL_HasNEON(void)
SDL_GetCPUCacheLineSize
int SDL_GetCPUCacheLineSize(void)
SDL_HasLASX
bool SDL_HasLASX(void)
SDL_HasSSE3
bool SDL_HasSSE3(void)
SDL_HasAVX
bool SDL_HasAVX(void)
SDL_HasAVX2
bool SDL_HasAVX2(void)
SDL_HasSSE41
bool SDL_HasSSE41(void)
SDL_GetSIMDAlignment
size_t SDL_GetSIMDAlignment(void)
SDL_HasMMX
bool SDL_HasMMX(void)
SDL_GetNumLogicalCPUCores
int SDL_GetNumLogicalCPUCores(void)
SDL_stdinc.h
include
SDL3
SDL_cpuinfo.h
Generated by
1.9.8