Skip to content

Commit

Permalink
MIG depth rewriting without area increase. (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
msoeken committed Aug 2, 2018
1 parent 46c0f67 commit ab2647d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Expand Up @@ -16,7 +16,7 @@ v0.1 (not yet released)
- LUT mapping (`lut_mapping`) `#7 <https://github.com/lsils/mockturtle/pull/7>`_
- Akers synthesis (`akers_synthesis`) `#9 <https://github.com/lsils/mockturtle/pull/9>`_
- Create LUT network from mapped network (`collapse_mapped_network`) `#13 <https://github.com/lsils/mockturtle/pull/13>`_
- MIG algebraic depth rewriting (`mig_algebraic_depth_rewriting`) `#16 <https://github.com/lsils/mockturtle/pull/16>`_
- MIG algebraic depth rewriting (`mig_algebraic_depth_rewriting`) `#16 <https://github.com/lsils/mockturtle/pull/16>`_ `#58 <https://github.com/lsils/mockturtle/pull/58>`_
- Cleanup dangling nodes (`cleanup_dangling`) `#16 <https://github.com/lsils/mockturtle/pull/16>`_
- Node resynthesis (`node_resynthesis`) `#17 <https://github.com/lsils/mockturtle/pull/17>`_
- Reconvergency-driven cut computation (`reconv_cut`) `#24 <https://github.com/lsils/mockturtle/pull/24>`_
Expand Down
20 changes: 15 additions & 5 deletions include/mockturtle/algorithms/mig_algebraic_rewriting.hpp
Expand Up @@ -78,6 +78,9 @@ struct mig_algebraic_depth_rewriting_params
* number of dangling nodes are taken into account.
*/
float overhead{2.0f};

/*! \brief Allow area increase while optimizing depth. */
bool allow_area_increase{true};
};

namespace detail
Expand Down Expand Up @@ -192,6 +195,10 @@ class mig_algebraic_depth_rewriting_impl
if ( ntk.level( ntk.get_node( ocs[2] ) ) <= ntk.level( ntk.get_node( ocs[1] ) ) + 1 )
return false;

/* child must have single fanout, if no area overhead is allowed */
if ( !ps.allow_area_increase && ntk.fanout_size( ntk.get_node( ocs[2] ) ) != 1 )
return false;

/* get children of last child */
auto ocs2 = ordered_children( ntk.get_node( ocs[2] ) );

Expand All @@ -218,11 +225,14 @@ class mig_algebraic_depth_rewriting_impl
}

/* distributivity */
auto opt = ntk.create_maj( ocs2[2],
ntk.create_maj( ocs[0], ocs[1], ocs2[0] ),
ntk.create_maj( ocs[0], ocs[1], ocs2[1] ) );
ntk.substitute_node( n, opt );
ntk.update();
if ( ps.allow_area_increase )
{
auto opt = ntk.create_maj( ocs2[2],
ntk.create_maj( ocs[0], ocs[1], ocs2[0] ),
ntk.create_maj( ocs[0], ocs[1], ocs2[1] ) );
ntk.substitute_node( n, opt );
ntk.update();
}
return true;
}

Expand Down
33 changes: 33 additions & 0 deletions test/algorithms/quality.cpp
Expand Up @@ -9,6 +9,7 @@
#include <mockturtle/algorithms/cut_enumeration.hpp>
#include <mockturtle/algorithms/cut_rewriting.hpp>
#include <mockturtle/algorithms/lut_mapping.hpp>
#include <mockturtle/algorithms/mig_algebraic_rewriting.hpp>
#include <mockturtle/algorithms/node_resynthesis.hpp>
#include <mockturtle/algorithms/node_resynthesis/akers.hpp>
#include <mockturtle/algorithms/node_resynthesis/mig_npn.hpp>
Expand Down Expand Up @@ -163,4 +164,36 @@ TEST_CASE( "Test quality of MIG resubstitution", "[quality]" )
CHECK( v == std::vector<uint32_t>{{6, 208, 398, 317, 502, 333, 704, 1007, 1741, 2322, 1460}} );
}

TEST_CASE( "Test quality of MIG algebraic depth rewriting", "[quality]" )
{
const auto v = foreach_benchmark<mig_network>( []( auto& ntk, auto ) {
depth_view depth_ntk{ntk};
const auto before = depth_ntk.depth();
mig_algebraic_depth_rewriting( depth_ntk );
ntk = cleanup_dangling( ntk );
depth_ntk.update();
return before - depth_ntk.depth();
} );

CHECK( v == std::vector<uint32_t>{{0, 4, 1, 8, 2, 4, 3, 11, 6, 35, 7}} );
}

TEST_CASE( "Test quality of MIG algebraic depth rewriting without area increase", "[quality]" )
{
const auto v = foreach_benchmark<mig_network>( []( auto& ntk, auto ) {
depth_view depth_ntk{ntk};
const auto size_before = ntk.num_gates();
const auto before = depth_ntk.depth();
mig_algebraic_depth_rewriting_params ps;
ps.allow_area_increase = false;
mig_algebraic_depth_rewriting( depth_ntk, ps );
ntk = cleanup_dangling( ntk );
depth_ntk.update();
CHECK( ntk.num_gates() <= size_before );
return before - depth_ntk.depth();
} );

CHECK( v == std::vector<uint32_t>{{0, 1, 0, 5, 0, 0, 2, 6, 3, 0, 6}} );
}

#endif

0 comments on commit ab2647d

Please sign in to comment.