summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-09-16 22:46:13 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-09-16 22:46:13 +0200
commitc8c99c59b4a09f8ade727bfb3276807d72961108 (patch)
treeed58271e0e8f29175d90f9ac5f99cf843d1fadec
parent10779454f169ab4616bb247cc6d141d56c16979c (diff)
downloadgnutls-c8c99c59b4a09f8ade727bfb3276807d72961108.tar.gz
Added better detection of capabilities in 386. If cpuid doesn't exist don't try to execute it.
-rw-r--r--configure.ac2
-rw-r--r--lib/accelerated/Makefile.am10
-rw-r--r--lib/accelerated/accelerated.c12
-rw-r--r--lib/accelerated/x86.h43
4 files changed, 50 insertions, 17 deletions
diff --git a/configure.ac b/configure.ac
index 85916ef627..a3ccb2cc91 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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")
diff --git a/lib/accelerated/Makefile.am b/lib/accelerated/Makefile.am
index 4a23dde76f..e9426d0be6 100644
--- a/lib/accelerated/Makefile.am
+++ b/lib/accelerated/Makefile.am
@@ -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
diff --git a/lib/accelerated/accelerated.c b/lib/accelerated/accelerated.c
index ddfdf0c54a..e2da12f6c3 100644
--- a/lib/accelerated/accelerated.c
+++ b/lib/accelerated/accelerated.c
@@ -21,16 +21,20 @@
*/
#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;
diff --git a/lib/accelerated/x86.h b/lib/accelerated/x86.h
index 2fdb9d6c79..0b61272cda 100644
--- a/lib/accelerated/x86.h
+++ b/lib/accelerated/x86.h
@@ -22,19 +22,25 @@
#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 */