ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
wlnRetime.c
Go to the documentation of this file.
1
20
21#include "wln.h"
22#include "misc/vec/vecHsh.h"
23
25
29
30typedef struct Wln_Ret_t_ Wln_Ret_t;
32{
33 Wln_Ntk_t * pNtk; // static netlist
34 Vec_Int_t vFanins; // fanins and edge places
35 Vec_Int_t vFanouts; // fanouts and edge places
36 Vec_Int_t vEdgeLinks; // edge links
37 Vec_Int_t vFfClasses; // flop classes
38 Vec_Int_t vNodeDelays; // object delays
39 Vec_Int_t vPathDelays; // delays from sources to sinks
40 Vec_Int_t vSources; // critical sources
41 Vec_Int_t vSinks; // critical sinks
42 Vec_Int_t vFront; // retiming frontier
43 Vec_Int_t vMoves; // retiming moves (paired with delay)
44 int nClasses; // the number of flop classes
45 int DelayMax; // critical delay at any time
46};
47
48static inline int * Wln_RetFanins( Wln_Ret_t * p, int i ) { return Vec_IntEntryP( &p->vFanins, Vec_IntEntry(&p->vFanins, i) ); }
49static inline int * Wln_RetFanouts( Wln_Ret_t * p, int i ) { return Vec_IntEntryP( &p->vFanouts, Vec_IntEntry(&p->vFanouts, i) ); }
50
51#define Wln_RetForEachFanin( p, iObj, iFanin, pLink, i ) \
52 for ( i = 0; (i < Wln_ObjFaninNum(p->pNtk, iObj)) && \
53 (((iFanin) = Wln_RetFanins(p, iObj)[2*i]), 1) && \
54 ((pLink) = (Wln_RetFanins(p, iObj)+2*i+1)); i++ ) if ( !iFanin || (!Wln_ObjFaninNum(p->pNtk, iFanin) && !Wln_ObjIsCi(p->pNtk, iFanin)) ) {} else
55
56#define Wln_RetForEachFanout( p, iObj, iFanout, pLink, i ) \
57 for ( i = 0; (i < Wln_ObjRefs(p->pNtk, iObj)) && \
58 (((iFanout) = Wln_RetFanouts(p, iObj)[2*i]), 1) && \
59 ((pLink) = Vec_IntEntryP(&p->vFanins, Wln_RetFanouts(p, iObj)[2*i+1])); i++ ) if ( !iFanout ) {} else
60
64
76void Wln_RetPrintObj( Wln_Ret_t * p, int iObj )
77{
78 int k, iFanin, Type = Wln_ObjType(p->pNtk, iObj), * pLink;
79 printf( "Obj %6d : Type = %6s NameId = %5d InstId = %5d Fanins = %d : ",
80 iObj, Abc_OperName(Type), Wln_ObjNameId(p->pNtk, iObj), Wln_ObjInstId(p->pNtk, iObj), Wln_ObjFaninNum(p->pNtk, iObj) );
81 Wln_RetForEachFanin( p, iObj, iFanin, pLink, k )
82 {
83 printf( "%5d ", iFanin );
84 if ( !pLink[0] )
85 continue;
86 printf( "(%d : %d %d) ", pLink[0],
87 Vec_IntEntry(&p->vEdgeLinks, pLink[0]),
88 Vec_IntEntry(&p->vEdgeLinks, pLink[0]+1) );
89 }
90 printf( "\n" );
91}
92void Wln_RetPrint( Wln_Ret_t * p, int fVerbose )
93{
94 int iObj, nCount = 0;
95 Wln_NtkForEachObj( p->pNtk, iObj )
96 if ( Wln_ObjInstId(p->pNtk, iObj) > 1 )
97 nCount++;
98 printf( "Total number of objects = %d. Objects with non-trivial delay = %d.\n", Wln_NtkObjNum(p->pNtk), nCount );
99 if ( !fVerbose )
100 {
101 int nPrints = 0, nLimit = 5;
102 printf( "The following %d objects have non-trivial delays:\n", nLimit );
103 Wln_NtkForEachObj( p->pNtk, iObj )
104 {
105 if ( Wln_ObjInstId(p->pNtk, iObj) <= 1 )
106 continue;
107 Wln_RetPrintObj( p, iObj );
108 if ( ++nPrints == nLimit )
109 break;
110 }
111 return;
112 }
113 printf( "Printing %d objects of network \"%s\":\n", Wln_NtkObjNum(p->pNtk), p->pNtk->pName );
114 Wln_NtkForEachObj( p->pNtk, iObj )
115 Wln_RetPrintObj( p, iObj );
116 printf( "\n" );
117}
118
131{
132 int i, k, iObj, nClasses;
133 Hsh_VecMan_t * p = Hsh_VecManStart( 10 );
134 Vec_Int_t * vFlop = Vec_IntAlloc( 6 );
135 Vec_IntFill( vClasses, Wln_NtkObjNum(pNtk), -1 );
136 Wln_NtkForEachFf( pNtk, iObj, i )
137 {
138 Vec_IntClear( vFlop );
139 for ( k = 1; k <= 6; k++ )
140 Vec_IntPush( vFlop, Wln_ObjFanin(pNtk, iObj, k) );
141 Vec_IntWriteEntry( vClasses, iObj, Hsh_VecManAdd(p, vFlop) );
142 }
143 nClasses = Hsh_VecSize( p );
144 Hsh_VecManStop( p );
145 Vec_IntFree( vFlop );
146 printf( "Detected %d flops and %d flop classes.\n", Wln_NtkFfNum(pNtk), nClasses );
147 return nClasses;
148}
150{
151 Wln_Ret_t * p; int k, iObj, iFanin, fFirst = 1;
152 Vec_Int_t * vRefsCopy = Vec_IntAlloc(0);
153 p = ABC_CALLOC( Wln_Ret_t, 1 );
154 p->pNtk = pNtk;
155 Wln_NtkCreateRefs( pNtk );
156 // print objects without fanout
157 Wln_NtkForEachObj( pNtk, iObj )
158 if ( Wln_ObjRefs(pNtk, iObj) == 0 && !Wln_ObjIsCio(pNtk, iObj) )
159 {
160 if ( fFirst )
161 {
162 fFirst = 0;
163 printf( "Objects without fanout:\n" );
164 }
165 Wln_ObjPrint(pNtk, iObj);
166 }
167 // start fanin/fanout maps
168 Wln_NtkStartFaninMap( pNtk, &p->vFanins, 2 );
169 Wln_NtkStartFanoutMap( pNtk, &p->vFanouts, &pNtk->vRefs, 2 );
170 ABC_SWAP( Vec_Int_t, *vRefsCopy, pNtk->vRefs );
171 Wln_NtkCleanRefs( pNtk );
172 Vec_IntGrow( &p->vEdgeLinks, 10*Wln_NtkFfNum(pNtk) );
173 Vec_IntPushTwo( &p->vEdgeLinks, -1, -1 );
174 Wln_NtkForEachObj( pNtk, iObj )
175 Wln_ObjForEachFanin( pNtk, iObj, iFanin, k )
176 {
177 int * pFanins = Wln_RetFanins( p, iObj );
178 int * pFanouts = Wln_RetFanouts( p, iFanin );
179 int Index = Wln_ObjRefsInc( pNtk, iFanin );
180 pFanins[2*k+0] = iFanin;
181 pFanins[2*k+1] = Wln_ObjIsFf(pNtk, iFanin) ? Vec_IntSize(&p->vEdgeLinks) : 0;
182 pFanouts[2*Index+0] = iObj;
183 pFanouts[2*Index+1] = Vec_IntEntry(&p->vFanins, iObj) + 2*k + 1;
184 if ( Wln_ObjIsFf(pNtk, iFanin) )
185 Vec_IntPushTwo( &p->vEdgeLinks, 0, iFanin );
186 }
187 // double-check the current number of fanouts added
188 Wln_NtkForEachObj( pNtk, iObj )
189 assert( Wln_ObjRefs(pNtk, iObj) == Vec_IntEntry(vRefsCopy, iObj) );
190 Vec_IntFree( vRefsCopy );
191 // other data
192 p->nClasses = Wln_RetComputeFfClasses( pNtk, &p->vFfClasses );
193 //ABC_SWAP( Vec_Int_t, p->vNodeDelays, pNtk->vInstIds );
194 Vec_IntAppend( &p->vNodeDelays, &pNtk->vInstIds );
195 Vec_IntGrow( &p->vSources, 1000 );
196 Vec_IntGrow( &p->vSinks, 1000 );
197 Vec_IntGrow( &p->vFront, 1000 );
198 Vec_IntGrow( &p->vMoves, 1000 );
199 return p;
200}
202{
203 ABC_FREE( p->vFanins.pArray );
204 ABC_FREE( p->vFanouts.pArray );
205 ABC_FREE( p->vEdgeLinks.pArray );
206 ABC_FREE( p->vFfClasses.pArray );
207 ABC_FREE( p->vNodeDelays.pArray );
208 ABC_FREE( p->vPathDelays.pArray );
209 ABC_FREE( p->vSources.pArray );
210 ABC_FREE( p->vSinks.pArray );
211 ABC_FREE( p->vFront.pArray );
212 ABC_FREE( p->vMoves.pArray );
213 ABC_FREE( p );
214}
216{
217 int Mem = sizeof(Wln_Ret_t);
218 Mem += 4 * p->vFanins.nCap;
219 Mem += 4 * p->vFanouts.nCap;
220 Mem += 4 * p->vEdgeLinks.nCap;
221 Mem += 4 * p->vFfClasses.nCap;
222 Mem += 4 * p->vNodeDelays.nCap;
223 Mem += 4 * p->vPathDelays.nCap;
224 Mem += 4 * p->vSources.nCap;
225 Mem += 4 * p->vSinks.nCap;
226 Mem += 4 * p->vFront.nCap;
227 Mem += 4 * p->vMoves.nCap;
228 return Mem;
229}
230
243{
244 int k, iFanout, * pLink, * pDelay = Vec_IntEntryP( &p->vPathDelays, iObj );
245 if ( *pDelay < 0 )
246 return;
247 *pDelay = -1;
248 Wln_RetForEachFanout( p, iObj, iFanout, pLink, k )
249 if ( !pLink[0] )
250 Wln_RetMarkChanges_rec( p, iFanout );
251}
253{
254 int i, iObj;
255 if ( vFront )
256 {
257 Vec_IntForEachEntry( vFront, iObj, i )
258 Wln_RetMarkChanges_rec( p, iObj );
259 }
260 else
261 {
262 Vec_IntFill( &p->vPathDelays, Wln_NtkObjNum(p->pNtk), -1 );
263 Wln_NtkForEachCi( p->pNtk, iObj, i )
264 Vec_IntWriteEntry( &p->vPathDelays, iObj, 0 );
265 }
266}
268{
269 int k, iFanin, * pLink, * pDelay = Vec_IntEntryP( &p->vPathDelays, iObj );
270 if ( *pDelay >= 0 )
271 return *pDelay;
272 *pDelay = 0;
273 Wln_RetForEachFanin( p, iObj, iFanin, pLink, k )
274 {
275 if ( Wln_ObjIsFf(p->pNtk, iObj) && k > 0 )
276 continue;
277 if ( pLink[0] )
278 *pDelay = Abc_MaxInt(*pDelay, 0);
279 else
280 *pDelay = Abc_MaxInt(*pDelay, Wln_RetPropDelay_rec(p, iFanin));
281 }
282 *pDelay += Vec_IntEntry( &p->vNodeDelays, iObj );
283 return *pDelay;
284}
286{
287 int iObj, DelayMax = 0;
288 Vec_IntClear( &p->vSinks );
289 Wln_NtkForEachObj( p->pNtk, iObj )
290 if ( !Wln_ObjIsCio(p->pNtk, iObj) )
291 {
292 int Delay = Wln_RetPropDelay_rec(p, iObj);
293 if ( DelayMax == Delay )
294 Vec_IntPush( &p->vSinks, iObj );
295 else if ( DelayMax < Delay )
296 {
297 DelayMax = Delay;
298 Vec_IntFill( &p->vSinks, 1, iObj );
299 }
300 }
301
302// Vec_IntForEachEntry( &p->vPathDelays, iObj, i )
303// printf( "Obj = %d. Delay = %d.\n", i, iObj );
304// printf( "\n" );
305
306// printf( "Sinks: " );
307// Vec_IntPrint( &p->vSinks );
308
309 return DelayMax;
310}
311
313{
314 int k, iFanin, * pLink, FaninDelay;
315 if ( Wln_ObjIsCi(p->pNtk, iObj) || Wln_ObjCheckTravId(p->pNtk, iObj) )
316 return;
317 FaninDelay = Vec_IntEntry( &p->vPathDelays, iObj ) - Vec_IntEntry( &p->vNodeDelays, iObj );
318 Wln_RetForEachFanin( p, iObj, iFanin, pLink, k )
319 if ( !pLink[0] && Vec_IntEntry(&p->vPathDelays, iFanin) == FaninDelay )
320 Wln_RetFindSources_rec( p, iFanin );
321 if ( FaninDelay == 0 )
322 Vec_IntPush( &p->vSources, iObj );
323}
325{
326 int i, iObj;
327 Vec_IntClear( &p->vSources );
328 Wln_NtkIncrementTravId( p->pNtk );
329 Vec_IntForEachEntry( &p->vSinks, iObj, i )
330 Wln_RetFindSources_rec( p, iObj );
331
332// printf( "Sources: " );
333// Vec_IntPrint( &p->vSources );
334}
335
347int Wln_RetMarkPaths_rec( Wln_Ntk_t * p, int iObj, int fVerbose )
348{
349 int k, iFanin, fPrev = 1;
350 if ( Wln_ObjIsTravIdPrevious(p, iObj) )
351 return 1;
352 if ( Wln_ObjIsTravIdCurrent(p, iObj) )
353 return 0;
354 if ( Wln_ObjIsCio(p, iObj) || Wln_ObjIsFf(p, iObj) )
355 return 0;
356 Wln_ObjForEachFanin( p, iObj, iFanin, k )
357 fPrev &= Wln_RetMarkPaths_rec( p, iFanin, fVerbose );
358 if ( fPrev )
359 {
360 Wln_ObjSetTravIdPrevious( p, iObj );
361 if ( Vec_IntEntry(&p->vInstIds, iObj) > 0 )
362 {
363 if ( fVerbose )
364 printf( "Updating delay %5d -> %5d : ", Vec_IntEntry(&p->vInstIds, iObj), 1 );
365 if ( fVerbose )
366 Wln_ObjPrint( p, iObj );
367 Vec_IntWriteEntry( &p->vInstIds, iObj, 1 );
368 }
369 return 1;
370 }
371 Wln_ObjSetTravIdCurrent( p, iObj );
372 return 0;
373}
374void Wln_RetMarkPaths( Wln_Ntk_t * p, int fVerbose )
375{
376 int i, iObj;
377 Wln_NtkIncrementTravId( p );
378 Wln_NtkIncrementTravId( p );
379 Wln_NtkForEachPi( p, iObj, i )
380 Wln_ObjSetTravIdPrevious( p, iObj );
381 Wln_NtkForEachPo( p, iObj, i )
382 Wln_RetMarkPaths_rec( p, Wln_ObjFanin0(p, iObj), fVerbose );
383}
384
396int * Wln_RetHeadToTail( Wln_Ret_t * p, int * pHead )
397{
398 int * pLink;
399 assert( pHead[0] );
400 pLink = Vec_IntEntryP( &p->vEdgeLinks, pHead[0] );
401 if ( pLink[0] == 0 )
402 return pHead;
403 return Wln_RetHeadToTail( p, pLink );
404}
405
406static inline int Wln_RetCheckForwardOne( Wln_Ret_t * p, int iObj )
407{
408 int k, iFanin, * pLink, iFlop, Class = -1;
409 Wln_RetForEachFanin( p, iObj, iFanin, pLink, k )
410 {
411 if ( Wln_ObjIsFf(p->pNtk, iObj) && k > 0 )
412 continue;
413 if ( !pLink[0] )
414 return 0;
415 iFlop = Vec_IntEntry( &p->vEdgeLinks, pLink[0] + 1 );
416 assert( Wln_ObjIsFf( p->pNtk, iFlop ) );
417 if ( Class == -1 )
418 Class = Vec_IntEntry( &p->vFfClasses, iFlop );
419 else if ( Class != Vec_IntEntry( &p->vFfClasses, iFlop ) )
420 return 0;
421 }
422 return 1;
423}
425{
426 int i, iObj;
427 Vec_IntForEachEntry( vSet, iObj, i )
428 if ( !Wln_RetCheckForwardOne( p, iObj ) )
429 return 0;
430 return 1;
431}
432
433static inline int Wln_RetCheckBackwardOne( Wln_Ret_t * p, int iObj )
434{
435 int k, iFanin, * pLink, iFlop, Class = -1;
436 if ( Wln_ObjRefs(p->pNtk, iObj) == 0 )
437 return 0;
438 Wln_RetForEachFanout( p, iObj, iFanin, pLink, k )
439 {
440 if ( !pLink[0] )
441 return 0;
442 pLink = Wln_RetHeadToTail( p, pLink );
443 iFlop = Vec_IntEntry( &p->vEdgeLinks, pLink[0] + 1 );
444 assert( Wln_ObjIsFf( p->pNtk, iFlop ) );
445 if ( Class == -1 )
446 Class = Vec_IntEntry( &p->vFfClasses, iFlop );
447 else if ( Class != Vec_IntEntry( &p->vFfClasses, iFlop ) )
448 return 0;
449 }
450 return 1;
451}
453{
454 int i, iObj;
455 Vec_IntForEachEntry( vSet, iObj, i )
456 if ( !Wln_RetCheckBackwardOne( p, iObj ) )
457 return 0;
458 return 1;
459}
460
461
474{
475 int k, iFanin, * pLink, iFlop, iFlop1 = -1;
476 int * pFanins = Wln_RetFanins( p, iObj );
477 Wln_RetForEachFanin( p, iObj, iFanin, pLink, k )
478 {
479 if ( Wln_ObjIsFf(p->pNtk, iObj) && k > 0 )
480 continue;
481 assert( pLink[0] );
482 iFlop = Vec_IntEntry( &p->vEdgeLinks, pLink[0] + 1 );
483 pFanins[2*k+1] = Vec_IntEntry( &p->vEdgeLinks, pLink[0] );
484 assert( Wln_ObjIsFf( p->pNtk, iFlop ) );
485 if ( iFlop1 == -1 )
486 iFlop1 = iFlop;
487 }
488 return iFlop1;
489}
491{
492 int k, iFanin, * pLink, iFlop, iFlop1 = -1;
493 //int * pFanins = Wln_RetFanins( p, iObj );
494 Wln_RetForEachFanout( p, iObj, iFanin, pLink, k )
495 {
496 assert( pLink[0] );
497 pLink = Wln_RetHeadToTail( p, pLink );
498 iFlop = Vec_IntEntry( &p->vEdgeLinks, pLink[0] + 1 );
499 pLink[0] = 0;
500 assert( Wln_ObjIsFf( p->pNtk, iFlop ) );
501 if ( iFlop1 == -1 )
502 iFlop1 = iFlop;
503 }
504 return iFlop1;
505}
506void Wln_RetInsertOneFanin( Wln_Ret_t * p, int iObj, int iFlop )
507{
508 int k, iHead, iFanin, * pLink;
509 int * pFanins = Wln_RetFanins( p, iObj );
510 assert( Wln_ObjIsFf( p->pNtk, iFlop ) );
511 Wln_RetForEachFanin( p, iObj, iFanin, pLink, k )
512 {
513 if ( Wln_ObjIsFf(p->pNtk, iObj) && k > 0 )
514 continue;
515 iHead = pFanins[2*k+1];
516 pFanins[2*k+1] = Vec_IntSize(&p->vEdgeLinks);
517 Vec_IntPushTwo( &p->vEdgeLinks, iHead, iFlop );
518 }
519}
520void Wln_RetInsertOneFanout( Wln_Ret_t * p, int iObj, int iFlop )
521{
522 int k, iFanin, * pLink;
523 assert( Wln_ObjIsFf( p->pNtk, iFlop ) );
524 Wln_RetForEachFanout( p, iObj, iFanin, pLink, k )
525 {
526 if ( pLink[0] )
527 pLink = Wln_RetHeadToTail( p, pLink );
528 //assert( pLink[0] == 0 );
529 pLink[0] = Vec_IntSize(&p->vEdgeLinks);
530 Vec_IntPushTwo( &p->vEdgeLinks, 0, iFlop );
531 }
532}
534{
535 int i, iObj, iFlop;
536 Vec_IntForEachEntry( vSet, iObj, i )
537 {
538 iFlop = Wln_RetRemoveOneFanin( p, iObj );
539 if ( iFlop == -1 )
540 continue;
541 Wln_RetInsertOneFanout( p, iObj, iFlop );
542 }
543}
545{
546 int i, iObj, iFlop;
547 Vec_IntForEachEntry( vSet, iObj, i )
548 {
549 iFlop = Wln_RetRemoveOneFanout( p, iObj );
550 if ( iFlop == -1 )
551 continue;
552 Wln_RetInsertOneFanin( p, iObj, iFlop );
553 }
554}
555void Wln_RetAddToMoves( Wln_Ret_t * p, Vec_Int_t * vSet, int Delay, int fForward, int nMoves, int fSkipSimple, int fVerbose )
556{
557 int i, iObj;
558 if ( vSet == NULL )
559 {
560 printf( "Move %4d : Recording initial state (delay = %6d)\n", nMoves, Delay );
561 Vec_IntPushTwo( &p->vMoves, Delay, 0 );
562 return;
563 }
564 printf( "Move %4d : Recording %s retiming (delay = %6d) :", nMoves, fForward ? "forward " : "backward", Delay );
565 Vec_IntPush( &p->vMoves, Delay );
566 Vec_IntForEachEntry( vSet, iObj, i )
567 {
568 int NameId = Vec_IntEntry( &p->pNtk->vNameIds, iObj );
569 if ( fSkipSimple && (Wln_ObjIsFf(p->pNtk, iObj) || Wln_ObjType(p->pNtk, iObj) == ABC_OPER_SLICE || Wln_ObjType(p->pNtk, iObj) == ABC_OPER_CONCAT) )
570 continue;
571 Vec_IntPush( &p->vMoves, fForward ? -NameId : NameId );
572 if ( fVerbose )
573 printf( " %d (NameID = %d) ", fForward ? -iObj : iObj, fForward ? -NameId : NameId );
574 }
575 Vec_IntPush( &p->vMoves, 0 );
576 if ( !fVerbose )
577 printf( " %3d retimed objects", Vec_IntSize(vSet) );
578 printf( "\n" );
579}
580
593{
594 int i, iObj;
595// if ( Wln_NtkHasInstId(pNtk) )
596// Vec_IntErase( &pNtk->vInstIds );
597 if ( Wln_NtkHasInstId(pNtk) )
598 {
599 printf( "Using delays given by the user in the input file.\n" );
600 Wln_NtkForEachObj( pNtk, iObj )
601 if ( !Wln_ObjIsCio(pNtk, iObj) && !Wln_ObjIsConst(pNtk, iObj) && Wln_ObjInstId(pNtk, iObj) == 0 )
602 printf( "Warning: Object %d of type %s has zero delay. Retiming will not work correctly.\n", iObj, Abc_OperName(Wln_ObjType(pNtk, iObj)) );
603 }
604 else
605 {
606 printf( "The design has no delay information.\n" );
607 Wln_NtkCleanInstId(pNtk);
608 Wln_NtkForEachObj( pNtk, iObj )
609 {
610 if ( Wln_ObjIsFf(pNtk, iObj) || Wln_ObjType(pNtk, iObj) == ABC_OPER_SLICE || Wln_ObjType(pNtk, iObj) == ABC_OPER_CONCAT )
611 Wln_ObjSetInstId( pNtk, iObj, 1 );
612 else if ( !Wln_ObjIsCio(pNtk, iObj) && Wln_ObjFaninNum(pNtk, iObj) > 0 )
613 Wln_ObjSetInstId( pNtk, iObj, 10 );
614 }
615 Wln_NtkForEachCo( pNtk, iObj, i )
616 {
617 if ( Wln_ObjType(pNtk, Wln_ObjFanin0(pNtk, iObj)) != ABC_OPER_LUT )
618 Wln_ObjSetInstId( pNtk, Wln_ObjFanin0(pNtk, iObj), 1 );
619 }
620 printf( "Assuming default delays: 10 units for most nodes and 1 unit for bit-slice, concat, and buffers driving COs.\n" );
621 }
622}
623Vec_Int_t * Wln_NtkRetime_int( Wln_Ntk_t * pNtk, int fSkipSimple, int fVerbose )
624{
625 Wln_Ret_t * p = Wln_RetAlloc( pNtk );
626 Vec_Int_t * vSources = &p->vSources;
627 Vec_Int_t * vSinks = &p->vSinks;
628 Vec_Int_t * vFront = &p->vFront;
629 Vec_Int_t * vMoves = Vec_IntAlloc(0);
630 int nMoves = 0, fPrevFwd = 0, fPrevBwd = 0, nCountIncrease = 0;
631 int DelayInit = 0, DelayBest = 0, nChange = 0;
632 Wln_RetPrint( p, fVerbose );
633 Wln_RetMarkChanges( p, NULL );
634 p->DelayMax = DelayInit = DelayBest = Wln_RetPropDelay( p );
636 Wln_RetAddToMoves( p, NULL, p->DelayMax, 0, nMoves, fSkipSimple, fVerbose );
637 while ( Vec_IntSize(vSources) || Vec_IntSize(vSinks) )
638 {
639 int DelayMaxPrev = p->DelayMax;
640 int fForward = Vec_IntSize(vSources) && Wln_RetCheckForward( p, vSources );
641 int fBackward = Vec_IntSize(vSinks) && Wln_RetCheckBackward( p, vSinks );
642 Vec_IntSort( vSources, 0 );
643 Vec_IntSort( vSinks, 0 );
644
645 if ( !fForward && !fBackward )
646 {
647 printf( "Cannot retime forward and backward.\n" );
648 break;
649 }
650 if ( Vec_IntTwoCountCommon(vSources, vSinks) )
651 {
652 printf( "Cannot reduce delay by retiming.\n" );
653 break;
654 }
655 nMoves++;
656 Vec_IntClear( vFront );
657 if ( (fPrevFwd && fForward) || (!(fPrevBwd && fBackward) && ((fForward && !fBackward) || (fForward && fBackward && Vec_IntSize(vSources) < Vec_IntSize(vSinks)))) )
658 {
659 Vec_IntAppend( vFront, vSources );
660 Wln_RetMarkChanges( p, vFront );
661 Wln_RetRetimeForward( p, vFront );
662 p->DelayMax = Wln_RetPropDelay( p );
663 fForward = 1, fBackward = 0;
664 fPrevFwd = 1;
665 }
666 else
667 {
668 Vec_IntAppend( vFront, vSinks );
669 Wln_RetRetimeBackward( p, vFront );
670 Wln_RetMarkChanges( p, vFront );
671 p->DelayMax = Wln_RetPropDelay( p );
672 fForward = 0, fBackward = 1;
673 fPrevBwd = 1;
674 }
675 DelayBest = Abc_MinInt( DelayBest, p->DelayMax );
676 //Wln_RetPrint( p );
677 if ( fVerbose )
678 printf( "\n" );
679 Wln_RetAddToMoves( p, vFront, p->DelayMax, fForward, nMoves, fSkipSimple, fVerbose );
680 if ( fVerbose )
681 {
682 printf( "Sinks: " );
683 Vec_IntPrint( &p->vSinks );
684 printf( "Sources: " );
685 Vec_IntPrint( &p->vSources );
686 }
687 if ( p->DelayMax >= DelayMaxPrev )
688 nCountIncrease++;
689 else
690 {
691 if ( nCountIncrease > 0 )
692 nChange++;
693 nCountIncrease = 0;
694 }
695 if ( nCountIncrease > 3 )
696 break;
697 if ( nChange > 5 )
698 break;
700 if ( 2*Vec_IntSize(&p->vEdgeLinks) > Vec_IntCap(&p->vEdgeLinks) )
701 Vec_IntGrow( &p->vEdgeLinks, 4*Vec_IntSize(&p->vEdgeLinks) );
702 }
703 ABC_SWAP( Vec_Int_t, *vMoves, p->vMoves );
704 Wln_RetFree( p );
705 if ( fVerbose )
706 {
707 printf( "\nThe resulting moves recorded in terms of name IDs of the NDR nodes:\n" );
708 Vec_IntPrint( vMoves );
709 }
710 else
711 {
712 printf( "Retiming instruction contains %d moves and %d total retimed objects.\n", nMoves, Vec_IntSize(vMoves)-2*nMoves-2 );
713 printf( "Initial delay = %d. The best delay achieved = %d. Improvement = %d. (%6.2f %%)\n",
714 DelayInit, DelayBest, DelayInit - DelayBest, 100.0 * (DelayInit - DelayBest) / DelayInit );
715 }
716 return vMoves;
717}
718Vec_Int_t * Wln_NtkRetime( Wln_Ntk_t * pNtk, int fIgnoreIO, int fSkipSimple, int fVerbose )
719{
720 if ( fIgnoreIO )
721 Wln_RetMarkPaths( pNtk, fVerbose );
722 return Wln_NtkRetime_int( pNtk, fSkipSimple, fVerbose );
723}
724
728
729
731
@ ABC_OPER_LUT
Definition abcOper.h:127
@ ABC_OPER_CONCAT
Definition abcOper.h:147
@ ABC_OPER_SLICE
Definition abcOper.h:146
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#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
Vec_Int_t vInstIds
Definition wln.h:69
Vec_Int_t vRefs
Definition wln.h:77
Vec_Int_t vEdgeLinks
Definition wlnRetime.c:36
Vec_Int_t vMoves
Definition wlnRetime.c:43
Vec_Int_t vSources
Definition wlnRetime.c:40
Vec_Int_t vSinks
Definition wlnRetime.c:41
int DelayMax
Definition wlnRetime.c:45
int nClasses
Definition wlnRetime.c:44
Vec_Int_t vFfClasses
Definition wlnRetime.c:37
Vec_Int_t vNodeDelays
Definition wlnRetime.c:38
Vec_Int_t vFront
Definition wlnRetime.c:42
Vec_Int_t vFanins
Definition wlnRetime.c:34
Vec_Int_t vPathDelays
Definition wlnRetime.c:39
Wln_Ntk_t * pNtk
Definition wlnRetime.c:33
Vec_Int_t vFanouts
Definition wlnRetime.c:35
#define assert(ex)
Definition util_old.h:213
struct Hsh_VecMan_t_ Hsh_VecMan_t
Definition vecHsh.h:85
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
int Wln_RetMemUsage(Wln_Ret_t *p)
Definition wlnRetime.c:215
void Wln_RetMarkChanges_rec(Wln_Ret_t *p, int iObj)
Definition wlnRetime.c:242
int * Wln_RetHeadToTail(Wln_Ret_t *p, int *pHead)
Definition wlnRetime.c:396
int Wln_RetRemoveOneFanin(Wln_Ret_t *p, int iObj)
Definition wlnRetime.c:473
int Wln_RetComputeFfClasses(Wln_Ntk_t *pNtk, Vec_Int_t *vClasses)
Definition wlnRetime.c:130
void Wln_RetPrint(Wln_Ret_t *p, int fVerbose)
Definition wlnRetime.c:92
#define Wln_RetForEachFanin(p, iObj, iFanin, pLink, i)
Definition wlnRetime.c:51
int Wln_RetPropDelay_rec(Wln_Ret_t *p, int iObj)
Definition wlnRetime.c:267
void Wln_RetRetimeBackward(Wln_Ret_t *p, Vec_Int_t *vSet)
Definition wlnRetime.c:544
int Wln_RetRemoveOneFanout(Wln_Ret_t *p, int iObj)
Definition wlnRetime.c:490
int Wln_RetPropDelay(Wln_Ret_t *p)
Definition wlnRetime.c:285
void Wln_RetRetimeForward(Wln_Ret_t *p, Vec_Int_t *vSet)
Definition wlnRetime.c:533
int Wln_RetCheckForward(Wln_Ret_t *p, Vec_Int_t *vSet)
Definition wlnRetime.c:424
void Wln_RetFindSources_rec(Wln_Ret_t *p, int iObj)
Definition wlnRetime.c:312
typedefABC_NAMESPACE_IMPL_START struct Wln_Ret_t_ Wln_Ret_t
DECLARATIONS ///.
Definition wlnRetime.c:30
#define Wln_RetForEachFanout(p, iObj, iFanout, pLink, i)
Definition wlnRetime.c:56
void Wln_NtkRetimeCreateDelayInfo(Wln_Ntk_t *pNtk)
Definition wlnRetime.c:592
void Wln_RetFindSources(Wln_Ret_t *p)
Definition wlnRetime.c:324
Vec_Int_t * Wln_NtkRetime_int(Wln_Ntk_t *pNtk, int fSkipSimple, int fVerbose)
Definition wlnRetime.c:623
void Wln_RetMarkPaths(Wln_Ntk_t *p, int fVerbose)
Definition wlnRetime.c:374
void Wln_RetFree(Wln_Ret_t *p)
Definition wlnRetime.c:201
void Wln_RetAddToMoves(Wln_Ret_t *p, Vec_Int_t *vSet, int Delay, int fForward, int nMoves, int fSkipSimple, int fVerbose)
Definition wlnRetime.c:555
void Wln_RetMarkChanges(Wln_Ret_t *p, Vec_Int_t *vFront)
Definition wlnRetime.c:252
int Wln_RetMarkPaths_rec(Wln_Ntk_t *p, int iObj, int fVerbose)
Definition wlnRetime.c:347
void Wln_RetPrintObj(Wln_Ret_t *p, int iObj)
FUNCTION DEFINITIONS ///.
Definition wlnRetime.c:76
void Wln_RetInsertOneFanout(Wln_Ret_t *p, int iObj, int iFlop)
Definition wlnRetime.c:520
Wln_Ret_t * Wln_RetAlloc(Wln_Ntk_t *pNtk)
Definition wlnRetime.c:149
void Wln_RetInsertOneFanin(Wln_Ret_t *p, int iObj, int iFlop)
Definition wlnRetime.c:506
Vec_Int_t * Wln_NtkRetime(Wln_Ntk_t *pNtk, int fIgnoreIO, int fSkipSimple, int fVerbose)
Definition wlnRetime.c:718
int Wln_RetCheckBackward(Wln_Ret_t *p, Vec_Int_t *vSet)
Definition wlnRetime.c:452
#define Wln_NtkForEachFf(p, iFf, i)
Definition wln.h:202
#define Wln_NtkForEachCo(p, iCo, i)
Definition wln.h:200
void Wln_ObjPrint(Wln_Ntk_t *p, int iObj)
Definition wlnObj.c:136
#define Wln_ObjForEachFanin(p, iObj, iFanin, i)
Definition wln.h:205
#define Wln_NtkForEachPo(p, iPo, i)
Definition wln.h:196
void Wln_NtkStartFaninMap(Wln_Ntk_t *p, Vec_Int_t *vFaninMap, int nMulti)
Definition wlnNtk.c:372
#define Wln_NtkForEachCi(p, iCi, i)
Definition wln.h:198
void Wln_NtkStartFanoutMap(Wln_Ntk_t *p, Vec_Int_t *vFanoutMap, Vec_Int_t *vFanoutNums, int nMulti)
Definition wlnNtk.c:383
#define Wln_NtkForEachPi(p, iPi, i)
Definition wln.h:194
void Wln_NtkCreateRefs(Wln_Ntk_t *p)
Definition wlnNtk.c:357
struct Wln_Ntk_t_ Wln_Ntk_t
Definition wln.h:55
#define Wln_NtkForEachObj(p, i)
MACRO DEFINITIONS ///.
Definition wln.h:187