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
|
/**CFile****************************************************************
FileName [sclUpsize.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Standard-cell library representation.]
Synopsis [Selective increase of gate sizes.]
Author [Alan Mishchenko, Niklas Een]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - August 24, 2012.]
Revision [$Id: sclUpsize.c,v 1.0 2012/08/24 00:00:00 alanmi Exp $]
***********************************************************************/
#include "sclSize.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Collect TFO of nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_SclFindTFO_rec( Abc_Obj_t * pObj, Vec_Int_t * vNodes, Vec_Int_t * vCos )
{
Abc_Obj_t * pNext;
int i;
if ( Abc_NodeIsTravIdCurrent( pObj ) )
return;
Abc_NodeSetTravIdCurrent( pObj );
if ( Abc_ObjIsCo(pObj) )
{
Vec_IntPush( vCos, Abc_ObjId(pObj) );
return;
}
assert( Abc_ObjIsNode(pObj) );
Abc_ObjForEachFanout( pObj, pNext, i )
Abc_SclFindTFO_rec( pNext, vNodes, vCos );
if ( Abc_ObjFaninNum(pObj) > 0 )
Vec_IntPush( vNodes, Abc_ObjId(pObj) );
}
Vec_Int_t * Abc_SclFindTFO( Abc_Ntk_t * p, Vec_Int_t * vPath )
{
Vec_Int_t * vNodes, * vCos;
Abc_Obj_t * pObj, * pFanin;
int i, k;
assert( Vec_IntSize(vPath) > 0 );
vCos = Vec_IntAlloc( 100 );
vNodes = Vec_IntAlloc( 100 );
// collect nodes in the TFO
Abc_NtkIncrementTravId( p );
Abc_NtkForEachObjVec( vPath, p, pObj, i )
Abc_ObjForEachFanin( pObj, pFanin, k )
if ( Abc_ObjIsNode(pFanin) )
Abc_SclFindTFO_rec( pFanin, vNodes, vCos );
// reverse order
Vec_IntReverseOrder( vNodes );
// Vec_IntSort( vNodes, 0 );
//Vec_IntPrint( vNodes );
//Vec_IntPrint( vCos );
Vec_IntAppend( vNodes, vCos );
Vec_IntFree( vCos );
return vNodes;
}
/**Function*************************************************************
Synopsis [Collect near-critical COs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Abc_SclFindCriticalCoWindow( SC_Man * p, int Window )
{
float fMaxArr = Abc_SclReadMaxDelay( p ) * (100.0 - Window) / 100.0;
Vec_Int_t * vPivots;
Abc_Obj_t * pObj;
int i;
vPivots = Vec_IntAlloc( 100 );
Abc_NtkForEachCo( p->pNtk, pObj, i )
if ( Abc_SclObjTimeMax(p, pObj) >= fMaxArr )
Vec_IntPush( vPivots, Abc_ObjId(pObj) );
assert( Vec_IntSize(vPivots) > 0 );
return vPivots;
}
/**Function*************************************************************
Synopsis [Collect near-critical internal nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_SclFindCriticalNodeWindow_rec( SC_Man * p, Abc_Obj_t * pObj, Vec_Int_t * vPath, float fSlack, int fDept )
{
Abc_Obj_t * pNext;
float fArrMax, fSlackFan;
int i;
if ( Abc_ObjIsCi(pObj) )
return;
if ( Abc_NodeIsTravIdCurrent( pObj ) )
return;
Abc_NodeSetTravIdCurrent( pObj );
assert( Abc_ObjIsNode(pObj) );
// compute the max arrival time of the fanins
if ( fDept )
fArrMax = p->pSlack[Abc_ObjId(pObj)];
else
fArrMax = Abc_SclGetMaxDelayNodeFanins( p, pObj );
assert( fArrMax >= 0 );
// traverse all fanins whose arrival times are within a window
Abc_ObjForEachFanin( pObj, pNext, i )
{
if ( Abc_ObjIsCi(pNext) || Abc_ObjFaninNum(pNext) == 0 )
continue;
assert( Abc_ObjIsNode(pNext) );
if ( fDept )
fSlackFan = fSlack - (p->pSlack[Abc_ObjId(pNext)] - fArrMax);
else
fSlackFan = fSlack - (fArrMax - Abc_SclObjTimeMax(p, pNext));
if ( fSlackFan >= 0 )
Abc_SclFindCriticalNodeWindow_rec( p, pNext, vPath, fSlackFan, fDept );
}
if ( Abc_ObjFaninNum(pObj) > 0 )
Vec_IntPush( vPath, Abc_ObjId(pObj) );
}
Vec_Int_t * Abc_SclFindCriticalNodeWindow( SC_Man * p, Vec_Int_t * vPathCos, int Window, int fDept )
{
float fMaxArr = Abc_SclReadMaxDelay( p );
float fSlackMax = fMaxArr * Window / 100.0;
Vec_Int_t * vPath = Vec_IntAlloc( 100 );
Abc_Obj_t * pObj;
int i;
Abc_NtkIncrementTravId( p->pNtk );
Abc_NtkForEachObjVec( vPathCos, p->pNtk, pObj, i )
{
float fSlackThis = fSlackMax - (fMaxArr - Abc_SclObjTimeMax(p, pObj));
if ( fSlackThis >= 0 )
Abc_SclFindCriticalNodeWindow_rec( p, Abc_ObjFanin0(pObj), vPath, fSlackThis, fDept );
}
// label critical nodes
Abc_NtkForEachObjVec( vPathCos, p->pNtk, pObj, i )
pObj->fMarkA = 1;
Abc_NtkForEachObjVec( vPath, p->pNtk, pObj, i )
pObj->fMarkA = 1;
return vPath;
}
void Abc_SclUnmarkCriticalNodeWindow( SC_Man * p, Vec_Int_t * vPath )
{
Abc_Obj_t * pObj;
int i;
Abc_NtkForEachObjVec( vPath, p->pNtk, pObj, i )
pObj->fMarkA = 0;
}
/**Function*************************************************************
Synopsis [Find the array of nodes to be updated.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_SclFindNodesToUpdate( Abc_Obj_t * pPivot, Vec_Int_t ** pvNodes, Vec_Int_t ** pvEvals )
{
Abc_Ntk_t * p = Abc_ObjNtk(pPivot);
Abc_Obj_t * pObj, * pNext, * pNext2;
Vec_Int_t * vNodes = *pvNodes;
Vec_Int_t * vEvals = *pvEvals;
int i, k;
assert( Abc_ObjIsNode(pPivot) );
assert( pPivot->fMarkA );
// collect fanins, node, and fanouts
Vec_IntClear( vNodes );
Abc_ObjForEachFanin( pPivot, pNext, i )
if ( Abc_ObjIsNode(pNext) && Abc_ObjFaninNum(pNext) > 0 )
Vec_IntPush( vNodes, Abc_ObjId(pNext) );
Vec_IntPush( vNodes, Abc_ObjId(pPivot) );
Abc_ObjForEachFanout( pPivot, pNext, i )
if ( Abc_ObjIsNode(pNext) && pNext->fMarkA )
{
Vec_IntPush( vNodes, Abc_ObjId(pNext) );
Abc_ObjForEachFanout( pNext, pNext2, k )
if ( Abc_ObjIsNode(pNext2) && pNext2->fMarkA )
Vec_IntPush( vNodes, Abc_ObjId(pNext2) );
}
Vec_IntUniqify( vNodes );
// label nodes
Abc_NtkForEachObjVec( vNodes, p, pObj, i )
{
assert( pObj->fMarkB == 0 );
pObj->fMarkB = 1;
}
// collect nodes visible from the critical paths
Vec_IntClear( vEvals );
Abc_NtkForEachObjVec( vNodes, p, pObj, i )
Abc_ObjForEachFanout( pObj, pNext, k )
if ( pNext->fMarkA && !pNext->fMarkB )
// if ( !pNext->fMarkB )
{
assert( pObj->fMarkB );
Vec_IntPush( vEvals, Abc_ObjId(pObj) );
break;
}
assert( Vec_IntSize(vEvals) > 0 );
// label nodes
Abc_NtkForEachObjVec( vNodes, p, pObj, i )
pObj->fMarkB = 0;
}
/**Function*************************************************************
Synopsis [Computes the set of gates to upsize.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_SclFindUpsizes( SC_Man * p, Vec_Int_t * vPathNodes, int Ratio, int Notches, int iIter, int DelayGap )
{
SC_Cell * pCellOld, * pCellNew;
Vec_Int_t * vRecalcs, * vEvals;
Abc_Obj_t * pObj, * pTemp;
float dGain, dGainBest;
int i, k, n, gateBest, Limit, iIterLast;
// compute savings due to upsizing each node
vRecalcs = Vec_IntAlloc( 100 );
vEvals = Vec_IntAlloc( 100 );
Vec_QueClear( p->vNodeByGain );
Abc_NtkForEachObjVec( vPathNodes, p->pNtk, pObj, i )
{
iIterLast = Vec_IntEntry(p->vNodeIter, Abc_ObjId(pObj));
if ( iIterLast >= 0 && iIterLast + 5 > iIter )
continue;
// compute nodes to recalculate timing and nodes to evaluate afterwards
Abc_SclFindNodesToUpdate( pObj, &vRecalcs, &vEvals );
assert( Vec_IntSize(vEvals) > 0 );
//printf( "%d -> %d\n", Vec_IntSize(vRecalcs), Vec_IntSize(vEvals) );
// save old gate, timing, fanin load
pCellOld = Abc_SclObjCell( p, pObj );
Abc_SclConeStore( p, vRecalcs );
Abc_SclLoadStore( p, pObj );
// try different gate sizes for this node
gateBest = -1;
dGainBest = -SC_LibTimeFromPs(p->pLib, (float)DelayGap);
SC_RingForEachCell( pCellOld, pCellNew, k )
{
if ( pCellNew == pCellOld )
continue;
if ( k > Notches )
break;
if ( p->pInDrive && !Abc_SclInputDriveOk( p, pObj, pCellNew ) )
continue;
// set new cell
Abc_SclObjSetCell( p, pObj, pCellNew );
Abc_SclUpdateLoad( p, pObj, pCellOld, pCellNew );
// recompute timing
Abc_SclTimeCone( p, vRecalcs );
// set old cell
Abc_SclObjSetCell( p, pObj, pCellOld );
Abc_SclLoadRestore( p, pObj );
// evaluate gain
dGain = 0.0;
Abc_NtkForEachObjVec( vEvals, p->pNtk, pTemp, n )
dGain += Abc_SclObjGain( p, pTemp );
dGain /= Vec_IntSize(vEvals);
// save best gain
if ( dGainBest < dGain )
{
dGainBest = dGain;
gateBest = pCellNew->Id;
}
}
// remember savings
if ( gateBest >= 0 )
{
assert( dGainBest > 0.0 );
Vec_FltWriteEntry( p->vNode2Gain, Abc_ObjId(pObj), dGainBest );
Vec_IntWriteEntry( p->vNode2Gate, Abc_ObjId(pObj), gateBest );
Vec_QuePush( p->vNodeByGain, Abc_ObjId(pObj) );
}
// put back old cell and timing
Abc_SclObjSetCell( p, pObj, pCellOld );
Abc_SclConeRestore( p, vRecalcs );
}
Vec_IntFree( vRecalcs );
Vec_IntFree( vEvals );
if ( Vec_QueSize(p->vNodeByGain) == 0 )
return 0;
Limit = Abc_MinInt( Vec_QueSize(p->vNodeByGain), Abc_MaxInt((int)(0.01 * Ratio * Vec_IntSize(vPathNodes)), 1) );
//printf( "\nSelecting %d out of %d\n", Limit, Vec_QueSize(p->vNodeByGain) );
for ( i = 0; i < Limit; i++ )
{
// get the object
pObj = Abc_NtkObj( p->pNtk, Vec_QuePop(p->vNodeByGain) );
assert( pObj->fMarkA );
// find old and new gates
pCellOld = Abc_SclObjCell( p, pObj );
pCellNew = SC_LibCell( p->pLib, Vec_IntEntry(p->vNode2Gate, Abc_ObjId(pObj)) );
assert( pCellNew != NULL );
//printf( "%6d %20s -> %20s ", Abc_ObjId(pObj), pCellOld->pName, pCellNew->pName );
//printf( "gain is %f\n", Vec_FltEntry(p->vNode2Gain, Abc_ObjId(pObj)) );
// update gate
Abc_SclUpdateLoad( p, pObj, pCellOld, pCellNew );
p->SumArea += pCellNew->area - pCellOld->area;
Abc_SclObjSetCell( p, pObj, pCellNew );
// record the update
Vec_IntPush( p->vUpdates, Abc_ObjId(pObj) );
Vec_IntPush( p->vUpdates, pCellNew->Id );
// remember when this node was upsized
Vec_IntWriteEntry( p->vNodeIter, Abc_ObjId(pObj), iIter );
}
return Limit;
}
void Abc_SclApplyUpdateToBest( Vec_Int_t * vGates, Vec_Int_t * vGatesBest, Vec_Int_t * vUpdate )
{
int i, ObjId, GateId, GateId2;
Vec_IntForEachEntryDouble( vUpdate, ObjId, GateId, i )
Vec_IntWriteEntry( vGatesBest, ObjId, GateId );
Vec_IntClear( vUpdate );
Vec_IntForEachEntryTwo( vGates, vGatesBest, GateId, GateId2, i )
assert( GateId == GateId2 );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_SclUpsizePrintDiffs( SC_Man * p, SC_Lib * pLib, Abc_Ntk_t * pNtk )
{
float fDiff = (float)0.001;
int k;
Abc_Obj_t * pObj;
SC_Pair * pTimes = ABC_ALLOC( SC_Pair, p->nObjs );
SC_Pair * pSlews = ABC_ALLOC( SC_Pair, p->nObjs );
SC_Pair * pLoads = ABC_ALLOC( SC_Pair, p->nObjs );
memcpy( pTimes, p->pTimes, sizeof(SC_Pair) * p->nObjs );
memcpy( pSlews, p->pSlews, sizeof(SC_Pair) * p->nObjs );
memcpy( pLoads, p->pLoads, sizeof(SC_Pair) * p->nObjs );
Abc_SclTimeNtkRecompute( p, NULL, NULL, 0, 0 );
Abc_NtkForEachNode( pNtk, pObj, k )
{
if ( Abc_AbsFloat(p->pLoads[k].rise - pLoads[k].rise) > fDiff )
printf( "%6d : load rise differs %12.6f %f %f\n", k, SC_LibCapFf(pLib, p->pLoads[k].rise)-SC_LibCapFf(pLib, pLoads[k].rise), SC_LibCapFf(pLib, p->pLoads[k].rise), SC_LibCapFf(pLib, pLoads[k].rise) );
if ( Abc_AbsFloat(p->pLoads[k].fall - pLoads[k].fall) > fDiff )
printf( "%6d : load fall differs %12.6f %f %f\n", k, SC_LibCapFf(pLib, p->pLoads[k].fall)-SC_LibCapFf(pLib, pLoads[k].fall), SC_LibCapFf(pLib, p->pLoads[k].fall), SC_LibCapFf(pLib, pLoads[k].fall) );
if ( Abc_AbsFloat(p->pSlews[k].rise - pSlews[k].rise) > fDiff )
printf( "%6d : slew rise differs %12.6f %f %f\n", k, SC_LibTimePs(pLib, p->pSlews[k].rise)-SC_LibTimePs(pLib, pSlews[k].rise), SC_LibTimePs(pLib, p->pSlews[k].rise), SC_LibTimePs(pLib, pSlews[k].rise) );
if ( Abc_AbsFloat(p->pSlews[k].fall - pSlews[k].fall) > fDiff )
printf( "%6d : slew fall differs %12.6f %f %f\n", k, SC_LibTimePs(pLib, p->pSlews[k].fall)-SC_LibTimePs(pLib, pSlews[k].fall), SC_LibTimePs(pLib, p->pSlews[k].fall), SC_LibTimePs(pLib, pSlews[k].fall) );
if ( Abc_AbsFloat(p->pTimes[k].rise - pTimes[k].rise) > fDiff )
printf( "%6d : time rise differs %12.6f %f %f\n", k, SC_LibTimePs(pLib, p->pTimes[k].rise)-SC_LibTimePs(pLib, pTimes[k].rise), SC_LibTimePs(pLib, p->pTimes[k].rise), SC_LibTimePs(pLib, pTimes[k].rise) );
if ( Abc_AbsFloat(p->pTimes[k].fall - pTimes[k].fall) > fDiff )
printf( "%6d : time fall differs %12.6f %f %f\n", k, SC_LibTimePs(pLib, p->pTimes[k].fall)-SC_LibTimePs(pLib, pTimes[k].fall), SC_LibTimePs(pLib, p->pTimes[k].fall), SC_LibTimePs(pLib, pTimes[k].fall) );
}
/*
if ( memcmp( pTimes, p->pTimes, sizeof(SC_Pair) * p->nObjs ) )
printf( "Times differ!\n" );
if ( memcmp( pSlews, p->pSlews, sizeof(SC_Pair) * p->nObjs ) )
printf( "Slews differ!\n" );
if ( memcmp( pLoads, p->pLoads, sizeof(SC_Pair) * p->nObjs ) )
printf( "Loads differ!\n" );
*/
ABC_FREE( pTimes );
ABC_FREE( pSlews );
ABC_FREE( pLoads );
}
/**Function*************************************************************
Synopsis [Print cumulative statistics.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_SclUpsizePrint( SC_Man * p, int Iter, int win, int nPathPos, int nPathNodes, int nUpsizes, int nTFOs, int fVerbose )
{
printf( "%4d ", Iter );
printf( "Win:%3d. ", win );
printf( "PO:%5d. ", nPathPos );
printf( "Path:%6d. ", nPathNodes );
printf( "Gate:%5d. ", nUpsizes );
printf( "TFO:%6d. ", nTFOs );
printf( "A: " );
printf( "%.2f ", p->SumArea );
printf( "(%+5.1f %%) ", 100.0 * (p->SumArea - p->SumArea0)/ p->SumArea0 );
printf( "D: " );
printf( "%.2f ps ", SC_LibTimePs(p->pLib, p->MaxDelay) );
printf( "(%+5.1f %%) ", 100.0 * (p->MaxDelay - p->MaxDelay0)/ p->MaxDelay0 );
printf( "B: " );
printf( "%.2f ps ", SC_LibTimePs(p->pLib, p->BestDelay) );
printf( "(%+5.1f %%)", 100.0 * (p->BestDelay - p->MaxDelay0)/ p->MaxDelay0 );
printf( "%8.2f sec", 1.0*(Abc_Clock() - p->timeTotal)/(CLOCKS_PER_SEC) );
printf( "%c", fVerbose ? '\n' : '\r' );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_SclUpsizePerform( SC_Lib * pLib, Abc_Ntk_t * pNtk, SC_SizePars * pPars )
{
SC_Man * p;
Vec_Int_t * vPathPos = NULL; // critical POs
Vec_Int_t * vPathNodes = NULL; // critical nodes and PIs
Vec_Int_t * vTFO;
abctime clk, nRuntimeLimit = pPars->TimeOut ? pPars->TimeOut * CLOCKS_PER_SEC + Abc_Clock() : 0;
int i = 0, win, nUpsizes = -1, nFramesNoChange = 0;
int nAllPos, nAllNodes, nAllTfos, nAllUpsizes;
if ( pPars->fVerbose )
{
printf( "Parameters: " );
printf( "Iters =%5d. ", pPars->nIters );
printf( "Time win =%3d %%. ", pPars->Window );
printf( "Update ratio =%3d %%. ", pPars->Ratio );
printf( "UseDept =%2d. ", pPars->fUseDept );
printf( "UseWL =%2d. ", pPars->fUseWireLoads );
printf( "Target =%5d ps. ", pPars->DelayUser );
printf( "DelayGap =%3d ps. ", pPars->DelayGap );
printf( "Timeout =%4d sec", pPars->TimeOut );
printf( "\n" );
}
// prepare the manager; collect init stats
p = Abc_SclManStart( pLib, pNtk, pPars->fUseWireLoads, pPars->fUseDept, 0, pPars->BuffTreeEst );
p->timeTotal = Abc_Clock();
assert( p->vGatesBest == NULL );
p->vGatesBest = Vec_IntDup( p->vGates );
p->BestDelay = p->MaxDelay0;
// perform upsizing
nAllPos = nAllNodes = nAllTfos = nAllUpsizes = 0;
if ( p->BestDelay <= SC_LibTimeFromPs(p->pLib, (float)pPars->DelayUser) )
printf( "Current delay (%.2f ps) is better than the target delay (%.2f ps).\n", SC_LibTimePs(p->pLib, p->BestDelay), (float)pPars->DelayUser );
else
for ( i = 0; i < pPars->nIters; i++ )
{
for ( win = pPars->Window; win <= 100; win *= 2 )
{
// detect critical path
clk = Abc_Clock();
vPathPos = Abc_SclFindCriticalCoWindow( p, win );
vPathNodes = Abc_SclFindCriticalNodeWindow( p, vPathPos, win, pPars->fUseDept );
p->timeCone += Abc_Clock() - clk;
// selectively upsize the nodes
clk = Abc_Clock();
nUpsizes = Abc_SclFindUpsizes( p, vPathNodes, pPars->Ratio, pPars->Notches, i, pPars->DelayGap );
p->timeSize += Abc_Clock() - clk;
// unmark critical path
clk = Abc_Clock();
Abc_SclUnmarkCriticalNodeWindow( p, vPathNodes );
Abc_SclUnmarkCriticalNodeWindow( p, vPathPos );
p->timeCone += Abc_Clock() - clk;
if ( nUpsizes > 0 )
break;
Vec_IntFree( vPathPos );
Vec_IntFree( vPathNodes );
}
if ( nUpsizes == 0 )
break;
// update timing information
clk = Abc_Clock();
if ( pPars->fUseDept )
{
vTFO = Vec_IntAlloc( 0 );
Abc_SclTimeNtkRecompute( p, NULL, NULL, pPars->fUseDept, 0 );
}
else
{
vTFO = Abc_SclFindTFO( p->pNtk, vPathNodes );
Abc_SclTimeCone( p, vTFO );
}
p->timeTime += Abc_Clock() - clk;
// Abc_SclUpsizePrintDiffs( p, pLib, pNtk );
// save the best network
p->MaxDelay = Abc_SclReadMaxDelay( p );
if ( p->BestDelay > p->MaxDelay )
{
p->BestDelay = p->MaxDelay;
Abc_SclApplyUpdateToBest( p->vGates, p->vGatesBest, p->vUpdates );
nFramesNoChange = 0;
}
else
nFramesNoChange++;
// report and cleanup
Abc_SclUpsizePrint( p, i, win, Vec_IntSize(vPathPos), Vec_IntSize(vPathNodes), nUpsizes, Vec_IntSize(vTFO), pPars->fVeryVerbose || (pPars->fVerbose && nFramesNoChange == 0) ); //|| (i == nIters-1) );
nAllPos += Vec_IntSize(vPathPos);
nAllNodes += Vec_IntSize(vPathNodes);
nAllTfos += Vec_IntSize(vTFO);
nAllUpsizes += nUpsizes;
Vec_IntFree( vPathPos );
Vec_IntFree( vPathNodes );
Vec_IntFree( vTFO );
// check timeout
if ( nRuntimeLimit && Abc_Clock() > nRuntimeLimit )
break;
// check no change
if ( nFramesNoChange > pPars->nIterNoChange )
break;
// check best delay
if ( p->BestDelay <= SC_LibTimeFromPs(p->pLib, (float)pPars->DelayUser) )
break;
}
// update for best gates and recompute timing
ABC_SWAP( Vec_Int_t *, p->vGatesBest, p->vGates );
Abc_SclTimeNtkRecompute( p, &p->SumArea, &p->MaxDelay, 0, 0 );
if ( pPars->fVerbose )
Abc_SclUpsizePrint( p, i, pPars->Window, nAllPos/(i?i:1), nAllNodes/(i?i:1), nAllUpsizes/(i?i:1), nAllTfos/(i?i:1), 1 );
else
printf( " \r" );
// report runtime
p->timeTotal = Abc_Clock() - p->timeTotal;
if ( pPars->fVerbose )
{
p->timeOther = p->timeTotal - p->timeCone - p->timeSize - p->timeTime;
ABC_PRTP( "Runtime: Critical path", p->timeCone, p->timeTotal );
ABC_PRTP( "Runtime: Sizing eval ", p->timeSize, p->timeTotal );
ABC_PRTP( "Runtime: Timing update", p->timeTime, p->timeTotal );
ABC_PRTP( "Runtime: Other ", p->timeOther, p->timeTotal );
ABC_PRTP( "Runtime: TOTAL ", p->timeTotal, p->timeTotal );
}
if ( pPars->fDumpStats )
Abc_SclDumpStats( p, "stats2.txt", p->timeTotal );
if ( nRuntimeLimit && Abc_Clock() > nRuntimeLimit )
printf( "Gate sizing timed out at %d seconds.\n", pPars->TimeOut );
// save the result and quit
Abc_SclManSetGates( pLib, pNtk, p->vGates ); // updates gate pointers
Abc_SclManFree( p );
// Abc_NtkCleanMarkAB( pNtk );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|