1
0
Fork 0
mirror of https://github.com/BLAKE3-team/BLAKE3 synced 2024-05-26 11:46:04 +02:00
This commit is contained in:
David CARLIER 2024-04-06 12:03:35 +08:00 committed by GitHub
commit c273deae35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,6 +13,12 @@
#else #else
#undef IS_X86 /* Unimplemented! */ #undef IS_X86 /* Unimplemented! */
#endif #endif
#else
#if defined(_MSC_VER)
//
#elif defined(__linux__)
#include <sys/auxv.h>
#endif
#endif #endif
#if !defined(BLAKE3_ATOMICS) #if !defined(BLAKE3_ATOMICS)
@ -88,7 +94,17 @@ static void cpuidex(uint32_t out[4], uint32_t id, uint32_t sid) {
#endif #endif
#if defined(IS_AARCH64)
static int has_neon(void) {
#if defined(__linux__)
return getauxval(AT_HWCAP) & (1 << 1);
#endif
return 1;
}
#endif
enum cpu_feature { enum cpu_feature {
#if defined(IS_X86)
SSE2 = 1 << 0, SSE2 = 1 << 0,
SSSE3 = 1 << 1, SSSE3 = 1 << 1,
SSE41 = 1 << 2, SSE41 = 1 << 2,
@ -96,6 +112,9 @@ enum cpu_feature {
AVX2 = 1 << 4, AVX2 = 1 << 4,
AVX512F = 1 << 5, AVX512F = 1 << 5,
AVX512VL = 1 << 6, AVX512VL = 1 << 6,
#else
NEON = 1 << 0,
#endif
/* ... */ /* ... */
UNDEFINED = 1 << 30 UNDEFINED = 1 << 30
}; };
@ -156,8 +175,10 @@ static
ATOMIC_STORE(g_cpu_features, features); ATOMIC_STORE(g_cpu_features, features);
return features; return features;
#else #else
/* How to detect NEON? */ enum cpu_feature features = 0;
return 0; if (has_neon())
features |= NEON;
return features;
#endif #endif
} }
} }
@ -262,9 +283,12 @@ void blake3_hash_many(const uint8_t *const *inputs, size_t num_inputs,
#endif #endif
#if BLAKE3_USE_NEON == 1 #if BLAKE3_USE_NEON == 1
blake3_hash_many_neon(inputs, num_inputs, blocks, key, counter, const enum cpu_feature features = get_cpu_features();
if (features & NEON) {
blake3_hash_many_neon(inputs, num_inputs, blocks, key, counter,
increment_counter, flags, flags_start, flags_end, out); increment_counter, flags, flags_start, flags_end, out);
return; return;
}
#endif #endif
blake3_hash_many_portable(inputs, num_inputs, blocks, key, counter, blake3_hash_many_portable(inputs, num_inputs, blocks, key, counter,