From f34d161e2f0e87b9963bfa87b896a7cec2210d02 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 9 Apr 2019 23:13:40 +0200 Subject: [PATCH] WIP: new backtracking algorithm for net matching. --- src/db/db/dbNetlistCompare.cc | 14 ++++++--- src/db/unit_tests/dbNetlistCompareTests.cc | 36 +++++++++++----------- testdata/ruby/dbNetlistCompare.rb | 28 ++++++++--------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/db/db/dbNetlistCompare.cc b/src/db/db/dbNetlistCompare.cc index 2797e1ffc..1aa331426 100644 --- a/src/db/db/dbNetlistCompare.cc +++ b/src/db/db/dbNetlistCompare.cc @@ -973,14 +973,14 @@ public: other.identify (other_ni, ni); #if defined(PRINT_DEBUG_NETCOMPARE) - tl::info << "deduced match: " << nodes_with_same_path.front ()->net ()->expanded_name () << " vs. " << other_nodes_with_same_path.front ()->net ()->expanded_name (); + tl::info << "deduced match (singular): " << nodes_with_same_path.front ()->net ()->expanded_name () << " vs. " << other_nodes_with_same_path.front ()->net ()->expanded_name (); #endif if (logger) { logger->match_nets (nodes_with_same_path.front ()->net (), other_nodes_with_same_path.front ()->net ()); } // unconditionally continue here. - // @@@ derive_node_identities (ni, other, depth + 1, n_branch, logger, false); + derive_node_identities (ni, other, depth + 1, n_branch, logger, false); } @@ -1064,6 +1064,12 @@ public: for (std::vector >::const_iterator p = pairs.begin (); p != pairs.end (); ++p) { + if (p->first->has_other () || p->second->has_other ()) { + // this may happen if "derive_node_identities" creates new pairs + // TODO: actually *both* should be paired, not just one. + continue; + } + size_t ni = node_index_for_net (p->first->net ()); size_t other_ni = other.node_index_for_net (p->second->net ()); @@ -1419,11 +1425,9 @@ NetlistComparer::compare_circuits (const db::Circuit *c1, const db::Circuit *c2, tl::info << "deducing from present nodes ..."; #endif - size_t new_identities = 0; for (db::NetDeviceGraph::node_iterator i1 = g1.begin (); i1 != g1.end (); ++i1) { if (i1->has_other () && i1->net ()) { size_t ni = g1.derive_node_identities (i1 - g1.begin (), g2, mp_logger); - new_identities += ni; if (ni > 0 && ni != std::numeric_limits::max ()) { #if defined(PRINT_DEBUG_NETCOMPARE) tl::info << ni << " new identities."; @@ -1441,7 +1445,7 @@ NetlistComparer::compare_circuits (const db::Circuit *c1, const db::Circuit *c2, break; } - new_identities = 0; + size_t new_identities = 0; #if defined(PRINT_DEBUG_NETCOMPARE) tl::info << "checking topological identity ..."; diff --git a/src/db/unit_tests/dbNetlistCompareTests.cc b/src/db/unit_tests/dbNetlistCompareTests.cc index fb250d97d..4cb7c998d 100644 --- a/src/db/unit_tests/dbNetlistCompareTests.cc +++ b/src/db/unit_tests/dbNetlistCompareTests.cc @@ -595,8 +595,8 @@ TEST(4_BufferTwoPaths) "match_nets VDD VDD\n" "match_nets IN IN\n" "match_nets VSS VSS\n" - "match_ambiguous_nets INT $10\n" - "match_ambiguous_nets INT2 $11\n" + "match_nets INT $10\n" + "match_nets INT2 $11\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -658,9 +658,9 @@ TEST(5_BufferTwoPathsDifferentParameters) EXPECT_EQ (logger.text (), "begin_circuit BUF BUF\n" "match_nets OUT OUT\n" - "match_nets IN IN\n" "match_ambiguous_nets INT $10\n" "match_nets INT2 $11\n" + "match_nets IN IN\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -685,8 +685,8 @@ TEST(5_BufferTwoPathsDifferentParameters) "begin_circuit BUF BUF\n" "match_nets OUT OUT\n" "match_nets IN IN\n" - "match_ambiguous_nets INT $10\n" - "match_ambiguous_nets INT2 $11\n" + "match_nets INT2 $11\n" + "match_nets INT $10\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -710,9 +710,9 @@ TEST(5_BufferTwoPathsDifferentParameters) EXPECT_EQ (logger.text (), "begin_circuit BUF BUF\n" "match_nets OUT OUT\n" - "match_nets IN IN\n" "match_ambiguous_nets INT $10\n" "match_nets INT2 $11\n" + "match_nets IN IN\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -736,9 +736,9 @@ TEST(5_BufferTwoPathsDifferentParameters) EXPECT_EQ (logger.text (), "begin_circuit BUF BUF\n" "match_nets OUT OUT\n" - "match_nets IN IN\n" "match_ambiguous_nets INT $10\n" "match_nets INT2 $11\n" + "match_nets IN IN\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -763,8 +763,8 @@ TEST(5_BufferTwoPathsDifferentParameters) "begin_circuit BUF BUF\n" "match_nets OUT OUT\n" "match_nets IN IN\n" - "match_ambiguous_nets INT $10\n" - "match_ambiguous_nets INT2 $11\n" + "match_nets INT2 $11\n" + "match_nets INT $10\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -790,8 +790,8 @@ TEST(5_BufferTwoPathsDifferentParameters) "begin_circuit BUF BUF\n" "match_nets OUT OUT\n" "match_nets IN IN\n" - "match_ambiguous_nets INT $10\n" - "match_ambiguous_nets INT2 $11\n" + "match_nets INT2 $11\n" + "match_nets INT $10\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -816,9 +816,9 @@ TEST(5_BufferTwoPathsDifferentParameters) EXPECT_EQ (logger.text (), "begin_circuit BUF BUF\n" "match_nets OUT OUT\n" - "match_nets IN IN\n" "match_ambiguous_nets INT $10\n" "match_nets INT2 $11\n" + "match_nets IN IN\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -879,10 +879,10 @@ TEST(5_BufferTwoPathsDifferentDeviceClasses) EXPECT_EQ (logger.text (), "begin_circuit BUF BUF\n" - "match_nets IN IN\n" "match_nets INT $10\n" - "match_nets OUT OUT\n" + "match_nets IN IN\n" "match_nets INT2 $11\n" + "match_nets OUT OUT\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -945,9 +945,9 @@ TEST(6_BufferTwoPathsAdditionalResistor) EXPECT_EQ (logger.text (), "begin_circuit BUF BUF\n" "match_nets INT $10\n" - "match_nets OUT OUT\n" - "match_nets INT2 $11\n" "match_nets IN IN\n" + "match_nets INT2 $11\n" + "match_nets OUT OUT\n" "match_pins $0 $1\n" "match_pins $1 $3\n" "match_pins $2 $0\n" @@ -2025,12 +2025,12 @@ TEST(16_UniqueSubCircuitMatching) "match_nets BULK,VSS BULK,VSS\n" "match_nets $I22 $I22\n" "match_nets $I13 $I13\n" - "match_nets $I7 $I7\n" "match_nets $I23 $I23\n" "match_nets $I5 $I5\n" - "match_nets $I25 $I25\n" "match_nets $I24 $I24\n" "match_nets $I6 $I6\n" + "match_nets $I25 $I25\n" + "match_nets $I7 $I7\n" "match_subcircuits $1 $1\n" "match_subcircuits $4 $2\n" "match_subcircuits $3 $3\n" diff --git a/testdata/ruby/dbNetlistCompare.rb b/testdata/ruby/dbNetlistCompare.rb index 8f8e254c9..15a2f2f72 100644 --- a/testdata/ruby/dbNetlistCompare.rb +++ b/testdata/ruby/dbNetlistCompare.rb @@ -392,8 +392,8 @@ match_nets OUT OUT match_nets VDD VDD match_nets IN IN match_nets VSS VSS -match_ambiguous_nets INT $10 -match_ambiguous_nets INT2 $11 +match_nets INT $10 +match_nets INT2 $11 match_pins $0 $1 match_pins $1 $3 match_pins $2 $0 @@ -460,9 +460,9 @@ END assert_equal(logger.text, <<"END") begin_circuit BUF BUF match_nets OUT OUT -match_nets IN IN match_ambiguous_nets INT $10 match_nets INT2 $11 +match_nets IN IN match_pins $0 $1 match_pins $1 $3 match_pins $2 $0 @@ -489,8 +489,8 @@ END begin_circuit BUF BUF match_nets OUT OUT match_nets IN IN -match_ambiguous_nets INT $10 -match_ambiguous_nets INT2 $11 +match_nets INT2 $11 +match_nets INT $10 match_pins $0 $1 match_pins $1 $3 match_pins $2 $0 @@ -518,8 +518,8 @@ END begin_circuit BUF BUF match_nets OUT OUT match_nets IN IN -match_ambiguous_nets INT $10 -match_ambiguous_nets INT2 $11 +match_nets INT2 $11 +match_nets INT $10 match_pins $0 $1 match_pins $1 $3 match_pins $2 $0 @@ -547,8 +547,8 @@ END begin_circuit BUF BUF match_nets OUT OUT match_nets IN IN -match_ambiguous_nets INT $10 -match_ambiguous_nets INT2 $11 +match_nets INT2 $11 +match_nets INT $10 match_pins $0 $1 match_pins $1 $3 match_pins $2 $0 @@ -614,10 +614,10 @@ END assert_equal(logger.text, <<"END") begin_circuit BUF BUF -match_nets IN IN match_nets INT $10 -match_nets OUT OUT +match_nets IN IN match_nets INT2 $11 +match_nets OUT OUT match_pins $0 $1 match_pins $1 $3 match_pins $2 $0 @@ -685,9 +685,9 @@ END assert_equal(logger.text, <<"END") begin_circuit BUF BUF match_nets INT $10 -match_nets OUT OUT -match_nets INT2 $11 match_nets IN IN +match_nets INT2 $11 +match_nets OUT OUT match_pins $0 $1 match_pins $1 $3 match_pins $2 $0 @@ -887,8 +887,8 @@ match_nets OUT OUT match_nets IN2 IN2 match_nets VSS VSS match_nets VDD VDD -match_nets INT INT match_nets IN1 IN1 +match_nets INT INT match_pins $0 $0 match_pins $1 $1 match_pins $2 $2