summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2015-10-28 11:21:55 +0100
committerClifford Wolf <clifford@clifford.at>2015-10-28 11:21:55 +0100
commit1e32e4bdae2e3fb3d1bf68314e146052a3c65561 (patch)
treed2e1e951be964afcc3b097c17b12e0a24d07ba96
parente69efec588ddfa65b7a2d6970bab7a3bcfa77b04 (diff)
Improved SigMap performance
-rw-r--r--CodingReadme3
-rw-r--r--kernel/hashlib.h5
-rw-r--r--kernel/sigtools.h13
3 files changed, 16 insertions, 5 deletions
diff --git a/CodingReadme b/CodingReadme
index a385a99d..5d5d9b32 100644
--- a/CodingReadme
+++ b/CodingReadme
@@ -93,6 +93,9 @@ creates a bijective map from K to the integers. For example:
It is not possible to remove elements from an idict.
+Finally mfp<K> implements a merge-find set data structure (aka. disjoint-set or
+union–find) over the type K ("mfp" = merge-find-promote).
+
2. Standard STL data types
In Yosys we use std::vector<T> and std::string whenever applicable. When
diff --git a/kernel/hashlib.h b/kernel/hashlib.h
index 83c112f3..1f022e47 100644
--- a/kernel/hashlib.h
+++ b/kernel/hashlib.h
@@ -985,6 +985,11 @@ public:
parents[i] = -1;
}
+ int lookup(const K &a) const
+ {
+ return ifind((*this)(a));
+ }
+
const K &find(const K &a) const
{
return (*this)[ifind((*this)(a))];
diff --git a/kernel/sigtools.h b/kernel/sigtools.h
index 3ef87199..d73c5623 100644
--- a/kernel/sigtools.h
+++ b/kernel/sigtools.h
@@ -253,18 +253,21 @@ struct SigMap
for (int i = 0; i < GetSize(from); i++)
{
- RTLIL::SigBit bf = database.find(from[i]);
- RTLIL::SigBit bt = database.find(to[i]);
+ int bfi = database.lookup(from[i]);
+ int bti = database.lookup(to[i]);
+
+ const RTLIL::SigBit &bf = database[bfi];
+ const RTLIL::SigBit &bt = database[bti];
if (bf.wire || bt.wire)
{
- database.merge(bf, bt);
+ database.imerge(bfi, bti);
if (bf.wire == nullptr)
- database.promote(bf);
+ database.ipromote(bfi);
if (bt.wire == nullptr)
- database.promote(bt);
+ database.ipromote(bti);
}
}
}