Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 OSHasAVXSupport() { |
| 65 #if V8_OS_MACOSX | 62 #if V8_OS_MACOSX |
| 66 // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being | 63 // 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. | 64 // caused by ISRs, so we detect that here and disable AVX in that case. |
| 68 char buffer[128]; | 65 char buffer[128]; |
| 69 size_t buffer_size = arraysize(buffer); | 66 size_t buffer_size = arraysize(buffer); |
| 70 int ctl_name[] = { CTL_KERN , KERN_OSRELEASE }; | 67 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE}; |
| 71 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { | 68 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { |
| 72 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); | 69 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); |
| 73 } | 70 } |
| 74 // The buffer now contains a string of the form XX.YY.ZZ, where | 71 // The buffer now contains a string of the form XX.YY.ZZ, where |
| 75 // XX is the major kernel version component. | 72 // XX is the major kernel version component. |
| 76 char* period_pos = strchr(buffer, '.'); | 73 char* period_pos = strchr(buffer, '.'); |
| 77 DCHECK_NOT_NULL(period_pos); | 74 DCHECK_NOT_NULL(period_pos); |
| 78 *period_pos = '\0'; | 75 *period_pos = '\0'; |
| 79 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT | 76 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT |
| 80 if (kernel_version_major <= 13) return false; | 77 if (kernel_version_major <= 13) return false; |
| 81 #elif V8_OS_WIN | 78 #endif // V8_OS_MACOSX |
| 82 // The same problem seems to appear on Windows XP and Vista. | 79 // Check whether OS claims to support AVX. |
| 83 OSVERSIONINFOEX osvi; | 80 int flags = 0; |
| 84 DWORDLONG mask = 0; | 81 #if V8_CC_GNU |
| 85 memset(&osvi, 0, sizeof(osvi)); | 82 // Check xgetbv; this uses a .byte sequence instead of the instruction |
| 86 osvi.dwOSVersionInfoSize = sizeof(osvi); | 83 // directly because older assemblers do not include support for xgetbv and |
| 87 osvi.dwMajorVersion = 6; | 84 // there is no easy way to conditionally compile based on the assembler used. |
| 88 osvi.dwMinorVersion = 1; | 85 __asm__ __volatile__(".byte 0x0f, 0x01, 0xd0" |
| 89 VER_SET_CONDITION(mask, VER_MAJORVERSION, VER_GREATER_EQUAL); | 86 : "=a"(flags) |
| 90 VER_SET_CONDITION(mask, VER_MINORVERSION, VER_GREATER_EQUAL); | 87 : "c"(0) |
| 91 if (!VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, mask)) { | 88 : "%edx"); |
| 92 return false; | 89 #elif V8_CC_MSVC |
| 90 __asm { | |
| 91 xor ecx, ecx // ecx = 0 | |
| 92 // Use the raw opcode for xgetbv for compatibility with older | |
| 93 // toolchains. | |
| 94 __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
| |
| 95 mov flags, eax | |
| 93 } | 96 } |
| 94 #endif // V8_OS_MACOSX | 97 #endif |
| 95 return FLAG_enable_avx; | 98 return (flags & 6) == 6; |
| 96 } | 99 } |
| 97 | 100 |
| 98 } // namespace | 101 } // namespace |
| 99 | 102 |
| 100 | 103 |
| 101 void CpuFeatures::ProbeImpl(bool cross_compile) { | 104 void CpuFeatures::ProbeImpl(bool cross_compile) { |
| 102 base::CPU cpu; | 105 base::CPU cpu; |
| 103 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. | 106 CHECK(cpu.has_sse2()); // SSE2 support is mandatory. |
| 104 CHECK(cpu.has_cmov()); // CMOV support is mandatory. | 107 CHECK(cpu.has_cmov()); // CMOV support is mandatory. |
| 105 | 108 |
| 106 // Only use statically determined features for cross compile (snapshot). | 109 // Only use statically determined features for cross compile (snapshot). |
| 107 if (cross_compile) return; | 110 if (cross_compile) return; |
| 108 | 111 |
| 109 if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1; | 112 if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1; |
| 110 if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3; | 113 if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3; |
| 111 if (cpu.has_avx() && EnableAVX()) supported_ |= 1u << AVX; | 114 if (cpu.has_avx() && FLAG_enable_avx && cpu.has_osxsave() && |
| 112 if (cpu.has_fma3() && FLAG_enable_fma3) supported_ |= 1u << FMA3; | 115 OSHasAVXSupport()) { |
| 116 supported_ |= 1u << AVX; | |
| 117 } | |
| 118 if (cpu.has_fma3() && FLAG_enable_fma3 && cpu.has_osxsave() && | |
| 119 OSHasAVXSupport()) { | |
| 120 supported_ |= 1u << FMA3; | |
| 121 } | |
| 113 if (strcmp(FLAG_mcpu, "auto") == 0) { | 122 if (strcmp(FLAG_mcpu, "auto") == 0) { |
| 114 if (cpu.is_atom()) supported_ |= 1u << ATOM; | 123 if (cpu.is_atom()) supported_ |= 1u << ATOM; |
| 115 } else if (strcmp(FLAG_mcpu, "atom") == 0) { | 124 } else if (strcmp(FLAG_mcpu, "atom") == 0) { |
| 116 supported_ |= 1u << ATOM; | 125 supported_ |= 1u << ATOM; |
| 117 } | 126 } |
| 118 } | 127 } |
| 119 | 128 |
| 120 | 129 |
| 121 void CpuFeatures::PrintTarget() { } | 130 void CpuFeatures::PrintTarget() { } |
| 122 void CpuFeatures::PrintFeatures() { | 131 void CpuFeatures::PrintFeatures() { |
| (...skipping 2676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2799 fprintf(coverage_log, "%s\n", file_line); | 2808 fprintf(coverage_log, "%s\n", file_line); |
| 2800 fflush(coverage_log); | 2809 fflush(coverage_log); |
| 2801 } | 2810 } |
| 2802 } | 2811 } |
| 2803 | 2812 |
| 2804 #endif | 2813 #endif |
| 2805 | 2814 |
| 2806 } } // namespace v8::internal | 2815 } } // namespace v8::internal |
| 2807 | 2816 |
| 2808 #endif // V8_TARGET_ARCH_IA32 | 2817 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |