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_ARMV5TE)
64 __except(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
)
69 #if defined(HAVE_ARMV6)
77 __except(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
)
82 #if defined(HAVE_ARMV7)
91 __except(GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
)
102 #elif defined(__linux__)
105 int arm_cpu_caps(void)
110 if (!arm_cpu_env_flags(&flags
))
114 mask
= arm_cpu_env_mask();
115 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably
117 * This also means that detection will fail in Scratchbox.
119 fin
= fopen("/proc/cpuinfo","r");
122 /* 512 should be enough for anybody (it's even enough for all the flags
123 * that x86 has accumulated... so far).
126 while (fgets(buf
, 511, fin
) != NULL
)
128 #if defined(HAVE_ARMV5TE) || defined(HAVE_ARMV7)
129 if (memcmp(buf
, "Features", 8) == 0)
132 #if defined(HAVE_ARMV5TE)
133 p
=strstr(buf
, " edsp");
134 if (p
!= NULL
&& (p
[5] == ' ' || p
[5] == '\n'))
138 #if defined(HAVE_ARMV7)
139 p
= strstr(buf
, " neon");
140 if (p
!= NULL
&& (p
[5] == ' ' || p
[5] == '\n'))
148 #if defined(HAVE_ARMV6)
149 if (memcmp(buf
, "CPU architecture:",17) == 0){
151 version
= atoi(buf
+17);
164 #elif !CONFIG_RUNTIME_CPU_DETECT
166 int arm_cpu_caps(void)
170 if (!arm_cpu_env_flags(&flags
))
174 mask
= arm_cpu_env_mask();
175 #if defined(HAVE_ARMV5TE)
178 #if defined(HAVE_ARMV6)
181 #if defined(HAVE_ARMV7)
188 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \
189 "available for your platform. Reconfigure without --enable-runtime-cpu-detect."