From: Mat Berchtold Date: Fri, 30 Oct 2015 13:37:32 +0000 (+0100) Subject: separated cpuid from up x86_check_features X-Git-Tag: 1.9.9-b1~793^2~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c5635fe2fb5ec3be89636fcce634a117f793af0;p=thirdparty%2Fzlib-ng.git separated cpuid from up x86_check_features new cpuid functions for different compilers --- diff --git a/arch/x86/x86.c b/arch/x86/x86.c index 8ab12e314..57af918cc 100644 --- a/arch/x86/x86.c +++ b/arch/x86/x86.c @@ -4,7 +4,7 @@ * Copyright (C) 2013 Intel Corporation. All rights reserved. * Author: * Jim Kukunas - * + * * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -15,39 +15,40 @@ ZLIB_INTERNAL int x86_cpu_has_sse42; ZLIB_INTERNAL int x86_cpu_has_pclmulqdq; #ifdef _MSC_VER -#include -#define CPU_PROCINFO_AND_FEATUREBITS 1 - -void ZLIB_INTERNAL x86_check_features(void) { - unsigned int registers[4]; - __cpuid(registers, CPU_PROCINFO_AND_FEATUREBITS); - - unsigned int ecx = registers[2]; - unsigned int edx = registers[3]; - - x86_cpu_has_sse2 = edx & 0x4000000; - x86_cpu_has_sse42 = ecx & 0x100000; - x86_cpu_has_pclmulqdq = ecx & 0x2; +#include +#define CPU_PROCINFO_AND_FEATUREBITS 1 + +static void cpuid(int info, unsigned* eax, unsigned* ebx, unsigned* ecx, unsigned* edx) { + unsigned int registers[4]; + __cpuid(registers, info); + + *eax = registers[0]; + *ebx = registers[1]; + *ecx = registers[2]; + *edx = registers[3]; } #else -void ZLIB_INTERNAL x86_check_features(void) { - unsigned eax, ebx, ecx, edx; +// Newer versions of GCC and clang come with cpuid.h +#include - eax = 1; - __asm__ __volatile__ ( -#ifdef X86 - "xchg %%ebx, %1\n\t" -#endif - "cpuid\n\t" -#ifdef X86 - "xchg %1, %%ebx\n\t" - : "+a" (eax), "=S" (ebx), "=c" (ecx), "=d" (edx) -#else - : "+a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) +static void cpuid(int info, unsigned* eax, unsigned* ebx, unsigned* ecx, unsigned* edx) { + unsigned int _eax; + unsigned int _ebx; + unsigned int _ecx; + unsigned int _edx; + __cpuid(info, _eax, _ebx, _ecx, _edx); + *eax = _eax; + *ebx = _ebx; + *ecx = _ecx; + *edx = _edx; +} #endif - ); - x86_cpu_has_sse2 = edx & 0x4000000; - x86_cpu_has_sse42 = ecx & 0x100000; - x86_cpu_has_pclmulqdq = ecx & 0x2; + +void ZLIB_INTERNAL x86_check_features(void) { + unsigned eax, ebx, ecx, edx; + cpuid(1 /*CPU_PROCINFO_AND_FEATUREBITS*/, &eax, &ebx, &ecx, &edx); + + x86_cpu_has_sse2 = edx & 0x4000000; + x86_cpu_has_sse42 = ecx & 0x100000; + x86_cpu_has_pclmulqdq = ecx & 0x2; } -#endif \ No newline at end of file