comparison cpudetect.c @ 10440:890f35b31edd

SSE os support detection for windows
author faust3
date Sat, 19 Jul 2003 12:25:18 +0000
parents 300649f96e22
children df1433f614f6
comparison
equal deleted inserted replaced
10439:6e38aeab712f 10440:890f35b31edd
25 #include <sys/sysctl.h> 25 #include <sys/sysctl.h>
26 #endif 26 #endif
27 27
28 #ifdef __linux__ 28 #ifdef __linux__
29 #include <signal.h> 29 #include <signal.h>
30 #endif
31
32 #ifdef WIN32
33 #include <windows.h>
30 #endif 34 #endif
31 35
32 //#define X86_FXSR_MAGIC 36 //#define X86_FXSR_MAGIC
33 /* Thanks to the FreeBSD project for some of this cpuid code, and 37 /* Thanks to the FreeBSD project for some of this cpuid code, and
34 * help understanding how to use it. Thanks to the Mesa 38 * help understanding how to use it. Thanks to the Mesa
161 gCpuCaps.has3DNow, 165 gCpuCaps.has3DNow,
162 gCpuCaps.has3DNowExt ); 166 gCpuCaps.has3DNowExt );
163 #endif 167 #endif
164 168
165 /* FIXME: Does SSE2 need more OS support, too? */ 169 /* FIXME: Does SSE2 need more OS support, too? */
166 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) 170 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(WIN32)
167 if (caps->hasSSE) 171 if (caps->hasSSE)
168 check_os_katmai_support(); 172 check_os_katmai_support();
169 if (!caps->hasSSE) 173 if (!caps->hasSSE)
170 caps->hasSSE2 = 0; 174 caps->hasSSE2 = 0;
171 #else 175 #else
291 mp_msg(MSGT_CPUDETECT,MSGL_V, "SSE enabling test failed badly!" ); 295 mp_msg(MSGT_CPUDETECT,MSGL_V, "SSE enabling test failed badly!" );
292 } 296 }
293 } 297 }
294 #endif /* __linux__ && _POSIX_SOURCE && X86_FXSR_MAGIC */ 298 #endif /* __linux__ && _POSIX_SOURCE && X86_FXSR_MAGIC */
295 299
300 #ifdef WIN32
301 LONG CALLBACK win32_sig_handler_sse(EXCEPTION_POINTERS* ep)
302 {
303 if(ep->ExceptionRecord->ExceptionCode==EXCEPTION_ILLEGAL_INSTRUCTION){
304 mp_msg(MSGT_CPUDETECT,MSGL_V, "SIGILL, " );
305 ep->ContextRecord->Eip +=3;
306 gCpuCaps.hasSSE=0;
307 return EXCEPTION_CONTINUE_EXECUTION;
308 }
309 return EXCEPTION_CONTINUE_SEARCH;
310 }
311 #endif /* WIN32 */
312
296 /* If we're running on a processor that can do SSE, let's see if we 313 /* If we're running on a processor that can do SSE, let's see if we
297 * are allowed to or not. This will catch 2.4.0 or later kernels that 314 * are allowed to or not. This will catch 2.4.0 or later kernels that
298 * haven't been configured for a Pentium III but are running on one, 315 * haven't been configured for a Pentium III but are running on one,
299 * and RedHat patched 2.2 kernels that have broken exception handling 316 * and RedHat patched 2.2 kernels that have broken exception handling
300 * support for user space apps that do SSE. 317 * support for user space apps that do SSE.
341 } 358 }
342 #else 359 #else
343 gCpuCaps.hasSSE = 0; 360 gCpuCaps.hasSSE = 0;
344 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "No OS support for SSE, disabling to be safe.\n" ); 361 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "No OS support for SSE, disabling to be safe.\n" );
345 #endif 362 #endif
363 #elif defined(WIN32)
364 LPTOP_LEVEL_EXCEPTION_FILTER exc_fil;
365 if ( gCpuCaps.hasSSE ) {
366 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
367 exc_fil = SetUnhandledExceptionFilter(win32_sig_handler_sse);
368 __asm __volatile ("xorps %xmm0, %xmm0");
369 SetUnhandledExceptionFilter(exc_fil);
370 if ( gCpuCaps.hasSSE ) mp_msg(MSGT_CPUDETECT,MSGL_V, "yes.\n" );
371 else mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
372 }
346 #elif defined(__linux__) 373 #elif defined(__linux__)
347 #if defined(_POSIX_SOURCE) && defined(X86_FXSR_MAGIC) 374 #if defined(_POSIX_SOURCE) && defined(X86_FXSR_MAGIC)
348 struct sigaction saved_sigill; 375 struct sigaction saved_sigill;
349 struct sigaction saved_sigfpe; 376 struct sigaction saved_sigfpe;
350 377