MeVisLabToolboxReference
MeVis/Foundation/Sources/OSXSupport/macCPUInfo.h
Go to the documentation of this file.
00001 // **InsertLicense** code author="Felix Ritter" version="1.0"
00002 
00006 
00007 #ifndef __macCPUInfo_H
00008 #define __macCPUInfo_H
00009 #if defined(__APPLE__)
00010 
00011 #include <stdint.h>
00012 
00013 namespace macx {
00014   
00016   class CPUInfo
00017   {
00018   public:
00019   
00021     enum CPUType {
00022       CPUTypeUnknown = -1,   
00023       CPUTypePPC,            
00024       CPUTypePPC64,          
00025       CPUTypeI386,           
00026       CPUTypeX86_64          
00027     };
00028     
00030     static CPUType getCPUType();
00031     
00033     static bool is64BitCapable() {
00034       return sysCtlBool("hw.cpu64bit_capable");
00035     }
00036     
00038     static bool isMMXPresent() {
00039       return sysCtlBool("hw.optional.mmx");
00040     }
00041     
00043     static bool isSSEPresent() {
00044       return sysCtlBool("hw.optional.sse");
00045     }
00046     
00048     static bool isSSE2Present() {
00049       return sysCtlBool("hw.optional.sse2");
00050     }
00051     
00053     static bool isSSE3Present() {
00054       return sysCtlBool("hw.optional.sse3");
00055     }
00056     
00058     static bool isSSSE3Present() {
00059       return sysCtlBool("hw.optional.supplementalsse3");
00060     }
00061     
00063     static bool isSSE4_1Present() {
00064       return sysCtlBool("hw.optional.sse4_1");
00065     }
00066     
00068     static bool isSSE4_2Present() {
00069       return sysCtlBool("hw.optional.sse4_2");
00070     }
00071     
00073     static bool isAESPresent() {
00074       return sysCtlBool("hw.optional.aes");
00075     }
00076     
00078     static uint64_t getCPUFrequency() {
00079       return sysCtlInt64("hw.cpufrequency");
00080     }
00081     
00083     static uint64_t getL1CacheSize() {
00084       // hw.l1dcachesize ?
00085       return sysCtlInt64("hw.l1icachesize");
00086     }
00087 
00089     static uint64_t getL2CacheSize() {
00090       return sysCtlInt64("hw.l2cachesize");
00091     }
00092     
00094     static uint64_t getL3CacheSize() {
00095       return sysCtlInt64("hw.l3cachesize");
00096     }
00097     
00099     static unsigned int getVirtualCoresCount() {
00100       int32_t packCount = sysCtlInt32("hw.packages");
00101       return (packCount == 0) ? 1 : sysCtlInt32("hw.ncpu") / packCount;
00102     }
00103     
00104   private:
00105     
00106     static bool    sysCtlBool (const char *option);
00107     static int32_t sysCtlInt32(const char *option);
00108     static int64_t sysCtlInt64(const char *option);
00109   };
00110   
00111 }
00112 
00113 #endif  // __APPLE__
00114 #endif  // __macCPUInfo_H