Refactoring

Header: mockturtle/algorithms/refactoring.hpp

The following example shows how to refactor an MIG using the Akers synthesis method.

/* derive some MIG */
mig_network mig = ...;

/* node resynthesis */
akers_resynthesis resyn;
refactoring( mig, resyn );
mig = cleanup_dangling( mig );

It is possible to change the cost function of nodes in refactoring. Here is an example, in which the cost function does not account for XOR gates in a network. This may be helpful in logic synthesis addressing cryptography applications where XOR gates are considered “for free”.

template<class Ntk>
struct free_xor_cost
{
  uint32_t operator()( Ntk const& ntk, node<Ntk> const& n ) const
  {
    return ntk.is_xor( n ) ? 0 : 1;
  }
};

SomeResynthesisClass resyn;
refactoring( ntk, resyn, free_xor_cost<Ntk>());

Parameters and statistics

struct refactoring_params

Parameters for refactoring.

The data structure refactoring_params holds configurable parameters with default arguments for refactoring.

Public Members

uint32_t max_pis = {6}

Maximum number of PIs of the MFFC or window.

bool allow_zero_gain = {false}

Allow zero-gain substitutions.

bool use_reconvergence_cut = {true}

Extract a reconvergence-driven cut for large MFFcs.

bool use_dont_cares = {false}

Use don’t cares for optimization.

bool progress = {false}

Show progress.

bool verbose = {false}

Be verbose.

struct refactoring_stats

Statistics for refactoring.

The data structure refactoring_stats provides data collected by running refactoring.

Public Members

stopwatch::duration time_total = {0}

Total runtime.

stopwatch::duration time_mffc = {0}

Accumulated runtime for computing MFFCs.

stopwatch::duration time_refactoring = {0}

Accumulated runtime for rewriting.

stopwatch::duration time_simulation = {0}

Accumulated runtime for simulating MFFCs.

Algorithm

template<class Ntk, class RefactoringFn, class NodeCostFn = unit_cost<Ntk>>
void mockturtle::refactoring(Ntk &ntk, RefactoringFn &&refactoring_fn, refactoring_params const &ps = {}, refactoring_stats *pst = nullptr, NodeCostFn const &cost_fn = {})

Boolean refactoring.

This algorithm performs refactoring by collapsing maximal fanout-free cones (MFFCs) into truth tables and recreating a new network structure from it. If the MFFC is too large a reconvergence-driven cut is extracted. The algorithm performs changes directly in the input network and keeps the substituted structures dangling in the network. They can be cleaned up using the cleanup_dangling algorithm.

The refactoring function must be of type NtkDest::signal(NtkDest&, kitty::dynamic_truth_table const&, LeavesIterator, LeavesIterator) where LeavesIterator can be dereferenced to a NtkDest::signal. The last two parameters compose an iterator pair where the distance matches the number of variables of the truth table that is passed as second parameter. There are some refactoring algorithms in the folder mockturtle/algorithms/node_resyntesis, since the resynthesis functions have the same signature.

Required network functions:

  • get_node

  • size

  • make_signal

  • foreach_gate

  • substitute_node

  • clear_visited

  • clear_values

  • fanout_size

  • set_value

  • foreach_node

Parameters:
  • ntk – Input network (will be changed in-place)

  • refactoring_fn – Refactoring function

  • ps – Refactoring params

  • pst – Refactoring statistics

  • cost_fn – Node cost function (a functor with signature uint32_t(Ntk const&, node<Ntk> const&))

Rewriting functions

One can use resynthesis functions that can be passed to node_resynthesis, see Resynthesis functions.