summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2013-06-20 14:20:36 +0300
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2013-06-20 14:20:36 +0300
commit3544fa8aa63bef9a35abf236e9376191b5ec206b (patch)
tree3e48b8009b02dfd544efc5199abc780dcca5a9d1
parentec2f8de409a93c80efa658134df22074a9bca5a4 (diff)
downloadlibgcrypt-cipher-amd64-optimizations.tar.gz
Check if assembler is compatible with AMD64 assembly implementationscipher-amd64-optimizations
* cipher/blowfish-amd64.S: Enable only if HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS is defined. * cipher/camellia-aesni-avx-amd64.S: Ditto. * cipher/camellia-aesni-avx2-amd64.S: Ditto. * cipher/cast5-amd64.S: Ditto. * cipher/rinjdael-amd64.S: Ditto. * cipher/serpent-avx2-amd64.S: Ditto. * cipher/serpent-sse2-amd64.S: Ditto. * cipher/twofish-amd64.S: Ditto. * cipher/blowfish.c: Use AMD64 assembly implementation only if HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS is defined * cipher/camellia-glue.c: Ditto. * cipher/cast5.c: Ditto. * cipher/rijndael.c: Ditto. * cipher/serpent.c: Ditto. * cipher/twofish.c: Ditto. * configure.ac: Check gcc/as compatibility with AMD64 assembly implementations. -- Later these checks can be split and assembly implementations adapted to handle different platforms, but for now disable AMD64 assembly implementations if assembler does not look to be able to handle them. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
-rw-r--r--cipher/blowfish-amd64.S2
-rw-r--r--cipher/blowfish.c3
-rw-r--r--cipher/camellia-aesni-avx-amd64.S3
-rw-r--r--cipher/camellia-aesni-avx2-amd64.S3
-rw-r--r--cipher/camellia-glue.c4
-rw-r--r--cipher/cast5-amd64.S2
-rw-r--r--cipher/cast5.c2
-rw-r--r--cipher/rijndael-amd64.S2
-rw-r--r--cipher/rijndael.c2
-rw-r--r--cipher/serpent-avx2-amd64.S3
-rw-r--r--cipher/serpent-sse2-amd64.S2
-rw-r--r--cipher/serpent.c4
-rw-r--r--cipher/twofish-amd64.S2
-rw-r--r--cipher/twofish.c2
-rw-r--r--configure.ac30
15 files changed, 50 insertions, 16 deletions
diff --git a/cipher/blowfish-amd64.S b/cipher/blowfish-amd64.S
index 1008387f..6975e559 100644
--- a/cipher/blowfish-amd64.S
+++ b/cipher/blowfish-amd64.S
@@ -20,7 +20,7 @@
#ifdef __x86_64
#include <config.h>
-#if defined(USE_BLOWFISH)
+#if defined(USE_BLOWFISH) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS)
.text
diff --git a/cipher/blowfish.c b/cipher/blowfish.c
index 39d4051c..69baebe0 100644
--- a/cipher/blowfish.c
+++ b/cipher/blowfish.c
@@ -45,7 +45,8 @@
/* USE_AMD64_ASM indicates whether to use AMD64 assembly code. */
#undef USE_AMD64_ASM
-#if defined(__x86_64__) && (BLOWFISH_ROUNDS == 16)
+#if defined(__x86_64__) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) && \
+ (BLOWFISH_ROUNDS == 16)
# define USE_AMD64_ASM 1
#endif
diff --git a/cipher/camellia-aesni-avx-amd64.S b/cipher/camellia-aesni-avx-amd64.S
index 95c96b8b..b0ef5fd0 100644
--- a/cipher/camellia-aesni-avx-amd64.S
+++ b/cipher/camellia-aesni-avx-amd64.S
@@ -20,7 +20,8 @@
#ifdef __x86_64
#include <config.h>
-#if defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX_SUPPORT)
+#if defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) && \
+ defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX_SUPPORT)
#ifdef __PIC__
# define RIP (%rip)
diff --git a/cipher/camellia-aesni-avx2-amd64.S b/cipher/camellia-aesni-avx2-amd64.S
index f0a34fd1..da427b47 100644
--- a/cipher/camellia-aesni-avx2-amd64.S
+++ b/cipher/camellia-aesni-avx2-amd64.S
@@ -20,7 +20,8 @@
#ifdef __x86_64
#include <config.h>
-#if defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT)
+#if defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) && \
+ defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT)
#ifdef __PIC__
# define RIP (%rip)
diff --git a/cipher/camellia-glue.c b/cipher/camellia-glue.c
index a5468fa9..b44bd7b4 100644
--- a/cipher/camellia-glue.c
+++ b/cipher/camellia-glue.c
@@ -75,7 +75,7 @@
/* USE_AESNI inidicates whether to compile with Intel AES-NI/AVX code. */
#undef USE_AESNI_AVX
#if defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX_SUPPORT)
-# if defined(__x86_64__)
+# if defined(__x86_64__) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS)
# define USE_AESNI_AVX 1
# endif
#endif
@@ -83,7 +83,7 @@
/* USE_AESNI_AVX2 inidicates whether to compile with Intel AES-NI/AVX2 code. */
#undef USE_AESNI_AVX2
#if defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT)
-# if defined(__x86_64__)
+# if defined(__x86_64__) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS)
# define USE_AESNI_AVX2 1
# endif
#endif
diff --git a/cipher/cast5-amd64.S b/cipher/cast5-amd64.S
index c3007d32..1bca2493 100644
--- a/cipher/cast5-amd64.S
+++ b/cipher/cast5-amd64.S
@@ -20,7 +20,7 @@
#ifdef __x86_64
#include <config.h>
-#if defined(USE_CAST5)
+#if defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) && defined(USE_CAST5)
#ifdef __PIC__
# define RIP %rip
diff --git a/cipher/cast5.c b/cipher/cast5.c
index 8c5664dd..41bc9ffa 100644
--- a/cipher/cast5.c
+++ b/cipher/cast5.c
@@ -47,7 +47,7 @@
/* USE_AMD64_ASM indicates whether to use AMD64 assembly code. */
#undef USE_AMD64_ASM
-#if defined(__x86_64__)
+#if defined(__x86_64__) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS)
# define USE_AMD64_ASM 1
#endif
diff --git a/cipher/rijndael-amd64.S b/cipher/rijndael-amd64.S
index 6921f318..2519adac 100644
--- a/cipher/rijndael-amd64.S
+++ b/cipher/rijndael-amd64.S
@@ -20,7 +20,7 @@
#ifdef __x86_64
#include <config.h>
-#if defined(USE_AES)
+#if defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) && defined(USE_AES)
#ifdef __PIC__
# define RIP %rip
diff --git a/cipher/rijndael.c b/cipher/rijndael.c
index 4a89e32c..35e599a3 100644
--- a/cipher/rijndael.c
+++ b/cipher/rijndael.c
@@ -63,7 +63,7 @@
/* USE_AMD64_ASM indicates whether to use AMD64 assembly code. */
#undef USE_AMD64_ASM
-#if defined(__x86_64__)
+#if defined(__x86_64__) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS)
# define USE_AMD64_ASM 1
#endif
diff --git a/cipher/serpent-avx2-amd64.S b/cipher/serpent-avx2-amd64.S
index 7f4f8b5e..7586c0c5 100644
--- a/cipher/serpent-avx2-amd64.S
+++ b/cipher/serpent-avx2-amd64.S
@@ -20,7 +20,8 @@
#ifdef __x86_64
#include <config.h>
-#if defined(USE_SERPENT) && defined(ENABLE_AVX2_SUPPORT)
+#if defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) && defined(USE_SERPENT) && \
+ defined(ENABLE_AVX2_SUPPORT)
#ifdef __PIC__
# define RIP (%rip)
diff --git a/cipher/serpent-sse2-amd64.S b/cipher/serpent-sse2-amd64.S
index 5f9e9d22..fe9feeea 100644
--- a/cipher/serpent-sse2-amd64.S
+++ b/cipher/serpent-sse2-amd64.S
@@ -20,7 +20,7 @@
#ifdef __x86_64
#include <config.h>
-#if defined(USE_SERPENT)
+#if defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) && defined(USE_SERPENT)
#ifdef __PIC__
# define RIP (%rip)
diff --git a/cipher/serpent.c b/cipher/serpent.c
index 89e14aef..8aded344 100644
--- a/cipher/serpent.c
+++ b/cipher/serpent.c
@@ -34,13 +34,13 @@
/* USE_SSE2 indicates whether to compile with AMD64 SSE2 code. */
#undef USE_SSE2
-#if defined(__x86_64__)
+#if defined(__x86_64__) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS)
# define USE_SSE2 1
#endif
/* USE_AVX2 indicates whether to compile with AMD64 AVX2 code. */
#undef USE_AVX2
-#if defined(__x86_64__)
+#if defined(__x86_64__) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS)
# if defined(ENABLE_AVX2_SUPPORT)
# define USE_AVX2 1
# endif
diff --git a/cipher/twofish-amd64.S b/cipher/twofish-amd64.S
index a2a878ae..d4668343 100644
--- a/cipher/twofish-amd64.S
+++ b/cipher/twofish-amd64.S
@@ -20,7 +20,7 @@
#ifdef __x86_64
#include <config.h>
-#if defined(USE_TWOFISH)
+#if defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) && defined(USE_TWOFISH)
#ifdef __PIC__
# define RIP %rip
diff --git a/cipher/twofish.c b/cipher/twofish.c
index ee721c6b..07a4ebe7 100644
--- a/cipher/twofish.c
+++ b/cipher/twofish.c
@@ -53,7 +53,7 @@
/* USE_AMD64_ASM indicates whether to use AMD64 assembly code. */
#undef USE_AMD64_ASM
-#if defined(__x86_64__)
+#if defined(__x86_64__) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS)
# define USE_AMD64_ASM 1
#endif
diff --git a/configure.ac b/configure.ac
index 5b9d837e..d9b16392 100644
--- a/configure.ac
+++ b/configure.ac
@@ -941,6 +941,36 @@ if test "$gcry_cv_gcc_inline_asm_avx2" = "yes" ; then
fi
+#
+# Check whether GCC assembler supports features needed for our amd64
+# implementations
+#
+AC_CACHE_CHECK([whether GCC assembler is compatible for amd64 assembly implementations],
+ [gcry_cv_gcc_amd64_platform_as_ok],
+ [gcry_cv_gcc_amd64_platform_as_ok=no
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+ [[__asm__(
+ /* Test if '.set' is supported by underlying assembler. */
+ ".set a0, %rax\n\t"
+ ".set b0, %rdx\n\t"
+ "asmfunc:\n\t"
+ "movq a0, b0;\n\t" /* Fails here if .set ignored by as. */
+
+ /* Test if '.type' and '.size' are supported. */
+ /* These work only on ELF targets. */
+ /* TODO: add COFF (mingw64, cygwin64) support to assembly
+ * implementations. Mingw64/cygwin64 also require additional
+ * work because they use different calling convention. */
+ ".size asmfunc,.-asmfunc;\n\t"
+ ".type asmfunc,@function;\n\t"
+ );]])],
+ [gcry_cv_gcc_amd64_platform_as_ok=yes])])
+if test "$gcry_cv_gcc_amd64_platform_as_ok" = "yes" ; then
+ AC_DEFINE(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS,1,
+ [Defined if underlying assembler is compatible with amd64 assembly implementations])
+fi
+
+
#######################################
#### Checks for library functions. ####
#######################################