00001
00021 #include "abc.h"
00022 #include "resInt.h"
00023
00027
00028 static void Res_WinMarkTfi( Res_Win_t * p );
00029
00033
00045 void Res_WinDivisors( Res_Win_t * p, int nLevDivMax )
00046 {
00047 Abc_Obj_t * pObj, * pFanout, * pFanin;
00048 int k, f, m;
00049
00050
00051 p->nLevDivMax = nLevDivMax;
00052
00053
00054 Abc_NtkIncrementTravId( p->pNode->pNtk );
00055 Res_WinMarkTfi( p );
00056
00057
00058
00059
00060
00061 Abc_NtkIncrementTravId( p->pNode->pNtk );
00062 Res_WinSweepLeafTfo_rec( p->pNode, p->nLevDivMax );
00063 Res_WinVisitMffc( p->pNode );
00064 Abc_ObjForEachFanin( p->pNode, pObj, k )
00065 Abc_NodeSetTravIdCurrent( pObj );
00066
00067
00068
00069
00070
00071
00072 Vec_PtrClear( p->vDivs );
00073 Vec_PtrForEachEntry( p->vLeaves, pObj, k )
00074 {
00075 assert( (int)pObj->Level >= p->nLevLeafMin );
00076 if ( !Abc_NodeIsTravIdPrevious(pObj) )
00077 continue;
00078 if ( (int)pObj->Level > p->nLevDivMax )
00079 continue;
00080 Vec_PtrPush( p->vDivs, pObj );
00081 }
00082
00083 Vec_PtrForEachEntry( p->vNodes, pObj, k )
00084 {
00085 if ( !Abc_NodeIsTravIdPrevious(pObj) )
00086 continue;
00087 if ( (int)pObj->Level > p->nLevDivMax )
00088 continue;
00089 Vec_PtrPush( p->vDivs, pObj );
00090 }
00091
00092
00093 p->nDivsPlus = 0;
00094 Vec_PtrForEachEntry( p->vDivs, pObj, k )
00095 {
00096
00097 Abc_ObjForEachFanout( pObj, pFanout, f )
00098 {
00099
00100 if ( f > 20 )
00101 break;
00102
00103 if ( Abc_NodeIsTravIdPrevious(pFanout) )
00104 continue;
00105
00106 if ( Abc_NodeIsTravIdCurrent(pFanout) )
00107 continue;
00108
00109 if ( !Abc_ObjIsNode(pFanout) )
00110 continue;
00111
00112 if ( (int)pFanout->Level >= p->nLevDivMax )
00113 continue;
00114
00115 Abc_ObjForEachFanin( pFanout, pFanin, m )
00116 if ( !Abc_NodeIsTravIdPrevious(pFanin) )
00117 break;
00118 if ( m < Abc_ObjFaninNum(pFanout) )
00119 continue;
00120
00121 Vec_PtrPush( p->vDivs, pFanout );
00122 Vec_PtrPush( p->vNodes, pFanout );
00123 Abc_NodeSetTravIdPrevious( pFanout );
00124 p->nDivsPlus++;
00125 }
00126 }
00127
00128
00129
00130
00131
00132
00133
00134 }
00135
00147 void Res_WinMarkTfi_rec( Res_Win_t * p, Abc_Obj_t * pObj )
00148 {
00149 Abc_Obj_t * pFanin;
00150 int i;
00151 if ( Abc_NodeIsTravIdCurrent(pObj) )
00152 return;
00153 Abc_NodeSetTravIdCurrent( pObj );
00154 assert( Abc_ObjIsNode(pObj) );
00155
00156 Abc_ObjForEachFanin( pObj, pFanin, i )
00157 Res_WinMarkTfi_rec( p, pFanin );
00158 }
00159
00171 void Res_WinMarkTfi( Res_Win_t * p )
00172 {
00173 Abc_Obj_t * pObj;
00174 int i;
00175
00176 Vec_PtrForEachEntry( p->vLeaves, pObj, i )
00177 Abc_NodeSetTravIdCurrent( pObj );
00178
00179 Res_WinMarkTfi_rec( p, p->pNode );
00180 }
00181
00193 void Res_WinSweepLeafTfo_rec( Abc_Obj_t * pObj, int nLevelLimit )
00194 {
00195 Abc_Obj_t * pFanout;
00196 int i;
00197 if ( Abc_ObjIsCo(pObj) || (int)pObj->Level > nLevelLimit )
00198 return;
00199 if ( Abc_NodeIsTravIdCurrent(pObj) )
00200 return;
00201 Abc_NodeSetTravIdCurrent( pObj );
00202 Abc_ObjForEachFanout( pObj, pFanout, i )
00203 Res_WinSweepLeafTfo_rec( pFanout, nLevelLimit );
00204 }
00205
00217 int Res_NodeDeref_rec( Abc_Obj_t * pNode )
00218 {
00219 Abc_Obj_t * pFanin;
00220 int i, Counter = 1;
00221 if ( Abc_ObjIsCi(pNode) )
00222 return 0;
00223 Abc_NodeSetTravIdCurrent( pNode );
00224 Abc_ObjForEachFanin( pNode, pFanin, i )
00225 {
00226 assert( pFanin->vFanouts.nSize > 0 );
00227 if ( --pFanin->vFanouts.nSize == 0 )
00228 Counter += Res_NodeDeref_rec( pFanin );
00229 }
00230 return Counter;
00231 }
00232
00244 int Res_NodeRef_rec( Abc_Obj_t * pNode )
00245 {
00246 Abc_Obj_t * pFanin;
00247 int i, Counter = 1;
00248 if ( Abc_ObjIsCi(pNode) )
00249 return 0;
00250 Abc_ObjForEachFanin( pNode, pFanin, i )
00251 {
00252 if ( pFanin->vFanouts.nSize++ == 0 )
00253 Counter += Res_NodeRef_rec( pFanin );
00254 }
00255 return Counter;
00256 }
00257
00269 int Res_WinVisitMffc( Abc_Obj_t * pNode )
00270 {
00271 int Count1, Count2;
00272 assert( Abc_ObjIsNode(pNode) );
00273
00274 Count1 = Res_NodeDeref_rec( pNode );
00275
00276 Count2 = Res_NodeRef_rec( pNode );
00277 assert( Count1 == Count2 );
00278 return Count1;
00279 }
00280
00284
00285