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 */
57 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
58 #define WIN32_LEAN_AND_MEAN
59 #define WIN32_EXTRA_LEAN
62 int arm_cpu_caps(void) {
65 if (!arm_cpu_env_flags(&flags)) {
68 mask = arm_cpu_env_mask();
69 /* MSVC has no inline __asm support for ARM, but it does let you __emit
70 * instructions via their assembled hex code.
71 * All of these instructions should be essentially nops.
74 if (mask & HAS_EDSP) {
79 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
89 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
99 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
100 /*Ignore exception.*/
103 #endif /* HAVE_NEON */
104 #endif /* HAVE_MEDIA */
105 #endif /* HAVE_EDSP */
109 #elif defined(__ANDROID__) /* end _MSC_VER */
110 #include <cpu-features.h>
112 int arm_cpu_caps(void) {
116 if (!arm_cpu_env_flags(&flags)) {
119 mask = arm_cpu_env_mask();
120 features = android_getCpuFeatures();
124 #endif /* HAVE_EDSP */
127 #endif /* HAVE_MEDIA */
129 if (features & ANDROID_CPU_ARM_FEATURE_NEON)
131 #endif /* HAVE_NEON */
135 #elif defined(__linux__) /* end __ANDROID__ */
139 int arm_cpu_caps(void) {
143 if (!arm_cpu_env_flags(&flags)) {
146 mask = arm_cpu_env_mask();
147 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
149 * This also means that detection will fail in Scratchbox.
151 fin = fopen("/proc/cpuinfo", "r");
153 /* 512 should be enough for anybody (it's even enough for all the flags
154 * that x86 has accumulated... so far).
157 while (fgets(buf, 511, fin) != NULL) {
158 #if HAVE_EDSP || HAVE_NEON
159 if (memcmp(buf, "Features", 8) == 0) {
162 p = strstr(buf, " edsp");
163 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) {
167 p = strstr(buf, " neon");
168 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) {
171 #endif /* HAVE_NEON */
172 #endif /* HAVE_EDSP */
174 #endif /* HAVE_EDSP || HAVE_NEON */
176 if (memcmp(buf, "CPU architecture:", 17) == 0) {
178 version = atoi(buf + 17);
183 #endif /* HAVE_MEDIA */
189 #else /* end __linux__ */
190 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \
191 "available for your platform. Reconfigure with --disable-runtime-cpu-detect."