Merge pull request #1097 from bmiklautz/avx_buildfix

sysinfo cpu detection and build fixes
This commit is contained in:
Marc-André Moreau 2013-03-14 18:35:14 -07:00
commit 6548a34151
3 changed files with 62 additions and 52 deletions

View File

@ -301,6 +301,7 @@ WINPR_API BOOL IsProcessorFeaturePresentEx(DWORD ProcessorFeature);
#define PF_EX_ARM_VFP4 11
#define PF_EX_ARM_IDIVA 12
#define PF_EX_ARM_IDIVT 13
#define PF_EX_AVX_PCLMULQDQ 14
/*
* some "aliases" for the standard defines

View File

@ -389,18 +389,20 @@ ULONGLONG GetTickCount64(void)
#define D_BIT_SSE2 (1<<26)
#define D_BIT_3DN (1<<30)
#define C_BIT_SSE3 (1<<0)
#define C_BIT_PCLMULQDQ (1<<1)
#define C_BIT_3DNP (1<<8)
#define C_BIT_3DNP (1<<8)
#define C_BIT_SSSE3 (1<<9)
#define C_BIT_SSE41 (1<<19)
#define C_BIT_SSE42 (1<<20)
#define C_BIT_XGETBV (1<<27)
#define C_BIT_FMA (1<<12)
#define C_BIT_AES (1<<25)
#define C_BIT_XGETBV (1<<27)
#define C_BIT_AVX (1<<28)
#define C_BITS_AVX (C_BIT_XGETBV|C_BIT_AVX)
#define E_BIT_XMM (1<<1)
#define E_BIT_YMM (1<<2)
#define E_BITS_AVX (E_BIT_XMM|E_BIT_YMM)
#define C_BIT_FMA (1<<11)
#define C_BIT_AVX_AES (1<<24)
static void cpuid(
unsigned info,
@ -660,34 +662,38 @@ BOOL IsProcessorFeaturePresentEx(DWORD ProcessorFeature)
case PF_EX_AVX:
case PF_EX_FMA:
case PF_EX_AVX_AES:
case PF_EX_AVX_PCLMULQDQ:
{
/* Check for general AVX support */
if ((c & C_BITS_AVX) != C_BITS_AVX)
ret = FALSE;
break;
int e, f;
xgetbv(0, e, f);
int e, f;
xgetbv(0, e, f);
if ((e & E_BITS_AVX) == E_BITS_AVX)
/* XGETBV enabled for applications and XMM/YMM states enabled */
if ((e & E_BITS_AVX) == E_BITS_AVX)
{
switch (ProcessorFeature)
{
switch (ProcessorFeature)
{
case: PF_EX_AVX:
ret = TRUE;
break;
case: PF_EX_FMA:
if (c & C_BIT_FMA)
ret = TRUE;
break;
case: PF_EX_AVX_AES:
if (c & C_BIT_AVX_AES)
ret = TRUE;
break;
{
case PF_EX_AVX:
ret = TRUE;
break;
}
}
}
case PF_EX_FMA:
if (c & C_BIT_FMA)
ret = TRUE;
break;
case PF_EX_AVX_AES:
if (c & C_BIT_AES)
ret = TRUE;
break;
case PF_EX_AVX_PCLMULQDQ:
if (c & C_BIT_PCLMULQDQ)
ret = TRUE;
break;
}
}
}
break;
#endif //__AVX__
default:

View File

@ -3,42 +3,45 @@
#include <winpr/sysinfo.h>
#include <winpr/platform.h>
#define TEST_FEATURE(feature) printf("\t" #feature ": %s\n", IsProcessorFeaturePresent(feature) ? "yes" : "no")
#define TEST_FEATURE_EX(feature) printf("\t" #feature ": %s\n", IsProcessorFeaturePresentEx(feature) ? "yes" : "no")
int TestCPUFeatures(int argc, char* argv[])
{
printf("Base CPU Flags:\n");
#ifdef _M_IX86_AMD64
printf("\tPF_MMX_INSTRUCTIONS_AVAILABLE: %s\n", IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE) ? "yes" : "no");
printf("\tPF_XMMI_INSTRUCTIONS_AVAILABLE: %s\n", IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE) ? "yes" : "no");
printf("\tPF_XMMI64_INSTRUCTIONS_AVAILABLE: %s\n", IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE) ? "yes" : "no");
printf("\tPF_3DNOW_INSTRUCTIONS_AVAILABLE: %s\n", IsProcessorFeaturePresent(PF_3DNOW_INSTRUCTIONS_AVAILABLE) ? "yes" : "no");
printf("\tPF_SSE3_INSTRUCTIONS_AVAILABLE: %s\n", IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE) ? "yes" : "no");
TEST_FEATURE(PF_MMX_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_XMMI_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_3DNOW_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_SSE3_INSTRUCTIONS_AVAILABLE);
printf("\n");
printf("Extended CPU Flags (not found in windows API):\n");
printf("\tPF_EX_3DNOW_PREFETCH: %s\n", IsProcessorFeaturePresentEx(PF_EX_3DNOW_PREFETCH) ? "yes" : "no");
printf("\tPF_EX_SSSE3: %s\n", IsProcessorFeaturePresentEx(PF_EX_SSSE3) ? "yes" : "no");
printf("\tPF_EX_SSE41: %s\n", IsProcessorFeaturePresentEx(PF_EX_SSE41) ? "yes" : "no");
printf("\tPF_EX_SSE42: %s\n", IsProcessorFeaturePresentEx(PF_EX_SSE42) ? "yes" : "no");
printf("\tPF_EX_AVX: %s\n", IsProcessorFeaturePresentEx(PF_EX_AVX) ? "yes" : "no");
printf("\tPF_EX_FMA: %s\n", IsProcessorFeaturePresentEx(PF_EX_FMA) ? "yes" : "no");
printf("\tPF_EX_AVX_AES: %s\n", IsProcessorFeaturePresentEx(PF_EX_AVX_AES) ? "yes" : "no");
TEST_FEATURE_EX(PF_EX_3DNOW_PREFETCH);
TEST_FEATURE_EX(PF_EX_SSSE3);
TEST_FEATURE_EX(PF_EX_SSE41);
TEST_FEATURE_EX(PF_EX_SSE42);
TEST_FEATURE_EX(PF_EX_AVX);
TEST_FEATURE_EX(PF_EX_FMA);
TEST_FEATURE_EX(PF_EX_AVX_AES);
TEST_FEATURE_EX(PF_EX_AVX_PCLMULQDQ);
#elif defined(_M_ARM)
printf("\tPF_ARM_NEON_INSTRUCTIONS_AVAILABLE: %s\n", IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) ? "yes" : "no");
printf("\tPF_ARM_THUMB: %s\n", IsProcessorFeaturePresent(PF_ARM_THUMB) ? "yes" : "no");
printf("\tPF_ARM_VFP_32_REGISTERS_AVAILABLE: %s\n", IsProcessorFeaturePresent(PF_ARM_VFP_32_REGISTERS_AVAILABLE) ? "yes" : "no");
printf("\tPF_ARM_DIVIDE_INSTRUCTION_AVAILABLE: %s\n", IsProcessorFeaturePresent(PF_ARM_DIVIDE_INSTRUCTION_AVAILABLE) ? "yes" : "no");
printf("\tPF_ARM_VFP3: %s\n", IsProcessorFeaturePresent(PF_ARM_VFP3) ? "yes" : "no");
printf("\tPF_ARM_THUMB: %s\n", IsProcessorFeaturePresent(PF_ARM_THUMB) ? "yes" : "no");
printf("\tPF_ARM_JAZELLE: %s\n", IsProcessorFeaturePresent(PF_ARM_JAZELLE) ? "yes" : "no");
printf("\tPF_ARM_DSP: %s\n", IsProcessorFeaturePresent(PF_ARM_DSP) ? "yes" : "no");
printf("\tPF_ARM_THUMB2: %s\n", IsProcessorFeaturePresent(PF_ARM_THUMB2) ? "yes" : "no");
printf("\tPF_ARM_T2EE: %s\n", IsProcessorFeaturePresent(PF_ARM_T2EE) ? "yes" : "no");
printf("\tPF_ARM_INTEL_WMMX: %s\n", IsProcessorFeaturePresent(PF_ARM_INTEL_WMMX) ? "yes" : "no");
TEST_FEATURE(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE);
TEST_FEATURE(PF_ARM_THUMB);
TEST_FEATURE(PF_ARM_VFP_32_REGISTERS_AVAILABLE);
TEST_FEATURE(PF_ARM_DIVIDE_INSTRUCTION_AVAILABLE);
TEST_FEATURE(PF_ARM_VFP3);
TEST_FEATURE(PF_ARM_THUMB);
TEST_FEATURE(PF_ARM_JAZELLE);
TEST_FEATURE(PF_ARM_DSP);
TEST_FEATURE(PF_ARM_THUMB2);
TEST_FEATURE(PF_ARM_T2EE);
TEST_FEATURE(PF_ARM_INTEL_WMMX);
printf("Extended CPU Flags (not found in windows API):\n");
printf("\tPF_EX_ARM_VFP1: %s\n", IsProcessorFeaturePresentEx(PF_EX_ARM_VFP1) ? "yes" : "no");
printf("\tPF_EX_ARM_VFP3D16: %s\n", IsProcessorFeaturePresentEx(PF_EX_ARM_VFP3D16) ? "yes" : "no");
printf("\tPF_EX_ARM_VFP4: %s\n", IsProcessorFeaturePresentEx(PF_EX_ARM_VFP4) ? "yes" : "no");
printf("\tPF_EX_ARM_IDIVA: %s\n", IsProcessorFeaturePresentEx(PF_EX_ARM_IDIVA) ? "yes" : "no");
printf("\tPF_EX_ARM_IDIVT: %s\n", IsProcessorFeaturePresentEx(PF_EX_ARM_IDIVT) ? "yes" : "no");
TEST_FEATURE_EX(PF_EX_ARM_VFP1);
TEST_FEATURE_EX(PF_EX_ARM_VFP3D16);
TEST_FEATURE_EX(PF_EX_ARM_VFP4);
TEST_FEATURE_EX(PF_EX_ARM_IDIVA);
TEST_FEATURE_EX(PF_EX_ARM_IDIVT);
#endif
printf("\n");
return 0;