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_MEDIA */
55 #if HAVE_NEON || HAVE_NEON_ASM
57 #endif /* HAVE_NEON || HAVE_NEON_ASM */
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) {
70 if (!arm_cpu_env_flags(&flags)) {
73 mask = arm_cpu_env_mask();
74 /* MSVC has no inline __asm support for ARM, but it does let you __emit
75 * instructions via their assembled hex code.
76 * All of these instructions should be essentially nops.
84 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
88 #endif /* HAVE_MEDIA */
89 #if HAVE_NEON || HAVE_NEON_ASM
95 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
99 #endif /* HAVE_NEON || HAVE_NEON_ASM */
103 #elif defined(__ANDROID__) /* end _MSC_VER */
104 #include <cpu-features.h>
106 int arm_cpu_caps(void) {
110 if (!arm_cpu_env_flags(&flags)) {
113 mask = arm_cpu_env_mask();
114 features = android_getCpuFeatures();
118 #endif /* HAVE_MEDIA */
119 #if HAVE_NEON || HAVE_NEON_ASM
120 if (features & ANDROID_CPU_ARM_FEATURE_NEON)
122 #endif /* HAVE_NEON || HAVE_NEON_ASM */
126 #elif defined(__linux__) /* end __ANDROID__ */
130 int arm_cpu_caps(void) {
134 if (!arm_cpu_env_flags(&flags)) {
137 mask = arm_cpu_env_mask();
138 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
140 * This also means that detection will fail in Scratchbox.
142 fin = fopen("/proc/cpuinfo", "r");
144 /* 512 should be enough for anybody (it's even enough for all the flags
145 * that x86 has accumulated... so far).
148 while (fgets(buf, 511, fin) != NULL) {
149 #if HAVE_NEON || HAVE_NEON_ASM
150 if (memcmp(buf, "Features", 8) == 0) {
152 p = strstr(buf, " neon");
153 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) {
157 #endif /* HAVE_NEON || HAVE_NEON_ASM */
159 if (memcmp(buf, "CPU architecture:", 17) == 0) {
161 version = atoi(buf + 17);
166 #endif /* HAVE_MEDIA */
172 #else /* end __linux__ */
173 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \
174 "available for your platform. Reconfigure with --disable-runtime-cpu-detect."