diff options
| author | Jack O'Connor <[email protected]> | 2020-01-21 14:04:59 -0500 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2020-01-22 21:32:39 -0500 |
| commit | 163f52245d3f6cfcc2ec2c91e01412ffba5f6d45 (patch) | |
| tree | 91937cc6aba2bb9d63b83b4d82b431fb9f9b9446 /c/blake3_dispatch.c | |
| parent | de1cf0038e26b8371408b4cb8b7fc6b4a47659df (diff) | |
port compress_subtree_to_parent_node from Rust to C
This recursive function performs parallel parent node hashing, which is
an important optimization.
Diffstat (limited to 'c/blake3_dispatch.c')
| -rw-r--r-- | c/blake3_dispatch.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/c/blake3_dispatch.c b/c/blake3_dispatch.c index 782139a..27a4d77 100644 --- a/c/blake3_dispatch.c +++ b/c/blake3_dispatch.c @@ -2,16 +2,7 @@ #include <stddef.h> #include <stdint.h> -#include "blake3.h" - -#if defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) || \ - defined(_M_X64) -#define IS_X86 -#endif - -#if defined(__arm__) -#define IS_ARM -#endif +#include "blake3_impl.h" #if defined(IS_X86) #if defined(_MSC_VER) @@ -82,7 +73,7 @@ void blake3_hash_many_avx512(const uint8_t *const *inputs, size_t num_inputs, #endif #endif -#if defined(IS_ARM) && !defined(BLAKE3_NO_NEON) +#if defined(IS_ARM) && defined(BLAKE3_USE_NEON) void blake3_hash_many_neon(const uint8_t *const *inputs, size_t num_inputs, size_t blocks, const uint32_t key[8], uint64_t counter, bool increment_counter, @@ -288,3 +279,29 @@ void blake3_hash_many(const uint8_t *const *inputs, size_t num_inputs, increment_counter, flags, flags_start, flags_end, out); } + +// The dynamically detected SIMD degree of the current platform. +size_t blake3_simd_degree() { + const enum cpu_feature features = get_cpu_features(); +#if defined(IS_X86) +#if !defined(BLAKE3_NO_AVX512) + if (features & AVX512F) { + return 16; + } +#endif +#if !defined(BLAKE3_NO_AVX2) + if (features & AVX2) { + return 8; + } +#endif +#if !defined(BLAKE3_NO_SSE41) + if (features & SSE41) { + return 4; + } +#endif +#endif +#if defined(BLAKE3_USE_NEON) + return 4; +#endif + return 1; +} |
