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

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

Issue 874103004: [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: Created 5 years, 10 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 | « no previous file | 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 28 matching lines...) Expand all
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_OS_MACOSX 43 #if V8_OS_MACOSX
44 #include <sys/sysctl.h> 44 #include <sys/sysctl.h>
45 #endif 45 #endif
46 46
47 #include "src/base/bits.h" 47 #include "src/base/bits.h"
48 #include "src/base/cpu.h" 48 #include "src/base/cpu.h"
49 #if V8_OS_WIN
50 #include "src/base/win32-headers.h"
51 #endif
52 #include "src/disassembler.h" 49 #include "src/disassembler.h"
53 #include "src/macro-assembler.h" 50 #include "src/macro-assembler.h"
54 #include "src/v8.h" 51 #include "src/v8.h"
55 52
56 namespace v8 { 53 namespace v8 {
57 namespace internal { 54 namespace internal {
58 55
59 // ----------------------------------------------------------------------------- 56 // -----------------------------------------------------------------------------
60 // Implementation of CpuFeatures 57 // Implementation of CpuFeatures
61 58
62 namespace { 59 namespace {
63 60
64 bool EnableAVX() { 61 bool EnableAVX() {
62 // Check whether OS claims to support AVX.
63 int flags = 0;
64 #if V8_CC_GNU
65 // Check xgetbv; this uses a .byte sequence instead of the instruction
66 // directly because older assemblers do not include support for xgetbv and
67 // there is no easy way to conditionally compile based on the assembler used.
68 asm volatile(".byte 0x0f, 0x01, 0xd0" : "=a"(flags) : "c"(0) : "%edx");
69 #elif V8_CC_MSVC
70 __asm {
71 xor ecx, ecx // ecx = 0
72 // Use the raw opcode for xgetbv for compatibility with older
73 // toolchains.
74 __asm _emit 0x0f __asm _emit 0x01 __asm _emit 0xd0
75 mov flags, eax
76 }
77 #endif
78 if ((flags & 6) == 0) return false;
65 #if V8_OS_MACOSX 79 #if V8_OS_MACOSX
66 // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being 80 // 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. 81 // caused by ISRs, so we detect that here and disable AVX in that case.
68 char buffer[128]; 82 char buffer[128];
69 size_t buffer_size = arraysize(buffer); 83 size_t buffer_size = arraysize(buffer);
70 int ctl_name[] = { CTL_KERN , KERN_OSRELEASE }; 84 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE};
71 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { 85 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) {
72 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); 86 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version");
73 } 87 }
74 // The buffer now contains a string of the form XX.YY.ZZ, where 88 // The buffer now contains a string of the form XX.YY.ZZ, where
75 // XX is the major kernel version component. 89 // XX is the major kernel version component.
76 char* period_pos = strchr(buffer, '.'); 90 char* period_pos = strchr(buffer, '.');
77 DCHECK_NOT_NULL(period_pos); 91 DCHECK_NOT_NULL(period_pos);
78 *period_pos = '\0'; 92 *period_pos = '\0';
79 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT 93 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT
80 if (kernel_version_major <= 13) return false; 94 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 95 #endif // V8_OS_MACOSX
95 return FLAG_enable_avx; 96 return FLAG_enable_avx;
96 } 97 }
97 98
98 } // namespace 99 } // namespace
99 100
100 101
101 void CpuFeatures::ProbeImpl(bool cross_compile) { 102 void CpuFeatures::ProbeImpl(bool cross_compile) {
102 base::CPU cpu; 103 base::CPU cpu;
103 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. 104 CHECK(cpu.has_sse2()); // SSE2 support is mandatory.
(...skipping 2695 matching lines...) Expand 10 before | Expand all | Expand 10 after
2799 fprintf(coverage_log, "%s\n", file_line); 2800 fprintf(coverage_log, "%s\n", file_line);
2800 fflush(coverage_log); 2801 fflush(coverage_log);
2801 } 2802 }
2802 } 2803 }
2803 2804
2804 #endif 2805 #endif
2805 2806
2806 } } // namespace v8::internal 2807 } } // namespace v8::internal
2807 2808
2808 #endif // V8_TARGET_ARCH_IA32 2809 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « no previous file | src/x64/assembler-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698