Bug 1590624 - mingw-clang cannot use _xgetbv without -mavx, work around it r=lsalzman,froydnj

Differential Revision: https://phabricator.services.mozilla.com/D54531
This commit is contained in:
Tom Ritter
2019-12-12 06:38:39 +00:00
parent 6289f15f45
commit 5656ba84b9
4 changed files with 18 additions and 16 deletions

View File

@@ -11,7 +11,7 @@
#include "src/core/SkCpu.h" #include "src/core/SkCpu.h"
#if defined(SK_CPU_X86) #if defined(SK_CPU_X86)
#if defined(SK_BUILD_FOR_WIN) #if defined(SK_BUILD_FOR_WIN) && !defined(__MINGW32__)
#include <intrin.h> #include <intrin.h>
static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); } static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); }
static void cpuid7(uint32_t abcd[4]) { __cpuidex((int*)abcd, 7, 0); } static void cpuid7(uint32_t abcd[4]) { __cpuidex((int*)abcd, 7, 0); }

View File

@@ -40,14 +40,6 @@ static bool has_cpuid_bits(unsigned int level, CPUIDRegister reg,
return (regs[reg] & bits) == bits; 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)) #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64))
enum CPUIDRegister { eax = 0, ebx = 1, ecx = 2, edx = 3 }; 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; 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)) && \ #elif (defined(__GNUC__) || defined(__SUNPRO_CC)) && \
(defined(__i386) || defined(__x86_64__)) (defined(__i386) || defined(__x86_64__))
@@ -194,4 +182,15 @@ bool aes_enabled = has_cpuid_bits(1u, ecx, (1u << 25));
#endif #endif
} // namespace sse_private } // 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 } // namespace mozilla

View File

@@ -227,6 +227,10 @@ extern bool MFBT_DATA aes_enabled;
#endif #endif
} // namespace sse_private } // namespace sse_private
#ifdef HAVE_CPUID_H
MOZ_EXPORT uint64_t xgetbv(uint32_t xcr);
#endif
#if defined(MOZILLA_PRESUME_MMX) #if defined(MOZILLA_PRESUME_MMX)
# define MOZILLA_MAY_SUPPORT_MMX 1 # define MOZILLA_MAY_SUPPORT_MMX 1
inline bool supports_mmx() { return true; } inline bool supports_mmx() { return true; }

View File

@@ -17,6 +17,7 @@
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/gfx/DeviceManagerDx.h" #include "mozilla/gfx/DeviceManagerDx.h"
#include "mozilla/gfx/Logging.h" #include "mozilla/gfx/Logging.h"
#include "mozilla/SSE.h"
#include "nsExceptionHandler.h" #include "nsExceptionHandler.h"
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
#include "jsapi.h" #include "jsapi.h"
@@ -32,8 +33,6 @@ using namespace mozilla::widget;
NS_IMPL_ISUPPORTS_INHERITED(GfxInfo, GfxInfoBase, nsIGfxInfoDebug) NS_IMPL_ISUPPORTS_INHERITED(GfxInfo, GfxInfoBase, nsIGfxInfoDebug)
#endif #endif
static const uint32_t allWindowsVersions = 0xffffffff;
GfxInfo::GfxInfo() GfxInfo::GfxInfo()
: mWindowsVersion(0), mActiveGPUIndex(0), mHasDualGPU(false) {} : mWindowsVersion(0), mActiveGPUIndex(0), mHasDualGPU(false) {}
@@ -1098,7 +1097,7 @@ static inline bool DetectBrokenAVX() {
} }
const unsigned AVX_CTRL_BITS = (1 << 1) | (1 << 2); 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 #endif