2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
14 #include "aom_ports/arm.h"
15 #include "config/aom_config.h"
18 #include <winapifamily.h>
19 #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
20 #define getenv(x) NULL
24 static int arm_cpu_env_flags(int *flags
) {
26 env
= getenv("AOM_SIMD_CAPS");
28 *flags
= (int)strtol(env
, NULL
, 0);
35 static int arm_cpu_env_mask(void) {
37 env
= getenv("AOM_SIMD_CAPS_MASK");
38 return env
&& *env
? (int)strtol(env
, NULL
, 0) : ~0;
41 #if !CONFIG_RUNTIME_CPU_DETECT || defined(__APPLE__)
43 int aom_arm_cpu_caps(void) {
44 /* This function should actually be a no-op. There is no way to adjust any of
45 * these because the RTCD tables do not exist: the functions are called
49 if (!arm_cpu_env_flags(&flags
)) {
52 mask
= arm_cpu_env_mask();
55 #endif /* HAVE_NEON */
59 #elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT || __APPLE__ */
60 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
61 #define WIN32_LEAN_AND_MEAN
62 #define WIN32_EXTRA_LEAN
65 int aom_arm_cpu_caps(void) {
68 if (!arm_cpu_env_flags(&flags
)) {
71 mask
= arm_cpu_env_mask();
72 /* MSVC has no inline __asm support for ARM, but it does let you __emit
73 * instructions via their assembled hex code.
74 * All of these instructions should be essentially nops.
77 if (mask
& HAS_NEON
) {
82 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
) {
86 #endif /* HAVE_NEON */
90 #elif defined(__ANDROID__) /* end _MSC_VER */
91 #include <cpu-features.h>
93 int aom_arm_cpu_caps(void) {
97 if (!arm_cpu_env_flags(&flags
)) {
100 mask
= arm_cpu_env_mask();
101 features
= android_getCpuFeatures();
104 if (features
& ANDROID_CPU_ARM_FEATURE_NEON
) flags
|= HAS_NEON
;
105 #endif /* HAVE_NEON */
109 #elif defined(__linux__) /* end __ANDROID__ */
113 int aom_arm_cpu_caps(void) {
117 if (!arm_cpu_env_flags(&flags
)) {
120 mask
= arm_cpu_env_mask();
121 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
123 * This also means that detection will fail in Scratchbox.
125 fin
= fopen("/proc/cpuinfo", "r");
127 /* 512 should be enough for anybody (it's even enough for all the flags
128 * that x86 has accumulated... so far).
131 while (fgets(buf
, 511, fin
) != NULL
) {
133 if (memcmp(buf
, "Features", 8) == 0) {
135 p
= strstr(buf
, " neon");
136 if (p
!= NULL
&& (p
[5] == ' ' || p
[5] == '\n')) {
140 #endif /* HAVE_NEON */
146 #else /* end __linux__ */
148 "Runtime CPU detection selected, but no CPU detection method " \
149 "available for your platform. Rerun cmake with -DCONFIG_RUNTIME_CPU_DETECT=0."