From a08e90c425343630d820b8775d5a2a63a02689ee Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Sun, 26 Jun 2016 21:09:08 +1000 Subject: [PATCH] libFLAC/cpu.c: Fixes for MSVC MSVC is strange and perverse. --- src/libFLAC/cpu.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/libFLAC/cpu.c b/src/libFLAC/cpu.c index e2bcc679..c288b033 100644 --- a/src/libFLAC/cpu.c +++ b/src/libFLAC/cpu.c @@ -35,6 +35,7 @@ #endif #include "private/cpu.h" +#include "share/compat.h" #include #include @@ -453,6 +454,21 @@ void FLAC__cpu_info (FLAC__CPUInfo *info) #if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN +#if defined _MSC_VER || defined __INTEL_COMPILER +static inline void +cpu_id_ex (int *cpuinfo, int result) +{ +// Stupid MSVC doesn't know how to optimise out: +// if (FLAC_AVC_SUPPORTER) +// __cpuidex(cpuinfo, level, 0); /* for AVX2 detection */ +#if FLAC__AVX_SUPPORTED + __cpuidex(cpuinfo, result, 0); /* for AVX2 detection */ +#else + __cpuid(cpuinfo, result); /* some old compilers don't support __cpuidex */ +#endif +} +#endif + void FLAC__cpu_info_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint32 *ecx, FLAC__uint32 *edx) { #if defined _MSC_VER || defined __INTEL_COMPILER @@ -463,10 +479,8 @@ void FLAC__cpu_info_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx *eax = *ebx = *ecx = *edx = 0; return; } - if (FLAC__AVX_SUPPORTED) - __cpuidex(cpuinfo, level, 0); /* for AVX2 detection */ - else - __cpuid(cpuinfo, level); /* some old compilers don't support __cpuidex */ + + cpu_id_ex (cpuinfo, ext); *eax = cpuinfo[0]; *ebx = cpuinfo[1]; *ecx = cpuinfo[2]; *edx = cpuinfo[3]; #elif defined __GNUC__ && defined HAVE_CPUID_H