From d536ec53bb775fa7286715011167fe25b3561f05 Mon Sep 17 00:00:00 2001 From: Tom Ritter Date: Tue, 10 Dec 2019 18:41:41 +0000 Subject: [PATCH] Bug 1590624 - mingw-clang cannot use _xgetbv without -mavx, work around it r=lsalzman,froydnj Differential Revision: https://phabricator.services.mozilla.com/D54531 --HG-- extra : moz-landing-system : lando --- gfx/skia/skia/src/core/SkCpu.cpp | 2 +- mozglue/build/SSE.cpp | 23 +++++++++++------------ mozglue/build/SSE.h | 4 ++++ widget/windows/GfxInfo.cpp | 5 ++--- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/gfx/skia/skia/src/core/SkCpu.cpp b/gfx/skia/skia/src/core/SkCpu.cpp index 54bf0c7ca809..bdae9d3a8a65 100644 --- a/gfx/skia/skia/src/core/SkCpu.cpp +++ b/gfx/skia/skia/src/core/SkCpu.cpp @@ -11,7 +11,7 @@ #include "src/core/SkCpu.h" #if defined(SK_CPU_X86) - #if defined(SK_BUILD_FOR_WIN) + #if defined(SK_BUILD_FOR_WIN) && !defined(__MINGW32__) #include static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); } static void cpuid7(uint32_t abcd[4]) { __cpuidex((int*)abcd, 7, 0); } diff --git a/mozglue/build/SSE.cpp b/mozglue/build/SSE.cpp index 403c653c817a..b3c9a5722492 100644 --- a/mozglue/build/SSE.cpp +++ b/mozglue/build/SSE.cpp @@ -40,14 +40,6 @@ static bool has_cpuid_bits(unsigned int level, CPUIDRegister reg, 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 }; @@ -65,10 +57,6 @@ static bool has_cpuid_bits(unsigned int level, CPUIDRegister reg, 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__)) @@ -194,4 +182,15 @@ bool aes_enabled = has_cpuid_bits(1u, ecx, (1u << 25)); #endif } // namespace sse_private + +#ifdef HAVE_CPUID_H + +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 + } // namespace mozilla diff --git a/mozglue/build/SSE.h b/mozglue/build/SSE.h index bd618c4680b1..8a2e66824754 100644 --- a/mozglue/build/SSE.h +++ b/mozglue/build/SSE.h @@ -227,6 +227,10 @@ extern bool MFBT_DATA aes_enabled; #endif } // namespace sse_private +#ifdef HAVE_CPUID_H +MOZ_EXPORT uint64_t xgetbv(uint32_t xcr); +#endif + #if defined(MOZILLA_PRESUME_MMX) # define MOZILLA_MAY_SUPPORT_MMX 1 inline bool supports_mmx() { return true; } diff --git a/widget/windows/GfxInfo.cpp b/widget/windows/GfxInfo.cpp index 24392a4f62d6..366f9b811b68 100644 --- a/widget/windows/GfxInfo.cpp +++ b/widget/windows/GfxInfo.cpp @@ -17,6 +17,7 @@ #include "mozilla/Preferences.h" #include "mozilla/gfx/DeviceManagerDx.h" #include "mozilla/gfx/Logging.h" +#include "mozilla/SSE.h" #include "nsExceptionHandler.h" #include "nsPrintfCString.h" #include "jsapi.h" @@ -32,8 +33,6 @@ using namespace mozilla::widget; NS_IMPL_ISUPPORTS_INHERITED(GfxInfo, GfxInfoBase, nsIGfxInfoDebug) #endif -static const uint32_t allWindowsVersions = 0xffffffff; - GfxInfo::GfxInfo() : mWindowsVersion(0), mActiveGPUIndex(0), mHasDualGPU(false) {} @@ -1098,7 +1097,7 @@ static inline bool DetectBrokenAVX() { } const unsigned AVX_CTRL_BITS = (1 << 1) | (1 << 2); - return (_xgetbv(0) & AVX_CTRL_BITS) != AVX_CTRL_BITS; + return (xgetbv(0) & AVX_CTRL_BITS) != AVX_CTRL_BITS; } #endif