comparison cpudetect.c @ 27605:5b7f52928bcd

Simplify cpudetect OS-support detection code, e.g. using one mp_msg to print either yes or no instead of two. Should not change code behaviour.
author reimar
date Thu, 18 Sep 2008 15:30:23 +0000
parents 11c1f98df84c
children 48c1ae64255b
comparison
equal deleted inserted replaced
27604:4b7f86c4a8b9 27605:5b7f52928bcd
380 mib[1] = CPU_SSE; 380 mib[1] = CPU_SSE;
381 varlen = sizeof(has_sse); 381 varlen = sizeof(has_sse);
382 382
383 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " ); 383 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
384 ret = sysctl(mib, 2, &has_sse, &varlen, NULL, 0); 384 ret = sysctl(mib, 2, &has_sse, &varlen, NULL, 0);
385 if (ret < 0 || !has_sse) { 385 gCpuCaps.hasSSE = ret >= 0 && has_sse;
386 gCpuCaps.hasSSE=0; 386 mp_msg(MSGT_CPUDETECT,MSGL_V, gCpuCaps.hasSSE ? "yes.\n" : "no!\n" );
387 mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
388 } else {
389 gCpuCaps.hasSSE=1;
390 mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" );
391 }
392 387
393 mib[1] = CPU_SSE2; 388 mib[1] = CPU_SSE2;
394 varlen = sizeof(has_sse2); 389 varlen = sizeof(has_sse2);
395 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE2... " ); 390 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE2... " );
396 ret = sysctl(mib, 2, &has_sse2, &varlen, NULL, 0); 391 ret = sysctl(mib, 2, &has_sse2, &varlen, NULL, 0);
397 if (ret < 0 || !has_sse2) { 392 gCpuCaps.hasSSE2 = ret >= 0 && has_sse2;
398 gCpuCaps.hasSSE2=0; 393 mp_msg(MSGT_CPUDETECT,MSGL_V, gCpuCaps.hasSSE2 ? "yes.\n" : "no!\n" );
399 mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
400 } else {
401 gCpuCaps.hasSSE2=1;
402 mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" );
403 }
404 #else 394 #else
405 gCpuCaps.hasSSE = 0; 395 gCpuCaps.hasSSE = 0;
406 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "No OS support for SSE, disabling to be safe.\n" ); 396 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "No OS support for SSE, disabling to be safe.\n" );
407 #endif 397 #endif
408 #elif defined(WIN32) 398 #elif defined(WIN32)
410 if ( gCpuCaps.hasSSE ) { 400 if ( gCpuCaps.hasSSE ) {
411 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " ); 401 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
412 exc_fil = SetUnhandledExceptionFilter(win32_sig_handler_sse); 402 exc_fil = SetUnhandledExceptionFilter(win32_sig_handler_sse);
413 __asm __volatile ("xorps %xmm0, %xmm0"); 403 __asm __volatile ("xorps %xmm0, %xmm0");
414 SetUnhandledExceptionFilter(exc_fil); 404 SetUnhandledExceptionFilter(exc_fil);
415 if ( gCpuCaps.hasSSE ) mp_msg(MSGT_CPUDETECT,MSGL_V, "yes.\n" ); 405 mp_msg(MSGT_CPUDETECT,MSGL_V, gCpuCaps.hasSSE ? "yes.\n" : "no!\n" );
416 else mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
417 } 406 }
418 #elif defined(__OS2__) 407 #elif defined(__OS2__)
419 EXCEPTIONREGISTRATIONRECORD RegRec = { 0, &os2_sig_handler_sse }; 408 EXCEPTIONREGISTRATIONRECORD RegRec = { 0, &os2_sig_handler_sse };
420 if ( gCpuCaps.hasSSE ) { 409 if ( gCpuCaps.hasSSE ) {
421 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " ); 410 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
422 DosSetExceptionHandler( &RegRec ); 411 DosSetExceptionHandler( &RegRec );
423 __asm __volatile ("xorps %xmm0, %xmm0"); 412 __asm __volatile ("xorps %xmm0, %xmm0");
424 DosUnsetExceptionHandler( &RegRec ); 413 DosUnsetExceptionHandler( &RegRec );
425 if ( gCpuCaps.hasSSE ) mp_msg(MSGT_CPUDETECT,MSGL_V, "yes.\n" ); 414 mp_msg(MSGT_CPUDETECT,MSGL_V, gCpuCaps.hasSSE ? "yes.\n" : "no!\n" );
426 else mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
427 } 415 }
428 #elif defined(__linux__) 416 #elif defined(__linux__)
429 #if defined(_POSIX_SOURCE) 417 #if defined(_POSIX_SOURCE)
430 struct sigaction saved_sigill; 418 struct sigaction saved_sigill;
431 419
445 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " ); 433 mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
446 434
447 // __asm __volatile ("xorps %%xmm0, %%xmm0"); 435 // __asm __volatile ("xorps %%xmm0, %%xmm0");
448 __asm __volatile ("xorps %xmm0, %xmm0"); 436 __asm __volatile ("xorps %xmm0, %xmm0");
449 437
450 if ( gCpuCaps.hasSSE ) { 438 mp_msg(MSGT_CPUDETECT,MSGL_V, gCpuCaps.hasSSE ? "yes.\n" : "no!\n" );
451 mp_msg(MSGT_CPUDETECT,MSGL_V, "yes.\n" );
452 } else {
453 mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
454 }
455 } 439 }
456 440
457 /* Restore the original signal handlers. 441 /* Restore the original signal handlers.
458 */ 442 */
459 sigaction( SIGILL, &saved_sigill, NULL ); 443 sigaction( SIGILL, &saved_sigill, NULL );
460 444
461 /* If we've gotten to here and the XMM CPUID bit is still set, we're 445 /* If we've gotten to here and the XMM CPUID bit is still set, we're
462 * safe to go ahead and hook out the SSE code throughout Mesa. 446 * safe to go ahead and hook out the SSE code throughout Mesa.
463 */ 447 */
464 if ( gCpuCaps.hasSSE ) { 448 mp_msg(MSGT_CPUDETECT,MSGL_V, "Tests of OS support for SSE %s\n", gCpuCaps.hasSSE ? "passed." : "failed!" );
465 mp_msg(MSGT_CPUDETECT,MSGL_V, "Tests of OS support for SSE passed.\n" );
466 } else {
467 mp_msg(MSGT_CPUDETECT,MSGL_V, "Tests of OS support for SSE failed!\n" );
468 }
469 #else 449 #else
470 /* We can't use POSIX signal handling to test the availability of 450 /* We can't use POSIX signal handling to test the availability of
471 * SSE, so we disable it by default. 451 * SSE, so we disable it by default.
472 */ 452 */
473 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "Cannot test OS support for SSE, disabling to be safe.\n" ); 453 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "Cannot test OS support for SSE, disabling to be safe.\n" );