From 06750987331a3d832ea83f2205c56612d3506332 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 30 Dec 2014 18:51:24 +0100 Subject: added hashlib::mkhash_init --- kernel/hashlib.h | 8 +++++--- kernel/rtlil.cc | 2 +- kernel/rtlil.h | 2 +- kernel/yosys.h | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) (limited to 'kernel') diff --git a/kernel/hashlib.h b/kernel/hashlib.h index c93e00a0..0b6e94a3 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -21,13 +21,15 @@ const int hashtable_size_trigger = 2; const int hashtable_size_factor = 3; // The XOR version of DJB2 -// (traditionally 5381 is used as starting value for the djb2 hash) inline unsigned int mkhash(unsigned int a, unsigned int b) { return ((a << 5) + a) ^ b; } +// traditionally 5381 is used as starting value for the djb2 hash +const unsigned int mkhash_init = 5381; + // The ADD version of DJB2 -// (use this version for cache locality in b) +// (usunsigned int mkhashe this version for cache locality in b) inline unsigned int mkhash_add(unsigned int a, unsigned int b) { return ((a << 5) + a) + b; } @@ -96,7 +98,7 @@ struct hash_cstr_ops { return true; } unsigned int hash(const char *a) const { - unsigned int hash = 5381; + unsigned int hash = mkhash_init; while (*a) hash = mkhash(hash, *(a++)); return hash; diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 912df790..cd2232c8 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -2325,7 +2325,7 @@ void RTLIL::SigSpec::updhash() const cover("kernel.rtlil.sigspec.hash"); that->pack(); - that->hash_ = 5381; + that->hash_ = mkhash_init; for (auto &c : that->chunks_) if (c.wire == NULL) { for (auto &v : c.data) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index bb9e85d9..739b701f 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -463,7 +463,7 @@ struct RTLIL::Const inline int size() const { return bits.size(); } inline unsigned int hash() const { - unsigned int h = 5381; + unsigned int h = mkhash_init; for (auto b : bits) mkhash(h, b); return h; diff --git a/kernel/yosys.h b/kernel/yosys.h index a4836f35..5f3c3577 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -138,6 +138,7 @@ YOSYS_NAMESPACE_BEGIN using std::vector; using std::string; using hashlib::mkhash; +using hashlib::mkhash_init; using hashlib::mkhash_add; using hashlib::mkhash_xorshift; using hashlib::hash_ops; -- cgit v1.2.3