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 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 break; | 108 break; |
109 } | 109 } |
110 } | 110 } |
111 fclose(fp); | 111 fclose(fp); |
112 } | 112 } |
113 return result; | 113 return result; |
114 } | 114 } |
115 | 115 |
116 #endif // V8_HOST_ARCH_ARM | 116 #endif // V8_HOST_ARCH_ARM |
117 | 117 |
118 #if V8_HOST_ARCH_MIPS | |
119 int __detect_fp64_mode(void) { | |
120 double result = 0; | |
121 // Bit representation of (double)1 is 0x3FF0000000000000. | |
122 asm( | |
123 "lui $t0, 0x3FF0\n\t" | |
124 "ldc1 $f0, %0\n\t" | |
125 "mtc1 $t0, $f1\n\t" | |
126 "sdc1 $f0, %0\n\t" | |
127 : "+m" (result) | |
128 : : "t0", "$f0", "$f1", "memory"); | |
129 | |
130 return !(result == 1); | |
131 } | |
132 | |
133 | |
134 int __detect_mips_arch_revision(void) { | |
135 // TODO(dusmil): Do the specific syscall as soon as it is implemented in mips | |
136 // kernel. Currently fail-back to the least common denominator which is | |
137 // mips32 revision 1. | |
138 return 1; | |
139 } | |
140 #endif | |
141 | |
142 // Extract the information exposed by the kernel via /proc/cpuinfo. | 118 // Extract the information exposed by the kernel via /proc/cpuinfo. |
143 class CPUInfo V8_FINAL { | 119 class CPUInfo V8_FINAL { |
144 public: | 120 public: |
145 CPUInfo() : datalen_(0) { | 121 CPUInfo() : datalen_(0) { |
146 // Get the size of the cpuinfo file by reading it until the end. This is | 122 // Get the size of the cpuinfo file by reading it until the end. This is |
147 // required because files under /proc do not always return a valid size | 123 // required because files under /proc do not always return a valid size |
148 // when using fseek(0, SEEK_END) + ftell(). Nor can the be mmap()-ed. | 124 // when using fseek(0, SEEK_END) + ftell(). Nor can the be mmap()-ed. |
149 static const char PATHNAME[] = "/proc/cpuinfo"; | 125 static const char PATHNAME[] = "/proc/cpuinfo"; |
150 FILE* fp = fopen(PATHNAME, "r"); | 126 FILE* fp = fopen(PATHNAME, "r"); |
151 if (fp != NULL) { | 127 if (fp != NULL) { |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 459 |
484 // Simple detection of FPU at runtime for Linux. | 460 // Simple detection of FPU at runtime for Linux. |
485 // It is based on /proc/cpuinfo, which reveals hardware configuration | 461 // It is based on /proc/cpuinfo, which reveals hardware configuration |
486 // to user-space applications. According to MIPS (early 2010), no similar | 462 // to user-space applications. According to MIPS (early 2010), no similar |
487 // facility is universally available on the MIPS architectures, | 463 // facility is universally available on the MIPS architectures, |
488 // so it's up to individual OSes to provide such. | 464 // so it's up to individual OSes to provide such. |
489 CPUInfo cpu_info; | 465 CPUInfo cpu_info; |
490 char* cpu_model = cpu_info.ExtractField("cpu model"); | 466 char* cpu_model = cpu_info.ExtractField("cpu model"); |
491 has_fpu_ = HasListItem(cpu_model, "FPU"); | 467 has_fpu_ = HasListItem(cpu_model, "FPU"); |
492 delete[] cpu_model; | 468 delete[] cpu_model; |
493 #ifdef V8_HOST_ARCH_MIPS | |
494 is_fp64_mode_ = __detect_fp64_mode(); | |
495 architecture_ = __detect_mips_arch_revision(); | |
496 #endif | |
497 | 469 |
498 #elif V8_HOST_ARCH_ARM64 | 470 #elif V8_HOST_ARCH_ARM64 |
499 | 471 |
500 CPUInfo cpu_info; | 472 CPUInfo cpu_info; |
501 | 473 |
502 // Extract implementor from the "CPU implementer" field. | 474 // Extract implementor from the "CPU implementer" field. |
503 char* implementer = cpu_info.ExtractField("CPU implementer"); | 475 char* implementer = cpu_info.ExtractField("CPU implementer"); |
504 if (implementer != NULL) { | 476 if (implementer != NULL) { |
505 char* end ; | 477 char* end ; |
506 implementer_ = strtol(implementer, &end, 0); | 478 implementer_ = strtol(implementer, &end, 0); |
(...skipping 11 matching lines...) Expand all Loading... |
518 if (end == part) { | 490 if (end == part) { |
519 part_ = 0; | 491 part_ = 0; |
520 } | 492 } |
521 delete[] part; | 493 delete[] part; |
522 } | 494 } |
523 | 495 |
524 #endif | 496 #endif |
525 } | 497 } |
526 | 498 |
527 } } // namespace v8::base | 499 } } // namespace v8::base |
OLD | NEW |