Bug 1160148: Disable CRT use of FMA3 on non-AVX2 processors. r=froydnj
authorDavid Major <dmajor@mozilla.com>
Wed, 06 May 2015 16:12:09 -0400
changeset 274052 3bf223d7eedd8e192d465582691c1510d2f656c9
parent 274051 b1d38f4141afb97e8908b439d3e94d794e8fb1dc
child 274053 eb08fbc9aec2ba95fda90a805abfb2053e8de2c0
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
bugs1160148
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1160148: Disable CRT use of FMA3 on non-AVX2 processors. r=froydnj
toolkit/xre/nsWindowsWMain.cpp
--- a/toolkit/xre/nsWindowsWMain.cpp
+++ b/toolkit/xre/nsWindowsWMain.cpp
@@ -6,16 +6,18 @@
 // similar bootstrap code. It converts wide-character windows wmain into UTF-8
 // narrow-character strings.
 
 #ifndef XP_WIN
 #error This file only makes sense on Windows.
 #endif
 
 #include "nsUTF8Utils.h"
+#include <intrin.h>
+#include <math.h>
 
 #ifndef XRE_DONT_PROTECT_DLL_LOAD
 #include "nsSetDllDirectory.h"
 #endif
 
 #if defined(__GNUC__)
 #define XRE_DONT_SUPPORT_XPSP2
 #endif
@@ -83,16 +85,27 @@ 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
+  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)) {
+    _set_FMA3_enable(0);
+  }
+#endif
+
 #ifndef XRE_DONT_PROTECT_DLL_LOAD
   mozilla::SanitizeEnvironmentVariables();
   SetDllDirectoryW(L"");
 #endif
 
   char **argvConverted = new char*[argc + 1];
   if (!argvConverted)
     return 127;