00001 
00021 #include "darInt.h"
00022 
00026 
00030 
00042 void Dar_ManDefaultRwrParams( Dar_RwrPar_t * pPars )
00043 {
00044     memset( pPars, 0, sizeof(Dar_RwrPar_t) );
00045     pPars->nCutsMax     =  8; 
00046     pPars->nSubgMax     =  5; 
00047     pPars->fFanout      =  1;
00048     pPars->fUpdateLevel =  0;
00049     pPars->fUseZeros    =  0;
00050     pPars->fVerbose     =  0;
00051     pPars->fVeryVerbose =  0;
00052 }
00053 
00065 int Dar_ManRewrite( Aig_Man_t * pAig, Dar_RwrPar_t * pPars )
00066 {
00067     Dar_Man_t * p;
00068 
00069     Dar_Cut_t * pCut;
00070     Aig_Obj_t * pObj, * pObjNew;
00071     int i, k, nNodesOld, nNodeBefore, nNodeAfter, Required;
00072     int clk = 0, clkStart;
00073     
00074     Dar_LibPrepare( pPars->nSubgMax ); 
00075     
00076     p = Dar_ManStart( pAig, pPars );
00077     
00078     Aig_ManCleanup( pAig );
00079     
00080     if ( p->pPars->fFanout )
00081         Aig_ManFanoutStart( pAig );
00082     if ( p->pPars->fUpdateLevel )
00083         Aig_ManStartReverseLevels( pAig, 0 );
00084     
00085     Dar_ManCutsStart( p );
00086     
00087     clkStart = clock();
00088     p->nNodesInit = Aig_ManNodeNum(pAig);
00089     nNodesOld = Vec_PtrSize( pAig->vObjs );
00090 
00091 
00092     Aig_ManForEachObj( pAig, pObj, i )
00093 
00094 
00095 
00096     {
00097 
00098 
00099 
00100         if ( !Aig_ObjIsNode(pObj) )
00101             continue;
00102         if ( i > nNodesOld )
00103             break;
00104 
00105         
00106 
00107 
00108 
00109         
00110         p->nNodesTried++;
00111 clk = clock();
00112         Dar_ObjComputeCuts_rec( p, pObj );
00113 p->timeCuts += clock() - clk;
00114 
00115         
00116         Dar_ObjForEachCut( pObj, pCut, k )
00117             if ( pCut->nLeaves == 0 || (pCut->nLeaves == 1 && pCut->pLeaves[0] != pObj->Id && Aig_ManObj(p->pAig, pCut->pLeaves[0])) )
00118                 break;
00119         if ( k < (int)pObj->nCuts )
00120         {
00121             assert( pCut->nLeaves < 2 );
00122             if ( pCut->nLeaves == 0 ) 
00123             {
00124                 assert( pCut->uTruth == 0 || pCut->uTruth == 0xFFFF );
00125                 pObjNew = Aig_NotCond( Aig_ManConst1(p->pAig), pCut->uTruth==0 );
00126             }
00127             else
00128             {
00129                 assert( pCut->uTruth == 0xAAAA || pCut->uTruth == 0x5555 );
00130                 pObjNew = Aig_NotCond( Aig_ManObj(p->pAig, pCut->pLeaves[0]), pCut->uTruth==0x5555 );
00131             }
00132             
00133             Dar_ObjSetCuts( pObj, NULL );
00134             
00135             Aig_ObjReplace( pAig, pObj, pObjNew, 1, p->pPars->fUpdateLevel );
00136             continue;
00137         }
00138 
00139         
00140         p->GainBest = -1;
00141         Required = pAig->vLevelR? Aig_ObjRequiredLevel(pAig, pObj) : AIG_INFINITY;
00142         Dar_ObjForEachCut( pObj, pCut, k )
00143             Dar_LibEval( p, pObj, pCut, Required );
00144         
00145         if ( !(p->GainBest > 0 || (p->GainBest == 0 && p->pPars->fUseZeros)) )
00146         {
00147 
00148             continue;
00149         }
00150         
00151         Dar_ObjSetCuts( pObj, NULL );
00152         
00153         nNodeBefore = Aig_ManNodeNum( pAig );
00154         pObjNew = Dar_LibBuildBest( p ); 
00155         pObjNew = Aig_NotCond( pObjNew, Aig_ObjPhaseReal(pObjNew) ^ pObj->fPhase );
00156         assert( (int)Aig_Regular(pObjNew)->Level <= Required );
00157         
00158         Aig_ObjReplace( pAig, pObj, pObjNew, 1, p->pPars->fUpdateLevel );
00159         
00160         nNodeAfter = Aig_ManNodeNum( pAig );
00161         assert( p->GainBest <= nNodeBefore - nNodeAfter );
00162         
00163         p->ClassGains[p->ClassBest] += nNodeBefore - nNodeAfter;
00164     }
00165 
00166 
00167 p->timeTotal = clock() - clkStart;
00168 p->timeOther = p->timeTotal - p->timeCuts - p->timeEval;
00169 
00170 
00171     p->nCutMemUsed = Aig_MmFixedReadMemUsage(p->pMemCuts)/(1<<20);
00172     Dar_ManCutsFree( p );
00173     
00174 
00175     
00176 
00177     if ( p->pPars->fFanout )
00178         Aig_ManFanoutStop( pAig );
00179     if ( p->pPars->fUpdateLevel )
00180     {
00181 
00182         Aig_ManStopReverseLevels( pAig );
00183     }
00184     
00185     Dar_ManStop( p );
00186     Aig_ManCheckPhase( pAig );
00187     
00188     if ( !Aig_ManCheck( pAig ) )
00189     {
00190         printf( "Aig_ManRewrite: The network check has failed.\n" );
00191         return 0;
00192     }
00193     return 1;
00194 }
00195 
00207 Aig_MmFixed_t * Dar_ManComputeCuts( Aig_Man_t * pAig, int nCutsMax )
00208 {
00209     Dar_Man_t * p;
00210     Dar_RwrPar_t Pars, * pPars = &Pars; 
00211     Aig_Obj_t * pObj;
00212     Aig_MmFixed_t * pMemCuts;
00213     int i, nNodes;
00214     
00215     if ( (nNodes = Aig_ManCleanup( pAig )) )
00216     {
00217 
00218     }
00219     
00220     Dar_ManDefaultRwrParams( pPars );
00221     pPars->nCutsMax = nCutsMax;
00222     
00223     p = Dar_ManStart( pAig, pPars );
00224     
00225     Dar_ManCutsStart( p );
00226     
00227     Aig_ManForEachNode( pAig, pObj, i )
00228         Dar_ObjComputeCuts( p, pObj );
00229     
00230     pMemCuts = p->pMemCuts;
00231     p->pMemCuts = NULL;
00232 
00233     
00234     Dar_ManStop( p );
00235     return pMemCuts;
00236 }
00237 
00238 
00239 
00243 
00244