comparison ppc/check_altivec.c @ 5750:09f99af1db40 libavcodec

Sanitize altivec code so it can be built with runtime check properly
author lu_zero
date Tue, 02 Oct 2007 11:39:32 +0000
parents
children ace63c809071
comparison
equal deleted inserted replaced
5749:784dcbdc910f 5750:09f99af1db40
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19
20 /**
21 * @file check_altivec.c
22 * Checks for AltiVec presence.
23 */
24
25 #ifdef __APPLE__
26 #include <sys/sysctl.h>
27 #elif __AMIGAOS4__
28 #include <exec/exec.h>
29 #include <interfaces/exec.h>
30 #include <proto/exec.h>
31 #else
32 #include <signal.h>
33 #include <setjmp.h>
34
35 static sigjmp_buf jmpbuf;
36 static volatile sig_atomic_t canjump = 0;
37
38 static void sigill_handler (int sig)
39 {
40 if (!canjump) {
41 signal (sig, SIG_DFL);
42 raise (sig);
43 }
44
45 canjump = 0;
46 siglongjmp (jmpbuf, 1);
47 }
48 #endif /* __APPLE__ */
49
50 /**
51 * This function MAY rely on signal() or fork() in order to make sure altivec
52 * is present
53 */
54
55 int has_altivec(void)
56 {
57 #ifdef __AMIGAOS4__
58 ULONG result = 0;
59 extern struct ExecIFace *IExec;
60
61 IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
62 if (result == VECTORTYPE_ALTIVEC) return 1;
63 return 0;
64 #elif __APPLE__
65 int sels[2] = {CTL_HW, HW_VECTORUNIT};
66 int has_vu = 0;
67 size_t len = sizeof(has_vu);
68 int err;
69
70 err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
71
72 if (err == 0) return (has_vu != 0);
73 return 0;
74 #else
75 /* Do it the brute-force way, borrowed from the libmpeg2 library. */
76 {
77 signal (SIGILL, sigill_handler);
78 if (sigsetjmp (jmpbuf, 1)) {
79 signal (SIGILL, SIG_DFL);
80 } else {
81 canjump = 1;
82
83 asm volatile ("mtspr 256, %0\n\t"
84 "vand %%v0, %%v0, %%v0"
85 :
86 : "r" (-1));
87
88 signal (SIGILL, SIG_DFL);
89 return 1;
90 }
91 }
92 return 0;
93 #endif /* __AMIGAOS4__ */
94 }
95