1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
|
/**CFile****************************************************************
FileName [nwkTiming.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Logic network representation.]
Synopsis [Manipulation of timing information.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: nwkTiming.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "nwk.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Cleans timing information for all nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Nwk_ManCleanTiming( Nwk_Man_t * pNtk )
{
Nwk_Obj_t * pObj;
int i;
Nwk_ManForEachObj( pNtk, pObj, i )
{
pObj->tArrival = pObj->tSlack = 0.0;
pObj->tRequired = TIM_ETERNITY;
}
}
/**Function*************************************************************
Synopsis [Sorts the pins in the decreasing order of delays.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Nwk_ManDelayTraceSortPins( Nwk_Obj_t * pNode, int * pPinPerm, float * pPinDelays )
{
Nwk_Obj_t * pFanin;
int i, j, best_i, temp;
// start the trivial permutation and collect pin delays
Nwk_ObjForEachFanin( pNode, pFanin, i )
{
pPinPerm[i] = i;
pPinDelays[i] = Nwk_ObjArrival(pFanin);
}
// selection sort the pins in the decreasible order of delays
// this order will match the increasing order of LUT input pins
for ( i = 0; i < Nwk_ObjFaninNum(pNode)-1; i++ )
{
best_i = i;
for ( j = i+1; j < Nwk_ObjFaninNum(pNode); j++ )
if ( pPinDelays[pPinPerm[j]] > pPinDelays[pPinPerm[best_i]] )
best_i = j;
if ( best_i == i )
continue;
temp = pPinPerm[i];
pPinPerm[i] = pPinPerm[best_i];
pPinPerm[best_i] = temp;
}
// verify
assert( Nwk_ObjFaninNum(pNode) == 0 || pPinPerm[0] < Nwk_ObjFaninNum(pNode) );
for ( i = 1; i < Nwk_ObjFaninNum(pNode); i++ )
{
assert( pPinPerm[i] < Nwk_ObjFaninNum(pNode) );
assert( pPinDelays[pPinPerm[i-1]] >= pPinDelays[pPinPerm[i]] );
}
}
/**Function*************************************************************
Synopsis [Sorts the pins in the decreasing order of delays.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Nwk_ManWhereIsPin( Nwk_Obj_t * pFanout, Nwk_Obj_t * pFanin, int * pPinPerm )
{
int i;
for ( i = 0; i < Nwk_ObjFaninNum(pFanout); i++ )
if ( Nwk_ObjFanin(pFanout, pPinPerm[i]) == pFanin )
return i;
return -1;
}
/**Function*************************************************************
Synopsis [Computes the arrival times for the given object.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
float Nwk_NodeComputeArrival( Nwk_Obj_t * pObj, int fUseSorting )
{
If_Lib_t * pLutLib = pObj->pMan->pLutLib;
int pPinPerm[32];
float pPinDelays[32];
Nwk_Obj_t * pFanin;
float tArrival, * pDelays;
int k;
assert( Nwk_ObjIsNode(pObj) || Nwk_ObjIsCi(pObj) || Nwk_ObjIsCo(pObj) );
if ( Nwk_ObjIsCi(pObj) )
return Nwk_ObjArrival(pObj);
if ( Nwk_ObjIsCo(pObj) )
return Nwk_ObjArrival( Nwk_ObjFanin0(pObj) );
tArrival = -TIM_ETERNITY;
if ( pLutLib == NULL )
{
Nwk_ObjForEachFanin( pObj, pFanin, k )
if ( tArrival < Nwk_ObjArrival(pFanin) + 1.0 )
tArrival = Nwk_ObjArrival(pFanin) + 1.0;
}
else if ( !pLutLib->fVarPinDelays )
{
pDelays = pLutLib->pLutDelays[Nwk_ObjFaninNum(pObj)];
Nwk_ObjForEachFanin( pObj, pFanin, k )
if ( tArrival < Nwk_ObjArrival(pFanin) + pDelays[0] )
tArrival = Nwk_ObjArrival(pFanin) + pDelays[0];
}
else
{
pDelays = pLutLib->pLutDelays[Nwk_ObjFaninNum(pObj)];
if ( fUseSorting )
{
Nwk_ManDelayTraceSortPins( pObj, pPinPerm, pPinDelays );
Nwk_ObjForEachFanin( pObj, pFanin, k )
if ( tArrival < Nwk_ObjArrival(Nwk_ObjFanin(pObj,pPinPerm[k])) + pDelays[k] )
tArrival = Nwk_ObjArrival(Nwk_ObjFanin(pObj,pPinPerm[k])) + pDelays[k];
}
else
{
Nwk_ObjForEachFanin( pObj, pFanin, k )
if ( tArrival < Nwk_ObjArrival(pFanin) + pDelays[k] )
tArrival = Nwk_ObjArrival(pFanin) + pDelays[k];
}
}
if ( Nwk_ObjFaninNum(pObj) == 0 )
tArrival = 0.0;
return tArrival;
}
/**Function*************************************************************
Synopsis [Computes the required times for the given node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
float Nwk_NodeComputeRequired( Nwk_Obj_t * pObj, int fUseSorting )
{
If_Lib_t * pLutLib = pObj->pMan->pLutLib;
int pPinPerm[32];
float pPinDelays[32];
Nwk_Obj_t * pFanout;
float tRequired, tDelay, * pDelays;
int k, iFanin;
assert( Nwk_ObjIsNode(pObj) || Nwk_ObjIsCi(pObj) || Nwk_ObjIsCo(pObj) );
if ( Nwk_ObjIsCo(pObj) )
return Nwk_ObjRequired(pObj);
tRequired = TIM_ETERNITY;
if ( pLutLib == NULL )
{
Nwk_ObjForEachFanout( pObj, pFanout, k )
{
tDelay = Nwk_ObjIsCo(pFanout)? 0.0 : 1.0;
if ( tRequired > Nwk_ObjRequired(pFanout) - tDelay )
tRequired = Nwk_ObjRequired(pFanout) - tDelay;
}
}
else if ( !pLutLib->fVarPinDelays )
{
Nwk_ObjForEachFanout( pObj, pFanout, k )
{
pDelays = pLutLib->pLutDelays[Nwk_ObjFaninNum(pFanout)];
tDelay = Nwk_ObjIsCo(pFanout)? 0.0 : pDelays[0];
if ( tRequired > Nwk_ObjRequired(pFanout) - tDelay )
tRequired = Nwk_ObjRequired(pFanout) - tDelay;
}
}
else
{
if ( fUseSorting )
{
Nwk_ObjForEachFanout( pObj, pFanout, k )
{
pDelays = pLutLib->pLutDelays[Nwk_ObjFaninNum(pFanout)];
Nwk_ManDelayTraceSortPins( pFanout, pPinPerm, pPinDelays );
iFanin = Nwk_ManWhereIsPin( pFanout, pObj, pPinPerm );
assert( Nwk_ObjFanin(pFanout,pPinPerm[iFanin]) == pObj );
tDelay = Nwk_ObjIsCo(pFanout)? 0.0 : pDelays[iFanin];
if ( tRequired > Nwk_ObjRequired(pFanout) - tDelay )
tRequired = Nwk_ObjRequired(pFanout) - tDelay;
}
}
else
{
Nwk_ObjForEachFanout( pObj, pFanout, k )
{
pDelays = pLutLib->pLutDelays[Nwk_ObjFaninNum(pFanout)];
iFanin = Nwk_ObjFindFanin( pFanout, pObj );
assert( Nwk_ObjFanin(pFanout,iFanin) == pObj );
tDelay = Nwk_ObjIsCo(pFanout)? 0.0 : pDelays[iFanin];
if ( tRequired > Nwk_ObjRequired(pFanout) - tDelay )
tRequired = Nwk_ObjRequired(pFanout) - tDelay;
}
}
}
return tRequired;
}
/**Function*************************************************************
Synopsis [Propagates the required times through the given node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
float Nwk_NodePropagateRequired( Nwk_Obj_t * pObj, int fUseSorting )
{
If_Lib_t * pLutLib = pObj->pMan->pLutLib;
int pPinPerm[32];
float pPinDelays[32];
Nwk_Obj_t * pFanin;
float tRequired, * pDelays;
int k;
assert( Nwk_ObjIsNode(pObj) );
if ( pLutLib == NULL )
{
tRequired = Nwk_ObjRequired(pObj) - (float)1.0;
Nwk_ObjForEachFanin( pObj, pFanin, k )
if ( Nwk_ObjRequired(pFanin) > tRequired )
Nwk_ObjSetRequired( pFanin, tRequired );
}
else if ( !pLutLib->fVarPinDelays )
{
pDelays = pLutLib->pLutDelays[Nwk_ObjFaninNum(pObj)];
tRequired = Nwk_ObjRequired(pObj) - pDelays[0];
Nwk_ObjForEachFanin( pObj, pFanin, k )
if ( Nwk_ObjRequired(pFanin) > tRequired )
Nwk_ObjSetRequired( pFanin, tRequired );
}
else
{
pDelays = pLutLib->pLutDelays[Nwk_ObjFaninNum(pObj)];
if ( fUseSorting )
{
Nwk_ManDelayTraceSortPins( pObj, pPinPerm, pPinDelays );
Nwk_ObjForEachFanin( pObj, pFanin, k )
{
tRequired = Nwk_ObjRequired(pObj) - pDelays[k];
if ( Nwk_ObjRequired(Nwk_ObjFanin(pObj,pPinPerm[k])) > tRequired )
Nwk_ObjSetRequired( Nwk_ObjFanin(pObj,pPinPerm[k]), tRequired );
}
}
else
{
Nwk_ObjForEachFanin( pObj, pFanin, k )
{
tRequired = Nwk_ObjRequired(pObj) - pDelays[k];
if ( Nwk_ObjRequired(pFanin) > tRequired )
Nwk_ObjSetRequired( pFanin, tRequired );
}
}
}
return tRequired;
}
/**Function*************************************************************
Synopsis [Computes the delay trace of the given network.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
float Nwk_ManDelayTraceLut( Nwk_Man_t * pNtk )
{
Vec_Ptr_t * vObjs;
int fUseSorting = 1;
If_Lib_t * pLutLib = pNtk->pLutLib;
Vec_Ptr_t * vNodes;
Nwk_Obj_t * pObj;
float tArrival, tRequired, tSlack;
int i;
// get the library
if ( pLutLib && pLutLib->LutMax < Nwk_ManGetFaninMax(pNtk) )
{
printf( "The max LUT size (%d) is less than the max fanin count (%d).\n",
pLutLib->LutMax, Nwk_ManGetFaninMax(pNtk) );
return -TIM_ETERNITY;
}
// compute the reverse order of all objects
vNodes = Nwk_ManDfsReverse( pNtk );
// initialize the arrival times
Nwk_ManCleanTiming( pNtk );
// propagate arrival times
if ( pNtk->pManTime )
Tim_ManIncrementTravId( pNtk->pManTime );
// Nwk_ManForEachObj( pNtk, pObj, i )
vObjs = Nwk_ManDfs( pNtk );
Vec_PtrForEachEntry( vObjs, pObj, i )
{
tArrival = Nwk_NodeComputeArrival( pObj, fUseSorting );
if ( Nwk_ObjIsCo(pObj) && pNtk->pManTime )
Tim_ManSetCoArrival( pNtk->pManTime, pObj->PioId, tArrival );
if ( Nwk_ObjIsCi(pObj) && pNtk->pManTime )
tArrival = Tim_ManGetCiArrival( pNtk->pManTime, pObj->PioId );
Nwk_ObjSetArrival( pObj, tArrival );
}
Vec_PtrFree( vObjs );
// get the latest arrival times
tArrival = -TIM_ETERNITY;
Nwk_ManForEachPo( pNtk, pObj, i )
if ( tArrival < Nwk_ObjArrival(pObj) )
tArrival = Nwk_ObjArrival(pObj);
// initialize the required times
if ( pNtk->pManTime )
{
Tim_ManIncrementTravId( pNtk->pManTime );
Tim_ManSetCoRequiredAll( pNtk->pManTime, tArrival );
}
else
{
Nwk_ManForEachCo( pNtk, pObj, i )
Nwk_ObjSetRequired( pObj, tArrival );
}
// propagate the required times
Vec_PtrForEachEntry( vNodes, pObj, i )
{
if ( Nwk_ObjIsNode(pObj) )
{
Nwk_NodePropagateRequired( pObj, fUseSorting );
}
else if ( Nwk_ObjIsCi(pObj) )
{
if ( pNtk->pManTime )
Tim_ManSetCiRequired( pNtk->pManTime, pObj->PioId, Nwk_ObjRequired(pObj) );
}
else if ( Nwk_ObjIsCo(pObj) )
{
if ( pNtk->pManTime )
{
tRequired = Tim_ManGetCoRequired( pNtk->pManTime, pObj->PioId );
Nwk_ObjSetRequired( pObj, tRequired );
}
if ( Nwk_ObjRequired(Nwk_ObjFanin0(pObj)) > Nwk_ObjRequired(pObj) )
Nwk_ObjSetRequired( Nwk_ObjFanin0(pObj), Nwk_ObjRequired(pObj) );
}
// set slack for this object
tSlack = Nwk_ObjRequired(pObj) - Nwk_ObjArrival(pObj);
assert( tSlack + 0.01 > 0.0 );
Nwk_ObjSetSlack( pObj, tSlack < 0.0 ? 0.0 : tSlack );
}
Vec_PtrFree( vNodes );
return tArrival;
}
/**Function*************************************************************
Synopsis [Computes the arrival times for the given node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Nwk_ManVerifyTiming( Nwk_Man_t * pNtk )
{
Nwk_Obj_t * pObj;
float tArrival, tRequired;
int i;
Nwk_ManForEachObj( pNtk, pObj, i )
{
if ( Nwk_ObjIsCi(pObj) && Nwk_ObjFanoutNum(pObj) == 0 )
continue;
tArrival = Nwk_NodeComputeArrival( pObj, 1 );
tRequired = Nwk_NodeComputeRequired( pObj, 1 );
if ( !Nwk_ManTimeEqual( tArrival, Nwk_ObjArrival(pObj), (float)0.01 ) )
printf( "Nwk_ManVerifyTiming(): Object %d has different arrival time (%.2f) from computed (%.2f).\n",
pObj->Id, Nwk_ObjArrival(pObj), tArrival );
if ( !Nwk_ManTimeEqual( tRequired, Nwk_ObjRequired(pObj), (float)0.01 ) )
printf( "Nwk_ManVerifyTiming(): Object %d has different required time (%.2f) from computed (%.2f).\n",
pObj->Id, Nwk_ObjRequired(pObj), tRequired );
}
return 1;
}
/**Function*************************************************************
Synopsis [Prints the delay trace for the given network.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Nwk_ManDelayTracePrint( Nwk_Man_t * pNtk )
{
If_Lib_t * pLutLib = pNtk->pLutLib;
Nwk_Obj_t * pNode;
int i, Nodes, * pCounters;
float tArrival, tDelta, nSteps, Num;
// get the library
if ( pLutLib && pLutLib->LutMax < Nwk_ManGetFaninMax(pNtk) )
{
printf( "The max LUT size (%d) is less than the max fanin count (%d).\n",
pLutLib->LutMax, Nwk_ManGetFaninMax(pNtk) );
return;
}
// decide how many steps
nSteps = pLutLib ? 20 : Nwk_ManLevelMax(pNtk);
pCounters = ALLOC( int, nSteps + 1 );
memset( pCounters, 0, sizeof(int)*(nSteps + 1) );
// perform delay trace
tArrival = Nwk_ManDelayTraceLut( pNtk );
tDelta = tArrival / nSteps;
// count how many nodes have slack in the corresponding intervals
Nwk_ManForEachNode( pNtk, pNode, i )
{
if ( Nwk_ObjFaninNum(pNode) == 0 )
continue;
Num = Nwk_ObjSlack(pNode) / tDelta;
if ( Num > nSteps )
continue;
assert( Num >=0 && Num <= nSteps );
pCounters[(int)Num]++;
}
// print the results
printf( "Max delay = %6.2f. Delay trace using %s model:\n", tArrival, pLutLib? "LUT library" : "unit-delay" );
Nodes = 0;
for ( i = 0; i < nSteps; i++ )
{
Nodes += pCounters[i];
printf( "%3d %s : %5d (%6.2f %%)\n", pLutLib? 5*(i+1) : i+1,
pLutLib? "%":"lev", Nodes, 100.0*Nodes/Nwk_ManNodeNum(pNtk) );
}
free( pCounters );
}
/**Function*************************************************************
Synopsis [Inserts node into the queue of nodes sorted by level.]
Description [The inserted node should not go before the current position
given by iCurrent. If the arrival times are computed, the nodes are sorted
in the increasing order of levels. If the required times are computed,
the nodes are sorted in the decreasing order of levels.]
SideEffects []
SeeAlso []
***********************************************************************/
void Nwk_NodeUpdateAddToQueue( Vec_Ptr_t * vQueue, Nwk_Obj_t * pObj, int iCurrent, int fArrival )
{
Nwk_Obj_t * pTemp1, * pTemp2;
int i;
Vec_PtrPush( vQueue, pObj );
for ( i = Vec_PtrSize(vQueue) - 1; i > iCurrent + 1; i-- )
{
pTemp1 = vQueue->pArray[i];
pTemp2 = vQueue->pArray[i-1];
if ( fArrival )
{
if ( Nwk_ObjLevel(pTemp2) <= Nwk_ObjLevel(pTemp1) )
break;
}
else
{
if ( Nwk_ObjLevel(pTemp2) >= Nwk_ObjLevel(pTemp1) )
break;
}
vQueue->pArray[i-1] = pTemp1;
vQueue->pArray[i] = pTemp2;
}
// verification
for ( i = iCurrent + 1; i < Vec_PtrSize(vQueue) - 1; i++ )
{
pTemp1 = vQueue->pArray[i];
pTemp2 = vQueue->pArray[i+1];
if ( fArrival )
assert( Nwk_ObjLevel(pTemp1) <= Nwk_ObjLevel(pTemp2) );
else
assert( Nwk_ObjLevel(pTemp1) >= Nwk_ObjLevel(pTemp2) );
}
}
/**Function*************************************************************
Synopsis [Incrementally updates arrival times of the node.]
Description [Supports variable-pin delay model and white-boxes.]
SideEffects []
SeeAlso []
***********************************************************************/
void Nwk_NodeUpdateArrival( Nwk_Obj_t * pObj )
{
If_Lib_t * pLutLib = pObj->pMan->pLutLib;
Tim_Man_t * pManTime = pObj->pMan->pManTime;
Vec_Ptr_t * vQueue = pObj->pMan->vTemp;
Nwk_Obj_t * pTemp, * pNext;
float tArrival;
int iCur, k, iBox, iTerm1, nTerms;
assert( Nwk_ObjIsNode(pObj) );
// verify the arrival time
tArrival = Nwk_NodeComputeArrival( pObj, 1 );
assert( Nwk_ManTimeLess( tArrival, Nwk_ObjRequired(pObj), (float)0.01 ) );
// initialize the queue with the node
Vec_PtrClear( vQueue );
Vec_PtrPush( vQueue, pObj );
pObj->MarkA = 1;
// process objects
if ( pManTime )
Tim_ManIncrementTravId( pManTime );
Vec_PtrForEachEntry( vQueue, pTemp, iCur )
{
pTemp->MarkA = 0;
tArrival = Nwk_NodeComputeArrival( pTemp, 1 );
if ( Nwk_ObjIsCi(pTemp) && pManTime )
tArrival = Tim_ManGetCiArrival( pManTime, pTemp->PioId );
if ( Nwk_ManTimeEqual( tArrival, Nwk_ObjArrival(pTemp), (float)0.01 ) )
continue;
Nwk_ObjSetArrival( pTemp, tArrival );
// add the fanouts to the queue
if ( Nwk_ObjIsCo(pTemp) )
{
if ( pManTime )
{
// it may happen that a box-input (CO) was already marked as visited
// when some other box-input of the same box was visited - here we undo this
iBox = Tim_ManBoxForCo( pManTime, pTemp->PioId );
if ( Tim_ManIsCoTravIdCurrent( pManTime, pTemp->PioId ) )
Tim_ManSetPreviousTravIdBoxInputs( pManTime, iBox );
Tim_ManSetCoArrival( pManTime, pTemp->PioId, tArrival );
if ( iBox >= 0 ) // this CO is an input of the box
{
Tim_ManSetCurrentTravIdBoxInputs( pManTime, iBox );
iTerm1 = Tim_ManBoxOutputFirst( pManTime, iBox );
nTerms = Tim_ManBoxOutputNum( pManTime, iBox );
for ( k = 0; k < nTerms; k++ )
{
pNext = Nwk_ManCi(pNext->pMan, iTerm1 + k);
if ( pNext->MarkA )
continue;
Nwk_NodeUpdateAddToQueue( vQueue, pNext, iCur, 1 );
pNext->MarkA = 1;
}
}
}
}
else
{
Nwk_ObjForEachFanout( pTemp, pNext, k )
{
if ( pNext->MarkA )
continue;
Nwk_NodeUpdateAddToQueue( vQueue, pNext, iCur, 1 );
pNext->MarkA = 1;
}
}
}
}
/**Function*************************************************************
Synopsis [Incrementally updates required times of the node.]
Description [Supports variable-pin delay model and white-boxes.]
SideEffects []
SeeAlso []
***********************************************************************/
void Nwk_NodeUpdateRequired( Nwk_Obj_t * pObj )
{
If_Lib_t * pLutLib = pObj->pMan->pLutLib;
Tim_Man_t * pManTime = pObj->pMan->pManTime;
Vec_Ptr_t * vQueue = pObj->pMan->vTemp;
Nwk_Obj_t * pTemp, * pNext;
float tRequired;
int iCur, k, iBox, iTerm1, nTerms;
assert( Nwk_ObjIsNode(pObj) );
// make sure the node's required time remained the same
tRequired = Nwk_NodeComputeRequired( pObj, 1 );
assert( Nwk_ManTimeEqual( tRequired, Nwk_ObjRequired(pObj), (float)0.01 ) );
// initialize the queue with the node's faninsa and the old node's fanins
Vec_PtrClear( vQueue );
Nwk_ObjForEachFanin( pObj, pNext, k )
{
if ( pNext->MarkA )
continue;
Nwk_NodeUpdateAddToQueue( vQueue, pNext, -1, 0 );
pNext->MarkA = 1;
}
// process objects
if ( pManTime )
Tim_ManIncrementTravId( pManTime );
Vec_PtrForEachEntry( vQueue, pTemp, iCur )
{
pTemp->MarkA = 0;
tRequired = Nwk_NodeComputeRequired( pTemp, 1 );
if ( Nwk_ObjIsCo(pTemp) && pManTime )
tRequired = Tim_ManGetCoRequired( pManTime, pTemp->PioId );
if ( Nwk_ManTimeEqual( tRequired, Nwk_ObjRequired(pTemp), (float)0.01 ) )
continue;
Nwk_ObjSetRequired( pTemp, tRequired );
// add the fanins to the queue
if ( Nwk_ObjIsCi(pTemp) )
{
if ( pManTime )
{
// it may happen that a box-output (CI) was already marked as visited
// when some other box-output of the same box was visited - here we undo this
iBox = Tim_ManBoxForCi( pManTime, pTemp->PioId );
if ( Tim_ManIsCiTravIdCurrent( pManTime, pTemp->PioId ) )
Tim_ManSetPreviousTravIdBoxOutputs( pManTime, iBox );
Tim_ManSetCiRequired( pManTime, pTemp->PioId, tRequired );
if ( iBox >= 0 ) // this CI is an output of the box
{
Tim_ManSetCurrentTravIdBoxOutputs( pManTime, iBox );
iTerm1 = Tim_ManBoxInputFirst( pManTime, iBox );
nTerms = Tim_ManBoxInputNum( pManTime, iBox );
for ( k = 0; k < nTerms; k++ )
{
pNext = Nwk_ManCo(pNext->pMan, iTerm1 + k);
if ( pNext->MarkA )
continue;
Nwk_NodeUpdateAddToQueue( vQueue, pNext, iCur, 0 );
pNext->MarkA = 1;
}
}
}
}
else
{
Nwk_ObjForEachFanin( pTemp, pNext, k )
{
if ( pNext->MarkA )
continue;
Nwk_NodeUpdateAddToQueue( vQueue, pNext, iCur, 0 );
pNext->MarkA = 1;
}
}
}
}
/**Function*************************************************************
Synopsis [Computes the level of the node using its fanin levels.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Nwk_ObjLevelNew( Nwk_Obj_t * pObj )
{
Tim_Man_t * pManTime = pObj->pMan->pManTime;
Nwk_Obj_t * pFanin;
int i, iBox, iTerm1, nTerms, Level = 0;
if ( Nwk_ObjIsCi(pObj) || Nwk_ObjIsLatch(pObj) )
{
if ( pManTime )
{
iBox = Tim_ManBoxForCi( pManTime, pObj->PioId );
if ( iBox >= 0 ) // this CI is an output of the box
{
iTerm1 = Tim_ManBoxInputFirst( pManTime, iBox );
nTerms = Tim_ManBoxInputNum( pManTime, iBox );
for ( i = 0; i < nTerms; i++ )
{
pFanin = Nwk_ManCo(pObj->pMan, iTerm1 + i);
Level = AIG_MAX( Level, Nwk_ObjLevel(pFanin) );
}
Level++;
}
}
return Level;
}
assert( Nwk_ObjIsNode(pObj) || Nwk_ObjIsCo(pObj) );
Nwk_ObjForEachFanin( pObj, pFanin, i )
Level = AIG_MAX( Level, Nwk_ObjLevel(pFanin) );
return Level + (Nwk_ObjIsNode(pObj) && Nwk_ObjFaninNum(pObj) > 0);
}
/**Function*************************************************************
Synopsis [Incrementally updates level of the nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Nwk_ManUpdateLevel( Nwk_Obj_t * pObj )
{
Tim_Man_t * pManTime = pObj->pMan->pManTime;
Vec_Ptr_t * vQueue = pObj->pMan->vTemp;
Nwk_Obj_t * pTemp, * pNext;
int LevelNew, iCur, k, iBox, iTerm1, nTerms;
assert( Nwk_ObjIsNode(pObj) );
// initialize the queue with the node
Vec_PtrClear( vQueue );
Vec_PtrPush( vQueue, pObj );
pObj->MarkA = 1;
// process objects
Vec_PtrForEachEntry( vQueue, pTemp, iCur )
{
pTemp->MarkA = 0;
LevelNew = Nwk_ObjLevelNew( pTemp );
if ( LevelNew == Nwk_ObjLevel(pTemp) )
continue;
Nwk_ObjSetLevel( pTemp, LevelNew );
// add the fanouts to the queue
if ( Nwk_ObjIsCo(pTemp) )
{
if ( pManTime )
{
iBox = Tim_ManBoxForCo( pManTime, pTemp->PioId );
if ( iBox >= 0 ) // this is not a true PO
{
Tim_ManSetCurrentTravIdBoxInputs( pManTime, iBox );
iTerm1 = Tim_ManBoxOutputFirst( pManTime, iBox );
nTerms = Tim_ManBoxOutputNum( pManTime, iBox );
for ( k = 0; k < nTerms; k++ )
{
pNext = Nwk_ManCi(pNext->pMan, iTerm1 + k);
if ( pNext->MarkA )
continue;
Nwk_NodeUpdateAddToQueue( vQueue, pNext, iCur, 1 );
pNext->MarkA = 1;
}
}
}
}
else
{
Nwk_ObjForEachFanout( pTemp, pNext, k )
{
if ( pNext->MarkA )
continue;
Nwk_NodeUpdateAddToQueue( vQueue, pNext, iCur, 1 );
pNext->MarkA = 1;
}
}
}
}
/**Function*************************************************************
Synopsis [Computes the level of the node using its fanin levels.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Nwk_ManVerifyLevel( Nwk_Man_t * pNtk )
{
Nwk_Obj_t * pObj;
int LevelNew, i;
Nwk_ManForEachObj( pNtk, pObj, i )
{
assert( pObj->MarkA == 0 );
LevelNew = Nwk_ObjLevelNew( pObj );
if ( Nwk_ObjLevel(pObj) != LevelNew )
{
printf( "Object %6d: Mismatch betweeh levels: Actual = %d. Correct = %d.\n",
i, Nwk_ObjLevel(pObj), LevelNew );
}
}
return 1;
}
/**Function*************************************************************
Synopsis [Replaces the node and incrementally updates levels.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Nwk_ManUpdate( Nwk_Obj_t * pObj, Nwk_Obj_t * pObjNew, Vec_Vec_t * vLevels )
{
assert( pObj->pMan == pObjNew->pMan );
assert( pObj != pObjNew );
assert( Nwk_ObjFanoutNum(pObj) > 0 );
assert( Nwk_ObjIsNode(pObj) && !Nwk_ObjIsCo(pObjNew) );
// transfer fanouts to the old node
Nwk_ObjTransferFanout( pObj, pObjNew );
// transfer the timing information
// (this is needed because updating level happens if the level has changed;
// when we set the old level, it will be recomputed by the level updating
// procedure, which will update level of other nodes if there is a difference)
pObjNew->Level = pObj->Level;
pObjNew->tArrival = pObj->tArrival;
pObjNew->tRequired = pObj->tRequired;
// update required times of the old fanins
pObj->tRequired = TIM_ETERNITY;
Nwk_NodeUpdateRequired( pObj );
// remove the old node
Nwk_ManDeleteNode_rec( pObj );
// update the information of the new node
Nwk_ManUpdateLevel( pObjNew );
Nwk_NodeUpdateArrival( pObjNew );
Nwk_NodeUpdateRequired( pObjNew );
//Nwk_ManVerifyTiming( pObjNew->pMan );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
|