30#define INLINE static __forceinline
32#define INLINE static inline __attribute__((always_inline))
35#if defined(__x86_64__) || defined(_M_X64)
40#if defined(__i386__) || defined(_M_IX86)
45#if defined(__aarch64__) || defined(_M_ARM64)
56#if !defined(BLAKE3_USE_NEON)
59 #if defined(IS_AARCH64) && !defined(__ARM_BIG_ENDIAN)
60 #define BLAKE3_USE_NEON 1
62 #define BLAKE3_USE_NEON 0
67#define MAX_SIMD_DEGREE 16
68#elif BLAKE3_USE_NEON == 1
69#define MAX_SIMD_DEGREE 4
71#define MAX_SIMD_DEGREE 1
76#define MAX_SIMD_DEGREE_OR_2 (MAX_SIMD_DEGREE > 2 ? MAX_SIMD_DEGREE : 2)
78static const uint32_t IV[8] = {0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL,
79 0xA54FF53AUL, 0x510E527FUL, 0x9B05688CUL,
80 0x1F83D9ABUL, 0x5BE0CD19UL};
83 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
84 {2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8},
85 {3, 4, 10, 12, 13, 2, 7, 14, 6, 5, 9, 0, 11, 15, 8, 1},
86 {10, 7, 12, 9, 14, 3, 13, 15, 4, 0, 11, 2, 5, 8, 1, 6},
87 {12, 13, 9, 11, 15, 10, 14, 8, 7, 2, 5, 3, 0, 1, 6, 4},
88 {9, 14, 11, 5, 8, 12, 15, 1, 13, 3, 0, 10, 2, 6, 4, 7},
89 {11, 15, 5, 0, 1, 9, 8, 6, 14, 10, 2, 12, 3, 4, 7, 13},
95#if defined(__GNUC__) || defined(__clang__)
96 return 63 ^ __builtin_clzll(x);
97#elif defined(_MSC_VER) && defined(IS_X86_64)
99 _BitScanReverse64(&index, x);
101#elif defined(_MSC_VER) && defined(IS_X86_32)
104 _BitScanReverse(&index, (
unsigned long)(x >> 32));
108 _BitScanReverse(&index, (
unsigned long)x);
113 if(x & 0xffffffff00000000ULL) { x >>= 32; c += 32; }
114 if(x & 0x00000000ffff0000ULL) { x >>= 16; c += 16; }
115 if(x & 0x000000000000ff00ULL) { x >>= 8; c += 8; }
116 if(x & 0x00000000000000f0ULL) { x >>= 4; c += 4; }
117 if(x & 0x000000000000000cULL) { x >>= 2; c += 2; }
118 if(x & 0x0000000000000002ULL) { c += 1; }
125#if defined(__GNUC__) || defined(__clang__)
126 return __builtin_popcountll(x);
128 unsigned int count = 0;
150 const uint8_t *p = (
const uint8_t *)src;
157 key_words[0] =
load32(&key[0 * 4]);
158 key_words[1] =
load32(&key[1 * 4]);
159 key_words[2] =
load32(&key[2 * 4]);
160 key_words[3] =
load32(&key[3 * 4]);
161 key_words[4] =
load32(&key[4 * 4]);
162 key_words[5] =
load32(&key[5 * 4]);
163 key_words[6] =
load32(&key[6 * 4]);
164 key_words[7] =
load32(&key[7 * 4]);
168 uint8_t *p = (uint8_t *)dst;
169 p[0] = (uint8_t)(w >> 0);
170 p[1] = (uint8_t)(w >> 8);
171 p[2] = (uint8_t)(w >> 16);
172 p[3] = (uint8_t)(w >> 24);
176 store32(&bytes_out[0 * 4], cv_words[0]);
177 store32(&bytes_out[1 * 4], cv_words[1]);
178 store32(&bytes_out[2 * 4], cv_words[2]);
179 store32(&bytes_out[3 * 4], cv_words[3]);
180 store32(&bytes_out[4 * 4], cv_words[4]);
181 store32(&bytes_out[5 * 4], cv_words[5]);
182 store32(&bytes_out[6 * 4], cv_words[6]);
183 store32(&bytes_out[7 * 4], cv_words[7]);
189 uint8_t block_len,
uint64_t counter,
195 uint8_t block_len,
uint64_t counter, uint8_t flags,
201 bool increment_counter, uint8_t flags,
202 uint8_t flags_start, uint8_t flags_end, uint8_t *out);
212 uint8_t block_len,
uint64_t counter,
218 uint8_t block_len,
uint64_t counter,
219 uint8_t flags, uint8_t out[64]);
224 uint64_t counter,
bool increment_counter,
225 uint8_t flags, uint8_t flags_start,
226 uint8_t flags_end, uint8_t *out);
229#if !defined(BLAKE3_NO_SSE2)
233 uint8_t block_len,
uint64_t counter,
238 uint8_t block_len,
uint64_t counter,
239 uint8_t flags, uint8_t out[64]);
243 uint64_t counter,
bool increment_counter,
244 uint8_t flags, uint8_t flags_start,
245 uint8_t flags_end, uint8_t *out);
247#if !defined(BLAKE3_NO_SSE41)
251 uint8_t block_len,
uint64_t counter,
256 uint8_t block_len,
uint64_t counter,
257 uint8_t flags, uint8_t out[64]);
261 uint64_t counter,
bool increment_counter,
262 uint8_t flags, uint8_t flags_start,
263 uint8_t flags_end, uint8_t *out);
265#if !defined(BLAKE3_NO_AVX2)
269 uint64_t counter,
bool increment_counter,
270 uint8_t flags, uint8_t flags_start,
271 uint8_t flags_end, uint8_t *out);
273#if !defined(BLAKE3_NO_AVX512)
277 uint8_t block_len,
uint64_t counter,
283 uint8_t block_len,
uint64_t counter,
284 uint8_t flags, uint8_t out[64]);
289 uint64_t counter,
bool increment_counter,
290 uint8_t flags, uint8_t flags_start,
291 uint8_t flags_end, uint8_t *out);
295#if BLAKE3_USE_NEON == 1
299 uint64_t counter,
bool increment_counter,
300 uint8_t flags, uint8_t flags_start,
301 uint8_t flags_end, uint8_t *out);
bbsections Prepares for basic block by splitting functions into clusters of basic blocks
#define LLVM_LIBRARY_VISIBILITY
unify loop Fixup each natural loop to have a single exit block
static const uint8_t MSG_SCHEDULE[7][16]
INLINE unsigned int popcnt(uint64_t x)
LLVM_LIBRARY_VISIBILITY size_t blake3_simd_degree(void)
static const uint32_t IV[8]
static unsigned int highest_one(uint64_t x)
INLINE uint32_t counter_high(uint64_t counter)
INLINE void load_key_words(const uint8_t key[BLAKE3_KEY_LEN], uint32_t key_words[8])
INLINE void store_cv_words(uint8_t bytes_out[32], uint32_t cv_words[8])
INLINE uint64_t round_down_to_power_of_2(uint64_t x)
INLINE uint32_t load32(const void *src)
INLINE void store32(void *dst, uint32_t w)
INLINE uint32_t counter_low(uint64_t counter)
#define blake3_compress_in_place_sse41
#define blake3_hash_many_neon
#define blake3_hash_many_avx512
#define blake3_hash_many_avx2
#define blake3_compress_xof_sse2
#define blake3_hash_many_sse41
#define blake3_compress_xof
#define blake3_compress_xof_sse41
#define blake3_compress_in_place_sse2
#define blake3_compress_in_place
#define blake3_compress_xof_avx512
#define blake3_compress_xof_portable
#define blake3_hash_many_portable
#define blake3_hash_many_sse2
#define blake3_compress_in_place_portable
#define blake3_compress_in_place_avx512