]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
separated cpuid from up x86_check_features
authorMat Berchtold <mberchtold@gmail.com>
Fri, 30 Oct 2015 13:37:32 +0000 (14:37 +0100)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 2 Nov 2015 12:16:40 +0000 (13:16 +0100)
new cpuid functions for different compilers

arch/x86/x86.c

index 8ab12e31494476545b1267b50a3c36a60247b59b..57af918cca136f0e005cfa3632108a85f2627c93 100644 (file)
@@ -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 <intrin.h>\r
-#define CPU_PROCINFO_AND_FEATUREBITS 1\r
-\r
-void ZLIB_INTERNAL x86_check_features(void) {\r
-       unsigned int registers[4];\r
-       __cpuid(registers, CPU_PROCINFO_AND_FEATUREBITS);\r
-\r
-       unsigned int ecx = registers[2];\r
-       unsigned int edx = registers[3];\r
-\r
-       x86_cpu_has_sse2 = edx & 0x4000000;
-       x86_cpu_has_sse42 = ecx & 0x100000;
-       x86_cpu_has_pclmulqdq = ecx & 0x2;\r
+#include <intrin.h>
+#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 <cpuid.h>
 
-    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