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)
18 env = getenv("VPX_SIMD_CAPS");
21 *flags = (int)strtol(env, NULL, 0);
28 static int arm_cpu_env_mask(void)
31 env = getenv("VPX_SIMD_CAPS_MASK");
32 return env && *env ? (int)strtol(env, NULL, 0) : ~0;
35 #if !CONFIG_RUNTIME_CPU_DETECT
37 int arm_cpu_caps(void)
39 /* This function should actually be a no-op. There is no way to adjust any of
40 * these because the RTCD tables do not exist: the functions are called
44 if (!arm_cpu_env_flags(&flags))
48 mask = arm_cpu_env_mask();
51 #endif /* HAVE_EDSP */
54 #endif /* HAVE_MEDIA */
57 #endif /* HAVE_NEON */
61 #elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT */
62 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
63 #define WIN32_LEAN_AND_MEAN
64 #define WIN32_EXTRA_LEAN
67 int arm_cpu_caps(void)
71 if (!arm_cpu_env_flags(&flags))
75 mask = arm_cpu_env_mask();
76 /* MSVC has no inline __asm support for ARM, but it does let you __emit
77 * instructions via their assembled hex code.
78 * All of these instructions should be essentially nops.
89 __except(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION)
102 __except(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION)
104 /*Ignore exception.*/
116 __except(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION)
118 /*Ignore exception.*/
121 #endif /* HAVE_NEON */
122 #endif /* HAVE_MEDIA */
123 #endif /* HAVE_EDSP */
127 #elif defined(__ANDROID__) /* end _MSC_VER */
128 #include <cpu-features.h>
130 int arm_cpu_caps(void)
135 if (!arm_cpu_env_flags(&flags))
139 mask = arm_cpu_env_mask();
140 features = android_getCpuFeatures();
144 #endif /* HAVE_EDSP */
147 #endif /* HAVE_MEDIA */
149 if (features & ANDROID_CPU_ARM_FEATURE_NEON)
151 #endif /* HAVE_NEON */
155 #elif defined(__linux__) /* end __ANDROID__ */
158 int arm_cpu_caps(void)
163 if (!arm_cpu_env_flags(&flags))
167 mask = arm_cpu_env_mask();
168 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
170 * This also means that detection will fail in Scratchbox.
172 fin = fopen("/proc/cpuinfo","r");
175 /* 512 should be enough for anybody (it's even enough for all the flags
176 * that x86 has accumulated... so far).
179 while (fgets(buf, 511, fin) != NULL)
181 #if HAVE_EDSP || HAVE_NEON
182 if (memcmp(buf, "Features", 8) == 0)
186 p=strstr(buf, " edsp");
187 if (p != NULL && (p[5] == ' ' || p[5] == '\n'))
192 p = strstr(buf, " neon");
193 if (p != NULL && (p[5] == ' ' || p[5] == '\n'))
197 #endif /* HAVE_NEON */
198 #endif /* HAVE_EDSP */
200 #endif /* HAVE_EDSP || HAVE_NEON */
202 if (memcmp(buf, "CPU architecture:",17) == 0){
204 version = atoi(buf+17);
210 #endif /* HAVE_MEDIA */
216 #else /* end __linux__ */
217 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \
218 "available for your platform. Reconfigure with --disable-runtime-cpu-detect."