00001
00003
00004
00005 #include <setjmp.h>
00006 #include <signal.h>
00007 #include "cpu_x86.h"
00008
00009 #ifdef WIN32
00010 #include <windows.h>
00011 #endif
00012
00013 static jmp_buf jmpPtr;
00014
00015 static void SSE_not_support(int sig)
00016 {
00017 signal(SIGILL, SIG_DFL);
00018 longjmp(jmpPtr, 1);
00019 }
00020
00021 int haveUNITa(void);
00022 void setPIII_round(void);
00023
00024 int haveX86_UNIT(void)
00025 {
00026 static int unit = -1;
00027
00028 if (unit != -1) return unit;
00029 unit = haveUNITa();
00030
00031 #if defined(WIN32) && defined(HAVE___TRY) && defined(HAVE_EXCEPTION_EXECUTE_HANDLER)
00032 if (unit & MU_tSSE) {
00033 __try {
00034 setPIII_round();
00035 }
00036 __except(EXCEPTION_EXECUTE_HANDLER) {
00037 unit &= ~(MU_tSSE|MU_tSSE2);
00038 }
00039 }
00040 #elif defined(__unix__) || defined(WIN32) || defined(__os2__) || defined(__dos__)
00041 if (unit & MU_tSSE) {
00042 int ret;
00043 ret = setjmp(jmpPtr);
00044 if (!ret) {
00045 signal(SIGILL, SSE_not_support);
00046 setPIII_round();
00047 signal(SIGILL, SIG_DFL);
00048 }else{
00049 unit &= ~(MU_tSSE|MU_tSSE2);
00050 }
00051 }
00052 #else
00053 if(unit & MU_tSSE) setPIII_round();
00054 #endif
00055
00056 return unit;
00057 }