Reviewers: Jakob,
Description:
[x86] Disable AVX unless the operating system explicitly claims to support
it.
[email protected]
BUG=chromium:452033
LOG=y
Please review this at https://codereview.chromium.org/874103004/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+35, -33 lines):
M src/ia32/assembler-ia32.cc
M src/x64/assembler-x64.cc
Index: src/ia32/assembler-ia32.cc
diff --git a/src/ia32/assembler-ia32.cc b/src/ia32/assembler-ia32.cc
index
19e69b319121dc786f6695706641a320e860874e..79989384be86c02fff1b5641f3d3fffa2231869d
100644
--- a/src/ia32/assembler-ia32.cc
+++ b/src/ia32/assembler-ia32.cc
@@ -46,9 +46,6 @@
#include "src/base/bits.h"
#include "src/base/cpu.h"
-#if V8_OS_WIN
-#include "src/base/win32-headers.h"
-#endif
#include "src/disassembler.h"
#include "src/macro-assembler.h"
#include "src/v8.h"
@@ -62,12 +59,29 @@ namespace internal {
namespace {
bool EnableAVX() {
+ // Check whether OS claims to support AVX.
+ int flags = 0;
+#if V8_CC_GNU
+ // Check xgetbv; this uses a .byte sequence instead of the instruction
+ // directly because older assemblers do not include support for xgetbv
and
+ // there is no easy way to conditionally compile based on the assembler
used.
+ asm volatile(".byte 0x0f, 0x01, 0xd0" : "=a"(flags) : "c"(0) : "%edx");
+#elif V8_CC_MSVC
+ __asm {
+ xor ecx, ecx // ecx = 0
+ // Use the raw opcode for xgetbv for compatibility with older
+ // toolchains.
+ __asm _emit 0x0f __asm _emit 0x01 __asm _emit 0xd0
+ mov flags, eax
+ }
+#endif
+ if ((flags & 6) == 0) return false;
#if V8_OS_MACOSX
// Mac OS X up to 10.9 has a bug where AVX transitions were indeed being
// caused by ISRs, so we detect that here and disable AVX in that case.
char buffer[128];
size_t buffer_size = arraysize(buffer);
- int ctl_name[] = { CTL_KERN , KERN_OSRELEASE };
+ int ctl_name[] = {CTL_KERN, KERN_OSRELEASE};
if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) {
V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version");
}
@@ -78,19 +92,6 @@ bool EnableAVX() {
*period_pos = '\0';
long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT
if (kernel_version_major <= 13) return false;
-#elif V8_OS_WIN
- // The same problem seems to appear on Windows XP and Vista.
- OSVERSIONINFOEX osvi;
- DWORDLONG mask = 0;
- memset(&osvi, 0, sizeof(osvi));
- osvi.dwOSVersionInfoSize = sizeof(osvi);
- osvi.dwMajorVersion = 6;
- osvi.dwMinorVersion = 1;
- VER_SET_CONDITION(mask, VER_MAJORVERSION, VER_GREATER_EQUAL);
- VER_SET_CONDITION(mask, VER_MINORVERSION, VER_GREATER_EQUAL);
- if (!VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION,
mask)) {
- return false;
- }
#endif // V8_OS_MACOSX
return FLAG_enable_avx;
}
Index: src/x64/assembler-x64.cc
diff --git a/src/x64/assembler-x64.cc b/src/x64/assembler-x64.cc
index
1806d5d639dd10c0b30a4cf273500cb073c0b3b0..ecadf46289930e385a8a6400acff5a6637026ea9
100644
--- a/src/x64/assembler-x64.cc
+++ b/src/x64/assembler-x64.cc
@@ -13,9 +13,6 @@
#endif
#include "src/base/bits.h"
-#if V8_OS_WIN
-#include "src/base/win32-headers.h"
-#endif
#include "src/macro-assembler.h"
#include "src/v8.h"
@@ -28,6 +25,23 @@ namespace internal {
namespace {
bool EnableAVX() {
+ // Check whether OS claims to support AVX.
+ int flags = 0;
+#if V8_CC_GNU
+ // Check xgetbv; this uses a .byte sequence instead of the instruction
+ // directly because older assemblers do not include support for xgetbv
and
+ // there is no easy way to conditionally compile based on the assembler
used.
+ asm volatile(".byte 0x0f, 0x01, 0xd0" : "=a"(flags) : "c"(0) : "%edx");
+#elif V8_CC_MSVC
+ __asm {
+ xor ecx, ecx // ecx = 0
+ // Use the raw opcode for xgetbv for compatibility with older
+ // toolchains.
+ __asm _emit 0x0f __asm _emit 0x01 __asm _emit 0xd0
+ mov flags, eax
+ }
+#endif
+ if ((flags & 6) == 0) return false;
#if V8_OS_MACOSX
// Mac OS X up to 10.9 has a bug where AVX transitions were indeed being
// caused by ISRs, so we detect that here and disable AVX in that case.
@@ -44,19 +58,6 @@ bool EnableAVX() {
*period_pos = '\0';
long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT
if (kernel_version_major <= 13) return false;
-#elif V8_OS_WIN
- // The same problem seems to appear on Windows XP and Vista.
- OSVERSIONINFOEX osvi;
- DWORDLONG mask = 0;
- memset(&osvi, 0, sizeof(osvi));
- osvi.dwOSVersionInfoSize = sizeof(osvi);
- osvi.dwMajorVersion = 6;
- osvi.dwMinorVersion = 1;
- VER_SET_CONDITION(mask, VER_MAJORVERSION, VER_GREATER_EQUAL);
- VER_SET_CONDITION(mask, VER_MINORVERSION, VER_GREATER_EQUAL);
- if (!VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION,
mask)) {
- return false;
- }
#endif // V8_OS_MACOSX
return FLAG_enable_avx;
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.