Chromium Code Reviews| OLD | NEW |
|---|---|
| (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)) { | |
|
torbjorng (webrtc)
2016/04/04 08:35:42
We don't usually use redundant parentheses.
Simon Hosie
2016/04/05 01:15:48
Done.
| |
| 40 if (read(fd, &auxv, sizeof(auxv)) < sizeof(auxv)) { | |
| 41 if (errno == EINTR) continue; | |
| 42 break; | |
| 43 } | |
| 44 switch (auxv.a_type) { | |
| 45 case AT_HWCAP: | |
| 46 hwcap = auxv.a_un.a_val; | |
| 47 break; | |
| 48 case AT_PLATFORM: | |
| 49 platform = (const char*)auxv.a_un.a_val; | |
| 50 break; | |
| 51 default: | |
| 52 (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.
| |
| 53 break; | |
| 54 } | |
| 55 } | |
| 56 close(fd); | |
| 57 } | |
| 58 #endif // __GLIBC_PREREQ(2,16) | |
| 59 #if defined(__aarch64__) | |
| 60 architecture = 8; | |
| 61 if ((hwcap & HWCAP_FP) != 0) result |= kCPUFeatureVFPv3; | |
| 62 if ((hwcap & HWCAP_ASIMD) != 0) 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') && | |
| 68 ('0' <= platform[1]) && (platform[1] <= '9')) { | |
| 69 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
| |
| 70 } | |
| 71 } | |
| 72 if ((hwcap & HWCAP_VFPv3) != 0) result |= kCPUFeatureVFPv3; | |
| 73 if ((hwcap & HWCAP_NEON) != 0) result |= kCPUFeatureNEON; | |
| 74 #endif | |
| 75 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".
| |
| 76 if (architecture >= 6) result |= kCPUFeatureLDREXSTREX; | |
| 77 return result; | |
| 78 } | |
| 79 #endif // WEBRTC_ARCH_ARM_FAMILY | |
| OLD | NEW |