CrystalSpace

Public API Reference

csutil/processorspecdetection.h
Go to the documentation of this file.
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 
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__

Generated for Crystal Space 2.0 by doxygen 1.7.6.1