mirror of https://github.com/YosysHQ/abc.git
Changing 'refactor' to work with truth tables.
This commit is contained in:
parent
24f2a120f2
commit
41d18ca051
|
|
@ -5919,7 +5919,7 @@ int Abc_CommandRefactor( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||||
fUseDcs = 0;
|
fUseDcs = 0;
|
||||||
fVerbose = 0;
|
fVerbose = 0;
|
||||||
Extra_UtilGetoptReset();
|
Extra_UtilGetoptReset();
|
||||||
while ( ( c = Extra_UtilGetopt( argc, argv, "NClzdvh" ) ) != EOF )
|
while ( ( c = Extra_UtilGetopt( argc, argv, "Nlzvh" ) ) != EOF )
|
||||||
{
|
{
|
||||||
switch ( c )
|
switch ( c )
|
||||||
{
|
{
|
||||||
|
|
@ -5979,6 +5979,11 @@ int Abc_CommandRefactor( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||||
Abc_Print( -1, "AIG resynthesis cannot be applied to AIGs with choice nodes.\n" );
|
Abc_Print( -1, "AIG resynthesis cannot be applied to AIGs with choice nodes.\n" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if ( nNodeSizeMax > 15 )
|
||||||
|
{
|
||||||
|
Abc_Print( -1, "The cone size cannot exceed 15.\n" );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ( fUseDcs && nNodeSizeMax >= nConeSizeMax )
|
if ( fUseDcs && nNodeSizeMax >= nConeSizeMax )
|
||||||
{
|
{
|
||||||
|
|
@ -5995,13 +6000,13 @@ int Abc_CommandRefactor( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
Abc_Print( -2, "usage: refactor [-NC <num>] [-lzdvh]\n" );
|
Abc_Print( -2, "usage: refactor [-N <num>] [-lzvh]\n" );
|
||||||
Abc_Print( -2, "\t performs technology-independent refactoring of the AIG\n" );
|
Abc_Print( -2, "\t performs technology-independent refactoring of the AIG\n" );
|
||||||
Abc_Print( -2, "\t-N <num> : the max support of the collapsed node [default = %d]\n", nNodeSizeMax );
|
Abc_Print( -2, "\t-N <num> : the max support of the collapsed node [default = %d]\n", nNodeSizeMax );
|
||||||
Abc_Print( -2, "\t-C <num> : the max support of the containing cone [default = %d]\n", nConeSizeMax );
|
// Abc_Print( -2, "\t-C <num> : the max support of the containing cone [default = %d]\n", nConeSizeMax );
|
||||||
Abc_Print( -2, "\t-l : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
|
Abc_Print( -2, "\t-l : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
|
||||||
Abc_Print( -2, "\t-z : toggle using zero-cost replacements [default = %s]\n", fUseZeros? "yes": "no" );
|
Abc_Print( -2, "\t-z : toggle using zero-cost replacements [default = %s]\n", fUseZeros? "yes": "no" );
|
||||||
Abc_Print( -2, "\t-d : toggle using don't-cares [default = %s]\n", fUseDcs? "yes": "no" );
|
// Abc_Print( -2, "\t-d : toggle using don't-cares [default = %s]\n", fUseDcs? "yes": "no" );
|
||||||
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
|
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
|
||||||
Abc_Print( -2, "\t-h : print the command usage\n");
|
Abc_Print( -2, "\t-h : print the command usage\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,7 @@
|
||||||
|
|
||||||
#include "base/abc/abc.h"
|
#include "base/abc/abc.h"
|
||||||
#include "bool/dec/dec.h"
|
#include "bool/dec/dec.h"
|
||||||
|
#include "bool/kit/kit.h"
|
||||||
#ifdef ABC_USE_CUDD
|
|
||||||
#include "bdd/extrab/extraBdd.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ABC_NAMESPACE_IMPL_START
|
ABC_NAMESPACE_IMPL_START
|
||||||
|
|
||||||
|
|
@ -32,8 +29,6 @@ ABC_NAMESPACE_IMPL_START
|
||||||
/// DECLARATIONS ///
|
/// DECLARATIONS ///
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef ABC_USE_CUDD
|
|
||||||
|
|
||||||
typedef struct Abc_ManRef_t_ Abc_ManRef_t;
|
typedef struct Abc_ManRef_t_ Abc_ManRef_t;
|
||||||
struct Abc_ManRef_t_
|
struct Abc_ManRef_t_
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +37,9 @@ struct Abc_ManRef_t_
|
||||||
int nConeSizeMax; // the limit on the size of the containing cone
|
int nConeSizeMax; // the limit on the size of the containing cone
|
||||||
int fVerbose; // the verbosity flag
|
int fVerbose; // the verbosity flag
|
||||||
// internal data structures
|
// internal data structures
|
||||||
DdManager * dd; // the BDD manager
|
Vec_Ptr_t * vVars; // truth tables
|
||||||
|
Vec_Ptr_t * vFuncs; // functions
|
||||||
|
Vec_Int_t * vMemory; // memory
|
||||||
Vec_Str_t * vCube; // temporary
|
Vec_Str_t * vCube; // temporary
|
||||||
Vec_Int_t * vForm; // temporary
|
Vec_Int_t * vForm; // temporary
|
||||||
Vec_Ptr_t * vVisited; // temporary
|
Vec_Ptr_t * vVisited; // temporary
|
||||||
|
|
@ -56,7 +53,7 @@ struct Abc_ManRef_t_
|
||||||
int nNodesEnd;
|
int nNodesEnd;
|
||||||
// runtime statistics
|
// runtime statistics
|
||||||
abctime timeCut;
|
abctime timeCut;
|
||||||
abctime timeBdd;
|
abctime timeTru;
|
||||||
abctime timeDcs;
|
abctime timeDcs;
|
||||||
abctime timeSop;
|
abctime timeSop;
|
||||||
abctime timeFact;
|
abctime timeFact;
|
||||||
|
|
@ -65,16 +62,249 @@ struct Abc_ManRef_t_
|
||||||
abctime timeNtk;
|
abctime timeNtk;
|
||||||
abctime timeTotal;
|
abctime timeTotal;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void Abc_NtkManRefPrintStats( Abc_ManRef_t * p );
|
|
||||||
static Abc_ManRef_t * Abc_NtkManRefStart( int nNodeSizeMax, int nConeSizeMax, int fUseDcs, int fVerbose );
|
|
||||||
static void Abc_NtkManRefStop( Abc_ManRef_t * p );
|
|
||||||
static Dec_Graph_t * Abc_NodeRefactor( Abc_ManRef_t * p, Abc_Obj_t * pNode, Vec_Ptr_t * vFanins, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose );
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
/// FUNCTION DEFINITIONS ///
|
/// FUNCTION DEFINITIONS ///
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**Function*************************************************************
|
||||||
|
|
||||||
|
Synopsis [Returns function of the cone.]
|
||||||
|
|
||||||
|
Description []
|
||||||
|
|
||||||
|
SideEffects []
|
||||||
|
|
||||||
|
SeeAlso []
|
||||||
|
|
||||||
|
***********************************************************************/
|
||||||
|
word * Abc_NodeConeTruth( Vec_Ptr_t * vVars, Vec_Ptr_t * vFuncs, int nWordsMax, Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vVisited )
|
||||||
|
{
|
||||||
|
Abc_Obj_t * pNode;
|
||||||
|
word * pTruth0, * pTruth1, * pTruth = NULL;
|
||||||
|
int i, k, nWords = Abc_Truth6WordNum( Vec_PtrSize(vLeaves) );
|
||||||
|
// get nodes in the cut without fanins in the DFS order
|
||||||
|
Abc_NodeConeCollect( &pRoot, 1, vLeaves, vVisited, 0 );
|
||||||
|
// set elementary functions
|
||||||
|
Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pNode, i )
|
||||||
|
pNode->pCopy = (Abc_Obj_t *)Vec_PtrEntry( vVars, i );
|
||||||
|
// prepare functions
|
||||||
|
for ( i = Vec_PtrSize(vFuncs); i < Vec_PtrSize(vVisited); i++ )
|
||||||
|
Vec_PtrPush( vFuncs, ABC_ALLOC(word, nWordsMax) );
|
||||||
|
// compute functions for the collected nodes
|
||||||
|
Vec_PtrForEachEntry( Abc_Obj_t *, vVisited, pNode, i )
|
||||||
|
{
|
||||||
|
assert( !Abc_ObjIsPi(pNode) );
|
||||||
|
pTruth0 = (word *)Abc_ObjFanin0(pNode)->pCopy;
|
||||||
|
pTruth1 = (word *)Abc_ObjFanin1(pNode)->pCopy;
|
||||||
|
pTruth = (word *)Vec_PtrEntry( vFuncs, i );
|
||||||
|
if ( Abc_ObjFaninC0(pNode) )
|
||||||
|
{
|
||||||
|
if ( Abc_ObjFaninC1(pNode) )
|
||||||
|
for ( k = 0; k < nWords; k++ )
|
||||||
|
pTruth[k] = ~pTruth0[k] & ~pTruth1[k];
|
||||||
|
else
|
||||||
|
for ( k = 0; k < nWords; k++ )
|
||||||
|
pTruth[k] = ~pTruth0[k] & pTruth1[k];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( Abc_ObjFaninC1(pNode) )
|
||||||
|
for ( k = 0; k < nWords; k++ )
|
||||||
|
pTruth[k] = pTruth0[k] & ~pTruth1[k];
|
||||||
|
else
|
||||||
|
for ( k = 0; k < nWords; k++ )
|
||||||
|
pTruth[k] = pTruth0[k] & pTruth1[k];
|
||||||
|
}
|
||||||
|
pNode->pCopy = (Abc_Obj_t *)pTruth;
|
||||||
|
}
|
||||||
|
return pTruth;
|
||||||
|
}
|
||||||
|
int Abc_NodeConeIsConst0( word * pTruth, int nVars )
|
||||||
|
{
|
||||||
|
int k, nWords = Abc_Truth6WordNum( nVars );
|
||||||
|
for ( k = 0; k < nWords; k++ )
|
||||||
|
if ( pTruth[k] )
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int Abc_NodeConeIsConst1( word * pTruth, int nVars )
|
||||||
|
{
|
||||||
|
int k, nWords = Abc_Truth6WordNum( nVars );
|
||||||
|
for ( k = 0; k < nWords; k++ )
|
||||||
|
if ( ~pTruth[k] )
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**Function*************************************************************
|
||||||
|
|
||||||
|
Synopsis [Resynthesizes the node using refactoring.]
|
||||||
|
|
||||||
|
Description []
|
||||||
|
|
||||||
|
SideEffects []
|
||||||
|
|
||||||
|
SeeAlso []
|
||||||
|
|
||||||
|
***********************************************************************/
|
||||||
|
Dec_Graph_t * Abc_NodeRefactor( Abc_ManRef_t * p, Abc_Obj_t * pNode, Vec_Ptr_t * vFanins, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose )
|
||||||
|
{
|
||||||
|
extern int Dec_GraphToNetworkCount( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax, int LevelMax );
|
||||||
|
int fVeryVerbose = 0;
|
||||||
|
int nVars = Vec_PtrSize(vFanins);
|
||||||
|
int nWordsMax = Abc_Truth6WordNum(p->nNodeSizeMax);
|
||||||
|
Dec_Graph_t * pFForm;
|
||||||
|
Abc_Obj_t * pFanin;
|
||||||
|
word * pTruth;
|
||||||
|
abctime clk;
|
||||||
|
int i, nNodesSaved, nNodesAdded, Required;
|
||||||
|
|
||||||
|
p->nNodesConsidered++;
|
||||||
|
|
||||||
|
Required = fUpdateLevel? Abc_ObjRequiredLevel(pNode) : ABC_INFINITY;
|
||||||
|
|
||||||
|
// get the function of the cut
|
||||||
|
clk = Abc_Clock();
|
||||||
|
pTruth = Abc_NodeConeTruth( p->vVars, p->vFuncs, nWordsMax, pNode, vFanins, p->vVisited );
|
||||||
|
p->timeTru += Abc_Clock() - clk;
|
||||||
|
|
||||||
|
// always accept the case of constant node
|
||||||
|
if ( Abc_NodeConeIsConst0(pTruth, nVars) || Abc_NodeConeIsConst1(pTruth, nVars) )
|
||||||
|
{
|
||||||
|
p->nLastGain = Abc_NodeMffcSize( pNode );
|
||||||
|
p->nNodesGained += p->nLastGain;
|
||||||
|
p->nNodesRefactored++;
|
||||||
|
return Abc_NodeConeIsConst0(pTruth, nVars) ? Dec_GraphCreateConst0() : Dec_GraphCreateConst1();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the factored form
|
||||||
|
clk = Abc_Clock();
|
||||||
|
pFForm = (Dec_Graph_t *)Kit_TruthToGraph( (unsigned *)pTruth, nVars, p->vMemory );
|
||||||
|
p->timeFact += Abc_Clock() - clk;
|
||||||
|
|
||||||
|
// mark the fanin boundary
|
||||||
|
// (can mark only essential fanins, belonging to bNodeFunc!)
|
||||||
|
Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pFanin, i )
|
||||||
|
pFanin->vFanouts.nSize++;
|
||||||
|
// label MFFC with current traversal ID
|
||||||
|
Abc_NtkIncrementTravId( pNode->pNtk );
|
||||||
|
nNodesSaved = Abc_NodeMffcLabelAig( pNode );
|
||||||
|
// unmark the fanin boundary and set the fanins as leaves in the form
|
||||||
|
Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pFanin, i )
|
||||||
|
{
|
||||||
|
pFanin->vFanouts.nSize--;
|
||||||
|
Dec_GraphNode(pFForm, i)->pFunc = pFanin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// detect how many new nodes will be added (while taking into account reused nodes)
|
||||||
|
clk = Abc_Clock();
|
||||||
|
nNodesAdded = Dec_GraphToNetworkCount( pNode, pFForm, nNodesSaved, Required );
|
||||||
|
p->timeEval += Abc_Clock() - clk;
|
||||||
|
// quit if there is no improvement
|
||||||
|
if ( nNodesAdded == -1 || (nNodesAdded == nNodesSaved && !fUseZeros) )
|
||||||
|
{
|
||||||
|
Dec_GraphFree( pFForm );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute the total gain in the number of nodes
|
||||||
|
p->nLastGain = nNodesSaved - nNodesAdded;
|
||||||
|
p->nNodesGained += p->nLastGain;
|
||||||
|
p->nNodesRefactored++;
|
||||||
|
|
||||||
|
// report the progress
|
||||||
|
if ( fVeryVerbose )
|
||||||
|
{
|
||||||
|
printf( "Node %6s : ", Abc_ObjName(pNode) );
|
||||||
|
printf( "Cone = %2d. ", vFanins->nSize );
|
||||||
|
printf( "FF = %2d. ", 1 + Dec_GraphNodeNum(pFForm) );
|
||||||
|
printf( "MFFC = %2d. ", nNodesSaved );
|
||||||
|
printf( "Add = %2d. ", nNodesAdded );
|
||||||
|
printf( "GAIN = %2d. ", p->nLastGain );
|
||||||
|
printf( "\n" );
|
||||||
|
}
|
||||||
|
return pFForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**Function*************************************************************
|
||||||
|
|
||||||
|
Synopsis [Starts the resynthesis manager.]
|
||||||
|
|
||||||
|
Description []
|
||||||
|
|
||||||
|
SideEffects []
|
||||||
|
|
||||||
|
SeeAlso []
|
||||||
|
|
||||||
|
***********************************************************************/
|
||||||
|
Abc_ManRef_t * Abc_NtkManRefStart( int nNodeSizeMax, int nConeSizeMax, int fUseDcs, int fVerbose )
|
||||||
|
{
|
||||||
|
Abc_ManRef_t * p;
|
||||||
|
p = ABC_ALLOC( Abc_ManRef_t, 1 );
|
||||||
|
memset( p, 0, sizeof(Abc_ManRef_t) );
|
||||||
|
p->vCube = Vec_StrAlloc( 100 );
|
||||||
|
p->vVisited = Vec_PtrAlloc( 100 );
|
||||||
|
p->nNodeSizeMax = nNodeSizeMax;
|
||||||
|
p->nConeSizeMax = nConeSizeMax;
|
||||||
|
p->fVerbose = fVerbose;
|
||||||
|
p->vVars = Vec_PtrAllocTruthTables( Abc_MaxInt(nNodeSizeMax, 6) );
|
||||||
|
p->vFuncs = Vec_PtrAlloc( 100 );
|
||||||
|
p->vMemory = Vec_IntAlloc( 1 << 16 );
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**Function*************************************************************
|
||||||
|
|
||||||
|
Synopsis [Stops the resynthesis manager.]
|
||||||
|
|
||||||
|
Description []
|
||||||
|
|
||||||
|
SideEffects []
|
||||||
|
|
||||||
|
SeeAlso []
|
||||||
|
|
||||||
|
***********************************************************************/
|
||||||
|
void Abc_NtkManRefStop( Abc_ManRef_t * p )
|
||||||
|
{
|
||||||
|
Vec_PtrFreeFree( p->vFuncs );
|
||||||
|
Vec_PtrFree( p->vVars );
|
||||||
|
Vec_IntFree( p->vMemory );
|
||||||
|
Vec_PtrFree( p->vVisited );
|
||||||
|
Vec_StrFree( p->vCube );
|
||||||
|
ABC_FREE( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**Function*************************************************************
|
||||||
|
|
||||||
|
Synopsis [Stops the resynthesis manager.]
|
||||||
|
|
||||||
|
Description []
|
||||||
|
|
||||||
|
SideEffects []
|
||||||
|
|
||||||
|
SeeAlso []
|
||||||
|
|
||||||
|
***********************************************************************/
|
||||||
|
void Abc_NtkManRefPrintStats( Abc_ManRef_t * p )
|
||||||
|
{
|
||||||
|
printf( "Refactoring statistics:\n" );
|
||||||
|
printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
|
||||||
|
printf( "Nodes refactored = %8d.\n", p->nNodesRefactored );
|
||||||
|
printf( "Gain = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
|
||||||
|
ABC_PRT( "Cuts ", p->timeCut );
|
||||||
|
ABC_PRT( "Resynthesis", p->timeRes );
|
||||||
|
ABC_PRT( " BDD ", p->timeTru );
|
||||||
|
ABC_PRT( " DCs ", p->timeDcs );
|
||||||
|
ABC_PRT( " SOP ", p->timeSop );
|
||||||
|
ABC_PRT( " FF ", p->timeFact );
|
||||||
|
ABC_PRT( " Eval ", p->timeEval );
|
||||||
|
ABC_PRT( "AIG update ", p->timeNtk );
|
||||||
|
ABC_PRT( "TOTAL ", p->timeTotal );
|
||||||
|
}
|
||||||
|
|
||||||
/**Function*************************************************************
|
/**Function*************************************************************
|
||||||
|
|
||||||
Synopsis [Performs incremental resynthesis of the AIG.]
|
Synopsis [Performs incremental resynthesis of the AIG.]
|
||||||
|
|
@ -148,10 +378,6 @@ clk = Abc_Clock();
|
||||||
Dec_GraphUpdateNetwork( pNode, pFForm, fUpdateLevel, pManRef->nLastGain );
|
Dec_GraphUpdateNetwork( pNode, pFForm, fUpdateLevel, pManRef->nLastGain );
|
||||||
pManRef->timeNtk += Abc_Clock() - clk;
|
pManRef->timeNtk += Abc_Clock() - clk;
|
||||||
Dec_GraphFree( pFForm );
|
Dec_GraphFree( pFForm );
|
||||||
// {
|
|
||||||
// extern int s_TotalChanges;
|
|
||||||
// s_TotalChanges++;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
Extra_ProgressBarStop( pProgress );
|
Extra_ProgressBarStop( pProgress );
|
||||||
pManRef->timeTotal = Abc_Clock() - clkStart;
|
pManRef->timeTotal = Abc_Clock() - clkStart;
|
||||||
|
|
@ -180,217 +406,6 @@ pManRef->timeTotal = Abc_Clock() - clkStart;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Function*************************************************************
|
|
||||||
|
|
||||||
Synopsis [Resynthesizes the node using refactoring.]
|
|
||||||
|
|
||||||
Description []
|
|
||||||
|
|
||||||
SideEffects []
|
|
||||||
|
|
||||||
SeeAlso []
|
|
||||||
|
|
||||||
***********************************************************************/
|
|
||||||
Dec_Graph_t * Abc_NodeRefactor( Abc_ManRef_t * p, Abc_Obj_t * pNode, Vec_Ptr_t * vFanins, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose )
|
|
||||||
{
|
|
||||||
extern DdNode * Abc_NodeConeBdd( DdManager * dd, DdNode ** pbVars, Abc_Obj_t * pNode, Vec_Ptr_t * vFanins, Vec_Ptr_t * vVisited );
|
|
||||||
extern DdNode * Abc_NodeConeDcs( DdManager * dd, DdNode ** pbVarsX, DdNode ** pbVarsY, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vRoots, Vec_Ptr_t * vVisited );
|
|
||||||
extern char * Abc_ConvertBddToSop( Mem_Flex_t * pMan, DdManager * dd, DdNode * bFuncOn, DdNode * bFuncOnDc, int nFanins, int fAllPrimes, Vec_Str_t * vCube, int fMode );
|
|
||||||
extern int Dec_GraphToNetworkCount( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax, int LevelMax );
|
|
||||||
int fVeryVerbose = 0;
|
|
||||||
Abc_Obj_t * pFanin;
|
|
||||||
Dec_Graph_t * pFForm;
|
|
||||||
DdNode * bNodeFunc;
|
|
||||||
int nNodesSaved, nNodesAdded, i;
|
|
||||||
abctime clk;
|
|
||||||
char * pSop;
|
|
||||||
int Required;
|
|
||||||
|
|
||||||
Required = fUpdateLevel? Abc_ObjRequiredLevel(pNode) : ABC_INFINITY;
|
|
||||||
|
|
||||||
p->nNodesConsidered++;
|
|
||||||
|
|
||||||
// get the function of the cut
|
|
||||||
clk = Abc_Clock();
|
|
||||||
bNodeFunc = Abc_NodeConeBdd( p->dd, p->dd->vars, pNode, vFanins, p->vVisited ); Cudd_Ref( bNodeFunc );
|
|
||||||
p->timeBdd += Abc_Clock() - clk;
|
|
||||||
|
|
||||||
// if don't-care are used, transform the function into ISOP
|
|
||||||
if ( fUseDcs )
|
|
||||||
{
|
|
||||||
DdNode * bNodeDc, * bNodeOn, * bNodeOnDc;
|
|
||||||
int nMints, nMintsDc;
|
|
||||||
clk = Abc_Clock();
|
|
||||||
// get the don't-cares
|
|
||||||
bNodeDc = Abc_NodeConeDcs( p->dd, p->dd->vars + vFanins->nSize, p->dd->vars, p->vLeaves, vFanins, p->vVisited ); Cudd_Ref( bNodeDc );
|
|
||||||
nMints = (1 << vFanins->nSize);
|
|
||||||
nMintsDc = (int)Cudd_CountMinterm( p->dd, bNodeDc, vFanins->nSize );
|
|
||||||
// printf( "Percentage of minterms = %5.2f.\n", 100.0 * nMintsDc / nMints );
|
|
||||||
// get the ISF
|
|
||||||
bNodeOn = Cudd_bddAnd( p->dd, bNodeFunc, Cudd_Not(bNodeDc) ); Cudd_Ref( bNodeOn );
|
|
||||||
bNodeOnDc = Cudd_bddOr ( p->dd, bNodeFunc, bNodeDc ); Cudd_Ref( bNodeOnDc );
|
|
||||||
Cudd_RecursiveDeref( p->dd, bNodeFunc );
|
|
||||||
Cudd_RecursiveDeref( p->dd, bNodeDc );
|
|
||||||
// get the ISOP
|
|
||||||
bNodeFunc = Cudd_bddIsop( p->dd, bNodeOn, bNodeOnDc ); Cudd_Ref( bNodeFunc );
|
|
||||||
Cudd_RecursiveDeref( p->dd, bNodeOn );
|
|
||||||
Cudd_RecursiveDeref( p->dd, bNodeOnDc );
|
|
||||||
p->timeDcs += Abc_Clock() - clk;
|
|
||||||
}
|
|
||||||
|
|
||||||
// always accept the case of constant node
|
|
||||||
if ( Cudd_IsConstant(bNodeFunc) )
|
|
||||||
{
|
|
||||||
p->nLastGain = Abc_NodeMffcSize( pNode );
|
|
||||||
p->nNodesGained += p->nLastGain;
|
|
||||||
p->nNodesRefactored++;
|
|
||||||
Cudd_RecursiveDeref( p->dd, bNodeFunc );
|
|
||||||
if ( Cudd_IsComplement(bNodeFunc) )
|
|
||||||
return Dec_GraphCreateConst0();
|
|
||||||
return Dec_GraphCreateConst1();
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the SOP of the cut
|
|
||||||
clk = Abc_Clock();
|
|
||||||
pSop = Abc_ConvertBddToSop( NULL, p->dd, bNodeFunc, bNodeFunc, vFanins->nSize, 0, p->vCube, -1 );
|
|
||||||
p->timeSop += Abc_Clock() - clk;
|
|
||||||
|
|
||||||
// get the factored form
|
|
||||||
clk = Abc_Clock();
|
|
||||||
pFForm = Dec_Factor( pSop );
|
|
||||||
ABC_FREE( pSop );
|
|
||||||
p->timeFact += Abc_Clock() - clk;
|
|
||||||
|
|
||||||
// mark the fanin boundary
|
|
||||||
// (can mark only essential fanins, belonging to bNodeFunc!)
|
|
||||||
Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pFanin, i )
|
|
||||||
pFanin->vFanouts.nSize++;
|
|
||||||
// label MFFC with current traversal ID
|
|
||||||
Abc_NtkIncrementTravId( pNode->pNtk );
|
|
||||||
nNodesSaved = Abc_NodeMffcLabelAig( pNode );
|
|
||||||
// unmark the fanin boundary and set the fanins as leaves in the form
|
|
||||||
Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pFanin, i )
|
|
||||||
{
|
|
||||||
pFanin->vFanouts.nSize--;
|
|
||||||
Dec_GraphNode(pFForm, i)->pFunc = pFanin;
|
|
||||||
}
|
|
||||||
|
|
||||||
// detect how many new nodes will be added (while taking into account reused nodes)
|
|
||||||
clk = Abc_Clock();
|
|
||||||
nNodesAdded = Dec_GraphToNetworkCount( pNode, pFForm, nNodesSaved, Required );
|
|
||||||
p->timeEval += Abc_Clock() - clk;
|
|
||||||
// quit if there is no improvement
|
|
||||||
if ( nNodesAdded == -1 || (nNodesAdded == nNodesSaved && !fUseZeros) )
|
|
||||||
{
|
|
||||||
Cudd_RecursiveDeref( p->dd, bNodeFunc );
|
|
||||||
Dec_GraphFree( pFForm );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// compute the total gain in the number of nodes
|
|
||||||
p->nLastGain = nNodesSaved - nNodesAdded;
|
|
||||||
p->nNodesGained += p->nLastGain;
|
|
||||||
p->nNodesRefactored++;
|
|
||||||
|
|
||||||
// report the progress
|
|
||||||
if ( fVeryVerbose )
|
|
||||||
{
|
|
||||||
printf( "Node %6s : ", Abc_ObjName(pNode) );
|
|
||||||
printf( "Cone = %2d. ", vFanins->nSize );
|
|
||||||
printf( "BDD = %2d. ", Cudd_DagSize(bNodeFunc) );
|
|
||||||
printf( "FF = %2d. ", 1 + Dec_GraphNodeNum(pFForm) );
|
|
||||||
printf( "MFFC = %2d. ", nNodesSaved );
|
|
||||||
printf( "Add = %2d. ", nNodesAdded );
|
|
||||||
printf( "GAIN = %2d. ", p->nLastGain );
|
|
||||||
printf( "\n" );
|
|
||||||
}
|
|
||||||
Cudd_RecursiveDeref( p->dd, bNodeFunc );
|
|
||||||
return pFForm;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**Function*************************************************************
|
|
||||||
|
|
||||||
Synopsis [Starts the resynthesis manager.]
|
|
||||||
|
|
||||||
Description []
|
|
||||||
|
|
||||||
SideEffects []
|
|
||||||
|
|
||||||
SeeAlso []
|
|
||||||
|
|
||||||
***********************************************************************/
|
|
||||||
Abc_ManRef_t * Abc_NtkManRefStart( int nNodeSizeMax, int nConeSizeMax, int fUseDcs, int fVerbose )
|
|
||||||
{
|
|
||||||
Abc_ManRef_t * p;
|
|
||||||
p = ABC_ALLOC( Abc_ManRef_t, 1 );
|
|
||||||
memset( p, 0, sizeof(Abc_ManRef_t) );
|
|
||||||
p->vCube = Vec_StrAlloc( 100 );
|
|
||||||
p->vVisited = Vec_PtrAlloc( 100 );
|
|
||||||
p->nNodeSizeMax = nNodeSizeMax;
|
|
||||||
p->nConeSizeMax = nConeSizeMax;
|
|
||||||
p->fVerbose = fVerbose;
|
|
||||||
// start the BDD manager
|
|
||||||
if ( fUseDcs )
|
|
||||||
p->dd = Cudd_Init( p->nNodeSizeMax + p->nConeSizeMax, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
|
|
||||||
else
|
|
||||||
p->dd = Cudd_Init( p->nNodeSizeMax, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
|
|
||||||
Cudd_zddVarsFromBddVars( p->dd, 2 );
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Function*************************************************************
|
|
||||||
|
|
||||||
Synopsis [Stops the resynthesis manager.]
|
|
||||||
|
|
||||||
Description []
|
|
||||||
|
|
||||||
SideEffects []
|
|
||||||
|
|
||||||
SeeAlso []
|
|
||||||
|
|
||||||
***********************************************************************/
|
|
||||||
void Abc_NtkManRefStop( Abc_ManRef_t * p )
|
|
||||||
{
|
|
||||||
Extra_StopManager( p->dd );
|
|
||||||
Vec_PtrFree( p->vVisited );
|
|
||||||
Vec_StrFree( p->vCube );
|
|
||||||
ABC_FREE( p );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Function*************************************************************
|
|
||||||
|
|
||||||
Synopsis [Stops the resynthesis manager.]
|
|
||||||
|
|
||||||
Description []
|
|
||||||
|
|
||||||
SideEffects []
|
|
||||||
|
|
||||||
SeeAlso []
|
|
||||||
|
|
||||||
***********************************************************************/
|
|
||||||
void Abc_NtkManRefPrintStats( Abc_ManRef_t * p )
|
|
||||||
{
|
|
||||||
printf( "Refactoring statistics:\n" );
|
|
||||||
printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
|
|
||||||
printf( "Nodes refactored = %8d.\n", p->nNodesRefactored );
|
|
||||||
printf( "Gain = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
|
|
||||||
ABC_PRT( "Cuts ", p->timeCut );
|
|
||||||
ABC_PRT( "Resynthesis", p->timeRes );
|
|
||||||
ABC_PRT( " BDD ", p->timeBdd );
|
|
||||||
ABC_PRT( " DCs ", p->timeDcs );
|
|
||||||
ABC_PRT( " SOP ", p->timeSop );
|
|
||||||
ABC_PRT( " FF ", p->timeFact );
|
|
||||||
ABC_PRT( " Eval ", p->timeEval );
|
|
||||||
ABC_PRT( "AIG update ", p->timeNtk );
|
|
||||||
ABC_PRT( "TOTAL ", p->timeTotal );
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
int Abc_NtkRefactor( Abc_Ntk_t * pNtk, int nNodeSizeMax, int nConeSizeMax, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose ) { return 1; }
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
/// END OF FILE ///
|
/// END OF FILE ///
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,6 @@ ABC_NAMESPACE_IMPL_START
|
||||||
/// DECLARATIONS ///
|
/// DECLARATIONS ///
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef ABC_USE_CUDD
|
|
||||||
|
|
||||||
static Abc_Ntk_t * Io_ReadEqnNetwork( Extra_FileReader_t * p );
|
static Abc_Ntk_t * Io_ReadEqnNetwork( Extra_FileReader_t * p );
|
||||||
static void Io_ReadEqnStrCompact( char * pStr );
|
static void Io_ReadEqnStrCompact( char * pStr );
|
||||||
static int Io_ReadEqnStrFind( Vec_Ptr_t * vTokens, char * pName );
|
static int Io_ReadEqnStrFind( Vec_Ptr_t * vTokens, char * pName );
|
||||||
|
|
@ -235,11 +233,6 @@ void Io_ReadEqnStrCutAt( char * pStr, char * pStop, int fUniqueOnly, Vec_Ptr_t *
|
||||||
Vec_PtrPush( vTokens, pToken );
|
Vec_PtrPush( vTokens, pToken );
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
Abc_Ntk_t * Io_ReadEqn( char * pFileName, int fCheck ) { return NULL; }
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
/// END OF FILE ///
|
/// END OF FILE ///
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue