| 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 | 10 #if V8_OS_LINUX |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 "=d"(cpu_info[3]) | 70 "=d"(cpu_info[3]) |
| 71 : "a"(info_type), "c"(0)); | 71 : "a"(info_type), "c"(0)); |
| 72 #endif // defined(__i386__) && defined(__pic__) | 72 #endif // defined(__i386__) && defined(__pic__) |
| 73 } | 73 } |
| 74 | 74 |
| 75 #endif // !V8_LIBC_MSVCRT | 75 #endif // !V8_LIBC_MSVCRT |
| 76 | 76 |
| 77 #elif V8_HOST_ARCH_ARM || V8_HOST_ARCH_ARM64 \ | 77 #elif V8_HOST_ARCH_ARM || V8_HOST_ARCH_ARM64 \ |
| 78 || V8_HOST_ARCH_MIPS || V8_HOST_ARCH_MIPS64 | 78 || V8_HOST_ARCH_MIPS || V8_HOST_ARCH_MIPS64 |
| 79 | 79 |
| 80 #if V8_HOST_ARCH_ARM64 |
| 81 class CacheLineSizes { |
| 82 public: |
| 83 CacheLineSizes() { |
| 84 #ifdef USE_SIMULATOR |
| 85 cache_type_register_ = 0; |
| 86 #else |
| 87 // Copy the content of the cache type register to a core register. |
| 88 __asm__ __volatile__("mrs %[ctr], ctr_el0" // NOLINT |
| 89 : [ctr] "=r"(cache_type_register_)); |
| 90 #endif |
| 91 } |
| 92 |
| 93 uint32_t icache_line_size() const { return ExtractCacheLineSize(0); } |
| 94 uint32_t dcache_line_size() const { return ExtractCacheLineSize(16); } |
| 95 |
| 96 private: |
| 97 uint32_t ExtractCacheLineSize(int cache_line_size_shift) const { |
| 98 // The cache type register holds the size of cache lines in words as a |
| 99 // power of two. |
| 100 return 4 << ((cache_type_register_ >> cache_line_size_shift) & 0xf); |
| 101 } |
| 102 |
| 103 uint32_t cache_type_register_; |
| 104 }; |
| 105 #endif // V8_HOST_ARCH_ARM64 |
| 106 |
| 80 #if V8_OS_LINUX | 107 #if V8_OS_LINUX |
| 81 | 108 |
| 82 #if V8_HOST_ARCH_ARM | 109 #if V8_HOST_ARCH_ARM |
| 83 | 110 |
| 84 // See <uapi/asm/hwcap.h> kernel header. | 111 // See <uapi/asm/hwcap.h> kernel header. |
| 85 /* | 112 /* |
| 86 * HWCAP flags - for elf_hwcap (in kernel) and AT_HWCAP | 113 * HWCAP flags - for elf_hwcap (in kernel) and AT_HWCAP |
| 87 */ | 114 */ |
| 88 #define HWCAP_SWP (1 << 0) | 115 #define HWCAP_SWP (1 << 0) |
| 89 #define HWCAP_HALF (1 << 1) | 116 #define HWCAP_HALF (1 << 1) |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 : stepping_(0), | 332 : stepping_(0), |
| 306 model_(0), | 333 model_(0), |
| 307 ext_model_(0), | 334 ext_model_(0), |
| 308 family_(0), | 335 family_(0), |
| 309 ext_family_(0), | 336 ext_family_(0), |
| 310 type_(0), | 337 type_(0), |
| 311 implementer_(0), | 338 implementer_(0), |
| 312 architecture_(0), | 339 architecture_(0), |
| 313 variant_(-1), | 340 variant_(-1), |
| 314 part_(0), | 341 part_(0), |
| 342 icache_line_size_(UNKNOWN_CACHE_LINE_SIZE), |
| 343 dcache_line_size_(UNKNOWN_CACHE_LINE_SIZE), |
| 315 has_fpu_(false), | 344 has_fpu_(false), |
| 316 has_cmov_(false), | 345 has_cmov_(false), |
| 317 has_sahf_(false), | 346 has_sahf_(false), |
| 318 has_mmx_(false), | 347 has_mmx_(false), |
| 319 has_sse_(false), | 348 has_sse_(false), |
| 320 has_sse2_(false), | 349 has_sse2_(false), |
| 321 has_sse3_(false), | 350 has_sse3_(false), |
| 322 has_ssse3_(false), | 351 has_ssse3_(false), |
| 323 has_sse41_(false), | 352 has_sse41_(false), |
| 324 has_sse42_(false), | 353 has_sse42_(false), |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 char* part = cpu_info.ExtractField("CPU part"); | 648 char* part = cpu_info.ExtractField("CPU part"); |
| 620 if (part != NULL) { | 649 if (part != NULL) { |
| 621 char* end; | 650 char* end; |
| 622 part_ = strtol(part, &end, 0); | 651 part_ = strtol(part, &end, 0); |
| 623 if (end == part) { | 652 if (end == part) { |
| 624 part_ = 0; | 653 part_ = 0; |
| 625 } | 654 } |
| 626 delete[] part; | 655 delete[] part; |
| 627 } | 656 } |
| 628 | 657 |
| 658 CacheLineSizes sizes; |
| 659 icache_line_size_ = sizes.dcache_line_size(); |
| 660 dcache_line_size_ = sizes.icache_line_size(); |
| 661 |
| 629 #elif V8_HOST_ARCH_PPC | 662 #elif V8_HOST_ARCH_PPC |
| 630 | 663 |
| 631 #ifndef USE_SIMULATOR | 664 #ifndef USE_SIMULATOR |
| 632 #if V8_OS_LINUX | 665 #if V8_OS_LINUX |
| 633 // Read processor info from /proc/self/auxv. | 666 // Read processor info from /proc/self/auxv. |
| 634 char* auxv_cpu_type = NULL; | 667 char* auxv_cpu_type = NULL; |
| 635 FILE* fp = fopen("/proc/self/auxv", "r"); | 668 FILE* fp = fopen("/proc/self/auxv", "r"); |
| 636 if (fp != NULL) { | 669 if (fp != NULL) { |
| 637 #if V8_TARGET_ARCH_PPC64 | 670 #if V8_TARGET_ARCH_PPC64 |
| 638 Elf64_auxv_t entry; | 671 Elf64_auxv_t entry; |
| 639 #else | 672 #else |
| 640 Elf32_auxv_t entry; | 673 Elf32_auxv_t entry; |
| 641 #endif | 674 #endif |
| 642 for (;;) { | 675 for (;;) { |
| 643 size_t n = fread(&entry, sizeof(entry), 1, fp); | 676 size_t n = fread(&entry, sizeof(entry), 1, fp); |
| 644 if (n == 0 || entry.a_type == AT_NULL) { | 677 if (n == 0 || entry.a_type == AT_NULL) { |
| 645 break; | 678 break; |
| 646 } | 679 } |
| 647 if (entry.a_type == AT_PLATFORM) { | 680 switch (entry.a_type) { |
| 648 auxv_cpu_type = reinterpret_cast<char*>(entry.a_un.a_val); | 681 case AT_PLATFORM: |
| 649 break; | 682 auxv_cpu_type = reinterpret_cast<char*>(entry.a_un.a_val); |
| 683 break; |
| 684 case AT_ICACHEBSIZE: |
| 685 icache_line_size_ = entry.a_un.a_val; |
| 686 break; |
| 687 case AT_DCACHEBSIZE: |
| 688 dcache_line_size_ = entry.a_un.a_val; |
| 689 break; |
| 650 } | 690 } |
| 651 } | 691 } |
| 652 fclose(fp); | 692 fclose(fp); |
| 653 } | 693 } |
| 654 | 694 |
| 655 part_ = -1; | 695 part_ = -1; |
| 656 if (auxv_cpu_type) { | 696 if (auxv_cpu_type) { |
| 657 if (strcmp(auxv_cpu_type, "power8") == 0) { | 697 if (strcmp(auxv_cpu_type, "power8") == 0) { |
| 658 part_ = PPC_POWER8; | 698 part_ = PPC_POWER8; |
| 659 } else if (strcmp(auxv_cpu_type, "power7") == 0) { | 699 } else if (strcmp(auxv_cpu_type, "power7") == 0) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 686 part_ = PPC_POWER5; | 726 part_ = PPC_POWER5; |
| 687 break; | 727 break; |
| 688 } | 728 } |
| 689 #endif // V8_OS_AIX | 729 #endif // V8_OS_AIX |
| 690 #endif // !USE_SIMULATOR | 730 #endif // !USE_SIMULATOR |
| 691 #endif // V8_HOST_ARCH_PPC | 731 #endif // V8_HOST_ARCH_PPC |
| 692 } | 732 } |
| 693 | 733 |
| 694 } // namespace base | 734 } // namespace base |
| 695 } // namespace v8 | 735 } // namespace v8 |
| OLD | NEW |