mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Use the AVX2 salsa20 implementation if the CPU supports it
This commit is contained in:
@@ -207,8 +207,8 @@ libsse2_la_SOURCES = \
|
||||
crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c \
|
||||
crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c \
|
||||
crypto_onetimeauth/poly1305/sse2/poly1305_sse2.h \
|
||||
crypto_stream/salsa20/xmm6int/salsa20_xmm6int.c \
|
||||
crypto_stream/salsa20/xmm6int/salsa20_xmm6int.h \
|
||||
crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c \
|
||||
crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.h \
|
||||
crypto_stream/salsa20/xmm6int/u0.h \
|
||||
crypto_stream/salsa20/xmm6int/u1.h \
|
||||
crypto_stream/salsa20/xmm6int/u4.h
|
||||
@@ -236,4 +236,7 @@ libavx2_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \
|
||||
@CFLAGS_SSE2@ @CFLAGS_SSSE3@ @CFLAGS_SSE41@ @CFLAGS_AVX@ @CFLAGS_AVX2@
|
||||
libavx2_la_SOURCES = \
|
||||
crypto_generichash/blake2b/ref/blake2b-compress-avx2.c \
|
||||
crypto_generichash/blake2b/ref/blake2b-compress-avx2.h
|
||||
crypto_generichash/blake2b/ref/blake2b-compress-avx2.h \
|
||||
crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c \
|
||||
crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.h \
|
||||
crypto_stream/salsa20/xmm6int/u8.h
|
||||
|
||||
@@ -6,12 +6,16 @@
|
||||
|
||||
#include "ref/salsa20_ref.h"
|
||||
#ifdef HAVE_EMMINTRIN_H
|
||||
# include "xmm6int/salsa20_xmm6int.h"
|
||||
# include "xmm6int/salsa20_xmm6int-sse2.h"
|
||||
#endif
|
||||
#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \
|
||||
defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)
|
||||
# include "xmm6int/salsa20_xmm6int-avx2.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_EMMINTRIN_H) && defined(__x86_64__)
|
||||
static const crypto_stream_salsa20_implementation *implementation =
|
||||
&crypto_stream_salsa20_xmm6int_implementation;
|
||||
&crypto_stream_salsa20_xmm6int_sse2_implementation;
|
||||
#else
|
||||
static const crypto_stream_salsa20_implementation *implementation =
|
||||
&crypto_stream_salsa20_ref_implementation;
|
||||
@@ -63,14 +67,22 @@ int
|
||||
_crypto_stream_salsa20_pick_best_implementation(void)
|
||||
{
|
||||
#if defined(HAVE_EMMINTRIN_H) && defined(__x86_64__)
|
||||
implementation = &crypto_stream_salsa20_xmm6int_implementation;
|
||||
implementation = &crypto_stream_salsa20_xmm6int_sse2_implementation;
|
||||
#else
|
||||
implementation = &crypto_stream_salsa20_ref_implementation;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \
|
||||
defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)
|
||||
if (sodium_runtime_has_avx2()) {
|
||||
implementation = &crypto_stream_salsa20_xmm6int_avx2_implementation;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_EMMINTRIN_H
|
||||
if (sodium_runtime_has_sse2()) {
|
||||
implementation = &crypto_stream_salsa20_xmm6int_implementation;
|
||||
implementation = &crypto_stream_salsa20_xmm6int_sse2_implementation;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user