2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
13 #include "vpx_ports/arm.h"
14 #include "./vpx_config.h"
17 #include <winapifamily.h>
18 #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
19 #define getenv(x) NULL
23 static int arm_cpu_env_flags(int *flags) {
25 env = getenv("VPX_SIMD_CAPS");
27 *flags = (int)strtol(env, NULL, 0);
34 static int arm_cpu_env_mask(void) {
36 env = getenv("VPX_SIMD_CAPS_MASK");
37 return env && *env ? (int)strtol(env, NULL, 0) : ~0;
40 #if !CONFIG_RUNTIME_CPU_DETECT
42 int arm_cpu_caps(void) {
43 /* This function should actually be a no-op. There is no way to adjust any of
44 * these because the RTCD tables do not exist: the functions are called
48 if (!arm_cpu_env_flags(&flags)) {
51 mask = arm_cpu_env_mask();
54 #endif /* HAVE_EDSP */
57 #endif /* HAVE_MEDIA */
58 #if HAVE_NEON || HAVE_NEON_ASM
60 #endif /* HAVE_NEON || HAVE_NEON_ASM */
64 #elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT */
65 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
66 #define WIN32_LEAN_AND_MEAN
67 #define WIN32_EXTRA_LEAN
70 int arm_cpu_caps(void) {
73 if (!arm_cpu_env_flags(&flags)) {
76 mask = arm_cpu_env_mask();
77 /* MSVC has no inline __asm support for ARM, but it does let you __emit
78 * instructions via their assembled hex code.
79 * All of these instructions should be essentially nops.
82 if (mask & HAS_EDSP) {
87 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
91 #endif /* HAVE_EDSP */
98 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
102 #endif /* HAVE_MEDIA */
103 #if HAVE_NEON || HAVE_NEON_ASM
104 if (mask &HAS_NEON) {
109 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
110 /*Ignore exception.*/
113 #endif /* HAVE_NEON || HAVE_NEON_ASM */
117 #elif defined(__ANDROID__) /* end _MSC_VER */
118 #include <cpu-features.h>
120 int arm_cpu_caps(void) {
124 if (!arm_cpu_env_flags(&flags)) {
127 mask = arm_cpu_env_mask();
128 features = android_getCpuFeatures();
132 #endif /* HAVE_EDSP */
135 #endif /* HAVE_MEDIA */
136 #if HAVE_NEON || HAVE_NEON_ASM
137 if (features & ANDROID_CPU_ARM_FEATURE_NEON)
139 #endif /* HAVE_NEON || HAVE_NEON_ASM */
143 #elif defined(__linux__) /* end __ANDROID__ */
147 int arm_cpu_caps(void) {
151 if (!arm_cpu_env_flags(&flags)) {
154 mask = arm_cpu_env_mask();
155 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
157 * This also means that detection will fail in Scratchbox.
159 fin = fopen("/proc/cpuinfo", "r");
161 /* 512 should be enough for anybody (it's even enough for all the flags
162 * that x86 has accumulated... so far).
165 while (fgets(buf, 511, fin) != NULL) {
166 #if HAVE_EDSP || HAVE_NEON || HAVE_NEON_ASM
167 if (memcmp(buf, "Features", 8) == 0) {
170 p = strstr(buf, " edsp");
171 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) {
174 #endif /* HAVE_EDSP */
175 #if HAVE_NEON || HAVE_NEON_ASM
176 p = strstr(buf, " neon");
177 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) {
180 #endif /* HAVE_NEON || HAVE_NEON_ASM */
182 #endif /* HAVE_EDSP || HAVE_NEON || HAVE_NEON_ASM */
184 if (memcmp(buf, "CPU architecture:", 17) == 0) {
186 version = atoi(buf + 17);
191 #endif /* HAVE_MEDIA */
197 #else /* end __linux__ */
198 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \
199 "available for your platform. Reconfigure with --disable-runtime-cpu-detect."