Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __PROCESSORSPECDETECTION_H__
00020 #define __PROCESSORSPECDETECTION_H__
00021
00026 #include "csextern.h"
00027 #include "cstypes.h"
00028
00029 namespace CS
00030 {
00031 namespace Platform
00032 {
00033 enum InstructionSetFlags
00034 {
00035 ALTIVEC = 1 << 0,
00036 MMX = 1 << 1,
00037 SSE = 1 << 2,
00038 SSE2 = 1 << 3,
00039 SSE3 = 1 << 4
00040 };
00041
00042 #ifdef CS_PLATFORM_WIN32
00043 #include "csutil/processor/processorspecdetection_win.h"
00044 #elif defined(CS_PROCESSOR_POWERPC)
00045 #include "csutil/processor/processorspecdetection_gcc_ppc.h"
00046 #elif defined(CS_PROCESSOR_ARM)
00047 #include "csutil/processor/processorspecdetection_nonwin_gcc_arm.h"
00048 #else
00049 #include "csutil/processor/processorspecdetection_nonwin_gcc_x86.h"
00050 #endif
00051
00052 using namespace Implementation;
00053 template <class T>
00054 class ProcessorSpecDetectionBase
00055 {
00056 public:
00057
00058 ProcessorSpecDetectionBase()
00059 {
00060
00061 checked = false;
00062 hasAltiVec = false;
00063 hasMMX = false;
00064 hasSSE = false;
00065 hasSSE2 = false;
00066 hasSSE3 = false;
00067 }
00068
00069 ~ProcessorSpecDetectionBase()
00070 {
00071 }
00072
00073 inline bool HasMMX()
00074 {
00075 CheckSupport();
00076 return hasMMX;
00077 }
00078
00079 inline bool HasSSE()
00080 {
00081 CheckSupport();
00082 return hasSSE;
00083 }
00084
00085 inline bool HasSSE2()
00086 {
00087 CheckSupport();
00088 return hasSSE2;
00089 }
00090
00091 inline bool HasSSE3()
00092 {
00093 CheckSupport();
00094 return hasSSE3;
00095 }
00096
00097 inline bool HasAltiVec()
00098 {
00099 CheckSupport();
00100 return hasAltiVec;
00101 }
00102
00103 private:
00104
00105 T platform;
00106 uint instructionBitMask;
00107 bool checked;
00108 bool hasAltiVec;
00109 bool hasMMX;
00110 bool hasSSE;
00111 bool hasSSE2;
00112 bool hasSSE3;
00113
00114 void CheckSupport()
00115 {
00116 if(checked)
00117 return;
00118
00119 instructionBitMask = platform.CheckSupportedInstruction();
00120 hasAltiVec = (instructionBitMask & ALTIVEC) != 0;
00121 hasMMX = (instructionBitMask & MMX) != 0;
00122 hasSSE = (instructionBitMask & SSE) != 0;
00123 hasSSE2 = (instructionBitMask & SSE2) != 0;
00124 hasSSE3 = (instructionBitMask & SSE3) != 0;
00125 checked = true;
00126 }
00127 };
00128
00132 class ProcessorSpecDetection
00133 {
00134 private:
00135
00136 #ifdef CS_PLATFORM_WIN32
00137 ProcessorSpecDetectionBase<DetectInstructionsWin> procDetect;
00138 #elif defined(CS_PROCESSOR_POWERPC)
00139 ProcessorSpecDetectionBase<DetectInstructionsGCCPPC> procDetect;
00140 #elif defined(CS_PROCESSOR_ARM)
00141 ProcessorSpecDetectionBase<DetectInstructionsNonWinGCCARM> procDetect;
00142 #else
00143 ProcessorSpecDetectionBase<DetectInstructionsNonWinGCCx86> procDetect;
00144 #endif
00145
00146 public:
00148 inline bool HasMMX()
00149 {
00150 return procDetect.HasMMX();
00151 }
00152
00154 inline bool HasSSE()
00155 {
00156 return procDetect.HasSSE();
00157 }
00158
00160 inline bool HasSSE2()
00161 {
00162 return procDetect.HasSSE2();
00163 }
00164
00166 inline bool HasSSE3()
00167 {
00168 return procDetect.HasSSE3();
00169 }
00170
00172 inline bool HasAltiVec()
00173 {
00174 return procDetect.HasAltiVec();
00175 }
00176
00177 };
00178 }
00179 }
00180
00181 #endif // __PROCESSORSPECDETECTION_H__