00001
00002
00003
00004
00005
00006
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
00041
00042 CPUID
00043 mov RegEDX, edx
00044 }
00045 }
00046 catch(...)
00047 {
00048 return false;
00049 }
00050
00051 if (RegEDX & 0x800000)
00052 {
00053 try { _asm {emms} }
00054 catch(...) { return false; }
00055 }
00056 else
00057 return false;
00058
00059
00060
00061
00062 return true;
00063 #elif __GNUC__
00064
00065 int edx=0;
00066 try
00067 {
00068 asm(
00069 "mov 1,%%eax \n"
00070 "CPUID \n"
00071 :"=d"(edx)
00072 );
00073 }
00074 catch(...)
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
00090
00091
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 }