00001
00021 #include "aig.h"
00022
00026
00030
00043 static inline int Aig_ObjReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObj )
00044 {
00045 assert( p->vLevelR );
00046 Vec_IntFillExtra( p->vLevelR, pObj->Id + 1, 0 );
00047 return Vec_IntEntry(p->vLevelR, pObj->Id);
00048 }
00049
00062 static inline void Aig_ObjSetReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObj, int LevelR )
00063 {
00064 assert( p->vLevelR );
00065 Vec_IntFillExtra( p->vLevelR, pObj->Id + 1, 0 );
00066 Vec_IntWriteEntry( p->vLevelR, pObj->Id, LevelR );
00067 }
00068
00080 void Aig_ObjClearReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObj )
00081 {
00082 Aig_ObjSetReverseLevel( p, pObj, 0 );
00083 }
00084
00097 int Aig_ObjRequiredLevel( Aig_Man_t * p, Aig_Obj_t * pObj )
00098 {
00099 assert( p->vLevelR );
00100 return p->nLevelMax + 1 - Aig_ObjReverseLevel(p, pObj);
00101 }
00102
00114 int Aig_ObjReverseLevelNew( Aig_Man_t * p, Aig_Obj_t * pObj )
00115 {
00116 Aig_Obj_t * pFanout;
00117 int i, iFanout = -1, LevelCur, Level = 0;
00118 Aig_ObjForEachFanout( p, pObj, pFanout, iFanout, i )
00119 {
00120 LevelCur = Aig_ObjReverseLevel( p, pFanout );
00121 Level = AIG_MAX( Level, LevelCur );
00122 }
00123 return Level + 1;
00124 }
00125
00139 void Aig_ManStartReverseLevels( Aig_Man_t * p, int nMaxLevelIncrease )
00140 {
00141 Vec_Ptr_t * vNodes;
00142 Aig_Obj_t * pObj;
00143 int i;
00144 assert( p->pFanData != NULL );
00145 assert( p->vLevelR == NULL );
00146
00147 p->nLevelMax = Aig_ManLevels(p) + nMaxLevelIncrease;
00148
00149 p->vLevelR = Vec_IntAlloc( 0 );
00150 Vec_IntFill( p->vLevelR, Aig_ManObjNumMax(p), 0 );
00151
00152 vNodes = Aig_ManDfsReverse( p );
00153 Vec_PtrForEachEntry( vNodes, pObj, i )
00154 {
00155 assert( pObj->fMarkA == 0 );
00156 Aig_ObjSetReverseLevel( p, pObj, Aig_ObjReverseLevelNew(p, pObj) );
00157 }
00158 Vec_PtrFree( vNodes );
00159 }
00160
00172 void Aig_ManStopReverseLevels( Aig_Man_t * p )
00173 {
00174 assert( p->vLevelR != NULL );
00175 Vec_IntFree( p->vLevelR );
00176 p->vLevelR = NULL;
00177 p->nLevelMax = 0;
00178
00179 }
00180
00192 void Aig_ManUpdateLevel( Aig_Man_t * p, Aig_Obj_t * pObjNew )
00193 {
00194 Aig_Obj_t * pFanout, * pTemp;
00195 int iFanout = -1, LevelOld, Lev, k, m;
00196 assert( p->pFanData != NULL );
00197 assert( Aig_ObjIsNode(pObjNew) );
00198
00199 if ( p->vLevels == NULL )
00200 p->vLevels = Vec_VecAlloc( Aig_ManLevels(p) + 8 );
00201
00202 LevelOld = Aig_ObjLevel(pObjNew);
00203 if ( LevelOld == Aig_ObjLevelNew(pObjNew) )
00204 return;
00205
00206
00207
00208 Vec_VecClear( p->vLevels );
00209 Vec_VecPush( p->vLevels, LevelOld, pObjNew );
00210 pObjNew->fMarkA = 1;
00211
00212 Vec_VecForEachEntryStart( p->vLevels, pTemp, Lev, k, LevelOld )
00213 {
00214 pTemp->fMarkA = 0;
00215 assert( Aig_ObjLevel(pTemp) == Lev );
00216 pTemp->Level = Aig_ObjLevelNew(pTemp);
00217
00218 if ( Aig_ObjLevel(pTemp) == Lev )
00219 continue;
00220
00221 Aig_ObjForEachFanout( p, pTemp, pFanout, iFanout, m )
00222 {
00223 if ( Aig_ObjIsNode(pFanout) && !pFanout->fMarkA )
00224 {
00225 assert( Aig_ObjLevel(pFanout) >= Lev );
00226 Vec_VecPush( p->vLevels, Aig_ObjLevel(pFanout), pFanout );
00227 pFanout->fMarkA = 1;
00228 }
00229 }
00230 }
00231 }
00232
00244 void Aig_ManUpdateReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObjNew )
00245 {
00246 Aig_Obj_t * pFanin, * pTemp;
00247 int LevelOld, LevFanin, Lev, k;
00248 assert( p->vLevelR != NULL );
00249 assert( Aig_ObjIsNode(pObjNew) );
00250
00251 if ( p->vLevels == NULL )
00252 p->vLevels = Vec_VecAlloc( Aig_ManLevels(p) + 8 );
00253
00254 LevelOld = Aig_ObjReverseLevel(p, pObjNew);
00255 if ( LevelOld == Aig_ObjReverseLevelNew(p, pObjNew) )
00256 return;
00257
00258
00259
00260 Vec_VecClear( p->vLevels );
00261 Vec_VecPush( p->vLevels, LevelOld, pObjNew );
00262 pObjNew->fMarkA = 1;
00263
00264 Vec_VecForEachEntryStart( p->vLevels, pTemp, Lev, k, LevelOld )
00265 {
00266 pTemp->fMarkA = 0;
00267 LevelOld = Aig_ObjReverseLevel(p, pTemp);
00268 assert( LevelOld == Lev );
00269 Aig_ObjSetReverseLevel( p, pTemp, Aig_ObjReverseLevelNew(p, pTemp) );
00270
00271 if ( Aig_ObjReverseLevel(p, pTemp) == Lev )
00272 continue;
00273
00274 pFanin = Aig_ObjFanin0(pTemp);
00275 if ( Aig_ObjIsNode(pFanin) && !pFanin->fMarkA )
00276 {
00277 LevFanin = Aig_ObjReverseLevel( p, pFanin );
00278 assert( LevFanin >= Lev );
00279 Vec_VecPush( p->vLevels, LevFanin, pFanin );
00280 pFanin->fMarkA = 1;
00281 }
00282 pFanin = Aig_ObjFanin1(pTemp);
00283 if ( Aig_ObjIsNode(pFanin) && !pFanin->fMarkA )
00284 {
00285 LevFanin = Aig_ObjReverseLevel( p, pFanin );
00286 assert( LevFanin >= Lev );
00287 Vec_VecPush( p->vLevels, LevFanin, pFanin );
00288 pFanin->fMarkA = 1;
00289 }
00290 }
00291 }
00292
00304 void Aig_ManVerifyLevel( Aig_Man_t * p )
00305 {
00306 Aig_Obj_t * pObj;
00307 int i, Counter = 0;
00308 assert( p->pFanData );
00309 Aig_ManForEachNode( p, pObj, i )
00310 if ( Aig_ObjLevel(pObj) != Aig_ObjLevelNew(pObj) )
00311 {
00312 printf( "Level of node %6d should be %4d instead of %4d.\n",
00313 pObj->Id, Aig_ObjLevelNew(pObj), Aig_ObjLevel(pObj) );
00314 Counter++;
00315 }
00316 if ( Counter )
00317 printf( "Levels of %d nodes are incorrect.\n", Counter );
00318 }
00319
00331 void Aig_ManVerifyReverseLevel( Aig_Man_t * p )
00332 {
00333 Aig_Obj_t * pObj;
00334 int i, Counter = 0;
00335 assert( p->vLevelR );
00336 Aig_ManForEachNode( p, pObj, i )
00337 if ( Aig_ObjLevel(pObj) != Aig_ObjLevelNew(pObj) )
00338 {
00339 printf( "Reverse level of node %6d should be %4d instead of %4d.\n",
00340 pObj->Id, Aig_ObjReverseLevelNew(p, pObj), Aig_ObjReverseLevel(p, pObj) );
00341 Counter++;
00342 }
00343 if ( Counter )
00344 printf( "Reverse levels of %d nodes are incorrect.\n", Counter );
00345 }
00346
00350
00351