Index: webrtc/system_wrappers/source/cpu_features_linux.c |
diff --git a/webrtc/system_wrappers/source/cpu_features_linux.c b/webrtc/system_wrappers/source/cpu_features_linux.c |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9a1dd4aee029665d0aef52849b8264e97285420e |
--- /dev/null |
+++ b/webrtc/system_wrappers/source/cpu_features_linux.c |
@@ -0,0 +1,79 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include <stdlib.h> |
+#include <string.h> |
+#include <features.h> |
+#if __GLIBC_PREREQ(2, 16) |
+#include <sys/auxv.h> |
+#else |
+#include <fcntl.h> |
+#include <unistd.h> |
+#include <errno.h> |
+#include <link.h> |
+#endif |
+#include "webrtc/system_wrappers/include/cpu_features_wrapper.h" |
+ |
+#if defined(WEBRTC_ARCH_ARM_FAMILY) |
+#include <asm/hwcap.h> |
+ |
+uint64_t WebRtc_GetCPUFeaturesARM(void) { |
+ uint64_t result = 0; |
+ int architecture = 0; |
+ unsigned long hwcap = 0; |
+ const char* platform = NULL; |
+#if __GLIBC_PREREQ(2, 16) |
+ hwcap = getauxval(AT_HWCAP); |
+ platform = (const char*)getauxval(AT_PLATFORM); |
+#else |
+ ElfW(auxv_t) auxv; |
+ int fd = open("/proc/self/auxv", O_RDONLY); |
+ if (fd >= 0) { |
+ while ((hwcap == 0) || (platform == NULL)) { |
torbjorng (webrtc)
2016/04/04 08:35:42
We don't usually use redundant parentheses.
Simon Hosie
2016/04/05 01:15:48
Done.
|
+ if (read(fd, &auxv, sizeof(auxv)) < sizeof(auxv)) { |
+ if (errno == EINTR) continue; |
+ break; |
+ } |
+ switch (auxv.a_type) { |
+ case AT_HWCAP: |
+ hwcap = auxv.a_un.a_val; |
+ break; |
+ case AT_PLATFORM: |
+ platform = (const char*)auxv.a_un.a_val; |
+ break; |
+ default: |
+ (void)auxv.a_un.a_val; |
torbjorng (webrtc)
2016/04/04 08:35:42
Please remove this.
Simon Hosie
2016/04/05 01:15:48
Done.
|
+ break; |
+ } |
+ } |
+ close(fd); |
+ } |
+#endif // __GLIBC_PREREQ(2,16) |
+#if defined(__aarch64__) |
+ architecture = 8; |
+ if ((hwcap & HWCAP_FP) != 0) result |= kCPUFeatureVFPv3; |
+ if ((hwcap & HWCAP_ASIMD) != 0) result |= kCPUFeatureNEON; |
+#else |
+ if (platform != NULL) { |
+ /* expect a string in the form "v6l" or "v7l", etc. |
+ */ |
+ if ((platform[0] == 'v') && |
+ ('0' <= platform[1]) && (platform[1] <= '9')) { |
+ architecture = atoi(platform + 1); |
torbjorng (webrtc)
2016/04/04 08:35:42
If the |platform| string end up not being 0-termin
Simon Hosie
2016/04/05 01:15:48
getauxval() defines `platform` as a pointer to a s
|
+ } |
+ } |
+ if ((hwcap & HWCAP_VFPv3) != 0) result |= kCPUFeatureVFPv3; |
+ if ((hwcap & HWCAP_NEON) != 0) result |= kCPUFeatureNEON; |
+#endif |
+ if (architecture >= 7) result |= kCPUFeatureARMv7; |
torbjorng (webrtc)
2016/04/04 08:35:42
This code will not detect CPU archs properly if th
Simon Hosie
2016/04/05 01:15:48
Reading just one digit makes "v10" less than "v7".
|
+ if (architecture >= 6) result |= kCPUFeatureLDREXSTREX; |
+ return result; |
+} |
+#endif // WEBRTC_ARCH_ARM_FAMILY |