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.
15 static int arm_cpu_env_flags(int *flags) {
17 env = getenv("VPX_SIMD_CAPS");
19 *flags = (int)strtol(env, NULL, 0);
26 static int arm_cpu_env_mask(void) {
28 env = getenv("VPX_SIMD_CAPS_MASK");
29 return env && *env ? (int)strtol(env, NULL, 0) : ~0;
32 #if !CONFIG_RUNTIME_CPU_DETECT
34 int arm_cpu_caps(void) {
35 /* This function should actually be a no-op. There is no way to adjust any of
36 * these because the RTCD tables do not exist: the functions are called
40 if (!arm_cpu_env_flags(&flags)) {
43 mask = arm_cpu_env_mask();
46 #endif /* HAVE_EDSP */
49 #endif /* HAVE_MEDIA */
52 #endif /* HAVE_NEON */
56 #elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT */
58 #elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT */
59 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
60 #define WIN32_LEAN_AND_MEAN
61 #define WIN32_EXTRA_LEAN
64 int arm_cpu_caps(void) {
67 if (!arm_cpu_env_flags(&flags)) {
70 mask = arm_cpu_env_mask();
71 /* MSVC has no inline __asm support for ARM, but it does let you __emit
72 * instructions via their assembled hex code.
73 * All of these instructions should be essentially nops.
76 if (mask & HAS_EDSP) {
81 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
91 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
101 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
102 /*Ignore exception.*/
105 #endif /* HAVE_NEON */
106 #endif /* HAVE_MEDIA */
107 #endif /* HAVE_EDSP */
111 #elif defined(__ANDROID__) /* end _MSC_VER */
112 #include <cpu-features.h>
114 int arm_cpu_caps(void) {
118 if (!arm_cpu_env_flags(&flags)) {
121 mask = arm_cpu_env_mask();
122 features = android_getCpuFeatures();
126 #endif /* HAVE_EDSP */
129 #endif /* HAVE_MEDIA */
131 if (features & ANDROID_CPU_ARM_FEATURE_NEON)
133 #endif /* HAVE_NEON */
137 #elif defined(__linux__) /* end __ANDROID__ */
141 int arm_cpu_caps(void) {
145 if (!arm_cpu_env_flags(&flags)) {
148 mask = arm_cpu_env_mask();
149 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
151 * This also means that detection will fail in Scratchbox.
153 fin = fopen("/proc/cpuinfo", "r");
155 /* 512 should be enough for anybody (it's even enough for all the flags
156 * that x86 has accumulated... so far).
159 while (fgets(buf, 511, fin) != NULL) {
160 #if HAVE_EDSP || HAVE_NEON
161 if (memcmp(buf, "Features", 8) == 0) {
164 p = strstr(buf, " edsp");
165 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) {
169 p = strstr(buf, " neon");
170 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) {
173 #endif /* HAVE_NEON */
174 #endif /* HAVE_EDSP */
176 #endif /* HAVE_EDSP || HAVE_NEON */
178 if (memcmp(buf, "CPU architecture:", 17) == 0) {
180 version = atoi(buf + 17);
185 #endif /* HAVE_MEDIA */
191 #else /* end __linux__ */
192 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \
193 "available for your platform. Reconfigure with --disable-runtime-cpu-detect."