annotate ffmpeg/libavutil/ppc/cpu.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * This file is part of FFmpeg.
yading@11 3 *
yading@11 4 * FFmpeg is free software; you can redistribute it and/or
yading@11 5 * modify it under the terms of the GNU Lesser General Public
yading@11 6 * License as published by the Free Software Foundation; either
yading@11 7 * version 2.1 of the License, or (at your option) any later version.
yading@11 8 *
yading@11 9 * FFmpeg is distributed in the hope that it will be useful,
yading@11 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 12 * Lesser General Public License for more details.
yading@11 13 *
yading@11 14 * You should have received a copy of the GNU Lesser General Public
yading@11 15 * License along with FFmpeg; if not, write to the Free Software
yading@11 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 17 */
yading@11 18
yading@11 19 #ifdef __APPLE__
yading@11 20 #include <sys/sysctl.h>
yading@11 21 #elif defined(__OpenBSD__)
yading@11 22 #include <sys/param.h>
yading@11 23 #include <sys/sysctl.h>
yading@11 24 #include <machine/cpu.h>
yading@11 25 #elif defined(__AMIGAOS4__)
yading@11 26 #include <exec/exec.h>
yading@11 27 #include <interfaces/exec.h>
yading@11 28 #include <proto/exec.h>
yading@11 29 #endif /* __APPLE__ */
yading@11 30
yading@11 31 #include "libavutil/cpu.h"
yading@11 32 #include "config.h"
yading@11 33
yading@11 34 /**
yading@11 35 * This function MAY rely on signal() or fork() in order to make sure AltiVec
yading@11 36 * is present.
yading@11 37 */
yading@11 38 int ff_get_cpu_flags_ppc(void)
yading@11 39 {
yading@11 40 #if HAVE_ALTIVEC
yading@11 41 #ifdef __AMIGAOS4__
yading@11 42 ULONG result = 0;
yading@11 43 extern struct ExecIFace *IExec;
yading@11 44
yading@11 45 IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
yading@11 46 if (result == VECTORTYPE_ALTIVEC)
yading@11 47 return AV_CPU_FLAG_ALTIVEC;
yading@11 48 return 0;
yading@11 49 #elif defined(__APPLE__) || defined(__OpenBSD__)
yading@11 50 #ifdef __OpenBSD__
yading@11 51 int sels[2] = {CTL_MACHDEP, CPU_ALTIVEC};
yading@11 52 #else
yading@11 53 int sels[2] = {CTL_HW, HW_VECTORUNIT};
yading@11 54 #endif
yading@11 55 int has_vu = 0;
yading@11 56 size_t len = sizeof(has_vu);
yading@11 57 int err;
yading@11 58
yading@11 59 err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
yading@11 60
yading@11 61 if (err == 0)
yading@11 62 return has_vu ? AV_CPU_FLAG_ALTIVEC : 0;
yading@11 63 return 0;
yading@11 64 #elif CONFIG_RUNTIME_CPUDETECT && defined(__linux__) && !ARCH_PPC64
yading@11 65 int proc_ver;
yading@11 66 // Support of mfspr PVR emulation added in Linux 2.6.17.
yading@11 67 __asm__ volatile("mfspr %0, 287" : "=r" (proc_ver));
yading@11 68 proc_ver >>= 16;
yading@11 69 if (proc_ver & 0x8000 ||
yading@11 70 proc_ver == 0x000c ||
yading@11 71 proc_ver == 0x0039 || proc_ver == 0x003c ||
yading@11 72 proc_ver == 0x0044 || proc_ver == 0x0045 ||
yading@11 73 proc_ver == 0x0070)
yading@11 74 return AV_CPU_FLAG_ALTIVEC;
yading@11 75 return 0;
yading@11 76 #else
yading@11 77 // Since we were compiled for AltiVec, just assume we have it
yading@11 78 // until someone comes up with a proper way (not involving signal hacks).
yading@11 79 return AV_CPU_FLAG_ALTIVEC;
yading@11 80 #endif /* __AMIGAOS4__ */
yading@11 81 #endif /* HAVE_ALTIVEC */
yading@11 82 return 0;
yading@11 83 }