abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcTiming.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcTiming.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Computation of timing info for mapped circuits.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcTiming.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "base/main/main.h"
23 #include "map/mio/mio.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
33 {
42 };
43 
44 // static functions
45 static Abc_ManTime_t * Abc_ManTimeStart( Abc_Ntk_t * pNtk );
46 static void Abc_ManTimeExpand( Abc_ManTime_t * p, int nSize, int fProgressive );
47 
48 // accessing the arrival and required times of a node
49 static inline Abc_Time_t * Abc_NodeArrival( Abc_Obj_t * pNode ) { return (Abc_Time_t *)pNode->pNtk->pManTime->vArrs->pArray[pNode->Id]; }
50 static inline Abc_Time_t * Abc_NodeRequired( Abc_Obj_t * pNode ) { return (Abc_Time_t *)pNode->pNtk->pManTime->vReqs->pArray[pNode->Id]; }
51 
52 ////////////////////////////////////////////////////////////////////////
53 /// FUNCTION DEFINITIONS ///
54 ////////////////////////////////////////////////////////////////////////
55 
56 /**Function*************************************************************
57 
58  Synopsis [Reads the arrival.required time of the node.]
59 
60  Description []
61 
62  SideEffects []
63 
64  SeeAlso []
65 
66 ***********************************************************************/
68 {
69  assert( pNtk->pManTime );
70  return &pNtk->pManTime->tArrDef;
71 }
73 {
74  assert( pNtk->pManTime );
75  return &pNtk->pManTime->tReqDef;
76 }
78 {
79  assert( pNode->pNtk->pManTime );
80  return Abc_NodeArrival(pNode);
81 }
83 {
84  assert( pNode->pNtk->pManTime );
85  return Abc_NodeRequired(pNode);
86 }
88 {
89  return 0.5 * Abc_NodeArrival(pNode)->Rise + 0.5 * Abc_NodeArrival(pNode)->Fall;
90 }
92 {
93  return 0.5 * Abc_NodeReadRequired(pNode)->Rise + 0.5 * Abc_NodeReadRequired(pNode)->Fall;
94 }
96 {
97  return Abc_MaxFloat( Abc_NodeArrival(pNode)->Rise, Abc_NodeArrival(pNode)->Fall );
98 }
100 {
101  return Abc_MaxFloat( Abc_NodeReadRequired(pNode)->Rise, Abc_NodeReadRequired(pNode)->Fall );
102 }
103 
104 /**Function*************************************************************
105 
106  Synopsis [Reads the input drive / output load of the node.]
107 
108  Description []
109 
110  SideEffects []
111 
112  SeeAlso []
113 
114 ***********************************************************************/
116 {
117  assert( pNtk->pManTime );
118  return &pNtk->pManTime->tInDriveDef;
119 }
121 {
122  assert( pNtk->pManTime );
123  return &pNtk->pManTime->tOutLoadDef;
124 }
126 {
127  assert( pNtk->pManTime );
128  return pNtk->pManTime->tInDrive ? pNtk->pManTime->tInDrive + iPi : NULL;
129 }
131 {
132  assert( pNtk->pManTime );
133  return pNtk->pManTime->tOutLoad ? pNtk->pManTime->tOutLoad + iPo : NULL;
134 }
135 float Abc_NodeReadInputDriveWorst( Abc_Ntk_t * pNtk, int iPi )
136 {
137  return Abc_MaxFloat( Abc_NodeReadInputDrive(pNtk, iPi)->Rise, Abc_NodeReadInputDrive(pNtk, iPi)->Fall );
138 }
139 float Abc_NodeReadOutputLoadWorst( Abc_Ntk_t * pNtk, int iPo )
140 {
141  return Abc_MaxFloat( Abc_NodeReadOutputLoad(pNtk, iPo)->Rise, Abc_NodeReadOutputLoad(pNtk, iPo)->Fall );
142 }
143 
144 /**Function*************************************************************
145 
146  Synopsis [Sets the default arrival time for the network.]
147 
148  Description []
149 
150  SideEffects []
151 
152  SeeAlso []
153 
154 ***********************************************************************/
155 void Abc_NtkTimeSetDefaultArrival( Abc_Ntk_t * pNtk, float Rise, float Fall )
156 {
157  if ( Rise == 0.0 && Fall == 0.0 )
158  return;
159  if ( pNtk->pManTime == NULL )
160  pNtk->pManTime = Abc_ManTimeStart(pNtk);
161  pNtk->pManTime->tArrDef.Rise = Rise;
162  pNtk->pManTime->tArrDef.Fall = Fall;
163 }
164 void Abc_NtkTimeSetDefaultRequired( Abc_Ntk_t * pNtk, float Rise, float Fall )
165 {
166  if ( Rise == 0.0 && Fall == 0.0 )
167  return;
168  if ( pNtk->pManTime == NULL )
169  pNtk->pManTime = Abc_ManTimeStart(pNtk);
170  pNtk->pManTime->tReqDef.Rise = Rise;
171  pNtk->pManTime->tReqDef.Fall = Fall;
172 }
173 
174 /**Function*************************************************************
175 
176  Synopsis [Sets the arrival time for an object.]
177 
178  Description []
179 
180  SideEffects []
181 
182  SeeAlso []
183 
184 ***********************************************************************/
185 void Abc_NtkTimeSetArrival( Abc_Ntk_t * pNtk, int ObjId, float Rise, float Fall )
186 {
187  Vec_Ptr_t * vTimes;
188  Abc_Time_t * pTime;
189  if ( pNtk->pManTime == NULL )
190  pNtk->pManTime = Abc_ManTimeStart(pNtk);
191  if ( pNtk->pManTime->tArrDef.Rise == Rise && pNtk->pManTime->tArrDef.Fall == Fall )
192  return;
193  Abc_ManTimeExpand( pNtk->pManTime, ObjId + 1, 1 );
194  // set the arrival time
195  vTimes = pNtk->pManTime->vArrs;
196  pTime = (Abc_Time_t *)vTimes->pArray[ObjId];
197  pTime->Rise = Rise;
198  pTime->Fall = Fall;
199 }
200 void Abc_NtkTimeSetRequired( Abc_Ntk_t * pNtk, int ObjId, float Rise, float Fall )
201 {
202  Vec_Ptr_t * vTimes;
203  Abc_Time_t * pTime;
204  if ( pNtk->pManTime == NULL )
205  pNtk->pManTime = Abc_ManTimeStart(pNtk);
206  if ( pNtk->pManTime->tReqDef.Rise == Rise && pNtk->pManTime->tReqDef.Fall == Fall )
207  return;
208  Abc_ManTimeExpand( pNtk->pManTime, ObjId + 1, 1 );
209  // set the required time
210  vTimes = pNtk->pManTime->vReqs;
211  pTime = (Abc_Time_t *)vTimes->pArray[ObjId];
212  pTime->Rise = Rise;
213  pTime->Fall = Fall;
214 }
215 
216 /**Function*************************************************************
217 
218  Synopsis [Sets the default arrival time for the network.]
219 
220  Description []
221 
222  SideEffects []
223 
224  SeeAlso []
225 
226 ***********************************************************************/
227 void Abc_NtkTimeSetDefaultInputDrive( Abc_Ntk_t * pNtk, float Rise, float Fall )
228 {
229  if ( Rise == 0.0 && Fall == 0.0 )
230  return;
231  if ( pNtk->pManTime == NULL )
232  pNtk->pManTime = Abc_ManTimeStart(pNtk);
233  pNtk->pManTime->tInDriveDef.Rise = Rise;
234  pNtk->pManTime->tInDriveDef.Fall = Fall;
235  if ( pNtk->pManTime->tInDrive != NULL )
236  {
237  int i;
238  for ( i = 0; i < Abc_NtkCiNum(pNtk); i++ )
239  if ( pNtk->pManTime->tInDrive[i].Rise == 0 && pNtk->pManTime->tInDrive[i].Fall == 0 )
240  pNtk->pManTime->tInDrive[i] = pNtk->pManTime->tInDriveDef;
241  }
242 }
243 void Abc_NtkTimeSetDefaultOutputLoad( Abc_Ntk_t * pNtk, float Rise, float Fall )
244 {
245  if ( Rise == 0.0 && Fall == 0.0 )
246  return;
247  if ( pNtk->pManTime == NULL )
248  pNtk->pManTime = Abc_ManTimeStart(pNtk);
249  pNtk->pManTime->tOutLoadDef.Rise = Rise;
250  pNtk->pManTime->tOutLoadDef.Fall = Fall;
251  if ( pNtk->pManTime->tOutLoad != NULL )
252  {
253  int i;
254  for ( i = 0; i < Abc_NtkCoNum(pNtk); i++ )
255  if ( pNtk->pManTime->tOutLoad[i].Rise == 0 && pNtk->pManTime->tOutLoad[i].Fall == 0 )
256  pNtk->pManTime->tOutLoad[i] = pNtk->pManTime->tOutLoadDef;
257  }
258 }
259 
260 /**Function*************************************************************
261 
262  Synopsis [Sets the arrival time for an object.]
263 
264  Description []
265 
266  SideEffects []
267 
268  SeeAlso []
269 
270 ***********************************************************************/
271 void Abc_NtkTimeSetInputDrive( Abc_Ntk_t * pNtk, int PiNum, float Rise, float Fall )
272 {
273  Abc_Time_t * pTime;
274  assert( PiNum >= 0 && PiNum < Abc_NtkCiNum(pNtk) );
275  if ( pNtk->pManTime == NULL )
276  pNtk->pManTime = Abc_ManTimeStart(pNtk);
277  if ( pNtk->pManTime->tInDriveDef.Rise == Rise && pNtk->pManTime->tInDriveDef.Fall == Fall )
278  return;
279  if ( pNtk->pManTime->tInDrive == NULL )
280  {
281  int i;
283  for ( i = 0; i < Abc_NtkCiNum(pNtk); i++ )
284  pNtk->pManTime->tInDrive[i] = pNtk->pManTime->tInDriveDef;
285  }
286  pTime = pNtk->pManTime->tInDrive + PiNum;
287  pTime->Rise = Rise;
288  pTime->Fall = Fall;
289 }
290 void Abc_NtkTimeSetOutputLoad( Abc_Ntk_t * pNtk, int PoNum, float Rise, float Fall )
291 {
292  Abc_Time_t * pTime;
293  assert( PoNum >= 0 && PoNum < Abc_NtkCoNum(pNtk) );
294  if ( pNtk->pManTime == NULL )
295  pNtk->pManTime = Abc_ManTimeStart(pNtk);
296  if ( pNtk->pManTime->tOutLoadDef.Rise == Rise && pNtk->pManTime->tOutLoadDef.Fall == Fall )
297  return;
298  if ( pNtk->pManTime->tOutLoad == NULL )
299  {
300  int i;
302  for ( i = 0; i < Abc_NtkCoNum(pNtk); i++ )
303  pNtk->pManTime->tOutLoad[i] = pNtk->pManTime->tOutLoadDef;
304  }
305  pTime = pNtk->pManTime->tOutLoad + PoNum;
306  pTime->Rise = Rise;
307  pTime->Fall = Fall;
308 }
309 
310 /**Function*************************************************************
311 
312  Synopsis [Finalizes the timing manager after setting arr/req times.]
313 
314  Description []
315 
316  SideEffects []
317 
318  SeeAlso []
319 
320 ***********************************************************************/
321 void Abc_NtkTimeInitialize( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkOld )
322 {
323  Abc_Obj_t * pObj;
324  Abc_Time_t ** ppTimes, * pTime;
325  int i;
326  assert( pNtkOld == NULL || pNtkOld->pManTime != NULL );
327  assert( pNtkOld == NULL || Abc_NtkCiNum(pNtk) == Abc_NtkCiNum(pNtkOld) );
328  assert( pNtkOld == NULL || Abc_NtkCoNum(pNtk) == Abc_NtkCoNum(pNtkOld) );
329  if ( pNtk->pManTime == NULL )
330  return;
331  Abc_ManTimeExpand( pNtk->pManTime, Abc_NtkObjNumMax(pNtk), 0 );
332  // set global defaults
333  if ( pNtkOld )
334  {
335  pNtk->pManTime->tArrDef = pNtkOld->pManTime->tArrDef;
336  pNtk->pManTime->tReqDef = pNtkOld->pManTime->tReqDef;
337  pNtk->AndGateDelay = pNtkOld->AndGateDelay;
338  }
339  // set the default timing
340  ppTimes = (Abc_Time_t **)pNtk->pManTime->vArrs->pArray;
341  Abc_NtkForEachCi( pNtk, pObj, i )
342  {
343  pTime = ppTimes[pObj->Id];
344  if ( Abc_MaxFloat(pTime->Fall, pTime->Rise) != -ABC_INFINITY )
345  continue;
346  *pTime = pNtkOld ? *Abc_NodeReadArrival(Abc_NtkCi(pNtkOld, i)) : pNtk->pManTime->tArrDef;
347  }
348  // set the default timing
349  ppTimes = (Abc_Time_t **)pNtk->pManTime->vReqs->pArray;
350  Abc_NtkForEachCo( pNtk, pObj, i )
351  {
352  pTime = ppTimes[pObj->Id];
353  if ( Abc_MaxFloat(pTime->Fall, pTime->Rise) != ABC_INFINITY )
354  continue;
355  *pTime = pNtkOld ? *Abc_NodeReadRequired(Abc_NtkCo(pNtkOld, i)) : pNtk->pManTime->tReqDef;
356  }
357  // set the 0 arrival times for latch outputs and constant nodes
358  ppTimes = (Abc_Time_t **)pNtk->pManTime->vArrs->pArray;
359  Abc_NtkForEachLatchOutput( pNtk, pObj, i )
360  {
361  pTime = ppTimes[pObj->Id];
362  pTime->Fall = pTime->Rise = 0.0;
363  }
364 }
365 
366 /**Function*************************************************************
367 
368  Synopsis [Prepares the timing manager for delay trace.]
369 
370  Description []
371 
372  SideEffects []
373 
374  SeeAlso []
375 
376 ***********************************************************************/
378 {
379  Abc_Obj_t * pObj;
380  Abc_Time_t ** ppTimes, * pTime;
381  int i;
382  // if there is no timing manager, allocate and initialize
383  if ( pNtk->pManTime == NULL )
384  {
385  pNtk->pManTime = Abc_ManTimeStart(pNtk);
386  Abc_NtkTimeInitialize( pNtk, NULL );
387  return;
388  }
389  // if timing manager is given, expand it if necessary
390  Abc_ManTimeExpand( pNtk->pManTime, Abc_NtkObjNumMax(pNtk), 0 );
391  // clean arrivals except for PIs
392  ppTimes = (Abc_Time_t **)pNtk->pManTime->vArrs->pArray;
393  Abc_NtkForEachNode( pNtk, pObj, i )
394  {
395  pTime = ppTimes[pObj->Id];
396  pTime->Fall = pTime->Rise = -ABC_INFINITY;
397  }
398  Abc_NtkForEachCo( pNtk, pObj, i )
399  {
400  pTime = ppTimes[pObj->Id];
401  pTime->Fall = pTime->Rise = -ABC_INFINITY;
402  }
403  // clean required except for POs
404  ppTimes = (Abc_Time_t **)pNtk->pManTime->vReqs->pArray;
405  Abc_NtkForEachNode( pNtk, pObj, i )
406  {
407  pTime = ppTimes[pObj->Id];
408  pTime->Fall = pTime->Rise = ABC_INFINITY;
409  }
410  Abc_NtkForEachCi( pNtk, pObj, i )
411  {
412  pTime = ppTimes[pObj->Id];
413  pTime->Fall = pTime->Rise = ABC_INFINITY;
414  }
415 }
416 
417 
418 
419 
420 /**Function*************************************************************
421 
422  Synopsis []
423 
424  Description []
425 
426  SideEffects []
427 
428  SeeAlso []
429 
430 ***********************************************************************/
432 {
433  Abc_ManTime_t * p;
434  p = ABC_ALLOC( Abc_ManTime_t, 1 );
435  memset( p, 0, sizeof(Abc_ManTime_t) );
436  p->vArrs = Vec_PtrAlloc( 0 );
437  p->vReqs = Vec_PtrAlloc( 0 );
440  Abc_ManTimeExpand( p, Abc_NtkObjNumMax(pNtk) + 1, 0 );
441  return p;
442 }
443 
444 /**Function*************************************************************
445 
446  Synopsis []
447 
448  Description []
449 
450  SideEffects []
451 
452  SeeAlso []
453 
454 ***********************************************************************/
456 {
457  if ( p->tInDrive )
458  ABC_FREE( p->tInDrive );
459  if ( p->tOutLoad )
460  ABC_FREE( p->tOutLoad );
461  if ( Vec_PtrSize(p->vArrs) > 0 )
462  ABC_FREE( p->vArrs->pArray[0] );
463  Vec_PtrFree( p->vArrs );
464  if ( Vec_PtrSize(p->vReqs) > 0 )
465  ABC_FREE( p->vReqs->pArray[0] );
466  Vec_PtrFree( p->vReqs );
467  ABC_FREE( p );
468 }
469 
470 /**Function*************************************************************
471 
472  Synopsis [Duplicates the timing manager with the PI/PO timing info.]
473 
474  Description [The PIs/POs of the new network should be allocated.]
475 
476  SideEffects []
477 
478  SeeAlso []
479 
480 ***********************************************************************/
481 void Abc_ManTimeDup( Abc_Ntk_t * pNtkOld, Abc_Ntk_t * pNtkNew )
482 {
483  Abc_Obj_t * pObj;
484  Abc_Time_t ** ppTimesOld, ** ppTimesNew;
485  int i;
486  if ( pNtkOld->pManTime == NULL )
487  return;
488  assert( Abc_NtkCiNum(pNtkOld) == Abc_NtkCiNum(pNtkNew) );
489  assert( Abc_NtkCoNum(pNtkOld) == Abc_NtkCoNum(pNtkNew) );
490  assert( Abc_NtkLatchNum(pNtkOld) == Abc_NtkLatchNum(pNtkNew) );
491  // create the new timing manager
492  pNtkNew->pManTime = Abc_ManTimeStart(pNtkNew);
493  Abc_ManTimeExpand( pNtkNew->pManTime, Abc_NtkObjNumMax(pNtkNew), 0 );
494  // set the default timing
495  pNtkNew->pManTime->tArrDef = pNtkOld->pManTime->tArrDef;
496  pNtkNew->pManTime->tReqDef = pNtkOld->pManTime->tReqDef;
497  // set the CI timing
498  ppTimesOld = (Abc_Time_t **)pNtkOld->pManTime->vArrs->pArray;
499  ppTimesNew = (Abc_Time_t **)pNtkNew->pManTime->vArrs->pArray;
500  Abc_NtkForEachCi( pNtkOld, pObj, i )
501  *ppTimesNew[ Abc_NtkCi(pNtkNew,i)->Id ] = *ppTimesOld[ pObj->Id ];
502  // set the CO timing
503  ppTimesOld = (Abc_Time_t **)pNtkOld->pManTime->vReqs->pArray;
504  ppTimesNew = (Abc_Time_t **)pNtkNew->pManTime->vReqs->pArray;
505  Abc_NtkForEachCo( pNtkOld, pObj, i )
506  *ppTimesNew[ Abc_NtkCo(pNtkNew,i)->Id ] = *ppTimesOld[ pObj->Id ];
507  // duplicate input drive
508  pNtkNew->pManTime->tInDriveDef = pNtkOld->pManTime->tInDriveDef;
509  pNtkNew->pManTime->tOutLoadDef = pNtkOld->pManTime->tOutLoadDef;
510  if ( pNtkOld->pManTime->tInDrive )
511  {
512  pNtkNew->pManTime->tInDrive = ABC_ALLOC( Abc_Time_t, Abc_NtkCiNum(pNtkOld) );
513  memcpy( pNtkNew->pManTime->tInDrive, pNtkOld->pManTime->tInDrive, sizeof(Abc_Time_t) * Abc_NtkCiNum(pNtkOld) );
514  }
515  if ( pNtkOld->pManTime->tOutLoad )
516  {
517  pNtkNew->pManTime->tOutLoad = ABC_ALLOC( Abc_Time_t, Abc_NtkCiNum(pNtkOld) );
518  memcpy( pNtkNew->pManTime->tOutLoad, pNtkOld->pManTime->tOutLoad, sizeof(Abc_Time_t) * Abc_NtkCoNum(pNtkOld) );
519  }
520 }
521 
522 /**Function*************************************************************
523 
524  Synopsis [Expends the storage for timing information.]
525 
526  Description []
527 
528  SideEffects []
529 
530  SeeAlso []
531 
532 ***********************************************************************/
533 void Abc_ManTimeExpand( Abc_ManTime_t * p, int nSize, int fProgressive )
534 {
535  Vec_Ptr_t * vTimes;
536  Abc_Time_t * ppTimes, * ppTimesOld, * pTime;
537  int nSizeOld, nSizeNew, i;
538 
539  nSizeOld = p->vArrs->nSize;
540  if ( nSizeOld >= nSize )
541  return;
542  nSizeNew = fProgressive? 2 * nSize : nSize;
543  if ( nSizeNew < 100 )
544  nSizeNew = 100;
545 
546  vTimes = p->vArrs;
547  Vec_PtrGrow( vTimes, nSizeNew );
548  vTimes->nSize = nSizeNew;
549  ppTimesOld = ( nSizeOld == 0 )? NULL : (Abc_Time_t *)vTimes->pArray[0];
550  ppTimes = ABC_REALLOC( Abc_Time_t, ppTimesOld, nSizeNew );
551  for ( i = 0; i < nSizeNew; i++ )
552  vTimes->pArray[i] = ppTimes + i;
553  for ( i = nSizeOld; i < nSizeNew; i++ )
554  {
555  pTime = (Abc_Time_t *)vTimes->pArray[i];
556  pTime->Rise = -ABC_INFINITY;
557  pTime->Fall = -ABC_INFINITY;
558  }
559 
560  vTimes = p->vReqs;
561  Vec_PtrGrow( vTimes, nSizeNew );
562  vTimes->nSize = nSizeNew;
563  ppTimesOld = ( nSizeOld == 0 )? NULL : (Abc_Time_t *)vTimes->pArray[0];
564  ppTimes = ABC_REALLOC( Abc_Time_t, ppTimesOld, nSizeNew );
565  for ( i = 0; i < nSizeNew; i++ )
566  vTimes->pArray[i] = ppTimes + i;
567  for ( i = nSizeOld; i < nSizeNew; i++ )
568  {
569  pTime = (Abc_Time_t *)vTimes->pArray[i];
570  pTime->Rise = ABC_INFINITY;
571  pTime->Fall = ABC_INFINITY;
572  }
573 }
574 
575 
576 
577 
578 
579 
580 /**Function*************************************************************
581 
582  Synopsis [Sets the CI node levels according to the arrival info.]
583 
584  Description []
585 
586  SideEffects []
587 
588  SeeAlso []
589 
590 ***********************************************************************/
592 {
593  Abc_Obj_t * pNodeOld, * pNodeNew;
594  float tAndDelay;
595  int i;
596  if ( pNtkOld->pManTime == NULL )
597  return;
599  return;
601  Abc_NtkForEachCi( pNtkOld, pNodeOld, i )
602  {
603  pNodeNew = pNodeOld->pCopy;
604  pNodeNew->Level = (int)(Abc_NodeReadArrivalWorst(pNodeOld) / tAndDelay);
605  }
606 }
607 
608 /**Function*************************************************************
609 
610  Synopsis [Sets the CI node levels according to the arrival info.]
611 
612  Description []
613 
614  SideEffects []
615 
616  SeeAlso []
617 
618 ***********************************************************************/
620 {
621  Abc_Time_t * p;
622  Abc_Obj_t * pNode;
623  int i;
624  p = ABC_CALLOC( Abc_Time_t, Abc_NtkCiNum(pNtk) );
625  if ( pNtk->pManTime == NULL )
626  return p;
627  // set the PI arrival times
628  Abc_NtkForEachCi( pNtk, pNode, i )
629  p[i] = *Abc_NodeArrival(pNode);
630  return p;
631 }
633 {
634  Abc_Time_t * p;
635  Abc_Obj_t * pNode;
636  int i;
637  p = ABC_CALLOC( Abc_Time_t, Abc_NtkCoNum(pNtk) );
638  if ( pNtk->pManTime == NULL )
639  return p;
640  // set the PO required times
641  Abc_NtkForEachCo( pNtk, pNode, i )
642  p[i] = *Abc_NodeRequired(pNode);
643  return p;
644 }
645 
646 
647 /**Function*************************************************************
648 
649  Synopsis [Sets the CI node levels according to the arrival info.]
650 
651  Description []
652 
653  SideEffects []
654 
655  SeeAlso []
656 
657 ***********************************************************************/
659 {
660  float * p;
661  Abc_Obj_t * pNode;
662  int i;
663  p = ABC_CALLOC( float, Abc_NtkCiNum(pNtk) );
664  if ( pNtk->pManTime == NULL )
665  return p;
666  Abc_NtkForEachCi( pNtk, pNode, i )
667  if ( Abc_NodeReadArrivalWorst(pNode) != 0 )
668  break;
669  if ( i == Abc_NtkCiNum(pNtk) )
670  return NULL;
671  // set the PI arrival times
672  Abc_NtkForEachCi( pNtk, pNode, i )
673  p[i] = Abc_NodeReadArrivalWorst(pNode);
674  return p;
675 }
677 {
678  float * p;
679  Abc_Obj_t * pNode;
680  int i;
681  if ( pNtk->pManTime == NULL )
682  return NULL;
683  Abc_NtkForEachCo( pNtk, pNode, i )
684  if ( Abc_NodeReadRequiredWorst(pNode) != ABC_INFINITY )
685  break;
686  if ( i == Abc_NtkCoNum(pNtk) )
687  return NULL;
688  // set the PO required times
689  p = ABC_CALLOC( float, Abc_NtkCoNum(pNtk) );
690  Abc_NtkForEachCo( pNtk, pNode, i )
691  p[i] = Abc_NodeReadRequiredWorst(pNode);
692  return p;
693 }
694 
695 
696 /**Function*************************************************************
697 
698  Synopsis []
699 
700  Description []
701 
702  SideEffects []
703 
704  SeeAlso []
705 
706 ***********************************************************************/
708 {
709  Vec_Int_t * vSlacks;
710  Abc_Obj_t * pObj;
711  int i, k;
712  vSlacks = Vec_IntAlloc( Abc_NtkObjNumMax(pNtk) + Abc_NtkGetTotalFanins(pNtk) );
713  Vec_IntFill( vSlacks, Abc_NtkObjNumMax(pNtk), -1 );
714  Abc_NtkForEachNode( pNtk, pObj, i )
715  {
716  Vec_IntWriteEntry( vSlacks, i, Vec_IntSize(vSlacks) );
717  for ( k = 0; k < Abc_ObjFaninNum(pObj); k++ )
718  Vec_IntPush( vSlacks, -1 );
719  }
720 // assert( Abc_MaxInt(16, Vec_IntSize(vSlacks)) == Vec_IntCap(vSlacks) );
721  return vSlacks;
722 }
723 
724 /**Function*************************************************************
725 
726  Synopsis [Read/write edge slacks.]
727 
728  Description []
729 
730  SideEffects []
731 
732  SeeAlso []
733 
734 ***********************************************************************/
735 static inline float Abc_NtkDelayTraceSlack( Vec_Int_t * vSlacks, Abc_Obj_t * pObj, int iFanin )
736 {
737  return Abc_Int2Float( Vec_IntEntry( vSlacks, Vec_IntEntry(vSlacks, Abc_ObjId(pObj)) + iFanin ) );
738 }
739 static inline void Abc_NtkDelayTraceSetSlack( Vec_Int_t * vSlacks, Abc_Obj_t * pObj, int iFanin, float Num )
740 {
741  Vec_IntWriteEntry( vSlacks, Vec_IntEntry(vSlacks, Abc_ObjId(pObj)) + iFanin, Abc_Float2Int(Num) );
742 }
743 
744 /**Function*************************************************************
745 
746  Synopsis [Find most-critical path (the path with smallest slacks).]
747 
748  Description []
749 
750  SideEffects []
751 
752  SeeAlso []
753 
754 ***********************************************************************/
755 int Abc_NtkDelayTraceCritPath_rec( Vec_Int_t * vSlacks, Abc_Obj_t * pNode, Abc_Obj_t * pLeaf, Vec_Int_t * vBest )
756 {
757  Abc_Obj_t * pFanin, * pFaninBest = NULL;
758  float SlackMin = ABC_INFINITY;
759  int i;
760  // check primary inputs
761  if ( Abc_ObjIsCi(pNode) )
762  return (pLeaf == NULL || pLeaf == pNode);
763  assert( Abc_ObjIsNode(pNode) );
764  // check visited
765  if ( Abc_NodeIsTravIdCurrent( pNode ) )
766  return Vec_IntEntry(vBest, Abc_ObjId(pNode)) >= 0;
767  Abc_NodeSetTravIdCurrent( pNode );
768  // check the node
769  assert( Abc_ObjIsNode(pNode) );
770  Abc_ObjForEachFanin( pNode, pFanin, i )
771  {
772  if ( !Abc_NtkDelayTraceCritPath_rec( vSlacks, pFanin, pLeaf, vBest ) )
773  continue;
774  if ( pFaninBest == NULL || SlackMin > Abc_NtkDelayTraceSlack(vSlacks, pNode, i) )
775  {
776  pFaninBest = pFanin;
777  SlackMin = Abc_NtkDelayTraceSlack(vSlacks, pNode, i);
778  }
779  }
780  if ( pFaninBest != NULL )
781  Vec_IntWriteEntry( vBest, Abc_ObjId(pNode), Abc_NodeFindFanin(pNode, pFaninBest) );
782  return (pFaninBest != NULL);
783 }
784 
785 /**Function*************************************************************
786 
787  Synopsis [Find most-critical path (the path with smallest slacks).]
788 
789  Description []
790 
791  SideEffects []
792 
793  SeeAlso []
794 
795 ***********************************************************************/
796 void Abc_NtkDelayTraceCritPathCollect_rec( Vec_Int_t * vSlacks, Abc_Obj_t * pNode, Vec_Int_t * vBest, Vec_Ptr_t * vPath )
797 {
798  assert( Abc_ObjIsCi(pNode) || Abc_ObjIsNode(pNode) );
799  if ( Abc_ObjIsNode(pNode) )
800  {
801  int iFanin = Vec_IntEntry( vBest, Abc_ObjId(pNode) );
802  assert( iFanin >= 0 );
803  Abc_NtkDelayTraceCritPathCollect_rec( vSlacks, Abc_ObjFanin(pNode, iFanin), vBest, vPath );
804  }
805  Vec_PtrPush( vPath, pNode );
806 }
807 
808 /**Function*************************************************************
809 
810  Synopsis []
811 
812  Description []
813 
814  SideEffects []
815 
816  SeeAlso []
817 
818 ***********************************************************************/
820 {
821  Abc_Obj_t * pFanin;
822  Abc_Time_t * pTimeIn, * pTimeOut;
823  float tDelayBlockRise, tDelayBlockFall;
824  Mio_PinPhase_t PinPhase;
825  Mio_Pin_t * pPin;
826  int i;
827 
828  // start the arrival time of the node
829  pTimeOut = Abc_NodeArrival(pNode);
830  pTimeOut->Rise = pTimeOut->Fall = -ABC_INFINITY;
831  // consider the buffer
832  if ( Abc_ObjIsBarBuf(pNode) )
833  {
834  pTimeIn = Abc_NodeArrival(Abc_ObjFanin0(pNode));
835  *pTimeOut = *pTimeIn;
836  return;
837  }
838  // go through the pins of the gate
839  pPin = Mio_GateReadPins((Mio_Gate_t *)pNode->pData);
840  Abc_ObjForEachFanin( pNode, pFanin, i )
841  {
842  pTimeIn = Abc_NodeArrival(pFanin);
843  // get the interesting parameters of this pin
844  PinPhase = Mio_PinReadPhase(pPin);
845  tDelayBlockRise = (float)Mio_PinReadDelayBlockRise( pPin );
846  tDelayBlockFall = (float)Mio_PinReadDelayBlockFall( pPin );
847  // compute the arrival times of the positive phase
848  if ( PinPhase != MIO_PHASE_INV ) // NONINV phase is present
849  {
850  if ( pTimeOut->Rise < pTimeIn->Rise + tDelayBlockRise )
851  pTimeOut->Rise = pTimeIn->Rise + tDelayBlockRise;
852  if ( pTimeOut->Fall < pTimeIn->Fall + tDelayBlockFall )
853  pTimeOut->Fall = pTimeIn->Fall + tDelayBlockFall;
854  }
855  if ( PinPhase != MIO_PHASE_NONINV ) // INV phase is present
856  {
857  if ( pTimeOut->Rise < pTimeIn->Fall + tDelayBlockRise )
858  pTimeOut->Rise = pTimeIn->Fall + tDelayBlockRise;
859  if ( pTimeOut->Fall < pTimeIn->Rise + tDelayBlockFall )
860  pTimeOut->Fall = pTimeIn->Rise + tDelayBlockFall;
861  }
862  pPin = Mio_PinReadNext(pPin);
863  }
864 
865  // compute edge slacks
866  if ( vSlacks )
867  {
868  float Slack;
869  // go through the pins of the gate
870  pPin = Mio_GateReadPins((Mio_Gate_t *)pNode->pData);
871  Abc_ObjForEachFanin( pNode, pFanin, i )
872  {
873  pTimeIn = Abc_NodeArrival(pFanin);
874  // get the interesting parameters of this pin
875  PinPhase = Mio_PinReadPhase(pPin);
876  tDelayBlockRise = (float)Mio_PinReadDelayBlockRise( pPin );
877  tDelayBlockFall = (float)Mio_PinReadDelayBlockFall( pPin );
878  // compute the arrival times of the positive phase
879  Slack = ABC_INFINITY;
880  if ( PinPhase != MIO_PHASE_INV ) // NONINV phase is present
881  {
882 // if ( pTimeOut->Rise < pTimeIn->Rise + tDelayBlockRise )
883 // pTimeOut->Rise = pTimeIn->Rise + tDelayBlockRise;
884 // if ( pTimeOut->Fall < pTimeIn->Fall + tDelayBlockFall )
885 // pTimeOut->Fall = pTimeIn->Fall + tDelayBlockFall;
886  Slack = Abc_MinFloat( Slack, Abc_AbsFloat(pTimeIn->Rise + tDelayBlockRise - pTimeOut->Rise) );
887  Slack = Abc_MinFloat( Slack, Abc_AbsFloat(pTimeIn->Fall + tDelayBlockFall - pTimeOut->Fall) );
888  }
889  if ( PinPhase != MIO_PHASE_NONINV ) // INV phase is present
890  {
891 // if ( pTimeOut->Rise < pTimeIn->Fall + tDelayBlockRise )
892 // pTimeOut->Rise = pTimeIn->Fall + tDelayBlockRise;
893 // if ( pTimeOut->Fall < pTimeIn->Rise + tDelayBlockFall )
894 // pTimeOut->Fall = pTimeIn->Rise + tDelayBlockFall;
895  Slack = Abc_MinFloat( Slack, Abc_AbsFloat(pTimeIn->Fall + tDelayBlockRise - pTimeOut->Rise) );
896  Slack = Abc_MinFloat( Slack, Abc_AbsFloat(pTimeIn->Rise + tDelayBlockFall - pTimeOut->Fall) );
897  }
898  pPin = Mio_PinReadNext(pPin);
899  Abc_NtkDelayTraceSetSlack( vSlacks, pNode, i, Slack );
900  }
901  }
902 }
903 
904 
905 /**Function*************************************************************
906 
907  Synopsis [Performs delay-trace of the network. If input (pIn) or
908  output (pOut) are given, finds the most-timing-critical path between
909  them and prints it to the standard output. If input and/or output are
910  not given, finds the most-critical path in the network and prints it.]
911 
912  Description []
913 
914  SideEffects []
915 
916  SeeAlso []
917 
918 ***********************************************************************/
919 float Abc_NtkDelayTrace( Abc_Ntk_t * pNtk, Abc_Obj_t * pOut, Abc_Obj_t * pIn, int fPrint )
920 {
921  Vec_Int_t * vSlacks = NULL;
922  Abc_Obj_t * pNode, * pDriver;
923  Vec_Ptr_t * vNodes;
924  Abc_Time_t * pTime;
925  float tArrivalMax;
926  int i;
927 
928  assert( Abc_NtkIsMappedLogic(pNtk) );
929  assert( pOut == NULL || Abc_ObjIsCo(pOut) );
930  assert( pIn == NULL || Abc_ObjIsCi(pIn) );
931 
932  // create slacks (need slacks if printing is requested even if pIn/pOut are not given)
933  if ( pOut || pIn || fPrint )
934  vSlacks = Abc_NtkDelayTraceSlackStart( pNtk );
935 
936  // compute the timing
937  Abc_NtkTimePrepare( pNtk );
938  vNodes = Abc_NtkDfs( pNtk, 1 );
939  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
940  Abc_NodeDelayTraceArrival( pNode, vSlacks );
941  Vec_PtrFree( vNodes );
942 
943  // get the latest arrival times
944  tArrivalMax = -ABC_INFINITY;
945  Abc_NtkForEachCo( pNtk, pNode, i )
946  {
947  pDriver = Abc_ObjFanin0(pNode);
948  pTime = Abc_NodeArrival(pDriver);
949  if ( tArrivalMax < Abc_MaxFloat(pTime->Fall, pTime->Rise) )
950  tArrivalMax = Abc_MaxFloat(pTime->Fall, pTime->Rise);
951  }
952 
953  // determine the output to print
954  if ( fPrint && pOut == NULL )
955  {
956  Abc_NtkForEachCo( pNtk, pNode, i )
957  {
958  pDriver = Abc_ObjFanin0(pNode);
959  pTime = Abc_NodeArrival(pDriver);
960  if ( tArrivalMax == Abc_MaxFloat(pTime->Fall, pTime->Rise) )
961  pOut = pNode;
962  }
963  assert( pOut != NULL );
964  }
965 
966  if ( fPrint )
967  {
968  Vec_Ptr_t * vPath = Vec_PtrAlloc( 100 );
969  Vec_Int_t * vBest = Vec_IntStartFull( Abc_NtkObjNumMax(pNtk) );
970  // traverse to determine the critical path
971  Abc_NtkIncrementTravId( pNtk );
972  if ( !Abc_NtkDelayTraceCritPath_rec( vSlacks, Abc_ObjFanin0(pOut), pIn, vBest ) )
973  {
974  if ( pIn == NULL )
975  printf( "The logic cone of PO \"%s\" has no primary inputs.\n", Abc_ObjName(pOut) );
976  else
977  printf( "There is no combinational path between PI \"%s\" and PO \"%s\".\n", Abc_ObjName(pIn), Abc_ObjName(pOut) );
978  }
979  else
980  {
981  float Slack = 0.0, SlackAdd;
982  int k, iFanin, Length = 0;
983  Abc_Obj_t * pFanin;
984  // check the additional slack
986  // collect the critical path
987  Abc_NtkDelayTraceCritPathCollect_rec( vSlacks, Abc_ObjFanin0(pOut), vBest, vPath );
988  if ( pIn == NULL )
989  pIn = (Abc_Obj_t *)Vec_PtrEntry( vPath, 0 );
990  // find the longest gate name
991  Vec_PtrForEachEntry( Abc_Obj_t *, vPath, pNode, i )
992  if ( Abc_ObjIsNode(pNode) )
993  Length = Abc_MaxInt( Length, strlen(Mio_GateReadName((Mio_Gate_t *)pNode->pData)) );
994  // print critical path
995  Abc_NtkLevel( pNtk );
996  printf( "Critical path from PI \"%s\" to PO \"%s\":\n", Abc_ObjName(pIn), Abc_ObjName(pOut) );
997  Vec_PtrForEachEntry( Abc_Obj_t *, vPath, pNode, i )
998  {
999  printf( "Level %3d : ", Abc_ObjLevel(pNode) );
1000  if ( Abc_ObjIsCi(pNode) )
1001  {
1002  printf( "Primary input \"%s\". ", Abc_ObjName(pNode) );
1003  printf( "Arrival time =%6.1f. ", Abc_NodeReadArrivalWorst(pNode) );
1004  printf( "\n" );
1005  continue;
1006  }
1007  if ( Abc_ObjIsCo(pNode) )
1008  {
1009  printf( "Primary output \"%s\". ", Abc_ObjName(pNode) );
1010  printf( "Arrival =%6.1f. ", Abc_NodeReadArrivalWorst(pNode) );
1011  }
1012  else
1013  {
1014  assert( Abc_ObjIsNode(pNode) );
1015  iFanin = Abc_NodeFindFanin( pNode, (Abc_Obj_t *)Vec_PtrEntry(vPath,i-1) );
1016  Slack = Abc_NtkDelayTraceSlack(vSlacks, pNode, iFanin);
1017  printf( "%10s/", Abc_ObjName(pNode) );
1018  printf( "%-4s", Mio_GateReadPinName((Mio_Gate_t *)pNode->pData, iFanin) );
1019  printf( " (%s)", Mio_GateReadName((Mio_Gate_t *)pNode->pData) );
1020  for ( k = strlen(Mio_GateReadName((Mio_Gate_t *)pNode->pData)); k < Length; k++ )
1021  printf( " " );
1022  printf( " " );
1023  printf( "Arrival =%6.1f. ", Abc_NodeReadArrivalWorst(pNode) );
1024  printf( "I/O times: (" );
1025  Abc_ObjForEachFanin( pNode, pFanin, k )
1026  printf( "%s%.1f", (k? ", ":""), Abc_NodeReadArrivalWorst(pFanin) );
1027 // printf( " -> %.1f)", Abc_NodeReadArrival(pNode)->Worst + Slack + SlackAdd );
1028  printf( " -> %.1f)", Abc_NodeReadArrivalWorst(pNode) );
1029  }
1030  printf( "\n" );
1031  }
1032  printf( "Level %3d : ", Abc_ObjLevel(Abc_ObjFanin0(pOut)) + 1 );
1033  printf( "Primary output \"%s\". ", Abc_ObjName(pOut) );
1034  printf( "Required time = %6.1f. ", Abc_NodeReadRequiredWorst(pOut) );
1035  printf( "Path slack = %6.1f.\n", SlackAdd );
1036  }
1037  Vec_PtrFree( vPath );
1038  Vec_IntFree( vBest );
1039  }
1040 
1041  Vec_IntFreeP( &vSlacks );
1042  return tArrivalMax;
1043 }
1044 
1045 
1046 
1047 /**Function*************************************************************
1048 
1049  Synopsis [Computes the level of the node using its fanin levels.]
1050 
1051  Description []
1052 
1053  SideEffects []
1054 
1055  SeeAlso []
1056 
1057 ***********************************************************************/
1059 {
1060  Abc_Obj_t * pFanin;
1061  int i, Level = 0;
1062  Abc_ObjForEachFanin( pObj, pFanin, i )
1063  Level = Abc_MaxFloat( Level, Abc_ObjLevel(pFanin) );
1064  return Level + (int)(Abc_ObjFaninNum(pObj) > 0);
1065 }
1066 
1067 /**Function*************************************************************
1068 
1069  Synopsis [Computes the reverse level of the node using its fanout levels.]
1070 
1071  Description []
1072 
1073  SideEffects []
1074 
1075  SeeAlso []
1076 
1077 ***********************************************************************/
1079 {
1080  Abc_Obj_t * pFanout;
1081  int i, LevelCur, Level = 0;
1082  Abc_ObjForEachFanout( pObj, pFanout, i )
1083  {
1084  LevelCur = Abc_ObjReverseLevel( pFanout );
1085  Level = Abc_MaxFloat( Level, LevelCur );
1086  }
1087  return Level + 1;
1088 }
1089 
1090 /**Function*************************************************************
1091 
1092  Synopsis [Returns required level of the node.]
1093 
1094  Description [Converts the reverse levels of the node into its required
1095  level as follows: ReqLevel(Node) = MaxLevels(Ntk) + 1 - LevelR(Node).]
1096 
1097  SideEffects []
1098 
1099  SeeAlso []
1100 
1101 ***********************************************************************/
1103 {
1104  Abc_Ntk_t * pNtk = pObj->pNtk;
1105  assert( pNtk->vLevelsR );
1106  return pNtk->LevelMax + 1 - Abc_ObjReverseLevel(pObj);
1107 }
1108 
1109 /**Function*************************************************************
1110 
1111  Synopsis [Returns the reverse level of the node.]
1112 
1113  Description [The reverse level is the level of the node in reverse
1114  topological order, starting from the COs.]
1115 
1116  SideEffects []
1117 
1118  SeeAlso []
1119 
1120 ***********************************************************************/
1122 {
1123  Abc_Ntk_t * pNtk = pObj->pNtk;
1124  assert( pNtk->vLevelsR );
1125  Vec_IntFillExtra( pNtk->vLevelsR, pObj->Id + 1, 0 );
1126  return Vec_IntEntry(pNtk->vLevelsR, pObj->Id);
1127 }
1128 
1129 /**Function*************************************************************
1130 
1131  Synopsis [Sets the reverse level of the node.]
1132 
1133  Description [The reverse level is the level of the node in reverse
1134  topological order, starting from the COs.]
1135 
1136  SideEffects []
1137 
1138  SeeAlso []
1139 
1140 ***********************************************************************/
1141 void Abc_ObjSetReverseLevel( Abc_Obj_t * pObj, int LevelR )
1142 {
1143  Abc_Ntk_t * pNtk = pObj->pNtk;
1144  assert( pNtk->vLevelsR );
1145  Vec_IntFillExtra( pNtk->vLevelsR, pObj->Id + 1, 0 );
1146  Vec_IntWriteEntry( pNtk->vLevelsR, pObj->Id, LevelR );
1147 }
1148 
1149 /**Function*************************************************************
1150 
1151  Synopsis [Prepares for the computation of required levels.]
1152 
1153  Description [This procedure should be called before the required times
1154  are used. It starts internal data structures, which records the level
1155  from the COs of the network nodes in reverse topologogical order.]
1156 
1157  SideEffects []
1158 
1159  SeeAlso []
1160 
1161 ***********************************************************************/
1162 void Abc_NtkStartReverseLevels( Abc_Ntk_t * pNtk, int nMaxLevelIncrease )
1163 {
1164  Vec_Ptr_t * vNodes;
1165  Abc_Obj_t * pObj;
1166  int i;
1167  // remember the maximum number of direct levels
1168  pNtk->LevelMax = Abc_NtkLevel(pNtk) + nMaxLevelIncrease;
1169  // start the reverse levels
1170  pNtk->vLevelsR = Vec_IntAlloc( 0 );
1171  Vec_IntFill( pNtk->vLevelsR, 1 + Abc_NtkObjNumMax(pNtk), 0 );
1172  // compute levels in reverse topological order
1173  vNodes = Abc_NtkDfsReverse( pNtk );
1174  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
1176  Vec_PtrFree( vNodes );
1177 }
1178 
1179 /**Function*************************************************************
1180 
1181  Synopsis [Cleans the data structures used to compute required levels.]
1182 
1183  Description []
1184 
1185  SideEffects []
1186 
1187  SeeAlso []
1188 
1189 ***********************************************************************/
1191 {
1192  assert( pNtk->vLevelsR );
1193  Vec_IntFree( pNtk->vLevelsR );
1194  pNtk->vLevelsR = NULL;
1195  pNtk->LevelMax = 0;
1196 
1197 }
1198 
1199 /**Function*************************************************************
1200 
1201  Synopsis [Incrementally updates level of the nodes.]
1202 
1203  Description []
1204 
1205  SideEffects []
1206 
1207  SeeAlso []
1208 
1209 ***********************************************************************/
1210 void Abc_NtkUpdateLevel( Abc_Obj_t * pObjNew, Vec_Vec_t * vLevels )
1211 {
1212  Abc_Obj_t * pFanout, * pTemp;
1213  int LevelOld, Lev, k, m;
1214 // int Counter = 0, CounterMax = 0;
1215  // check if level has changed
1216  LevelOld = Abc_ObjLevel(pObjNew);
1217  if ( LevelOld == Abc_ObjLevelNew(pObjNew) )
1218  return;
1219  // start the data structure for level update
1220  // we cannot fail to visit a node when using this structure because the
1221  // nodes are stored by their _old_ levels, which are assumed to be correct
1222  Vec_VecClear( vLevels );
1223  Vec_VecPush( vLevels, LevelOld, pObjNew );
1224  pObjNew->fMarkA = 1;
1225  // recursively update level
1226  Vec_VecForEachEntryStart( Abc_Obj_t *, vLevels, pTemp, Lev, k, LevelOld )
1227  {
1228 // Counter--;
1229  pTemp->fMarkA = 0;
1230  assert( Abc_ObjLevel(pTemp) == Lev );
1231  Abc_ObjSetLevel( pTemp, Abc_ObjLevelNew(pTemp) );
1232  // if the level did not change, no need to check the fanout levels
1233  if ( Abc_ObjLevel(pTemp) == Lev )
1234  continue;
1235  // schedule fanout for level update
1236  Abc_ObjForEachFanout( pTemp, pFanout, m )
1237  {
1238  if ( !Abc_ObjIsCo(pFanout) && !pFanout->fMarkA )
1239  {
1240  assert( Abc_ObjLevel(pFanout) >= Lev );
1241  Vec_VecPush( vLevels, Abc_ObjLevel(pFanout), pFanout );
1242 // Counter++;
1243 // CounterMax = Abc_MaxFloat( CounterMax, Counter );
1244  pFanout->fMarkA = 1;
1245  }
1246  }
1247  }
1248 // printf( "%d ", CounterMax );
1249 }
1250 
1251 /**Function*************************************************************
1252 
1253  Synopsis [Incrementally updates level of the nodes.]
1254 
1255  Description []
1256 
1257  SideEffects []
1258 
1259  SeeAlso []
1260 
1261 ***********************************************************************/
1262 void Abc_NtkUpdateReverseLevel( Abc_Obj_t * pObjNew, Vec_Vec_t * vLevels )
1263 {
1264  Abc_Obj_t * pFanin, * pTemp;
1265  int LevelOld, LevFanin, Lev, k, m;
1266  // check if level has changed
1267  LevelOld = Abc_ObjReverseLevel(pObjNew);
1268  if ( LevelOld == Abc_ObjReverseLevelNew(pObjNew) )
1269  return;
1270  // start the data structure for level update
1271  // we cannot fail to visit a node when using this structure because the
1272  // nodes are stored by their _old_ levels, which are assumed to be correct
1273  Vec_VecClear( vLevels );
1274  Vec_VecPush( vLevels, LevelOld, pObjNew );
1275  pObjNew->fMarkA = 1;
1276  // recursively update level
1277  Vec_VecForEachEntryStart( Abc_Obj_t *, vLevels, pTemp, Lev, k, LevelOld )
1278  {
1279  pTemp->fMarkA = 0;
1280  LevelOld = Abc_ObjReverseLevel(pTemp);
1281  assert( LevelOld == Lev );
1283  // if the level did not change, no need to check the fanout levels
1284  if ( Abc_ObjReverseLevel(pTemp) == Lev )
1285  continue;
1286  // schedule fanins for level update
1287  Abc_ObjForEachFanin( pTemp, pFanin, m )
1288  {
1289  if ( !Abc_ObjIsCi(pFanin) && !pFanin->fMarkA )
1290  {
1291  LevFanin = Abc_ObjReverseLevel( pFanin );
1292  assert( LevFanin >= Lev );
1293  Vec_VecPush( vLevels, LevFanin, pFanin );
1294  pFanin->fMarkA = 1;
1295  }
1296  }
1297  }
1298 }
1299 
1300 /**Function*************************************************************
1301 
1302  Synopsis [Replaces the node and incrementally updates levels.]
1303 
1304  Description []
1305 
1306  SideEffects []
1307 
1308  SeeAlso []
1309 
1310 ***********************************************************************/
1311 void Abc_NtkUpdate( Abc_Obj_t * pObj, Abc_Obj_t * pObjNew, Vec_Vec_t * vLevels )
1312 {
1313  // replace the old node by the new node
1314  pObjNew->Level = pObj->Level;
1315  Abc_ObjReplace( pObj, pObjNew );
1316  // update the level of the node
1317  Abc_NtkUpdateLevel( pObjNew, vLevels );
1318  Abc_ObjSetReverseLevel( pObjNew, 0 );
1319  Abc_NtkUpdateReverseLevel( pObjNew, vLevels );
1320 }
1321 
1322 ////////////////////////////////////////////////////////////////////////
1323 /// END OF FILE ///
1324 ////////////////////////////////////////////////////////////////////////
1325 
1326 
1328 
char * memset()
static unsigned Abc_ObjId(Abc_Obj_t *pObj)
Definition: abc.h:329
Abc_Time_t * Abc_NtkReadDefaultOutputLoad(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:120
Abc_Time_t * Abc_NtkReadDefaultRequired(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:72
Vec_Int_t * vLevelsR
Definition: abc.h:196
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Abc_Time_t * Abc_NodeReadRequired(Abc_Obj_t *pNode)
Definition: abcTiming.c:82
ABC_DLL void * Abc_FrameReadLibGen()
Definition: mainFrame.c:56
static float Abc_MinFloat(float a, float b)
Definition: abc_global.h:244
static void Vec_VecPush(Vec_Vec_t *p, int Level, void *Entry)
Definition: vecVec.h:456
static int Abc_ObjIsCi(Abc_Obj_t *pObj)
Definition: abc.h:351
unsigned fMarkA
Definition: abc.h:134
static float Abc_NtkDelayTraceSlack(Vec_Int_t *vSlacks, Abc_Obj_t *pObj, int iFanin)
Definition: abcTiming.c:735
Abc_Time_t * tOutLoad
Definition: abcTiming.c:41
void Abc_NtkUpdateReverseLevel(Abc_Obj_t *pObjNew, Vec_Vec_t *vLevels)
Definition: abcTiming.c:1262
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
void Abc_NtkStartReverseLevels(Abc_Ntk_t *pNtk, int nMaxLevelIncrease)
Definition: abcTiming.c:1162
int Abc_ObjReverseLevel(Abc_Obj_t *pObj)
Definition: abcTiming.c:1121
static float Abc_AbsFloat(float a)
Definition: abc_global.h:242
void Abc_NtkTimeSetOutputLoad(Abc_Ntk_t *pNtk, int PoNum, float Rise, float Fall)
Definition: abcTiming.c:290
static Llb_Mgr_t * p
Definition: llb3Image.c:950
float Abc_NtkDelayTrace(Abc_Ntk_t *pNtk, Abc_Obj_t *pOut, Abc_Obj_t *pIn, int fPrint)
Definition: abcTiming.c:919
static void Vec_IntFillExtra(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:376
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
float AndGateDelay
Definition: abc.h:194
int LevelMax
Definition: abc.h:195
Mio_Pin_t * Mio_GateReadPins(Mio_Gate_t *pGate)
Definition: mioApi.c:147
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
static void Vec_PtrGrow(Vec_Ptr_t *p, int nCapMin)
Definition: vecPtr.h:430
int Abc_ObjLevelNew(Abc_Obj_t *pObj)
Definition: abcTiming.c:1058
#define Abc_NtkForEachLatchOutput(pNtk, pObj, i)
Definition: abc.h:503
ABC_DLL int Abc_NodeFindFanin(Abc_Obj_t *pNode, Abc_Obj_t *pFanin)
Definition: abcUtil.c:758
char * Mio_GateReadPinName(Mio_Gate_t *pGate, int iPin)
Definition: mioApi.c:192
double Mio_PinReadDelayBlockFall(Mio_Pin_t *pPin)
Definition: mioApi.c:176
void Abc_NtkTimeInitialize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkOld)
Definition: abcTiming.c:321
Mio_PinPhase_t
INCLUDES ///.
Definition: mio.h:40
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
void Abc_NtkDelayTraceCritPathCollect_rec(Vec_Int_t *vSlacks, Abc_Obj_t *pNode, Vec_Int_t *vBest, Vec_Ptr_t *vPath)
Definition: abcTiming.c:796
static int Abc_ObjIsBarBuf(Abc_Obj_t *pObj)
Definition: abc.h:360
float Abc_NodeReadRequiredAve(Abc_Obj_t *pNode)
Definition: abcTiming.c:91
Vec_Ptr_t * vArrs
Definition: abcTiming.c:36
void Abc_ObjSetReverseLevel(Abc_Obj_t *pObj, int LevelR)
Definition: abcTiming.c:1141
float Mio_LibraryReadDelayNand2Max(Mio_Library_t *pLib)
Definition: mioApi.c:58
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
static void Abc_NtkDelayTraceSetSlack(Vec_Int_t *vSlacks, Abc_Obj_t *pObj, int iFanin, float Num)
Definition: abcTiming.c:739
char * memcpy()
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Abc_NtkCiNum(Abc_Ntk_t *pNtk)
Definition: abc.h:287
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static Abc_Obj_t * Abc_NtkCi(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:317
void Abc_NtkUpdate(Abc_Obj_t *pObj, Abc_Obj_t *pObjNew, Vec_Vec_t *vLevels)
Definition: abcTiming.c:1311
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
Definition: abcDfs.c:81
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
Mio_Pin_t * Mio_PinReadNext(Mio_Pin_t *pPin)
Definition: mioApi.c:179
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
ABC_DLL int Abc_NtkGetTotalFanins(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:487
static Vec_Int_t * Vec_IntStartFull(int nSize)
Definition: vecInt.h:119
static void Abc_ObjSetLevel(Abc_Obj_t *pObj, int Level)
Definition: abc.h:341
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static float Abc_MaxFloat(float a, float b)
Definition: abc_global.h:243
for(p=first;p->value< newval;p=p->next)
DECLARATIONS ///.
Definition: abcTiming.c:32
static int Abc_NtkCoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:288
unsigned Level
Definition: abc.h:142
static int Abc_ObjIsCo(Abc_Obj_t *pObj)
Definition: abc.h:352
ABC_DLL Vec_Ptr_t * Abc_NtkDfsReverse(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:190
static Abc_Obj_t * Abc_NtkCo(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:318
static void Vec_VecClear(Vec_Vec_t *p)
Definition: vecVec.h:437
Abc_Time_t * Abc_NodeReadOutputLoad(Abc_Ntk_t *pNtk, int iPo)
Definition: abcTiming.c:130
static void Abc_ManTimeExpand(Abc_ManTime_t *p, int nSize, int fProgressive)
Definition: abcTiming.c:533
Mio_Gate_t * Mio_LibraryReadNand2(Mio_Library_t *pLib)
Definition: mioApi.c:51
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
Abc_Time_t tInDriveDef
Definition: abcTiming.c:38
Abc_Time_t * Abc_NtkReadDefaultArrival(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcTiming.c:67
static int Abc_Float2Int(float Val)
Definition: abc_global.h:249
Abc_Obj_t * pCopy
Definition: abc.h:148
int Abc_ObjReverseLevelNew(Abc_Obj_t *pObj)
Definition: abcTiming.c:1078
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
void Abc_NtkTimeSetDefaultRequired(Abc_Ntk_t *pNtk, float Rise, float Fall)
Definition: abcTiming.c:164
float Abc_NodeReadArrivalWorst(Abc_Obj_t *pNode)
Definition: abcTiming.c:95
float Abc_NodeReadInputDriveWorst(Abc_Ntk_t *pNtk, int iPi)
Definition: abcTiming.c:135
void Abc_NtkTimeSetArrival(Abc_Ntk_t *pNtk, int ObjId, float Rise, float Fall)
Definition: abcTiming.c:185
Abc_Time_t * Abc_NtkGetCoRequiredTimes(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:632
static int Abc_ObjLevel(Abc_Obj_t *pObj)
Definition: abc.h:330
float Abc_NodeReadRequiredWorst(Abc_Obj_t *pNode)
Definition: abcTiming.c:99
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
ABC_DLL void Abc_ObjReplace(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:297
int Abc_NtkDelayTraceCritPath_rec(Vec_Int_t *vSlacks, Abc_Obj_t *pNode, Abc_Obj_t *pLeaf, Vec_Int_t *vBest)
Definition: abcTiming.c:755
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
void Abc_ManTimeDup(Abc_Ntk_t *pNtkOld, Abc_Ntk_t *pNtkNew)
Definition: abcTiming.c:481
int Abc_ObjRequiredLevel(Abc_Obj_t *pObj)
Definition: abcTiming.c:1102
float * Abc_NtkGetCoRequiredFloats(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:676
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
void Abc_NtkStopReverseLevels(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:1190
void Abc_NodeDelayTraceArrival(Abc_Obj_t *pNode, Vec_Int_t *vSlacks)
Definition: abcTiming.c:819
#define Vec_VecForEachEntryStart(Type, vGlob, pEntry, i, k, LevelStart)
Definition: vecVec.h:92
Abc_Time_t tArrDef
Definition: abcTiming.c:34
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
void Abc_NtkTimeSetInputDrive(Abc_Ntk_t *pNtk, int PiNum, float Rise, float Fall)
Definition: abcTiming.c:271
Vec_Int_t * Abc_NtkDelayTraceSlackStart(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:707
float Abc_NodeReadArrivalAve(Abc_Obj_t *pNode)
Definition: abcTiming.c:87
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
Abc_Time_t * tInDrive
Definition: abcTiming.c:40
static int Abc_NodeIsTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:411
Abc_Time_t * Abc_NtkGetCiArrivalTimes(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:619
float Fall
Definition: abc.h:125
Abc_Ntk_t * pNtk
Definition: abc.h:130
static int Abc_NtkIsMappedLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:267
Vec_Ptr_t * vReqs
Definition: abcTiming.c:37
Abc_Time_t * Abc_NodeReadInputDrive(Abc_Ntk_t *pNtk, int iPi)
Definition: abcTiming.c:125
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
void Abc_NtkUpdateLevel(Abc_Obj_t *pObjNew, Vec_Vec_t *vLevels)
Definition: abcTiming.c:1210
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition: abc.h:526
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
void Abc_NtkTimePrepare(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:377
static Abc_ManTime_t * Abc_ManTimeStart(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:431
void Abc_ManTimeStop(Abc_ManTime_t *p)
Definition: abcTiming.c:455
void Abc_NtkTimeSetDefaultOutputLoad(Abc_Ntk_t *pNtk, float Rise, float Fall)
Definition: abcTiming.c:243
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
Abc_Time_t * Abc_NtkReadDefaultInputDrive(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:115
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Id
Definition: abc.h:132
Abc_ManTime_t * pManTime
Definition: abc.h:192
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
static void Abc_NtkIncrementTravId(Abc_Ntk_t *p)
Definition: abc.h:406
Mio_PinPhase_t Mio_PinReadPhase(Mio_Pin_t *pPin)
Definition: mioApi.c:171
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
double Mio_PinReadDelayBlockRise(Mio_Pin_t *pPin)
Definition: mioApi.c:174
static float Abc_Int2Float(int Num)
Definition: abc_global.h:250
void Abc_NtkTimeSetRequired(Abc_Ntk_t *pNtk, int ObjId, float Rise, float Fall)
Definition: abcTiming.c:200
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition: abc_global.h:216
void Abc_NtkTimeSetDefaultInputDrive(Abc_Ntk_t *pNtk, float Rise, float Fall)
Definition: abcTiming.c:227
#define assert(ex)
Definition: util_old.h:213
int strlen()
Abc_Time_t tOutLoadDef
Definition: abcTiming.c:39
void * pData
Definition: abc.h:145
static Abc_Time_t * Abc_NodeArrival(Abc_Obj_t *pNode)
Definition: abcTiming.c:49
static Abc_Obj_t * Abc_ObjFanin(Abc_Obj_t *pObj, int i)
Definition: abc.h:372
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
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:1265
Abc_Time_t * Abc_NodeReadArrival(Abc_Obj_t *pNode)
Definition: abcTiming.c:77
char * Mio_GateReadName(Mio_Gate_t *pGate)
Definition: mioApi.c:143
Abc_Time_t tReqDef
Definition: abcTiming.c:35
float Rise
Definition: abc.h:124
void Abc_NtkTimeSetDefaultArrival(Abc_Ntk_t *pNtk, float Rise, float Fall)
Definition: abcTiming.c:155
static void Abc_NodeSetTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:409
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
float * Abc_NtkGetCiArrivalFloats(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:658
void Abc_NtkSetNodeLevelsArrival(Abc_Ntk_t *pNtkOld)
Definition: abcTiming.c:591
static Abc_Time_t * Abc_NodeRequired(Abc_Obj_t *pNode)
Definition: abcTiming.c:50
float Abc_NodeReadOutputLoadWorst(Abc_Ntk_t *pNtk, int iPo)
Definition: abcTiming.c:139