From 3ca23c0c0ac6a1b649ebf7bd8bf776e19cbb607e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 8 Apr 2015 12:01:40 +0100 Subject: [PATCH] Check for SSE3, SSSE3 and SSE4.1 instructions. --- src/libcryptobox/CMakeLists.txt | 3 +++ src/libcryptobox/cryptobox.c | 11 ++++++++++- src/libcryptobox/platform_config.h.in | 6 ++++++ src/libcryptobox/siphash/siphash.c | 9 +++++---- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/libcryptobox/CMakeLists.txt b/src/libcryptobox/CMakeLists.txt index 59e5133be..491d7f9b5 100644 --- a/src/libcryptobox/CMakeLists.txt +++ b/src/libcryptobox/CMakeLists.txt @@ -14,6 +14,9 @@ IF(${ARCH} STREQUAL "x86_64") ASM_OP(HAVE_AVX2 "vpaddq %ymm0, %ymm0, %ymm0" "avx2") ASM_OP(HAVE_AVX "vpaddq %xmm0, %xmm0, %xmm0" "avx") ASM_OP(HAVE_SSE2 "pmuludq %xmm0, %xmm0" "sse2") + ASM_OP(HAVE_SSE3 "lddqu 0(%esi), %xmm0" "sse3") + ASM_OP(HAVE_SSSE3 "pshufb %xmm0, %xmm0" "ssse3") + ASM_OP(HAVE_SSE41 "pblendw \$0, %xmm0, %xmm0" "sse41") ASM_OP(HAVE_SLASHMACRO " .macro TEST1 op diff --git a/src/libcryptobox/cryptobox.c b/src/libcryptobox/cryptobox.c index 70e6992c6..847f005f1 100644 --- a/src/libcryptobox/cryptobox.c +++ b/src/libcryptobox/cryptobox.c @@ -87,7 +87,6 @@ rspamd_cryptobox_cpuid (gint cpu[4], gint info) #endif } - void rspamd_cryptobox_init (void) { @@ -106,6 +105,16 @@ rspamd_cryptobox_init (void) if ((cpu[2] & ((gint)1 << 28))) { cpu_config |= CPUID_AVX; } + if ((cpu[2] & ((gint)1 << 0))) { + cpu_config |= CPUID_SSE3; + } + if ((cpu[2] & ((gint)1 << 9))) { + cpu_config |= CPUID_SSSE3; + } + if ((cpu[2] & ((gint)1 << 19))) { + cpu_config |= CPUID_SSE41; + } + if (nid > 7) { rspamd_cryptobox_cpuid (cpu, 7); if ((cpu[1] & ((gint)1 << 5))) { diff --git a/src/libcryptobox/platform_config.h.in b/src/libcryptobox/platform_config.h.in index d109a7cd0..8feecb229 100644 --- a/src/libcryptobox/platform_config.h.in +++ b/src/libcryptobox/platform_config.h.in @@ -5,11 +5,17 @@ #cmakedefine HAVE_AVX2 1 #cmakedefine HAVE_AVX 1 #cmakedefine HAVE_SSE2 1 +#cmakedefine HAVE_SSE41 1 +#cmakedefine HAVE_SSE3 1 +#cmakedefine HAVE_SSSE3 1 #cmakedefine HAVE_SLASHMACRO 1 #cmakedefine HAVE_DOLLARMACRO 1 #define CPUID_AVX2 0x1 #define CPUID_AVX 0x2 #define CPUID_SSE2 0x4 +#define CPUID_SSE3 0x8 +#define CPUID_SSSE3 0x16 +#define CPUID_SSE41 0x32 #endif \ No newline at end of file diff --git a/src/libcryptobox/siphash/siphash.c b/src/libcryptobox/siphash/siphash.c index 68c4ba1cc..f4c8a1854 100644 --- a/src/libcryptobox/siphash/siphash.c +++ b/src/libcryptobox/siphash/siphash.c @@ -144,10 +144,11 @@ siphash24_test (void) { { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, } }; unsigned char in[64]; - static const unsigned char k[] = - {'\000', '\001', '\002', '\003', '\004', - '\005', '\006', '\007', '\010', '\011', - '\012', '\013', '\014', '\015', '\016', '\017'}; + static const unsigned char k[] ={ + '\000', '\001', '\002', '\003', '\004', + '\005', '\006', '\007', '\010', '\011', + '\012', '\013', '\014', '\015', '\016', '\017' + }; size_t i, cycles; union { guint64 m; -- 2.39.5