mirror of
https://github.com/YosysHQ/yosys
synced 2025-10-01 13:39:30 +00:00
Merge pull request #5349 from rocallahan/cleanup-hashops
Reduce hashops verbiage in `OptMergePass`
This commit is contained in:
commit
7719beb4ae
2 changed files with 14 additions and 7 deletions
|
@ -114,7 +114,7 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
hash_t yield() {
|
hash_t yield() const {
|
||||||
return (hash_t)state;
|
return (hash_t)state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +382,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;
|
||||||
|
|
|
@ -34,6 +34,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;
|
||||||
|
@ -52,7 +55,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);
|
||||||
}
|
}
|
||||||
|
@ -87,8 +90,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));
|
||||||
|
@ -108,7 +111,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 (cell->is_builtin_ff())
|
if (cell->is_builtin_ff())
|
||||||
|
@ -121,7 +124,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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue