00001
00002
00003
00004
00005
00006 #ifndef COMMONS_CPUID_H
00007 #define COMMONS_CPUID_H
00008
00009 #include <commons/x86asm.h>
00010
00011 namespace commons
00012 {
00013
00014 enum {
00015 CACHE = 2,
00016 CACHE_LINE_SIZES = 0x80000005
00017 };
00018
00019 #define cpuid(func,ax,bx,cx,dx)\
00020 __asm__ __volatile__ ("cpuid":\
00021 "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
00022
00029 inline unsigned short
00030 cache_line_sizes_intel()
00031 {
00032 unsigned int a, b, c, d;
00033 cpuid(1, a, b, c, d);
00034 return static_cast<unsigned short>(high(b) * 8);
00035 }
00036
00042 inline void
00043 cache_line_sizes_amd(unsigned char *iline, unsigned char *dline)
00044 {
00045 int a, b, c, d;
00046 cpuid(CACHE_LINE_SIZES, a, b, c, d);
00047 *dline = low(c);
00048 *iline = low(d);
00049 }
00050
00051 }
00052
00053 #endif