00001
00021 #include "abc.h"
00022 #include "reo.h"
00023 #include "if.h"
00024 #include "kit.h"
00025
00029
00030 static int Abc_NtkRenodeEvalAig( If_Cut_t * pCut );
00031 static int Abc_NtkRenodeEvalBdd( If_Cut_t * pCut );
00032 static int Abc_NtkRenodeEvalSop( If_Cut_t * pCut );
00033 static int Abc_NtkRenodeEvalCnf( If_Cut_t * pCut );
00034 static int Abc_NtkRenodeEvalMv( If_Cut_t * pCut );
00035
00036 static reo_man * s_pReo = NULL;
00037 static DdManager * s_pDd = NULL;
00038 static Vec_Int_t * s_vMemory = NULL;
00039 static Vec_Int_t * s_vMemory2 = NULL;
00040
00041 static int nDsdCounter = 0;
00042
00046
00058 Abc_Ntk_t * Abc_NtkRenode( Abc_Ntk_t * pNtk, int nFaninMax, int nCubeMax, int nFlowIters, int nAreaIters, int fArea, int fUseBdds, int fUseSops, int fUseCnfs, int fUseMv, int fVerbose )
00059 {
00060 extern Abc_Ntk_t * Abc_NtkIf( Abc_Ntk_t * pNtk, If_Par_t * pPars );
00061 If_Par_t Pars, * pPars = &Pars;
00062 Abc_Ntk_t * pNtkNew;
00063
00064 if ( Abc_NtkGetChoiceNum( pNtk ) )
00065 printf( "Performing renoding with choices.\n" );
00066
00067 nDsdCounter = 0;
00068
00069
00070 memset( pPars, 0, sizeof(If_Par_t) );
00071
00072 pPars->nLutSize = nFaninMax;
00073 pPars->nCutsMax = nCubeMax;
00074 pPars->nFlowIters = nFlowIters;
00075 pPars->nAreaIters = nAreaIters;
00076 pPars->DelayTarget = -1;
00077 pPars->fPreprocess = 1;
00078 pPars->fArea = fArea;
00079 pPars->fFancy = 0;
00080 pPars->fExpRed = 0;
00081 pPars->fLatchPaths = 0;
00082 pPars->fSeqMap = 0;
00083 pPars->fVerbose = fVerbose;
00084
00085 pPars->fTruth = 1;
00086 pPars->fUsePerm = 1;
00087 pPars->nLatches = 0;
00088 pPars->pLutLib = NULL;
00089 pPars->pTimesArr = NULL;
00090 pPars->pTimesArr = NULL;
00091 pPars->fUseBdds = fUseBdds;
00092 pPars->fUseSops = fUseSops;
00093 pPars->fUseCnfs = fUseCnfs;
00094 pPars->fUseMv = fUseMv;
00095 if ( fUseBdds )
00096 pPars->pFuncCost = Abc_NtkRenodeEvalBdd;
00097 else if ( fUseSops )
00098 pPars->pFuncCost = Abc_NtkRenodeEvalSop;
00099 else if ( fUseCnfs )
00100 {
00101 pPars->fArea = 1;
00102 pPars->pFuncCost = Abc_NtkRenodeEvalCnf;
00103 }
00104 else if ( fUseMv )
00105 pPars->pFuncCost = Abc_NtkRenodeEvalMv;
00106 else
00107 pPars->pFuncCost = Abc_NtkRenodeEvalAig;
00108
00109
00110 if ( fUseBdds )
00111 {
00112 assert( s_pReo == NULL );
00113 s_pDd = Cudd_Init( nFaninMax, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
00114 s_pReo = Extra_ReorderInit( nFaninMax, 100 );
00115 pPars->pReoMan = s_pReo;
00116 }
00117 else
00118 {
00119 assert( s_vMemory == NULL );
00120 s_vMemory = Vec_IntAlloc( 1 << 16 );
00121 s_vMemory2 = Vec_IntAlloc( 1 << 16 );
00122 }
00123
00124
00125 pNtkNew = Abc_NtkIf( pNtk, pPars );
00126
00127
00128 if ( fUseBdds )
00129 {
00130 Extra_StopManager( s_pDd );
00131 Extra_ReorderQuit( s_pReo );
00132 s_pReo = NULL;
00133 s_pDd = NULL;
00134 }
00135 else
00136 {
00137 Vec_IntFree( s_vMemory );
00138 Vec_IntFree( s_vMemory2 );
00139 s_vMemory = NULL;
00140 s_vMemory2 = NULL;
00141 }
00142
00143
00144
00145 return pNtkNew;
00146 }
00147
00159 int Abc_NtkRenodeEvalAig( If_Cut_t * pCut )
00160 {
00161 Kit_Graph_t * pGraph;
00162 int i, nNodes;
00163
00164
00165
00166
00167
00168
00169
00170
00171 pGraph = Kit_TruthToGraph( If_CutTruth(pCut), If_CutLeaveNum(pCut), s_vMemory );
00172 if ( pGraph == NULL )
00173 {
00174 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
00175 pCut->pPerm[i] = 100;
00176 return IF_COST_MAX;
00177 }
00178 nNodes = Kit_GraphNodeNum( pGraph );
00179 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
00180 pCut->pPerm[i] = Kit_GraphLeafDepth_rec( pGraph, Kit_GraphNodeLast(pGraph), Kit_GraphNode(pGraph, i) );
00181 Kit_GraphFree( pGraph );
00182 return nNodes;
00183 }
00184
00196 int Abc_NtkRenodeEvalBdd( If_Cut_t * pCut )
00197 {
00198 int pOrder[IF_MAX_LUTSIZE];
00199 DdNode * bFunc, * bFuncNew;
00200 int i, k, nNodes;
00201 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
00202 pCut->pPerm[i] = pOrder[i] = -100;
00203 bFunc = Kit_TruthToBdd( s_pDd, If_CutTruth(pCut), If_CutLeaveNum(pCut), 0 ); Cudd_Ref( bFunc );
00204 bFuncNew = Extra_Reorder( s_pReo, s_pDd, bFunc, pOrder ); Cudd_Ref( bFuncNew );
00205 for ( i = k = 0; i < If_CutLeaveNum(pCut); i++ )
00206 if ( pOrder[i] >= 0 )
00207 pCut->pPerm[pOrder[i]] = ++k;
00208 nNodes = -1 + Cudd_DagSize( bFuncNew );
00209 Cudd_RecursiveDeref( s_pDd, bFuncNew );
00210 Cudd_RecursiveDeref( s_pDd, bFunc );
00211 return nNodes;
00212 }
00213
00225 int Abc_NtkRenodeEvalSop( If_Cut_t * pCut )
00226 {
00227 int i, RetValue;
00228 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
00229 pCut->pPerm[i] = 1;
00230 RetValue = Kit_TruthIsop( If_CutTruth(pCut), If_CutLeaveNum(pCut), s_vMemory, 1 );
00231 if ( RetValue == -1 )
00232 return IF_COST_MAX;
00233 assert( RetValue == 0 || RetValue == 1 );
00234 return Vec_IntSize( s_vMemory );
00235 }
00236
00248 int Abc_NtkRenodeEvalCnf( If_Cut_t * pCut )
00249 {
00250 int i, RetValue, nClauses;
00251
00252 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
00253 pCut->pPerm[i] = 1;
00254
00255 RetValue = Kit_TruthIsop( If_CutTruth(pCut), If_CutLeaveNum(pCut), s_vMemory, 0 );
00256 if ( RetValue == -1 )
00257 return IF_COST_MAX;
00258 assert( RetValue == 0 || RetValue == 1 );
00259 nClauses = Vec_IntSize( s_vMemory );
00260
00261 Kit_TruthNot( If_CutTruth(pCut), If_CutTruth(pCut), If_CutLeaveNum(pCut) );
00262 RetValue = Kit_TruthIsop( If_CutTruth(pCut), If_CutLeaveNum(pCut), s_vMemory, 0 );
00263 Kit_TruthNot( If_CutTruth(pCut), If_CutTruth(pCut), If_CutLeaveNum(pCut) );
00264 if ( RetValue == -1 )
00265 return IF_COST_MAX;
00266 assert( RetValue == 0 || RetValue == 1 );
00267 nClauses += Vec_IntSize( s_vMemory );
00268 return nClauses;
00269 }
00270
00282 int Abc_NtkRenodeEvalMv( If_Cut_t * pCut )
00283 {
00284 int i, RetValue;
00285
00286 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
00287 pCut->pPerm[i] = 1;
00288
00289 RetValue = Kit_TruthIsop( If_CutTruth(pCut), If_CutLeaveNum(pCut), s_vMemory, 0 );
00290 if ( RetValue == -1 )
00291 return IF_COST_MAX;
00292 assert( RetValue == 0 || RetValue == 1 );
00293
00294 Kit_TruthNot( If_CutTruth(pCut), If_CutTruth(pCut), If_CutLeaveNum(pCut) );
00295 RetValue = Kit_TruthIsop( If_CutTruth(pCut), If_CutLeaveNum(pCut), s_vMemory2, 0 );
00296 Kit_TruthNot( If_CutTruth(pCut), If_CutTruth(pCut), If_CutLeaveNum(pCut) );
00297 if ( RetValue == -1 )
00298 return IF_COST_MAX;
00299 assert( RetValue == 0 || RetValue == 1 );
00300
00301 RetValue = Abc_NodeEvalMvCost( If_CutLeaveNum(pCut), s_vMemory, s_vMemory2 );
00302 if ( RetValue >= IF_COST_MAX )
00303 return IF_COST_MAX;
00304 return RetValue;
00305 }
00306
00310
00311