2012-04-21 17:31:10 +03:00
|
|
|
/*
|
2013-08-16 00:12:51 +03:00
|
|
|
* This file is part of FFmpeg.
|
2012-04-21 17:31:10 +03:00
|
|
|
*
|
2013-08-16 00:12:51 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2012-04-21 17:31:10 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2013-08-16 00:12:51 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2012-04-21 17:31:10 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2013-08-16 00:12:51 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2012-04-21 17:31:10 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/cpu.h"
|
2013-08-20 18:49:01 +03:00
|
|
|
#include "libavutil/cpu_internal.h"
|
2012-04-21 17:31:10 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-12-05 05:11:22 +03:00
|
|
|
#define CORE_FLAG(f) \
|
|
|
|
(AV_CPU_FLAG_ ## f * (HAVE_ ## f ## _EXTERNAL || HAVE_ ## f ## _INLINE))
|
|
|
|
|
|
|
|
#define CORE_CPU_FLAGS \
|
|
|
|
(CORE_FLAG(ARMV5TE) | \
|
|
|
|
CORE_FLAG(ARMV6) | \
|
|
|
|
CORE_FLAG(ARMV6T2) | \
|
|
|
|
CORE_FLAG(VFP) | \
|
|
|
|
CORE_FLAG(VFPV3) | \
|
|
|
|
CORE_FLAG(NEON))
|
|
|
|
|
|
|
|
#if defined __linux__ || defined __ANDROID__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2013-02-07 11:54:20 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include "libavutil/avstring.h"
|
2012-12-05 05:11:22 +03:00
|
|
|
|
|
|
|
#define AT_HWCAP 16
|
|
|
|
|
|
|
|
/* Relevant HWCAP values from kernel headers */
|
|
|
|
#define HWCAP_VFP (1 << 6)
|
|
|
|
#define HWCAP_EDSP (1 << 7)
|
|
|
|
#define HWCAP_THUMBEE (1 << 11)
|
|
|
|
#define HWCAP_NEON (1 << 12)
|
|
|
|
#define HWCAP_VFPv3 (1 << 13)
|
|
|
|
#define HWCAP_TLS (1 << 15)
|
|
|
|
|
|
|
|
static int get_hwcap(uint32_t *hwcap)
|
|
|
|
{
|
|
|
|
struct { uint32_t a_type; uint32_t a_val; } auxv;
|
|
|
|
FILE *f = fopen("/proc/self/auxv", "r");
|
|
|
|
int err = -1;
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (fread(&auxv, sizeof(auxv), 1, f) > 0) {
|
|
|
|
if (auxv.a_type == AT_HWCAP) {
|
|
|
|
*hwcap = auxv.a_val;
|
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-02-07 11:54:20 +03:00
|
|
|
static int get_cpuinfo(uint32_t *hwcap)
|
|
|
|
{
|
|
|
|
FILE *f = fopen("/proc/cpuinfo", "r");
|
|
|
|
char buf[200];
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*hwcap = 0;
|
|
|
|
while (fgets(buf, sizeof(buf), f)) {
|
|
|
|
if (av_strstart(buf, "Features", NULL)) {
|
|
|
|
if (strstr(buf, " edsp "))
|
|
|
|
*hwcap |= HWCAP_EDSP;
|
|
|
|
if (strstr(buf, " tls "))
|
|
|
|
*hwcap |= HWCAP_TLS;
|
|
|
|
if (strstr(buf, " thumbee "))
|
|
|
|
*hwcap |= HWCAP_THUMBEE;
|
|
|
|
if (strstr(buf, " vfp "))
|
|
|
|
*hwcap |= HWCAP_VFP;
|
|
|
|
if (strstr(buf, " vfpv3 "))
|
|
|
|
*hwcap |= HWCAP_VFPv3;
|
2014-06-23 20:49:21 +03:00
|
|
|
if (strstr(buf, " neon ") || strstr(buf, " asimd "))
|
2013-02-07 11:54:20 +03:00
|
|
|
*hwcap |= HWCAP_NEON;
|
2014-06-23 20:49:21 +03:00
|
|
|
if (strstr(buf, " fp ")) // Listed on 64 bit ARMv8 kernels
|
|
|
|
*hwcap |= HWCAP_VFP | HWCAP_VFPv3;
|
2013-02-07 11:54:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-05 05:11:22 +03:00
|
|
|
int ff_get_cpu_flags_arm(void)
|
|
|
|
{
|
|
|
|
int flags = CORE_CPU_FLAGS;
|
|
|
|
uint32_t hwcap;
|
|
|
|
|
|
|
|
if (get_hwcap(&hwcap) < 0)
|
2013-02-07 11:54:20 +03:00
|
|
|
if (get_cpuinfo(&hwcap) < 0)
|
|
|
|
return flags;
|
2012-12-05 05:11:22 +03:00
|
|
|
|
|
|
|
#define check_cap(cap, flag) do { \
|
|
|
|
if (hwcap & HWCAP_ ## cap) \
|
|
|
|
flags |= AV_CPU_FLAG_ ## flag; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* No flags explicitly indicate v6 or v6T2 so check others which
|
|
|
|
imply support. */
|
|
|
|
check_cap(EDSP, ARMV5TE);
|
|
|
|
check_cap(TLS, ARMV6);
|
|
|
|
check_cap(THUMBEE, ARMV6T2);
|
|
|
|
check_cap(VFP, VFP);
|
|
|
|
check_cap(VFPv3, VFPV3);
|
|
|
|
check_cap(NEON, NEON);
|
|
|
|
|
|
|
|
/* The v6 checks above are not reliable so let higher flags
|
|
|
|
trickle down. */
|
|
|
|
if (flags & (AV_CPU_FLAG_VFPV3 | AV_CPU_FLAG_NEON))
|
|
|
|
flags |= AV_CPU_FLAG_ARMV6T2;
|
2015-06-04 23:07:44 +02:00
|
|
|
else if (flags & (AV_CPU_FLAG_ARMV6T2 | AV_CPU_FLAG_ARMV6))
|
2014-08-07 19:34:35 +03:00
|
|
|
/* Some functions use the 'setend' instruction which is deprecated on ARMv8
|
|
|
|
* and serializing on some ARMv7 cores. This ensures such functions
|
|
|
|
* are only enabled on ARMv6. */
|
|
|
|
flags |= AV_CPU_FLAG_SETEND;
|
|
|
|
|
2012-12-05 05:11:22 +03:00
|
|
|
if (flags & AV_CPU_FLAG_ARMV6T2)
|
|
|
|
flags |= AV_CPU_FLAG_ARMV6;
|
|
|
|
|
2015-12-09 23:28:36 +02:00
|
|
|
/* set the virtual VFPv2 vector mode flag */
|
|
|
|
if ((flags & AV_CPU_FLAG_VFP) && !(flags & (AV_CPU_FLAG_VFPV3 | AV_CPU_FLAG_NEON)))
|
|
|
|
flags |= AV_CPU_FLAG_VFP_VM;
|
|
|
|
|
2012-12-05 05:11:22 +03:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2012-04-21 17:31:10 +03:00
|
|
|
int ff_get_cpu_flags_arm(void)
|
|
|
|
{
|
|
|
|
return AV_CPU_FLAG_ARMV5TE * HAVE_ARMV5TE |
|
|
|
|
AV_CPU_FLAG_ARMV6 * HAVE_ARMV6 |
|
|
|
|
AV_CPU_FLAG_ARMV6T2 * HAVE_ARMV6T2 |
|
2012-12-05 02:29:34 +03:00
|
|
|
AV_CPU_FLAG_VFP * HAVE_VFP |
|
2012-04-21 17:31:10 +03:00
|
|
|
AV_CPU_FLAG_VFPV3 * HAVE_VFPV3 |
|
2014-08-07 19:34:35 +03:00
|
|
|
AV_CPU_FLAG_NEON * HAVE_NEON |
|
|
|
|
AV_CPU_FLAG_SETEND * !(HAVE_NEON | HAVE_VFPV3);
|
2012-04-21 17:31:10 +03:00
|
|
|
}
|
2012-12-05 05:11:22 +03:00
|
|
|
|
|
|
|
#endif
|