From: Clifford Wolf Date: Sun, 28 Dec 2014 23:12:36 +0000 (+0100) Subject: Added mkhash_xorshift() X-Git-Tag: yosys-0.5~195 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a2226e530791ec9dea45cd905f812de28d2c1c06;p=yosys.git Added mkhash_xorshift() --- diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 24a1dbf6d..021cc66ee 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -31,6 +31,20 @@ inline unsigned int mkhash_add(unsigned int a, unsigned int b) { return ((a << 5) + a) + b; } +inline unsigned int mkhash_xorshift(unsigned int a) { + if (sizeof(a) == 4) { + a ^= a << 13; + a ^= a >> 17; + a ^= a << 5; + } else if (sizeof(a) == 8) { + a ^= a << 13; + a ^= a >> 7; + a ^= a << 17; + } else + throw std::runtime_error("mkhash_xorshift() only implemented for 32 bit and 64 bit ints"); + return a; +} + template struct hash_ops { bool cmp(const T &a, const T &b) const { return a == b; @@ -122,7 +136,11 @@ inline int hashtable_size(int old_size) if (old_size < 250999999) return 250999999; if (old_size < 503000009) return 503000009; if (old_size < 1129999999) return 1129999999; - throw std::length_error("hash table exceeded maximum size"); + + if (sizeof(old_size) == 4) + throw std::length_error("hash table exceeded maximum size. recompile with -mint64."); + + return old_size * 2; } template> diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index cdbaa5bbf..f25df175d 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -236,8 +236,9 @@ void RTLIL::Selection::optimize(RTLIL::Design *design) RTLIL::Design::Design() { - static unsigned int hashidx_count = 0; - hashidx_ = hashidx_count++; + static unsigned int hashidx_count = 123456789; + hashidx_count = mkhash_xorshift(hashidx_count); + hashidx_ = hashidx_count; refcount_modules_ = 0; selection_stack.push_back(RTLIL::Selection()); @@ -450,8 +451,9 @@ std::vector RTLIL::Design::selected_whole_modules_warn() const RTLIL::Module::Module() { - static unsigned int hashidx_count = 0; - hashidx_ = hashidx_count++; + static unsigned int hashidx_count = 123456789; + hashidx_count = mkhash_xorshift(hashidx_count); + hashidx_ = hashidx_count; design = nullptr; refcount_wires_ = 0; @@ -1741,8 +1743,9 @@ RTLIL::Cell* RTLIL::Module::addDlatchsrGate(RTLIL::IdString name, RTLIL::SigSpec RTLIL::Wire::Wire() { - static unsigned int hashidx_count = 0; - hashidx_ = hashidx_count++; + static unsigned int hashidx_count = 123456789; + hashidx_count = mkhash_xorshift(hashidx_count); + hashidx_ = hashidx_count; module = nullptr; width = 1; @@ -1755,8 +1758,9 @@ RTLIL::Wire::Wire() RTLIL::Memory::Memory() { - static unsigned int hashidx_count = 0; - hashidx_ = hashidx_count++; + static unsigned int hashidx_count = 123456789; + hashidx_count = mkhash_xorshift(hashidx_count); + hashidx_ = hashidx_count; width = 1; size = 0; @@ -1764,8 +1768,9 @@ RTLIL::Memory::Memory() RTLIL::Cell::Cell() : module(nullptr) { - static unsigned int hashidx_count = 0; - hashidx_ = hashidx_count++; + static unsigned int hashidx_count = 123456789; + hashidx_count = mkhash_xorshift(hashidx_count); + hashidx_ = hashidx_count; // log("#memtrace# %p\n", this); memhasher(); diff --git a/kernel/rtlil.h b/kernel/rtlil.h index f759a014f..5bca060f4 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -712,8 +712,9 @@ struct RTLIL::Monitor unsigned int hash() const { return hashidx_; } Monitor() { - static unsigned int hashidx_count = 0; - hashidx_ = hashidx_count++; + static unsigned int hashidx_count = 123456789; + hashidx_count = mkhash_xorshift(hashidx_count); + hashidx_ = hashidx_count; } virtual ~Monitor() { } diff --git a/kernel/yosys.h b/kernel/yosys.h index bbcbd5fed..8ddd6f540 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -136,6 +136,7 @@ using std::vector; using std::string; using hashlib::mkhash; using hashlib::mkhash_add; +using hashlib::mkhash_xorshift; using hashlib::hash_ops; using hashlib::hash_cstr_ops; using hashlib::hash_ptr_ops;