ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaSif.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22
24
28
32
45{
46 if ( Gia_ObjUpdateTravIdCurrent(p, pObj) )
47 return;
48 assert( Gia_ObjIsAnd(pObj) );
49 Gia_ManSifDupNode_rec( pNew, p, Gia_ObjFanin0(pObj) );
50 Gia_ManSifDupNode_rec( pNew, p, Gia_ObjFanin1(pObj) );
51 pObj->Value = Gia_ManAppendAnd2( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
52}
53void Gia_ManSifDupNode( Gia_Man_t * pNew, Gia_Man_t * p, int iObj, Vec_Int_t * vCopy )
54{
55 int k, iFan;
56 Gia_Obj_t * pObj = Gia_ManObj(p, iObj);
58 Gia_LutForEachFanin( p, iObj, iFan, k )
59 {
60 assert( Vec_IntEntry(vCopy, iFan) >= 0 );
61 Gia_ManObj(p, iFan)->Value = Vec_IntEntry(vCopy, iFan);
62 Gia_ObjUpdateTravIdCurrentId(p, iFan);
63 }
64 Gia_ManSifDupNode_rec( pNew, p, pObj );
65 Vec_IntWriteEntry( vCopy, iObj, pObj->Value );
66}
68{
69 Vec_Int_t * vRes = Vec_IntAlloc( Vec_IntSize(vRegs) );
70 Gia_Obj_t * pObj; int i, iObj;
71 Gia_Man_t * pNew = Gia_ManStart( 1000 ), * pTemp;
72 Vec_Int_t * vCopy = Vec_IntStartFull( Gia_ManObjNum(p) );
73 Vec_IntWriteEntry( vCopy, 0, 0 );
74 Gia_ManForEachRo( p, pObj, i )
75 Vec_IntWriteEntry( vCopy, Gia_ObjId(p, pObj), Gia_ManAppendCi(pNew) );
76 pNew->pName = Abc_UtilStrsav( p->pName );
77 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
78 Vec_IntForEachEntry( vMoves, iObj, i )
79 Gia_ManSifDupNode( pNew, p, iObj, vCopy );
80 Vec_IntForEachEntry( vRegs, iObj, i )
81 {
82 int iLit = Vec_IntEntry( vCopy, iObj );
83 assert( iLit >= 0 );
84 Gia_ManAppendCo( pNew, iLit );
85 }
86 pNew = Gia_ManCleanup( pTemp = pNew );
87 Gia_ManStop( pTemp );
88 Gia_ManSetPhase( pNew );
89 Gia_ManForEachPo( pNew, pObj, i )
90 Vec_IntPush( vRes, pObj->fPhase );
91 Gia_ManStop( pNew );
92 Vec_IntFree( vCopy );
93 assert( Vec_IntSize(vRes) == Vec_IntSize(vRegs) );
94 return vRes;
95}
97{
98 extern int * Abc_NtkSolveGiaMiter( Gia_Man_t * p );
99 int i, iObj, iLitAnd = 1, * pResult = NULL;
100 Gia_Obj_t * pObj; Vec_Int_t * vRes = NULL;
101 Gia_Man_t * pNew = Gia_ManStart( 1000 ), * pTemp;
102 Vec_Int_t * vCopy = Vec_IntStartFull( Gia_ManObjNum(p) );
103 Vec_IntWriteEntry( vCopy, 0, 0 );
104 Vec_IntForEachEntry( vRegs, iObj, i )
105 Vec_IntWriteEntry( vCopy, iObj, Gia_ManAppendCi(pNew) );
106 pNew->pName = Abc_UtilStrsav( p->pName );
107 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
108 Vec_IntForEachEntry( vMoves, iObj, i )
109 Gia_ManSifDupNode( pNew, p, iObj, vCopy );
110 Gia_ManForEachRi( p, pObj, i )
111 {
112 int iFan = Gia_ObjFaninId0p(p, pObj);
113 int iLit = Vec_IntEntry(vCopy, iFan);
114 if ( iLit == -1 )
115 continue;
116 iLit = Abc_LitNotCond( iLit, Gia_ObjFaninC0(pObj) );
117 iLitAnd = Gia_ManAppendAnd2( pNew, iLitAnd, Abc_LitNot(iLit) );
118 }
119 Gia_ManAppendCo( pNew, iLitAnd );
120 pNew = Gia_ManCleanup( pTemp = pNew );
121 Gia_ManStop( pTemp );
122 pResult = Abc_NtkSolveGiaMiter( pNew );
123 if ( pResult )
124 {
125 vRes = Vec_IntAllocArray( pResult, Vec_IntSize(vRegs) );
126 Gia_ManSetPhasePattern( pNew, vRes );
127 assert( Gia_ManPo(pNew, 0)->fPhase == 1 );
128 }
129 else
130 {
131 vRes = Vec_IntStart( Vec_IntSize(vRegs) );
132 printf( "***!!!*** The SAT problem has no solution. Using all-0 initial state. ***!!!***\n" );
133 }
134 Gia_ManStop( pNew );
135 Vec_IntFree( vCopy );
136 assert( Vec_IntSize(vRes) == Vec_IntSize(vRegs) );
137 return vRes;
138}
139Gia_Man_t * Gia_ManSifDerive( Gia_Man_t * p, Vec_Int_t * vCounts, int fVerbose )
140{
141 Gia_Man_t * pNew = NULL; Gia_Obj_t * pObj;
142 Vec_Int_t * vCopy = Vec_IntStartFull( Gia_ManObjNum(p) );
143 Vec_Int_t * vCopy2 = Vec_IntStartFull( Gia_ManObjNum(p) );
144 Vec_Int_t * vLuts[3], * vRos[3], * vRegs[2], * vInits[2], * vTemp;
145 int i, k, Id, iFan;
146 for ( i = 0; i < 3; i++ )
147 {
148 vLuts[i] = Vec_IntAlloc(100);
149 vRos[i] = Vec_IntAlloc(100);
150 if ( i == 2 ) break;
151 vRegs[i] = Vec_IntAlloc(100);
152 }
153 Gia_ManForEachLut( p, i )
154 if ( Vec_IntEntry(vCounts, i) == 1 )
155 Vec_IntPush( vLuts[0], i );
156 else if ( Vec_IntEntry(vCounts, i) == -1 )
157 Vec_IntPush( vLuts[1], i );
158 else if ( Vec_IntEntry(vCounts, i) == 0 )
159 Vec_IntPush( vLuts[2], i );
160 else assert( 0 );
161 assert( Vec_IntSize(vLuts[0]) || Vec_IntSize(vLuts[1]) );
162 if ( Vec_IntSize(vLuts[0]) )
163 {
165 Vec_IntForEachEntry( vLuts[0], Id, i )
166 Gia_ObjSetTravIdCurrentId(p, Id);
167 Gia_ManForEachRo( p, pObj, i )
168 if ( Gia_ObjIsTravIdCurrent(p, Gia_ObjFanin0(Gia_ObjRoToRi(p, pObj))) )
169 Vec_IntPush( vRos[0], Gia_ObjId(p, pObj) );
170 assert( !Vec_IntSize(vLuts[0]) == !Vec_IntSize(vRos[0]) );
171 }
172 if ( Vec_IntSize(vLuts[1]) )
173 {
175 Vec_IntForEachEntry( vLuts[1], Id, i )
176 Gia_LutForEachFanin( p, Id, iFan, k )
177 Gia_ObjSetTravIdCurrentId(p, iFan);
178 Gia_ManForEachRo( p, pObj, i )
179 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
180 Vec_IntPush( vRos[1], Gia_ObjId(p, pObj) );
181 assert( !Vec_IntSize(vLuts[1]) == !Vec_IntSize(vRos[1]) );
182 }
184 for ( k = 0; k < 2; k++ )
185 Vec_IntForEachEntry( vRos[k], Id, i )
186 Gia_ObjSetTravIdCurrentId(p, Id);
187 Gia_ManForEachRo( p, pObj, i )
188 if ( !Gia_ObjIsTravIdCurrent(p, pObj) )
189 Vec_IntPush( vRos[2], Gia_ObjId(p, pObj) );
190
192 Vec_IntForEachEntry( vLuts[0], Id, i )
193 Gia_ObjSetTravIdCurrentId(p, Id);
194 Vec_IntForEachEntry( vLuts[0], Id, i )
195 Gia_LutForEachFanin( p, Id, iFan, k )
196 if ( !Gia_ObjUpdateTravIdCurrentId(p, iFan) )
197 Vec_IntPush( vRegs[0], iFan );
198 Vec_IntSort( vRegs[0], 0 );
199 assert( Vec_IntCountDuplicates(vRegs[1]) == 0 );
200 assert( !Vec_IntSize(vLuts[0]) == !Vec_IntSize(vRegs[0]) );
201
203 Vec_IntForEachEntry( vLuts[0], Id, i )
204 Gia_LutForEachFanin( p, Id, iFan, k )
205 Gia_ObjSetTravIdCurrentId(p, iFan);
206 Vec_IntForEachEntry( vLuts[2], Id, i )
207 Gia_LutForEachFanin( p, Id, iFan, k )
208 Gia_ObjSetTravIdCurrentId(p, iFan);
209 Gia_ManForEachCo( p, pObj, i )
210 Gia_ObjSetTravIdCurrentId(p, Gia_ObjFaninId0p(p, pObj));
211 Vec_IntForEachEntry( vRos[1], Id, i )
212 if ( Gia_ObjIsTravIdCurrentId(p, Id) )
213 Vec_IntPush( vRegs[1], Id );
214 Vec_IntForEachEntry( vLuts[1], Id, i )
215 if ( Gia_ObjIsTravIdCurrentId(p, Id) )
216 Vec_IntPush( vRegs[1], Id );
217 Vec_IntSort( vRegs[1], 0 );
218 assert( Vec_IntCountDuplicates(vRegs[1]) == 0 );
219 assert( !Vec_IntSize(vLuts[1]) == !Vec_IntSize(vRegs[1]) );
220
221 vInits[0] = Vec_IntSize(vLuts[0]) ? Gia_ManSifInitPos( p, vLuts[0], vRegs[0] ) : Vec_IntAlloc(0);
222 vInits[1] = Vec_IntSize(vLuts[1]) ? Gia_ManSifInitNeg( p, vLuts[1], vRegs[1] ) : Vec_IntAlloc(0);
223
224 if ( fVerbose )
225 {
226 printf( "Flops : %5d %5d %5d\n", Vec_IntSize(vRos[0]), Vec_IntSize(vRos[1]), Vec_IntSize(vRos[2]) );
227 printf( "LUTs : %5d %5d %5d\n", Vec_IntSize(vLuts[0]), Vec_IntSize(vLuts[1]), Vec_IntSize(vLuts[2]) );
228 printf( "Spots : %5d %5d %5d\n", Vec_IntSize(vRegs[0]), Vec_IntSize(vRegs[1]), 0 );
229 }
230
231 pNew = Gia_ManStart( Gia_ManObjNum(p) + Vec_IntSize(vRegs[0]) + Vec_IntSize(vRegs[1]) );
232 pNew->pName = Abc_UtilStrsav( p->pName );
233 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
234
235 Vec_IntWriteEntry( vCopy, 0, 0 );
236 Gia_ManForEachPi( p, pObj, i )
237 Vec_IntWriteEntry( vCopy, Gia_ObjId(p, pObj), Gia_ManAppendCi(pNew) );
238 Vec_IntForEachEntry( vRos[2], Id, i )
239 Vec_IntWriteEntry( vCopy, Id, Gia_ManAppendCi(pNew) );
240 Vec_IntForEachEntry( vRegs[1], Id, i )
241 Vec_IntWriteEntry( vCopy, Id, Abc_LitNotCond(Gia_ManAppendCi(pNew), Vec_IntEntry(vInits[1], i)) );
242
243 vTemp = Vec_IntAlloc(100);
244 Vec_IntForEachEntry( vRegs[0], Id, i )
245 Vec_IntPush( vTemp, Vec_IntEntry(vCopy, Id) );
246 Vec_IntForEachEntry( vRegs[0], Id, i )
247 Vec_IntWriteEntry( vCopy, Id, Abc_LitNotCond(Gia_ManAppendCi(pNew), Vec_IntEntry(vInits[0], i)) );
248 Vec_IntForEachEntry( vLuts[0], Id, i )
249 Gia_ManSifDupNode( pNew, p, Id, vCopy );
250 Vec_IntForEachEntry( vRegs[0], Id, i )
251 Vec_IntWriteEntry( vCopy, Id, Vec_IntEntry(vTemp, i) );
252 Vec_IntFree( vTemp );
253
254 Gia_ManForEachRoToRiVec( vRos[0], p, pObj, i )
255 Vec_IntWriteEntry( vCopy, Vec_IntEntry(vRos[0], i), Abc_LitNotCond(Vec_IntEntry(vCopy, Gia_ObjFaninId0p(p, pObj)), Gia_ObjFaninC0(pObj)) );
256 Vec_IntForEachEntry( vLuts[2], Id, i )
257 Gia_ManSifDupNode( pNew, p, Id, vCopy );
258
259 Gia_ManForEachRoToRiVec( vRos[1], p, pObj, i )
260 Vec_IntWriteEntry( vCopy2, Vec_IntEntry(vRos[1], i), Abc_LitNotCond(Vec_IntEntry(vCopy, Gia_ObjFaninId0p(p, pObj)), Gia_ObjFaninC0(pObj)) );
261 Vec_IntForEachEntry( vLuts[1], Id, i )
262 Gia_ManSifDupNode( pNew, p, Id, vCopy2 );
263
264 Gia_ManForEachPo( p, pObj, i )
265 Gia_ManAppendCo( pNew, Abc_LitNotCond(Vec_IntEntry(vCopy, Gia_ObjFaninId0p(p, pObj)), Gia_ObjFaninC0(pObj)) );
266 Gia_ManForEachRoToRiVec( vRos[2], p, pObj, i )
267 Gia_ManAppendCo( pNew, Abc_LitNotCond(Vec_IntEntry(vCopy, Gia_ObjFaninId0p(p, pObj)), Gia_ObjFaninC0(pObj)) );
268 Vec_IntForEachEntry( vRegs[1], Id, i )
269 Gia_ManAppendCo( pNew, Abc_LitNotCond(Vec_IntEntry(vCopy2, Id), Vec_IntEntry(vInits[1], i)) );
270 Vec_IntForEachEntry( vRegs[0], Id, i )
271 Gia_ManAppendCo( pNew, Abc_LitNotCond(Vec_IntEntry(vCopy, Id), Vec_IntEntry(vInits[0], i)) );
272
273 Gia_ManSetRegNum( pNew, Vec_IntSize(vRos[2]) + Vec_IntSize(vRegs[0]) + Vec_IntSize(vRegs[1]) );
274
275 for ( i = 0; i < 3; i++ )
276 {
277 Vec_IntFreeP( &vLuts[i] );
278 Vec_IntFreeP( &vRos[i] );
279 if ( i == 2 ) break;
280 Vec_IntFreeP( &vRegs[i] );
281 Vec_IntFreeP( &vInits[i] );
282 }
283 Vec_IntFree( vCopy );
284 Vec_IntFree( vCopy2 );
285 return pNew;
286}
287
288
289
301int Gia_ManSifArea_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vCuts, int nSize )
302{
303 int i, * pCut, Area = 1;
304 if ( Gia_ObjUpdateTravIdCurrent(p, pObj) )
305 return 0;
306 if ( !Gia_ObjIsAnd(pObj) )
307 return 0;
308 pCut = Vec_IntEntryP( vCuts, Gia_ObjId(p, pObj)*nSize );
309 for ( i = 1; i <= pCut[0]; i++ )
310 Area += Gia_ManSifArea_rec( p, Gia_ManObj(p, pCut[i] >> 8), vCuts, nSize );
311 return Area;
312}
313int Gia_ManSifArea( Gia_Man_t * p, Vec_Int_t * vCuts, int nSize )
314{
315 Gia_Obj_t * pObj; int i, nArea = 0;
317 Gia_ManForEachCo( p, pObj, i )
318 nArea += Gia_ManSifArea_rec( p, Gia_ObjFanin0(pObj), vCuts, nSize );
319 return nArea;
320}
321int Gia_ManSifDelay_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nSize )
322{
323 int i, * pCut, Delay, nFails = 0;
324 if ( Gia_ObjUpdateTravIdCurrent(p, pObj) )
325 return 0;
326 if ( !Gia_ObjIsAnd(pObj) )
327 return 0;
328 pCut = Vec_IntEntryP( vCuts, Gia_ObjId(p, pObj)*nSize );
329 Delay = -ABC_INFINITY-10000;
330 for ( i = 1; i <= pCut[0]; i++ )
331 {
332 nFails += Gia_ManSifDelay_rec( p, Gia_ManObj(p, pCut[i] >> 8), vCuts, vTimes, nSize );
333 Delay = Abc_MaxInt( Delay, Vec_IntEntry(vTimes, pCut[i] >> 8) );
334 }
335 Delay += 1;
336 return nFails + (int)(Delay > Vec_IntEntry(vTimes, Gia_ObjId(p, pObj)));
337}
338int Gia_ManSifDelay( Gia_Man_t * p, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nSize )
339{
340 Gia_Obj_t * pObj; int i, nFails = 0;
342 Gia_ManForEachCo( p, pObj, i )
343 nFails += Gia_ManSifDelay_rec( p, Gia_ObjFanin0(pObj), vCuts, vTimes, nSize );
344 return nFails;
345}
346static inline int Gia_ManSifTimeToCount( int Value, int Period )
347{
348 return (Period*0xFFFF + Value)/Period + ((Period*0xFFFF + Value)%Period != 0) - 0x10000;
349}
351{
352 int i, Times;
353 Vec_Int_t * vCounts = Vec_IntStart( Gia_ManObjNum(p) );
354 Vec_IntFillExtra( vTimes, Gia_ManObjNum(p), 0 );
355 Vec_IntForEachEntry( vTimes, Times, i )
356 if ( Gia_ObjIsLut(p, i) )
357 Vec_IntWriteEntry( vCounts, i, Gia_ManSifTimeToCount(Times, Period) );
358 return vCounts;
359}
360Gia_Man_t * Gia_ManSifTransform( Gia_Man_t * p, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nLutSize, int Period, int fVerbose )
361{
362 Gia_Man_t * pNew = NULL; Vec_Int_t * vCounts = NULL;
363 if ( fVerbose )
364 printf( "Current area = %d. Period = %d. ", Gia_ManSifArea(p, vCuts, nLutSize+1), Period );
365 if ( fVerbose )
366 printf( "Delay checking failed for %d cuts.\n", Gia_ManSifDelay( p, vCuts, vTimes, nLutSize+1 ) );
367 vCounts = Gia_ManSifTimesToCounts( p, vTimes, Period );
368 pNew = Gia_ManSifDerive( p, vCounts, fVerbose );
369 Vec_IntFreeP( &vCounts );
370 return pNew;
371}
372
373
385static inline void Gia_ManSifCutMerge( int * pCut, int * pCut1, int * pCut2, int nSize )
386{
387 int * pBeg = pCut+1;
388 int * pBeg1 = pCut1+1;
389 int * pBeg2 = pCut2+1;
390 int * pEnd1 = pBeg1 + pCut1[0];
391 int * pEnd2 = pBeg2 + pCut2[0];
392 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
393 {
394 if ( pBeg == pCut+nSize )
395 {
396 pCut[0] = -1;
397 return;
398 }
399 if ( *pBeg1 == *pBeg2 )
400 *pBeg++ = *pBeg1++, pBeg2++;
401 else if ( *pBeg1 < *pBeg2 )
402 *pBeg++ = *pBeg1++;
403 else
404 *pBeg++ = *pBeg2++;
405 }
406 while ( pBeg1 < pEnd1 )
407 {
408 if ( pBeg == pCut+nSize )
409 {
410 pCut[0] = -1;
411 return;
412 }
413 *pBeg++ = *pBeg1++;
414 }
415 while ( pBeg2 < pEnd2 )
416 {
417 if ( pBeg == pCut+nSize )
418 {
419 pCut[0] = -1;
420 return;
421 }
422 *pBeg++ = *pBeg2++;
423 }
424 pCut[0] = pBeg-(pCut+1);
425 assert( pCut[0] < nSize );
426}
427static inline int Gia_ManSifCutChoice( Gia_Man_t * p, int Level, int iObj, int iSibl, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nSize )
428{
429 int * pCut = Vec_IntEntryP( vCuts, iObj*nSize );
430 int * pCut2 = Vec_IntEntryP( vCuts, iSibl*nSize );
431 int Level2 = Vec_IntEntry( vTimes, iSibl ); int i;
432 assert( iObj > iSibl );
433 if ( Level < Level2 || (Level == Level2 && pCut[0] <= pCut2[0]) )
434 return Level;
435 for ( i = 0; i <= pCut2[0]; i++ )
436 pCut[i] = pCut2[i];
437 return Level2;
438}
439static inline int Gia_ManSifCutOne( Gia_Man_t * p, int iObj, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nSize )
440{
441 Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
442 int iFan0 = Gia_ObjFaninId0(pObj, iObj);
443 int iFan1 = Gia_ObjFaninId1(pObj, iObj);
444 int Cut0[2] = { 1, iFan0 << 8 };
445 int Cut1[2] = { 1, iFan1 << 8 };
446 int * pCut = Vec_IntEntryP( vCuts, iObj*nSize );
447 int * pCut0 = Vec_IntEntryP( vCuts, iFan0*nSize );
448 int * pCut1 = Vec_IntEntryP( vCuts, iFan1*nSize );
449 int Level_ = Vec_IntEntry( vTimes, iObj );
450 int Level0 = Vec_IntEntry( vTimes, iFan0 );
451 int Level1 = Vec_IntEntry( vTimes, iFan1 );
452 int Level = -ABC_INFINITY, i;
453 assert( pCut0[0] > 0 && pCut1[0] > 0 );
454 if ( Level0 == Level1 )
455 Gia_ManSifCutMerge( pCut, pCut0, pCut1, nSize );
456 else if ( Level0 > Level1 )
457 Gia_ManSifCutMerge( pCut, pCut0, Cut1, nSize );
458 else //if ( Level0 < Level1 )
459 Gia_ManSifCutMerge( pCut, pCut1, Cut0, nSize );
460 if ( pCut[0] == -1 )
461 {
462 pCut[0] = 2;
463 pCut[1] = iFan0 << 8;
464 pCut[2] = iFan1 << 8;
465 }
466 for ( i = 1; i <= pCut[0]; i++ )
467 Level = Abc_MaxInt( Level, Vec_IntEntry(vTimes, pCut[i] >> 8) );
468 Level++;
469 if ( Gia_ObjSibl(p, iObj) )
470 Level = Gia_ManSifCutChoice( p, Level, iObj, Gia_ObjSibl(p, iObj), vCuts, vTimes, nSize );
471 assert( pCut[0] > 0 && pCut[0] < nSize );
472 Vec_IntUpdateEntry( vTimes, iObj, Level );
473 return Level > Level_;
474}
475int Gia_ManSifCheckIter( Gia_Man_t * p, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nLutSize, int Period )
476{
477 int i, fChange = 0, nSize = nLutSize+1;
478 Gia_Obj_t * pObj, * pObjRi, * pObjRo;
479 Gia_ManForEachAnd( p, pObj, i )
480 fChange |= Gia_ManSifCutOne( p, i, vCuts, vTimes, nSize );
481 Gia_ManForEachCo( p, pObj, i )
482 Vec_IntWriteEntry( vTimes, Gia_ObjId(p, pObj), Vec_IntEntry(vTimes, Gia_ObjFaninId0p(p, pObj)) );
483 Gia_ManForEachRiRo( p, pObjRi, pObjRo, i )
484 {
485 int TimeNew = Vec_IntEntry(vTimes, Gia_ObjId(p, pObjRi)) - Period;
486 TimeNew = Abc_MaxInt( TimeNew, Vec_IntEntry(vTimes, Gia_ObjId(p, pObjRo)) );
487 Vec_IntWriteEntry( vTimes, Gia_ObjId(p, pObjRo), TimeNew );
488 }
489 return fChange;
490}
491int Gia_ManSifCheckPeriod( Gia_Man_t * p, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nLutSize, int Period, int * pIters )
492{
493 Gia_Obj_t * pObj; int i, Id, Stop, nSize = nLutSize+1;
494 assert( Gia_ManRegNum(p) > 0 );
495 Gia_ManForEachCiId( p, Id, i )
496 Vec_IntWriteEntry( vCuts, Id*nSize, 1 );
497 Gia_ManForEachCiId( p, Id, i )
498 Vec_IntWriteEntry( vCuts, Id*nSize+1, Id << 8 );
499 Vec_IntFill( vTimes, Gia_ManObjNum(p), -Period );
500 if ( p->vStopsF )
501 Vec_StrForEachEntry( p->vStopsF, Stop, i )
502 if ( Stop ) Vec_IntWriteEntry( vTimes, i, 0 );
503 Vec_IntWriteEntry( vTimes, 0, 0 );
504 Gia_ManForEachPi( p, pObj, i )
505 Vec_IntWriteEntry( vTimes, Gia_ObjId(p, pObj), 0 );
506 for ( *pIters = 0; *pIters < 100; (*pIters)++ )
507 {
508 if ( !Gia_ManSifCheckIter(p, vCuts, vTimes, nLutSize, Period) )
509 return 1;
510 Gia_ManForEachPo( p, pObj, i )
511 if ( Vec_IntEntry(vTimes, Gia_ObjId(p, pObj)) > Period )
512 return 0;
513 Gia_ManForEachObj( p, pObj, i )
514 if ( Vec_IntEntry(vTimes, Gia_ObjId(p, pObj)) > 2*Period )
515 return 0;
516 if ( p->vStopsB )
517 Vec_StrForEachEntry( p->vStopsB, Stop, i )
518 if ( Stop && Vec_IntEntry(vTimes, i) > Period )
519 return 0;
520 }
521 return 0;
522}
523int Gia_ManSifMapComb( Gia_Man_t * p, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nLutSize )
524{
525 Gia_Obj_t * pObj; int i, Id, Res = 0, nSize = nLutSize+1;
526 Vec_IntFill( vTimes, Gia_ManObjNum(p), 0 );
527 Gia_ManForEachCiId( p, Id, i )
528 Vec_IntWriteEntry( vCuts, Id*nSize, 1 );
529 Gia_ManForEachCiId( p, Id, i )
530 Vec_IntWriteEntry( vCuts, Id*nSize+1, Id << 8 );
531 Gia_ManForEachAnd( p, pObj, i )
532 Gia_ManSifCutOne( p, i, vCuts, vTimes, nSize );
533 Gia_ManForEachCo( p, pObj, i )
534 Res = Abc_MaxInt( Res, Vec_IntEntry(vTimes, Gia_ObjFaninId0p(p, pObj)) );
535 return Res;
536}
537void Gia_ManSifPrintTimes( Gia_Man_t * p, Vec_Int_t * vTimes, int Period )
538{
539 int i, Value, Pos[256] = {0}, Neg[256] = {0};
540 Gia_ManForEachLut( p, i )
541 {
542 Value = Gia_ManSifTimeToCount( Vec_IntEntry(vTimes, i), Period );
543 Value = Abc_MinInt( Value, 255 );
544 Value = Abc_MaxInt( Value, -255 );
545 if ( Value >= 0 )
546 Pos[Value]++;
547 else
548 Neg[-Value]++;
549 }
550 printf( "Statistics: " );
551 for ( i = 255; i > 0; i-- )
552 if ( Neg[i] )
553 printf( " -%d=%d", i, Neg[i] );
554 for ( i = 0; i < 256; i++ )
555 if ( Pos[i] )
556 printf( " %d=%d", i, Pos[i] );
557 printf( "\n" );
558}
559int Gia_ManSifDeriveMapping_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vCuts, int nSize )
560{
561 int i, * pCut, Area = 1;
562 if ( !Gia_ObjIsAnd(pObj) )
563 return 0;
564 if ( Gia_ObjUpdateTravIdCurrent(p, pObj) )
565 return 0;
566 pCut = Vec_IntEntryP( vCuts, Gia_ObjId(p, pObj)*nSize );
567 for ( i = 1; i <= pCut[0]; i++ )
568 Area += Gia_ManSifDeriveMapping_rec( p, Gia_ManObj(p, pCut[i] >> 8), vCuts, nSize );
569 Vec_IntWriteEntry( p->vMapping, Gia_ObjId(p, pObj), Vec_IntSize(p->vMapping) );
570 Vec_IntPush( p->vMapping, pCut[0] );
571 for ( i = 1; i <= pCut[0]; i++ )
572 {
573 Gia_Obj_t * pObj = Gia_ManObj(p, pCut[i] >> 8);
574 assert( !Gia_ObjIsAnd(pObj) || Gia_ObjIsLut(p, pCut[i] >> 8) );
575 Vec_IntPush( p->vMapping, pCut[i] >> 8 );
576 }
577 Vec_IntPush( p->vMapping, -1 );
578 return Area;
579}
580int Gia_ManSifDeriveMapping( Gia_Man_t * p, Vec_Int_t * vCuts, Vec_Int_t * vTimes, int nLutSize, int Period, int fVerbose )
581{
582 Gia_Obj_t * pObj; int i, nArea = 0;
583 if ( p->vMapping != NULL )
584 {
585 printf( "Removing available combinational mapping.\n" );
586 Vec_IntFreeP( &p->vMapping );
587 }
588 assert( p->vMapping == NULL );
589 p->vMapping = Vec_IntStart( Gia_ManObjNum(p) );
591 Gia_ManForEachCo( p, pObj, i )
592 nArea += Gia_ManSifDeriveMapping_rec( p, Gia_ObjFanin0(pObj), vCuts, nLutSize+1 );
593 return nArea;
594}
595Gia_Man_t * Gia_ManSifPerform( Gia_Man_t * p, int nLutSize, int fEvalOnly, int fVerbose )
596{
597 Gia_Man_t * pNew = NULL;
598 int nIters, Status, nSize = nLutSize+1; // (2+1+nSize)*4=40 bytes/node
599 abctime clk = Abc_Clock();
600 Vec_Int_t * vCuts = Vec_IntStart( Gia_ManObjNum(p) * nSize );
601 Vec_Int_t * vTimes = Vec_IntAlloc( Gia_ManObjNum(p) );
602 int Lower = 0;
603 int Upper = Gia_ManSifMapComb( p, vCuts, vTimes, nLutSize );
604 int CombD = Upper;
605 if ( fVerbose && Gia_ManRegNum(p) )
606 printf( "Clock period %2d is %s\n", Lower, 0 ? "Yes" : "No " );
607 if ( fVerbose && Gia_ManRegNum(p) )
608 printf( "Clock period %2d is %s\n", Upper, 1 ? "Yes" : "No " );
609 while ( Gia_ManRegNum(p) > 0 && Upper - Lower > 1 )
610 {
611 int Middle = (Upper + Lower) / 2;
612 int Status = Gia_ManSifCheckPeriod( p, vCuts, vTimes, nLutSize, Middle, &nIters );
613 if ( Status )
614 Upper = Middle;
615 else
616 Lower = Middle;
617 if ( fVerbose )
618 printf( "Clock period %2d is %s after %d iterations\n", Middle, Status ? "Yes" : "No ", nIters );
619 }
620 if ( fVerbose )
621 printf( "Best period = <<%d>> (%.2f %%) ", Upper, (float)(100.0*(CombD-Upper)/CombD) );
622 if ( fVerbose )
623 printf( "LUT size = %d ", nLutSize );
624 if ( fVerbose )
625 printf( "Memory usage = %.2f MB ", 4.0*(2+1+nSize)*Gia_ManObjNum(p)/(1 << 20) );
626 if ( fVerbose )
627 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
628 if ( Upper == CombD )
629 {
630 Vec_IntFree( vCuts );
631 Vec_IntFree( vTimes );
632 printf( "Combinational delay (%d) cannot be improved.\n", CombD );
633 return Gia_ManDup( p );
634 }
635 Status = Gia_ManSifCheckPeriod( p, vCuts, vTimes, nLutSize, Upper, &nIters );
636 assert( Status );
637 Status = Gia_ManSifDeriveMapping( p, vCuts, vTimes, nLutSize, Upper, fVerbose );
638 if ( fEvalOnly )
639 {
640 printf( "Optimized level %2d (%6.2f %% less than comb level %2d). LUT size = %d. Area estimate = %d.\n",
641 Upper, (float)(100.0*(CombD-Upper)/CombD), CombD, nLutSize, Gia_ManSifArea(p, vCuts, nLutSize+1) );
642 printf( "The command is invoked in the evaluation mode. Retiming is not performed.\n" );
643 }
644 else
645 pNew = Gia_ManSifTransform( p, vCuts, vTimes, nLutSize, Upper, fVerbose );
646 Vec_IntFree( vCuts );
647 Vec_IntFree( vTimes );
648 //Gia_ManTransferTiming( pNew, p );
649 if ( p->vNamesIn ) {
650 char * pName; int i;
651 pNew->vNamesIn = p->vNamesIn; p->vNamesIn = NULL;
652 Vec_PtrForEachEntryStart( char *, pNew->vNamesIn, pName, i, Gia_ManPiNum(pNew) )
653 ABC_FREE( pName );
654 Vec_PtrShrink( pNew->vNamesIn, Gia_ManPiNum(pNew) );
655 for ( i = 0; i < Gia_ManRegNum(pNew); i++ )
656 Vec_PtrPush( pNew->vNamesIn, Abc_UtilStrsavNum("_fo", i) );
657 }
658 if ( p->vNamesOut ) {
659 char * pName; int i;
660 pNew->vNamesOut = p->vNamesOut; p->vNamesOut = NULL;
661 Vec_PtrForEachEntryStart( char *, pNew->vNamesOut, pName, i, Gia_ManPoNum(pNew) )
662 ABC_FREE( pName );
663 Vec_PtrShrink( pNew->vNamesOut, Gia_ManPoNum(pNew) );
664 for ( i = 0; i < Gia_ManRegNum(pNew); i++ )
665 Vec_PtrPush( pNew->vNamesOut, Abc_UtilStrsavNum("_fi", i) );
666 }
667 return pNew;
668}
669
673
674
676
int * Abc_NtkSolveGiaMiter(Gia_Man_t *p)
Definition abcSat.c:159
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#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
ush Pos
Definition deflate.h:88
Cube * p
Definition exorList.c:222
void Gia_ManSifPrintTimes(Gia_Man_t *p, Vec_Int_t *vTimes, int Period)
Definition giaSif.c:537
int Gia_ManSifCheckPeriod(Gia_Man_t *p, Vec_Int_t *vCuts, Vec_Int_t *vTimes, int nLutSize, int Period, int *pIters)
Definition giaSif.c:491
int Gia_ManSifMapComb(Gia_Man_t *p, Vec_Int_t *vCuts, Vec_Int_t *vTimes, int nLutSize)
Definition giaSif.c:523
int Gia_ManSifDelay(Gia_Man_t *p, Vec_Int_t *vCuts, Vec_Int_t *vTimes, int nSize)
Definition giaSif.c:338
int Gia_ManSifDeriveMapping(Gia_Man_t *p, Vec_Int_t *vCuts, Vec_Int_t *vTimes, int nLutSize, int Period, int fVerbose)
Definition giaSif.c:580
int Gia_ManSifArea(Gia_Man_t *p, Vec_Int_t *vCuts, int nSize)
Definition giaSif.c:313
ABC_NAMESPACE_IMPL_START void Gia_ManSifDupNode_rec(Gia_Man_t *pNew, Gia_Man_t *p, Gia_Obj_t *pObj)
DECLARATIONS ///.
Definition giaSif.c:44
int Gia_ManSifDelay_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vCuts, Vec_Int_t *vTimes, int nSize)
Definition giaSif.c:321
void Gia_ManSifDupNode(Gia_Man_t *pNew, Gia_Man_t *p, int iObj, Vec_Int_t *vCopy)
Definition giaSif.c:53
Vec_Int_t * Gia_ManSifTimesToCounts(Gia_Man_t *p, Vec_Int_t *vTimes, int Period)
Definition giaSif.c:350
Vec_Int_t * Gia_ManSifInitPos(Gia_Man_t *p, Vec_Int_t *vMoves, Vec_Int_t *vRegs)
Definition giaSif.c:96
Gia_Man_t * Gia_ManSifDerive(Gia_Man_t *p, Vec_Int_t *vCounts, int fVerbose)
Definition giaSif.c:139
Vec_Int_t * Gia_ManSifInitNeg(Gia_Man_t *p, Vec_Int_t *vMoves, Vec_Int_t *vRegs)
Definition giaSif.c:67
Gia_Man_t * Gia_ManSifTransform(Gia_Man_t *p, Vec_Int_t *vCuts, Vec_Int_t *vTimes, int nLutSize, int Period, int fVerbose)
Definition giaSif.c:360
int Gia_ManSifCheckIter(Gia_Man_t *p, Vec_Int_t *vCuts, Vec_Int_t *vTimes, int nLutSize, int Period)
Definition giaSif.c:475
Gia_Man_t * Gia_ManSifPerform(Gia_Man_t *p, int nLutSize, int fEvalOnly, int fVerbose)
Definition giaSif.c:595
int Gia_ManSifArea_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vCuts, int nSize)
Definition giaSif.c:301
int Gia_ManSifDeriveMapping_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vCuts, int nSize)
Definition giaSif.c:559
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition giaDup.c:720
#define Gia_ManForEachRo(p, pObj, i)
Definition gia.h:1252
#define Gia_ManForEachPo(p, pObj, i)
Definition gia.h:1250
void Gia_ManSetPhasePattern(Gia_Man_t *p, Vec_Int_t *vCiValues)
Definition giaUtil.c:427
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
#define Gia_ManForEachPi(p, pObj, i)
Definition gia.h:1248
#define Gia_ManForEachLut(p, i)
Definition gia.h:1157
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition gia.h:1161
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition gia.h:1190
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
#define Gia_ManForEachRoToRiVec(vRoIds, p, pObj, i)
Definition gia.h:1258
#define Gia_ManForEachRiRo(p, pObjRi, pObjRo, i)
Definition gia.h:1256
void Gia_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
#define Gia_ManForEachRi(p, pObj, i)
Definition gia.h:1254
#define Gia_ManForEachCiId(p, Id, i)
Definition gia.h:1230
Vec_Ptr_t * vNamesIn
Definition gia.h:181
char * pSpec
Definition gia.h:100
Vec_Ptr_t * vNamesOut
Definition gia.h:182
char * pName
Definition gia.h:99
unsigned Value
Definition gia.h:89
unsigned fPhase
Definition gia.h:87
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition vecPtr.h:57
#define Vec_StrForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecStr.h:54