Skip to content

Commit

Permalink
XAG resubstitution for multiplicative complexity (#231)
Browse files Browse the repository at this point in the history
* XAG resubstitution (with don't cares)
  • Loading branch information
eletesta authored Feb 11, 2020
1 parent 3485fcd commit a1f0f90
Show file tree
Hide file tree
Showing 7 changed files with 1,217 additions and 170 deletions.
18 changes: 12 additions & 6 deletions include/mockturtle/algorithms/aig_resub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct aig_resub_stats
}
}; /* aig_resub_stats */

template<typename Ntk, typename Simulator>
template<typename Ntk, typename Simulator, typename TT>
struct aig_resub_functor
{
public:
Expand Down Expand Up @@ -180,8 +180,11 @@ struct aig_resub_functor
{
}

std::optional<signal> operator()( node const& root, uint32_t required, uint32_t max_inserts, uint32_t num_mffc, uint32_t& last_gain )
std::optional<signal> operator()( node const& root, TT care, uint32_t required, uint32_t max_inserts, uint32_t num_mffc, uint32_t& last_gain )
{

assert(is_const0(~care));

/* consider constants */
auto g = call_with_stopwatch( st.time_resubC, [&]() {
return resub_const( root, required );
Expand Down Expand Up @@ -745,10 +748,12 @@ void aig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubst
if ( ps.max_pis == 8 )
{
using truthtable_t = kitty::static_truth_table<8>;
using truthtable_dc_t = kitty::dynamic_truth_table;
using simulator_t = detail::simulator<resub_view_t, truthtable_t>;
using resubstitution_functor_t = aig_resub_functor<resub_view_t, simulator_t>;
using node_mffc_t = detail::node_mffc_inside<Ntk>;
using resubstitution_functor_t = aig_resub_functor<resub_view_t, simulator_t, truthtable_dc_t>;
typename resubstitution_functor_t::stats resub_st;
detail::resubstitution_impl<resub_view_t, simulator_t, resubstitution_functor_t> p( resub_view, ps, st, resub_st );
detail::resubstitution_impl<resub_view_t, simulator_t, resubstitution_functor_t, truthtable_dc_t, node_mffc_t> p( resub_view, ps, st, resub_st );
p.run();
if ( ps.verbose )
{
Expand All @@ -760,9 +765,10 @@ void aig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubst
{
using truthtable_t = kitty::dynamic_truth_table;
using simulator_t = detail::simulator<resub_view_t, truthtable_t>;
using resubstitution_functor_t = aig_resub_functor<resub_view_t, simulator_t>;
using node_mffc_t = detail::node_mffc_inside<Ntk>;
using resubstitution_functor_t = aig_resub_functor<resub_view_t, simulator_t, truthtable_t>;
typename resubstitution_functor_t::stats resub_st;
detail::resubstitution_impl<resub_view_t, simulator_t, resubstitution_functor_t> p( resub_view, ps, st, resub_st );
detail::resubstitution_impl<resub_view_t, simulator_t, resubstitution_functor_t, truthtable_t, node_mffc_t> p( resub_view, ps, st, resub_st );
p.run();
if ( ps.verbose )
{
Expand Down
4 changes: 2 additions & 2 deletions include/mockturtle/algorithms/dont_cares.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ namespace mockturtle
* \param max_tfi_inputs Maximum number of inputs in the transitive fanin.
*/
template<class Ntk>
kitty::dynamic_truth_table satisfiability_dont_cares( Ntk const& ntk, std::vector<node<Ntk>> const& leaves, uint32_t max_tfi_inputs = 10u )
kitty::dynamic_truth_table satisfiability_dont_cares( Ntk const& ntk, std::vector<node<Ntk>> const& leaves, uint32_t max_tfi_inputs = 16u )
{
auto extended_leaves = reconv_cut( reconv_cut_params{max_tfi_inputs} )( ntk, leaves );

fanout_view<Ntk> fanout_ntk{ntk};
fanout_ntk.clear_visited();

Expand Down
18 changes: 12 additions & 6 deletions include/mockturtle/algorithms/mig_resub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct mig_resub_stats
}
}; /* mig_resub_stats */

template<typename Ntk, typename Simulator>
template<typename Ntk, typename Simulator, typename TT>
struct mig_resub_functor
{
public:
Expand Down Expand Up @@ -179,8 +179,11 @@ struct mig_resub_functor
{
}

std::optional<signal> operator()( node const& root, uint32_t required, uint32_t max_inserts, uint32_t num_mffc, uint32_t& last_gain )
std::optional<signal> operator()( node const& root, TT care, uint32_t required, uint32_t max_inserts, uint32_t num_mffc, uint32_t& last_gain )
{

assert(is_const0(~care));

/* consider constants */
auto g = call_with_stopwatch( st.time_resubC, [&]() {
return resub_const( root, required );
Expand Down Expand Up @@ -670,10 +673,12 @@ void mig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubst
if ( ps.max_pis == 8 )
{
using truthtable_t = kitty::static_truth_table<8>;
using truthtable_dc_t = kitty::dynamic_truth_table;
using simulator_t = detail::simulator<resub_view_t, truthtable_t>;
using resubstitution_functor_t = mig_resub_functor<resub_view_t, simulator_t>;
using node_mffc_t = detail::node_mffc_inside<Ntk>;
using resubstitution_functor_t = mig_resub_functor<resub_view_t, simulator_t, truthtable_dc_t>;
typename resubstitution_functor_t::stats resub_st;
detail::resubstitution_impl<resub_view_t, simulator_t, resubstitution_functor_t> p( resub_view, ps, st, resub_st );
detail::resubstitution_impl<resub_view_t, simulator_t, resubstitution_functor_t, truthtable_dc_t, node_mffc_t> p( resub_view, ps, st, resub_st );
p.run();
if ( ps.verbose )
{
Expand All @@ -685,9 +690,10 @@ void mig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubst
{
using truthtable_t = kitty::dynamic_truth_table;
using simulator_t = detail::simulator<resub_view_t, truthtable_t>;
using resubstitution_functor_t = mig_resub_functor<resub_view_t, simulator_t>;
using node_mffc_t = detail::node_mffc_inside<Ntk>;
using resubstitution_functor_t = mig_resub_functor<resub_view_t, simulator_t, truthtable_t>;
typename resubstitution_functor_t::stats resub_st;
detail::resubstitution_impl<resub_view_t, simulator_t, resubstitution_functor_t> p( resub_view, ps, st, resub_st );
detail::resubstitution_impl<resub_view_t, simulator_t, resubstitution_functor_t, truthtable_t, node_mffc_t> p( resub_view, ps, st, resub_st );
p.run();
if ( ps.verbose )
{
Expand Down
5 changes: 3 additions & 2 deletions include/mockturtle/algorithms/refactoring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class refactoring_impl
}

std::vector<signal<Ntk>> leaves( mffc.num_pis() );
mffc.foreach_pi( [&]( auto const& n, auto j ) {
leaves[j] = ntk.make_signal( n );
mffc.foreach_pi( [&]( auto const& m, auto j ) {
leaves[j] = ntk.make_signal( m );
} );

default_simulator<kitty::dynamic_truth_table> sim( mffc.num_pis() );
Expand Down Expand Up @@ -210,6 +210,7 @@ class refactoring_impl

if ( gain > 0 || ( ps.allow_zero_gain && gain == 0 ) )
{

++_candidates;
_estimated_gain += gain;
ntk.substitute_node( n, new_f );
Expand Down
Loading

0 comments on commit a1f0f90

Please sign in to comment.