mirror of
https://github.com/BLAKE3-team/BLAKE3
synced 2024-05-09 03:26:16 +02:00
Compare commits
7 Commits
73e3e540bd
...
2f569069b6
Author | SHA1 | Date | |
---|---|---|---|
divinity76 | 2f569069b6 | ||
Javier Blazquez | 0816badf3a | ||
divinity76 | 059ad2d922 | ||
divinity76 | f9b332c61c | ||
divinity76 | 21459753ca | ||
divinity76 | 349f8300f9 | ||
hanshenrik | ba665ca9f1 |
|
@ -4,9 +4,12 @@
|
|||
|
||||
#include "blake3_impl.h"
|
||||
|
||||
#if defined(IS_X86)
|
||||
#if defined(_MSC_VER)
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(IS_X86)
|
||||
#if defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
#elif defined(__GNUC__)
|
||||
#include <immintrin.h>
|
||||
|
@ -96,6 +99,7 @@ enum cpu_feature {
|
|||
AVX2 = 1 << 4,
|
||||
AVX512F = 1 << 5,
|
||||
AVX512VL = 1 << 6,
|
||||
ARM_NEON = 1 << 7,
|
||||
/* ... */
|
||||
UNDEFINED = 1 << 30
|
||||
};
|
||||
|
@ -155,8 +159,19 @@ static
|
|||
}
|
||||
ATOMIC_STORE(g_cpu_features, features);
|
||||
return features;
|
||||
#elif defined(__aarch64__)
|
||||
uint64_t id_aa64pfr0_el1;
|
||||
__asm__ ("mrs %0, ID_AA64PFR0_EL1" : "=r" (id_aa64pfr0_el1));
|
||||
if(((id_aa64pfr0_el1 >> 20) & (1<<0 | 1<<1 | 1<<2 | 1 << 3)) != 15) {
|
||||
// https://developer.arm.com/documentation/ddi0595/2021-12/AArch64-Registers/ID-AA64PFR0-EL1--AArch64-Processor-Feature-Register-0?lang=en
|
||||
// 15 means not implemented, 0 means neon is present but float16 is missing, 1 means neon with float16 is present ?
|
||||
features = ARM_NEON;
|
||||
} else {
|
||||
features = 0;
|
||||
}
|
||||
ATOMIC_STORE(g_cpu_features, features);
|
||||
return features;
|
||||
#else
|
||||
/* How to detect NEON? */
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
@ -260,11 +275,19 @@ void blake3_hash_many(const uint8_t *const *inputs, size_t num_inputs,
|
|||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BLAKE3_USE_NEON == 1
|
||||
blake3_hash_many_neon(inputs, num_inputs, blocks, key, counter,
|
||||
increment_counter, flags, flags_start, flags_end, out);
|
||||
return;
|
||||
#elif __aarch64__
|
||||
{
|
||||
const enum cpu_feature features = get_cpu_features();
|
||||
if(features & ARM_NEON) {
|
||||
blake3_hash_many_neon(inputs, num_inputs, blocks, key, counter,
|
||||
increment_counter, flags, flags_start, flags_end, out);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
blake3_hash_many_portable(inputs, num_inputs, blocks, key, counter,
|
||||
|
@ -300,6 +323,11 @@ size_t blake3_simd_degree(void) {
|
|||
#endif
|
||||
#if BLAKE3_USE_NEON == 1
|
||||
return 4;
|
||||
#elif defined(__aarch64__)
|
||||
const enum cpu_feature features = get_cpu_features();
|
||||
if(features & ARM_NEON) {
|
||||
return 4;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ enum blake3_flags {
|
|||
#define INLINE static inline __attribute__((always_inline))
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(_M_X64)
|
||||
#if (defined(__x86_64__) || defined(_M_X64)) && !defined(_M_ARM64EC)
|
||||
#define IS_X86
|
||||
#define IS_X86_64
|
||||
#endif
|
||||
|
@ -38,7 +38,7 @@ enum blake3_flags {
|
|||
#define IS_X86_32
|
||||
#endif
|
||||
|
||||
#if defined(__aarch64__) || defined(_M_ARM64)
|
||||
#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
|
||||
#define IS_AARCH64
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue