forked from EPFL-CS-472/mockturtle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sort fanouts of PIs * tests for fanout_limit_view * duplicate popular PIs in fanout_limit_view * Revert "duplicate popular PIs in fanout_limit_view" This reverts commit b80008a.
- Loading branch information
1 parent
85ebf3e
commit e9da8ee
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#include <catch.hpp> | ||
|
||
#include <mockturtle/traits.hpp> | ||
#include <mockturtle/networks/mig.hpp> | ||
#include <mockturtle/views/fanout_limit_view.hpp> | ||
|
||
using namespace mockturtle; | ||
|
||
TEST_CASE( "test node replication", "[fanout_limit_view]" ) | ||
{ | ||
using node = mig_network::node; | ||
using signal = mig_network::signal; | ||
|
||
fanout_limit_view_params ps{4u}; | ||
fanout_limit_view<mig_network> lim_mig{ps}; | ||
|
||
signal const a = lim_mig.create_pi(); | ||
signal const b = lim_mig.create_pi(); | ||
signal const c = lim_mig.create_pi(); | ||
|
||
/* create a node */ | ||
signal const f1 = lim_mig.create_maj( a, b, c ); | ||
|
||
/* make f1 very popular */ | ||
lim_mig.create_and( f1, a ); | ||
lim_mig.create_and( f1, b ); | ||
lim_mig.create_and( f1, c ); | ||
lim_mig.create_or( f1, a ); | ||
|
||
CHECK( lim_mig.num_gates() == 5u ); | ||
|
||
lim_mig.create_or( f1, b ); | ||
lim_mig.create_or( f1, c ); | ||
|
||
CHECK( lim_mig.num_gates() == 8u ); | ||
lim_mig.foreach_gate( [&]( node const& n ){ | ||
CHECK( lim_mig.fanout_size( n ) <= 4u ); | ||
}); | ||
} | ||
|
||
TEST_CASE( "test rippled replication", "[fanout_limit_view]" ) | ||
{ | ||
using node = mig_network::node; | ||
using signal = mig_network::signal; | ||
|
||
fanout_limit_view_params ps{4u}; | ||
fanout_limit_view<mig_network> lim_mig{ps}; | ||
|
||
signal const a = lim_mig.create_pi(); | ||
signal const b = lim_mig.create_pi(); | ||
signal const c = lim_mig.create_pi(); | ||
signal const d = lim_mig.create_pi(); | ||
signal const e = lim_mig.create_pi(); | ||
|
||
/* create two nodes */ | ||
signal const f1 = lim_mig.create_maj( a, b, c ); | ||
signal const f2 = lim_mig.create_maj( d, f1, e ); | ||
|
||
/* make f1 and f2 popular */ | ||
lim_mig.create_and( f1, a ); | ||
lim_mig.create_and( f1, b ); | ||
lim_mig.create_and( f1, c ); | ||
|
||
lim_mig.create_and( f2, a ); | ||
lim_mig.create_and( f2, b ); | ||
lim_mig.create_and( f2, c ); | ||
lim_mig.create_or( f2, a ); | ||
|
||
CHECK( lim_mig.num_gates() == 9u ); | ||
lim_mig.foreach_gate( [&]( node const& n ){ | ||
CHECK( lim_mig.fanout_size( n ) <= 4u ); | ||
}); | ||
|
||
/* +3 majority gates, because first f2 has to be replicated, and then also f1 */ | ||
lim_mig.create_or( f2, b ); | ||
|
||
CHECK( lim_mig.num_gates() == 12u ); | ||
lim_mig.foreach_gate( [&]( node const& n ){ | ||
CHECK( lim_mig.fanout_size( n ) <= 4u ); | ||
}); | ||
|
||
CHECK( lim_mig.fanout_size( lim_mig.get_node( f1 ) ) == 4u ); | ||
CHECK( lim_mig.fanout_size( lim_mig.get_node( f2 ) ) == 4u ); | ||
} | ||
|
||
TEST_CASE( "test duplicate fanout node", "[fanout_limit_view]" ) | ||
{ | ||
using node = mig_network::node; | ||
using signal = mig_network::signal; | ||
|
||
fanout_limit_view_params ps{4u}; | ||
fanout_limit_view<mig_network> lim_mig{ps}; | ||
|
||
signal const a = lim_mig.create_pi(); | ||
signal const b = lim_mig.create_pi(); | ||
signal const c = lim_mig.create_pi(); | ||
|
||
signal const f = lim_mig.create_maj( a, b, c ); | ||
|
||
/* only one node is needed for fanout up to 4 */ | ||
lim_mig.create_po( f ); | ||
lim_mig.create_po( f ); | ||
lim_mig.create_po( f ); | ||
lim_mig.create_po( f ); | ||
|
||
CHECK( lim_mig.num_gates() == 1u ); | ||
CHECK( lim_mig.fanout_size( lim_mig.get_node( f ) ) == 4u ); | ||
|
||
/* afterward the node need to be replicated */ | ||
lim_mig.create_po( f ); | ||
lim_mig.create_po( f ); | ||
lim_mig.create_po( f ); | ||
lim_mig.create_po( f ); | ||
|
||
CHECK( lim_mig.num_gates() == 2u ); | ||
|
||
lim_mig.foreach_gate( [&]( node const& n ){ | ||
CHECK( lim_mig.fanout_size( n ) <= 4u ); | ||
}); | ||
} |