ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sfmTim.c
Go to the documentation of this file.
1
20
21#include "sfmInt.h"
22
24
25
29
31{
32 // external
33 Mio_Library_t * pLib; // library
34 Scl_Con_t * pExt; // external timing
35 Abc_Ntk_t * pNtk; // mapped network
36 int Delay; // the largest delay
37 int DeltaCrit; // critical delay delta
38 // timing info
39 Vec_Int_t vTimArrs; // arrivals (rise/fall)
40 Vec_Int_t vTimReqs; // required (rise/fall)
41 // incremental timing
42 Vec_Wec_t vLevels; // levels
43 // critical path
44 Vec_Int_t vPath; // critical path
45 Vec_Wrd_t vSortData; // node priority order
46};
47
48static inline int * Sfm_TimArrId( Sfm_Tim_t * p, int Id ) { return Vec_IntEntryP( &p->vTimArrs, Abc_Var2Lit(Id, 0) ); }
49static inline int * Sfm_TimReqId( Sfm_Tim_t * p, int Id ) { return Vec_IntEntryP( &p->vTimReqs, Abc_Var2Lit(Id, 0) ); }
50
51static inline int * Sfm_TimArr( Sfm_Tim_t * p, Abc_Obj_t * pNode ) { return Vec_IntEntryP( &p->vTimArrs, Abc_Var2Lit(Abc_ObjId(pNode), 0) ); }
52static inline int * Sfm_TimReq( Sfm_Tim_t * p, Abc_Obj_t * pNode ) { return Vec_IntEntryP( &p->vTimReqs, Abc_Var2Lit(Abc_ObjId(pNode), 0) ); }
53
54static inline int Sfm_TimArrMaxId( Sfm_Tim_t * p, int Id ) { int * a = Sfm_TimArrId(p, Id); return Abc_MaxInt(a[0], a[1]); }
55
56static inline int Sfm_TimArrMax( Sfm_Tim_t * p, Abc_Obj_t * pNode ) { int * a = Sfm_TimArr(p, pNode); return Abc_MaxInt(a[0], a[1]); }
57static inline void Sfm_TimSetReq( Sfm_Tim_t * p, Abc_Obj_t * pNode, int t ) { int * r = Sfm_TimReq(p, pNode); r[0] = r[1] = t; }
58static inline int Sfm_TimSlack( Sfm_Tim_t * p, Abc_Obj_t * pNode ) { int * r = Sfm_TimReq(p, pNode), * a = Sfm_TimArr(p, pNode); return Abc_MinInt(r[0]-a[0], r[1]-a[1]); }
59
63
75static inline void Sfm_TimEdgeArrival( Sfm_Tim_t * p, Mio_Pin_t * pPin, int * pTimeIn, int * pTimeOut )
76{
77 Mio_PinPhase_t PinPhase = Mio_PinReadPhase(pPin);
78 int tDelayBlockRise = Scl_Flt2Int(Mio_PinReadDelayBlockRise(pPin));
79 int tDelayBlockFall = Scl_Flt2Int(Mio_PinReadDelayBlockFall(pPin));
80 if ( PinPhase != MIO_PHASE_INV ) // NONINV phase is present
81 {
82 pTimeOut[0] = Abc_MaxInt( pTimeOut[0], pTimeIn[0] + tDelayBlockRise );
83 pTimeOut[1] = Abc_MaxInt( pTimeOut[1], pTimeIn[1] + tDelayBlockFall );
84 }
85 if ( PinPhase != MIO_PHASE_NONINV ) // INV phase is present
86 {
87 pTimeOut[0] = Abc_MaxInt( pTimeOut[0], pTimeIn[1] + tDelayBlockRise );
88 pTimeOut[1] = Abc_MaxInt( pTimeOut[1], pTimeIn[0] + tDelayBlockFall );
89 }
90}
91static inline void Sfm_TimGateArrival( Sfm_Tim_t * p, Mio_Gate_t * pGate, int ** pTimesIn, int * pTimeOut )
92{
93 Mio_Pin_t * pPin; int i = 0;
94 pTimeOut[0] = pTimeOut[1] = 0;
95 Mio_GateForEachPin( pGate, pPin )
96 Sfm_TimEdgeArrival( p, pPin, pTimesIn[i++], pTimeOut );
97 assert( i == Mio_GateReadPinNum(pGate) );
98}
99static inline void Sfm_TimNodeArrival( Sfm_Tim_t * p, Abc_Obj_t * pNode )
100{
101 int i, iFanin, * pTimesIn[6];
102 int * pTimeOut = Sfm_TimArr(p, pNode);
103 assert( Abc_ObjFaninNum(pNode) <= 6 );
104 Abc_ObjForEachFaninId( pNode, iFanin, i )
105 pTimesIn[i] = Sfm_TimArrId( p, iFanin );
106 Sfm_TimGateArrival( p, (Mio_Gate_t *)pNode->pData, pTimesIn, pTimeOut );
107}
108
109static inline void Sfm_TimEdgeRequired( Sfm_Tim_t * p, Mio_Pin_t * pPin, int * pTimeIn, int * pTimeOut )
110{
111 Mio_PinPhase_t PinPhase = Mio_PinReadPhase(pPin);
112 int tDelayBlockRise = Scl_Flt2Int(Mio_PinReadDelayBlockRise(pPin));
113 int tDelayBlockFall = Scl_Flt2Int(Mio_PinReadDelayBlockFall(pPin));
114 if ( PinPhase != MIO_PHASE_INV ) // NONINV phase is present
115 {
116 pTimeIn[0] = Abc_MinInt( pTimeIn[0], pTimeOut[0] - tDelayBlockRise );
117 pTimeIn[1] = Abc_MinInt( pTimeIn[1], pTimeOut[1] - tDelayBlockFall );
118 }
119 if ( PinPhase != MIO_PHASE_NONINV ) // INV phase is present
120 {
121 pTimeIn[0] = Abc_MinInt( pTimeIn[0], pTimeOut[1] - tDelayBlockRise );
122 pTimeIn[1] = Abc_MinInt( pTimeIn[1], pTimeOut[0] - tDelayBlockFall );
123 }
124}
125static inline void Sfm_TimGateRequired( Sfm_Tim_t * p, Mio_Gate_t * pGate, int ** pTimesIn, int * pTimeOut )
126{
127 Mio_Pin_t * pPin; int i = 0;
128 Mio_GateForEachPin( pGate, pPin )
129 Sfm_TimEdgeRequired( p, pPin, pTimesIn[i++], pTimeOut );
130 assert( i == Mio_GateReadPinNum(pGate) );
131}
133{
134 int i, iFanin, * pTimesIn[6];
135 int * pTimeOut = Sfm_TimReq(p, pNode);
136 assert( Abc_ObjFaninNum(pNode) <= 6 );
137 Abc_ObjForEachFaninId( pNode, iFanin, i )
138 pTimesIn[i] = Sfm_TimReqId( p, iFanin );
139 Sfm_TimGateRequired( p, (Mio_Gate_t *)pNode->pData, pTimesIn, pTimeOut );
140}
141
142
154void Sfm_TimCriticalPath_int( Sfm_Tim_t * p, Abc_Obj_t * pObj, Vec_Int_t * vPath, int SlackMax )
155{
156 Abc_Obj_t * pNext; int i;
157 if ( Abc_NodeIsTravIdCurrent( pObj ) )
158 return;
159 Abc_NodeSetTravIdCurrent( pObj );
160 assert( Abc_ObjIsNode(pObj) );
161 Abc_ObjForEachFanin( pObj, pNext, i )
162 {
163 if ( Abc_ObjIsCi(pNext) || Abc_ObjFaninNum(pNext) == 0 )
164 continue;
165 assert( Abc_ObjIsNode(pNext) );
166 if ( Sfm_TimSlack(p, pNext) <= SlackMax )
167 Sfm_TimCriticalPath_int( p, pNext, vPath, SlackMax );
168 }
169 if ( Abc_ObjFaninNum(pObj) > 0 )
170 Vec_IntPush( vPath, Abc_ObjId(pObj) );
171}
172int Sfm_TimCriticalPath( Sfm_Tim_t * p, int Window )
173{
174 int i, SlackMax = p->Delay * Window / 100;
175 Abc_Obj_t * pObj, * pNext;
176 Vec_IntClear( &p->vPath );
177 Abc_NtkIncrementTravId( p->pNtk );
178 Abc_NtkForEachCo( p->pNtk, pObj, i )
179 {
180 pNext = Abc_ObjFanin0(pObj);
181 if ( Abc_ObjIsCi(pNext) || Abc_ObjFaninNum(pNext) == 0 )
182 continue;
183 assert( Abc_ObjIsNode(pNext) );
184 if ( Sfm_TimSlack(p, pNext) <= SlackMax )
185 Sfm_TimCriticalPath_int( p, pNext, &p->vPath, SlackMax );
186 }
187 return Vec_IntSize(&p->vPath);
188}
189
202{
203 Abc_Obj_t * pObj; int i, Delay = 0;
204 Vec_Ptr_t * vNodes = Abc_NtkDfs( p->pNtk, 1 );
205 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
206 Sfm_TimNodeArrival( p, pObj );
207 Abc_NtkForEachCo( p->pNtk, pObj, i )
208 Delay = Abc_MaxInt( Delay, Sfm_TimArrMax(p, Abc_ObjFanin0(pObj)) );
209 Vec_IntFill( &p->vTimReqs, 2*Abc_NtkObjNumMax(p->pNtk), ABC_INFINITY );
210 Abc_NtkForEachCo( p->pNtk, pObj, i )
211 Sfm_TimSetReq( p, Abc_ObjFanin0(pObj), Delay );
212 Vec_PtrForEachEntryReverse( Abc_Obj_t *, vNodes, pObj, i )
213 Sfm_TimNodeRequired( p, pObj );
214 Vec_PtrFree( vNodes );
215 return Delay;
216}
217
229Sfm_Tim_t * Sfm_TimStart( Mio_Library_t * pLib, Scl_Con_t * pExt, Abc_Ntk_t * pNtk, int DeltaCrit )
230{
232 p->pLib = pLib;
233 p->pExt = pExt;
234 p->pNtk = pNtk;
235 Vec_IntFill( &p->vTimArrs, 3*Abc_NtkObjNumMax(pNtk), 0 );
236 Vec_IntFill( &p->vTimReqs, 3*Abc_NtkObjNumMax(pNtk), 0 );
237 p->Delay = Sfm_TimTrace( p );
238 assert( DeltaCrit > 0 && DeltaCrit < Scl_Flt2Int(1000.0) );
239 p->DeltaCrit = DeltaCrit;
240 return p;
241}
243{
244 Vec_IntErase( &p->vTimArrs );
245 Vec_IntErase( &p->vTimReqs );
246 Vec_WecErase( &p->vLevels );
247 Vec_IntErase( &p->vPath );
248 Vec_WrdErase( &p->vSortData );
249 ABC_FREE( p );
250}
252{
253 return p->Delay;
254}
256{
257 return Sfm_TimArrMaxId(p, iObj);
258}
259
271void Sfm_TimTest( Abc_Ntk_t * pNtk )
272{
273 Mio_Library_t * pLib = (Mio_Library_t *)pNtk->pManFunc;
274 Sfm_Tim_t * p = Sfm_TimStart( pLib, NULL, pNtk, 100 );
275 printf( "Max delay = %.2f. Path = %d (%d).\n", Scl_Int2Flt(p->Delay), Sfm_TimCriticalPath(p, 1), Abc_NtkNodeNum(p->pNtk) );
276 Sfm_TimStop( p );
277}
278
290static inline void Sfm_TimUpdateClean( Sfm_Tim_t * p )
291{
292 Vec_Int_t * vLevel;
293 Abc_Obj_t * pObj;
294 int i, k;
295 Vec_WecForEachLevel( &p->vLevels, vLevel, i )
296 {
297 Abc_NtkForEachObjVec( vLevel, p->pNtk, pObj, k )
298 {
299 assert( pObj->fMarkC == 1 );
300 pObj->fMarkC = 0;
301 }
302 Vec_IntClear( vLevel );
303 }
304}
305
318{
319 assert( Vec_IntSize(vTimeNodes) > 0 && Vec_IntSize(vTimeNodes) <= 2 );
320 Vec_IntFillExtra( &p->vTimArrs, 2*Abc_NtkObjNumMax(p->pNtk), 0 );
321 Vec_IntFillExtra( &p->vTimReqs, 2*Abc_NtkObjNumMax(p->pNtk), 0 );
322 p->Delay = Sfm_TimTrace( p );
323}
324
336int Sfm_TimSortArrayByArrival( Sfm_Tim_t * p, Vec_Int_t * vNodes, int iPivot )
337{
338 word Entry;
339 int i, Id, Time, nDivNew = -1;
340 int MaxDelay = ABC_INFINITY/2+Sfm_TimArrMaxId(p, iPivot);
341 assert( p->DeltaCrit > 0 );
342 // collect nodes
343 Vec_WrdClear( &p->vSortData );
344 Vec_IntForEachEntry( vNodes, Id, i )
345 {
346 Time = Sfm_TimArrMaxId( p, Id );
347 assert( -ABC_INFINITY/2 < Time && Time < ABC_INFINITY/2 );
348 Vec_WrdPush( &p->vSortData, ((word)Id << 32) | (ABC_INFINITY/2+Time) );
349 }
350 // sort nodes by delay
351 Abc_QuickSort3( Vec_WrdArray(&p->vSortData), Vec_WrdSize(&p->vSortData), 0 );
352 // collect sorted nodes and find place where divisors end
353 Vec_IntClear( vNodes );
354 Vec_WrdForEachEntry( &p->vSortData, Entry, i )
355 {
356 Vec_IntPush( vNodes, (int)(Entry >> 32) );
357 if ( nDivNew == -1 && ((int)Entry) + p->DeltaCrit > MaxDelay )
358 nDivNew = i;
359 }
360 return nDivNew;
361}
362
374int Sfm_TimPriorityNodes( Sfm_Tim_t * p, Vec_Int_t * vCands, int Window )
375{
376 Vec_Int_t * vLevel;
377 Abc_Obj_t * pObj;
378 int i, k;
379 assert( Window >= 0 && Window <= 100 );
380 // collect critical path
381 Sfm_TimCriticalPath( p, Window );
382 // add nodes to the levelized structure
383 Sfm_TimUpdateClean( p );
384 Abc_NtkForEachObjVec( &p->vPath, p->pNtk, pObj, i )
385 {
386 assert( pObj->fMarkC == 0 );
387 pObj->fMarkC = 1;
388 Vec_WecPush( &p->vLevels, Abc_ObjLevel(pObj), Abc_ObjId(pObj) );
389 }
390 // prioritize nodes by expected gain
391 Vec_WecSort( &p->vLevels, 0 );
392 Vec_IntClear( vCands );
393 Vec_WecForEachLevel( &p->vLevels, vLevel, i )
394 Abc_NtkForEachObjVec( vLevel, p->pNtk, pObj, k )
395 if ( !pObj->fMarkA )
396 Vec_IntPush( vCands, Abc_ObjId(pObj) );
397// printf( "Path = %5d Cand = %5d\n", Vec_IntSize(&p->vPath) );
398 return Vec_IntSize(vCands) > 0;
399}
400
413{
414 return Sfm_TimArrMax(p, pNode) + p->DeltaCrit <= Sfm_TimArrMax(p, pPivot);
415}
416
428int Sfm_TimEvalRemapping( Sfm_Tim_t * p, Vec_Int_t * vFanins, Vec_Int_t * vMap, Mio_Gate_t * pGate1, char * pFans1, Mio_Gate_t * pGate2, char * pFans2 )
429{
430 int TimeOut[2][2];
431 int * pTimesIn1[6], * pTimesIn2[6];
432 int i, nFanins1, nFanins2;
433 // process the first gate
434 nFanins1 = Mio_GateReadPinNum( pGate1 );
435 for ( i = 0; i < nFanins1; i++ )
436 pTimesIn1[i] = Sfm_TimArrId( p, Vec_IntEntry(vMap, Vec_IntEntry(vFanins, (int)pFans1[i])) );
437 Sfm_TimGateArrival( p, pGate1, pTimesIn1, TimeOut[0] );
438 if ( pGate2 == NULL )
439 return Abc_MaxInt(TimeOut[0][0], TimeOut[0][1]);
440 // process the second gate
441 nFanins2 = Mio_GateReadPinNum( pGate2 );
442 for ( i = 0; i < nFanins2; i++ )
443 if ( (int)pFans2[i] == 16 )
444 pTimesIn2[i] = TimeOut[0];
445 else
446 pTimesIn2[i] = Sfm_TimArrId( p, Vec_IntEntry(vMap, Vec_IntEntry(vFanins, (int)pFans2[i])) );
447 Sfm_TimGateArrival( p, pGate2, pTimesIn2, TimeOut[1] );
448 return Abc_MaxInt(TimeOut[1][0], TimeOut[1][1]);
449}
450
451
455
456
458
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
Definition abcDfs.c:82
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define Abc_ObjForEachFaninId(pObj, iFanin, i)
Definition abc.h:531
#define Abc_NtkForEachObjVec(vIds, pNtk, pObj, i)
Definition abc.h:455
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
void Abc_QuickSort3(word *pData, int nSize, int fDecrease)
Definition utilSort.c:884
#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
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
double Mio_PinReadDelayBlockFall(Mio_Pin_t *pPin)
Definition mioApi.c:214
int Mio_GateReadPinNum(Mio_Gate_t *pGate)
Definition mioApi.c:177
Mio_PinPhase_t
INCLUDES ///.
Definition mio.h:40
@ MIO_PHASE_INV
Definition mio.h:40
@ MIO_PHASE_NONINV
Definition mio.h:40
struct Mio_LibraryStruct_t_ Mio_Library_t
Definition mio.h:42
Mio_PinPhase_t Mio_PinReadPhase(Mio_Pin_t *pPin)
Definition mioApi.c:209
struct Mio_PinStruct_t_ Mio_Pin_t
Definition mio.h:44
double Mio_PinReadDelayBlockRise(Mio_Pin_t *pPin)
Definition mioApi.c:212
#define Mio_GateForEachPin(Gate, Pin)
Definition mio.h:92
struct Mio_GateStruct_t_ Mio_Gate_t
Definition mio.h:43
typedefABC_NAMESPACE_HEADER_START struct Scl_Con_t_ Scl_Con_t
DECLARATIONS ///.
Definition sclCon.h:30
struct Sfm_Tim_t_ Sfm_Tim_t
Definition sfmInt.h:68
int Sfm_TimSortArrayByArrival(Sfm_Tim_t *p, Vec_Int_t *vNodes, int iPivot)
Definition sfmTim.c:336
int Sfm_TimCriticalPath(Sfm_Tim_t *p, int Window)
Definition sfmTim.c:172
int Sfm_TimTrace(Sfm_Tim_t *p)
Definition sfmTim.c:201
void Sfm_TimTest(Abc_Ntk_t *pNtk)
Definition sfmTim.c:271
Sfm_Tim_t * Sfm_TimStart(Mio_Library_t *pLib, Scl_Con_t *pExt, Abc_Ntk_t *pNtk, int DeltaCrit)
Definition sfmTim.c:229
void Sfm_TimCriticalPath_int(Sfm_Tim_t *p, Abc_Obj_t *pObj, Vec_Int_t *vPath, int SlackMax)
Definition sfmTim.c:154
int Sfm_TimReadObjDelay(Sfm_Tim_t *p, int iObj)
Definition sfmTim.c:255
int Sfm_TimNodeIsNonCritical(Sfm_Tim_t *p, Abc_Obj_t *pPivot, Abc_Obj_t *pNode)
Definition sfmTim.c:412
int Sfm_TimReadNtkDelay(Sfm_Tim_t *p)
Definition sfmTim.c:251
void Sfm_TimUpdateTiming(Sfm_Tim_t *p, Vec_Int_t *vTimeNodes)
Definition sfmTim.c:317
void Sfm_TimStop(Sfm_Tim_t *p)
Definition sfmTim.c:242
void Sfm_TimNodeRequired(Sfm_Tim_t *p, Abc_Obj_t *pNode)
Definition sfmTim.c:132
int Sfm_TimEvalRemapping(Sfm_Tim_t *p, Vec_Int_t *vFanins, Vec_Int_t *vMap, Mio_Gate_t *pGate1, char *pFans1, Mio_Gate_t *pGate2, char *pFans2)
Definition sfmTim.c:428
int Sfm_TimPriorityNodes(Sfm_Tim_t *p, Vec_Int_t *vCands, int Window)
Definition sfmTim.c:374
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:145
unsigned fMarkC
Definition abc.h:136
unsigned fMarkA
Definition abc.h:134
DECLARATIONS ///.
Definition sfmTim.c:31
int Delay
Definition sfmTim.c:36
Vec_Wec_t vLevels
Definition sfmTim.c:42
Vec_Int_t vPath
Definition sfmTim.c:44
Scl_Con_t * pExt
Definition sfmTim.c:34
Abc_Ntk_t * pNtk
Definition sfmTim.c:35
Vec_Int_t vTimArrs
Definition sfmTim.c:39
Vec_Wrd_t vSortData
Definition sfmTim.c:45
Vec_Int_t vTimReqs
Definition sfmTim.c:40
int DeltaCrit
Definition sfmTim.c:37
Mio_Library_t * pLib
Definition sfmTim.c:33
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_PtrForEachEntryReverse(Type, vVec, pEntry, i)
Definition vecPtr.h:63
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
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition vecWec.h:55
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecWrd.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42