Mesa (master): nir: replace fnv1a hash function with xxhash
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon May 25 19:56:39 UTC 2020
Module: Mesa
Branch: master
Commit: 0e9af023234d7dbe3349a5303312c613dd28c861
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=0e9af023234d7dbe3349a5303312c613dd28c861
Author: Dmitriy Nester <dmitriynester at gmail.com>
Date: Thu Feb 27 15:04:25 2020 +0200
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 <dmytro.nester at globallogic.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4020>
---
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 d32bbab5dfc..8b43c98754e 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 <stdio.h>
#ifndef NDEBUG
diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c
index 212afbf3dac..5e280a1e3e0 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 e417c6419fa..dcac46727cf 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 814c5a55264..b35bcdaf988 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 20e03db0d38..aee902c8a94 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:
More information about the mesa-commit
mailing list