From 35f0add66d83d574d1f6ff3c454c05d32aea7d24 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Mon, 16 Mar 2015 20:02:04 +0000 Subject: [PATCH] cpuid ifdefs fixed to remove some duplicate code cases. BUG=none TESTED=local windows build R=tpsiaki@google.com Review URL: https://webrtc-codereview.appspot.com/47619004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@1332 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- source/cpu_id.cc | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/source/cpu_id.cc b/source/cpu_id.cc index 1efa26525..d4fc7cd48 100644 --- a/source/cpu_id.cc +++ b/source/cpu_id.cc @@ -43,17 +43,17 @@ extern "C" { #define SAFEBUFFERS #endif -// Low level cpuid for X86. Returns zeros on other CPUs. -#if !defined(__pnacl__) && !defined(__CLR_VER) && \ - (defined(_M_IX86) || defined(_M_X64) || \ - defined(__i386__) || defined(__x86_64__)) +// Low level cpuid for X86. +#if (defined(_M_IX86) || defined(_M_X64) || \ + defined(__i386__) || defined(__x86_64__)) && \ + !defined(__pnacl__) && !defined(__CLR_VER) LIBYUV_API void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { #if defined(_MSC_VER) && !defined(__clang__) +// Visual C version uses intrinsic or inline x86 assembly. #if (_MSC_FULL_VER >= 160040219) __cpuidex((int*)(cpu_info), info_eax, info_ecx); -#endif -#if defined(_M_IX86) +#elif defined(_M_IX86) __asm { mov eax, info_eax mov ecx, info_ecx @@ -71,7 +71,8 @@ void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { cpu_info[3] = cpu_info[2] = cpu_info[1] = cpu_info[0] = 0; } #endif -#else // defined(_MSC_VER) +// GCC version uses inline x86 assembly. +#else // defined(_MSC_VER) && !defined(__clang__) uint32 info_ebx, info_edx; asm volatile ( // NOLINT #if defined( __i386__) && defined(__PIC__) @@ -89,36 +90,37 @@ void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { cpu_info[1] = info_ebx; cpu_info[2] = info_ecx; cpu_info[3] = info_edx; -#endif // defined(_MSC_VER) +#endif // defined(_MSC_VER) && !defined(__clang__) } +#else // (defined(_M_IX86) || defined(_M_X64) ... +LIBYUV_API +void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info) { + cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; +} +#endif -#if !defined(__native_client__) +// TODO(fbarchard): Enable xgetbv when validator supports it. +#if (defined(_M_IX86) || defined(_M_X64) || \ + defined(__i386__) || defined(__x86_64__)) && \ + !defined(__pnacl__) && !defined(__CLR_VER) && !defined(__native_client__) #define HAS_XGETBV // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers. int TestOsSaveYmm() { uint32 xcr0 = 0u; #if defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219) xcr0 = (uint32)(_xgetbv(0)); // VS2010 SP1 required. -#endif -#if defined(_M_IX86) && defined(_MSC_VER) +#elif defined(_M_IX86) && defined(_MSC_VER) && !defined(__clang__) __asm { xor ecx, ecx // xcr 0 _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0 // For VS2010 and earlier. mov xcr0, eax } -#endif -#if defined(__i386__) || defined(__x86_64__) +#elif defined(__i386__) || defined(__x86_64__) asm(".byte 0x0f, 0x01, 0xd0" : "=a" (xcr0) : "c" (0) : "%edx"); -#endif // defined(_MSC_VER) +#endif // defined(__i386__) || defined(__x86_64__) return((xcr0 & 6) == 6); // Is ymm saved? } -#endif // !defined(__native_client__) -#else -LIBYUV_API -void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info) { - cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; -} -#endif +#endif // defined(_M_IX86) || defined(_M_X64) .. // based on libvpx arm_cpudetect.c // For Arm, but public to allow testing on any CPU