Improved SigMap performance
authorClifford Wolf <clifford@clifford.at>
Wed, 28 Oct 2015 10:21:55 +0000 (11:21 +0100)
committerClifford Wolf <clifford@clifford.at>
Wed, 28 Oct 2015 10:21:55 +0000 (11:21 +0100)
CodingReadme
kernel/hashlib.h
kernel/sigtools.h

index a385a99dc759032d244df1f73fb7b1bb24daca6f..5d5d9b32ce9622bde5a9eaf6653dbb5c6d691550 100644 (file)
@@ -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
index 83c112f3cc6d69c05e0262444f5e605fc6483d8b..1f022e473c6302c27676f005eb1970f9ce11b564 100644 (file)
@@ -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))];
index 3ef87199e309b22653bdc417b8079198ae7c796a..d73c5623d3c61163650d8b70d2ec3b42eeac2bea 100644 (file)
@@ -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);
                        }
                }
        }