Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
513 lines (467 loc) · 15.2 KB

SDL_cpuinfo.c

File metadata and controls

513 lines (467 loc) · 15.2 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Feb 12, 2011
Feb 12, 2011
3
Copyright (C) 1997-2011 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
23
24
25
/* CPU feature detection for SDL */
Feb 16, 2006
Feb 16, 2006
26
27
#include "SDL_cpuinfo.h"
Dec 17, 2009
Dec 17, 2009
28
29
30
#ifdef HAVE_SYSCONF
#include <unistd.h>
#endif
Dec 16, 2009
Dec 16, 2009
31
32
33
34
#ifdef HAVE_SYSCTLBYNAME
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
Jan 24, 2011
Jan 24, 2011
35
#ifdef __WIN32__
Jan 25, 2011
Jan 25, 2011
36
#include "../core/windows/SDL_windows.h"
Dec 16, 2009
Dec 16, 2009
37
#endif
Jan 6, 2004
Jan 6, 2004
38
Dec 16, 2009
Dec 16, 2009
39
40
#define CPU_HAS_RDTSC 0x00000001
#define CPU_HAS_MMX 0x00000002
Feb 11, 2011
Feb 11, 2011
41
42
43
44
45
#define CPU_HAS_SSE 0x00000010
#define CPU_HAS_SSE2 0x00000020
#define CPU_HAS_SSE3 0x00000040
#define CPU_HAS_SSE4 0x00000080
Jan 29, 2004
Jan 29, 2004
46
Jul 10, 2006
Jul 10, 2006
47
48
static __inline__ int
CPU_haveCPUID(void)
Nov 24, 2003
Nov 24, 2003
49
{
Jul 10, 2006
Jul 10, 2006
50
51
int has_CPUID = 0;
/* *INDENT-OFF* */
Nov 24, 2003
Nov 24, 2003
52
#if defined(__GNUC__) && defined(i386)
Dec 16, 2009
Dec 16, 2009
53
__asm__ (
Nov 24, 2003
Nov 24, 2003
54
55
56
57
58
59
60
61
62
63
64
65
" pushfl # Get original EFLAGS \n"
" popl %%eax \n"
" movl %%eax,%%ecx \n"
" xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
" pushl %%eax # Save new EFLAGS value on stack \n"
" popfl # Replace current EFLAGS value \n"
" pushfl # Get new EFLAGS \n"
" popl %%eax # Store new EFLAGS in EAX \n"
" xorl %%ecx,%%eax # Can not toggle ID bit, \n"
" jz 1f # Processor=80486 \n"
" movl $1,%0 # We have CPUID support \n"
"1: \n"
Dec 16, 2009
Dec 16, 2009
66
67
68
69
: "=m" (has_CPUID)
:
: "%eax", "%ecx"
);
Apr 11, 2004
Apr 11, 2004
70
71
72
#elif defined(__GNUC__) && defined(__x86_64__)
/* Technically, if this is being compiled under __x86_64__ then it has
CPUid by definition. But it's nice to be able to prove it. :) */
Dec 16, 2009
Dec 16, 2009
73
__asm__ (
Apr 11, 2004
Apr 11, 2004
74
75
76
77
78
79
80
81
82
83
84
85
" pushfq # Get original EFLAGS \n"
" popq %%rax \n"
" movq %%rax,%%rcx \n"
" xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
" pushq %%rax # Save new EFLAGS value on stack \n"
" popfq # Replace current EFLAGS value \n"
" pushfq # Get new EFLAGS \n"
" popq %%rax # Store new EFLAGS in EAX \n"
" xorl %%ecx,%%eax # Can not toggle ID bit, \n"
" jz 1f # Processor=80486 \n"
" movl $1,%0 # We have CPUID support \n"
"1: \n"
Dec 16, 2009
Dec 16, 2009
86
87
88
89
: "=m" (has_CPUID)
:
: "%rax", "%rcx"
);
Feb 26, 2006
Feb 26, 2006
90
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
Dec 16, 2009
Dec 16, 2009
91
__asm {
Nov 24, 2003
Nov 24, 2003
92
93
94
95
96
97
98
99
100
101
102
103
pushfd ; Get original EFLAGS
pop eax
mov ecx, eax
xor eax, 200000h ; Flip ID bit in EFLAGS
push eax ; Save new EFLAGS value on stack
popfd ; Replace current EFLAGS value
pushfd ; Get new EFLAGS
pop eax ; Store new EFLAGS in EAX
xor eax, ecx ; Can not toggle ID bit,
jz done ; Processor=80486
mov has_CPUID,1 ; We have CPUID support
done:
Dec 16, 2009
Dec 16, 2009
104
}
Jun 20, 2006
Jun 20, 2006
105
#elif defined(__sun) && defined(__i386)
Dec 16, 2009
Dec 16, 2009
106
__asm (
Jan 5, 2006
Jan 5, 2006
107
" pushfl \n"
Dec 16, 2009
Dec 16, 2009
108
109
110
111
112
113
114
115
116
117
" popl %eax \n"
" movl %eax,%ecx \n"
" xorl $0x200000,%eax \n"
" pushl %eax \n"
" popfl \n"
" pushfl \n"
" popl %eax \n"
" xorl %ecx,%eax \n"
" jz 1f \n"
" movl $1,-8(%ebp) \n"
Jan 5, 2006
Jan 5, 2006
118
"1: \n"
Dec 16, 2009
Dec 16, 2009
119
);
Jan 5, 2006
Jan 5, 2006
120
#elif defined(__sun) && defined(__amd64)
Dec 16, 2009
Dec 16, 2009
121
__asm (
Jan 5, 2006
Jan 5, 2006
122
123
124
125
126
127
128
129
130
131
132
133
" pushfq \n"
" popq %rax \n"
" movq %rax,%rcx \n"
" xorl $0x200000,%eax \n"
" pushq %rax \n"
" popfq \n"
" pushfq \n"
" popq %rax \n"
" xorl %ecx,%eax \n"
" jz 1f \n"
" movl $1,-8(%rbp) \n"
"1: \n"
Dec 16, 2009
Dec 16, 2009
134
);
Nov 24, 2003
Nov 24, 2003
135
#endif
Jul 10, 2006
Jul 10, 2006
136
137
/* *INDENT-ON* */
return has_CPUID;
Nov 24, 2003
Nov 24, 2003
138
139
}
Dec 17, 2009
Dec 17, 2009
140
#if defined(__GNUC__) && defined(i386)
Dec 16, 2009
Dec 16, 2009
141
#define cpuid(func, a, b, c, d) \
Dec 16, 2009
Dec 16, 2009
142
143
144
145
146
147
__asm__ __volatile__ ( \
" pushl %%ebx \n" \
" cpuid \n" \
" movl %%ebx, %%esi \n" \
" popl %%ebx \n" : \
"=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
Dec 17, 2009
Dec 17, 2009
148
149
150
151
152
153
154
155
#elif defined(__GNUC__) && defined(__x86_64__)
#define cpuid(func, a, b, c, d) \
__asm__ __volatile__ ( \
" pushq %%rbx \n" \
" cpuid \n" \
" movq %%rbx, %%rsi \n" \
" popq %%rbx \n" : \
"=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
Dec 16, 2009
Dec 16, 2009
156
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
Dec 16, 2009
Dec 16, 2009
157
158
159
160
161
162
163
164
#define cpuid(func, a, b, c, d) \
__asm { \
__asm mov eax, func \
__asm cpuid \
__asm mov a, eax \
__asm mov b, ebx \
__asm mov c, ecx \
__asm mov d, edx \
Dec 16, 2009
Dec 16, 2009
165
166
}
#else
Dec 16, 2009
Dec 16, 2009
167
168
#define cpuid(func, a, b, c, d) \
a = b = c = d = 0
Dec 16, 2009
Dec 16, 2009
169
170
#endif
Jul 10, 2006
Jul 10, 2006
171
172
static __inline__ int
CPU_getCPUIDFeatures(void)
Nov 24, 2003
Nov 24, 2003
173
{
Jul 10, 2006
Jul 10, 2006
174
int features = 0;
Dec 16, 2009
Dec 16, 2009
175
int a, b, c, d;
Dec 16, 2009
Dec 16, 2009
176
Dec 16, 2009
Dec 16, 2009
177
178
179
180
cpuid(0, a, b, c, d);
if (a >= 1) {
cpuid(1, a, b, c, d);
features = d;
Dec 16, 2009
Dec 16, 2009
181
}
Jul 10, 2006
Jul 10, 2006
182
return features;
Nov 24, 2003
Nov 24, 2003
183
184
}
Jul 10, 2006
Jul 10, 2006
185
186
static __inline__ int
CPU_haveRDTSC(void)
Jan 24, 2004
Jan 24, 2004
187
{
Jul 10, 2006
Jul 10, 2006
188
189
190
191
if (CPU_haveCPUID()) {
return (CPU_getCPUIDFeatures() & 0x00000010);
}
return 0;
Jan 24, 2004
Jan 24, 2004
192
193
}
Jul 10, 2006
Jul 10, 2006
194
195
static __inline__ int
CPU_haveMMX(void)
Jan 24, 2004
Jan 24, 2004
196
{
Jul 10, 2006
Jul 10, 2006
197
198
199
200
if (CPU_haveCPUID()) {
return (CPU_getCPUIDFeatures() & 0x00800000);
}
return 0;
Jan 24, 2004
Jan 24, 2004
201
202
}
Jul 10, 2006
Jul 10, 2006
203
static __inline__ int
Feb 11, 2011
Feb 11, 2011
204
CPU_haveSSE(void)
Jan 24, 2004
Jan 24, 2004
205
{
Jul 10, 2006
Jul 10, 2006
206
if (CPU_haveCPUID()) {
Feb 11, 2011
Feb 11, 2011
207
return (CPU_getCPUIDFeatures() & 0x02000000);
Jul 10, 2006
Jul 10, 2006
208
209
}
return 0;
Jan 24, 2004
Jan 24, 2004
210
211
}
Jul 10, 2006
Jul 10, 2006
212
static __inline__ int
Feb 11, 2011
Feb 11, 2011
213
CPU_haveSSE2(void)
Jan 24, 2004
Jan 24, 2004
214
{
Jul 10, 2006
Jul 10, 2006
215
if (CPU_haveCPUID()) {
Feb 11, 2011
Feb 11, 2011
216
return (CPU_getCPUIDFeatures() & 0x04000000);
Jul 10, 2006
Jul 10, 2006
217
218
}
return 0;
Jan 24, 2004
Jan 24, 2004
219
220
}
Jul 10, 2006
Jul 10, 2006
221
static __inline__ int
Feb 11, 2011
Feb 11, 2011
222
CPU_haveSSE3(void)
Jan 24, 2004
Jan 24, 2004
223
{
Jul 10, 2006
Jul 10, 2006
224
if (CPU_haveCPUID()) {
Feb 11, 2011
Feb 11, 2011
225
int a, b, c, d;
Nov 24, 2003
Nov 24, 2003
226
Feb 11, 2011
Feb 11, 2011
227
228
229
230
231
cpuid(0, a, b, c, d);
if (a >= 1) {
cpuid(1, a, b, c, d);
return (c & 0x00000001);
}
Jul 10, 2006
Jul 10, 2006
232
233
}
return 0;
Nov 24, 2003
Nov 24, 2003
234
}
Jul 10, 2006
Jul 10, 2006
236
static __inline__ int
Feb 11, 2011
Feb 11, 2011
237
CPU_haveSSE4(void)
Jan 24, 2004
Jan 24, 2004
238
{
Jul 10, 2006
Jul 10, 2006
239
if (CPU_haveCPUID()) {
Feb 11, 2011
Feb 11, 2011
240
int a, b, c, d;
Jan 24, 2004
Jan 24, 2004
241
Feb 11, 2011
Feb 11, 2011
242
243
244
245
246
cpuid(0, a, b, c, d);
if (a >= 1) {
cpuid(1, a, b, c, d);
return (c & 0x00000100);
}
Jul 10, 2006
Jul 10, 2006
247
}
Feb 11, 2011
Feb 11, 2011
248
return 0;
Jan 6, 2004
Jan 6, 2004
249
250
}
Dec 16, 2009
Dec 16, 2009
251
252
253
static int SDL_CPUCount = 0;
int
Jan 28, 2011
Jan 28, 2011
254
SDL_GetCPUCount(void)
Dec 16, 2009
Dec 16, 2009
255
256
{
if (!SDL_CPUCount) {
Jan 6, 2010
Jan 6, 2010
257
#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
Dec 17, 2009
Dec 17, 2009
258
259
260
261
if (SDL_CPUCount <= 0) {
SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
}
#endif
Dec 16, 2009
Dec 16, 2009
262
#ifdef HAVE_SYSCTLBYNAME
Dec 17, 2009
Dec 17, 2009
263
if (SDL_CPUCount <= 0) {
Dec 16, 2009
Dec 16, 2009
264
265
266
267
size_t size = sizeof(SDL_CPUCount);
sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
}
#endif
Jan 24, 2011
Jan 24, 2011
268
#ifdef __WIN32__
Dec 17, 2009
Dec 17, 2009
269
if (SDL_CPUCount <= 0) {
Dec 16, 2009
Dec 16, 2009
270
271
272
273
SYSTEM_INFO info;
GetSystemInfo(&info);
SDL_CPUCount = info.dwNumberOfProcessors;
}
Dec 16, 2009
Dec 16, 2009
274
275
#endif
/* There has to be at least 1, right? :) */
Dec 17, 2009
Dec 17, 2009
276
if (SDL_CPUCount <= 0) {
Dec 16, 2009
Dec 16, 2009
277
278
279
280
281
282
283
SDL_CPUCount = 1;
}
}
return SDL_CPUCount;
}
/* Oh, such a sweet sweet trick, just not very useful. :) */
Jun 26, 2010
Jun 26, 2010
284
static const char *
Jan 28, 2011
Jan 28, 2011
285
SDL_GetCPUType(void)
Dec 16, 2009
Dec 16, 2009
286
{
Jan 28, 2011
Jan 28, 2011
287
static char SDL_CPUType[13];
Dec 16, 2009
Dec 16, 2009
288
289
290
if (!SDL_CPUType[0]) {
int i = 0;
Dec 16, 2009
Dec 16, 2009
291
int a, b, c, d;
Dec 16, 2009
Dec 16, 2009
292
Jan 28, 2011
Jan 28, 2011
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
if (CPU_haveCPUID()) {
cpuid(0x00000000, a, b, c, d);
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
}
if (!SDL_CPUType[0]) {
SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
}
}
return SDL_CPUType;
}
static const char *
Jan 28, 2011
Jan 28, 2011
316
SDL_GetCPUName(void)
Jan 28, 2011
Jan 28, 2011
317
318
319
320
321
322
323
{
static char SDL_CPUName[48];
if (!SDL_CPUName[0]) {
int i = 0;
int a, b, c, d;
Dec 16, 2009
Dec 16, 2009
324
if (CPU_haveCPUID()) {
Dec 16, 2009
Dec 16, 2009
325
326
327
cpuid(0x80000000, a, b, c, d);
if (a >= 0x80000004) {
cpuid(0x80000002, a, b, c, d);
Jan 28, 2011
Jan 28, 2011
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
Dec 16, 2009
Dec 16, 2009
344
cpuid(0x80000003, a, b, c, d);
Jan 28, 2011
Jan 28, 2011
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
Dec 16, 2009
Dec 16, 2009
361
cpuid(0x80000004, a, b, c, d);
Jan 28, 2011
Jan 28, 2011
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
Dec 16, 2009
Dec 16, 2009
378
379
}
}
Jan 28, 2011
Jan 28, 2011
380
381
if (!SDL_CPUName[0]) {
SDL_strlcpy(SDL_CPUName, "Unknown", sizeof(SDL_CPUName));
Dec 16, 2009
Dec 16, 2009
382
383
}
}
Jan 28, 2011
Jan 28, 2011
384
385
386
return SDL_CPUName;
}
Jan 28, 2011
Jan 28, 2011
387
388
int
SDL_GetCPUCacheLineSize(void)
Jan 28, 2011
Jan 28, 2011
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
{
const char *cpuType = SDL_GetCPUType();
if (SDL_strcmp(cpuType, "GenuineIntel") == 0) {
int a, b, c, d;
cpuid(0x00000001, a, b, c, d);
return (((b >> 8) & 0xff) * 8);
} else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) {
int a, b, c, d;
cpuid(0x80000005, a, b, c, d);
return (c & 0xff);
} else {
/* Just make a guess here... */
return SDL_CACHELINE_SIZE;
}
Dec 16, 2009
Dec 16, 2009
406
407
}
408
409
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
Jul 10, 2006
Jul 10, 2006
410
411
static Uint32
SDL_GetCPUFeatures(void)
Jul 10, 2006
Jul 10, 2006
413
414
415
416
417
418
419
420
421
422
423
424
425
426
if (SDL_CPUFeatures == 0xFFFFFFFF) {
SDL_CPUFeatures = 0;
if (CPU_haveRDTSC()) {
SDL_CPUFeatures |= CPU_HAS_RDTSC;
}
if (CPU_haveMMX()) {
SDL_CPUFeatures |= CPU_HAS_MMX;
}
if (CPU_haveSSE()) {
SDL_CPUFeatures |= CPU_HAS_SSE;
}
if (CPU_haveSSE2()) {
SDL_CPUFeatures |= CPU_HAS_SSE2;
}
Feb 11, 2011
Feb 11, 2011
427
428
429
430
431
if (CPU_haveSSE3()) {
SDL_CPUFeatures |= CPU_HAS_SSE3;
}
if (CPU_haveSSE4()) {
SDL_CPUFeatures |= CPU_HAS_SSE4;
Jul 10, 2006
Jul 10, 2006
432
433
434
}
}
return SDL_CPUFeatures;
Jul 10, 2006
Jul 10, 2006
437
438
SDL_bool
SDL_HasRDTSC(void)
Nov 24, 2003
Nov 24, 2003
439
{
Jul 10, 2006
Jul 10, 2006
440
441
442
443
if (SDL_GetCPUFeatures() & CPU_HAS_RDTSC) {
return SDL_TRUE;
}
return SDL_FALSE;
Nov 24, 2003
Nov 24, 2003
444
445
}
Jul 10, 2006
Jul 10, 2006
446
447
SDL_bool
SDL_HasMMX(void)
Jul 10, 2006
Jul 10, 2006
449
450
451
452
if (SDL_GetCPUFeatures() & CPU_HAS_MMX) {
return SDL_TRUE;
}
return SDL_FALSE;
Jul 10, 2006
Jul 10, 2006
455
SDL_bool
Feb 11, 2011
Feb 11, 2011
456
SDL_HasSSE(void)
Jan 6, 2004
Jan 6, 2004
457
{
Feb 11, 2011
Feb 11, 2011
458
if (SDL_GetCPUFeatures() & CPU_HAS_SSE) {
Jul 10, 2006
Jul 10, 2006
459
460
461
return SDL_TRUE;
}
return SDL_FALSE;
Jan 6, 2004
Jan 6, 2004
462
463
}
Jul 10, 2006
Jul 10, 2006
464
SDL_bool
Feb 11, 2011
Feb 11, 2011
465
SDL_HasSSE2(void)
Jan 24, 2004
Jan 24, 2004
466
{
Feb 11, 2011
Feb 11, 2011
467
if (SDL_GetCPUFeatures() & CPU_HAS_SSE2) {
Jul 10, 2006
Jul 10, 2006
468
469
470
return SDL_TRUE;
}
return SDL_FALSE;
Jan 24, 2004
Jan 24, 2004
471
472
}
Jul 10, 2006
Jul 10, 2006
473
SDL_bool
Feb 11, 2011
Feb 11, 2011
474
SDL_HasSSE3(void)
Jan 24, 2004
Jan 24, 2004
475
{
Feb 11, 2011
Feb 11, 2011
476
if (SDL_GetCPUFeatures() & CPU_HAS_SSE3) {
Jul 10, 2006
Jul 10, 2006
477
478
479
return SDL_TRUE;
}
return SDL_FALSE;
Jan 24, 2004
Jan 24, 2004
480
481
}
Jul 10, 2006
Jul 10, 2006
482
SDL_bool
Feb 11, 2011
Feb 11, 2011
483
SDL_HasSSE4(void)
Jan 24, 2004
Jan 24, 2004
484
{
Feb 11, 2011
Feb 11, 2011
485
if (SDL_GetCPUFeatures() & CPU_HAS_SSE4) {
Jul 10, 2006
Jul 10, 2006
486
487
488
return SDL_TRUE;
}
return SDL_FALSE;
Jan 24, 2004
Jan 24, 2004
489
490
}
491
492
493
494
#ifdef TEST_MAIN
#include <stdio.h>
Jul 10, 2006
Jul 10, 2006
495
496
int
main()
Dec 16, 2009
Dec 16, 2009
498
printf("CPU count: %d\n", SDL_GetCPUCount());
Jan 28, 2011
Jan 28, 2011
499
500
501
printf("CPU type: %s\n", SDL_GetCPUType());
printf("CPU name: %s\n", SDL_GetCPUName());
printf("CacheLine size: %d\n", SDL_GetCPUCacheLineSize());
Jul 10, 2006
Jul 10, 2006
502
503
504
505
printf("RDTSC: %d\n", SDL_HasRDTSC());
printf("MMX: %d\n", SDL_HasMMX());
printf("SSE: %d\n", SDL_HasSSE());
printf("SSE2: %d\n", SDL_HasSSE2());
Feb 11, 2011
Feb 11, 2011
506
507
printf("SSE3: %d\n", SDL_HasSSE3());
printf("SSE4: %d\n", SDL_HasSSE4());
Jul 10, 2006
Jul 10, 2006
508
return 0;
509
510
511
}
#endif /* TEST_MAIN */
Jul 10, 2006
Jul 10, 2006
512
513
/* vi: set ts=4 sw=4 expandtab: */