30 #ifdef HAVE_SYSCTLBYNAME
32 #include <sys/sysctl.h>
34 #if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
35 #include <sys/sysctl.h>
36 #elif defined(__OpenBSD__) && defined(__powerpc__)
37 #include <sys/param.h>
38 #include <sys/sysctl.h>
39 #include <machine/cpu.h>
40 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
45 #include "../core/windows/SDL_windows.h"
48 #define CPU_HAS_RDTSC 0x00000001
49 #define CPU_HAS_ALTIVEC 0x00000002
50 #define CPU_HAS_MMX 0x00000004
51 #define CPU_HAS_3DNOW 0x00000008
52 #define CPU_HAS_SSE 0x00000010
53 #define CPU_HAS_SSE2 0x00000020
54 #define CPU_HAS_SSE3 0x00000040
55 #define CPU_HAS_SSE41 0x00000100
56 #define CPU_HAS_SSE42 0x00000200
58 #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
62 static jmp_buf jmpbuf;
64 illegal_instruction(
int sig)
75 #if defined(__GNUC__) && defined(i386)
77 " pushfl # Get original EFLAGS \n"
79 " movl %%eax,%%ecx \n"
80 " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
81 " pushl %%eax # Save new EFLAGS value on stack \n"
82 " popfl # Replace current EFLAGS value \n"
83 " pushfl # Get new EFLAGS \n"
84 " popl %%eax # Store new EFLAGS in EAX \n"
85 " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
86 " jz 1f # Processor=80486 \n"
87 " movl $1,%0 # We have CPUID support \n"
93 #elif defined(__GNUC__) && defined(__x86_64__)
97 " pushfq # Get original EFLAGS \n"
99 " movq %%rax,%%rcx \n"
100 " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
101 " pushq %%rax # Save new EFLAGS value on stack \n"
102 " popfq # Replace current EFLAGS value \n"
103 " pushfq # Get new EFLAGS \n"
104 " popq %%rax # Store new EFLAGS in EAX \n"
105 " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
106 " jz 1f # Processor=80486 \n"
107 " movl $1,%0 # We have CPUID support \n"
113 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
115 pushfd ; Get original EFLAGS
118 xor eax, 200000
h ; Flip ID bit
in EFLAGS
119 push eax ; Save
new EFLAGS
value on stack
120 popfd ; Replace current EFLAGS
value
121 pushfd ; Get
new EFLAGS
122 pop eax ; Store
new EFLAGS
in EAX
123 xor eax, ecx ; Can not toggle ID bit,
124 jz done ; Processor=80486
125 mov has_CPUID,1 ; We have CPUID support
128 #elif defined(__sun) && defined(__i386)
133 " xorl $0x200000,%eax \n"
140 " movl $1,-8(%ebp) \n"
143 #elif defined(__sun) && defined(__amd64)
148 " xorl $0x200000,%eax \n"
155 " movl $1,-8(%rbp) \n"
163 #if defined(__GNUC__) && defined(i386)
164 #define cpuid(func, a, b, c, d) \
165 __asm__ __volatile__ ( \
168 " movl %%ebx, %%esi \n" \
170 "=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
171 #elif defined(__GNUC__) && defined(__x86_64__)
172 #define cpuid(func, a, b, c, d) \
173 __asm__ __volatile__ ( \
176 " movq %%rbx, %%rsi \n" \
178 "=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
179 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
180 #define cpuid(func, a, b, c, d) \
182 __asm mov eax, func \
190 #define cpuid(func, a, b, c, d) \
200 cpuid(0, a, b, c, d);
202 cpuid(1, a, b, c, d);
220 volatile int altivec = 0;
221 #if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
223 int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
225 int selectors[2] = { CTL_HW, HW_VECTORUNIT };
227 int hasVectorUnit = 0;
228 size_t length =
sizeof(hasVectorUnit);
229 int error = sysctl(selectors, 2, &hasVectorUnit, &length,
NULL, 0);
231 altivec = (hasVectorUnit != 0);
232 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
233 void (*handler) (
int sig);
234 handler = signal(SIGILL, illegal_instruction);
235 if (setjmp(jmpbuf) == 0) {
236 asm volatile (
"mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::
"r" (-1));
239 signal(SIGILL, handler);
259 cpuid(0x80000000, a, b, c, d);
260 if (a >= 0x80000001) {
261 cpuid(0x80000001, a, b, c, d);
262 return (d & 0x80000000);
292 cpuid(0, a, b, c, d);
294 cpuid(1, a, b, c, d);
295 return (c & 0x00000001);
307 cpuid(1, a, b, c, d);
309 cpuid(1, a, b, c, d);
310 return (c & 0x00080000);
322 cpuid(1, a, b, c, d);
324 cpuid(1, a, b, c, d);
325 return (c & 0x00100000);
337 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
342 #ifdef HAVE_SYSCTLBYNAME
351 GetSystemInfo(&info);
367 static char SDL_CPUType[13];
369 if (!SDL_CPUType[0]) {
374 cpuid(0x00000000, a, b, c, d);
375 SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
376 SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
377 SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
378 SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
379 SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
380 SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
381 SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
382 SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
383 SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
384 SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
385 SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
386 SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
388 if (!SDL_CPUType[0]) {
389 SDL_strlcpy(SDL_CPUType,
"Unknown",
sizeof(SDL_CPUType));
400 static char SDL_CPUName[48];
402 if (!SDL_CPUName[0]) {
407 cpuid(0x80000000, a, b, c, d);
408 if (a >= 0x80000004) {
409 cpuid(0x80000002, a, b, c, d);
410 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
411 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
412 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
413 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
414 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
415 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
416 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
417 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
418 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
419 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
420 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
421 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
422 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
423 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
424 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
425 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
426 cpuid(0x80000003, a, b, c, d);
427 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
428 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
429 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
430 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
431 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
432 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
433 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
434 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
435 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
436 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
437 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
438 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
439 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
440 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
441 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
442 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
443 cpuid(0x80000004, a, b, c, d);
444 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
445 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
446 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
447 SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
448 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
449 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
450 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
451 SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
452 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
453 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
454 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
455 SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
456 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
457 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
458 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
459 SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
462 if (!SDL_CPUName[0]) {
463 SDL_strlcpy(SDL_CPUName,
"Unknown",
sizeof(SDL_CPUName));
475 if (
SDL_strcmp(cpuType,
"GenuineIntel") == 0) {
478 cpuid(0x00000001, a, b, c, d);
479 return (((b >> 8) & 0xff) * 8);
480 }
else if (
SDL_strcmp(cpuType,
"AuthenticAMD") == 0) {
483 cpuid(0x80000005, a, b, c, d);
496 if (SDL_CPUFeatures == 0xFFFFFFFF) {
619 printf(
"CPU name: %s\n", SDL_GetCPUName());
static __inline__ int CPU_haveMMX(void)
static __inline__ int CPU_have3DNow(void)
GLfloat GLfloat GLfloat GLfloat h
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
int main(int argc, char **argv)
DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void)
static __inline__ int CPU_haveAltiVec(void)
static const char * SDL_GetCPUType(void)
static __inline__ int CPU_getCPUIDFeatures(void)
DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void)
GLboolean GLboolean GLboolean GLboolean a
static __inline__ int CPU_haveSSE41(void)
DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void)
return Display return Display Bool Bool int d
DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void)
DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void)
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void)
static __inline__ int CPU_haveSSE42(void)
DECLSPEC int SDLCALL SDL_GetCPUCount(void)
DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen)
#define SDL_CACHELINE_SIZE
DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void)
#define cpuid(func, a, b, c, d)
static Uint32 SDL_CPUFeatures
static __inline__ int CPU_haveRDTSC(void)
DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void)
static Uint32 SDL_GetCPUFeatures(void)
DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2)
DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void)
static __inline__ int CPU_haveSSE3(void)
EGLSurface EGLint void ** value
DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void)
static __inline__ int CPU_haveSSE(void)
GLdouble GLdouble GLdouble b
static __inline__ int CPU_haveSSE2(void)
static __inline__ int CPU_haveCPUID(void)