#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "private/cpu.h"
#include "share/compat.h"
#include <stdlib.h>
#include <string.h>
#if defined _MSC_VER
#include <intrin.h>
#elif defined __GNUC__ && defined HAVE_CPUID_H
#include <cpuid.h>
#endif
#ifndef NDEBUG
#include <stdio.h>
#define dfprintf …
#else
#define dfprintf …
#endif
#if defined(HAVE_SYS_AUXV_H)
#include <sys/auxv.h>
#endif
#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN && !defined FLAC__NO_ASM
static const uint32_t FLAC__CPUINFO_X86_CPUID_CMOV = 0x00008000;
static const uint32_t FLAC__CPUINFO_X86_CPUID_MMX = 0x00800000;
static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE = 0x02000000;
static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE2 = 0x04000000;
static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE3 = 0x00000001;
static const uint32_t FLAC__CPUINFO_X86_CPUID_SSSE3 = 0x00000200;
static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE41 = 0x00080000;
static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE42 = 0x00100000;
static const uint32_t FLAC__CPUINFO_X86_CPUID_OSXSAVE = 0x08000000;
static const uint32_t FLAC__CPUINFO_X86_CPUID_AVX = 0x10000000;
static const uint32_t FLAC__CPUINFO_X86_CPUID_FMA = 0x00001000;
static const uint32_t FLAC__CPUINFO_X86_CPUID_AVX2 = 0x00000020;
static uint32_t
cpu_xgetbv_x86(void)
{
#if (defined _MSC_VER || defined __INTEL_COMPILER) && FLAC__AVX_SUPPORTED
return (uint32_t)_xgetbv(0);
#elif defined __GNUC__
uint32_t lo, hi;
__asm__ volatile (".byte 0x0f, 0x01, 0xd0" : "=a"(lo), "=d"(hi) : "c" (0));
return lo;
#else
return 0;
#endif
}
static uint32_t
cpu_have_cpuid(void)
{
#if defined FLAC__CPU_X86_64 || defined __i686__ || defined __SSE__ || (defined _M_IX86_FP && _M_IX86_FP > 0)
return 1;
#elif defined __GNUC__ && defined HAVE_CPUID_H
if (__get_cpuid_max(0, 0) != 0)
return 1;
else
return 0;
#elif defined _MSC_VER
FLAC__uint32 flags1, flags2;
__asm {
pushfd
pushfd
pop eax
mov flags1, eax
xor eax, 0x200000
push eax
popfd
pushfd
pop eax
mov flags2, eax
popfd
}
if (((flags1^flags2) & 0x200000) != 0)
return 1;
else
return 0;
#else
return 0;
#endif
}
static void
cpuinfo_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint32 *ecx, FLAC__uint32 *edx)
{
#if defined _MSC_VER
int cpuinfo[4];
int ext = level & 0x80000000;
__cpuid(cpuinfo, ext);
if ((uint32_t)cpuinfo[0] >= level) {
#if FLAC__AVX_SUPPORTED
__cpuidex(cpuinfo, level, 0);
#else
__cpuid(cpuinfo, level);
#endif
*eax = cpuinfo[0]; *ebx = cpuinfo[1]; *ecx = cpuinfo[2]; *edx = cpuinfo[3];
return;
}
#elif defined __GNUC__ && defined HAVE_CPUID_H
FLAC__uint32 ext = level & 0x80000000;
__cpuid(ext, *eax, *ebx, *ecx, *edx);
if (*eax >= level) {
__cpuid_count(level, 0, *eax, *ebx, *ecx, *edx);
return;
}
#endif
*eax = *ebx = *ecx = *edx = 0;
}
#endif
static void
x86_cpu_info (FLAC__CPUInfo *info)
{ … }
static void
ppc_cpu_info (FLAC__CPUInfo *info)
{ … }
void FLAC__cpu_info (FLAC__CPUInfo *info)
{ … }