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

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: GN correction, dead file removal, formatting, stricter string structure test for AT_PLATFORM. Created 4 years, 8 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 #if __GLIBC_PREREQ(2, 16)
15 #include <sys/auxv.h>
16 #else
17 #include <fcntl.h>
18 #include <unistd.h>
19 #include <errno.h>
20 #include <link.h>
21 #endif
22 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
23
24 #if defined(WEBRTC_ARCH_ARM_FAMILY)
25 #include <asm/hwcap.h>
26
27 uint64_t WebRtc_GetCPUFeaturesARM(void) {
28 uint64_t result = 0;
29 int architecture = 0;
30 unsigned long hwcap = 0;
31 const char* platform = NULL;
32 #if __GLIBC_PREREQ(2, 16)
33 hwcap = getauxval(AT_HWCAP);
34 platform = (const char*)getauxval(AT_PLATFORM);
35 #else
36 ElfW(auxv_t) auxv;
37 int fd = open("/proc/self/auxv", O_RDONLY);
38 if (fd >= 0) {
39 while (hwcap == 0 || platform == NULL) {
40 if (read(fd, &auxv, sizeof(auxv)) < (ssize_t)sizeof(auxv)) {
41 if (errno == EINTR)
42 continue;
43 break;
44 }
45 switch (auxv.a_type) {
46 case AT_HWCAP:
47 hwcap = auxv.a_un.a_val;
48 break;
49 case AT_PLATFORM:
50 platform = (const char*)auxv.a_un.a_val;
51 break;
52 }
53 }
54 close(fd);
55 }
56 #endif // __GLIBC_PREREQ(2,16)
57 #if defined(__aarch64__)
58 architecture = 8;
59 if ((hwcap & HWCAP_FP) != 0)
60 result |= kCPUFeatureVFPv3;
61 if ((hwcap & HWCAP_ASIMD) != 0)
62 result |= kCPUFeatureNEON;
63 #else
64 if (platform != NULL) {
65 /* expect a string in the form "v6l" or "v7l", etc.
66 */
67 if (platform[0] == 'v' && '0' <= platform[1] && platform[1] <= '9' &&
68 (platform[2] == 'l' || platform[2] == 'b')) {
69 architecture = platform[1] - '0';
70 }
71 }
72 if ((hwcap & HWCAP_VFPv3) != 0)
73 result |= kCPUFeatureVFPv3;
74 if ((hwcap & HWCAP_NEON) != 0)
75 result |= kCPUFeatureNEON;
76 #endif
77 if (architecture >= 7)
78 result |= kCPUFeatureARMv7;
79 if (architecture >= 6)
80 result |= kCPUFeatureLDREXSTREX;
81 return result;
82 }
83 #endif // WEBRTC_ARCH_ARM_FAMILY
OLDNEW
« no previous file with comments | « webrtc/system_wrappers/cpu_features_webrtc.gyp ('k') | webrtc/system_wrappers/system_wrappers.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698