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_paramsholds configurable parameters with default arguments forrefactoring.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.
-
uint32_t max_pis = {6}
-
struct refactoring_stats
Statistics for refactoring.
The data structure
refactoring_statsprovides data collected by runningrefactoring.Public Members
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_danglingalgorithm.The refactoring function must be of type
NtkDest::signal(NtkDest&, kitty::dynamic_truth_table const&, LeavesIterator, LeavesIterator)whereLeavesIteratorcan be dereferenced to aNtkDest::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 foldermockturtle/algorithms/node_resyntesis, since the resynthesis functions have the same signature.Required network functions:
get_nodesizemake_signalforeach_gatesubstitute_nodeclear_visitedclear_valuesfanout_sizeset_valueforeach_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.