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;
37 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
38 #define WIN32_LEAN_AND_MEAN
39 #define WIN32_EXTRA_LEAN
42 int arm_cpu_caps(void)
46 if (!arm_cpu_env_flags(&flags))
50 mask = arm_cpu_env_mask();
51 /* MSVC has no inline __asm support for ARM, but it does let you __emit
52 * instructions via their assembled hex code.
53 * All of these instructions should be essentially nops.
55 #if defined(HAVE_EDSP)
64 __except(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION)
69 #if defined(HAVE_MEDIA)
77 __except(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION)
82 #if defined(HAVE_NEON)
91 __except(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION)
102 #elif defined(__linux__)
103 #if defined(__ANDROID__)
104 #include <cpu-features.h>
106 int arm_cpu_caps(void)
111 if (!arm_cpu_env_flags(&flags))
115 mask = arm_cpu_env_mask();
116 features = android_getCpuFeatures();
118 #if defined(HAVE_EDSP)
121 #if defined(HAVE_MEDIA)
124 #if defined(HAVE_NEON)
125 if (features & ANDROID_CPU_ARM_FEATURE_NEON)
130 #else // !defined(__ANDROID__)
133 int arm_cpu_caps(void)
138 if (!arm_cpu_env_flags(&flags))
142 mask = arm_cpu_env_mask();
143 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
145 * This also means that detection will fail in Scratchbox.
147 fin = fopen("/proc/cpuinfo","r");
150 /* 512 should be enough for anybody (it's even enough for all the flags
151 * that x86 has accumulated... so far).
154 while (fgets(buf, 511, fin) != NULL)
156 #if defined(HAVE_EDSP) || defined(HAVE_NEON)
157 if (memcmp(buf, "Features", 8) == 0)
160 #if defined(HAVE_EDSP)
161 p=strstr(buf, " edsp");
162 if (p != NULL && (p[5] == ' ' || p[5] == '\n'))
166 #if defined(HAVE_NEON)
167 p = strstr(buf, " neon");
168 if (p != NULL && (p[5] == ' ' || p[5] == '\n'))
176 #if defined(HAVE_MEDIA)
177 if (memcmp(buf, "CPU architecture:",17) == 0){
179 version = atoi(buf+17);
191 #endif // defined(__linux__)
192 #elif !CONFIG_RUNTIME_CPU_DETECT
194 int arm_cpu_caps(void)
198 if (!arm_cpu_env_flags(&flags))
202 mask = arm_cpu_env_mask();
203 #if defined(HAVE_EDSP)
206 #if defined(HAVE_MEDIA)
209 #if defined(HAVE_NEON)
216 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \
217 "available for your platform. Reconfigure without --enable-runtime-cpu-detect."