3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-10-01 13:39:30 +00:00

Reduce hashops verbiage in OptMergePass

This commit is contained in:
Robert O'Callahan 2025-09-16 04:16:11 +00:00
parent 09742e27f7
commit 4fe21dd652
2 changed files with 14 additions and 7 deletions

View file

@ -114,7 +114,7 @@ public:
return; return;
} }
[[nodiscard]] [[nodiscard]]
hash_t yield() { hash_t yield() const {
return (hash_t)state; return (hash_t)state;
} }
@ -373,7 +373,11 @@ public:
commutative_hash() { commutative_hash() {
buckets.fill(0); buckets.fill(0);
} }
void eat(Hasher h) { template <typename T>
void eat(const T &obj) {
eat(hash_ops<T>::hash(obj));
}
void eat(const Hasher &h) {
Hasher::hash_t v = h.yield(); Hasher::hash_t v = h.yield();
size_t index = v & (buckets.size() - 1); size_t index = v & (buckets.size() - 1);
buckets[index] += v; buckets[index] += v;

View file

@ -33,6 +33,9 @@
USING_YOSYS_NAMESPACE USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN PRIVATE_NAMESPACE_BEGIN
template <typename T, typename U>
inline Hasher hash_pair(const T &t, const U &u) { return hash_ops<std::pair<T, U>>::hash(t, u); }
struct OptMergeWorker struct OptMergeWorker
{ {
RTLIL::Design *design; RTLIL::Design *design;
@ -51,7 +54,7 @@ struct OptMergeWorker
hashlib::commutative_hash comm; hashlib::commutative_hash comm;
for (int i = 0; i < s_width; i++) for (int i = 0; i < s_width; i++)
comm.eat(hash_ops<std::pair<SigBit, SigSpec>>::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); 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), 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_))) { ID($logic_and), ID($logic_or), ID($_AND_), ID($_OR_), ID($_XOR_))) {
hashlib::commutative_hash comm; hashlib::commutative_hash comm;
comm.eat(hash_ops<RTLIL::SigSpec>::hash(assign_map(cell->getPort(ID::A)))); comm.eat(assign_map(cell->getPort(ID::A)));
comm.eat(hash_ops<RTLIL::SigSpec>::hash(assign_map(cell->getPort(ID::B)))); comm.eat(assign_map(cell->getPort(ID::B)));
h = comm.hash_into(h); h = comm.hash_into(h);
} else if (cell->type.in(ID($reduce_xor), ID($reduce_xnor))) { } else if (cell->type.in(ID($reduce_xor), ID($reduce_xnor))) {
SigSpec a = assign_map(cell->getPort(ID::A)); SigSpec a = assign_map(cell->getPort(ID::A));
@ -107,7 +110,7 @@ struct OptMergeWorker
for (const auto& [port, sig] : cell->connections()) { for (const auto& [port, sig] : cell->connections()) {
if (cell->output(port)) if (cell->output(port))
continue; continue;
comm.eat(hash_ops<std::pair<IdString, SigSpec>>::hash(port, assign_map(sig))); comm.eat(hash_pair(port, assign_map(sig)));
} }
h = comm.hash_into(h); h = comm.hash_into(h);
if (RTLIL::builtin_ff_cell_types().count(cell->type)) if (RTLIL::builtin_ff_cell_types().count(cell->type))
@ -120,7 +123,7 @@ struct OptMergeWorker
{ {
hashlib::commutative_hash comm; hashlib::commutative_hash comm;
for (const auto& param : cell->parameters) { for (const auto& param : cell->parameters) {
comm.eat(hash_ops<std::pair<IdString, Const>>::hash(param)); comm.eat(param);
} }
return comm.hash_into(h); return comm.hash_into(h);
} }