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