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_LIBC_MSVCRT |
| 12 #include <intrin.h> // _xgetbv() |
| 13 #endif |
11 #if V8_OS_MACOSX | 14 #if V8_OS_MACOSX |
12 #include <sys/sysctl.h> | 15 #include <sys/sysctl.h> |
13 #endif | 16 #endif |
14 | 17 |
15 #include "src/base/bits.h" | 18 #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" | 19 #include "src/macro-assembler.h" |
20 #include "src/v8.h" | 20 #include "src/v8.h" |
21 | 21 |
22 namespace v8 { | 22 namespace v8 { |
23 namespace internal { | 23 namespace internal { |
24 | 24 |
25 // ----------------------------------------------------------------------------- | 25 // ----------------------------------------------------------------------------- |
26 // Implementation of CpuFeatures | 26 // Implementation of CpuFeatures |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 bool EnableAVX() { | 30 #if !V8_LIBC_MSVCRT |
| 31 |
| 32 V8_INLINE uint64_t _xgetbv(unsigned int xcr) { |
| 33 unsigned eax, edx; |
| 34 // Check xgetbv; this uses a .byte sequence instead of the instruction |
| 35 // directly because older assemblers do not include support for xgetbv and |
| 36 // there is no easy way to conditionally compile based on the assembler |
| 37 // used. |
| 38 __asm__ volatile(".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"(xcr)); |
| 39 return static_cast<uint64_t>(eax) | (static_cast<uint64_t>(edx) << 32); |
| 40 } |
| 41 |
| 42 #define _XCR_XFEATURE_ENABLED_MASK 0 |
| 43 |
| 44 #endif // !V8_LIBC_MSVCRT |
| 45 |
| 46 |
| 47 bool OSHasAVXSupport() { |
31 #if V8_OS_MACOSX | 48 #if V8_OS_MACOSX |
32 // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being | 49 // 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. | 50 // caused by ISRs, so we detect that here and disable AVX in that case. |
34 char buffer[128]; | 51 char buffer[128]; |
35 size_t buffer_size = arraysize(buffer); | 52 size_t buffer_size = arraysize(buffer); |
36 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE}; | 53 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE}; |
37 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { | 54 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { |
38 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); | 55 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); |
39 } | 56 } |
40 // The buffer now contains a string of the form XX.YY.ZZ, where | 57 // The buffer now contains a string of the form XX.YY.ZZ, where |
41 // XX is the major kernel version component. | 58 // XX is the major kernel version component. |
42 char* period_pos = strchr(buffer, '.'); | 59 char* period_pos = strchr(buffer, '.'); |
43 DCHECK_NOT_NULL(period_pos); | 60 DCHECK_NOT_NULL(period_pos); |
44 *period_pos = '\0'; | 61 *period_pos = '\0'; |
45 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT | 62 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT |
46 if (kernel_version_major <= 13) return false; | 63 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 | 64 #endif // V8_OS_MACOSX |
61 return FLAG_enable_avx; | 65 // Check whether OS claims to support AVX. |
| 66 uint64_t feature_mask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK); |
| 67 return (feature_mask & 0x6) == 0x6; |
62 } | 68 } |
63 | 69 |
64 } // namespace | 70 } // namespace |
65 | 71 |
66 | 72 |
67 void CpuFeatures::ProbeImpl(bool cross_compile) { | 73 void CpuFeatures::ProbeImpl(bool cross_compile) { |
68 base::CPU cpu; | 74 base::CPU cpu; |
69 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. | 75 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. |
70 CHECK(cpu.has_cmov()); // CMOV support is mandatory. | 76 CHECK(cpu.has_cmov()); // CMOV support is mandatory. |
71 | 77 |
72 // Only use statically determined features for cross compile (snapshot). | 78 // Only use statically determined features for cross compile (snapshot). |
73 if (cross_compile) return; | 79 if (cross_compile) return; |
74 | 80 |
75 if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1; | 81 if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1; |
76 if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3; | 82 if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3; |
77 // SAHF is not generally available in long mode. | 83 // SAHF is not generally available in long mode. |
78 if (cpu.has_sahf() && FLAG_enable_sahf) supported_ |= 1u << SAHF; | 84 if (cpu.has_sahf() && FLAG_enable_sahf) supported_ |= 1u << SAHF; |
79 if (cpu.has_avx() && EnableAVX()) supported_ |= 1u << AVX; | 85 if (cpu.has_avx() && FLAG_enable_avx && cpu.has_osxsave() && |
80 if (cpu.has_fma3() && FLAG_enable_fma3) supported_ |= 1u << FMA3; | 86 OSHasAVXSupport()) { |
| 87 supported_ |= 1u << AVX; |
| 88 } |
| 89 if (cpu.has_fma3() && FLAG_enable_fma3 && cpu.has_osxsave() && |
| 90 OSHasAVXSupport()) { |
| 91 supported_ |= 1u << FMA3; |
| 92 } |
81 if (strcmp(FLAG_mcpu, "auto") == 0) { | 93 if (strcmp(FLAG_mcpu, "auto") == 0) { |
82 if (cpu.is_atom()) supported_ |= 1u << ATOM; | 94 if (cpu.is_atom()) supported_ |= 1u << ATOM; |
83 } else if (strcmp(FLAG_mcpu, "atom") == 0) { | 95 } else if (strcmp(FLAG_mcpu, "atom") == 0) { |
84 supported_ |= 1u << ATOM; | 96 supported_ |= 1u << ATOM; |
85 } | 97 } |
86 } | 98 } |
87 | 99 |
88 | 100 |
89 void CpuFeatures::PrintTarget() { } | 101 void CpuFeatures::PrintTarget() { } |
90 void CpuFeatures::PrintFeatures() { | 102 void CpuFeatures::PrintFeatures() { |
(...skipping 3312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3403 | 3415 |
3404 | 3416 |
3405 bool RelocInfo::IsInConstantPool() { | 3417 bool RelocInfo::IsInConstantPool() { |
3406 return false; | 3418 return false; |
3407 } | 3419 } |
3408 | 3420 |
3409 | 3421 |
3410 } } // namespace v8::internal | 3422 } } // namespace v8::internal |
3411 | 3423 |
3412 #endif // V8_TARGET_ARCH_X64 | 3424 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |