ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sclDnsize.c
Go to the documentation of this file.
1
20
21#include "sclSize.h"
22
24
25
29
33
45void Abc_SclFindWindow( Abc_Obj_t * pPivot, Vec_Int_t ** pvNodes, Vec_Int_t ** pvEvals )
46{
47 Abc_Ntk_t * p = Abc_ObjNtk(pPivot);
48 Abc_Obj_t * pObj, * pNext, * pNext2;
49 Vec_Int_t * vNodes = *pvNodes;
50 Vec_Int_t * vEvals = *pvEvals;
51 int i, k;
52 assert( Abc_ObjIsNode(pPivot) );
53 // collect fanins, node, and fanouts
54 Vec_IntClear( vNodes );
55 Abc_ObjForEachFanin( pPivot, pNext, i )
56// if ( Abc_ObjIsNode(pNext) && Abc_ObjFaninNum(pNext) > 0 )
57 if ( Abc_ObjIsCi(pNext) || Abc_ObjFaninNum(pNext) > 0 )
58 Vec_IntPush( vNodes, Abc_ObjId(pNext) );
59 Vec_IntPush( vNodes, Abc_ObjId(pPivot) );
60 Abc_ObjForEachFanout( pPivot, pNext, i )
61 if ( Abc_ObjIsNode(pNext) )
62 {
63 Vec_IntPush( vNodes, Abc_ObjId(pNext) );
64 Abc_ObjForEachFanout( pNext, pNext2, k )
65 if ( Abc_ObjIsNode(pNext2) )
66 Vec_IntPush( vNodes, Abc_ObjId(pNext2) );
67 }
68 Vec_IntUniqify( vNodes );
69 // label nodes
70 Abc_NtkForEachObjVec( vNodes, p, pObj, i )
71 {
72 assert( pObj->fMarkB == 0 );
73 pObj->fMarkB = 1;
74 }
75 // collect nodes visible from the critical paths
76 Vec_IntClear( vEvals );
77 Abc_NtkForEachObjVec( vNodes, p, pObj, i )
78 Abc_ObjForEachFanout( pObj, pNext, k )
79 if ( !pNext->fMarkB )
80 {
81 assert( pObj->fMarkB );
82 Vec_IntPush( vEvals, Abc_ObjId(pObj) );
83 break;
84 }
85 assert( Vec_IntSize(vEvals) > 0 );
86 // label nodes
87 Abc_NtkForEachObjVec( vNodes, p, pObj, i )
88 pObj->fMarkB = 0;
89}
90
102int Abc_SclCheckImprovement( SC_Man * p, Abc_Obj_t * pObj, Vec_Int_t * vNodes, Vec_Int_t * vEvals, int Notches, int DelayGap )
103{
104 Abc_Obj_t * pTemp;
105 SC_Cell * pCellOld, * pCellNew;
106 float dGain, dGainBest;
107 int i, k, gateBest;
108 abctime clk;
109clk = Abc_Clock();
110// printf( "%d -> %d\n", Vec_IntSize(vNodes), Vec_IntSize(vEvals) );
111 // save old gate, timing, fanin load
112 pCellOld = Abc_SclObjCell( pObj );
113 Abc_SclConeStore( p, vNodes );
114 Abc_SclEvalStore( p, vEvals );
115 Abc_SclLoadStore( p, pObj );
116 // try different gate sizes for this node
117 gateBest = -1;
118 dGainBest = -DelayGap;
119 SC_RingForEachCellRev( pCellOld, pCellNew, i )
120 {
121 if ( pCellNew->area >= pCellOld->area )
122 continue;
123 if ( i > Notches )
124 break;
125 // set new cell
126 Abc_SclObjSetCell( pObj, pCellNew );
127 Abc_SclUpdateLoad( p, pObj, pCellOld, pCellNew );
128 // recompute timing
129 Abc_SclTimeCone( p, vNodes );
130 // set old cell
131 Abc_SclObjSetCell( pObj, pCellOld );
132 Abc_SclLoadRestore( p, pObj );
133 // evaluate gain
134 dGain = Abc_SclEvalPerformLegal( p, vEvals, p->MaxDelay0 );
135 if ( dGain == -1 )
136 continue;
137 // save best gain
138 if ( dGainBest < dGain )
139 {
140 dGainBest = dGain;
141 gateBest = pCellNew->Id;
142 }
143 }
144 // put back old cell and timing
145 Abc_SclObjSetCell( pObj, pCellOld );
146 Abc_SclConeRestore( p, vNodes );
147p->timeSize += Abc_Clock() - clk;
148 if ( gateBest >= 0 )
149 {
150 pCellNew = SC_LibCell( p->pLib, gateBest );
151 Abc_SclObjSetCell( pObj, pCellNew );
152 p->SumArea += pCellNew->area - pCellOld->area;
153// printf( "%f %f -> %f\n", pCellNew->area - pCellOld->area, p->SumArea - (pCellNew->area - pCellOld->area), p->SumArea );
154// printf( "%6d %20s -> %20s %f -> %f\n", Abc_ObjId(pObj), pCellOld->pName, pCellNew->pName, pCellOld->area, pCellNew->area );
155 // mark used nodes with the current trav ID
156 Abc_NtkForEachObjVec( vNodes, p->pNtk, pTemp, k )
157 Abc_NodeSetTravIdCurrent( pTemp );
158 // update load and timing...
159 Abc_SclUpdateLoad( p, pObj, pCellOld, pCellNew );
160 Abc_SclTimeIncInsert( p, pObj );
161 return 1;
162 }
163 return 0;
164}
165
178{
179 Abc_Obj_t * pObj;
180 int i;
181 assert( Vec_QueSize(p->vNodeByGain) == 0 );
182 Vec_QueClear( p->vNodeByGain );
183 Abc_NtkForEachNode( pNtk, pObj, i )
184 if ( Abc_ObjFaninNum(pObj) > 0 )
185 {
186 Vec_FltWriteEntry( p->vNode2Gain, Abc_ObjId(pObj), Abc_SclObjCell(pObj)->area );
187 Vec_QuePush( p->vNodeByGain, Abc_ObjId(pObj) );
188 }
189}
191{
192 Abc_Obj_t * pObj;
193 int i;
194 Abc_NtkForEachObjVec( vNodes, pNtk, pObj, i )
195 if ( Abc_NodeIsTravIdCurrent(pObj) )
196 return 1;
197 return 0;
198}
199
211void Abc_SclDnsizePrint( SC_Man * p, int Iter, int nAttempts, int nOverlaps, int nChanges, int fVerbose )
212{
213 if ( Iter == -1 )
214 printf( "Total : " );
215 else
216 printf( "%5d : ", Iter );
217 printf( "Try =%6d ", nAttempts );
218 printf( "Over =%6d ", nOverlaps );
219 printf( "Fail =%6d ", nAttempts-nOverlaps-nChanges );
220 printf( "Win =%6d ", nChanges );
221 printf( "A: " );
222 printf( "%.2f ", p->SumArea );
223 printf( "(%+5.1f %%) ", 100.0 * (p->SumArea - p->SumArea0)/ p->SumArea0 );
224 printf( "D: " );
225 printf( "%.2f ps ", p->MaxDelay );
226 printf( "(%+5.1f %%) ", 100.0 * (p->MaxDelay - p->MaxDelay0)/ p->MaxDelay0 );
227 printf( "%8.2f sec ", 1.0*(Abc_Clock() - p->timeTotal)/(CLOCKS_PER_SEC) );
228 printf( "%c", fVerbose ? '\n' : '\r' );
229}
230
242void Abc_SclDnsizePerformInt( SC_Lib * pLib, Abc_Ntk_t * pNtk, SC_SizePars * pPars, void * pFuncFanin )
243{
244 SC_Man * p;
245 Abc_Obj_t * pObj;
246 Vec_Int_t * vNodes, * vEvals, * vTryLater;
247 abctime clk, nRuntimeLimit = pPars->TimeOut ? pPars->TimeOut * CLOCKS_PER_SEC + Abc_Clock() : 0;
248 int i, k;
249
250 if ( pPars->fVerbose )
251 {
252 printf( "Parameters: " );
253 printf( "Iters =%5d. ", pPars->nIters );
254 printf( "UseDept =%2d. ", pPars->fUseDept );
255 printf( "UseWL =%2d. ", pPars->fUseWireLoads );
256 printf( "Target =%5d ps. ", pPars->DelayUser );
257 printf( "DelayGap =%3d ps. ", pPars->DelayGap );
258 printf( "Timeout =%4d sec", pPars->TimeOut );
259 printf( "\n" );
260 }
261
262 // prepare the manager; collect init stats
263 p = Abc_SclManStart( pLib, pNtk, pPars->fUseWireLoads, pPars->fUseDept, pPars->DelayUser, pPars->BuffTreeEst );
264 p->pFuncFanin = (float (*)(void *, Abc_Obj_t *, Abc_Obj_t *, int, int))pFuncFanin;
265 p->timeTotal = Abc_Clock();
266 assert( p->vGatesBest == NULL );
267 p->vGatesBest = Vec_IntDup( p->pNtk->vGates );
268
269 // perform downsizing
270 vNodes = Vec_IntAlloc( 1000 );
271 vEvals = Vec_IntAlloc( 1000 );
272 vTryLater = Vec_IntAlloc( 1000 );
273 for ( i = 0; i < pPars->nIters; i++ )
274 {
275 int nRounds = 0;
276 int nAttemptAll = 0, nOverlapAll = 0, nChangesAll = 0;
278 while ( Vec_QueSize(p->vNodeByGain) > 0 )
279 {
280 int nAttempt = 0, nOverlap = 0, nChanges = 0;
281 Vec_IntClear( vTryLater );
282 Abc_NtkIncrementTravId( pNtk );
283 while ( Vec_QueSize(p->vNodeByGain) > 0 )
284 {
285 clk = Abc_Clock();
286 pObj = Abc_NtkObj( p->pNtk, Vec_QuePop(p->vNodeByGain) );
287 Abc_SclFindWindow( pObj, &vNodes, &vEvals );
288 p->timeCone += Abc_Clock() - clk;
289 if ( Abc_SclCheckOverlap( p->pNtk, vNodes ) )
290 nOverlap++, Vec_IntPush( vTryLater, Abc_ObjId(pObj) );
291 else
292 nChanges += Abc_SclCheckImprovement( p, pObj, vNodes, vEvals, pPars->Notches, pPars->DelayGap );
293 nAttempt++;
294 }
295 Abc_NtkForEachObjVec( vTryLater, pNtk, pObj, k )
296 Vec_QuePush( p->vNodeByGain, Abc_ObjId(pObj) );
297
298 clk = Abc_Clock();
299 if ( Vec_IntSize(p->vChanged) )
301 else
302 Abc_SclTimeNtkRecompute( p, &p->SumArea, &p->MaxDelay, pPars->fUseDept, pPars->DelayUser );
303 p->timeTime += Abc_Clock() - clk;
304
305 p->MaxDelay = Abc_SclReadMaxDelay( p );
306 if ( pPars->fUseDept && pPars->DelayUser > 0 && p->MaxDelay < pPars->DelayUser )
307 p->MaxDelay = pPars->DelayUser;
308 Abc_SclDnsizePrint( p, nRounds++, nAttempt, nOverlap, nChanges, pPars->fVeryVerbose );
309 nAttemptAll += nAttempt; nOverlapAll += nOverlap; nChangesAll += nChanges;
310 if ( nRuntimeLimit && Abc_Clock() > nRuntimeLimit )
311 break;
312 }
313 // recompute
314// Abc_SclTimeNtkRecompute( p, &p->SumArea, &p->MaxDelay, pPars->fUseDept, pPars->DelayUser );
315 if ( pPars->fVerbose )
316 Abc_SclDnsizePrint( p, -1, nAttemptAll, nOverlapAll, nChangesAll, 1 );
317 if ( nRuntimeLimit && Abc_Clock() > nRuntimeLimit )
318 break;
319 if ( nAttemptAll == 0 )
320 break;
321 }
322 Vec_IntFree( vNodes );
323 Vec_IntFree( vEvals );
324 Vec_IntFree( vTryLater );
325 if ( !pPars->fVerbose )
326 printf( " \r" );
327
328 // report runtime
329 p->timeTotal = Abc_Clock() - p->timeTotal;
330 if ( pPars->fVerbose )
331 {
332 p->timeOther = p->timeTotal - p->timeCone - p->timeSize - p->timeTime;
333 ABC_PRTP( "Runtime: Critical path", p->timeCone, p->timeTotal );
334 ABC_PRTP( "Runtime: Sizing eval ", p->timeSize, p->timeTotal );
335 ABC_PRTP( "Runtime: Timing update", p->timeTime, p->timeTotal );
336 ABC_PRTP( "Runtime: Other ", p->timeOther, p->timeTotal );
337 ABC_PRTP( "Runtime: TOTAL ", p->timeTotal, p->timeTotal );
338 }
339 if ( pPars->fDumpStats )
340 Abc_SclDumpStats( p, "stats2.txt", p->timeTotal );
341 if ( nRuntimeLimit && Abc_Clock() > nRuntimeLimit )
342 printf( "Gate sizing timed out at %d seconds.\n", pPars->TimeOut );
343
344 // save the result and quit
345 Abc_SclSclGates2MioGates( pLib, pNtk ); // updates gate pointers
346 Abc_SclManFree( p );
347// Abc_NtkCleanMarkAB( pNtk );
348}
349
361void Abc_SclDnsizePerform( SC_Lib * pLib, Abc_Ntk_t * pNtk, SC_SizePars * pPars, void * pFuncFanin )
362{
363 Abc_Ntk_t * pNtkNew = pNtk;
364 if ( pNtk->nBarBufs2 > 0 )
365 pNtkNew = Abc_NtkDupDfsNoBarBufs( pNtk );
366 Abc_SclDnsizePerformInt( pLib, pNtkNew, pPars, pFuncFanin );
367 if ( pNtk->nBarBufs2 > 0 )
368 Abc_SclTransferGates( pNtk, pNtkNew );
369 if ( pNtk->nBarBufs2 > 0 )
370 Abc_NtkDelete( pNtkNew );
371}
372
376
377
379
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL Abc_Ntk_t * Abc_NtkDupDfsNoBarBufs(Abc_Ntk_t *pNtk)
Definition abcNtk.c:578
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition abc.h:529
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
#define Abc_NtkForEachObjVec(vIds, pNtk, pObj, i)
Definition abc.h:455
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRTP(a, t, T)
Definition abc_global.h:258
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
ABC_NAMESPACE_IMPL_START void Abc_SclFindWindow(Abc_Obj_t *pPivot, Vec_Int_t **pvNodes, Vec_Int_t **pvEvals)
DECLARATIONS ///.
Definition sclDnsize.c:45
void Abc_SclDnsizePrint(SC_Man *p, int Iter, int nAttempts, int nOverlaps, int nChanges, int fVerbose)
Definition sclDnsize.c:211
void Abc_NtkCollectNodesByArea(SC_Man *p, Abc_Ntk_t *pNtk)
Definition sclDnsize.c:177
int Abc_SclCheckOverlap(Abc_Ntk_t *pNtk, Vec_Int_t *vNodes)
Definition sclDnsize.c:190
void Abc_SclDnsizePerformInt(SC_Lib *pLib, Abc_Ntk_t *pNtk, SC_SizePars *pPars, void *pFuncFanin)
Definition sclDnsize.c:242
void Abc_SclDnsizePerform(SC_Lib *pLib, Abc_Ntk_t *pNtk, SC_SizePars *pPars, void *pFuncFanin)
Definition sclDnsize.c:361
int Abc_SclCheckImprovement(SC_Man *p, Abc_Obj_t *pObj, Vec_Int_t *vNodes, Vec_Int_t *vEvals, int Notches, int DelayGap)
Definition sclDnsize.c:102
struct SC_SizePars_ SC_SizePars
Definition sclLib.h:82
struct SC_Lib_ SC_Lib
Definition sclLib.h:128
#define SC_RingForEachCellRev(pRing, pCell, i)
Definition sclLib.h:278
struct SC_Cell_ SC_Cell
Definition sclLib.h:127
void Abc_SclUpdateLoad(SC_Man *p, Abc_Obj_t *pObj, SC_Cell *pOld, SC_Cell *pNew)
Definition sclLoad.c:201
int Abc_SclTimeIncUpdate(SC_Man *p)
Definition sclSize.c:555
void Abc_SclTimeCone(SC_Man *p, Vec_Int_t *vCone)
Definition sclSize.c:398
void Abc_SclTimeIncInsert(SC_Man *p, Abc_Obj_t *pObj)
Definition sclSize.c:577
SC_Man * Abc_SclManStart(SC_Lib *pLib, Abc_Ntk_t *pNtk, int fUseWireLoads, int fDept, float DUser, int nTreeCRatio)
Definition sclSize.c:648
void Abc_SclTimeNtkRecompute(SC_Man *p, float *pArea, float *pDelay, int fReverse, float DUser)
Definition sclSize.c:415
void Abc_SclSclGates2MioGates(SC_Lib *pLib, Abc_Ntk_t *p)
Definition sclUtil.c:70
void Abc_SclTransferGates(Abc_Ntk_t *pOld, Abc_Ntk_t *pNew)
Definition sclUtil.c:102
typedefABC_NAMESPACE_HEADER_START struct SC_Man_ SC_Man
INCLUDES ///.
Definition sclSize.h:44
int nBarBufs2
Definition abc.h:175
unsigned fMarkB
Definition abc.h:135
float area
Definition sclLib.h:207
int Id
Definition sclLib.h:203
int DelayUser
Definition sclLib.h:90
int fDumpStats
Definition sclLib.h:96
int Notches
Definition sclLib.h:89
int fUseDept
Definition sclLib.h:95
int nIters
Definition sclLib.h:85
int fVerbose
Definition sclLib.h:98
int fVeryVerbose
Definition sclLib.h:99
int DelayGap
Definition sclLib.h:91
int BuffTreeEst
Definition sclLib.h:93
int TimeOut
Definition sclLib.h:92
int fUseWireLoads
Definition sclLib.h:97
#define assert(ex)
Definition util_old.h:213