From 0e9af023234d7dbe3349a5303312c613dd28c861 Mon Sep 17 00:00:00 2001 From: Dmitriy Nester Date: Thu, 27 Feb 2020 15:04:25 +0200 Subject: [PATCH] nir: replace fnv1a hash function with xxhash xxhash is faster than fnv1a in almost all circumstances, so we're switching to it globally. Signed-off-by: Dmytro Nester Reviewed-by: Eric Anholt Part-of: --- src/compiler/nir/nir.h | 2 ++ src/compiler/nir/nir_instr_set.c | 10 ++++------ src/compiler/nir/nir_lower_locals_to_regs.c | 6 +++--- src/compiler/nir/nir_opt_load_store_vectorize.c | 13 ++++++------- src/compiler/nir/nir_opt_vectorize.c | 4 ++-- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index d32bbab..8b43c98 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -41,6 +41,8 @@ #include "compiler/nir_types.h" #include "compiler/shader_enums.h" #include "compiler/shader_info.h" +#define XXH_INLINE_ALL +#include "util/xxhash.h" #include #ifndef NDEBUG diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c index 212afbf..5e280a1 100644 --- a/src/compiler/nir/nir_instr_set.c +++ b/src/compiler/nir/nir_instr_set.c @@ -83,7 +83,7 @@ instr_can_rewrite(const nir_instr *instr) } -#define HASH(hash, data) _mesa_fnv32_1a_accumulate((hash), (data)) +#define HASH(hash, data) XXH32(&(data), sizeof(data), hash) static uint32_t hash_src(uint32_t hash, const nir_src *src) @@ -198,7 +198,7 @@ hash_load_const(uint32_t hash, const nir_load_const_instr *instr) } } else { unsigned size = instr->def.num_components * sizeof(*instr->value); - hash = _mesa_fnv32_1a_accumulate_block(hash, instr->value, size); + hash = XXH32(instr->value, size, hash); } return hash; @@ -246,9 +246,7 @@ hash_intrinsic(uint32_t hash, const nir_intrinsic_instr *instr) hash = HASH(hash, instr->dest.ssa.bit_size); } - hash = _mesa_fnv32_1a_accumulate_block(hash, instr->const_index, - info->num_indices - * sizeof(instr->const_index[0])); + hash = XXH32(instr->const_index, info->num_indices * sizeof(instr->const_index[0]), hash); return hash; } @@ -291,7 +289,7 @@ static uint32_t hash_instr(const void *data) { const nir_instr *instr = data; - uint32_t hash = _mesa_fnv32_1a_offset_bias; + uint32_t hash = 0; switch (instr->type) { case nir_instr_type_alu: diff --git a/src/compiler/nir/nir_lower_locals_to_regs.c b/src/compiler/nir/nir_lower_locals_to_regs.c index e417c64..dcac467 100644 --- a/src/compiler/nir/nir_lower_locals_to_regs.c +++ b/src/compiler/nir/nir_lower_locals_to_regs.c @@ -45,19 +45,19 @@ struct locals_to_regs_state { static uint32_t hash_deref(const void *void_deref) { - uint32_t hash = _mesa_fnv32_1a_offset_bias; + uint32_t hash = 0; for (const nir_deref_instr *deref = void_deref; deref; deref = nir_deref_instr_parent(deref)) { switch (deref->deref_type) { case nir_deref_type_var: - return _mesa_fnv32_1a_accumulate(hash, deref->var); + return XXH32(&deref->var, sizeof(deref->var), hash); case nir_deref_type_array: continue; /* Do nothing */ case nir_deref_type_struct: - hash = _mesa_fnv32_1a_accumulate(hash, deref->strct.index); + hash = XXH32(&deref->strct.index, sizeof(deref->strct.index), hash); continue; default: diff --git a/src/compiler/nir/nir_opt_load_store_vectorize.c b/src/compiler/nir/nir_opt_load_store_vectorize.c index 814c5a5..b35bcda 100644 --- a/src/compiler/nir/nir_opt_load_store_vectorize.c +++ b/src/compiler/nir/nir_opt_load_store_vectorize.c @@ -199,20 +199,19 @@ static uint32_t hash_entry_key(const void *key_) * the order of the hash table walk is deterministic */ struct entry_key *key = (struct entry_key*)key_; - uint32_t hash = _mesa_fnv32_1a_offset_bias; + uint32_t hash = 0; if (key->resource) - hash = _mesa_fnv32_1a_accumulate(hash, key->resource->index); + hash = XXH32(&key->resource->index, sizeof(key->resource->index), hash); if (key->var) { - hash = _mesa_fnv32_1a_accumulate(hash, key->var->index); + hash = XXH32(&key->var->index, sizeof(key->var->index), hash); unsigned mode = key->var->data.mode; - hash = _mesa_fnv32_1a_accumulate(hash, mode); + hash = XXH32(&mode, sizeof(mode), hash); } for (unsigned i = 0; i < key->offset_def_count; i++) - hash = _mesa_fnv32_1a_accumulate(hash, key->offset_defs[i]->index); + hash = XXH32(&key->offset_defs[i]->index, sizeof(key->offset_defs[i]->index), hash); - hash = _mesa_fnv32_1a_accumulate_block( - hash, key->offset_defs_mul, key->offset_def_count * sizeof(uint64_t)); + hash = XXH32(key->offset_defs_mul, key->offset_def_count * sizeof(uint64_t), hash); return hash; } diff --git a/src/compiler/nir/nir_opt_vectorize.c b/src/compiler/nir/nir_opt_vectorize.c index 20e03db..aee902c 100644 --- a/src/compiler/nir/nir_opt_vectorize.c +++ b/src/compiler/nir/nir_opt_vectorize.c @@ -27,7 +27,7 @@ #include "nir_builder.h" #include "util/u_dynarray.h" -#define HASH(hash, data) _mesa_fnv32_1a_accumulate((hash), (data)) +#define HASH(hash, data) XXH32(&data, sizeof(data), hash) static uint32_t hash_src(uint32_t hash, const nir_src *src) @@ -64,7 +64,7 @@ hash_alu(uint32_t hash, const nir_alu_instr *instr) static uint32_t hash_instr(const nir_instr *instr) { - uint32_t hash = _mesa_fnv32_1a_offset_bias; + uint32_t hash = 0; switch (instr->type) { case nir_instr_type_alu: -- 2.7.4