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_POSIX | 10 #if V8_OS_POSIX |
11 #include <unistd.h> // sysconf() | 11 #include <unistd.h> // sysconf() |
12 #endif | 12 #endif |
13 #if V8_OS_QNX | 13 #if V8_OS_QNX |
14 #include <sys/syspage.h> // cpuinfo | 14 #include <sys/syspage.h> // cpuinfo |
15 #endif | 15 #endif |
16 #if V8_OS_LINUX && V8_HOST_ARCH_PPC | |
17 #include <elf.h> | |
18 #endif | |
16 | 19 |
17 #include <ctype.h> | 20 #include <ctype.h> |
18 #include <limits.h> | 21 #include <limits.h> |
19 #include <stdio.h> | 22 #include <stdio.h> |
20 #include <stdlib.h> | 23 #include <stdlib.h> |
21 #include <string.h> | 24 #include <string.h> |
22 #include <algorithm> | 25 #include <algorithm> |
23 | 26 |
24 #include "src/base/logging.h" | 27 #include "src/base/logging.h" |
25 #if V8_OS_WIN | 28 #if V8_OS_WIN |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 | 244 |
242 CPU::CPU() : stepping_(0), | 245 CPU::CPU() : stepping_(0), |
243 model_(0), | 246 model_(0), |
244 ext_model_(0), | 247 ext_model_(0), |
245 family_(0), | 248 family_(0), |
246 ext_family_(0), | 249 ext_family_(0), |
247 type_(0), | 250 type_(0), |
248 implementer_(0), | 251 implementer_(0), |
249 architecture_(0), | 252 architecture_(0), |
250 part_(0), | 253 part_(0), |
254 cache_line_size_(0), | |
danno
2014/07/29 13:24:08
Seems like it makes sense to add a sentinel consta
andrew_low
2014/07/30 13:27:05
Seems sensible, I've made what I believe are the c
| |
251 has_fpu_(false), | 255 has_fpu_(false), |
252 has_cmov_(false), | 256 has_cmov_(false), |
253 has_sahf_(false), | 257 has_sahf_(false), |
254 has_mmx_(false), | 258 has_mmx_(false), |
255 has_sse_(false), | 259 has_sse_(false), |
256 has_sse2_(false), | 260 has_sse2_(false), |
257 has_sse3_(false), | 261 has_sse3_(false), |
258 has_ssse3_(false), | 262 has_ssse3_(false), |
259 has_sse41_(false), | 263 has_sse41_(false), |
260 has_sse42_(false), | 264 has_sse42_(false), |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 char* part = cpu_info.ExtractField("CPU part"); | 490 char* part = cpu_info.ExtractField("CPU part"); |
487 if (part != NULL) { | 491 if (part != NULL) { |
488 char* end ; | 492 char* end ; |
489 part_ = strtol(part, &end, 0); | 493 part_ = strtol(part, &end, 0); |
490 if (end == part) { | 494 if (end == part) { |
491 part_ = 0; | 495 part_ = 0; |
492 } | 496 } |
493 delete[] part; | 497 delete[] part; |
494 } | 498 } |
495 | 499 |
500 #elif V8_HOST_ARCH_PPC | |
501 | |
502 #if V8_OS_LINUX && !defined(USE_SIMULATOR) | |
503 // Read processor info from /proc/self/auxv. | |
504 char *auxv_cpu_type = NULL; | |
505 unsigned auxv_cache_line_size = 0; | |
506 FILE* fp = fopen("/proc/self/auxv", "r"); | |
507 if (fp != NULL) { | |
508 #if V8_TARGET_ARCH_PPC64 | |
509 Elf64_auxv_t entry; | |
510 #else | |
511 Elf32_auxv_t entry; | |
512 #endif | |
513 for (;;) { | |
514 size_t n = fread(&entry, sizeof(entry), 1, fp); | |
515 if (n == 0 || entry.a_type == AT_NULL) { | |
516 break; | |
517 } | |
518 if (entry.a_type == AT_PLATFORM) { | |
519 auxv_cpu_type = reinterpret_cast<char*>(entry.a_un.a_val); | |
520 break; | |
521 } else if (entry.a_type == AT_DCACHEBSIZE || | |
522 entry.a_type == AT_ICACHEBSIZE || | |
523 entry.a_type == AT_UCACHEBSIZE) { | |
524 unsigned cachebsize = entry.a_un.a_val; | |
525 if (cachebsize > 0 && | |
526 (auxv_cache_line_size == 0 || cachebsize < auxv_cache_line_size)) { | |
527 auxv_cache_line_size = cachebsize; | |
528 } | |
529 } | |
530 } | |
531 fclose(fp); | |
532 } | |
533 | |
534 part_ = -1; | |
535 if (auxv_cpu_type) { | |
536 if (strcmp(auxv_cpu_type, "power8") == 0) { | |
537 part_ = PPC_POWER8; | |
538 } else if (strcmp(auxv_cpu_type, "power7") == 0) { | |
539 part_ = PPC_POWER7; | |
540 } else if (strcmp(auxv_cpu_type, "power6") == 0) { | |
541 part_ = PPC_POWER6; | |
542 } else if (strcmp(auxv_cpu_type, "power5") == 0) { | |
543 part_ = PPC_POWER5; | |
544 } else if (strcmp(auxv_cpu_type, "ppc970") == 0) { | |
545 part_ = PPC_G5; | |
546 } else if (strcmp(auxv_cpu_type, "ppc7450") == 0) { | |
547 part_ = PPC_G4; | |
548 } else if (strcmp(auxv_cpu_type, "pa6t") == 0) { | |
549 part_ = PPC_PA6T; | |
550 } | |
551 } | |
552 | |
553 if (auxv_cache_line_size > 0) { | |
554 cache_line_size_ = auxv_cache_line_size; | |
555 } | |
556 #endif | |
557 | |
496 #endif | 558 #endif |
497 } | 559 } |
498 | 560 |
499 } } // namespace v8::base | 561 } } // namespace v8::base |
OLD | NEW |