Skip to content

Commit f580f02

Browse files
committed
Reduce hashops verbiage in OptMergePass
1 parent 09742e2 commit f580f02

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

kernel/hashlib.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class HasherDJB32 {
114114
return;
115115
}
116116
[[nodiscard]]
117-
hash_t yield() {
117+
hash_t yield() const {
118118
return (hash_t)state;
119119
}
120120

@@ -373,11 +373,20 @@ class commutative_hash {
373373
commutative_hash() {
374374
buckets.fill(0);
375375
}
376-
void eat(Hasher h) {
376+
template <typename T>
377+
void eat(const T &obj) {
378+
eat(hash_ops<T>::hash(obj));
379+
}
380+
template <>
381+
void eat(const Hasher &h) {
377382
Hasher::hash_t v = h.yield();
378383
size_t index = v & (buckets.size() - 1);
379384
buckets[index] += v;
380385
}
386+
template <typename T, typename U>
387+
void eat_pair(const T &v, const U &u) {
388+
eat(hash_ops<std::pair<T, U>>::hash(v, u));
389+
}
381390
[[nodiscard]] Hasher hash_into(Hasher h) const {
382391
for (auto b : buckets)
383392
h.eat(b);

passes/opt/opt_merge.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct OptMergeWorker
5151

5252
hashlib::commutative_hash comm;
5353
for (int i = 0; i < s_width; i++)
54-
comm.eat(hash_ops<std::pair<SigBit, SigSpec>>::hash({sig_s[i], sig_b.extract(i*width, width)}));
54+
comm.eat_pair(sig_s[i], sig_b.extract(i*width, width));
5555

5656
return comm.hash_into(h);
5757
}
@@ -86,8 +86,8 @@ struct OptMergeWorker
8686
if (cell->type.in(ID($and), ID($or), ID($xor), ID($xnor), ID($add), ID($mul),
8787
ID($logic_and), ID($logic_or), ID($_AND_), ID($_OR_), ID($_XOR_))) {
8888
hashlib::commutative_hash comm;
89-
comm.eat(hash_ops<RTLIL::SigSpec>::hash(assign_map(cell->getPort(ID::A))));
90-
comm.eat(hash_ops<RTLIL::SigSpec>::hash(assign_map(cell->getPort(ID::B))));
89+
comm.eat(assign_map(cell->getPort(ID::A)));
90+
comm.eat(assign_map(cell->getPort(ID::B)));
9191
h = comm.hash_into(h);
9292
} else if (cell->type.in(ID($reduce_xor), ID($reduce_xnor))) {
9393
SigSpec a = assign_map(cell->getPort(ID::A));
@@ -107,7 +107,7 @@ struct OptMergeWorker
107107
for (const auto& [port, sig] : cell->connections()) {
108108
if (cell->output(port))
109109
continue;
110-
comm.eat(hash_ops<std::pair<IdString, SigSpec>>::hash(port, assign_map(sig)));
110+
comm.eat_pair(port, assign_map(sig));
111111
}
112112
h = comm.hash_into(h);
113113
if (RTLIL::builtin_ff_cell_types().count(cell->type))
@@ -120,7 +120,7 @@ struct OptMergeWorker
120120
{
121121
hashlib::commutative_hash comm;
122122
for (const auto& param : cell->parameters) {
123-
comm.eat(hash_ops<std::pair<IdString, Const>>::hash(param));
123+
comm.eat(param);
124124
}
125125
return comm.hash_into(h);
126126
}

0 commit comments

Comments
 (0)