diff options
author | Dan Shumow <shumow@gmail.com> | 2017-05-09 19:29:41 +0300 |
---|---|---|
committer | Dan Shumow <shumow@gmail.com> | 2017-05-09 19:29:41 +0300 |
commit | b04a1905345a9cc015113752ee195822160c09c9 (patch) | |
tree | cc5dfa807d6cc062625d1c32eda73eb8e114491d | |
parent | c8effa8e875edcce415414c163d71a68eabe622f (diff) |
Establishes mechanisms for selecting SIMD implementations.
-rw-r--r-- | lib/simd/sha1_simd.c | 33 | ||||
-rw-r--r-- | lib/simd/sha1_simd.h | 72 |
2 files changed, 102 insertions, 3 deletions
diff --git a/lib/simd/sha1_simd.c b/lib/simd/sha1_simd.c index 1a07c40..cfc6f6c 100644 --- a/lib/simd/sha1_simd.c +++ b/lib/simd/sha1_simd.c @@ -8,7 +8,9 @@ #include <stdlib.h> #include <stdint.h> -#include <sha1.h> +#include "sha1.h" +#include "sha1_simd.h" + #define CNT_SHA1_DVS (16) uint32_t sha1_dvs_interleaved[80][CNT_SHA1_DVS] = @@ -103,7 +105,32 @@ size_t offset65 = 0; size_t len58 = 0; size_t len65 = 0; -/* +/* volatile char should have atomic writes. */ +volatile char simd_index = -1; + +sha1_simd_implementation_t *simd_implementation_table[SIMD_IMPLEMENTATION_CNT+1] = +{ +#ifdef SHA1DC_HAVE_MMX64 + &sha1_simd_mmx64_implementation, +#endif +#ifdef SHA1DC_HAVE_SSE128 + &sha1_simd_SSE128_implementation, +#endif +#ifdef SHA1DC_HAVE_NEON128 + &sha1_simd_neon128_implementation, +#endif +#ifdef SHA1DC_HAVE_AVX256 + &sha1_simd_avx256_implementation, +#endif +#ifdef SHA1DC_HAVE_AVX512 + &sha1_simd_avx512_implementation, +#endif + NULL +}; + + + +#ifdef SHA1_SIMD_IMPLEMENTED_XXXXX static void sha1_process_simd(SHA1_CTX* ctx, const uint32_t block[16]) { ctx->ihv1[0] = ctx->ihv[0]; @@ -138,4 +165,4 @@ static void sha1_process_simd(SHA1_CTX* ctx, const uint32_t block[16]) } } } -*/ +#endif diff --git a/lib/simd/sha1_simd.h b/lib/simd/sha1_simd.h new file mode 100644 index 0000000..7ec9e87 --- /dev/null +++ b/lib/simd/sha1_simd.h @@ -0,0 +1,72 @@ +/*** +* Copyright 2017 Marc Stevens <marc@marc-stevens.nl>, Dan Shumow (danshu@microsoft.com) +* Distributed under the MIT Software License. +* See accompanying file LICENSE.txt or copy at +* https://opensource.org/licenses/MIT +***/ +#ifndef SHA1DC_SHA1_SIMD_H +#define SHA1DC_SHA1_SIMD_H + +typedef enum { + simd_type_mmx64 = 0, + simd_type_sse128, + simd_type_neon128, + simd_type_avx256, + simd_type_avx512, + simd_type_unknown = 0xff +} simd_type; + +typedef void (*sha1_recompression_simd_fn)(void*, void*, const void*, const void*); +typedef void (*sha1_apply_message_differences_simd_fn)(const uint32_t me[80], const void*, void*); +typedef void (*sha1_compare_digests_simd_fn)(const SHA1_CTX* ctx, const void*, const void*, void*); + +typedef struct { + simd_type type; + size_t cnt_lanes; + sha1_recompression_simd_fn sha1_recompression_fast_58; + sha1_recompression_simd_fn sha1_recompression_fast_65; + sha1_apply_message_differences_simd_fn sha1_apply_message_differences; + sha1_compare_digests_simd_fn sha1_compare_digests; +} sha1_simd_implementation_t; + +#ifdef SHA1DC_HAVE_MMX64 + #define SHA1DC_MMX64 (1) + extern sha1_simd_implementation_t sha1_simd_mmx64_implementation; +#else + #define SHA1DC_MMX64 (0) +#endif + +#ifdef SHA1DC_HAVE_SSE128 + #define SHA1DC_SSE128 (1)_ + extern sha1_simd_implementation_t sha1_simd_sse128_implementation; +#else + #define SHA1DC_SSE128 (0) +#endif + +#ifdef SHA1DC_HAVE_NEON128 + #define SHA1DC_NEON128 (1) + extern sha1_simd_implementation_t sha1_simd_neon128_implementation; +#else + #define SHA1DC_NEON128 (0) +#endif + +#ifdef SHA1DC_HAVE_AVX256 + #define SHA1DC_AVX256 (1) + extern sha1_simd_implementation_t sha1_simd_avx256_implementation; +#else + #define SHA1DC_AVX256 (0) +#endif + +#ifdef SHA1DC_HAVE_AVX512 + #define SHA1DC_AVX512 (1) + extern sha1_simd_implementation_t sha1_simd_avx512_implementation; +#else + #define SHA1DC_AVX512 (0) +#endif + +#define SIMD_IMPLEMENTATION_CNT (SHA1DC_MMX64 + SHA1DC_SSE128 + SHA1DC_NEON128 + SHA1DC_AVX256 + SHA1DC_AVX512) + + + + +#endif /* SHA1DC_SHA1_SIMD_H */ |