From fbea60028b69963366264f16216da4a071fde5a5 Mon Sep 17 00:00:00 2001 From: Heinz Riener Date: Mon, 30 Nov 2020 22:23:40 +0100 Subject: [PATCH 1/2] special case of substitute (with restrashing). --- test/networks/aig.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/networks/aig.cpp b/test/networks/aig.cpp index e73e892d4..028eb2486 100644 --- a/test/networks/aig.cpp +++ b/test/networks/aig.cpp @@ -811,3 +811,36 @@ TEST_CASE( "invoke take_out_node two times on the same node", "[aig]" ) CHECK( aig.fanout_size( aig.get_node( x1 ) ) == 1u ); CHECK( aig.fanout_size( aig.get_node( x2 ) ) == 1u ); } + +TEST_CASE( "substitute node and restrash", "[aig]" ) +{ + aig_network aig; + auto const x1 = aig.create_pi(); + auto const x2 = aig.create_pi(); + + auto const f1 = aig.create_and( x1, x2 ); + auto const f2 = aig.create_and( f1, x2 ); + aig.create_po( f2 ); + + CHECK( aig.fanout_size( aig.get_node( x1 ) ) == 1 ); + CHECK( aig.fanout_size( aig.get_node( x2 ) ) == 2 ); + CHECK( aig.fanout_size( aig.get_node( f1 ) ) == 1 ); + CHECK( aig.fanout_size( aig.get_node( f2 ) ) == 1 ); + + CHECK( simulate>( aig )[0]._bits == 0x8 ); + + /* substitute f1 with x1 + * + * this is a very interesting test case because replacing f1 with x1 + * in f2 makes f2 and f1 equal. a correct implementation will + * create a new entry in the hash, although (x1, x2) is already + * there, because (x1, x2) will be deleted in the next step. + */ + aig.substitute_node( aig.get_node( f1 ), x1 ); + CHECK( simulate>( aig )[0]._bits == 0x8 ); + + CHECK( aig.fanout_size( aig.get_node( x1 ) ) == 1 ); + CHECK( aig.fanout_size( aig.get_node( x2 ) ) == 1 ); + CHECK( aig.fanout_size( aig.get_node( f1 ) ) == 0 ); + CHECK( aig.fanout_size( aig.get_node( f2 ) ) == 1 ); +} From a14ea6dafa82d4913b6ebc651a4a8de43cee08b0 Mon Sep 17 00:00:00 2001 From: Heinz Riener Date: Mon, 30 Nov 2020 22:39:30 +0100 Subject: [PATCH 2/2] bugfix: avoid recreating the old_node that will be deleted by substitute_node. --- include/mockturtle/networks/aig.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mockturtle/networks/aig.hpp b/include/mockturtle/networks/aig.hpp index cdc2449a3..c35f10126 100644 --- a/include/mockturtle/networks/aig.hpp +++ b/include/mockturtle/networks/aig.hpp @@ -481,7 +481,7 @@ class aig_network storage::element_type::node_type _hash_obj; _hash_obj.children[0] = child0; _hash_obj.children[1] = child1; - if ( const auto it = _storage->hash.find( _hash_obj ); it != _storage->hash.end() ) + if ( const auto it = _storage->hash.find( _hash_obj ); it != _storage->hash.end() && it->second != old_node ) { return std::make_pair( n, signal( it->second, 0 ) ); }