[Zlib-devel] [PATCH 02/13] For x86, add CPUID check.

Jim Kukunas james.t.kukunas at linux.intel.com
Mon Nov 25 17:21:38 EST 2013


Adds check for SSE2, SSE4.2, and the PCLMULQDQ instructions.
---
 configure |    8 ++++----
 x86.c     |   21 +++++++++++++++++++++
 x86.h     |   15 +++++++++++++++
 3 files changed, 40 insertions(+), 4 deletions(-)
 create mode 100644 x86.c
 create mode 100644 x86.h

diff --git a/configure b/configure
index 07ed27f..344f3a2 100755
--- a/configure
+++ b/configure
@@ -746,12 +746,12 @@ fi
 # Set ARCH specific FLAGS
 case "${ARCH}" in
     x86_64)
-        OBJC="${OBJC}"
-        PIC_OBJC="${PIC_OBJC}"
+        OBJC="${OBJC} x86.o"
+        PIC_OBJC="${PIC_OBJC} x86.lo"
     ;;
     i386 | i486 | i586 | i686)
-        OBJC="${OBJC}"
-        PIC_OBJC="${PIC_OBJC}"
+        OBJC="${OBJC} x86.o"
+        PIC_OBJC="${PIC_OBJC} x86.lo"
     ;;
 esac
 
diff --git a/x86.c b/x86.c
new file mode 100644
index 0000000..101c133
--- /dev/null
+++ b/x86.c
@@ -0,0 +1,21 @@
+#include "x86.h"
+
+int x86_cpu_has_sse2;
+int x86_cpu_has_sse42;
+int x86_cpu_has_pclmulqdq;
+
+void x86_check_features(void)
+{
+    unsigned eax, ebx, ecx, edx;
+
+    eax = 1;
+    __asm__ __volatile__ (
+        "cpuid\n\t"
+    : "+a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
+    );
+
+    x86_cpu_has_sse2 = edx & 0x4000000;
+    x86_cpu_has_sse42= ecx & 0x100000;
+    x86_cpu_has_pclmulqdq = ecx & 0x2;
+}
+
diff --git a/x86.h b/x86.h
new file mode 100644
index 0000000..99f4499
--- /dev/null
+++ b/x86.h
@@ -0,0 +1,15 @@
+ /* cpu.h -- check for CPU features
+ * Copyright (C) 2013 Intel Corporation Jim Kukunas
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#ifndef CPU_H
+#define CPU_H
+
+extern int x86_cpu_has_sse2;
+extern int x86_cpu_has_sse42;
+extern int x86_cpu_has_pclmulqdq;
+
+void x86_check_features(void);
+
+#endif
-- 
1.7.1





More information about the Zlib-devel mailing list