diff --git a/configure.ac b/configure.ac index 5fa28987..813e7259 100644 --- a/configure.ac +++ b/configure.ac @@ -399,7 +399,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ HAVE_AMD64_ASM_V=0 AS_IF([test "$enable_asm" != "no"],[ - AC_MSG_CHECKING(whether we should use x86_64 asm code) + AC_MSG_CHECKING(whether we can use x86_64 asm code) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[ #if defined(__amd64) || defined(__amd64__) || defined(__x86_64__) @@ -413,13 +413,36 @@ AS_IF([test "$enable_asm" != "no"],[ __asm__("pxor %xmm12,%xmm6"); ]])], [AC_MSG_RESULT(yes) - AC_DEFINE([HAVE_AMD64_ASM], [1], [x86_64 asm code should be used]) + AC_DEFINE([HAVE_AMD64_ASM], [1], [x86_64 asm code can be used]) HAVE_AMD64_ASM_V=1], [AC_MSG_RESULT(no)]) ]) AM_CONDITIONAL([HAVE_AMD64_ASM], [test $HAVE_AMD64_ASM_V = 1]) AC_SUBST(HAVE_AMD64_ASM_V) +HAVE_AVX_ASM_V=0 +AS_IF([test "$enable_asm" != "no"],[ + AC_MSG_CHECKING(whether we can assemble AVX opcodes) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + ]], [[ +#if defined(__amd64) || defined(__amd64__) || defined(__x86_64__) +# if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64) +# error Windows x86_64 calling conventions are not supported yet +# endif +/* neat */ +#else +# error !x86_64 +#endif +__asm__("vpunpcklqdq %xmm0,%xmm13,%xmm0"); +]])], + [AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_AVX_ASM], [1], [AVX opcodes are supported]) + HAVE_AVX_ASM_V=1], + [AC_MSG_RESULT(no)]) +]) +AM_CONDITIONAL([HAVE_AVX_ASM], [test $HAVE_AVX_ASM_V = 1]) +AC_SUBST(HAVE_AVX_ASM_V) + AC_MSG_CHECKING(for 128-bit arithmetic) HAVE_TI_MODE_V=0 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index 90efeda7..19b2f126 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -204,10 +204,8 @@ EXTRA_DIST = \ crypto_scalarmult/curve25519/sandy2x/ladder.S \ crypto_scalarmult/curve25519/sandy2x/ladder_base.S -if HAVE_AMD64_ASM +if HAVE_AVX_ASM libsodium_la_SOURCES += \ - crypto_stream/salsa20/amd64_xmm6/api.h \ - crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S \ crypto_scalarmult/curve25519/sandy2x/consts_namespace.h \ crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c \ crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.h \ @@ -221,6 +219,12 @@ libsodium_la_SOURCES += \ crypto_scalarmult/curve25519/sandy2x/ladder_base_namespace.h \ crypto_scalarmult/curve25519/sandy2x/ladder_namespace.h \ crypto_scalarmult/curve25519/sandy2x/sandy2x.S +endif + +if HAVE_AMD64_ASM +libsodium_la_SOURCES += \ + crypto_stream/salsa20/amd64_xmm6/api.h \ + crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S else libsodium_la_SOURCES += \ crypto_stream/salsa20/ref/api.h \ diff --git a/src/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c b/src/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c index 2af7adba..3d126a0e 100644 --- a/src/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c +++ b/src/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c @@ -7,7 +7,7 @@ #include -#ifdef HAVE_AMD64_ASM +#ifdef HAVE_AVX_ASM #include "utils.h" #include "curve25519_sandy2x.h" diff --git a/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c b/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c index 149054ee..a9d0be76 100644 --- a/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c +++ b/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c @@ -5,7 +5,7 @@ #include "fe51.h" -#ifdef HAVE_AMD64_ASM +#ifdef HAVE_AVX_ASM #define fe51_square(x, y) fe51_nsquare(x, y, 1) diff --git a/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c b/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c index 208f7df7..0de060c8 100644 --- a/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c +++ b/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c @@ -5,7 +5,7 @@ #include "fe.h" #include "crypto_uint64.h" -#ifdef HAVE_AMD64_ASM +#ifdef HAVE_AVX_ASM static crypto_uint64 load_3(const unsigned char *in) { diff --git a/src/libsodium/crypto_scalarmult/curve25519/sandy2x/sandy2x.S b/src/libsodium/crypto_scalarmult/curve25519/sandy2x/sandy2x.S index c955b0af..1fd63205 100644 --- a/src/libsodium/crypto_scalarmult/curve25519/sandy2x/sandy2x.S +++ b/src/libsodium/crypto_scalarmult/curve25519/sandy2x/sandy2x.S @@ -1,5 +1,5 @@ -#ifdef HAVE_AMD64_ASM +#ifdef HAVE_AVX_ASM #define IN_SANDY2X diff --git a/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c b/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c index 21420723..3075747a 100644 --- a/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c +++ b/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c @@ -3,7 +3,7 @@ #include "scalarmult_curve25519.h" #include "runtime.h" -#ifdef HAVE_AMD64_ASM +#ifdef HAVE_AVX_ASM # include "sandy2x/curve25519_sandy2x.h" #endif #ifdef HAVE_TI_MODE @@ -49,7 +49,7 @@ _crypto_scalarmult_curve25519_pick_best_implementation(void) #else implementation = &crypto_scalarmult_curve25519_ref10_implementation; #endif -#ifdef HAVE_AMD64_ASM +#ifdef HAVE_AVX_ASM if (sodium_runtime_has_avx()) { implementation = &crypto_scalarmult_curve25519_sandy2x_implementation; }