u_cpu_detect.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cpu_detect_caps

Enumerations

enum  cpu_detect_type {
  CPU_DETECT_TYPE_MIPS, CPU_DETECT_TYPE_ALPHA, CPU_DETECT_TYPE_SPARC, CPU_DETECT_TYPE_X86,
  CPU_DETECT_TYPE_POWERPC, CPU_DETECT_TYPE_OTHER
}

Functions

void cpu_detect_initialize (void)
struct cpu_detect_capscpu_detect_get_caps (void)
int cpu_detect_get_tsc (void)
int cpu_detect_get_mmx (void)
int cpu_detect_get_mmx2 (void)
int cpu_detect_get_sse (void)
int cpu_detect_get_sse2 (void)
int cpu_detect_get_sse3 (void)
int cpu_detect_get_ssse3 (void)
int cpu_detect_get_3dnow (void)
int cpu_detect_get_3dnow2 (void)
int cpu_detect_get_altivec (void)


Enumeration Type Documentation

enum cpu_detect_type

Enumerator:
CPU_DETECT_TYPE_MIPS 
CPU_DETECT_TYPE_ALPHA 
CPU_DETECT_TYPE_SPARC 
CPU_DETECT_TYPE_X86 
CPU_DETECT_TYPE_POWERPC 
CPU_DETECT_TYPE_OTHER 

Definition at line 34 of file u_cpu_detect.h.


Function Documentation

int cpu_detect_get_3dnow ( void   ) 

Definition at line 492 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::has3DNow.

00493 {
00494         return __cpu_detect_caps.has3DNow;
00495 }

int cpu_detect_get_3dnow2 ( void   ) 

Definition at line 497 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::has3DNowExt.

00498 {
00499         return __cpu_detect_caps.has3DNowExt;
00500 }

int cpu_detect_get_altivec ( void   ) 

Definition at line 502 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::hasAltiVec.

00503 {
00504         return __cpu_detect_caps.hasAltiVec;
00505 }

struct cpu_detect_caps* cpu_detect_get_caps ( void   )  [read]

Definition at line 451 of file u_cpu_detect.c.

References __cpu_detect_caps.

00452 {
00453         return &__cpu_detect_caps;
00454 }

int cpu_detect_get_mmx ( void   ) 

Definition at line 462 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::hasMMX.

00463 {
00464         return __cpu_detect_caps.hasMMX;
00465 }

int cpu_detect_get_mmx2 ( void   ) 

Definition at line 467 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::hasMMX2.

00468 {
00469         return __cpu_detect_caps.hasMMX2;
00470 }

int cpu_detect_get_sse ( void   ) 

Definition at line 472 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::hasSSE.

00473 {
00474         return __cpu_detect_caps.hasSSE;
00475 }

int cpu_detect_get_sse2 ( void   ) 

Definition at line 477 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::hasSSE2.

00478 {
00479         return __cpu_detect_caps.hasSSE2;
00480 }

int cpu_detect_get_sse3 ( void   ) 

Definition at line 482 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::hasSSE3.

00483 {
00484         return __cpu_detect_caps.hasSSE3;
00485 }

int cpu_detect_get_ssse3 ( void   ) 

Definition at line 487 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::hasSSSE3.

00488 {
00489         return __cpu_detect_caps.hasSSSE3;
00490 }

int cpu_detect_get_tsc ( void   ) 

Definition at line 457 of file u_cpu_detect.c.

References __cpu_detect_caps, and cpu_detect_caps::hasTSC.

00458 {
00459         return __cpu_detect_caps.hasTSC;
00460 }

void cpu_detect_initialize ( void   ) 

Definition at line 332 of file u_cpu_detect.c.

References __cpu_detect_caps, __cpu_detect_initialized, cpu_detect_caps::cacheline, check_os_katmai_support(), CPU_DETECT_TYPE_ALPHA, CPU_DETECT_TYPE_MIPS, CPU_DETECT_TYPE_OTHER, CPU_DETECT_TYPE_POWERPC, CPU_DETECT_TYPE_SPARC, CPU_DETECT_TYPE_X86, cpuid(), cpu_detect_caps::has3DNow, cpu_detect_caps::has3DNowExt, has_cpuid(), cpu_detect_caps::hasMMX, cpu_detect_caps::hasMMX2, cpu_detect_caps::hasSSE, cpu_detect_caps::hasSSE2, cpu_detect_caps::hasSSE3, cpu_detect_caps::hasSSSE3, cpu_detect_caps::hasTSC, cpu_detect_caps::nrcpu, cpu_detect_caps::type, and cpu_detect_caps::x86cpuType.

00333 {
00334         unsigned int regs[4];
00335         unsigned int regs2[4];
00336 
00337         int mib[2], ncpu;
00338         int len;
00339 
00340         memset(&__cpu_detect_caps, 0, sizeof (struct cpu_detect_caps));
00341 
00342         /* Check for arch type */
00343 #if defined(ARCH_MIPS)
00344         __cpu_detect_caps.type = CPU_DETECT_TYPE_MIPS;
00345 #elif defined(ARCH_ALPHA)
00346         __cpu_detect_caps.type = CPU_DETECT_TYPE_ALPHA;
00347 #elif defined(ARCH_SPARC)
00348         __cpu_detect_caps.type = CPU_DETECT_TYPE_SPARC;
00349 #elif defined(ARCH_X86)
00350         __cpu_detect_caps.type = CPU_DETECT_TYPE_X86;
00351 #elif defined(ARCH_POWERPC)
00352         __cpu_detect_caps.type = CPU_DETECT_TYPE_POWERPC;
00353 #else
00354         __cpu_detect_caps.type = CPU_DETECT_TYPE_OTHER;
00355 #endif
00356 
00357         /* Count the number of CPUs in system */
00358 #if !defined(OS_WIN32) && !defined(OS_UNKNOWN) && defined(_SC_NPROCESSORS_ONLN)
00359         __cpu_detect_caps.nrcpu = sysconf(_SC_NPROCESSORS_ONLN);
00360         if (__cpu_detect_caps.nrcpu == -1)
00361                 __cpu_detect_caps.nrcpu = 1;
00362 
00363 #elif defined(OS_NETBSD) || defined(OS_FREEBSD) || defined(OS_OPENBSD)
00364 
00365         mib[0] = CTL_HW;
00366         mib[1] = HW_NCPU;
00367 
00368         len = sizeof (ncpu);
00369         sysctl(mib, 2, &ncpu, &len, NULL, 0);
00370         __cpu_detect_caps.nrcpu = ncpu;
00371 
00372 #else
00373         __cpu_detect_caps.nrcpu = 1;
00374 #endif
00375 
00376 #if defined(ARCH_X86)
00377         /* No cpuid, old 486 or lower */
00378         if (has_cpuid() == 0)
00379                 return;
00380 
00381         __cpu_detect_caps.cacheline = 32;
00382 
00383         /* Get max cpuid level */
00384         cpuid(0x00000000, regs);
00385 
00386         if (regs[0] >= 0x00000001) {
00387                 unsigned int cacheline;
00388 
00389                 cpuid (0x00000001, regs2);
00390 
00391                 __cpu_detect_caps.x86cpuType = (regs2[0] >> 8) & 0xf;
00392                 if (__cpu_detect_caps.x86cpuType == 0xf)
00393                     __cpu_detect_caps.x86cpuType = 8 + ((regs2[0] >> 20) & 255); /* use extended family (P4, IA64) */
00394 
00395                 /* general feature flags */
00396                 __cpu_detect_caps.hasTSC  = (regs2[3] & (1 << 8  )) >>  8; /* 0x0000010 */
00397                 __cpu_detect_caps.hasMMX  = (regs2[3] & (1 << 23 )) >> 23; /* 0x0800000 */
00398                 __cpu_detect_caps.hasSSE  = (regs2[3] & (1 << 25 )) >> 25; /* 0x2000000 */
00399                 __cpu_detect_caps.hasSSE2 = (regs2[3] & (1 << 26 )) >> 26; /* 0x4000000 */
00400                 __cpu_detect_caps.hasSSE3 = (regs2[2] & (1));          /* 0x0000001 */
00401                 __cpu_detect_caps.hasSSSE3 = (regs2[2] & (1 << 9 )) >> 9;   /* 0x0000020 */
00402                 __cpu_detect_caps.hasMMX2 = __cpu_detect_caps.hasSSE; /* SSE cpus supports mmxext too */
00403 
00404                 cacheline = ((regs2[1] >> 8) & 0xFF) * 8;
00405                 if (cacheline > 0)
00406                         __cpu_detect_caps.cacheline = cacheline;
00407         }
00408 
00409         cpuid(0x80000000, regs);
00410 
00411         if (regs[0] >= 0x80000001) {
00412 
00413                 cpuid(0x80000001, regs2);
00414 
00415                 __cpu_detect_caps.hasMMX  |= (regs2[3] & (1 << 23 )) >> 23; /* 0x0800000 */
00416                 __cpu_detect_caps.hasMMX2 |= (regs2[3] & (1 << 22 )) >> 22; /* 0x400000 */
00417                 __cpu_detect_caps.has3DNow    = (regs2[3] & (1 << 31 )) >> 31; /* 0x80000000 */
00418                 __cpu_detect_caps.has3DNowExt = (regs2[3] & (1 << 30 )) >> 30;
00419         }
00420 
00421         if (regs[0] >= 0x80000006) {
00422                 cpuid(0x80000006, regs2);
00423                 __cpu_detect_caps.cacheline = regs2[2] & 0xFF;
00424         }
00425 
00426 
00427 #if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_NETBSD) || defined(OS_CYGWIN) || defined(OS_OPENBSD)
00428         if (__cpu_detect_caps.hasSSE)
00429                 check_os_katmai_support();
00430 
00431         if (!__cpu_detect_caps.hasSSE) {
00432                 __cpu_detect_caps.hasSSE2 = 0;
00433                 __cpu_detect_caps.hasSSE3 = 0;
00434                 __cpu_detect_caps.hasSSSE3 = 0;
00435         }
00436 #else
00437         __cpu_detect_caps.hasSSE = 0;
00438         __cpu_detect_caps.hasSSE2 = 0;
00439         __cpu_detect_caps.hasSSE3 = 0;
00440         __cpu_detect_caps.hasSSSE3 = 0;
00441 #endif
00442 #endif /* ARCH_X86 */
00443 
00444 #if defined(ARCH_POWERPC)
00445         check_os_altivec_support();
00446 #endif /* ARCH_POWERPC */
00447 
00448         __cpu_detect_initialized = 1;
00449 }


Generated on Tue Sep 29 06:25:28 2009 for Gallium3D by  doxygen 1.5.4