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
This commit is contained in:
Tom Ritter 2019-12-10 18:41:41 +00:00
parent 6311ebf459
commit d536ec53bb
4 changed files with 18 additions and 16 deletions

View File

@ -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 <intrin.h>
static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); }
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;
}
# 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

View File

@ -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; }

View File

@ -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