OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <string.h> | 12 #include <string.h> |
13 #include "arm.h" | 13 #include "vpx_ports/arm.h" |
| 14 #include "./vpx_config.h" |
14 | 15 |
15 #ifdef WINAPI_FAMILY | 16 #ifdef WINAPI_FAMILY |
16 #include <winapifamily.h> | 17 #include <winapifamily.h> |
17 #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) | 18 #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) |
18 #define getenv(x) NULL | 19 #define getenv(x) NULL |
19 #endif | 20 #endif |
20 #endif | 21 #endif |
21 | 22 |
22 static int arm_cpu_env_flags(int *flags) { | 23 static int arm_cpu_env_flags(int *flags) { |
23 char *env; | 24 char *env; |
(...skipping 23 matching lines...) Expand all Loading... |
47 if (!arm_cpu_env_flags(&flags)) { | 48 if (!arm_cpu_env_flags(&flags)) { |
48 return flags; | 49 return flags; |
49 } | 50 } |
50 mask = arm_cpu_env_mask(); | 51 mask = arm_cpu_env_mask(); |
51 #if HAVE_EDSP | 52 #if HAVE_EDSP |
52 flags |= HAS_EDSP; | 53 flags |= HAS_EDSP; |
53 #endif /* HAVE_EDSP */ | 54 #endif /* HAVE_EDSP */ |
54 #if HAVE_MEDIA | 55 #if HAVE_MEDIA |
55 flags |= HAS_MEDIA; | 56 flags |= HAS_MEDIA; |
56 #endif /* HAVE_MEDIA */ | 57 #endif /* HAVE_MEDIA */ |
57 #if HAVE_NEON | 58 #if HAVE_NEON || HAVE_NEON_ASM |
58 flags |= HAS_NEON; | 59 flags |= HAS_NEON; |
59 #endif /* HAVE_NEON */ | 60 #endif /* HAVE_NEON || HAVE_NEON_ASM */ |
60 return flags & mask; | 61 return flags & mask; |
61 } | 62 } |
62 | 63 |
63 #elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT */ | 64 #elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT */ |
64 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/ | 65 /*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/ |
65 #define WIN32_LEAN_AND_MEAN | 66 #define WIN32_LEAN_AND_MEAN |
66 #define WIN32_EXTRA_LEAN | 67 #define WIN32_EXTRA_LEAN |
67 #include <windows.h> | 68 #include <windows.h> |
68 | 69 |
69 int arm_cpu_caps(void) { | 70 int arm_cpu_caps(void) { |
(...skipping 10 matching lines...) Expand all Loading... |
80 #if HAVE_EDSP | 81 #if HAVE_EDSP |
81 if (mask & HAS_EDSP) { | 82 if (mask & HAS_EDSP) { |
82 __try { | 83 __try { |
83 /*PLD [r13]*/ | 84 /*PLD [r13]*/ |
84 __emit(0xF5DDF000); | 85 __emit(0xF5DDF000); |
85 flags |= HAS_EDSP; | 86 flags |= HAS_EDSP; |
86 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) { | 87 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) { |
87 /*Ignore exception.*/ | 88 /*Ignore exception.*/ |
88 } | 89 } |
89 } | 90 } |
| 91 #endif /* HAVE_EDSP */ |
90 #if HAVE_MEDIA | 92 #if HAVE_MEDIA |
91 if (mask & HAS_MEDIA) | 93 if (mask & HAS_MEDIA) |
92 __try { | 94 __try { |
93 /*SHADD8 r3,r3,r3*/ | 95 /*SHADD8 r3,r3,r3*/ |
94 __emit(0xE6333F93); | 96 __emit(0xE6333F93); |
95 flags |= HAS_MEDIA; | 97 flags |= HAS_MEDIA; |
96 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) { | 98 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) { |
97 /*Ignore exception.*/ | 99 /*Ignore exception.*/ |
98 } | 100 } |
99 } | 101 } |
100 #if HAVE_NEON | 102 #endif /* HAVE_MEDIA */ |
| 103 #if HAVE_NEON || HAVE_NEON_ASM |
101 if (mask &HAS_NEON) { | 104 if (mask &HAS_NEON) { |
102 __try { | 105 __try { |
103 /*VORR q0,q0,q0*/ | 106 /*VORR q0,q0,q0*/ |
104 __emit(0xF2200150); | 107 __emit(0xF2200150); |
105 flags |= HAS_NEON; | 108 flags |= HAS_NEON; |
106 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) { | 109 } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) { |
107 /*Ignore exception.*/ | 110 /*Ignore exception.*/ |
108 } | 111 } |
109 } | 112 } |
110 #endif /* HAVE_NEON */ | 113 #endif /* HAVE_NEON || HAVE_NEON_ASM */ |
111 #endif /* HAVE_MEDIA */ | |
112 #endif /* HAVE_EDSP */ | |
113 return flags & mask; | 114 return flags & mask; |
114 } | 115 } |
115 | 116 |
116 #elif defined(__ANDROID__) /* end _MSC_VER */ | 117 #elif defined(__ANDROID__) /* end _MSC_VER */ |
117 #include <cpu-features.h> | 118 #include <cpu-features.h> |
118 | 119 |
119 int arm_cpu_caps(void) { | 120 int arm_cpu_caps(void) { |
120 int flags; | 121 int flags; |
121 int mask; | 122 int mask; |
122 uint64_t features; | 123 uint64_t features; |
123 if (!arm_cpu_env_flags(&flags)) { | 124 if (!arm_cpu_env_flags(&flags)) { |
124 return flags; | 125 return flags; |
125 } | 126 } |
126 mask = arm_cpu_env_mask(); | 127 mask = arm_cpu_env_mask(); |
127 features = android_getCpuFeatures(); | 128 features = android_getCpuFeatures(); |
128 | 129 |
129 #if HAVE_EDSP | 130 #if HAVE_EDSP |
130 flags |= HAS_EDSP; | 131 flags |= HAS_EDSP; |
131 #endif /* HAVE_EDSP */ | 132 #endif /* HAVE_EDSP */ |
132 #if HAVE_MEDIA | 133 #if HAVE_MEDIA |
133 flags |= HAS_MEDIA; | 134 flags |= HAS_MEDIA; |
134 #endif /* HAVE_MEDIA */ | 135 #endif /* HAVE_MEDIA */ |
135 #if HAVE_NEON | 136 #if HAVE_NEON || HAVE_NEON_ASM |
136 if (features & ANDROID_CPU_ARM_FEATURE_NEON) | 137 if (features & ANDROID_CPU_ARM_FEATURE_NEON) |
137 flags |= HAS_NEON; | 138 flags |= HAS_NEON; |
138 #endif /* HAVE_NEON */ | 139 #endif /* HAVE_NEON || HAVE_NEON_ASM */ |
139 return flags & mask; | 140 return flags & mask; |
140 } | 141 } |
141 | 142 |
142 #elif defined(__linux__) /* end __ANDROID__ */ | 143 #elif defined(__linux__) /* end __ANDROID__ */ |
143 | 144 |
144 #include <stdio.h> | 145 #include <stdio.h> |
145 | 146 |
146 int arm_cpu_caps(void) { | 147 int arm_cpu_caps(void) { |
147 FILE *fin; | 148 FILE *fin; |
148 int flags; | 149 int flags; |
149 int mask; | 150 int mask; |
150 if (!arm_cpu_env_flags(&flags)) { | 151 if (!arm_cpu_env_flags(&flags)) { |
151 return flags; | 152 return flags; |
152 } | 153 } |
153 mask = arm_cpu_env_mask(); | 154 mask = arm_cpu_env_mask(); |
154 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably | 155 /* Reading /proc/self/auxv would be easier, but that doesn't work reliably |
155 * on Android. | 156 * on Android. |
156 * This also means that detection will fail in Scratchbox. | 157 * This also means that detection will fail in Scratchbox. |
157 */ | 158 */ |
158 fin = fopen("/proc/cpuinfo", "r"); | 159 fin = fopen("/proc/cpuinfo", "r"); |
159 if (fin != NULL) { | 160 if (fin != NULL) { |
160 /* 512 should be enough for anybody (it's even enough for all the flags | 161 /* 512 should be enough for anybody (it's even enough for all the flags |
161 * that x86 has accumulated... so far). | 162 * that x86 has accumulated... so far). |
162 */ | 163 */ |
163 char buf[512]; | 164 char buf[512]; |
164 while (fgets(buf, 511, fin) != NULL) { | 165 while (fgets(buf, 511, fin) != NULL) { |
165 #if HAVE_EDSP || HAVE_NEON | 166 #if HAVE_EDSP || HAVE_NEON || HAVE_NEON_ASM |
166 if (memcmp(buf, "Features", 8) == 0) { | 167 if (memcmp(buf, "Features", 8) == 0) { |
167 char *p; | 168 char *p; |
168 #if HAVE_EDSP | 169 #if HAVE_EDSP |
169 p = strstr(buf, " edsp"); | 170 p = strstr(buf, " edsp"); |
170 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) { | 171 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) { |
171 flags |= HAS_EDSP; | 172 flags |= HAS_EDSP; |
172 } | 173 } |
173 #if HAVE_NEON | 174 #endif /* HAVE_EDSP */ |
| 175 #if HAVE_NEON || HAVE_NEON_ASM |
174 p = strstr(buf, " neon"); | 176 p = strstr(buf, " neon"); |
175 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) { | 177 if (p != NULL && (p[5] == ' ' || p[5] == '\n')) { |
176 flags |= HAS_NEON; | 178 flags |= HAS_NEON; |
177 } | 179 } |
178 #endif /* HAVE_NEON */ | 180 #endif /* HAVE_NEON || HAVE_NEON_ASM */ |
179 #endif /* HAVE_EDSP */ | |
180 } | 181 } |
181 #endif /* HAVE_EDSP || HAVE_NEON */ | 182 #endif /* HAVE_EDSP || HAVE_NEON || HAVE_NEON_ASM */ |
182 #if HAVE_MEDIA | 183 #if HAVE_MEDIA |
183 if (memcmp(buf, "CPU architecture:", 17) == 0) { | 184 if (memcmp(buf, "CPU architecture:", 17) == 0) { |
184 int version; | 185 int version; |
185 version = atoi(buf + 17); | 186 version = atoi(buf + 17); |
186 if (version >= 6) { | 187 if (version >= 6) { |
187 flags |= HAS_MEDIA; | 188 flags |= HAS_MEDIA; |
188 } | 189 } |
189 } | 190 } |
190 #endif /* HAVE_MEDIA */ | 191 #endif /* HAVE_MEDIA */ |
191 } | 192 } |
192 fclose(fin); | 193 fclose(fin); |
193 } | 194 } |
194 return flags & mask; | 195 return flags & mask; |
195 } | 196 } |
196 #else /* end __linux__ */ | 197 #else /* end __linux__ */ |
197 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \ | 198 #error "--enable-runtime-cpu-detect selected, but no CPU detection method " \ |
198 "available for your platform. Reconfigure with --disable-runtime-cpu-detect." | 199 "available for your platform. Reconfigure with --disable-runtime-cpu-detect." |
199 #endif | 200 #endif |
OLD | NEW |