From: Clifford Wolf Date: Tue, 30 Dec 2014 22:45:43 +0000 (+0100) Subject: using pool<> in bitpattern.h X-Git-Tag: yosys-0.5~168 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6fef4b82a2315830f99eeca3a4e80697a90a8447;p=yosys.git using pool<> in bitpattern.h --- diff --git a/kernel/bitpattern.h b/kernel/bitpattern.h index 4d88c8e34..7416a488d 100644 --- a/kernel/bitpattern.h +++ b/kernel/bitpattern.h @@ -29,7 +29,7 @@ struct BitPatternPool { int width; typedef std::vector bits_t; - std::set pool; + pool database; BitPatternPool(RTLIL::SigSpec sig) { @@ -42,7 +42,7 @@ struct BitPatternPool else pattern[i] = RTLIL::State::Sa; } - pool.insert(pattern); + database.insert(pattern); } } @@ -53,7 +53,7 @@ struct BitPatternPool std::vector pattern(width); for (int i = 0; i < width; i++) pattern[i] = RTLIL::State::Sa; - pool.insert(pattern); + database.insert(pattern); } } @@ -79,7 +79,7 @@ struct BitPatternPool bool has_any(RTLIL::SigSpec sig) { bits_t bits = sig2bits(sig); - for (auto &it : pool) + for (auto &it : database) if (match(it, bits)) return true; return false; @@ -88,13 +88,13 @@ struct BitPatternPool bool has_all(RTLIL::SigSpec sig) { bits_t bits = sig2bits(sig); - for (auto &it : pool) + for (auto &it : database) if (match(it, bits)) { for (int i = 0; i < width; i++) if (bits[i] > RTLIL::State::S1 && it[i] <= RTLIL::State::S1) - goto next_pool_entry; + goto next_database_entry; return true; - next_pool_entry:; + next_database_entry:; } return false; } @@ -104,17 +104,17 @@ struct BitPatternPool bool status = false; bits_t bits = sig2bits(sig); std::vector pattern_list; - for (auto &it : pool) + for (auto &it : database) if (match(it, bits)) pattern_list.push_back(it); for (auto pattern : pattern_list) { - pool.erase(pattern); + database.erase(pattern); for (int i = 0; i < width; i++) { if (pattern[i] != RTLIL::State::Sa || bits[i] == RTLIL::State::Sa) continue; bits_t new_pattern = pattern; new_pattern[i] = bits[i] == RTLIL::State::S1 ? RTLIL::State::S0 : RTLIL::State::S1; - pool.insert(new_pattern); + database.insert(new_pattern); } status = true; } @@ -123,15 +123,15 @@ struct BitPatternPool bool take_all() { - if (pool.empty()) + if (database.empty()) return false; - pool.clear(); + database.clear(); return true; } bool empty() { - return pool.empty(); + return database.empty(); } }; diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 0b6e94a32..3164282f2 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -62,7 +62,8 @@ template<> struct hash_ops { bool cmp(T a, T b) const { return a == b; } - unsigned int hash(unsigned int a) const { + template + unsigned int hash(T a) const { return a; } }; @@ -90,6 +91,19 @@ template struct hash_ops> { } }; +template struct hash_ops> { + bool cmp(std::vector a, std::vector b) const { + return a == b; + } + unsigned int hash(std::vector a) const { + hash_ops t_ops; + unsigned int h = mkhash_init; + for (auto k : a) + h = mkhash(h, t_ops.hash(k)); + return h; + } +}; + struct hash_cstr_ops { bool cmp(const char *a, const char *b) const { for (int i = 0; a[i] || b[i]; i++) diff --git a/kernel/yosys.h b/kernel/yosys.h index 5f3c3577d..2c9ca0dd9 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -221,6 +221,10 @@ YOSYS_NAMESPACE_END YOSYS_NAMESPACE_BEGIN +namespace hashlib { + template<> struct hash_ops : hash_ops {}; +} + void yosys_setup(); void yosys_shutdown();