| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/x64/assembler-x64.h" | 5 #include "src/x64/assembler-x64.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #if V8_TARGET_ARCH_X64 | 9 #if V8_TARGET_ARCH_X64 |
| 10 | 10 |
| 11 #if V8_OS_MACOSX | 11 #if V8_OS_MACOSX |
| 12 #include <sys/sysctl.h> | 12 #include <sys/sysctl.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "src/base/bits.h" | 15 #include "src/base/bits.h" |
| 16 #if V8_OS_WIN | |
| 17 #include "src/base/win32-headers.h" | |
| 18 #endif | |
| 19 #include "src/macro-assembler.h" | 16 #include "src/macro-assembler.h" |
| 20 #include "src/v8.h" | 17 #include "src/v8.h" |
| 21 | 18 |
| 22 namespace v8 { | 19 namespace v8 { |
| 23 namespace internal { | 20 namespace internal { |
| 24 | 21 |
| 25 // ----------------------------------------------------------------------------- | 22 // ----------------------------------------------------------------------------- |
| 26 // Implementation of CpuFeatures | 23 // Implementation of CpuFeatures |
| 27 | 24 |
| 28 namespace { | 25 namespace { |
| 29 | 26 |
| 30 bool EnableAVX() { | 27 bool EnableAVX() { |
| 28 // Check whether OS claims to support AVX. |
| 29 int flags = 0; |
| 30 #if V8_CC_GNU |
| 31 // Check xgetbv; this uses a .byte sequence instead of the instruction |
| 32 // directly because older assemblers do not include support for xgetbv and |
| 33 // there is no easy way to conditionally compile based on the assembler used. |
| 34 asm volatile(".byte 0x0f, 0x01, 0xd0" : "=a"(flags) : "c"(0) : "%edx"); |
| 35 #elif V8_CC_MSVC |
| 36 __asm { |
| 37 xor ecx, ecx // ecx = 0 |
| 38 // Use the raw opcode for xgetbv for compatibility with older |
| 39 // toolchains. |
| 40 __asm _emit 0x0f __asm _emit 0x01 __asm _emit 0xd0 |
| 41 mov flags, eax |
| 42 } |
| 43 #endif |
| 44 if ((flags & 6) == 0) return false; |
| 31 #if V8_OS_MACOSX | 45 #if V8_OS_MACOSX |
| 32 // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being | 46 // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being |
| 33 // caused by ISRs, so we detect that here and disable AVX in that case. | 47 // caused by ISRs, so we detect that here and disable AVX in that case. |
| 34 char buffer[128]; | 48 char buffer[128]; |
| 35 size_t buffer_size = arraysize(buffer); | 49 size_t buffer_size = arraysize(buffer); |
| 36 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE}; | 50 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE}; |
| 37 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { | 51 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { |
| 38 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); | 52 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); |
| 39 } | 53 } |
| 40 // The buffer now contains a string of the form XX.YY.ZZ, where | 54 // The buffer now contains a string of the form XX.YY.ZZ, where |
| 41 // XX is the major kernel version component. | 55 // XX is the major kernel version component. |
| 42 char* period_pos = strchr(buffer, '.'); | 56 char* period_pos = strchr(buffer, '.'); |
| 43 DCHECK_NOT_NULL(period_pos); | 57 DCHECK_NOT_NULL(period_pos); |
| 44 *period_pos = '\0'; | 58 *period_pos = '\0'; |
| 45 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT | 59 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT |
| 46 if (kernel_version_major <= 13) return false; | 60 if (kernel_version_major <= 13) return false; |
| 47 #elif V8_OS_WIN | |
| 48 // The same problem seems to appear on Windows XP and Vista. | |
| 49 OSVERSIONINFOEX osvi; | |
| 50 DWORDLONG mask = 0; | |
| 51 memset(&osvi, 0, sizeof(osvi)); | |
| 52 osvi.dwOSVersionInfoSize = sizeof(osvi); | |
| 53 osvi.dwMajorVersion = 6; | |
| 54 osvi.dwMinorVersion = 1; | |
| 55 VER_SET_CONDITION(mask, VER_MAJORVERSION, VER_GREATER_EQUAL); | |
| 56 VER_SET_CONDITION(mask, VER_MINORVERSION, VER_GREATER_EQUAL); | |
| 57 if (!VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, mask)) { | |
| 58 return false; | |
| 59 } | |
| 60 #endif // V8_OS_MACOSX | 61 #endif // V8_OS_MACOSX |
| 61 return FLAG_enable_avx; | 62 return FLAG_enable_avx; |
| 62 } | 63 } |
| 63 | 64 |
| 64 } // namespace | 65 } // namespace |
| 65 | 66 |
| 66 | 67 |
| 67 void CpuFeatures::ProbeImpl(bool cross_compile) { | 68 void CpuFeatures::ProbeImpl(bool cross_compile) { |
| 68 base::CPU cpu; | 69 base::CPU cpu; |
| 69 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. | 70 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. |
| (...skipping 3333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3403 | 3404 |
| 3404 | 3405 |
| 3405 bool RelocInfo::IsInConstantPool() { | 3406 bool RelocInfo::IsInConstantPool() { |
| 3406 return false; | 3407 return false; |
| 3407 } | 3408 } |
| 3408 | 3409 |
| 3409 | 3410 |
| 3410 } } // namespace v8::internal | 3411 } } // namespace v8::internal |
| 3411 | 3412 |
| 3412 #endif // V8_TARGET_ARCH_X64 | 3413 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |