ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ifSeq.c
Go to the documentation of this file.
1
20
21#include "if.h"
22
24
25
29
31
35
48{
49 If_Obj_t * pObjLi, * pObjLo;
50 int i;
51
52 // link the latch outputs (CIs) directly to the drivers of latch inputs (COs)
53 for ( i = 0; i < p->pPars->nLatchesCi; i++ )
54 {
55 pObjLi = If_ManLi( p, i );
56 pObjLo = If_ManLo( p, i );
57 pObjLo->pFanin0 = If_ObjFanin0( pObjLi );
58 pObjLo->fCompl0 = If_ObjFaninC0( pObjLi );
59 }
60}
61
74{
75 if ( !If_ObjIsLatch(pObj) )
76 return;
77 if ( pObj->fMark )
78 return;
79 pObj->fMark = 1;
80 If_ManCollectLatches_rec( pObj->pFanin0, vLatches );
81 Vec_PtrPush( vLatches, pObj );
82}
83
96{
97 Vec_Ptr_t * vLatches;
98 If_Obj_t * pObj;
99 int i;
100 // collect latches
101 vLatches = Vec_PtrAlloc( p->pPars->nLatchesCi );
102 If_ManForEachLatchOutput( p, pObj, i )
103 If_ManCollectLatches_rec( pObj, vLatches );
104 // clean marks
105 Vec_PtrForEachEntry( If_Obj_t *, vLatches, pObj, i )
106 pObj->fMark = 0;
107 assert( Vec_PtrSize(vLatches) == p->pPars->nLatchesCi );
108 return vLatches;
109}
110
124{
125 If_Obj_t * pObj;
126 int i;
127 abctime clk = Abc_Clock();
128 int fVeryVerbose = 0;
129 int fChange = 0;
130
131 if ( nIter == 1 )
132 {
133 // if some latches depend on PIs, update their values
134 Vec_PtrForEachEntry( If_Obj_t *, p->vLatchOrder, pObj, i )
135 {
136 If_ObjSetLValue( pObj, If_ObjLValue(If_ObjFanin0(pObj)) - p->Period );
137 If_ObjSetArrTime( pObj, If_ObjLValue(pObj) );
138 }
139 }
140
141 // map the internal nodes
142 p->nCutsMerged = 0;
143 If_ManForEachNode( p, pObj, i )
144 {
145 If_ObjPerformMappingAnd( p, pObj, 0, 0, 0 );
146 if ( pObj->fRepr )
147 If_ObjPerformMappingChoice( p, pObj, 0, 0 );
148 }
149
150 // postprocess the mapping
151//Abc_Print( 1, "Itereation %d: \n", nIter );
152 If_ManForEachNode( p, pObj, i )
153 {
154 // update the LValues stored separately
155 if ( If_ObjLValue(pObj) < If_ObjCutBest(pObj)->Delay - p->fEpsilon )
156 {
157 If_ObjSetLValue( pObj, If_ObjCutBest(pObj)->Delay );
158 fChange = 1;
159 }
160//Abc_Print( 1, "%d ", (int)If_ObjLValue(pObj) );
161 // reset the visit counters
162 assert( pObj->nVisits == 0 );
163 pObj->nVisits = pObj->nVisitsCopy;
164 }
165//Abc_Print( 1, "\n" );
166
167 // propagate LValues over the registers
168 Vec_PtrForEachEntry( If_Obj_t *, p->vLatchOrder, pObj, i )
169 {
170 If_ObjSetLValue( pObj, If_ObjLValue(If_ObjFanin0(pObj)) - p->Period );
171 If_ObjSetArrTime( pObj, If_ObjLValue(pObj) );
172 }
173
174 // compute area and delay
176 if ( fVeryVerbose )
177 {
178 p->RequiredGlo = If_ManDelayMax( p, 1 );
179// p->AreaGlo = If_ManScanMapping(p);
180 Abc_Print( 1, "S%d: Fi = %6.2f. Del = %6.2f. Area = %8.2f. Cuts = %8d. ",
181 nIter, (float)p->Period, p->RequiredGlo, p->AreaGlo, p->nCutsMerged );
182 Abc_PrintTime( 1, "T", Abc_Clock() - clk );
183 }
184 return fChange;
185}
186
199{
200 If_Obj_t * pObj;
201 int i, c, fConverged;
202// int fResetRefs = 0;
203 p->nAttempts++;
204
205 // reset initial LValues (PIs to 0; others to -inf)
206 If_ManForEachObj( p, pObj, i )
207 {
208 If_ObjSetLValue( pObj, (float)-IF_INFINITY );
209 If_ObjSetArrTime( pObj, (float)-IF_INFINITY );
210 // undo any previous mapping, except for CIs
211 if ( If_ObjIsAnd(pObj) )
212 If_ObjCutBest(pObj)->nLeaves = 0;
213 }
214 pObj = If_ManConst1( p );
215 If_ObjSetLValue( pObj, (float)0.0 );
216 If_ObjSetArrTime( pObj, (float)0.0 );
217 If_ManForEachPi( p, pObj, i )
218 {
219 pObj = If_ManCi( p, i );
220 If_ObjSetLValue( pObj, (float)0.0 );
221 If_ObjSetArrTime( pObj, (float)0.0 );
222 }
223
224 // update all values iteratively
225 fConverged = 0;
226 for ( c = 1; c <= p->nMaxIters; c++ )
227 {
228 if ( !If_ManPerformMappingRoundSeq( p, c ) )
229 {
230 p->RequiredGlo = If_ManDelayMax( p, 1 );
231 fConverged = 1;
232 break;
233 }
234 p->RequiredGlo = If_ManDelayMax( p, 1 );
235//Abc_Print( 1, "Global = %d \n", (int)p->RequiredGlo );
236 if ( p->RequiredGlo > p->Period + p->fEpsilon )
237 break;
238 }
239
240 // report the results
242 if ( p->pPars->fVerbose )
243 {
244// p->AreaGlo = If_ManScanMapping(p);
245 Abc_Print( 1, "Attempt = %2d. Iters = %3d. Area = %10.2f. Fi = %6.2f. ", p->nAttempts, c, p->AreaGlo, (float)p->Period );
246 if ( fConverged )
247 Abc_Print( 1, " Feasible" );
248 else if ( c > p->nMaxIters )
249 Abc_Print( 1, "Infeasible (timeout)" );
250 else
251 Abc_Print( 1, "Infeasible" );
252 Abc_Print( 1, "\n" );
253 }
254 return fConverged;
255}
256
257
269int If_ManBinarySearch_rec( If_Man_t * p, int FiMin, int FiMax )
270{
271 assert( FiMin < FiMax );
272 if ( FiMin + 1 == FiMax )
273 return FiMax;
274 // compute the median
275 p->Period = FiMin + (FiMax - FiMin)/2;
277 return If_ManBinarySearch_rec( p, FiMin, p->Period ); // Median is feasible
278 else
279 return If_ManBinarySearch_rec( p, p->Period, FiMax ); // Median is infeasible
280}
281
294{
295 If_Obj_t * pObjLi, * pObjLo, * pObj;
296 int i;
297 assert( 0 );
298
299 // set arrival times
300 assert( p->pPars->pTimesArr != NULL );
301 If_ManForEachLatchOutput( p, pObjLo, i )
302 p->pPars->pTimesArr[i] = If_ObjLValue(pObjLo);
303
304 // set the required times
305 assert( p->pPars->pTimesReq == NULL );
306 p->pPars->pTimesReq = ABC_ALLOC( float, If_ManCoNum(p) );
307 If_ManForEachPo( p, pObj, i )
308 p->pPars->pTimesReq[i] = p->RequiredGlo2;
309 If_ManForEachLatchInput( p, pObjLi, i )
310 p->pPars->pTimesReq[i] = If_ObjLValue(If_ObjFanin0(pObjLi));
311
312 // undo previous mapping
313 If_ManForEachObj( p, pObj, i )
314 if ( If_ObjIsAnd(pObj) )
315 If_ObjCutBest(pObj)->nLeaves = 0;
316
317 // map again combinationally
318// p->pPars->fSeqMap = 0;
320// p->pPars->fSeqMap = 1;
321}
322
335{
336 abctime clkTotal = Abc_Clock();
337 int PeriodBest;
338
339 p->SortMode = 0;
340
341 // perform combinational mapping to get the upper bound on the clock period
342 If_ManPerformMappingRound( p, 1, 0, 0, 1, NULL );
343 p->RequiredGlo = If_ManDelayMax( p, 0 );
344 p->RequiredGlo2 = p->RequiredGlo;
345
346 // set direct linking of latches with their inputs
348
349 // collect latches
350 p->vLatchOrder = If_ManCollectLatches( p );
351
352 // set parameters
353 p->nCutsUsed = p->pPars->nCutsMax;
354 p->nAttempts = 0;
355 p->nMaxIters = 50;
356 p->Period = (int)p->RequiredGlo;
357
358 // make sure the clock period works
359 if ( !If_ManBinarySearchPeriod( p ) )
360 {
361 Abc_Print( 1, "If_ManPerformMappingSeq(): The upper bound on the clock period cannot be computed.\n" );
362 return 0;
363 }
364
365 // perform binary search
366 PeriodBest = If_ManBinarySearch_rec( p, 0, p->Period );
367
368 // recompute the best l-values
369 if ( p->Period != PeriodBest )
370 {
371 p->Period = PeriodBest;
372 if ( !If_ManBinarySearchPeriod( p ) )
373 {
374 Abc_Print( 1, "If_ManPerformMappingSeq(): The final clock period cannot be confirmed.\n" );
375 return 0;
376 }
377 }
378// if ( p->pPars->fVerbose )
379 {
380 Abc_Print( 1, "The best clock period is %3d. ", p->Period );
381 Abc_PrintTime( 1, "Time", Abc_Clock() - clkTotal );
382 }
383 p->RequiredGlo = (float)(PeriodBest);
384
385 // postprocess it using combinational mapping
387 s_MappingTime = Abc_Clock() - clkTotal;
388 return 1;
389}
390
394
395
397
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
Vec_Ptr_t * If_ManCollectLatches(If_Man_t *p)
Definition ifSeq.c:95
int If_ManBinarySearch_rec(If_Man_t *p, int FiMin, int FiMax)
Definition ifSeq.c:269
int If_ManPerformMappingRoundSeq(If_Man_t *p, int nIter)
Definition ifSeq.c:123
void If_ManPerformMappingSeqPost(If_Man_t *p)
Definition ifSeq.c:293
void If_ManPrepareMappingSeq(If_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition ifSeq.c:47
void If_ManCollectLatches_rec(If_Obj_t *pObj, Vec_Ptr_t *vLatches)
Definition ifSeq.c:73
int If_ManPerformMappingSeq(If_Man_t *p)
Definition ifSeq.c:334
int If_ManBinarySearchPeriod(If_Man_t *p)
Definition ifSeq.c:198
#define If_ManForEachObj(p, pObj, i)
Definition if.h:491
void If_ObjPerformMappingAnd(If_Man_t *p, If_Obj_t *pObj, int Mode, int fPreprocess, int fFirst)
Definition ifMap.c:162
#define If_ManForEachPi(p, pObj, i)
Definition if.h:480
int If_ManPerformMappingComb(If_Man_t *p)
Definition ifCore.c:106
void If_ManMarkMapping(If_Man_t *p)
Definition ifUtil.c:434
void If_ObjPerformMappingChoice(If_Man_t *p, If_Obj_t *pObj, int Mode, int fPreprocess)
Definition ifMap.c:521
float If_ManDelayMax(If_Man_t *p, int fSeq)
Definition ifTime.c:269
int If_ManPerformMappingRound(If_Man_t *p, int nCutsUsed, int Mode, int fPreprocess, int fFirst, char *pLabel)
Definition ifMap.c:606
#define If_ManForEachLatchInput(p, pObj, i)
Definition if.h:486
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
Definition if.h:77
#define If_ManForEachNode(p, pObj, i)
Definition if.h:497
#define If_ManForEachPo(p, pObj, i)
Definition if.h:483
struct If_Obj_t_ If_Obj_t
Definition if.h:79
#define IF_INFINITY
Definition if.h:57
#define If_ManForEachLatchOutput(p, pObj, i)
Definition if.h:488
abctime s_MappingTime
DECLARATIONS ///.
Definition abcPrint.c:47
unsigned fMark
Definition if.h:338
If_Obj_t * pFanin0
Definition if.h:349
int nVisits
Definition if.h:347
unsigned fRepr
Definition if.h:337
int nVisitsCopy
Definition if.h:348
unsigned fCompl0
Definition if.h:334
#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