| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/base/cpu.h" | 5 #include "src/base/cpu.h" |
| 6 | 6 |
| 7 #if V8_LIBC_MSVCRT | 7 #if V8_LIBC_MSVCRT |
| 8 #include <intrin.h> // __cpuid() | 8 #include <intrin.h> // __cpuid() |
| 9 #endif | 9 #endif |
| 10 #if V8_OS_LINUX |
| 11 #include <linux/auxvec.h> // AT_HWCAP |
| 12 #endif |
| 13 #if V8_GLIBC_PREREQ(2, 16) |
| 14 #include <sys/auxv.h> // getauxval() |
| 15 #endif |
| 16 #if V8_OS_QNX |
| 17 #include <sys/syspage.h> // cpuinfo |
| 18 #endif |
| 10 #if V8_OS_POSIX | 19 #if V8_OS_POSIX |
| 11 #include <unistd.h> // sysconf() | 20 #include <unistd.h> // sysconf() |
| 12 #endif | 21 #endif |
| 13 #if V8_OS_QNX | |
| 14 #include <sys/syspage.h> // cpuinfo | |
| 15 #endif | |
| 16 | 22 |
| 17 #include <ctype.h> | 23 #include <ctype.h> |
| 18 #include <limits.h> | 24 #include <limits.h> |
| 19 #include <stdio.h> | 25 #include <stdio.h> |
| 20 #include <stdlib.h> | 26 #include <stdlib.h> |
| 21 #include <string.h> | 27 #include <string.h> |
| 22 #include <algorithm> | 28 #include <algorithm> |
| 23 | 29 |
| 24 #include "src/base/logging.h" | 30 #include "src/base/logging.h" |
| 25 #if V8_OS_WIN | 31 #if V8_OS_WIN |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 #define HWCAP_VFPv3 (1 << 13) | 91 #define HWCAP_VFPv3 (1 << 13) |
| 86 #define HWCAP_VFPv3D16 (1 << 14) /* also set for VFPv4-D16 */ | 92 #define HWCAP_VFPv3D16 (1 << 14) /* also set for VFPv4-D16 */ |
| 87 #define HWCAP_TLS (1 << 15) | 93 #define HWCAP_TLS (1 << 15) |
| 88 #define HWCAP_VFPv4 (1 << 16) | 94 #define HWCAP_VFPv4 (1 << 16) |
| 89 #define HWCAP_IDIVA (1 << 17) | 95 #define HWCAP_IDIVA (1 << 17) |
| 90 #define HWCAP_IDIVT (1 << 18) | 96 #define HWCAP_IDIVT (1 << 18) |
| 91 #define HWCAP_VFPD32 (1 << 19) /* set if VFP has 32 regs (not 16) */ | 97 #define HWCAP_VFPD32 (1 << 19) /* set if VFP has 32 regs (not 16) */ |
| 92 #define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT) | 98 #define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT) |
| 93 #define HWCAP_LPAE (1 << 20) | 99 #define HWCAP_LPAE (1 << 20) |
| 94 | 100 |
| 95 #define AT_HWCAP 16 | |
| 96 | |
| 97 // Read the ELF HWCAP flags by parsing /proc/self/auxv. | |
| 98 static uint32_t ReadELFHWCaps() { | 101 static uint32_t ReadELFHWCaps() { |
| 99 uint32_t result = 0; | 102 uint32_t result = 0; |
| 103 #if V8_GLIBC_PREREQ(2, 16) |
| 104 result = static_cast<uint32_t>(getauxval(AT_HWCAP)); |
| 105 #else |
| 106 // Read the ELF HWCAP flags by parsing /proc/self/auxv. |
| 100 FILE* fp = fopen("/proc/self/auxv", "r"); | 107 FILE* fp = fopen("/proc/self/auxv", "r"); |
| 101 if (fp != NULL) { | 108 if (fp != NULL) { |
| 102 struct { uint32_t tag; uint32_t value; } entry; | 109 struct { uint32_t tag; uint32_t value; } entry; |
| 103 for (;;) { | 110 for (;;) { |
| 104 size_t n = fread(&entry, sizeof(entry), 1, fp); | 111 size_t n = fread(&entry, sizeof(entry), 1, fp); |
| 105 if (n == 0 || (entry.tag == 0 && entry.value == 0)) { | 112 if (n == 0 || (entry.tag == 0 && entry.value == 0)) { |
| 106 break; | 113 break; |
| 107 } | 114 } |
| 108 if (entry.tag == AT_HWCAP) { | 115 if (entry.tag == AT_HWCAP) { |
| 109 result = entry.value; | 116 result = entry.value; |
| 110 break; | 117 break; |
| 111 } | 118 } |
| 112 } | 119 } |
| 113 fclose(fp); | 120 fclose(fp); |
| 114 } | 121 } |
| 122 #endif |
| 115 return result; | 123 return result; |
| 116 } | 124 } |
| 117 | 125 |
| 118 #endif // V8_HOST_ARCH_ARM | 126 #endif // V8_HOST_ARCH_ARM |
| 119 | 127 |
| 120 #if V8_HOST_ARCH_MIPS | 128 #if V8_HOST_ARCH_MIPS |
| 121 int __detect_fp64_mode(void) { | 129 int __detect_fp64_mode(void) { |
| 122 double result = 0; | 130 double result = 0; |
| 123 // Bit representation of (double)1 is 0x3FF0000000000000. | 131 // Bit representation of (double)1 is 0x3FF0000000000000. |
| 124 __asm__ volatile( | 132 __asm__ volatile( |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 has_sse41_(false), | 311 has_sse41_(false), |
| 304 has_sse42_(false), | 312 has_sse42_(false), |
| 305 has_idiva_(false), | 313 has_idiva_(false), |
| 306 has_neon_(false), | 314 has_neon_(false), |
| 307 has_thumb2_(false), | 315 has_thumb2_(false), |
| 308 has_vfp_(false), | 316 has_vfp_(false), |
| 309 has_vfp3_(false), | 317 has_vfp3_(false), |
| 310 has_vfp3_d32_(false), | 318 has_vfp3_d32_(false), |
| 311 is_fp64_mode_(false) { | 319 is_fp64_mode_(false) { |
| 312 memcpy(vendor_, "Unknown", 8); | 320 memcpy(vendor_, "Unknown", 8); |
| 313 #if defined(__pnacl__) | 321 #if V8_OS_NACL |
| 314 // Portable host shouldn't do feature detection. | 322 // Portable host shouldn't do feature detection. |
| 315 // TODO(jfb): Remove the hardcoded ARM simulator flags in the build, and | 323 // TODO(jfb): Remove the hardcoded ARM simulator flags in the build, and |
| 316 // hardcode them here instead. | 324 // hardcode them here instead. |
| 317 #elif V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 | 325 #elif V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 |
| 318 int cpu_info[4]; | 326 int cpu_info[4]; |
| 319 | 327 |
| 320 // __cpuid with an InfoType argument of 0 returns the number of | 328 // __cpuid with an InfoType argument of 0 returns the number of |
| 321 // valid Ids in CPUInfo[0] and the CPU identification string in | 329 // valid Ids in CPUInfo[0] and the CPU identification string in |
| 322 // the other three array elements. The CPU identification string is | 330 // the other three array elements. The CPU identification string is |
| 323 // not in linear order. The code below arranges the information | 331 // not in linear order. The code below arranges the information |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 if (end == part) { | 551 if (end == part) { |
| 544 part_ = 0; | 552 part_ = 0; |
| 545 } | 553 } |
| 546 delete[] part; | 554 delete[] part; |
| 547 } | 555 } |
| 548 | 556 |
| 549 #endif | 557 #endif |
| 550 } | 558 } |
| 551 | 559 |
| 552 } } // namespace v8::base | 560 } } // namespace v8::base |
| OLD | NEW |