From 47ec9a706bd82c43231d965f0a8b525acdb06c26 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 13 Aug 2022 01:36:25 +0200 Subject: [PATCH] WIP: enhanced and debugged LVS hints --- src/db/db/dbNetlistCompareCore.cc | 48 ++++++++++++++++++++---------- src/db/db/dbNetlistCompareGraph.cc | 44 +++++++++++++++++++++++++++ src/db/db/dbNetlistCompareGraph.h | 10 +++++++ 3 files changed, 87 insertions(+), 15 deletions(-) diff --git a/src/db/db/dbNetlistCompareCore.cc b/src/db/db/dbNetlistCompareCore.cc index 03719b474..ace9f1783 100644 --- a/src/db/db/dbNetlistCompareCore.cc +++ b/src/db/db/dbNetlistCompareCore.cc @@ -1276,11 +1276,11 @@ static size_t distance (const NetGraphNode &a, const NetGraphNode &b) continue; } - if (*i < *j) { + if (i->first < j->first) { ++fuzz; ++i; continue; - } else if (*j < *i) { + } else if (j->first < i->first) { ++fuzz; ++j; continue; @@ -1294,8 +1294,22 @@ static size_t distance (const NetGraphNode &a, const NetGraphNode &b) return fuzz; } -static size_t distance3 (const NetGraphNode &a, const NetGraphNode &b1, const NetGraphNode &b2) +static size_t distance3 (const NetGraphNode &a, const NetGraphNode &b1, const NetGraphNode &b2, const NetGraph &gb) { + bool needs_join = false; + + for (auto e = b1.begin (); e != b1.end () && ! needs_join; ++e) { + needs_join = (e->second.second == b1.net () || e->second.second == b2.net ()); + } + + for (auto e = b2.begin (); e != b2.end () && ! needs_join; ++e) { + needs_join = (e->second.second == b1.net () || e->second.second == b2.net ()); + } + + if (needs_join) { + return distance (a, gb.joined (b1, b2)); + } + auto i = a.begin (); auto j1 = b1.begin (); auto j2 = b2.begin (); @@ -1319,11 +1333,11 @@ static size_t distance3 (const NetGraphNode &a, const NetGraphNode &b1, const Ne continue; } - if (*i < *j) { + if (i->first < j->first) { ++fuzz; ++i; continue; - } else if (*j < *i) { + } else if (j->first < i->first) { ++fuzz; ++j; continue; @@ -1338,12 +1352,13 @@ static size_t distance3 (const NetGraphNode &a, const NetGraphNode &b1, const Ne } static void -analyze_nodes_for_close_matches (const std::multimap &nodes_by_edges1, const std::multimap &nodes_by_edges2, bool layout2ref, db::NetlistCompareLogger *logger) +analyze_nodes_for_close_matches (const std::multimap &nodes_by_edges1, const std::multimap &nodes_by_edges2, bool layout2ref, db::NetlistCompareLogger *logger, const db::NetGraph &g2) { size_t max_search = 100; - double max_fuzz_factor = 0.1; + double max_fuzz_factor = 0.25; size_t max_fuzz_count = 3; - size_t min_edges = 6; + size_t max_edges_split = 3; // by how many edges joining will reduce the edge count at max + size_t min_edges = 2; std::string msg; if (layout2ref) { @@ -1358,8 +1373,12 @@ analyze_nodes_for_close_matches (const std::multimap seen; + for (auto j = nodes_by_edges2.begin (); j != nodes_by_edges2.end (); ++j) { + seen.insert (j->second); + if (j->first > i->first + max_fuzz_count - 1) { break; } @@ -1388,14 +1407,14 @@ analyze_nodes_for_close_matches (const std::multimapfirst + k->first < i->first + max_fuzz_count && tries > 0) { + for ( ; k != nodes_by_edges2.end () && j->first + k->first < i->first + max_fuzz_count + max_edges_split && tries > 0; ++k) { - if (k == j) { + if (seen.find (k->second) != seen.end ()) { continue; } - size_t fuzz = distance3 (*i->second, *j->second, *k->second); - double fuzz_factor = double (fuzz) / ne; + size_t fuzz = distance3 (*i->second, *j->second, *k->second, g2); + double fuzz_factor = double (fuzz) / i->first; if (fuzz_factor < max_fuzz_factor) { logger->log_entry (db::NetlistCompareLogger::Info, tl::sprintf (msg, (layout2ref ? i : j)->second->net ()->expanded_name (), @@ -1405,7 +1424,6 @@ analyze_nodes_for_close_matches (const std::multimapend () - n->begin (), n)); } - analyze_nodes_for_close_matches (nodes_by_edges1, nodes_by_edges2, true, logger); - analyze_nodes_for_close_matches (nodes_by_edges2, nodes_by_edges1, false, logger); + analyze_nodes_for_close_matches (nodes_by_edges1, nodes_by_edges2, true, logger, *mp_other_graph); + analyze_nodes_for_close_matches (nodes_by_edges2, nodes_by_edges1, false, logger, *mp_graph); } size_t diff --git a/src/db/db/dbNetlistCompareGraph.cc b/src/db/db/dbNetlistCompareGraph.cc index 66e593c27..eb7001a1f 100644 --- a/src/db/db/dbNetlistCompareGraph.cc +++ b/src/db/db/dbNetlistCompareGraph.cc @@ -624,4 +624,48 @@ NetGraph::build (const db::Circuit *c, DeviceCategorizer &device_categorizer, Ci } } +NetGraphNode +NetGraph::joined (const NetGraphNode &a, const NetGraphNode &b) const +{ + NetGraphNode nj = a; + + nj.edges ().clear (); + nj.edges ().reserve ((a.end () - a.begin ()) + (b.end () - b.begin ())); + + std::map joined; + + for (int m = 0; m < 2; ++m) { + + const NetGraphNode &n = (m == 0 ? a : b); + + for (auto i = n.begin (); i != n.end (); ++i) { + + if (i->second.second) { + + const db::Net *net = i->second.second == b.net () ? a.net () : i->second.second; + + auto j = joined.find (net); + if (j != joined.end ()) { + j->second.first.insert (j->second.first.end (), i->first.begin (), i->first.end ()); + } else { + j = joined.insert (std::make_pair (net, *i)).first; + j->second.second.second = net; + } + + } else { + nj.edges ().push_back (*i); + } + + } + + } + + for (auto i = joined.begin (); i != joined.end (); ++i) { + nj.edges ().push_back (i->second); + } + + nj.apply_net_index (m_net_index); + return nj; +} + } diff --git a/src/db/db/dbNetlistCompareGraph.h b/src/db/db/dbNetlistCompareGraph.h index 115138997..7ee8a94c3 100644 --- a/src/db/db/dbNetlistCompareGraph.h +++ b/src/db/db/dbNetlistCompareGraph.h @@ -272,6 +272,11 @@ public: } } + std::vector &edges () + { + return m_edges; + } + private: const db::Net *mp_net; size_t m_other_net_index; @@ -414,6 +419,11 @@ public: return const_cast (((const NetGraph *) this)->virtual_node (sc)); } + /** + * @brief Creates a new node representing two joined nodes + */ + NetGraphNode joined (const NetGraphNode &a, const NetGraphNode &b) const; + /** * @brief Gets the net for a given node index */