ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
retDelay.c
Go to the documentation of this file.
1
20
21#include "retInt.h"
22
24
25
29
30static int Abc_NtkRetimeMinDelayTry( Abc_Ntk_t * pNtk, int nDelayLim, int fForward, int fInitial, int nIterLimit, int * pIterBest, int fVerbose );
31static int Abc_NtkRetimeTiming( Abc_Ntk_t * pNtk, int fForward, Vec_Ptr_t * vCritical );
32static int Abc_NtkRetimeTiming_rec( Abc_Obj_t * pObj, int fForward );
33
37
50int Abc_NtkRetimeMinDelay( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkCopy, int nDelayLim, int nIterLimit, int fForward, int fVerbose )
51{
52 int IterBest, DelayBest;
53 int IterBest2, DelayBest2;
54 // try to find the best delay iteration on a copy
55 DelayBest = Abc_NtkRetimeMinDelayTry( pNtkCopy, nDelayLim, fForward, 0, nIterLimit, &IterBest, fVerbose );
56 if ( IterBest == 0 )
57 return 1;
58 // perform the given number of iterations on the original network
59 DelayBest2 = Abc_NtkRetimeMinDelayTry( pNtk, nDelayLim, fForward, 1, IterBest, &IterBest2, fVerbose );
60 assert( DelayBest == DelayBest2 );
61 assert( IterBest == IterBest2 );
62 return 1;
63}
64
76int Abc_NtkRetimeMinDelayTry( Abc_Ntk_t * pNtk, int nDelayLim, int fForward, int fInitial, int nIterLimit, int * pIterBest, int fVerbose )
77{
78 Abc_Ntk_t * pNtkNew = NULL;
79 Vec_Ptr_t * vCritical;
80 Vec_Int_t * vValues = NULL; // Suppress "might be used uninitialized"
81 Abc_Obj_t * pObj;
82 int i, k, IterBest, DelayCur, DelayBest;
83 int DelayStart = -1; // Suppress "might be used uninitialized"
84 int LatchesBest;
85 // transfer intitial values
86 if ( fInitial )
87 {
88 if ( fForward )
90 else
91 {
92 // save initial value of the latches
93 vValues = Abc_NtkRetimeCollectLatchValues( pNtk );
94 // start the network for initial value computation
95 pNtkNew = Abc_NtkRetimeBackwardInitialStart( pNtk );
96 }
97 }
98
99 if ( fVerbose && !fInitial )
100 printf( "Performing analysis:\n" );
101 // find the best iteration
102 DelayBest = ABC_INFINITY; IterBest = 0; LatchesBest = Abc_NtkLatchNum(pNtk);
103 vCritical = Vec_PtrAlloc( 100 );
104 for ( i = 0; ; i++ )
105 {
106 // perform moves for the timing-critical nodes
107 DelayCur = Abc_NtkRetimeTiming( pNtk, fForward, vCritical );
108 if ( i == 0 )
109 DelayStart = DelayCur;
110 // record this position if it has the best delay
111 if ( DelayBest > DelayCur )
112 {
113if ( fVerbose && !fInitial )
114 printf( "%s Iter = %3d. Delay = %3d. Latches = %5d. Delta = %6.2f. Ratio = %4.2f %%\n",
115 fForward ? "Fwd": "Bwd", i, DelayCur, Abc_NtkLatchNum(pNtk),
116 1.0*(Abc_NtkLatchNum(pNtk)-LatchesBest)/(DelayBest-DelayCur),
117 100.0*(Abc_NtkLatchNum(pNtk)-LatchesBest)/Abc_NtkLatchNum(pNtk)/(DelayBest-DelayCur) );
118
119 DelayBest = DelayCur;
120 IterBest = i;
121 LatchesBest = Abc_NtkLatchNum(pNtk);
122 }
123 // quit after timing analysis
124 if ( i == nIterLimit )
125 break;
126 // skip if 10 iterations did not give improvement
127 if ( i - IterBest > 20 )
128 break;
129 // skip if delay limit is reached
130 if ( nDelayLim > 0 && DelayCur <= nDelayLim )
131 break;
132 // try retiming to improve the delay
133 Vec_PtrForEachEntry( Abc_Obj_t *, vCritical, pObj, k )
134 if ( Abc_NtkRetimeNodeIsEnabled(pObj, fForward) )
135 Abc_NtkRetimeNode( pObj, fForward, fInitial );
136 // share latches
137 if ( !fForward )
138 Abc_NtkRetimeShareLatches( pNtk, fInitial );
139 }
140 Vec_PtrFree( vCritical );
141 // transfer the initial state back to the latches
142 if ( fInitial )
143 {
144 if ( fForward )
146 else
147 {
148 Abc_NtkRetimeBackwardInitialFinish( pNtk, pNtkNew, vValues, fVerbose );
149 Abc_NtkDelete( pNtkNew );
150 Vec_IntFree( vValues );
151 }
152 }
153 if ( fVerbose && !fInitial )
154 printf( "%s : Starting delay = %3d. Final delay = %3d. IterBest = %2d (out of %2d).\n",
155 fForward? "Forward " : "Backward", DelayStart, DelayBest, IterBest, nIterLimit );
156 *pIterBest = (nIterLimit == 1) ? 1 : IterBest;
157 return DelayBest;
158}
159
172int Abc_NtkRetimeTiming( Abc_Ntk_t * pNtk, int fForward, Vec_Ptr_t * vCritical )
173{
174 Vec_Ptr_t * vLatches;
175 Abc_Obj_t * pObj, * pNext;
176 int i, k, LevelCur, LevelMax = 0;
177 // mark all objects except nodes
178 Abc_NtkIncrementTravId(pNtk);
179 vLatches = Vec_PtrAlloc( Abc_NtkLatchNum(pNtk) );
180 Abc_NtkForEachObj( pNtk, pObj, i )
181 {
182 if ( Abc_ObjIsLatch(pObj) )
183 Vec_PtrPush( vLatches, pObj );
184 if ( Abc_ObjIsNode(pObj) )
185 continue;
186 pObj->Level = 0;
187 Abc_NodeSetTravIdCurrent( pObj );
188 }
189 // perform analysis from CIs/COs
190 if ( fForward )
191 {
192 Vec_PtrForEachEntry( Abc_Obj_t *, vLatches, pObj, i )
193 {
194 Abc_ObjForEachFanout( pObj, pNext, k )
195 {
196 LevelCur = Abc_NtkRetimeTiming_rec( pNext, fForward );
197 if ( LevelMax < LevelCur )
198 LevelMax = LevelCur;
199 }
200 }
201 Abc_NtkForEachPi( pNtk, pObj, i )
202 {
203 Abc_ObjForEachFanout( pObj, pNext, k )
204 {
205 LevelCur = Abc_NtkRetimeTiming_rec( pNext, fForward );
206 if ( LevelMax < LevelCur )
207 LevelMax = LevelCur;
208 }
209 }
210 }
211 else
212 {
213 Vec_PtrForEachEntry( Abc_Obj_t *, vLatches, pObj, i )
214 {
215 LevelCur = Abc_NtkRetimeTiming_rec( Abc_ObjFanin0(pObj), fForward );
216 if ( LevelMax < LevelCur )
217 LevelMax = LevelCur;
218 }
219 Abc_NtkForEachPo( pNtk, pObj, i )
220 {
221 LevelCur = Abc_NtkRetimeTiming_rec( Abc_ObjFanin0(pObj), fForward );
222 if ( LevelMax < LevelCur )
223 LevelMax = LevelCur;
224 }
225 }
226 // collect timing critical nodes, which should be retimed forward/backward
227 Vec_PtrClear( vCritical );
228 Abc_NtkIncrementTravId(pNtk);
229 if ( fForward )
230 {
231 Vec_PtrForEachEntry( Abc_Obj_t *, vLatches, pObj, i )
232 {
233 Abc_ObjForEachFanout( pObj, pNext, k )
234 {
235 if ( Abc_NodeIsTravIdCurrent(pNext) )
236 continue;
237 if ( LevelMax != (int)pNext->Level )
238 continue;
239 // new critical node
240 Vec_PtrPush( vCritical, pNext );
241 Abc_NodeSetTravIdCurrent( pNext );
242 }
243 }
244 }
245 else
246 {
247 Vec_PtrForEachEntry( Abc_Obj_t *, vLatches, pObj, i )
248 {
249 Abc_ObjForEachFanin( pObj, pNext, k )
250 {
251 if ( Abc_NodeIsTravIdCurrent(pNext) )
252 continue;
253 if ( LevelMax != (int)pNext->Level )
254 continue;
255 // new critical node
256 Vec_PtrPush( vCritical, pNext );
257 Abc_NodeSetTravIdCurrent( pNext );
258 }
259 }
260 }
261 Vec_PtrFree( vLatches );
262 return LevelMax;
263}
264
277int Abc_NtkRetimeTiming_rec( Abc_Obj_t * pObj, int fForward )
278{
279 Abc_Obj_t * pNext;
280 int i, LevelCur, LevelMax = 0;
281 // skip visited nodes
282 if ( Abc_NodeIsTravIdCurrent(pObj) )
283 return pObj->Level;
284 Abc_NodeSetTravIdCurrent(pObj);
285 // visit the next nodes
286 if ( fForward )
287 {
288 Abc_ObjForEachFanout( pObj, pNext, i )
289 {
290 LevelCur = Abc_NtkRetimeTiming_rec( pNext, fForward );
291 if ( LevelMax < LevelCur )
292 LevelMax = LevelCur;
293 }
294 }
295 else
296 {
297 Abc_ObjForEachFanin( pObj, pNext, i )
298 {
299 LevelCur = Abc_NtkRetimeTiming_rec( pNext, fForward );
300 if ( LevelMax < LevelCur )
301 LevelMax = LevelCur;
302 }
303 }
304// printf( "Node %3d -> Level %3d.\n", pObj->Id, LevelMax + 1 );
305 pObj->Level = LevelMax + 1;
306 return pObj->Level;
307}
308
312
313
315
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
#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
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#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
int Abc_NtkRetimeMinDelay(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkCopy, int nDelayLim, int nIterLimit, int fForward, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition retDelay.c:50
void Abc_NtkRetimeNode(Abc_Obj_t *pObj, int fForward, int fInitial)
Definition retIncrem.c:324
void Abc_NtkRetimeShareLatches(Abc_Ntk_t *pNtk, int fInitial)
Definition retIncrem.c:436
int Abc_NtkRetimeNodeIsEnabled(Abc_Obj_t *pObj, int fForward)
Definition retIncrem.c:293
Abc_Ntk_t * Abc_NtkRetimeBackwardInitialStart(Abc_Ntk_t *pNtk)
Definition retInit.c:254
void Abc_NtkRetimeTranferToCopy(Abc_Ntk_t *pNtk)
Definition retInit.c:168
Vec_Int_t * Abc_NtkRetimeCollectLatchValues(Abc_Ntk_t *pNtk)
Definition retInit.c:208
void Abc_NtkRetimeBackwardInitialFinish(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew, Vec_Int_t *vValuesOld, int fVerbose)
Definition retInit.c:279
void Abc_NtkRetimeTranferFromCopy(Abc_Ntk_t *pNtk)
Definition retInit.c:188
unsigned Level
Definition abc.h:142
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55