| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "cpu.h" | 28 #include "cpu.h" |
| 29 | 29 |
| 30 #if V8_CC_MSVC | 30 #if V8_CC_MSVC |
| 31 #include <intrin.h> // __cpuid() | 31 #include <intrin.h> // __cpuid() |
| 32 #endif | 32 #endif |
| 33 #if V8_OS_POSIX | 33 #if V8_OS_POSIX |
| 34 #include <unistd.h> // sysconf() | 34 #include <unistd.h> // sysconf() |
| 35 #endif | 35 #endif |
| 36 #if V8_OS_QNX |
| 37 #include <sys/syspage.h> // cpuinfo |
| 38 #endif |
| 36 | 39 |
| 37 #include <algorithm> | 40 #include <algorithm> |
| 38 #include <cctype> | 41 #include <cctype> |
| 39 #include <climits> | 42 #include <climits> |
| 40 #include <cstdio> | 43 #include <cstdio> |
| 41 #include <cstdlib> | 44 #include <cstdlib> |
| 42 #include <cstring> | 45 #include <cstring> |
| 43 | 46 |
| 44 #include "checks.h" | 47 #include "checks.h" |
| 45 #if V8_OS_WIN | 48 #if V8_OS_WIN |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) | 74 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) |
| 72 : "a"(info_type) | 75 : "a"(info_type) |
| 73 ); | 76 ); |
| 74 #endif // defined(__i386__) && defined(__pic__) | 77 #endif // defined(__i386__) && defined(__pic__) |
| 75 } | 78 } |
| 76 | 79 |
| 77 #endif // !V8_CC_MSVC | 80 #endif // !V8_CC_MSVC |
| 78 | 81 |
| 79 #elif V8_HOST_ARCH_ARM || V8_HOST_ARCH_MIPS | 82 #elif V8_HOST_ARCH_ARM || V8_HOST_ARCH_MIPS |
| 80 | 83 |
| 84 #if V8_OS_LINUX |
| 85 |
| 81 #if V8_HOST_ARCH_ARM | 86 #if V8_HOST_ARCH_ARM |
| 82 | 87 |
| 83 // See <uapi/asm/hwcap.h> kernel header. | 88 // See <uapi/asm/hwcap.h> kernel header. |
| 84 /* | 89 /* |
| 85 * HWCAP flags - for elf_hwcap (in kernel) and AT_HWCAP | 90 * HWCAP flags - for elf_hwcap (in kernel) and AT_HWCAP |
| 86 */ | 91 */ |
| 87 #define HWCAP_SWP (1 << 0) | 92 #define HWCAP_SWP (1 << 0) |
| 88 #define HWCAP_HALF (1 << 1) | 93 #define HWCAP_HALF (1 << 1) |
| 89 #define HWCAP_THUMB (1 << 2) | 94 #define HWCAP_THUMB (1 << 2) |
| 90 #define HWCAP_26BIT (1 << 3) /* Play it safe */ | 95 #define HWCAP_26BIT (1 << 3) /* Play it safe */ |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 return true; | 247 return true; |
| 243 } | 248 } |
| 244 | 249 |
| 245 // Skip to next item. | 250 // Skip to next item. |
| 246 p = q; | 251 p = q; |
| 247 } | 252 } |
| 248 } | 253 } |
| 249 return false; | 254 return false; |
| 250 } | 255 } |
| 251 | 256 |
| 257 #endif // V8_OS_LINUX |
| 258 |
| 252 #endif // V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 | 259 #endif // V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 |
| 253 | 260 |
| 254 CPU::CPU() : stepping_(0), | 261 CPU::CPU() : stepping_(0), |
| 255 model_(0), | 262 model_(0), |
| 256 ext_model_(0), | 263 ext_model_(0), |
| 257 family_(0), | 264 family_(0), |
| 258 ext_family_(0), | 265 ext_family_(0), |
| 259 type_(0), | 266 type_(0), |
| 260 implementer_(0), | 267 implementer_(0), |
| 261 architecture_(0), | 268 architecture_(0), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 if (num_ext_ids > 0x80000000) { | 328 if (num_ext_ids > 0x80000000) { |
| 322 __cpuid(cpu_info, 0x80000001); | 329 __cpuid(cpu_info, 0x80000001); |
| 323 // SAHF is always available in compat/legacy mode, | 330 // SAHF is always available in compat/legacy mode, |
| 324 // but must be probed in long mode. | 331 // but must be probed in long mode. |
| 325 #if V8_HOST_ARCH_IA32 | 332 #if V8_HOST_ARCH_IA32 |
| 326 has_sahf_ = true; | 333 has_sahf_ = true; |
| 327 #else | 334 #else |
| 328 has_sahf_ = (cpu_info[2] & 0x00000001) != 0; | 335 has_sahf_ = (cpu_info[2] & 0x00000001) != 0; |
| 329 #endif | 336 #endif |
| 330 } | 337 } |
| 338 |
| 331 #elif V8_HOST_ARCH_ARM | 339 #elif V8_HOST_ARCH_ARM |
| 340 |
| 341 #if V8_OS_LINUX |
| 342 |
| 332 CPUInfo cpu_info; | 343 CPUInfo cpu_info; |
| 333 | 344 |
| 334 // Extract implementor from the "CPU implementer" field. | 345 // Extract implementor from the "CPU implementer" field. |
| 335 char* implementer = cpu_info.ExtractField("CPU implementer"); | 346 char* implementer = cpu_info.ExtractField("CPU implementer"); |
| 336 if (implementer != NULL) { | 347 if (implementer != NULL) { |
| 337 char* end ; | 348 char* end ; |
| 338 implementer_ = strtol(implementer, &end, 0); | 349 implementer_ = strtol(implementer, &end, 0); |
| 339 if (end == implementer) { | 350 if (end == implementer) { |
| 340 implementer_ = 0; | 351 implementer_ = 0; |
| 341 } | 352 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 has_thumbee_ = true; | 442 has_thumbee_ = true; |
| 432 } | 443 } |
| 433 | 444 |
| 434 // The earliest architecture with ThumbEE is ARMv6T2. | 445 // The earliest architecture with ThumbEE is ARMv6T2. |
| 435 if (has_thumbee_ && architecture_ < 6) { | 446 if (has_thumbee_ && architecture_ < 6) { |
| 436 architecture_ = 6; | 447 architecture_ = 6; |
| 437 } | 448 } |
| 438 | 449 |
| 439 // We don't support any FPUs other than VFP. | 450 // We don't support any FPUs other than VFP. |
| 440 has_fpu_ = has_vfp_; | 451 has_fpu_ = has_vfp_; |
| 452 |
| 453 #elif V8_OS_QNX |
| 454 |
| 455 uint32_t cpu_flags = SYSPAGE_ENTRY(cpuinfo)->flags; |
| 456 if (cpu_flags & ARM_CPU_FLAG_V7) { |
| 457 architecture_ = 7; |
| 458 has_thumbee_ = true; |
| 459 } else if (cpu_flags & ARM_CPU_FLAG_V6) { |
| 460 architecture_ = 6; |
| 461 // QNX doesn't say if ThumbEE is available. |
| 462 // Assume false for the architectures older than ARMv7. |
| 463 } |
| 464 ASSERT(architecture_ >= 6); |
| 465 has_fpu_ = (cpu_flags & CPU_FLAG_FPU) != 0; |
| 466 has_vfp_ = has_fpu_; |
| 467 if (cpu_flags & ARM_CPU_FLAG_NEON) { |
| 468 has_neon_ = true; |
| 469 has_vfp3_ = has_vfp_; |
| 470 #ifdef ARM_CPU_FLAG_VFP_D32 |
| 471 has_vfp3_d32_ = (cpu_flags & ARM_CPU_FLAG_VFP_D32) != 0; |
| 472 #endif |
| 473 } |
| 474 has_idiva_ = (cpu_flags & ARM_CPU_FLAG_IDIV) != 0; |
| 475 |
| 476 #endif // V8_OS_LINUX |
| 477 |
| 441 #elif V8_HOST_ARCH_MIPS | 478 #elif V8_HOST_ARCH_MIPS |
| 479 |
| 442 // Simple detection of FPU at runtime for Linux. | 480 // Simple detection of FPU at runtime for Linux. |
| 443 // It is based on /proc/cpuinfo, which reveals hardware configuration | 481 // It is based on /proc/cpuinfo, which reveals hardware configuration |
| 444 // to user-space applications. According to MIPS (early 2010), no similar | 482 // to user-space applications. According to MIPS (early 2010), no similar |
| 445 // facility is universally available on the MIPS architectures, | 483 // facility is universally available on the MIPS architectures, |
| 446 // so it's up to individual OSes to provide such. | 484 // so it's up to individual OSes to provide such. |
| 447 CPUInfo cpu_info; | 485 CPUInfo cpu_info; |
| 448 char* cpu_model = cpu_info.ExtractField("cpu model"); | 486 char* cpu_model = cpu_info.ExtractField("cpu model"); |
| 449 has_fpu_ = HasListItem(cpu_model, "FPU"); | 487 has_fpu_ = HasListItem(cpu_model, "FPU"); |
| 450 delete[] cpu_model; | 488 delete[] cpu_model; |
| 489 |
| 451 #endif | 490 #endif |
| 452 } | 491 } |
| 453 | 492 |
| 454 | 493 |
| 455 // static | 494 // static |
| 456 int CPU::NumberOfProcessorsOnline() { | 495 int CPU::NumberOfProcessorsOnline() { |
| 457 #if V8_OS_WIN | 496 #if V8_OS_WIN |
| 458 SYSTEM_INFO info; | 497 SYSTEM_INFO info; |
| 459 GetSystemInfo(&info); | 498 GetSystemInfo(&info); |
| 460 return info.dwNumberOfProcessors; | 499 return info.dwNumberOfProcessors; |
| 461 #else | 500 #else |
| 462 return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN)); | 501 return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN)); |
| 463 #endif | 502 #endif |
| 464 } | 503 } |
| 465 | 504 |
| 466 } } // namespace v8::internal | 505 } } // namespace v8::internal |
| OLD | NEW |