diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 92188a220..70e9736f7 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -114,7 +114,7 @@ public: return; } [[nodiscard]] - hash_t yield() { + hash_t yield() const { return (hash_t)state; } @@ -373,7 +373,11 @@ public: commutative_hash() { buckets.fill(0); } - void eat(Hasher h) { + template + void eat(const T &obj) { + eat(hash_ops::hash(obj)); + } + void eat(const Hasher &h) { Hasher::hash_t v = h.yield(); size_t index = v & (buckets.size() - 1); buckets[index] += v; diff --git a/passes/opt/opt_merge.cc b/passes/opt/opt_merge.cc index fbfdb9b63..ded0e7360 100644 --- a/passes/opt/opt_merge.cc +++ b/passes/opt/opt_merge.cc @@ -33,6 +33,9 @@ USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN +template +inline Hasher hash_pair(const T &t, const U &u) { return hash_ops>::hash(t, u); } + struct OptMergeWorker { RTLIL::Design *design; @@ -51,7 +54,7 @@ struct OptMergeWorker hashlib::commutative_hash comm; for (int i = 0; i < s_width; i++) - comm.eat(hash_ops>::hash({sig_s[i], sig_b.extract(i*width, width)})); + comm.eat(hash_pair(sig_s[i], sig_b.extract(i*width, width))); return comm.hash_into(h); } @@ -86,8 +89,8 @@ struct OptMergeWorker if (cell->type.in(ID($and), ID($or), ID($xor), ID($xnor), ID($add), ID($mul), ID($logic_and), ID($logic_or), ID($_AND_), ID($_OR_), ID($_XOR_))) { hashlib::commutative_hash comm; - comm.eat(hash_ops::hash(assign_map(cell->getPort(ID::A)))); - comm.eat(hash_ops::hash(assign_map(cell->getPort(ID::B)))); + comm.eat(assign_map(cell->getPort(ID::A))); + comm.eat(assign_map(cell->getPort(ID::B))); h = comm.hash_into(h); } else if (cell->type.in(ID($reduce_xor), ID($reduce_xnor))) { SigSpec a = assign_map(cell->getPort(ID::A)); @@ -107,7 +110,7 @@ struct OptMergeWorker for (const auto& [port, sig] : cell->connections()) { if (cell->output(port)) continue; - comm.eat(hash_ops>::hash(port, assign_map(sig))); + comm.eat(hash_pair(port, assign_map(sig))); } h = comm.hash_into(h); if (RTLIL::builtin_ff_cell_types().count(cell->type)) @@ -120,7 +123,7 @@ struct OptMergeWorker { hashlib::commutative_hash comm; for (const auto& param : cell->parameters) { - comm.eat(hash_ops>::hash(param)); + comm.eat(param); } return comm.hash_into(h); }