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.
16 #include <winapifamily.h>
17 #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
18 #define getenv(x) NULL
22 static int arm_cpu_env_flags(int *flags
) {
24 env
= getenv("VPX_SIMD_CAPS");
26 *flags
= (int)strtol(env
, NULL
, 0);
33 static int arm_cpu_env_mask(void) {
35 env
= getenv("VPX_SIMD_CAPS_MASK");
36 return env
&& *env
? (int)strtol(env
, NULL
, 0) : ~0;
39 #if !CONFIG_RUNTIME_CPU_DETECT
41 int arm_cpu_caps(void) {
42 /* This function should actually be a no-op. There is no way to adjust any of
43 * these because the RTCD tables do not exist: the functions are called
47 if (!arm_cpu_env_flags(&flags
)) {
50 mask
= arm_cpu_env_mask();
53 #endif /* HAVE_EDSP */
56 #endif /* HAVE_MEDIA */
59 #endif /* HAVE_NEON */
63 #elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT */
64 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
65 #define WIN32_LEAN_AND_MEAN
66 #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.
81 if (mask
& HAS_EDSP
) {
86 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
) {
96 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
) {
101 if (mask
&HAS_NEON
) {
106 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
) {
107 /*Ignore exception.*/
110 #endif /* HAVE_NEON */
111 #endif /* HAVE_MEDIA */
112 #endif /* HAVE_EDSP */
116 #elif defined(__ANDROID__) /* end _MSC_VER */
117 #include <cpu-features.h>
119 int arm_cpu_caps(void) {
123 if (!arm_cpu_env_flags(&flags
)) {
126 mask
= arm_cpu_env_mask();
127 features
= android_getCpuFeatures();
131 #endif /* HAVE_EDSP */
134 #endif /* HAVE_MEDIA */
136 if (features
& ANDROID_CPU_ARM_FEATURE_NEON
)
138 #endif /* HAVE_NEON */
142 #elif defined(__linux__) /* end __ANDROID__ */
146 int arm_cpu_caps(void) {
150 if (!arm_cpu_env_flags(&flags
)) {
153 mask
= arm_cpu_env_mask();
154 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
156 * This also means that detection will fail in Scratchbox.
158 fin
= fopen("/proc/cpuinfo", "r");
160 /* 512 should be enough for anybody (it's even enough for all the flags
161 * that x86 has accumulated... so far).
164 while (fgets(buf
, 511, fin
) != NULL
) {
165 #if HAVE_EDSP || HAVE_NEON
166 if (memcmp(buf
, "Features", 8) == 0) {
169 p
= strstr(buf
, " edsp");
170 if (p
!= NULL
&& (p
[5] == ' ' || p
[5] == '\n')) {
174 p
= strstr(buf
, " neon");
175 if (p
!= NULL
&& (p
[5] == ' ' || p
[5] == '\n')) {
178 #endif /* HAVE_NEON */
179 #endif /* HAVE_EDSP */
181 #endif /* HAVE_EDSP || HAVE_NEON */
183 if (memcmp(buf
, "CPU architecture:", 17) == 0) {
185 version
= atoi(buf
+ 17);
190 #endif /* HAVE_MEDIA */
196 #else /* end __linux__ */
197 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \
198 "available for your platform. Reconfigure with --disable-runtime-cpu-detect."