Bug 1334777 - Hide unused has_avx() if CXXFLAGS have -mavx. r=glandium a=gchang
authorJan Beich <jbeich@FreeBSD.org>
Sat, 28 Jan 2017 10:51:06 +0000
changeset 376173 85ae3b00692108495df1d7c54cc5fd3d70e74137
parent 376172 c682c0d49f8c006cbb7ab706357c7303e6228c35
child 376174 c6d0cc154d82c3b3a7af5893e45e6e9313f6e9c1
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, gchang
bugs1334777
milestone53.0a2
Bug 1334777 - Hide unused has_avx() if CXXFLAGS have -mavx. r=glandium a=gchang MozReview-Commit-ID: 1IWEU8HrmtW
mozglue/build/SSE.cpp
--- a/mozglue/build/SSE.cpp
+++ b/mozglue/build/SSE.cpp
@@ -37,21 +37,23 @@ has_cpuid_bits(unsigned int level, CPUID
   __cpuid_count(level, 0, eax, ebx, ecx, edx);
   regs[0] = eax;
   regs[1] = ebx;
   regs[2] = ecx;
   regs[3] = edx;
   return (regs[reg] & bits) == bits;
 }
 
+#if !defined(MOZILLA_PRESUME_AVX)
 static uint64_t xgetbv(uint32_t xcr) {
     uint32_t eax, edx;
     __asm__ ( ".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"(xcr));
     return (uint64_t)(edx) << 32 | eax;
 }
+#endif
 
 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64))
 
 enum CPUIDRegister { eax = 0, ebx = 1, ecx = 2, edx = 3 };
 
 static bool
 has_cpuid_bits(unsigned int level, CPUIDRegister reg, unsigned int bits)
 {
@@ -61,17 +63,19 @@ has_cpuid_bits(unsigned int level, CPUID
   if (unsigned(regs[0]) < level)
     return false;
 
   // "The __cpuid intrinsic clears the ECX register before calling the cpuid instruction."
   __cpuid(regs, level);
   return (unsigned(regs[reg]) & bits) == bits;
 }
 
+#if !defined(MOZILLA_PRESUME_AVX)
 static uint64_t xgetbv(uint32_t xcr) { return _xgetbv(xcr); }
+#endif
 
 #elif (defined(__GNUC__) || defined(__SUNPRO_CC)) && (defined(__i386) || defined(__x86_64__))
 
 enum CPUIDRegister { eax = 0, ebx = 1, ecx = 2, edx = 3 };
 
 #ifdef __i386
 static void
 moz_cpuid(int CPUInfo[4], int InfoType)
@@ -162,30 +166,36 @@ namespace sse_private {
 #if !defined(MOZILLA_PRESUME_SSE4_1)
   bool sse4_1_enabled = has_cpuid_bits(1u, ecx, (1u<<19));
 #endif
 
 #if !defined(MOZILLA_PRESUME_SSE4_2)
   bool sse4_2_enabled = has_cpuid_bits(1u, ecx, (1u<<20));
 #endif
 
+#if !defined(MOZILLA_PRESUME_AVX) || !defined(MOZILLA_PRESUME_AVX2)
   static bool has_avx()
   {
+#if defined(MOZILLA_PRESUME_AVX)
+      return true;
+#else
       const unsigned AVX = 1u << 28;
       const unsigned OSXSAVE = 1u << 27;
       const unsigned XSAVE = 1u << 26;
 
       const unsigned XMM_STATE = 1u << 1;
       const unsigned YMM_STATE = 1u << 2;
       const unsigned AVX_STATE = XMM_STATE | YMM_STATE;
 
       return has_cpuid_bits(1u, ecx, AVX | OSXSAVE | XSAVE) &&
           // ensure the OS supports XSAVE of YMM registers
           (xgetbv(0) & AVX_STATE) == AVX_STATE;
+#endif // MOZILLA_PRESUME_AVX
   }
+#endif // !MOZILLA_PRESUME_AVX || !MOZILLA_PRESUME_AVX2
 
 #if !defined(MOZILLA_PRESUME_AVX)
   bool avx_enabled = has_avx();
 #endif
 
 #if !defined(MOZILLA_PRESUME_AVX2)
   bool avx2_enabled = has_avx() && has_cpuid_bits(7u, ebx, (1u<<5));
 #endif