Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: src/ia32/assembler-ia32.cc

Issue 878063002: [x86] Disable AVX unless the operating system explicitly claims to support it. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix compilation. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/base/cpu.cc ('k') | src/x64/assembler-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. 1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved. 2 // All Rights Reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions 5 // modification, are permitted provided that the following conditions
6 // are met: 6 // are met:
7 // 7 //
8 // - Redistributions of source code must retain the above copyright notice, 8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer. 9 // this list of conditions and the following disclaimer.
10 // 10 //
(...skipping 22 matching lines...) Expand all
33 // The original source code covered by the above license above has been modified 33 // The original source code covered by the above license above has been modified
34 // significantly by Google Inc. 34 // significantly by Google Inc.
35 // Copyright 2012 the V8 project authors. All rights reserved. 35 // Copyright 2012 the V8 project authors. All rights reserved.
36 36
37 #include "src/ia32/assembler-ia32.h" 37 #include "src/ia32/assembler-ia32.h"
38 38
39 #include <cstring> 39 #include <cstring>
40 40
41 #if V8_TARGET_ARCH_IA32 41 #if V8_TARGET_ARCH_IA32
42 42
43 #if V8_LIBC_MSVCRT
44 #include <intrin.h> // _xgetbv()
45 #endif
43 #if V8_OS_MACOSX 46 #if V8_OS_MACOSX
44 #include <sys/sysctl.h> 47 #include <sys/sysctl.h>
45 #endif 48 #endif
46 49
47 #include "src/base/bits.h" 50 #include "src/base/bits.h"
48 #include "src/base/cpu.h" 51 #include "src/base/cpu.h"
49 #if V8_OS_WIN
50 #include "src/base/win32-headers.h"
51 #endif
52 #include "src/disassembler.h" 52 #include "src/disassembler.h"
53 #include "src/macro-assembler.h" 53 #include "src/macro-assembler.h"
54 #include "src/v8.h" 54 #include "src/v8.h"
55 55
56 namespace v8 { 56 namespace v8 {
57 namespace internal { 57 namespace internal {
58 58
59 // ----------------------------------------------------------------------------- 59 // -----------------------------------------------------------------------------
60 // Implementation of CpuFeatures 60 // Implementation of CpuFeatures
61 61
62 namespace { 62 namespace {
63 63
64 bool EnableAVX() { 64 #if !V8_LIBC_MSVCRT
65
66 V8_INLINE uint64_t _xgetbv(unsigned int xcr) {
67 unsigned eax, edx;
68 // Check xgetbv; this uses a .byte sequence instead of the instruction
69 // directly because older assemblers do not include support for xgetbv and
70 // there is no easy way to conditionally compile based on the assembler
71 // used.
72 __asm__ volatile(".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"(xcr));
73 return static_cast<uint64_t>(eax) | (static_cast<uint64_t>(edx) << 32);
74 }
75
76 #define _XCR_XFEATURE_ENABLED_MASK 0
77
78 #endif // !V8_LIBC_MSVCRT
79
80
81 bool OSHasAVXSupport() {
65 #if V8_OS_MACOSX 82 #if V8_OS_MACOSX
66 // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being 83 // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being
67 // caused by ISRs, so we detect that here and disable AVX in that case. 84 // caused by ISRs, so we detect that here and disable AVX in that case.
68 char buffer[128]; 85 char buffer[128];
69 size_t buffer_size = arraysize(buffer); 86 size_t buffer_size = arraysize(buffer);
70 int ctl_name[] = { CTL_KERN , KERN_OSRELEASE }; 87 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE};
71 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { 88 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) {
72 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); 89 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version");
73 } 90 }
74 // The buffer now contains a string of the form XX.YY.ZZ, where 91 // The buffer now contains a string of the form XX.YY.ZZ, where
75 // XX is the major kernel version component. 92 // XX is the major kernel version component.
76 char* period_pos = strchr(buffer, '.'); 93 char* period_pos = strchr(buffer, '.');
77 DCHECK_NOT_NULL(period_pos); 94 DCHECK_NOT_NULL(period_pos);
78 *period_pos = '\0'; 95 *period_pos = '\0';
79 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT 96 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT
80 if (kernel_version_major <= 13) return false; 97 if (kernel_version_major <= 13) return false;
81 #elif V8_OS_WIN
82 // The same problem seems to appear on Windows XP and Vista.
83 OSVERSIONINFOEX osvi;
84 DWORDLONG mask = 0;
85 memset(&osvi, 0, sizeof(osvi));
86 osvi.dwOSVersionInfoSize = sizeof(osvi);
87 osvi.dwMajorVersion = 6;
88 osvi.dwMinorVersion = 1;
89 VER_SET_CONDITION(mask, VER_MAJORVERSION, VER_GREATER_EQUAL);
90 VER_SET_CONDITION(mask, VER_MINORVERSION, VER_GREATER_EQUAL);
91 if (!VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, mask)) {
92 return false;
93 }
94 #endif // V8_OS_MACOSX 98 #endif // V8_OS_MACOSX
95 return FLAG_enable_avx; 99 // Check whether OS claims to support AVX.
100 uint64_t feature_mask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
101 return (feature_mask & 0x6) == 0x6;
96 } 102 }
97 103
98 } // namespace 104 } // namespace
99 105
100 106
101 void CpuFeatures::ProbeImpl(bool cross_compile) { 107 void CpuFeatures::ProbeImpl(bool cross_compile) {
102 base::CPU cpu; 108 base::CPU cpu;
103 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. 109 CHECK(cpu.has_sse2()); // SSE2 support is mandatory.
104 CHECK(cpu.has_cmov()); // CMOV support is mandatory. 110 CHECK(cpu.has_cmov()); // CMOV support is mandatory.
105 111
106 // Only use statically determined features for cross compile (snapshot). 112 // Only use statically determined features for cross compile (snapshot).
107 if (cross_compile) return; 113 if (cross_compile) return;
108 114
109 if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1; 115 if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1;
110 if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3; 116 if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3;
111 if (cpu.has_avx() && EnableAVX()) supported_ |= 1u << AVX; 117 if (cpu.has_avx() && FLAG_enable_avx && cpu.has_osxsave() &&
112 if (cpu.has_fma3() && FLAG_enable_fma3) supported_ |= 1u << FMA3; 118 OSHasAVXSupport()) {
119 supported_ |= 1u << AVX;
120 }
121 if (cpu.has_fma3() && FLAG_enable_fma3 && cpu.has_osxsave() &&
122 OSHasAVXSupport()) {
123 supported_ |= 1u << FMA3;
124 }
113 if (strcmp(FLAG_mcpu, "auto") == 0) { 125 if (strcmp(FLAG_mcpu, "auto") == 0) {
114 if (cpu.is_atom()) supported_ |= 1u << ATOM; 126 if (cpu.is_atom()) supported_ |= 1u << ATOM;
115 } else if (strcmp(FLAG_mcpu, "atom") == 0) { 127 } else if (strcmp(FLAG_mcpu, "atom") == 0) {
116 supported_ |= 1u << ATOM; 128 supported_ |= 1u << ATOM;
117 } 129 }
118 } 130 }
119 131
120 132
121 void CpuFeatures::PrintTarget() { } 133 void CpuFeatures::PrintTarget() { }
122 void CpuFeatures::PrintFeatures() { 134 void CpuFeatures::PrintFeatures() {
(...skipping 2676 matching lines...) Expand 10 before | Expand all | Expand 10 after
2799 fprintf(coverage_log, "%s\n", file_line); 2811 fprintf(coverage_log, "%s\n", file_line);
2800 fflush(coverage_log); 2812 fflush(coverage_log);
2801 } 2813 }
2802 } 2814 }
2803 2815
2804 #endif 2816 #endif
2805 2817
2806 } } // namespace v8::internal 2818 } } // namespace v8::internal
2807 2819
2808 #endif // V8_TARGET_ARCH_IA32 2820 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/base/cpu.cc ('k') | src/x64/assembler-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698