Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: webrtc/system_wrappers/source/cpu_features_linux.c

Issue 1820133002: Implement CPU feature detection for ARM Linux. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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.
9 */
10
11 #include <stdlib.h>
12 #include <string.h>
13 #include <features.h>
14 #include <asm/hwcap.h>
15 #if __GLIBC_PREREQ(2, 16)
16 #include <sys/auxv.h>
17 #else
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <errno.h>
21 #include <link.h>
22 #endif
23 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
24
25 #if defined(WEBRTC_ARCH_ARM_FAMILY)
26 uint64_t WebRtc_GetCPUFeaturesARM(void) {
27 uint64_t result = 0;
28 int architecture = 0;
29 unsigned long hwcap = 0;
30 const char* platform = NULL;
31 #if __GLIBC_PREREQ(2, 16)
32 hwcap = getauxval(AT_HWCAP);
33 platform = (const char*)getauxval(AT_PLATFORM);
34 #else
35 ElfW(auxv_t) auxv;
36 int fd = open("/proc/self/auxv", O_RDONLY);
37 if (fd >= 0) {
38 while ((hwcap == 0) || (platform == NULL)) {
39 if (read(fd, &auxv, sizeof(auxv)) < sizeof(auxv)) {
40 if (errno == EINTR) continue;
41 break;
42 }
43 switch (auxv.a_type) {
44 case AT_HWCAP:
45 hwcap = auxv.a_un.a_val;
46 break;
47 case AT_PLATFORM:
48 platform = (const char*)auxv.a_un.a_val;
49 break;
50 default:
51 (void)auxv.a_un.a_val;
52 break;
53 }
54 }
55 close(fd);
56 }
57 #endif // __GLIBC_PREREQ(2,16)
58 #if defined(__aarch64__)
59 architecture = 8;
60 if ((hwcap & HWCAP_FP) != 0) result |= kCPUFeatureVFPv3;
61 if ((hwcap & HWCAP_ASIMD) != 0) result |= kCPUFeatureNEON;
62 #else
63 if (platform != NULL) {
64 /* expect a string in the form "v6l" or "v7l", etc.
65 */
66 if ((platform[0] == 'v') &&
67 ('0' <= platform[1]) && (platform[1] <= '9')) {
68 architecture = atoi(platform + 1);
69 }
70 }
71 if ((hwcap & HWCAP_VFPv3) != 0) result |= kCPUFeatureVFPv3;
72 if ((hwcap & HWCAP_NEON) != 0) result |= kCPUFeatureNEON;
73 #endif
74 if (architecture >= 7) result |= kCPUFeatureARMv7;
75 if (architecture >= 6) result |= kCPUFeatureLDREXSTREX;
76 return result;
77 }
78 #endif // WEBRTC_ARCH_ARM_FAMILY
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698