Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

detect_mmx.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *
00003  * DetectMMX.cpp
00004  * by Darryl Agostinelli March 4, 2000
00005  *
00006  * Code was adopted from Intel web page
00007  *
00008  */
00009 
00010 #include "Core/precomp.h"
00011 #include "API/Core/System/system.h"
00012 #include "API/Core/System/cl_assert.h"
00013 
00014 static bool do_mmx_test();
00015 
00016 bool CL_System::detect_mmx()
00017 {
00018         static bool has_mmx = false;
00019         static bool first_time = true;
00020         
00021         if (first_time)
00022         {
00023                 first_time = false;
00024                 has_mmx = do_mmx_test();
00025         }
00026         
00027         return has_mmx;
00028 }
00029 
00030 static bool do_mmx_test()
00031 {
00032 #ifdef USE_I386_ASSEMBLER
00033 #ifdef __MSC__
00034         unsigned long RegEDX;
00035 
00036         try 
00037         {
00038                 _asm
00039                 {
00040                         mov eax, 1                      // set up CPUID to return processor version and features
00041                                                                 //      0 = vendor string, 1 = version info, 2 = cache info
00042                         CPUID                           // code bytes = 0fh,  0a2h
00043                         mov RegEDX, edx         // features returned in edx
00044                 }
00045         }
00046         catch(...)                                      // catch everything
00047         {
00048                 return false;           // processor does not support CPUID
00049         }
00050 
00051         if (RegEDX & 0x800000)          // bit 23 is set for MMX technology
00052         {
00053                 try { _asm {emms} }             // try executing the MMX instruction "emms"
00054                 catch(...) { return false; }
00055         }
00056         else
00057                 return false;           // processor supports CPUID but does not support MMX technology
00058 
00059         // if we get here, it means the processor has MMX technology but
00060         // floating-point emulation is on; so MMX technology is unavailable
00061 
00062         return true;
00063 #elif  __GNUC__
00064 
00065         int edx=0;
00066         try 
00067         {
00068                 asm(
00069                                 "mov 1,%%eax \n" //Get ready for CPUID
00070                                 "CPUID \n" //Access CPUID
00071                                 :"=d"(edx) 
00072                          );
00073         }
00074         catch(...) //Catch all
00075         {
00076                 return false;
00077         }
00078         if (edx & 0x800000)
00079         {
00080                 try{ asm("emms"); }
00081                 catch(...) {return false;}
00082         }
00083         else
00084                 return false;
00085         
00086         return true;
00087 #elif __BORLANDC__
00088 
00089 //This is for detecting assembly when using the Borland compilers
00090 //If you do not have TASM then this will not compile
00091 //If you do have TASM then uncomment the code below, otherwise ignore it
00092 
00093         #ifdef USE_TASM
00094         int RegEDX=0;
00095         try
00096   {
00097         asm
00098     {
00099         mov eax, 1
00100       CPUID
00101       mov RegEDX, edx
00102     }
00103   }
00104   catch(...) {return false;}
00105 
00106   if (RegEDX & 0x800000)
00107   {
00108         try{asm{emms}}
00109                 catch(...) {return false;}
00110   }
00111   else
00112         return false;
00113   return true;
00114 #else
00115 
00116         std::cout<<"Support to detect this has not been compiled in.  Please check source(detect_mmx.cpp)"<<std::endl;
00117   return false;
00118 #endif //Endif USE_TASM
00119 
00120 #else
00121 
00122         cl_info(0, "CL_System::detect_mmx() not implemented under your OS/Compiler/Architecture.");
00123         return false;
00124 
00125 #endif
00126 
00127 #else
00128         return false;
00129 #endif //End USE_I386_ASSEMBLER
00130 }

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001