| 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 OSHasAVXSupport() { |
| 31 #if V8_OS_MACOSX | 28 #if V8_OS_MACOSX |
| 32 // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being | 29 // 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. | 30 // caused by ISRs, so we detect that here and disable AVX in that case. |
| 34 char buffer[128]; | 31 char buffer[128]; |
| 35 size_t buffer_size = arraysize(buffer); | 32 size_t buffer_size = arraysize(buffer); |
| 36 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE}; | 33 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE}; |
| 37 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { | 34 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { |
| 38 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); | 35 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); |
| 39 } | 36 } |
| 40 // The buffer now contains a string of the form XX.YY.ZZ, where | 37 // The buffer now contains a string of the form XX.YY.ZZ, where |
| 41 // XX is the major kernel version component. | 38 // XX is the major kernel version component. |
| 42 char* period_pos = strchr(buffer, '.'); | 39 char* period_pos = strchr(buffer, '.'); |
| 43 DCHECK_NOT_NULL(period_pos); | 40 DCHECK_NOT_NULL(period_pos); |
| 44 *period_pos = '\0'; | 41 *period_pos = '\0'; |
| 45 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT | 42 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT |
| 46 if (kernel_version_major <= 13) return false; | 43 if (kernel_version_major <= 13) return false; |
| 47 #elif V8_OS_WIN | 44 #endif // V8_OS_MACOSX |
| 48 // The same problem seems to appear on Windows XP and Vista. | 45 // Check whether OS claims to support AVX. |
| 49 OSVERSIONINFOEX osvi; | 46 int flags = 0; |
| 50 DWORDLONG mask = 0; | 47 #if V8_CC_GNU |
| 51 memset(&osvi, 0, sizeof(osvi)); | 48 // Check xgetbv; this uses a .byte sequence instead of the instruction |
| 52 osvi.dwOSVersionInfoSize = sizeof(osvi); | 49 // directly because older assemblers do not include support for xgetbv and |
| 53 osvi.dwMajorVersion = 6; | 50 // there is no easy way to conditionally compile based on the assembler used. |
| 54 osvi.dwMinorVersion = 1; | 51 __asm__ __volatile__(".byte 0x0f, 0x01, 0xd0" |
| 55 VER_SET_CONDITION(mask, VER_MAJORVERSION, VER_GREATER_EQUAL); | 52 : "=a"(flags) |
| 56 VER_SET_CONDITION(mask, VER_MINORVERSION, VER_GREATER_EQUAL); | 53 : "c"(0) |
| 57 if (!VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, mask)) { | 54 : "%edx"); |
| 58 return false; | 55 #elif V8_CC_MSVC |
| 56 __asm { |
| 57 xor ecx, ecx // ecx = 0 |
| 58 // Use the raw opcode for xgetbv for compatibility with older |
| 59 // toolchains. |
| 60 __asm _emit 0x0f __asm _emit 0x01 __asm _emit 0xd0 |
| 61 mov flags, eax |
| 59 } | 62 } |
| 60 #endif // V8_OS_MACOSX | 63 #endif |
| 61 return FLAG_enable_avx; | 64 return (flags & 6) == 6; |
| 62 } | 65 } |
| 63 | 66 |
| 64 } // namespace | 67 } // namespace |
| 65 | 68 |
| 66 | 69 |
| 67 void CpuFeatures::ProbeImpl(bool cross_compile) { | 70 void CpuFeatures::ProbeImpl(bool cross_compile) { |
| 68 base::CPU cpu; | 71 base::CPU cpu; |
| 69 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. | 72 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. |
| 70 CHECK(cpu.has_cmov()); // CMOV support is mandatory. | 73 CHECK(cpu.has_cmov()); // CMOV support is mandatory. |
| 71 | 74 |
| 72 // Only use statically determined features for cross compile (snapshot). | 75 // Only use statically determined features for cross compile (snapshot). |
| 73 if (cross_compile) return; | 76 if (cross_compile) return; |
| 74 | 77 |
| 75 if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1; | 78 if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1; |
| 76 if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3; | 79 if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3; |
| 77 // SAHF is not generally available in long mode. | 80 // SAHF is not generally available in long mode. |
| 78 if (cpu.has_sahf() && FLAG_enable_sahf) supported_ |= 1u << SAHF; | 81 if (cpu.has_sahf() && FLAG_enable_sahf) supported_ |= 1u << SAHF; |
| 79 if (cpu.has_avx() && EnableAVX()) supported_ |= 1u << AVX; | 82 if (cpu.has_avx() && FLAG_enable_avx && cpu.has_osxsave() && |
| 80 if (cpu.has_fma3() && FLAG_enable_fma3) supported_ |= 1u << FMA3; | 83 OSHasAVXSupport()) { |
| 84 supported_ |= 1u << AVX; |
| 85 } |
| 86 if (cpu.has_fma3() && FLAG_enable_fma3 && cpu.has_osxsave() && |
| 87 OSHasAVXSupport()) { |
| 88 supported_ |= 1u << FMA3; |
| 89 } |
| 81 if (strcmp(FLAG_mcpu, "auto") == 0) { | 90 if (strcmp(FLAG_mcpu, "auto") == 0) { |
| 82 if (cpu.is_atom()) supported_ |= 1u << ATOM; | 91 if (cpu.is_atom()) supported_ |= 1u << ATOM; |
| 83 } else if (strcmp(FLAG_mcpu, "atom") == 0) { | 92 } else if (strcmp(FLAG_mcpu, "atom") == 0) { |
| 84 supported_ |= 1u << ATOM; | 93 supported_ |= 1u << ATOM; |
| 85 } | 94 } |
| 86 } | 95 } |
| 87 | 96 |
| 88 | 97 |
| 89 void CpuFeatures::PrintTarget() { } | 98 void CpuFeatures::PrintTarget() { } |
| 90 void CpuFeatures::PrintFeatures() { | 99 void CpuFeatures::PrintFeatures() { |
| (...skipping 3312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3403 | 3412 |
| 3404 | 3413 |
| 3405 bool RelocInfo::IsInConstantPool() { | 3414 bool RelocInfo::IsInConstantPool() { |
| 3406 return false; | 3415 return false; |
| 3407 } | 3416 } |
| 3408 | 3417 |
| 3409 | 3418 |
| 3410 } } // namespace v8::internal | 3419 } } // namespace v8::internal |
| 3411 | 3420 |
| 3412 #endif // V8_TARGET_ARCH_X64 | 3421 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |