Bug 1160148 - Disable CRT use of FMA3 on non-AVX2 processors. r=froydnj, a=lmandel
authorDavid Major <dmajor@mozilla.com>
Thu, 14 May 2015 08:25:00 -0400
changeset 274615 87d556c9f685320fea0105280532fb0186db4128
parent 274614 65b16a4f88c8946c4b5e01fa1af537bc1852d786
child 274616 b40e595a89a637cc41f6df430b7cfa03d5d59b2d
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, lmandel
bugs1160148
milestone40.0a2
Bug 1160148 - Disable CRT use of FMA3 on non-AVX2 processors. r=froydnj, a=lmandel
mozglue/build/WindowsDllBlocklist.cpp
toolkit/xre/nsWindowsWMain.cpp
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -697,16 +697,31 @@ continue_loading:
 
 WindowsDllInterceptor NtDllIntercept;
 
 } // anonymous namespace
 
 NS_EXPORT void
 DllBlocklist_Initialize()
 {
+#if defined(_MSC_VER) && _MSC_VER < 1900 && defined(_M_X64)
+  // The code below is not blocklist-related, but is the best place for it.
+  // This is the earliest place where msvcr120.dll is loaded, and this
+  // codepath is used by both firefox.exe and plugin-container.exe processes.
+
+  // Disable CRT use of FMA3 on non-AVX2 CPUs and on Win7RTM due to bug 1160148
+  int cpuid0[4] = {0};
+  int cpuid7[4] = {0};
+  __cpuid(cpuid0, 0); // Get the maximum supported CPUID function
+  __cpuid(cpuid7, 7); // AVX2 is function 7, subfunction 0, EBX, bit 5
+  if (cpuid0[0] < 7 || !(cpuid7[1] & 0x20) || !IsWin7SP1OrLater()) {
+    _set_FMA3_enable(0);
+  }
+#endif
+
   if (GetModuleHandleA("user32.dll")) {
     sUser32BeforeBlocklist = true;
   }
 
   NtDllIntercept.Init("ntdll.dll");
 
   ReentrancySentinel::InitializeStatics();
 
--- a/toolkit/xre/nsWindowsWMain.cpp
+++ b/toolkit/xre/nsWindowsWMain.cpp
@@ -8,16 +8,17 @@
 
 #ifndef XP_WIN
 #error This file only makes sense on Windows.
 #endif
 
 #include "nsUTF8Utils.h"
 #include <intrin.h>
 #include <math.h>
+#include "mozilla/WindowsVersion.h"
 
 #ifndef XRE_DONT_PROTECT_DLL_LOAD
 #include "nsSetDllDirectory.h"
 #endif
 
 #if defined(__GNUC__)
 #define XRE_DONT_SUPPORT_XPSP2
 #endif
@@ -86,22 +87,22 @@ FreeAllocStrings(int argc, char **argv)
 
 int wmain(int argc, WCHAR **argv)
 {
 #if !defined(XRE_DONT_SUPPORT_XPSP2)
   WindowsCrtPatch::Init();
 #endif
 
 #if defined(_MSC_VER) && _MSC_VER < 1900 && defined(_M_X64)
-  // Disable CRT use of FMA3 on non-AVX2 processors because of bug 1160148
+  // Disable CRT use of FMA3 on non-AVX2 CPUs and on Win7RTM due to bug 1160148
   int cpuid0[4] = {0};
   int cpuid7[4] = {0};
   __cpuid(cpuid0, 0); // Get the maximum supported CPUID function
   __cpuid(cpuid7, 7); // AVX2 is function 7, subfunction 0, EBX, bit 5
-  if (cpuid0[0] < 7 || !(cpuid7[1] & 0x20)) {
+  if (cpuid0[0] < 7 || !(cpuid7[1] & 0x20) || !mozilla::IsWin7SP1OrLater()) {
     _set_FMA3_enable(0);
   }
 #endif
 
 #ifndef XRE_DONT_PROTECT_DLL_LOAD
   mozilla::SanitizeEnvironmentVariables();
   SetDllDirectoryW(L"");
 #endif