annotate ppc/check_altivec.c @ 12473:06abedae2906 libavcodec

Merge has_altivec() function into mm_support(), remove it and use mm_support() instead. Reduce complexity and simplify pending move to libavutil.
author stefano
date Wed, 08 Sep 2010 10:02:40 +0000
parents fdafbcef52f5
children
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 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11407
diff changeset
21 * @file
12024
fdafbcef52f5 Fix grammar errors in documentation
mru
parents: 11644
diff changeset
22 * Check for AltiVec presence.
5750
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>
8699
450a1c5bab22 Use '#if defined()' for OS-specific preprocessor checks.
diego
parents: 8031
diff changeset
28 #elif defined(__OpenBSD__)
7904
47717d5239fa AltiVec detection support for OpenBSD, patch by Brad, brad comstyle com.
diego
parents: 7852
diff changeset
29 #include <sys/param.h>
47717d5239fa AltiVec detection support for OpenBSD, patch by Brad, brad comstyle com.
diego
parents: 7852
diff changeset
30 #include <sys/sysctl.h>
47717d5239fa AltiVec detection support for OpenBSD, patch by Brad, brad comstyle com.
diego
parents: 7852
diff changeset
31 #include <machine/cpu.h>
8699
450a1c5bab22 Use '#if defined()' for OS-specific preprocessor checks.
diego
parents: 8031
diff changeset
32 #elif defined(__AMIGAOS4__)
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
33 #include <exec/exec.h>
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
34 #include <interfaces/exec.h>
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
35 #include <proto/exec.h>
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
36 #endif /* __APPLE__ */
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
37
11407
fb94047e23d2 Move the local includes below the system includes
mstorsjo
parents: 11382
diff changeset
38 #include "config.h"
fb94047e23d2 Move the local includes below the system includes
mstorsjo
parents: 11382
diff changeset
39 #include "dsputil_altivec.h"
fb94047e23d2 Move the local includes below the system includes
mstorsjo
parents: 11382
diff changeset
40
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
41 /**
7905
ae410599f388 spelling cosmetics
diego
parents: 7904
diff changeset
42 * This function MAY rely on signal() or fork() in order to make sure AltiVec
ae410599f388 spelling cosmetics
diego
parents: 7904
diff changeset
43 * is present.
5750
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
12473
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
46 int mm_support(void)
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
47 {
12473
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
48 #if HAVE_ALTIVEC
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
49 #ifdef __AMIGAOS4__
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
50 ULONG result = 0;
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
51 extern struct ExecIFace *IExec;
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
52
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
53 IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
12473
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
54 if (result == VECTORTYPE_ALTIVEC)
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
55 return AV_CPU_FLAG_ALTIVEC;
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
56 return 0;
7904
47717d5239fa AltiVec detection support for OpenBSD, patch by Brad, brad comstyle com.
diego
parents: 7852
diff changeset
57 #elif defined(__APPLE__) || defined(__OpenBSD__)
47717d5239fa AltiVec detection support for OpenBSD, patch by Brad, brad comstyle com.
diego
parents: 7852
diff changeset
58 #ifdef __OpenBSD__
47717d5239fa AltiVec detection support for OpenBSD, patch by Brad, brad comstyle com.
diego
parents: 7852
diff changeset
59 int sels[2] = {CTL_MACHDEP, CPU_ALTIVEC};
47717d5239fa AltiVec detection support for OpenBSD, patch by Brad, brad comstyle com.
diego
parents: 7852
diff changeset
60 #else
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
61 int sels[2] = {CTL_HW, HW_VECTORUNIT};
7904
47717d5239fa AltiVec detection support for OpenBSD, patch by Brad, brad comstyle com.
diego
parents: 7852
diff changeset
62 #endif
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
63 int has_vu = 0;
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
64 size_t len = sizeof(has_vu);
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
65 int err;
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
66
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
67 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
68
12473
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
69 if (err == 0)
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
70 return has_vu ? AV_CPU_FLAG_ALTIVEC : 0;
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
71 return 0;
9361
53e5c6a453e9 configure: Add --enable-runtime-cpudetect
ramiro
parents: 8718
diff changeset
72 #elif CONFIG_RUNTIME_CPUDETECT
6159
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
73 int proc_ver;
7905
ae410599f388 spelling cosmetics
diego
parents: 7904
diff changeset
74 // Support of mfspr PVR emulation added in Linux 2.6.17.
8031
eebc7209c47f Convert asm keyword into __asm__.
flameeyes
parents: 7905
diff changeset
75 __asm__ volatile("mfspr %0, 287" : "=r" (proc_ver));
6159
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
76 proc_ver >>= 16;
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
77 if (proc_ver & 0x8000 ||
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
78 proc_ver == 0x000c ||
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
79 proc_ver == 0x0039 || proc_ver == 0x003c ||
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
80 proc_ver == 0x0044 || proc_ver == 0x0045 ||
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
81 proc_ver == 0x0070)
12473
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
82 return AV_CPU_FLAG_ALTIVEC;
6159
eb2e3c3b7f78 Add mfspr-based AltiVec detection code.
reimar
parents: 5757
diff changeset
83 return 0;
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
84 #else
7905
ae410599f388 spelling cosmetics
diego
parents: 7904
diff changeset
85 // Since we were compiled for AltiVec, just assume we have it
5757
ace63c809071 Remove uses of SIGILL for CPU extension detection, that method is not acceptable
reimar
parents: 5750
diff changeset
86 // until someone comes up with a proper way (not involving signal hacks).
12473
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
87 return AV_CPU_FLAG_ALTIVEC;
5750
09f99af1db40 Sanitize altivec code so it can be built with runtime check properly
lu_zero
parents:
diff changeset
88 #endif /* __AMIGAOS4__ */
12473
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
89 #endif /* HAVE_ALTIVEC */
06abedae2906 Merge has_altivec() function into mm_support(), remove it and use
stefano
parents: 12024
diff changeset
90 return 0;
5750
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