LLVM 22.0.0git
blake3_impl.h File Reference
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "llvm-c/blake3.h"
#include "llvm/Support/Compiler.h"
#include "llvm_blake3_prefix.h"

Go to the source code of this file.

Macros

#define BLAKE3_PRIVATE
#define INLINE   static inline __attribute__((always_inline))
#define BLAKE3_USE_NEON   0
#define MAX_SIMD_DEGREE   1
#define MAX_SIMD_DEGREE_OR_2   (MAX_SIMD_DEGREE > 2 ? MAX_SIMD_DEGREE : 2)

Enumerations

enum  blake3_flags {
  CHUNK_START = 1 << 0 , CHUNK_END = 1 << 1 , PARENT = 1 << 2 , ROOT = 1 << 3 ,
  KEYED_HASH = 1 << 4 , DERIVE_KEY_CONTEXT = 1 << 5 , DERIVE_KEY_MATERIAL = 1 << 6
}

Functions

static unsigned int highest_one (uint64_t x)
INLINE unsigned int popcnt (uint64_t x)
INLINE uint64_t round_down_to_power_of_2 (uint64_t x)
INLINE uint32_t counter_low (uint64_t counter)
INLINE uint32_t counter_high (uint64_t counter)
INLINE uint32_t load32 (const void *src)
INLINE void load_key_words (const uint8_t key[BLAKE3_KEY_LEN], uint32_t key_words[8])
INLINE void load_block_words (const uint8_t block[BLAKE3_BLOCK_LEN], uint32_t block_words[16])
INLINE void store32 (void *dst, uint32_t w)
INLINE void store_cv_words (uint8_t bytes_out[32], uint32_t cv_words[8])
LLVM_LIBRARY_VISIBILITY void blake3_compress_in_place (uint32_t cv[8], const uint8_t block[BLAKE3_BLOCK_LEN], uint8_t block_len, uint64_t counter, uint8_t flags)
LLVM_LIBRARY_VISIBILITY void blake3_compress_xof (const uint32_t cv[8], const uint8_t block[BLAKE3_BLOCK_LEN], uint8_t block_len, uint64_t counter, uint8_t flags, uint8_t out[64])
LLVM_LIBRARY_VISIBILITY void blake3_xof_many (const uint32_t cv[8], const uint8_t block[BLAKE3_BLOCK_LEN], uint8_t block_len, uint64_t counter, uint8_t flags, uint8_t out[64], size_t outblocks)
LLVM_LIBRARY_VISIBILITY void blake3_hash_many (const uint8_t *const *inputs, size_t num_inputs, size_t blocks, const uint32_t key[8], uint64_t counter, bool increment_counter, uint8_t flags, uint8_t flags_start, uint8_t flags_end, uint8_t *out)
LLVM_LIBRARY_VISIBILITY size_t blake3_simd_degree (void)
BLAKE3_PRIVATE size_t blake3_compress_subtree_wide (const uint8_t *input, size_t input_len, const uint32_t key[8], uint64_t chunk_counter, uint8_t flags, uint8_t *out, bool use_tbb)
LLVM_LIBRARY_VISIBILITY void blake3_compress_in_place_portable (uint32_t cv[8], const uint8_t block[BLAKE3_BLOCK_LEN], uint8_t block_len, uint64_t counter, uint8_t flags)
LLVM_LIBRARY_VISIBILITY void blake3_compress_xof_portable (const uint32_t cv[8], const uint8_t block[BLAKE3_BLOCK_LEN], uint8_t block_len, uint64_t counter, uint8_t flags, uint8_t out[64])
LLVM_LIBRARY_VISIBILITY void blake3_hash_many_portable (const uint8_t *const *inputs, size_t num_inputs, size_t blocks, const uint32_t key[8], uint64_t counter, bool increment_counter, uint8_t flags, uint8_t flags_start, uint8_t flags_end, uint8_t *out)

Variables

static const uint32_t IV [8]
static const uint8_t MSG_SCHEDULE [7][16]

Macro Definition Documentation

◆ BLAKE3_PRIVATE

#define BLAKE3_PRIVATE

Definition at line 16 of file blake3_impl.h.

◆ BLAKE3_USE_NEON

#define BLAKE3_USE_NEON   0

Definition at line 67 of file blake3_impl.h.

◆ INLINE

#define INLINE   static inline __attribute__((always_inline))

Definition at line 34 of file blake3_impl.h.

Referenced by add_128(), add_256(), add_512(), addv(), addv(), blake3_hasher_update_base(), blend_epi16(), chunk_state_fill_buf(), chunk_state_init(), chunk_state_len(), chunk_state_maybe_start_flag(), chunk_state_output(), chunk_state_reset(), chunk_state_update(), compress_chunks_parallel(), compress_parents_parallel(), compress_pre(), compress_pre(), counter_high(), counter_low(), diagonalize(), g(), g1(), g2(), hash_one_avx512(), hash_one_portable(), hash_one_sse2(), hash_one_sse41(), hasher_init_base(), hasher_merge_cv_stack(), hasher_push_cv(), left_subtree_len(), load32(), load_block_words(), load_counters(), load_counters(), load_counters16(), load_counters4(), load_counters8(), load_key_words(), loadu(), loadu(), loadu_128(), loadu_256(), loadu_512(), make_output(), output_chaining_value(), output_root_bytes(), parent_output(), popcnt(), rot12(), rot12(), rot12_128(), rot12_256(), rot12_512(), rot16(), rot16(), rot16_128(), rot16_256(), rot16_512(), rot7(), rot7(), rot7_128(), rot7_256(), rot7_512(), rot8(), rot8(), rot8_128(), rot8_256(), rot8_512(), rotr32(), round_down_to_power_of_2(), round_fn(), round_fn(), round_fn(), round_fn16(), round_fn4(), round_fn8(), set1(), set1_128(), set1_256(), set1_512(), set4(), store32(), store_cv_words(), storeu(), storeu(), storeu_128(), storeu_256(), storeu_512(), transpose_msg_vecs(), transpose_msg_vecs(), transpose_msg_vecs16(), transpose_msg_vecs4(), transpose_msg_vecs8(), transpose_vecs(), transpose_vecs(), transpose_vecs_128(), transpose_vecs_256(), transpose_vecs_512(), undiagonalize(), unpack_hi_128(), unpack_lo_128(), xor_128(), xor_256(), xor_512(), xorv(), and xorv().

◆ MAX_SIMD_DEGREE

#define MAX_SIMD_DEGREE   1

Definition at line 76 of file blake3_impl.h.

Referenced by compress_chunks_parallel().

◆ MAX_SIMD_DEGREE_OR_2

#define MAX_SIMD_DEGREE_OR_2   (MAX_SIMD_DEGREE > 2 ? MAX_SIMD_DEGREE : 2)

Enumeration Type Documentation

◆ blake3_flags

Enumerator
CHUNK_START 
CHUNK_END 
PARENT 
ROOT 
KEYED_HASH 
DERIVE_KEY_CONTEXT 
DERIVE_KEY_MATERIAL 

Definition at line 19 of file blake3_impl.h.

Function Documentation

◆ blake3_compress_in_place()

◆ blake3_compress_in_place_portable()

LLVM_LIBRARY_VISIBILITY void blake3_compress_in_place_portable ( uint32_t cv[8],
const uint8_t block[BLAKE3_BLOCK_LEN],
uint8_t block_len,
uint64_t counter,
uint8_t flags )

Definition at line 84 of file blake3_portable.c.

References BLAKE3_BLOCK_LEN, block, and compress_pre().

◆ blake3_compress_subtree_wide()

BLAKE3_PRIVATE size_t blake3_compress_subtree_wide ( const uint8_t * input,
size_t input_len,
const uint32_t key[8],
uint64_t chunk_counter,
uint8_t flags,
uint8_t * out,
bool use_tbb )

◆ blake3_compress_xof()

◆ blake3_compress_xof_portable()

LLVM_LIBRARY_VISIBILITY void blake3_compress_xof_portable ( const uint32_t cv[8],
const uint8_t block[BLAKE3_BLOCK_LEN],
uint8_t block_len,
uint64_t counter,
uint8_t flags,
uint8_t out[64] )

Definition at line 100 of file blake3_portable.c.

References BLAKE3_BLOCK_LEN, block, compress_pre(), and store32().

◆ blake3_hash_many()

LLVM_LIBRARY_VISIBILITY void blake3_hash_many ( const uint8_t *const * inputs,
size_t num_inputs,
size_t blocks,
const uint32_t key[8],
uint64_t counter,
bool increment_counter,
uint8_t flags,
uint8_t flags_start,
uint8_t flags_end,
uint8_t * out )

◆ blake3_hash_many_portable()

LLVM_LIBRARY_VISIBILITY void blake3_hash_many_portable ( const uint8_t *const * inputs,
size_t num_inputs,
size_t blocks,
const uint32_t key[8],
uint64_t counter,
bool increment_counter,
uint8_t flags,
uint8_t flags_start,
uint8_t flags_end,
uint8_t * out )

Definition at line 145 of file blake3_portable.c.

References BLAKE3_OUT_LEN, blocks, and hash_one_portable().

◆ blake3_simd_degree()

LLVM_LIBRARY_VISIBILITY size_t blake3_simd_degree ( void )

Definition at line 304 of file blake3_dispatch.c.

References AVX2, AVX512F, AVX512VL, get_cpu_features(), MAYBE_UNUSED, SSE2, and SSE41.

◆ blake3_xof_many()

LLVM_LIBRARY_VISIBILITY void blake3_xof_many ( const uint32_t cv[8],
const uint8_t block[BLAKE3_BLOCK_LEN],
uint8_t block_len,
uint64_t counter,
uint8_t flags,
uint8_t out[64],
size_t outblocks )

◆ counter_high()

INLINE uint32_t counter_high ( uint64_t counter)

Definition at line 150 of file blake3_impl.h.

References INLINE.

Referenced by compress_pre(), and compress_pre().

◆ counter_low()

INLINE uint32_t counter_low ( uint64_t counter)

Definition at line 148 of file blake3_impl.h.

References INLINE.

Referenced by compress_pre(), and compress_pre().

◆ highest_one()

unsigned int highest_one ( uint64_t x)
static

Definition at line 99 of file blake3_impl.h.

Referenced by round_down_to_power_of_2().

◆ load32()

INLINE uint32_t load32 ( const void * src)

Definition at line 154 of file blake3_impl.h.

References INLINE.

Referenced by compress_pre(), load_block_words(), and load_key_words().

◆ load_block_words()

INLINE void load_block_words ( const uint8_t block[BLAKE3_BLOCK_LEN],
uint32_t block_words[16] )

Definition at line 172 of file blake3_impl.h.

References BLAKE3_BLOCK_LEN, block, INLINE, and load32().

Referenced by blake3_xof16_avx512(), blake3_xof4_avx512(), and blake3_xof8_avx512().

◆ load_key_words()

INLINE void load_key_words ( const uint8_t key[BLAKE3_KEY_LEN],
uint32_t key_words[8] )

◆ popcnt()

INLINE unsigned int popcnt ( uint64_t x)

Definition at line 129 of file blake3_impl.h.

References INLINE.

Referenced by hasher_merge_cv_stack().

◆ round_down_to_power_of_2()

INLINE uint64_t round_down_to_power_of_2 ( uint64_t x)

Definition at line 144 of file blake3_impl.h.

References highest_one(), and INLINE.

Referenced by blake3_hasher_update_base(), and left_subtree_len().

◆ store32()

INLINE void store32 ( void * dst,
uint32_t w )

Definition at line 179 of file blake3_impl.h.

References INLINE.

Referenced by blake3_compress_xof_portable(), and store_cv_words().

◆ store_cv_words()

INLINE void store_cv_words ( uint8_t bytes_out[32],
uint32_t cv_words[8] )

Definition at line 187 of file blake3_impl.h.

References INLINE, and store32().

Referenced by hash_one_portable(), and output_chaining_value().

Variable Documentation

◆ IV

const uint32_t IV[8]
static
Initial value:
= {0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL,
0xA54FF53AUL, 0x510E527FUL, 0x9B05688CUL,
0x1F83D9ABUL, 0x5BE0CD19UL}

Definition at line 83 of file blake3_impl.h.

Referenced by addFullyUnrolledInstructionsToIgnore(), addPHINodeEntriesForMappedBlock(), llvm::MCELFStreamer::AttributeItem::AttributeItem(), blake3_hash16_avx512(), blake3_hash4_avx512(), blake3_hash4_sse2(), blake3_hash4_sse41(), blake3_hash8_avx2(), blake3_hash8_avx512(), blake3_xof16_avx512(), blake3_xof4_avx512(), blake3_xof8_avx512(), llvm::BuildAttributeItem::BuildAttributeItem(), compress_pre(), compress_pre(), llvm::VPBuilder::createScalarIVSteps(), detectShiftUntilZeroIdiom(), llvm::JumpThreadingPass::duplicateCondBranchOnPHIIntoPred(), llvm::InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(), getAggregateSize(), getElementIndex(), llvm::DenseMapInfo< PointerIntPair< PointerTy, IntBits, IntType >, void >::getHashValue(), GetInductionVariable(), getTrueOrFalseValue(), insertUniqueBackedgeBlock(), llvm::isUniformLoop(), IsValueFullyAvailableInBlock(), likeBitCastFromVector(), llvm_blake3_hasher_init(), llvm_blake3_hasher_init_derive_key_raw(), LLVMGetIndices(), LLVMGetNumIndices(), preparePlanForEpilogueVectorLoop(), ReduceLoopStrength(), removeRedundantInductionCasts(), simplifyInstructionWithOperands(), llvm::SplitBlockAndInsertSimpleForLoop(), llvm::SCCPInstVisitor::trackValueOfGlobalVariable(), llvm::MemorySSAUpdater::updatePhisWhenInsertingUniqueBackedgeBlock(), llvm::slpvectorizer::BoUpSLP::vectorizeTree(), llvm::InstCombinerImpl::visitExtractValueInst(), llvm::InstCombinerImpl::visitPHINode(), llvm::InstCombinerImpl::visitSelectInst(), llvm::VPDerivedIVRecipe::VPDerivedIVRecipe(), llvm::VPScalarIVStepsRecipe::VPScalarIVStepsRecipe(), llvm::VPScalarIVStepsRecipe::VPScalarIVStepsRecipe(), llvm::VPWidenInductionRecipe::VPWidenInductionRecipe(), llvm::VPWidenIntOrFpInductionRecipe::VPWidenIntOrFpInductionRecipe(), and llvm::VPWidenIntOrFpInductionRecipe::VPWidenIntOrFpInductionRecipe().

◆ MSG_SCHEDULE

const uint8_t MSG_SCHEDULE[7][16]
static
Initial value:
= {
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
{2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8},
{3, 4, 10, 12, 13, 2, 7, 14, 6, 5, 9, 0, 11, 15, 8, 1},
{10, 7, 12, 9, 14, 3, 13, 15, 4, 0, 11, 2, 5, 8, 1, 6},
{12, 13, 9, 11, 15, 10, 14, 8, 7, 2, 5, 3, 0, 1, 6, 4},
{9, 14, 11, 5, 8, 12, 15, 1, 13, 3, 0, 10, 2, 6, 4, 7},
{11, 15, 5, 0, 1, 9, 8, 6, 14, 10, 2, 12, 3, 4, 7, 13},
}

Definition at line 87 of file blake3_impl.h.

Referenced by round_fn(), round_fn(), round_fn(), round_fn16(), round_fn4(), and round_fn8().