abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
aigTiming.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [aigTiming.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [AIG package.]
8 
9  Synopsis [Incremental updating of direct/reverse AIG levels.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: aigTiming.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "aig.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Returns the reverse level of the node.]
37 
38  Description [The reverse level is the level of the node in reverse
39  topological order, starting from the COs.]
40 
41  SideEffects []
42 
43  SeeAlso []
44 
45 ***********************************************************************/
46 static inline int Aig_ObjReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObj )
47 {
48  assert( p->vLevelR );
49  Vec_IntFillExtra( p->vLevelR, pObj->Id + 1, 0 );
50  return Vec_IntEntry(p->vLevelR, pObj->Id);
51 }
52 
53 /**Function*************************************************************
54 
55  Synopsis [Sets the reverse level of the node.]
56 
57  Description [The reverse level is the level of the node in reverse
58  topological order, starting from the COs.]
59 
60  SideEffects []
61 
62  SeeAlso []
63 
64 ***********************************************************************/
65 static inline void Aig_ObjSetReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObj, int LevelR )
66 {
67  assert( p->vLevelR );
68  Vec_IntFillExtra( p->vLevelR, pObj->Id + 1, 0 );
69  Vec_IntWriteEntry( p->vLevelR, pObj->Id, LevelR );
70 }
71 
72 /**Function*************************************************************
73 
74  Synopsis [Resets reverse level of the node.]
75 
76  Description []
77 
78  SideEffects []
79 
80  SeeAlso []
81 
82 ***********************************************************************/
84 {
85  Aig_ObjSetReverseLevel( p, pObj, 0 );
86 }
87 
88 /**Function*************************************************************
89 
90  Synopsis [Returns required level of the node.]
91 
92  Description [Converts the reverse levels of the node into its required
93  level as follows: ReqLevel(Node) = MaxLevels(Ntk) + 1 - LevelR(Node).]
94 
95  SideEffects []
96 
97  SeeAlso []
98 
99 ***********************************************************************/
101 {
102  assert( p->vLevelR );
103  return p->nLevelMax + 1 - Aig_ObjReverseLevel(p, pObj);
104 }
105 
106 /**Function*************************************************************
107 
108  Synopsis [Computes the reverse level of the node using its fanout levels.]
109 
110  Description []
111 
112  SideEffects []
113 
114  SeeAlso []
115 
116 ***********************************************************************/
118 {
119  Aig_Obj_t * pFanout;
120  int i, iFanout = -1, LevelCur, Level = 0;
121  Aig_ObjForEachFanout( p, pObj, pFanout, iFanout, i )
122  {
123  LevelCur = Aig_ObjReverseLevel( p, pFanout );
124  Level = Abc_MaxInt( Level, LevelCur );
125  }
126  return Level + 1;
127 }
128 
129 /**Function*************************************************************
130 
131  Synopsis [Prepares for the computation of required levels.]
132 
133  Description [This procedure should be called before the required times
134  are used. It starts internal data structures, which records the level
135  from the COs of the network nodes in reverse topologogical order.]
136 
137  SideEffects []
138 
139  SeeAlso []
140 
141 ***********************************************************************/
142 void Aig_ManStartReverseLevels( Aig_Man_t * p, int nMaxLevelIncrease )
143 {
144  Vec_Ptr_t * vNodes;
145  Aig_Obj_t * pObj;
146  int i;
147  assert( p->pFanData != NULL );
148  assert( p->vLevelR == NULL );
149  // remember the maximum number of direct levels
150  p->nLevelMax = Aig_ManLevels(p) + nMaxLevelIncrease;
151  // start the reverse levels
152  p->vLevelR = Vec_IntAlloc( 0 );
153  Vec_IntFill( p->vLevelR, Aig_ManObjNumMax(p), 0 );
154  // compute levels in reverse topological order
155  vNodes = Aig_ManDfsReverse( p );
156  Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj, i )
157  {
158  assert( pObj->fMarkA == 0 );
159  Aig_ObjSetReverseLevel( p, pObj, Aig_ObjReverseLevelNew(p, pObj) );
160  }
161  Vec_PtrFree( vNodes );
162 }
163 
164 /**Function*************************************************************
165 
166  Synopsis [Cleans the data structures used to compute required levels.]
167 
168  Description []
169 
170  SideEffects []
171 
172  SeeAlso []
173 
174 ***********************************************************************/
176 {
177  assert( p->vLevelR != NULL );
178  Vec_IntFree( p->vLevelR );
179  p->vLevelR = NULL;
180  p->nLevelMax = 0;
181 
182 }
183 
184 /**Function*************************************************************
185 
186  Synopsis [Incrementally updates level of the nodes.]
187 
188  Description []
189 
190  SideEffects []
191 
192  SeeAlso []
193 
194 ***********************************************************************/
196 {
197  Aig_Obj_t * pFanout, * pTemp;
198  int iFanout = -1, LevelOld, Lev, k, m;
199  assert( p->pFanData != NULL );
200  assert( Aig_ObjIsNode(pObjNew) );
201  // allocate level if needed
202  if ( p->vLevels == NULL )
203  p->vLevels = Vec_VecAlloc( Aig_ManLevels(p) + 8 );
204  // check if level has changed
205  LevelOld = Aig_ObjLevel(pObjNew);
206  if ( LevelOld == Aig_ObjLevelNew(pObjNew) )
207  return;
208  // start the data structure for level update
209  // we cannot fail to visit a node when using this structure because the
210  // nodes are stored by their _old_ levels, which are assumed to be correct
211  Vec_VecClear( p->vLevels );
212  Vec_VecPush( p->vLevels, LevelOld, pObjNew );
213  pObjNew->fMarkA = 1;
214  // recursively update level
215  Vec_VecForEachEntryStart( Aig_Obj_t *, p->vLevels, pTemp, Lev, k, LevelOld )
216  {
217  pTemp->fMarkA = 0;
218  assert( Aig_ObjLevel(pTemp) == Lev );
219  pTemp->Level = Aig_ObjLevelNew(pTemp);
220  // if the level did not change, no need to check the fanout levels
221  if ( Aig_ObjLevel(pTemp) == Lev )
222  continue;
223  // schedule fanout for level update
224  Aig_ObjForEachFanout( p, pTemp, pFanout, iFanout, m )
225  {
226  if ( Aig_ObjIsNode(pFanout) && !pFanout->fMarkA )
227  {
228  assert( Aig_ObjLevel(pFanout) >= Lev );
229  Vec_VecPush( p->vLevels, Aig_ObjLevel(pFanout), pFanout );
230  pFanout->fMarkA = 1;
231  }
232  }
233  }
234 }
235 
236 /**Function*************************************************************
237 
238  Synopsis [Incrementally updates level of the nodes.]
239 
240  Description []
241 
242  SideEffects []
243 
244  SeeAlso []
245 
246 ***********************************************************************/
248 {
249  Aig_Obj_t * pFanin, * pTemp;
250  int LevelOld, LevFanin, Lev, k;
251  assert( p->vLevelR != NULL );
252  assert( Aig_ObjIsNode(pObjNew) );
253  // allocate level if needed
254  if ( p->vLevels == NULL )
255  p->vLevels = Vec_VecAlloc( Aig_ManLevels(p) + 8 );
256  // check if level has changed
257  LevelOld = Aig_ObjReverseLevel(p, pObjNew);
258  if ( LevelOld == Aig_ObjReverseLevelNew(p, pObjNew) )
259  return;
260  // start the data structure for level update
261  // we cannot fail to visit a node when using this structure because the
262  // nodes are stored by their _old_ levels, which are assumed to be correct
263  Vec_VecClear( p->vLevels );
264  Vec_VecPush( p->vLevels, LevelOld, pObjNew );
265  pObjNew->fMarkA = 1;
266  // recursively update level
267  Vec_VecForEachEntryStart( Aig_Obj_t *, p->vLevels, pTemp, Lev, k, LevelOld )
268  {
269  pTemp->fMarkA = 0;
270  LevelOld = Aig_ObjReverseLevel(p, pTemp);
271  assert( LevelOld == Lev );
272  Aig_ObjSetReverseLevel( p, pTemp, Aig_ObjReverseLevelNew(p, pTemp) );
273  // if the level did not change, to need to check the fanout levels
274  if ( Aig_ObjReverseLevel(p, pTemp) == Lev )
275  continue;
276  // schedule fanins for level update
277  pFanin = Aig_ObjFanin0(pTemp);
278  if ( Aig_ObjIsNode(pFanin) && !pFanin->fMarkA )
279  {
280  LevFanin = Aig_ObjReverseLevel( p, pFanin );
281  assert( LevFanin >= Lev );
282  Vec_VecPush( p->vLevels, LevFanin, pFanin );
283  pFanin->fMarkA = 1;
284  }
285  pFanin = Aig_ObjFanin1(pTemp);
286  if ( Aig_ObjIsNode(pFanin) && !pFanin->fMarkA )
287  {
288  LevFanin = Aig_ObjReverseLevel( p, pFanin );
289  assert( LevFanin >= Lev );
290  Vec_VecPush( p->vLevels, LevFanin, pFanin );
291  pFanin->fMarkA = 1;
292  }
293  }
294 }
295 
296 /**Function*************************************************************
297 
298  Synopsis [Verifies direct level of the nodes.]
299 
300  Description []
301 
302  SideEffects []
303 
304  SeeAlso []
305 
306 ***********************************************************************/
308 {
309  Aig_Obj_t * pObj;
310  int i, Counter = 0;
311  assert( p->pFanData );
312  Aig_ManForEachNode( p, pObj, i )
313  if ( Aig_ObjLevel(pObj) != Aig_ObjLevelNew(pObj) )
314  {
315  printf( "Level of node %6d should be %4d instead of %4d.\n",
316  pObj->Id, Aig_ObjLevelNew(pObj), Aig_ObjLevel(pObj) );
317  Counter++;
318  }
319  if ( Counter )
320  printf( "Levels of %d nodes are incorrect.\n", Counter );
321 }
322 
323 /**Function*************************************************************
324 
325  Synopsis [Verifies reverse level of the nodes.]
326 
327  Description []
328 
329  SideEffects []
330 
331  SeeAlso []
332 
333 ***********************************************************************/
335 {
336  Aig_Obj_t * pObj;
337  int i, Counter = 0;
338  assert( p->vLevelR );
339  Aig_ManForEachNode( p, pObj, i )
340  if ( Aig_ObjLevel(pObj) != Aig_ObjLevelNew(pObj) )
341  {
342  printf( "Reverse level of node %6d should be %4d instead of %4d.\n",
343  pObj->Id, Aig_ObjReverseLevelNew(p, pObj), Aig_ObjReverseLevel(p, pObj) );
344  Counter++;
345  }
346  if ( Counter )
347  printf( "Reverse levels of %d nodes are incorrect.\n", Counter );
348 }
349 
350 ////////////////////////////////////////////////////////////////////////
351 /// END OF FILE ///
352 ////////////////////////////////////////////////////////////////////////
353 
354 
356 
#define Aig_ObjForEachFanout(p, pObj, pFanout, iFan, i)
Definition: aig.h:427
static int Aig_ObjLevelNew(Aig_Obj_t *pObj)
Definition: aig.h:324
void Aig_ManUpdateLevel(Aig_Man_t *p, Aig_Obj_t *pObjNew)
Definition: aigTiming.c:195
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
unsigned Level
Definition: aig.h:82
static void Vec_VecPush(Vec_Vec_t *p, int Level, void *Entry)
Definition: vecVec.h:456
static Vec_Vec_t * Vec_VecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecVec.h:145
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_IntFillExtra(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:376
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
void Aig_ManStartReverseLevels(Aig_Man_t *p, int nMaxLevelIncrease)
Definition: aigTiming.c:142
unsigned int fMarkA
Definition: aig.h:79
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
static void Vec_VecClear(Vec_Vec_t *p)
Definition: vecVec.h:437
void Aig_ObjClearReverseLevel(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aigTiming.c:83
void Aig_ManVerifyReverseLevel(Aig_Man_t *p)
Definition: aigTiming.c:334
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
int Aig_ObjReverseLevelNew(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aigTiming.c:117
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
static ABC_NAMESPACE_IMPL_START int Aig_ObjReverseLevel(Aig_Man_t *p, Aig_Obj_t *pObj)
DECLARATIONS ///.
Definition: aigTiming.c:46
Definition: aig.h:69
static int Counter
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
Vec_Ptr_t * Aig_ManDfsReverse(Aig_Man_t *p)
Definition: aigDfs.c:458
#define Vec_VecForEachEntryStart(Type, vGlob, pEntry, i, k, LevelStart)
Definition: vecVec.h:92
void Aig_ManStopReverseLevels(Aig_Man_t *p)
Definition: aigTiming.c:175
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Aig_ManUpdateReverseLevel(Aig_Man_t *p, Aig_Obj_t *pObjNew)
Definition: aigTiming.c:247
static void Aig_ObjSetReverseLevel(Aig_Man_t *p, Aig_Obj_t *pObj, int LevelR)
Definition: aigTiming.c:65
static int Aig_ObjLevel(Aig_Obj_t *pObj)
Definition: aig.h:323
#define assert(ex)
Definition: util_old.h:213
int Aig_ObjRequiredLevel(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aigTiming.c:100
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Aig_ManVerifyLevel(Aig_Man_t *p)
Definition: aigTiming.c:307
int Aig_ManLevels(Aig_Man_t *p)
Definition: aigUtil.c:102
int Id
Definition: aig.h:85
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223