csutil/processorspecdetection.h
00001 /* 00002 Copyright (C) 2007 by Michael Gist 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __PROCESSORSPECDETECTION_H__ 00020 #define __PROCESSORSPECDETECTION_H__ 00021 00022 #include "csextern.h" 00023 #include "cstypes.h" 00024 00025 namespace CS 00026 { 00027 namespace Platform 00028 { 00029 enum InstructionSetFlags 00030 { 00031 ALTIVEC = 1 << 0, 00032 MMX = 1 << 1, 00033 SSE = 1 << 2, 00034 SSE2 = 1 << 3, 00035 SSE3 = 1 << 4 00036 }; 00037 00038 #ifdef CS_PLATFORM_WIN32 00039 #include "csutil/processor/processorspecdetection_win.h" 00040 #elif defined(CS_PROCESSOR_POWERPC) 00041 #include "csutil/processor/processorspecdetection_gcc_ppc.h" 00042 #else 00043 #include "csutil/processor/processorspecdetection_nonwin_gcc_x86.h" 00044 #endif 00045 00046 using namespace Implementation; 00047 template <class T> 00048 class ProcessorSpecDetectionBase 00049 { 00050 public: 00051 00052 ProcessorSpecDetectionBase() 00053 { 00054 00055 checked = false; 00056 hasAltiVec = false; 00057 hasMMX = false; 00058 hasSSE = false; 00059 hasSSE2 = false; 00060 hasSSE3 = false; 00061 } 00062 00063 ~ProcessorSpecDetectionBase() 00064 { 00065 } 00066 00067 inline bool HasMMX() 00068 { 00069 CheckSupport(); 00070 return hasMMX; 00071 } 00072 00073 inline bool HasSSE() 00074 { 00075 CheckSupport(); 00076 return hasSSE; 00077 } 00078 00079 inline bool HasSSE2() 00080 { 00081 CheckSupport(); 00082 return hasSSE2; 00083 } 00084 00085 inline bool HasSSE3() 00086 { 00087 CheckSupport(); 00088 return hasSSE3; 00089 } 00090 00091 inline bool HasAltiVec() 00092 { 00093 CheckSupport(); 00094 return hasAltiVec; 00095 } 00096 00097 private: 00098 00099 T platform; 00100 uint instructionBitMask; 00101 bool checked; 00102 bool hasAltiVec; 00103 bool hasMMX; 00104 bool hasSSE; 00105 bool hasSSE2; 00106 bool hasSSE3; 00107 00108 void CheckSupport() 00109 { 00110 if(checked) 00111 return; 00112 00113 instructionBitMask = platform.CheckSupportedInstruction(); 00114 hasAltiVec = (instructionBitMask & ALTIVEC) != 0; 00115 hasMMX = (instructionBitMask & MMX) != 0; 00116 hasSSE = (instructionBitMask & SSE) != 0; 00117 hasSSE2 = (instructionBitMask & SSE2) != 0; 00118 hasSSE3 = (instructionBitMask & SSE3) != 0; 00119 checked = true; 00120 } 00121 }; 00122 00123 class ProcessorSpecDetection 00124 { 00125 private: 00126 00127 #ifdef CS_PLATFORM_WIN32 00128 ProcessorSpecDetectionBase<DetectInstructionsWin> procDetect; 00129 #elif defined(CS_PROCESSOR_POWERPC) 00130 ProcessorSpecDetectionBase<DetectInstructionsGCCPPC> procDetect; 00131 #else 00132 ProcessorSpecDetectionBase<DetectInstructionsNonWinGCCx86> procDetect; 00133 #endif 00134 00135 public: 00136 inline bool HasMMX() 00137 { 00138 return procDetect.HasMMX(); 00139 } 00140 00141 inline bool HasSSE() 00142 { 00143 return procDetect.HasSSE(); 00144 } 00145 00146 inline bool HasSSE2() 00147 { 00148 return procDetect.HasSSE2(); 00149 } 00150 00151 inline bool HasSSE3() 00152 { 00153 return procDetect.HasSSE3(); 00154 } 00155 00156 inline bool HasAltiVec() 00157 { 00158 return procDetect.HasAltiVec(); 00159 } 00160 00161 }; 00162 } 00163 } 00164 00165 #endif // __PROCESSORSPECDETECTION_H__
Generated for Crystal Space 1.4.1 by doxygen 1.7.1