Chromium Code Reviews| Index: src/ia32/assembler-ia32.cc |
| diff --git a/src/ia32/assembler-ia32.cc b/src/ia32/assembler-ia32.cc |
| index 19e69b319121dc786f6695706641a320e860874e..7368f4a0582afbc79893df8740f1a86c13325c53 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" |
| @@ -61,13 +58,13 @@ namespace internal { |
| namespace { |
| -bool EnableAVX() { |
| +bool OSHasAVXSupport() { |
| #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,21 +75,27 @@ 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; |
| + // 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 |
|
Jakob Kummerow
2015/01/27 09:07:34
nit: indentation. (Or not, if clang-format doesn't
|
| + mov flags, eax |
| + } |
| +#endif |
| + return (flags & 6) == 6; |
| } |
| } // namespace |
| @@ -108,8 +111,14 @@ void CpuFeatures::ProbeImpl(bool cross_compile) { |
| if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1; |
| if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3; |
| - if (cpu.has_avx() && EnableAVX()) supported_ |= 1u << AVX; |
| - if (cpu.has_fma3() && FLAG_enable_fma3) supported_ |= 1u << FMA3; |
| + if (cpu.has_avx() && FLAG_enable_avx && cpu.has_osxsave() && |
| + OSHasAVXSupport()) { |
| + supported_ |= 1u << AVX; |
| + } |
| + if (cpu.has_fma3() && FLAG_enable_fma3 && cpu.has_osxsave() && |
| + OSHasAVXSupport()) { |
| + supported_ |= 1u << FMA3; |
| + } |
| if (strcmp(FLAG_mcpu, "auto") == 0) { |
| if (cpu.is_atom()) supported_ |= 1u << ATOM; |
| } else if (strcmp(FLAG_mcpu, "atom") == 0) { |