annotate ppc/check_altivec.c @ 7852:0d60b8b7f30b libavcodec

Fix compilation on Mac OS X 10.4: Defining _POSIX_C_SOURCE hides the u_char & similar typedefs that sysctl.h needs. Since sysctl() itself isn't POSIX undefining _POSIX_C_SOURCE for check_altivec.c seems the best way to fix this. patch by David Conrad lessen42 at gmail com
author diego
date Sat, 13 Sep 2008 13:18:35 +0000
parents c93570aeb3eb
children 47717d5239fa
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__
7852
0d60b8b7f30b Fix compilation on Mac OS X 10.4: Defining _POSIX_C_SOURCE hides the u_char &
diego
parents: 6750
diff changeset
26 #undef _POSIX_C_SOURCE
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
27 #include <sys/sysctl.h>
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
28 #elif __AMIGAOS4__
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
29 #include <exec/exec.h>
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
30 #include <interfaces/exec.h>
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
31 #include <proto/exec.h>
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
32 #endif /* __APPLE__ */
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
33
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 * 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
36 * is present
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
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
39 int has_altivec(void)
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
40 {
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
41 #ifdef __AMIGAOS4__
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
42 ULONG result = 0;
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
43 extern struct ExecIFace *IExec;
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 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
46 if (result == VECTORTYPE_ALTIVEC) return 1;
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
47 return 0;
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
48 #elif __APPLE__
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
49 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
50 int has_vu = 0;
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
51 size_t len = sizeof(has_vu);
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
52 int err;
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 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
55
6750
c93570aeb3eb Remove unnecessary parentheses from return calls.
diego
parents: 6159
diff changeset
56 if (err == 0) return has_vu != 0;
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
57 return 0;
6159
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
58 #elif defined(RUNTIME_CPUDETECT)
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
59 int proc_ver;
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
60 // support of mfspr PVR emulation added in Linux 2.6.17
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
61 asm volatile("mfspr %0, 287" : "=r" (proc_ver));
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
62 proc_ver >>= 16;
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
63 if (proc_ver & 0x8000 ||
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
64 proc_ver == 0x000c ||
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
65 proc_ver == 0x0039 || proc_ver == 0x003c ||
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
66 proc_ver == 0x0044 || proc_ver == 0x0045 ||
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
67 proc_ver == 0x0070)
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
68 return 1;
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
69 return 0;
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
70 #else
5757
ace63c809071 Remove uses of SIGILL for CPU extension detection, that method is not acceptable
reimar
parents: 5750
diff changeset
71 // since we were compiled for altivec, just assume we have it
ace63c809071 Remove uses of SIGILL for CPU extension detection, that method is not acceptable
reimar
parents: 5750
diff changeset
72 // until someone comes up with a proper way (not involving signal hacks).
ace63c809071 Remove uses of SIGILL for CPU extension detection, that method is not acceptable
reimar
parents: 5750
diff changeset
73 return 1;
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
74 #endif /* __AMIGAOS4__ */
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
75 }
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
76