comparison cpudetect.c @ 9003:c428933c7e54

AltiVec detection code ("borrowed" from FFmpeg and libmpeg2) & enough code to enable the AltiVec IMDCT in liba52 and the DCT64 in mp3lib. patch by Romain Dolbeau <dolbeau@irisa.fr>
author arpi
date Sat, 18 Jan 2003 19:29:46 +0000
parents 778989dba3a2
children 5ba896a38d75
comparison
equal deleted inserted replaced
9002:60d144a16088 9003:c428933c7e54
427 gCpuCaps.hasSSE=0; 427 gCpuCaps.hasSSE=0;
428 #endif /* __linux__ */ 428 #endif /* __linux__ */
429 } 429 }
430 #else /* ARCH_X86 */ 430 #else /* ARCH_X86 */
431 431
432 #ifdef SYS_DARWIN
433 #include <sys/sysctl.h>
434 #else
435 #include <signal.h>
436 #include <setjmp.h>
437
438 static sigjmp_buf jmpbuf;
439 static volatile sig_atomic_t canjump = 0;
440
441 static void sigill_handler (int sig)
442 {
443 if (!canjump) {
444 signal (sig, SIG_DFL);
445 raise (sig);
446 }
447
448 canjump = 0;
449 siglongjmp (jmpbuf, 1);
450 }
451 #endif
452
432 void GetCpuCaps( CpuCaps *caps) 453 void GetCpuCaps( CpuCaps *caps)
433 { 454 {
434 caps->cpuType=0; 455 caps->cpuType=0;
435 caps->cpuStepping=0; 456 caps->cpuStepping=0;
436 caps->hasMMX=0; 457 caps->hasMMX=0;
438 caps->has3DNow=0; 459 caps->has3DNow=0;
439 caps->has3DNowExt=0; 460 caps->has3DNowExt=0;
440 caps->hasSSE=0; 461 caps->hasSSE=0;
441 caps->hasSSE2=0; 462 caps->hasSSE2=0;
442 caps->isX86=0; 463 caps->isX86=0;
464 caps->hasAltiVec = 0;
465 #ifdef HAVE_ALTIVEC
466 #ifdef SYS_DARWIN
467 /*
468 rip-off from ffmpeg altivec detection code.
469 this code also appears on Apple's AltiVec pages.
470 */
471 {
472 int sels[2] = {CTL_HW, HW_VECTORUNIT};
473 int has_vu = 0;
474 size_t len = sizeof(has_vu);
475 int err;
476
477 err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
478
479 if (err == 0)
480 if (has_vu != 0)
481 caps->hasAltiVec = 1;
482 mp_msg(MSGT_CPUDETECT,MSGL_INFO,"AltiVec %sfound\n", (caps->hasAltiVec ? "" : "not "));
483 }
484 #else /* SYS_DARWIN */
485 /* no Darwin, do it the brute-force way */
486 /* this is borrowed from the libmpeg2 library */
487 {
488 signal (SIGILL, sigill_handler);
489 if (sigsetjmp (jmpbuf, 1)) {
490 signal (SIGILL, SIG_DFL);
491 } else {
492 canjump = 1;
493
494 asm volatile ("mtspr 256, %0\n\t"
495 "vand v0, v0, v0"
496 :
497 : "r" (-1));
498
499 signal (SIGILL, SIG_DFL);
500 caps->hasAltiVec = 1;
501 }
502 }
503 #endif /* SYS_DARWIN */
504 #endif /* HAVE_ALTIVEC */
443 } 505 }
444 #endif /* !ARCH_X86 */ 506 #endif /* !ARCH_X86 */