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.
14 #include "./vpx_config.h"
15 #include "vpx_ports/arm.h"
18 #include <winapifamily.h>
19 #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
20 #define getenv(x) NULL
24 static int arm_cpu_env_flags(int *flags) {
26 env = getenv("VPX_SIMD_CAPS");
28 *flags = (int)strtol(env, NULL, 0);
35 static int arm_cpu_env_mask(void) {
37 env = getenv("VPX_SIMD_CAPS_MASK");
38 return env && *env ? (int)strtol(env, NULL, 0) : ~0;
41 #if !CONFIG_RUNTIME_CPU_DETECT
43 int arm_cpu_caps(void) {
44 /* This function should actually be a no-op. There is no way to adjust any of
45 * these because the RTCD tables do not exist: the functions are called
49 if (!arm_cpu_env_flags(&flags)) {
52 mask = arm_cpu_env_mask();
53 #if HAVE_NEON || HAVE_NEON_ASM
55 #endif /* HAVE_NEON || HAVE_NEON_ASM */
59 #elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT */
60 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
61 #ifndef WIN32_LEAN_AND_MEAN
62 #define WIN32_LEAN_AND_MEAN
64 #ifndef WIN32_EXTRA_LEAN
65 #define WIN32_EXTRA_LEAN
69 int arm_cpu_caps(void) {
72 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.
80 #if HAVE_NEON || HAVE_NEON_ASM
81 if (mask & HAS_NEON) {
86 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) {
90 #endif /* HAVE_NEON || HAVE_NEON_ASM */
94 #elif defined(__ANDROID__) /* end _MSC_VER */
95 #include <cpu-features.h>
97 int arm_cpu_caps(void) {
101 if (!arm_cpu_env_flags(&flags)) {
104 mask = arm_cpu_env_mask();
105 features = android_getCpuFeatures();
107 #if HAVE_NEON || HAVE_NEON_ASM
108 if (features & ANDROID_CPU_ARM_FEATURE_NEON) flags |= HAS_NEON;
109 #endif /* HAVE_NEON || HAVE_NEON_ASM */
113 #elif defined(__linux__) /* end __ANDROID__ */
117 int arm_cpu_caps(void) {
121 if (!arm_cpu_env_flags(&flags)) {
124 mask = arm_cpu_env_mask();
125 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
127 * This also means that detection will fail in Scratchbox.
129 fin = fopen("/proc/cpuinfo", "r");
131 /* 512 should be enough for anybody (it's even enough for all the flags
132 * that x86 has accumulated... so far).
135 while (fgets(buf, 511, fin) != NULL) {
136 #if HAVE_NEON || HAVE_NEON_ASM
137 if (memcmp(buf, "Features", 8) == 0) {
139 p = strstr(buf, " neon");
140 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) {
144 #endif /* HAVE_NEON || HAVE_NEON_ASM */
150 #else /* end __linux__ */
152 "--enable-runtime-cpu-detect selected, but no CPU detection method " \
153 "available for your platform. Reconfigure with --disable-runtime-cpu-detect."