diff --git a/experiments/mig_resubstitution.cpp b/experiments/mig_resubstitution.cpp index 7e5f0039d..933853a4d 100644 --- a/experiments/mig_resubstitution.cpp +++ b/experiments/mig_resubstitution.cpp @@ -23,45 +23,47 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include - -#include -#include #include #include #include #include +#include +#include +#include #include +#include +#include int main() { using namespace experiments; using namespace mockturtle; - experiment exp( "mig_resubstitution", "benchmark", "size_before", "size_after", "runtime", "equivalent" ); + experiment + exp( "mig_resubstitution", "benchmark", "size_before", "size_after", "runtime", "equivalent" ); for ( auto const& benchmark : epfl_benchmarks() ) { fmt::print( "[i] processing {}\n", benchmark ); + mig_network mig; lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( mig ) ); resubstitution_params ps; resubstitution_stats st; - ps.max_pis = 8u; ps.max_inserts = 1u; ps.progress = false; - const uint32_t size_before = mig.num_gates(); - mig_resubstitution( mig, ps, &st ); + depth_view depth_mig{mig}; + fanout_view fanout_mig{depth_mig}; + uint32_t const size_before = fanout_mig.num_gates(); + mig_resubstitution( fanout_mig, ps, &st ); mig = cleanup_dangling( mig ); - const auto cec = benchmark == "hyp" ? true : abc_cec( mig, benchmark ); - + bool const cec = benchmark == "hyp" ? true : abc_cec( fanout_mig, benchmark ); exp( benchmark, size_before, mig.num_gates(), to_seconds( st.time_total ), cec ); } diff --git a/include/mockturtle/algorithms/mig_resub.hpp b/include/mockturtle/algorithms/mig_resub.hpp index 8962908d0..e6677abbc 100644 --- a/include/mockturtle/algorithms/mig_resub.hpp +++ b/include/mockturtle/algorithms/mig_resub.hpp @@ -25,7 +25,7 @@ /*! \file mig_resub.hpp - \brief Resubstitution + \brief Majority-specific resustitution rules \author Heinz Riener */ @@ -643,11 +643,47 @@ struct mig_resub_functor binate_divisors bdivs; }; /* mig_resub_functor */ +/*! \brief MIG-specific resubstitution algorithm. + * + * This algorithms iterates over each node, creates a + * reconvergence-driven cut, and attempts to re-express the node's + * function using existing nodes from the cut. Node which are no + * longer used (including nodes in their transitive fanins) can then + * be removed. The objective is to reduce the size of the network as + * much as possible while maintaing the global input-output + * functionality. + * + * **Required network functions:** + * + * - `clear_values` + * - `fanout_size` + * - `foreach_fanin` + * - `foreach_fanout` + * - `foreach_gate` + * - `foreach_node` + * - `get_constant` + * - `get_node` + * - `is_complemented` + * - `is_pi` + * - `level` + * - `make_signal` + * - `set_value` + * - `set_visited` + * - `size` + * - `substitute_node` + * - `value` + * - `visited` + * + * \param ntk A network type derived from mig_network + * \param ps Resubstitution parameters + * \param pst Resubstitution statistics + */ template void mig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubstitution_stats* pst = nullptr ) { - /* TODO: check if basetype of ntk is aig */ static_assert( is_network_type_v, "Ntk is not a network type" ); + static_assert( std::is_same_v, "Network type is not mig_network" ); + static_assert( has_clear_values_v, "Ntk does not implement the clear_values method" ); static_assert( has_fanout_size_v, "Ntk does not implement the fanout_size method" ); static_assert( has_foreach_fanin_v, "Ntk does not implement the foreach_fanin method" ); @@ -664,22 +700,20 @@ void mig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubst static_assert( has_substitute_node_v, "Ntk does not implement the has substitute_node method" ); static_assert( has_value_v, "Ntk does not implement the has_value method" ); static_assert( has_visited_v, "Ntk does not implement the has_visited method" ); - - using resub_view_t = fanout_view>; - depth_view depth_view{ntk}; - resub_view_t resub_view{depth_view}; + static_assert( has_level_v, "Ntk does not implement the level method" ); + static_assert( has_foreach_fanout_v, "Ntk does not implement the foreach_fanout method" ); if ( ps.max_pis == 8 ) { using truthtable_t = kitty::static_truth_table<8u>; using truthtable_dc_t = kitty::dynamic_truth_table; - using resub_impl_t = detail::resubstitution_impl, truthtable_dc_t>>>; + using resub_impl_t = detail::resubstitution_impl, truthtable_dc_t>>>; resubstitution_stats st; typename resub_impl_t::engine_st_t engine_st; typename resub_impl_t::collector_st_t collector_st; - resub_impl_t p( resub_view, ps, st, engine_st, collector_st ); + resub_impl_t p( ntk, ps, st, engine_st, collector_st ); p.run(); if ( ps.verbose ) @@ -698,13 +732,13 @@ void mig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubst { using truthtable_t = kitty::dynamic_truth_table; using truthtable_dc_t = kitty::dynamic_truth_table; - using resub_impl_t = detail::resubstitution_impl, truthtable_dc_t>>>; + using resub_impl_t = detail::resubstitution_impl, truthtable_dc_t>>>; resubstitution_stats st; typename resub_impl_t::engine_st_t engine_st; typename resub_impl_t::collector_st_t collector_st; - resub_impl_t p( resub_view, ps, st, engine_st, collector_st ); + resub_impl_t p( ntk, ps, st, engine_st, collector_st ); p.run(); if ( ps.verbose ) diff --git a/include/mockturtle/algorithms/resubstitution.hpp b/include/mockturtle/algorithms/resubstitution.hpp index d8fac0e64..41a38cd30 100644 --- a/include/mockturtle/algorithms/resubstitution.hpp +++ b/include/mockturtle/algorithms/resubstitution.hpp @@ -25,8 +25,7 @@ /*! \file resubstitution.hpp - \brief Generalized resubstitution framework - + \brief Generic resubstitution framework \author Heinz Riener \author Siang-Yun Lee