]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Added better detection of capabilities in 386. If cpuid doesn't exist don't try to...
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 16 Sep 2011 20:46:13 +0000 (22:46 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 16 Sep 2011 20:46:13 +0000 (22:46 +0200)
configure.ac
lib/accelerated/Makefile.am
lib/accelerated/accelerated.c
lib/accelerated/x86.h

index 85916ef627b10ab10cb4004d3773f283c4c16343..a3ccb2cc9113aa617482bec0f2a729add67b93b4 100644 (file)
@@ -94,8 +94,8 @@ esac
 
 fi
 
-AM_CONDITIONAL(TRY_X86_OPTIMIZATIONS, test x"$hw_accel" = x"x86" || test x"$hw_accel" = x"x86-64")
 AM_CONDITIONAL(ASM_X86_64, test x"$hw_accel" = x"x86-64")
+AM_CONDITIONAL(ASM_X86_32, test x"$hw_accel" = x"x86")
 AM_CONDITIONAL(HAVE_GCC_GNU89_INLINE_OPTION, test "$gnu89_inline" = "yes"])
 AM_CONDITIONAL(HAVE_GCC, test "$GCC" = "yes")
 
index 4a23dde76ffff388bdc1f69a1358d01e3d229e44..e9426d0be64fad9bb58ae09cca2b13cc8fa29b3f 100644 (file)
@@ -36,8 +36,14 @@ EXTRA_DIST = x86.h accelerated.h cryptodev.h
 libaccelerated_la_SOURCES = accelerated.c cryptodev.c
 libaccelerated_la_LIBADD =
 
-if TRY_X86_OPTIMIZATIONS
+if ASM_X86_64
 SUBDIRS += intel
-AM_CFLAGS += -DTRY_X86_OPTIMIZATIONS
+AM_CFLAGS += -DASM_X86_64
+libaccelerated_la_LIBADD += intel/libintel.la
+endif
+
+if ASM_X86_32
+SUBDIRS += intel
+AM_CFLAGS += -DASM_X86_32
 libaccelerated_la_LIBADD += intel/libintel.la
 endif
index ddfdf0c54a957da3d362fbfff6741e46196c8944..e2da12f6c3abb471ef9ffea412761c39bad9fffe 100644 (file)
  */
 
 #include <accelerated.h>
-#ifdef TRY_X86_OPTIMIZATIONS
+#if defined(ASM_X86_32) || defined(ASM_X86_64)
 # include <intel/aes-x86.h>
+# include <x86.h>
 #endif
 
 void _gnutls_register_accel_crypto(void)
 {
 
-#ifdef TRY_X86_OPTIMIZATIONS
-  register_x86_crypto ();
-  register_padlock_crypto ();
+#if defined(ASM_X86_32) || defined(ASM_X86_64)
+  if (have_cpuid() != 0)
+    {
+      register_x86_crypto ();
+      register_padlock_crypto ();
+    }
 #endif
 
   return;
index 2fdb9d6c790186c62360d09c94e814b72d137c36..0b61272cda9f0129d1cd539a69f309edab157698 100644 (file)
 
 #include <config.h>
 
-#ifdef HAVE_CPUID_H
-# include <cpuid.h>
-# define cpuid __cpuid
+#ifdef ASM_X86_64
 
-#else
-
-# ifdef ASM_X86_64
+# ifdef HAVE_CPUID_H
+#  include <cpuid.h>
+#  define cpuid __cpuid
+# else
 
-#  define cpuid(func,ax,bx,cx,dx)\
+#define cpuid(func,ax,bx,cx,dx)\
   __asm__ __volatile__ ("cpuid":\
   "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
 
-# else
+# endif
+
+# define have_cpuid() 1
+
+#endif /* ASM_X86_64 */
+
+
+#ifdef ASM_X86_32
 /* some GCC versions complain on the version above */
 #  define cpuid(func, a, b, c, d) g_cpuid(func, &a, &b, &c, &d)
 
@@ -48,6 +54,23 @@ inline static void g_cpuid(uint32_t func, unsigned int *ax, unsigned int *bx, un
                   :"a"(func)
                   :"cc");
 }
-# endif
 
-#endif
+inline static unsigned int have_cpuid(void)
+{
+  unsigned int have_id;
+  asm volatile(
+    "pushfl\t\n"
+    "pop %0\t\n"
+    "orl $0x200000, %0\t\n"
+    "push %0\t\n"
+    "popfl\t\n"
+    "pushfl\t\n"
+    "pop %0\t\n"
+    "andl $0x200000, %0\t\n"
+    :"=r" (have_id)
+    ::
+  );
+  
+  return have_id;
+}
+#endif /* ASM_X86_32 */