ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cecCorr.c
Go to the documentation of this file.
1
20
21#include "cecInt.h"
22
24
25
29
30static void Gia_ManCorrSpecReduce_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj, int f, int nPrefix );
31
35
47static inline int Gia_ManCorrSpecReal( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj, int f, int nPrefix )
48{
49 if ( Gia_ObjIsAnd(pObj) )
50 {
51 Gia_ManCorrSpecReduce_rec( pNew, p, Gia_ObjFanin0(pObj), f, nPrefix );
52 Gia_ManCorrSpecReduce_rec( pNew, p, Gia_ObjFanin1(pObj), f, nPrefix );
53 return Gia_ManHashAnd( pNew, Gia_ObjFanin0CopyF(p, f, pObj), Gia_ObjFanin1CopyF(p, f, pObj) );
54 }
55 if ( f == 0 )
56 {
57 assert( Gia_ObjIsRo(p, pObj) );
58 return Gia_ObjCopyF(p, f, pObj);
59 }
60 assert( f && Gia_ObjIsRo(p, pObj) );
61 pObj = Gia_ObjRoToRi( p, pObj );
62 Gia_ManCorrSpecReduce_rec( pNew, p, Gia_ObjFanin0(pObj), f-1, nPrefix );
63 return Gia_ObjFanin0CopyF( p, f-1, pObj );
64}
65
77void Gia_ManCorrSpecReduce_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj, int f, int nPrefix )
78{
79 Gia_Obj_t * pRepr;
80 int iLitNew;
81 if ( ~Gia_ObjCopyF(p, f, pObj) )
82 return;
83 if ( f >= nPrefix && (pRepr = Gia_ObjReprObj(p, Gia_ObjId(p, pObj))) )
84 {
85 Gia_ManCorrSpecReduce_rec( pNew, p, pRepr, f, nPrefix );
86 iLitNew = Abc_LitNotCond( Gia_ObjCopyF(p, f, pRepr), Gia_ObjPhase(pRepr) ^ Gia_ObjPhase(pObj) );
87 Gia_ObjSetCopyF( p, f, pObj, iLitNew );
88 return;
89 }
90 assert( Gia_ObjIsCand(pObj) );
91 iLitNew = Gia_ManCorrSpecReal( pNew, p, pObj, f, nPrefix );
92 Gia_ObjSetCopyF( p, f, pObj, iLitNew );
93}
94
106Gia_Man_t * Gia_ManCorrSpecReduce( Gia_Man_t * p, int nFrames, int fScorr, Vec_Int_t ** pvOutputs, int fRings )
107{
108 Gia_Man_t * pNew, * pTemp;
109 Gia_Obj_t * pObj, * pRepr;
110 Vec_Int_t * vXorLits;
111 int f, i, iPrev, iObj, iPrevNew, iObjNew;
112 assert( nFrames > 0 );
113 assert( Gia_ManRegNum(p) > 0 );
114 assert( p->pReprs != NULL );
115 Vec_IntFill( &p->vCopies, (nFrames+fScorr)*Gia_ManObjNum(p), -1 );
117 pNew = Gia_ManStart( nFrames * Gia_ManObjNum(p) );
118 pNew->pName = Abc_UtilStrsav( p->pName );
119 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
120 Gia_ManHashAlloc( pNew );
121 Gia_ObjSetCopyF( p, 0, Gia_ManConst0(p), 0 );
122 Gia_ManForEachRo( p, pObj, i )
123 Gia_ObjSetCopyF( p, 0, pObj, Gia_ManAppendCi(pNew) );
124 Gia_ManForEachRo( p, pObj, i )
125 if ( (pRepr = Gia_ObjReprObj(p, Gia_ObjId(p, pObj))) )
126 Gia_ObjSetCopyF( p, 0, pObj, Gia_ObjCopyF(p, 0, pRepr) );
127 for ( f = 0; f < nFrames+fScorr; f++ )
128 {
129 Gia_ObjSetCopyF( p, f, Gia_ManConst0(p), 0 );
130 Gia_ManForEachPi( p, pObj, i )
131 Gia_ObjSetCopyF( p, f, pObj, Gia_ManAppendCi(pNew) );
132 }
133 *pvOutputs = Vec_IntAlloc( 1000 );
134 vXorLits = Vec_IntAlloc( 1000 );
135 if ( fRings )
136 {
137 Gia_ManForEachObj1( p, pObj, i )
138 {
139 if ( Gia_ObjIsConst( p, i ) )
140 {
141 iObjNew = Gia_ManCorrSpecReal( pNew, p, pObj, nFrames, 0 );
142 iObjNew = Abc_LitNotCond( iObjNew, Gia_ObjPhase(pObj) );
143 if ( iObjNew != 0 )
144 {
145 Vec_IntPush( *pvOutputs, 0 );
146 Vec_IntPush( *pvOutputs, i );
147 Vec_IntPush( vXorLits, iObjNew );
148 }
149 }
150 else if ( Gia_ObjIsHead( p, i ) )
151 {
152 iPrev = i;
153 Gia_ClassForEachObj1( p, i, iObj )
154 {
155 iPrevNew = Gia_ManCorrSpecReal( pNew, p, Gia_ManObj(p, iPrev), nFrames, 0 );
156 iObjNew = Gia_ManCorrSpecReal( pNew, p, Gia_ManObj(p, iObj), nFrames, 0 );
157 iPrevNew = Abc_LitNotCond( iPrevNew, Gia_ObjPhase(pObj) ^ Gia_ObjPhase(Gia_ManObj(p, iPrev)) );
158 iObjNew = Abc_LitNotCond( iObjNew, Gia_ObjPhase(pObj) ^ Gia_ObjPhase(Gia_ManObj(p, iObj)) );
159 if ( iPrevNew != iObjNew && iPrevNew != 0 && iObjNew != 1 )
160 {
161 Vec_IntPush( *pvOutputs, iPrev );
162 Vec_IntPush( *pvOutputs, iObj );
163 Vec_IntPush( vXorLits, Gia_ManHashAnd(pNew, iPrevNew, Abc_LitNot(iObjNew)) );
164 }
165 iPrev = iObj;
166 }
167 iObj = i;
168 iPrevNew = Gia_ManCorrSpecReal( pNew, p, Gia_ManObj(p, iPrev), nFrames, 0 );
169 iObjNew = Gia_ManCorrSpecReal( pNew, p, Gia_ManObj(p, iObj), nFrames, 0 );
170 iPrevNew = Abc_LitNotCond( iPrevNew, Gia_ObjPhase(pObj) ^ Gia_ObjPhase(Gia_ManObj(p, iPrev)) );
171 iObjNew = Abc_LitNotCond( iObjNew, Gia_ObjPhase(pObj) ^ Gia_ObjPhase(Gia_ManObj(p, iObj)) );
172 if ( iPrevNew != iObjNew && iPrevNew != 0 && iObjNew != 1 )
173 {
174 Vec_IntPush( *pvOutputs, iPrev );
175 Vec_IntPush( *pvOutputs, iObj );
176 Vec_IntPush( vXorLits, Gia_ManHashAnd(pNew, iPrevNew, Abc_LitNot(iObjNew)) );
177 }
178 }
179 }
180 }
181 else
182 {
183 Gia_ManForEachObj1( p, pObj, i )
184 {
185 pRepr = Gia_ObjReprObj( p, Gia_ObjId(p,pObj) );
186 if ( pRepr == NULL )
187 continue;
188 iPrevNew = Gia_ObjIsConst(p, i)? 0 : Gia_ManCorrSpecReal( pNew, p, pRepr, nFrames, 0 );
189 iObjNew = Gia_ManCorrSpecReal( pNew, p, pObj, nFrames, 0 );
190 iObjNew = Abc_LitNotCond( iObjNew, Gia_ObjPhase(pRepr) ^ Gia_ObjPhase(pObj) );
191 if ( iPrevNew != iObjNew )
192 {
193 Vec_IntPush( *pvOutputs, Gia_ObjId(p, pRepr) );
194 Vec_IntPush( *pvOutputs, Gia_ObjId(p, pObj) );
195 Vec_IntPush( vXorLits, Gia_ManHashXor(pNew, iPrevNew, iObjNew) );
196 }
197 }
198 }
199 Vec_IntForEachEntry( vXorLits, iObjNew, i )
200 Gia_ManAppendCo( pNew, iObjNew );
201 Vec_IntFree( vXorLits );
202 Gia_ManHashStop( pNew );
203 Vec_IntErase( &p->vCopies );
204//Abc_Print( 1, "Before sweeping = %d\n", Gia_ManAndNum(pNew) );
205 pNew = Gia_ManCleanup( pTemp = pNew );
206//Abc_Print( 1, "After sweeping = %d\n", Gia_ManAndNum(pNew) );
207 Gia_ManStop( pTemp );
208 return pNew;
209}
210
211
223Gia_Man_t * Gia_ManCorrSpecReduceInit( Gia_Man_t * p, int nFrames, int nPrefix, int fScorr, Vec_Int_t ** pvOutputs, int fRings )
224{
225 Gia_Man_t * pNew, * pTemp;
226 Gia_Obj_t * pObj, * pRepr;
227 Vec_Int_t * vXorLits;
228 int f, i, iPrevNew, iObjNew;
229 assert( (!fScorr && nFrames > 1) || (fScorr && nFrames > 0) || nPrefix );
230 assert( Gia_ManRegNum(p) > 0 );
231 assert( p->pReprs != NULL );
232 Vec_IntFill( &p->vCopies, (nFrames+nPrefix+fScorr)*Gia_ManObjNum(p), -1 );
234 pNew = Gia_ManStart( (nFrames+nPrefix) * Gia_ManObjNum(p) );
235 pNew->pName = Abc_UtilStrsav( p->pName );
236 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
237 Gia_ManHashAlloc( pNew );
238 Gia_ManForEachRo( p, pObj, i )
239 {
240 Gia_ManAppendCi(pNew);
241 Gia_ObjSetCopyF( p, 0, pObj, 0 );
242 }
243 for ( f = 0; f < nFrames+nPrefix+fScorr; f++ )
244 {
245 Gia_ObjSetCopyF( p, f, Gia_ManConst0(p), 0 );
246 Gia_ManForEachPi( p, pObj, i )
247 Gia_ObjSetCopyF( p, f, pObj, Gia_ManAppendCi(pNew) );
248 }
249 *pvOutputs = Vec_IntAlloc( 1000 );
250 vXorLits = Vec_IntAlloc( 1000 );
251 for ( f = nPrefix; f < nFrames+nPrefix; f++ )
252 {
253 Gia_ManForEachObj1( p, pObj, i )
254 {
255 pRepr = Gia_ObjReprObj( p, Gia_ObjId(p,pObj) );
256 if ( pRepr == NULL )
257 continue;
258 iPrevNew = Gia_ObjIsConst(p, i)? 0 : Gia_ManCorrSpecReal( pNew, p, pRepr, f, nPrefix );
259 iObjNew = Gia_ManCorrSpecReal( pNew, p, pObj, f, nPrefix );
260 iObjNew = Abc_LitNotCond( iObjNew, Gia_ObjPhase(pRepr) ^ Gia_ObjPhase(pObj) );
261 if ( iPrevNew != iObjNew )
262 {
263 Vec_IntPush( *pvOutputs, Gia_ObjId(p, pRepr) );
264 Vec_IntPush( *pvOutputs, Gia_ObjId(p, pObj) );
265 Vec_IntPush( vXorLits, Gia_ManHashXor(pNew, iPrevNew, iObjNew) );
266 }
267 }
268 }
269 Vec_IntForEachEntry( vXorLits, iObjNew, i )
270 Gia_ManAppendCo( pNew, iObjNew );
271 Vec_IntFree( vXorLits );
272 Gia_ManHashStop( pNew );
273 Vec_IntErase( &p->vCopies );
274//Abc_Print( 1, "Before sweeping = %d\n", Gia_ManAndNum(pNew) );
275 pNew = Gia_ManCleanup( pTemp = pNew );
276//Abc_Print( 1, "After sweeping = %d\n", Gia_ManAndNum(pNew) );
277 Gia_ManStop( pTemp );
278 return pNew;
279}
280
292void Cec_ManStartSimInfo( Vec_Ptr_t * vInfo, int nFlops )
293{
294 unsigned * pInfo;
295 int k, w, nWords;
296 nWords = Vec_PtrReadWordsSimInfo( vInfo );
297 assert( nFlops <= Vec_PtrSize(vInfo) );
298 for ( k = 0; k < nFlops; k++ )
299 {
300 pInfo = (unsigned *)Vec_PtrEntry( vInfo, k );
301 for ( w = 0; w < nWords; w++ )
302 pInfo[w] = 0;
303 }
304 for ( k = nFlops; k < Vec_PtrSize(vInfo); k++ )
305 {
306 pInfo = (unsigned *)Vec_PtrEntry( vInfo, k );
307 for ( w = 0; w < nWords; w++ )
308 pInfo[w] = Gia_ManRandom( 0 );
309 }
310}
311
324{
325 Gia_Obj_t * pObj, * pRepr;
326 unsigned * pInfoObj, * pInfoRepr;
327 int i, w, nWords;
328 nWords = Vec_PtrReadWordsSimInfo( vInfo );
329 Gia_ManForEachRo( p, pObj, i )
330 {
331 // skip ROs without representatives
332 pRepr = Gia_ObjReprObj( p, Gia_ObjId(p,pObj) );
333 if ( pRepr == NULL || Gia_ObjFailed(p, Gia_ObjId(p,pObj)) )
334 continue;
335 pInfoObj = (unsigned *)Vec_PtrEntry( vInfo, i );
336 for ( w = 0; w < nWords; w++ )
337 assert( pInfoObj[w] == 0 );
338 // skip ROs with constant representatives
339 if ( Gia_ObjIsConst0(pRepr) )
340 continue;
341 assert( Gia_ObjIsRo(p, pRepr) );
342// Abc_Print( 1, "%d -> %d ", i, Gia_ObjId(p, pRepr) );
343 // transfer info from the representative
344 pInfoRepr = (unsigned *)Vec_PtrEntry( vInfo, Gia_ObjCioId(pRepr) - Gia_ManPiNum(p) );
345 for ( w = 0; w < nWords; w++ )
346 pInfoObj[w] = pInfoRepr[w];
347 }
348// Abc_Print( 1, "\n" );
349}
350
363{
364 Vec_Int_t * vPairs;
365 Gia_Obj_t * pObj, * pRepr;
366 int i;
367 vPairs = Vec_IntAlloc( 100 );
368 Gia_ManForEachRo( p, pObj, i )
369 {
370 // skip ROs without representatives
371 pRepr = Gia_ObjReprObj( p, Gia_ObjId(p,pObj) );
372 if ( pRepr == NULL || Gia_ObjIsConst0(pRepr) || Gia_ObjFailed(p, Gia_ObjId(p,pObj)) )
373// if ( pRepr == NULL || Gia_ObjIsConst0(pRepr) || Gia_ObjIsFailedPair(p, Gia_ObjId(p, pRepr), Gia_ObjId(p, pObj)) )
374 continue;
375 assert( Gia_ObjIsRo(p, pRepr) );
376// Abc_Print( 1, "%d -> %d ", Gia_ObjId(p,pObj), Gia_ObjId(p, pRepr) );
377 // remember the pair
378 Vec_IntPush( vPairs, Gia_ObjCioId(pRepr) - Gia_ManPiNum(p) );
379 Vec_IntPush( vPairs, i );
380 }
381 return vPairs;
382}
383
396{
397 unsigned * pInfoObj, * pInfoRepr;
398 int w, i, iObj, iRepr, nWords;
399 nWords = Vec_PtrReadWordsSimInfo( vInfo );
400 Vec_IntForEachEntry( vPairs, iRepr, i )
401 {
402 iObj = Vec_IntEntry( vPairs, ++i );
403 pInfoObj = (unsigned *)Vec_PtrEntry( vInfo, iObj );
404 pInfoRepr = (unsigned *)Vec_PtrEntry( vInfo, iRepr );
405 for ( w = 0; w < nWords; w++ )
406 {
407 assert( pInfoObj[w] == 0 );
408 pInfoObj[w] = pInfoRepr[w];
409 }
410 }
411}
412
424int Cec_ManLoadCounterExamplesTry( Vec_Ptr_t * vInfo, Vec_Ptr_t * vPres, int iBit, int * pLits, int nLits )
425{
426 unsigned * pInfo, * pPres;
427 int i;
428 for ( i = 0; i < nLits; i++ )
429 {
430 pInfo = (unsigned *)Vec_PtrEntry(vInfo, Abc_Lit2Var(pLits[i]));
431 pPres = (unsigned *)Vec_PtrEntry(vPres, Abc_Lit2Var(pLits[i]));
432 if ( Abc_InfoHasBit( pPres, iBit ) &&
433 Abc_InfoHasBit( pInfo, iBit ) == Abc_LitIsCompl(pLits[i]) )
434 return 0;
435 }
436 for ( i = 0; i < nLits; i++ )
437 {
438 pInfo = (unsigned *)Vec_PtrEntry(vInfo, Abc_Lit2Var(pLits[i]));
439 pPres = (unsigned *)Vec_PtrEntry(vPres, Abc_Lit2Var(pLits[i]));
440 Abc_InfoSetBit( pPres, iBit );
441 if ( Abc_InfoHasBit( pInfo, iBit ) == Abc_LitIsCompl(pLits[i]) )
442 Abc_InfoXorBit( pInfo, iBit );
443 }
444 return 1;
445}
446
458int Cec_ManLoadCounterExamples( Vec_Ptr_t * vInfo, Vec_Int_t * vCexStore, int iStart )
459{
460 Vec_Int_t * vPat;
461 Vec_Ptr_t * vPres;
462 int nWords = Vec_PtrReadWordsSimInfo(vInfo);
463 int nBits = 32 * nWords;
464 int k, nSize, kMax = 0;//, iBit = 1;
465 vPat = Vec_IntAlloc( 100 );
466 vPres = Vec_PtrAllocSimInfo( Vec_PtrSize(vInfo), nWords );
467 Vec_PtrCleanSimInfo( vPres, 0, nWords );
468 while ( iStart < Vec_IntSize(vCexStore) )
469 {
470 // skip the output number
471 iStart++;
472 // get the number of items
473 nSize = Vec_IntEntry( vCexStore, iStart++ );
474 if ( nSize <= 0 )
475 continue;
476 // extract pattern
477 Vec_IntClear( vPat );
478 for ( k = 0; k < nSize; k++ )
479 Vec_IntPush( vPat, Vec_IntEntry( vCexStore, iStart++ ) );
480 // add pattern to storage
481 for ( k = 1; k < nBits; k++ )
482 if ( Cec_ManLoadCounterExamplesTry( vInfo, vPres, k, (int *)Vec_IntArray(vPat), Vec_IntSize(vPat) ) )
483 break;
484 kMax = Abc_MaxInt( kMax, k );
485 if ( k == nBits-1 )
486 break;
487 }
488 Vec_PtrFree( vPres );
489 Vec_IntFree( vPat );
490 return iStart;
491}
492
504int Cec_ManLoadCounterExamples2( Vec_Ptr_t * vInfo, Vec_Int_t * vCexStore, int iStart )
505{
506 unsigned * pInfo;
507 int nBits = 32 * Vec_PtrReadWordsSimInfo(vInfo);
508 int k, iLit, nLits, Out, iBit = 1;
509 while ( iStart < Vec_IntSize(vCexStore) )
510 {
511 // skip the output number
512// iStart++;
513 Out = Vec_IntEntry( vCexStore, iStart++ );
514// Abc_Print( 1, "iBit = %d. Out = %d.\n", iBit, Out );
515 // get the number of items
516 nLits = Vec_IntEntry( vCexStore, iStart++ );
517 if ( nLits <= 0 )
518 continue;
519 // add pattern to storage
520 for ( k = 0; k < nLits; k++ )
521 {
522 iLit = Vec_IntEntry( vCexStore, iStart++ );
523 pInfo = (unsigned *)Vec_PtrEntry( vInfo, Abc_Lit2Var(iLit) );
524 if ( Abc_InfoHasBit( pInfo, iBit ) == Abc_LitIsCompl(iLit) )
525 Abc_InfoXorBit( pInfo, iBit );
526 }
527 if ( ++iBit == nBits )
528 break;
529 }
530// Abc_Print( 1, "added %d bits\n", iBit-1 );
531 return iStart;
532}
533
545int Cec_ManResimulateCounterExamples( Cec_ManSim_t * pSim, Vec_Int_t * vCexStore, int nFrames )
546{
547 Vec_Int_t * vPairs;
548 Vec_Ptr_t * vSimInfo;
549 int RetValue = 0, iStart = 0;
550 vPairs = Gia_ManCorrCreateRemapping( pSim->pAig );
552// pSim->pPars->nWords = 63;
553 pSim->pPars->nFrames = nFrames;
554 vSimInfo = Vec_PtrAllocSimInfo( Gia_ManRegNum(pSim->pAig) + Gia_ManPiNum(pSim->pAig) * nFrames, pSim->pPars->nWords );
555 while ( iStart < Vec_IntSize(vCexStore) )
556 {
557 Cec_ManStartSimInfo( vSimInfo, Gia_ManRegNum(pSim->pAig) );
558 iStart = Cec_ManLoadCounterExamples( vSimInfo, vCexStore, iStart );
559// iStart = Cec_ManLoadCounterExamples2( vSimInfo, vCexStore, iStart );
560// Gia_ManCorrRemapSimInfo( pSim->pAig, vSimInfo );
561 Gia_ManCorrPerformRemapping( vPairs, vSimInfo );
562 RetValue |= Cec_ManSeqResimulate( pSim, vSimInfo );
563// Cec_ManSeqResimulateInfo( pSim->pAig, vSimInfo, NULL );
564 }
565//Gia_ManEquivPrintOne( pSim->pAig, 85, 0 );
566 assert( iStart == Vec_IntSize(vCexStore) );
567 Vec_PtrFree( vSimInfo );
568 Vec_IntFree( vPairs );
569 return RetValue;
570}
571
584{
585 Vec_Ptr_t * vSimInfo;
586 int RetValue = 0, iStart = 0;
588 pSim->pPars->nFrames = 1;
589 vSimInfo = Vec_PtrAllocSimInfo( Gia_ManCiNum(pSim->pAig), pSim->pPars->nWords );
590 while ( iStart < Vec_IntSize(vCexStore) )
591 {
592 Cec_ManStartSimInfo( vSimInfo, 0 );
593 iStart = Cec_ManLoadCounterExamples( vSimInfo, vCexStore, iStart );
594 RetValue |= Cec_ManSeqResimulate( pSim, vSimInfo );
595 }
596 assert( iStart == Vec_IntSize(vCexStore) );
597 Vec_PtrFree( vSimInfo );
598 return RetValue;
599}
600
612int Gia_ManCheckRefinements( Gia_Man_t * p, Vec_Str_t * vStatus, Vec_Int_t * vOutputs, Cec_ManSim_t * pSim, int fRings )
613{
614 int i, status, iRepr, iObj;
615 int Counter = 0;
616 assert( 2 * Vec_StrSize(vStatus) == Vec_IntSize(vOutputs) );
617 Vec_StrForEachEntry( vStatus, status, i )
618 {
619 iRepr = Vec_IntEntry( vOutputs, 2*i );
620 iObj = Vec_IntEntry( vOutputs, 2*i+1 );
621 if ( status == 1 )
622 continue;
623 if ( status == 0 )
624 {
625 if ( Gia_ObjHasSameRepr(p, iRepr, iObj) )
626 Counter++;
627// if ( Gia_ObjHasSameRepr(p, iRepr, iObj) )
628// Abc_Print( 1, "Gia_ManCheckRefinements(): Disproved equivalence (%d,%d) is not refined!\n", iRepr, iObj );
629// if ( Gia_ObjHasSameRepr(p, iRepr, iObj) )
630// Cec_ManSimClassRemoveOne( pSim, iObj );
631 continue;
632 }
633 if ( status == -1 )
634 {
635// if ( !Gia_ObjFailed( p, iObj ) )
636// Abc_Print( 1, "Gia_ManCheckRefinements(): Failed equivalence is not marked as failed!\n" );
637// Gia_ObjSetFailed( p, iRepr );
638// Gia_ObjSetFailed( p, iObj );
639// if ( fRings )
640// Cec_ManSimClassRemoveOne( pSim, iRepr );
641 Cec_ManSimClassRemoveOne( pSim, iObj );
642 continue;
643 }
644 }
645// if ( Counter )
646// Abc_Print( 1, "Gia_ManCheckRefinements(): Could not refine %d nodes.\n", Counter );
647 return 1;
648}
649
650
663{
664 Gia_Obj_t * pRepr;
665 if ( (pRepr = Gia_ObjReprObj(p, Gia_ObjId(p, pObj))) )
666 {
667 Gia_ManCorrReduce_rec( pNew, p, pRepr );
668 pObj->Value = Abc_LitNotCond( pRepr->Value, Gia_ObjPhaseReal(pRepr) ^ Gia_ObjPhaseReal(pObj) );
669 return;
670 }
671 if ( ~pObj->Value )
672 return;
673 assert( Gia_ObjIsAnd(pObj) );
674 Gia_ManCorrReduce_rec( pNew, p, Gia_ObjFanin0(pObj) );
675 Gia_ManCorrReduce_rec( pNew, p, Gia_ObjFanin1(pObj) );
676 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
677}
678
691{
692 Gia_Man_t * pNew;
693 Gia_Obj_t * pObj;
694 int i;
696 pNew = Gia_ManStart( Gia_ManObjNum(p) );
697 pNew->pName = Abc_UtilStrsav( p->pName );
698 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
700 Gia_ManConst0(p)->Value = 0;
701 Gia_ManForEachCi( p, pObj, i )
702 pObj->Value = Gia_ManAppendCi(pNew);
703 Gia_ManHashAlloc( pNew );
704 Gia_ManForEachCo( p, pObj, i )
705 Gia_ManCorrReduce_rec( pNew, p, Gia_ObjFanin0(pObj) );
706 Gia_ManForEachCo( p, pObj, i )
707 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
708 Gia_ManHashStop( pNew );
709 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
710 return pNew;
711}
712
713
725void Cec_ManRefinedClassPrintStats( Gia_Man_t * p, Vec_Str_t * vStatus, int iIter, abctime Time )
726{
727 int nLits, CounterX = 0, Counter0 = 0, Counter = 0;
728 int i, Entry, nProve = 0, nDispr = 0, nFail = 0;
729 for ( i = 1; i < Gia_ManObjNum(p); i++ )
730 {
731 if ( Gia_ObjIsNone(p, i) )
732 CounterX++;
733 else if ( Gia_ObjIsConst(p, i) )
734 Counter0++;
735 else if ( Gia_ObjIsHead(p, i) )
736 Counter++;
737 }
738 CounterX -= Gia_ManCoNum(p);
739 nLits = Gia_ManCiNum(p) + Gia_ManAndNum(p) - Counter - CounterX;
740 if ( iIter == -1 )
741 Abc_Print( 1, "BMC : " );
742 else
743 Abc_Print( 1, "%3d : ", iIter );
744 Abc_Print( 1, "c =%8d cl =%7d lit =%8d ", Counter0, Counter, nLits );
745 if ( vStatus )
746 Vec_StrForEachEntry( vStatus, Entry, i )
747 {
748 if ( Entry == 1 )
749 nProve++;
750 else if ( Entry == 0 )
751 nDispr++;
752 else if ( Entry == -1 )
753 nFail++;
754 }
755 Abc_Print( 1, "p =%6d d =%6d f =%6d ", nProve, nDispr, nFail );
756 Abc_Print( 1, "%c ", Gia_ObjIsConst( p, Gia_ObjFaninId0p(p, Gia_ManPo(p, 0)) ) ? '+' : '-' );
757 Abc_PrintTime( 1, "T", Time );
758}
760{
761 int i, CounterX = 0, Counter0 = 0, Counter = 0;
762 for ( i = 1; i < Gia_ManObjNum(p); i++ )
763 {
764 if ( Gia_ObjIsNone(p, i) )
765 CounterX++;
766 else if ( Gia_ObjIsConst(p, i) )
767 Counter0++;
768 else if ( Gia_ObjIsHead(p, i) )
769 Counter++;
770 }
771 CounterX -= Gia_ManCoNum(p);
772 return Gia_ManCiNum(p) + Gia_ManAndNum(p) - Counter - CounterX;
773}
774
786void Cec_ManLSCorrespondenceBmc( Gia_Man_t * pAig, Cec_ParCor_t * pPars, int nPrefs )
787{
788 Cec_ParSim_t ParsSim, * pParsSim = &ParsSim;
789 Cec_ParSat_t ParsSat, * pParsSat = &ParsSat;
790 Vec_Str_t * vStatus;
791 Vec_Int_t * vOutputs;
792 Vec_Int_t * vCexStore;
793 Cec_ManSim_t * pSim;
794 Gia_Man_t * pSrm;
795 int fChanges, RetValue, i;
796 // prepare simulation manager
797 Cec_ManSimSetDefaultParams( pParsSim );
798 pParsSim->nWords = pPars->nWords;
799 pParsSim->nFrames = pPars->nRounds;
800 pParsSim->fVerbose = pPars->fVerbose;
801 pParsSim->fLatchCorr = pPars->fLatchCorr;
802 pParsSim->fSeqSimulate = 1;
803 pSim = Cec_ManSimStart( pAig, pParsSim );
804 // prepare SAT solving
805 Cec_ManSatSetDefaultParams( pParsSat );
806 pParsSat->nBTLimit = pPars->nBTLimit;
807 pParsSat->fVerbose = pPars->fVerbose;
808 fChanges = 1;
809 for ( i = 0; fChanges && (!pPars->nLimitMax || i < pPars->nLimitMax); i++ )
810 {
811 abctime clkBmc = Abc_Clock();
812 fChanges = 0;
813 pSrm = Gia_ManCorrSpecReduceInit( pAig, pPars->nFrames, nPrefs, !pPars->fLatchCorr, &vOutputs, pPars->fUseRings );
814 if ( Gia_ManPoNum(pSrm) == 0 )
815 {
816 Gia_ManStop( pSrm );
817 Vec_IntFree( vOutputs );
818 break;
819 }
820 pParsSat->nBTLimit *= 10;
821 if ( pPars->fUseCSat )
822 vCexStore = Tas_ManSolveMiterNc( pSrm, pPars->nBTLimit, &vStatus, 0 );
823 else
824 vCexStore = Cec_ManSatSolveMiter( pSrm, pParsSat, &vStatus );
825 // refine classes with these counter-examples
826 if ( Vec_IntSize(vCexStore) )
827 {
828 RetValue = Cec_ManResimulateCounterExamples( pSim, vCexStore, pPars->nFrames + 1 + nPrefs );
829 Gia_ManCheckRefinements( pAig, vStatus, vOutputs, pSim, pPars->fUseRings );
830 fChanges = 1;
831 }
832 if ( pPars->fVerbose )
833 Cec_ManRefinedClassPrintStats( pAig, vStatus, -1, Abc_Clock() - clkBmc );
834 // recycle
835 Vec_IntFree( vCexStore );
836 Vec_StrFree( vStatus );
837 Gia_ManStop( pSrm );
838 Vec_IntFree( vOutputs );
839 }
840 Cec_ManSimStop( pSim );
841}
842
855{
856 Gia_Obj_t * pObj, * pObjRo;
857 int i, Iter, iObj, iRepr, fPrev, Total, Count0, Count1;
858 assert( Vec_StrSize(vStatus) * 2 == Vec_IntSize(vEquivs) );
859 Total = 0;
860 Gia_ManForEachObj( p, pObj, i )
861 {
862 assert( pObj->fMark1 == 0 );
863 if ( Gia_ObjHasRepr(p, i) )
864 Total++;
865 }
866 Count0 = 0;
867 for ( i = 0; i < Vec_StrSize(vStatus); i++ )
868 {
869 iRepr = Vec_IntEntry(vEquivs, 2*i);
870 iObj = Vec_IntEntry(vEquivs, 2*i+1);
871 assert( iRepr == Gia_ObjRepr(p, iObj) );
872 if ( Vec_StrEntry(vStatus, i) != 1 ) // disproved or undecided
873 {
874 Gia_ManObj(p, iObj)->fMark1 = 1;
875 Count0++;
876 }
877 }
878 for ( Iter = 0; Iter < 100; Iter++ )
879 {
880 int fChanges = 0;
881 Gia_ManForEachObj1( p, pObj, i )
882 {
883 if ( Gia_ObjIsCi(pObj) )
884 continue;
885 assert( Gia_ObjIsAnd(pObj) || Gia_ObjIsCo(pObj) );
886// fPrev = pObj->fMark1;
887 if ( Gia_ObjIsAnd(pObj) )
888 pObj->fMark1 |= Gia_ObjFanin0(pObj)->fMark1 | Gia_ObjFanin1(pObj)->fMark1;
889 else
890 pObj->fMark1 |= Gia_ObjFanin0(pObj)->fMark1;
891// fChanges += fPrev ^ pObj->fMark1;
892 }
893 Gia_ManForEachRiRo( p, pObj, pObjRo, i )
894 {
895 fPrev = pObjRo->fMark1;
896 pObjRo->fMark1 = pObj->fMark1;
897 fChanges += fPrev ^ pObjRo->fMark1;
898 }
899 if ( fChanges == 0 )
900 break;
901 }
902 Count1 = 0;
903 Gia_ManForEachObj( p, pObj, i )
904 {
905 if ( pObj->fMark1 && Gia_ObjHasRepr(p, i) )
906 Count1++;
907 pObj->fMark1 = 0;
908 }
909 printf( "%5d -> %5d (%3d) ", Count0, Count1, Iter );
910 return 0;
911}
912
925{
926 int nIterMax = 100000;
927 int nAddFrames = 1; // additional timeframes to simulate
928 int fRunBmcFirst = 1;
929 Vec_Str_t * vStatus;
930 Vec_Int_t * vOutputs;
931 Vec_Int_t * vCexStore;
932 Cec_ParSim_t ParsSim, * pParsSim = &ParsSim;
933 Cec_ParSat_t ParsSat, * pParsSat = &ParsSat;
934 Cec_ManSim_t * pSim;
935 Gia_Man_t * pSrm;
936 int r, RetValue, nPrev[4] = {0};
937 abctime clkTotal = Abc_Clock();
938 abctime clkSat = 0, clkSim = 0, clkSrm = 0;
939 abctime clk2, clk = Abc_Clock();
940 if ( Gia_ManRegNum(pAig) == 0 )
941 {
942 Abc_Print( 1, "Cec_ManLatchCorrespondence(): Not a sequential AIG.\n" );
943 return 0;
944 }
945 Gia_ManRandom( 1 );
946 // prepare simulation manager
947 Cec_ManSimSetDefaultParams( pParsSim );
948 pParsSim->nWords = pPars->nWords;
949 pParsSim->nFrames = pPars->nFrames;
950 pParsSim->fVerbose = pPars->fVerbose;
951 pParsSim->fLatchCorr = pPars->fLatchCorr;
952 pParsSim->fConstCorr = pPars->fConstCorr;
953 pParsSim->fSeqSimulate = 1;
954 // create equivalence classes of registers
955 pSim = Cec_ManSimStart( pAig, pParsSim );
956 if ( pAig->pReprs == NULL )
957 {
958 Cec_ManSimClassesPrepare( pSim, pPars->nLevelMax );
960 }
961 // prepare SAT solving
962 Cec_ManSatSetDefaultParams( pParsSat );
963 pParsSat->nBTLimit = pPars->nBTLimit;
964 pParsSat->fVerbose = pPars->fVerbose;
965 // limit the number of conflicts in the circuit-based solver
966 if ( pPars->fUseCSat )
967 pParsSat->nBTLimit = Abc_MinInt( pParsSat->nBTLimit, 1000 );
968 if ( pPars->fVerbose )
969 {
970 Abc_Print( 1, "Obj = %7d. And = %7d. Conf = %5d. Fr = %d. Lcorr = %d. Ring = %d. CSat = %d.\n",
971 Gia_ManObjNum(pAig), Gia_ManAndNum(pAig),
972 pPars->nBTLimit, pPars->nFrames, pPars->fLatchCorr, pPars->fUseRings, pPars->fUseCSat );
973 Cec_ManRefinedClassPrintStats( pAig, NULL, 0, Abc_Clock() - clk );
974 }
975 // check the base case
976 if ( fRunBmcFirst && (!pPars->fLatchCorr || pPars->nFrames > 1) )
977 Cec_ManLSCorrespondenceBmc( pAig, pPars, 0 );
978 if ( pPars->pFunc )
979 {
980 ((int (*)(void *))pPars->pFunc)( pPars->pData );
981 ((int (*)(void *))pPars->pFunc)( pPars->pData );
982 }
983 if ( pPars->nStepsMax == 0 )
984 {
985 Abc_Print( 1, "Stopped signal correspondence after BMC.\n" );
986 Cec_ManSimStop( pSim );
987 return 1;
988 }
989 // perform refinement of equivalence classes
990 for ( r = 0; r < nIterMax; r++ )
991 {
992 if ( pPars->nStepsMax == r )
993 {
994 Cec_ManSimStop( pSim );
995 Abc_Print( 1, "Stopped signal correspondence after %d refiment iterations.\n", r );
996 return 1;
997 }
998 clk = Abc_Clock();
999 // perform speculative reduction
1000 clk2 = Abc_Clock();
1001 pSrm = Gia_ManCorrSpecReduce( pAig, pPars->nFrames, !pPars->fLatchCorr, &vOutputs, pPars->fUseRings );
1002 assert( Gia_ManRegNum(pSrm) == 0 && Gia_ManPiNum(pSrm) == Gia_ManRegNum(pAig)+(pPars->nFrames+!pPars->fLatchCorr)*Gia_ManPiNum(pAig) );
1003 clkSrm += Abc_Clock() - clk2;
1004 if ( Gia_ManCoNum(pSrm) == 0 )
1005 {
1006 Vec_IntFree( vOutputs );
1007 Gia_ManStop( pSrm );
1008 break;
1009 }
1010//Gia_DumpAiger( pSrm, "corrsrm", r, 2 );
1011 // found counter-examples to speculation
1012 clk2 = Abc_Clock();
1013 if ( pPars->fUseCSat )
1014 vCexStore = Cbs_ManSolveMiterNc( pSrm, pPars->nBTLimit, &vStatus, 0, 0 );
1015 else
1016 vCexStore = Cec_ManSatSolveMiter( pSrm, pParsSat, &vStatus );
1017 Gia_ManStop( pSrm );
1018 clkSat += Abc_Clock() - clk2;
1019 if ( Vec_IntSize(vCexStore) == 0 )
1020 {
1021 Vec_IntFree( vCexStore );
1022 Vec_StrFree( vStatus );
1023 Vec_IntFree( vOutputs );
1024 break;
1025 }
1026// Cec_ManLSCorrAnalyzeDependence( pAig, vOutputs, vStatus );
1027
1028 // refine classes with these counter-examples
1029 clk2 = Abc_Clock();
1030 RetValue = Cec_ManResimulateCounterExamples( pSim, vCexStore, pPars->nFrames + 1 + nAddFrames );
1031 Vec_IntFree( vCexStore );
1032 clkSim += Abc_Clock() - clk2;
1033 Gia_ManCheckRefinements( pAig, vStatus, vOutputs, pSim, pPars->fUseRings );
1034 if ( pPars->fVerbose )
1035 Cec_ManRefinedClassPrintStats( pAig, vStatus, r+1, Abc_Clock() - clk );
1036 Vec_StrFree( vStatus );
1037 Vec_IntFree( vOutputs );
1038//Gia_ManEquivPrintClasses( pAig, 1, 0 );
1039 if ( pPars->pFunc )
1040 ((int (*)(void *))pPars->pFunc)( pPars->pData );
1041 // quit if const is no longer there
1042 if ( pPars->fStopWhenGone && Gia_ManPoNum(pAig) == 1 && !Gia_ObjIsConst( pAig, Gia_ObjFaninId0p(pAig, Gia_ManPo(pAig, 0)) ) )
1043 {
1044 printf( "Iterative refinement is stopped after iteration %d\n", r );
1045 printf( "because the property output is no longer a candidate constant.\n" );
1046 Cec_ManSimStop( pSim );
1047 return 0;
1048 }
1049 if ( pPars->nLimitMax )
1050 {
1051 int nCur = Cec_ManCountLits(pAig);
1052 if ( r > 4 && nPrev[0] - nCur <= 4*pPars->nLimitMax )
1053 {
1054 printf( "Iterative refinement is stopped after iteration %d\n", r );
1055 printf( "because refinement does not proceed quickly.\n" );
1056 Cec_ManSimStop( pSim );
1057 ABC_FREE( pAig->pReprs );
1058 ABC_FREE( pAig->pNexts );
1059 return 0;
1060 }
1061 nPrev[0] = nPrev[1];
1062 nPrev[1] = nPrev[2];
1063 nPrev[2] = nPrev[3];
1064 nPrev[3] = nCur;
1065 }
1066 }
1067 if ( pPars->fVerbose )
1068 Cec_ManRefinedClassPrintStats( pAig, NULL, r+1, Abc_Clock() - clk );
1069 // check the overflow
1070 if ( r == nIterMax )
1071 Abc_Print( 1, "The refinement was not finished. The result may be incorrect.\n" );
1072 Cec_ManSimStop( pSim );
1073 // check the base case
1074 if ( !fRunBmcFirst && (!pPars->fLatchCorr || pPars->nFrames > 1) )
1075 Cec_ManLSCorrespondenceBmc( pAig, pPars, 0 );
1076 clkTotal = Abc_Clock() - clkTotal;
1077 // report the results
1078 if ( pPars->fVerbose )
1079 {
1080 ABC_PRTP( "Srm ", clkSrm, clkTotal );
1081 ABC_PRTP( "Sat ", clkSat, clkTotal );
1082 ABC_PRTP( "Sim ", clkSim, clkTotal );
1083 ABC_PRTP( "Other", clkTotal-clkSat-clkSrm-clkSim, clkTotal );
1084 Abc_PrintTime( 1, "TOTAL", clkTotal );
1085 }
1086 return 1;
1087}
1088
1100unsigned * Cec_ManComputeInitState( Gia_Man_t * pAig, int nFrames )
1101{
1102 Gia_Obj_t * pObj, * pObjRo, * pObjRi;
1103 unsigned * pInitState;
1104 int i, f;
1105 Gia_ManRandom( 1 );
1106// Abc_Print( 1, "Simulating %d timeframes.\n", nFrames );
1107 Gia_ManForEachRo( pAig, pObj, i )
1108 pObj->fMark1 = 0;
1109 for ( f = 0; f < nFrames; f++ )
1110 {
1111 Gia_ManConst0(pAig)->fMark1 = 0;
1112 Gia_ManForEachPi( pAig, pObj, i )
1113 pObj->fMark1 = Gia_ManRandom(0) & 1;
1114 Gia_ManForEachAnd( pAig, pObj, i )
1115 pObj->fMark1 = (Gia_ObjFanin0(pObj)->fMark1 ^ Gia_ObjFaninC0(pObj)) &
1116 (Gia_ObjFanin1(pObj)->fMark1 ^ Gia_ObjFaninC1(pObj));
1117 Gia_ManForEachRi( pAig, pObj, i )
1118 pObj->fMark1 = (Gia_ObjFanin0(pObj)->fMark1 ^ Gia_ObjFaninC0(pObj));
1119 Gia_ManForEachRiRo( pAig, pObjRi, pObjRo, i )
1120 pObjRo->fMark1 = pObjRi->fMark1;
1121 }
1122 pInitState = ABC_CALLOC( unsigned, Abc_BitWordNum(Gia_ManRegNum(pAig)) );
1123 Gia_ManForEachRo( pAig, pObj, i )
1124 {
1125 if ( pObj->fMark1 )
1126 Abc_InfoSetBit( pInitState, i );
1127// Abc_Print( 1, "%d", pObj->fMark1 );
1128 }
1129// Abc_Print( 1, "\n" );
1130 Gia_ManCleanMark1( pAig );
1131 return pInitState;
1132}
1133
1146{
1147 Gia_Obj_t * pObj, * pRepr;
1148 int i;
1149 assert( p->vNamesIn != NULL );
1150 Gia_ManForEachRo( p, pObj, i )
1151 {
1152 if ( Gia_ObjIsConst(p, Gia_ObjId(p, pObj)) )
1153 Abc_Print( 1, "Original flop %s is proved equivalent to constant.\n", Vec_PtrEntry(p->vNamesIn, Gia_ObjCioId(pObj)) );
1154 else if ( (pRepr = Gia_ObjReprObj(p, Gia_ObjId(p, pObj))) )
1155 {
1156 if ( Gia_ObjIsCi(pRepr) )
1157 Abc_Print( 1, "Original flop %s is proved equivalent to flop %s.\n",
1158 Vec_PtrEntry( p->vNamesIn, Gia_ObjCioId(pObj) ),
1159 Vec_PtrEntry( p->vNamesIn, Gia_ObjCioId(pRepr) ) );
1160 else
1161 Abc_Print( 1, "Original flop %s is proved equivalent to internal node %d.\n",
1162 Vec_PtrEntry( p->vNamesIn, Gia_ObjCioId(pObj) ), Gia_ObjId(p, pRepr) );
1163 }
1164 }
1165}
1166
1167
1180{
1181 Gia_Man_t * pNew, * pTemp;
1182 unsigned * pInitState;
1183 int RetValue;
1184 ABC_FREE( pAig->pReprs );
1185 ABC_FREE( pAig->pNexts );
1186 if ( pPars->nPrefix == 0 )
1187 {
1188 RetValue = Cec_ManLSCorrespondenceClasses( pAig, pPars );
1189 if ( RetValue == 0 )
1190 return Gia_ManDup( pAig );
1191 }
1192 else
1193 {
1194 // compute the cycles AIG
1195 pInitState = Cec_ManComputeInitState( pAig, pPars->nPrefix );
1196 pTemp = Gia_ManDupFlip( pAig, (int *)pInitState );
1197 ABC_FREE( pInitState );
1198 // compute classes of this AIG
1199 RetValue = Cec_ManLSCorrespondenceClasses( pTemp, pPars );
1200 // transfer the class info
1201 pAig->pReprs = pTemp->pReprs; pTemp->pReprs = NULL;
1202 pAig->pNexts = pTemp->pNexts; pTemp->pNexts = NULL;
1203 // perform additional BMC
1204 pPars->fUseCSat = 0;
1205 pPars->nBTLimit = Abc_MaxInt( pPars->nBTLimit, 1000 );
1206 Cec_ManLSCorrespondenceBmc( pAig, pPars, pPars->nPrefix );
1207/*
1208 // transfer the class info back
1209 pTemp->pReprs = pAig->pReprs; pAig->pReprs = NULL;
1210 pTemp->pNexts = pAig->pNexts; pAig->pNexts = NULL;
1211 // continue refining
1212 RetValue = Cec_ManLSCorrespondenceClasses( pTemp, pPars );
1213 // transfer the class info
1214 pAig->pReprs = pTemp->pReprs; pTemp->pReprs = NULL;
1215 pAig->pNexts = pTemp->pNexts; pTemp->pNexts = NULL;
1216*/
1217 Gia_ManStop( pTemp );
1218 }
1219 // derive reduced AIG
1220 if ( pPars->fMakeChoices )
1221 {
1222 pNew = Gia_ManEquivToChoices( pAig, 1 );
1223// Gia_ManHasChoices_very_old( pNew );
1224 }
1225 else
1226 {
1227// Gia_ManEquivImprove( pAig );
1228 pNew = Gia_ManCorrReduce( pAig );
1229 pNew = Gia_ManSeqCleanup( pTemp = pNew );
1230 Gia_ManStop( pTemp );
1231 //Gia_AigerWrite( pNew, "reduced.aig", 0, 0, 0 );
1232 }
1233 // report the results
1234 if ( pPars->fVerbose )
1235 {
1236 Abc_Print( 1, "NBeg = %d. NEnd = %d. (Gain = %6.2f %%). RBeg = %d. REnd = %d. (Gain = %6.2f %%).\n",
1237 Gia_ManAndNum(pAig), Gia_ManAndNum(pNew),
1238 100.0*(Gia_ManAndNum(pAig)-Gia_ManAndNum(pNew))/(Gia_ManAndNum(pAig)?Gia_ManAndNum(pAig):1),
1239 Gia_ManRegNum(pAig), Gia_ManRegNum(pNew),
1240 100.0*(Gia_ManRegNum(pAig)-Gia_ManRegNum(pNew))/(Gia_ManRegNum(pAig)?Gia_ManRegNum(pAig):1) );
1241 }
1242 if ( pPars->nPrefix && (Gia_ManAndNum(pNew) < Gia_ManAndNum(pAig) || Gia_ManRegNum(pNew) < Gia_ManRegNum(pAig)) )
1243 Abc_Print( 1, "The reduced AIG was produced using %d-th invariants and will not verify.\n", pPars->nPrefix );
1244 // print verbose info about equivalences
1245 if ( pPars->fVerboseFlops )
1246 {
1247 if ( pAig->vNamesIn == NULL )
1248 Abc_Print( 1, "Flop output names are not available. Use command \"&get -n\".\n" );
1249 else
1250 Cec_ManPrintFlopEquivs( pAig );
1251 }
1252 // copy names if present
1253 if ( pAig->vNamesIn )
1254 {
1255 char * pName; int i;
1256 pNew->vNamesIn = Vec_PtrDupStr( pAig->vNamesIn );
1257 Vec_PtrForEachEntryStart( char *, pNew->vNamesIn, pName, i, Gia_ManCiNum(pNew) )
1258 ABC_FREE( pName );
1259 Vec_PtrShrink( pNew->vNamesIn, Gia_ManCiNum(pNew) );
1260 }
1261 if ( pAig->vNamesOut )
1262 {
1263 char * pName; int i;
1264 pNew->vNamesOut = Vec_PtrDupStr( pAig->vNamesOut );
1265 Vec_PtrForEachEntryStart( char *, pNew->vNamesOut, pName, i, Gia_ManCoNum(pNew) )
1266 ABC_FREE( pName );
1267 Vec_PtrShrink( pNew->vNamesOut, Gia_ManCoNum(pNew) );
1268 }
1269 return pNew;
1270}
1271
1284{
1285 abctime clk = Abc_Clock();
1286 Gia_Obj_t * pObj; int i, Id;
1287 Vec_Wec_t * vSuppsR = Vec_WecStart( Gia_ManRegNum(p) );
1288 Vec_Wec_t * vSupps = Vec_WecStart( Gia_ManObjNum(p) );
1289 Gia_ManForEachRo( p, pObj, i )
1290 Vec_IntPush( Vec_WecEntry(vSupps, Gia_ObjId(p, pObj)), i );
1291 Gia_ManForEachAnd( p, pObj, Id )
1292 Vec_IntTwoMerge2( Vec_WecEntry(vSupps, Gia_ObjFaninId0(pObj, Id)),
1293 Vec_WecEntry(vSupps, Gia_ObjFaninId1(pObj, Id)),
1294 Vec_WecEntry(vSupps, Id) );
1295 Gia_ManForEachRi( p, pObj, i )
1296 Vec_IntAppend( Vec_WecEntry(vSuppsR, i), Vec_WecEntry(vSupps, Gia_ObjFaninId0p(p, pObj)) );
1297 Vec_WecFree( vSupps );
1298 if ( fVerbose )
1299 Abc_PrintTime( 1, "Support computation", Abc_Clock() - clk );
1300 return vSuppsR;
1301}
1302Vec_Int_t * Gia_ManFindStopFlops( Gia_Man_t * p, int nFlopIncFreq, int fVerbose )
1303{
1304 Vec_Int_t * vRes = NULL, * vTemp; int i, k, Spot, Temp, nItems = 0;
1305 Vec_Wec_t * vSupps = Gia_ManCreateRegSupps( p, fVerbose );
1306 Vec_Int_t * vNexts = Vec_IntStartFull( Gia_ManRegNum(p) );
1307 Vec_Int_t * vAvail = Vec_IntStart( Gia_ManRegNum(p) );
1308 Vec_Int_t * vHeads = Vec_IntAlloc( 10 );
1309 Vec_WecForEachLevel( vSupps, vTemp, i ) {
1310 if ( Vec_IntSize(vTemp) > 2 )
1311 continue;
1312 if ( (Spot = Vec_IntFind(vTemp, i)) >= 0 )
1313 Vec_IntDrop( vTemp, Spot );
1314 if ( Vec_IntSize(vTemp) != 1 )
1315 continue;
1316 Vec_IntWriteEntry( vNexts, i, Vec_IntEntry(vTemp, 0) );
1317 Vec_IntWriteEntry( vAvail, Vec_IntEntry(vTemp, 0), 1 );
1318 }
1319 Vec_IntForEachEntry( vNexts, Spot, i )
1320 if ( Spot >= 0 && Vec_IntEntry(vAvail, i) == 0 )
1321 Vec_IntPush( vHeads, i );
1322 Vec_IntForEachEntry( vHeads, Spot, i ) {
1324 for ( k = 0, Temp = Spot; Vec_IntEntry(vNexts, Temp) >= 0; k++, Temp = Vec_IntEntry(vNexts, Temp) ) {
1325 if ( Gia_ObjUpdateTravIdCurrentId(p, Temp) )
1326 break;
1327 Vec_IntWriteEntry( vAvail, Temp, 1 );
1328 }
1329 if ( k > 100 )
1330 {
1331 nItems++;
1332 if ( vRes == NULL )
1333 vRes = Vec_IntAlloc( 100 );
1335 for ( k = 0, Temp = Spot; Vec_IntEntry(vNexts, Temp) >= 0; k++, Temp = Vec_IntEntry(vNexts, Temp) ) {
1336 if ( Gia_ObjUpdateTravIdCurrentId(p, Temp) )
1337 break;
1338 if ( k % nFlopIncFreq == 0 )
1339 Vec_IntPush( vRes, Temp );
1340 }
1341 }
1342 while ( Vec_IntEntry(vNexts, Spot) >= 0 )
1343 {
1344 int Next = Vec_IntEntry(vNexts, Spot);
1345 Vec_IntWriteEntry( vNexts, Spot, -1 );
1346 Spot = Next;
1347 }
1348 }
1349 if ( fVerbose && vRes )
1350 printf( "Detected %d sequence%s containing %d flops.\n", nItems, nItems > 1 ? "s":"", Vec_IntSize(vRes) );
1351 Vec_IntFree( vNexts );
1352 Vec_IntFree( vAvail );
1353 Vec_IntFree( vHeads );
1354 Vec_WecFree( vSupps );
1355 return vRes;
1356}
1358{
1359 Gia_Man_t * pNew;
1360 Gia_Obj_t * pObj; int i, Stop;
1361 Vec_Int_t * vExtras = Vec_IntAlloc( Vec_IntSize(vStops) );
1362 pNew = Gia_ManStart( Gia_ManObjNum(p) );
1363 pNew->pName = Abc_UtilStrsav( p->pName );
1364 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
1366 Gia_ManConst0(p)->Value = 0;
1367 Gia_ManForEachPi( p, pObj, i )
1368 pObj->Value = Gia_ManAppendCi(pNew);
1369 Vec_IntForEachEntry( vStops, Stop, i )
1370 Vec_IntPush( vExtras, Gia_ManAppendCi(pNew) );
1371 Gia_ManForEachRo( p, pObj, i )
1372 pObj->Value = Gia_ManAppendCi(pNew);
1373 Vec_IntForEachEntry( vStops, Stop, i )
1374 {
1375 int Lit = Gia_ManCi(p, Gia_ManPiNum(p)+Stop)->Value;
1376 Gia_ManCi(p, Gia_ManPiNum(p)+Stop)->Value = Vec_IntEntry(vExtras, i);
1377 Vec_IntWriteEntry( vExtras, i, Lit );
1378 }
1379 Gia_ManForEachAnd( p, pObj, i )
1380 pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1381 Gia_ManForEachPo( p, pObj, i )
1382 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
1383 Vec_IntForEachEntry( vExtras, Stop, i )
1384 Gia_ManAppendCo( pNew, Stop );
1385 Gia_ManForEachRi( p, pObj, i )
1386 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
1387 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
1388 Vec_IntFree( vExtras );
1389 return pNew;
1390}
1392{
1393 if ( ~pObj->Value )
1394 return;
1395 assert( Gia_ObjIsAnd(pObj) );
1396 Gia_ManDupStopsRem_rec( pNew, p, Gia_ObjFanin0(pObj) );
1397 Gia_ManDupStopsRem_rec( pNew, p, Gia_ObjFanin1(pObj) );
1398 pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1399}
1401{
1402 Gia_Man_t * pNew;
1403 Gia_Obj_t * pObj; int i;
1404 pNew = Gia_ManStart( Gia_ManObjNum(p) );
1405 pNew->pName = Abc_UtilStrsav( p->pName );
1406 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
1408 Gia_ManConst0(p)->Value = 0;
1409 Gia_ManForEachPi( p, pObj, i )
1410 if ( i < Gia_ManPiNum(p) - Vec_IntSize(vStops) )
1411 pObj->Value = Gia_ManAppendCi(pNew);
1412 Gia_ManForEachRo( p, pObj, i )
1413 pObj->Value = Gia_ManAppendCi(pNew);
1414 Gia_ManForEachPo( p, pObj, i )
1415 if ( i >= Gia_ManPoNum(p) - Vec_IntSize(vStops) )
1416 Gia_ManDupStopsRem_rec( pNew, p, Gia_ObjFanin0(pObj) );
1417 Gia_ManForEachPi( p, pObj, i )
1418 if ( i >= Gia_ManPiNum(p) - Vec_IntSize(vStops) )
1419 pObj->Value = Gia_ObjFanin0Copy( Gia_ManPo(p, i - Gia_ManPiNum(p) + Gia_ManPoNum(p)) );
1420 Gia_ManForEachPo( p, pObj, i )
1421 if ( i < Gia_ManPoNum(p) - Vec_IntSize(vStops) )
1422 Gia_ManDupStopsRem_rec( pNew, p, Gia_ObjFanin0(pObj) );
1423 Gia_ManForEachRi( p, pObj, i )
1424 Gia_ManDupStopsRem_rec( pNew, p, Gia_ObjFanin0(pObj) );
1425 Gia_ManForEachPo( p, pObj, i )
1426 if ( i < Gia_ManPoNum(p) - Vec_IntSize(vStops) )
1427 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
1428 Gia_ManForEachRi( p, pObj, i )
1429 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
1430 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
1431 return pNew;
1432}
1434{
1435 Vec_Int_t * vStops = Gia_ManFindStopFlops( p, 1, 1 );
1436 if ( vStops == NULL )
1437 return Gia_ManDup(p);
1438 Gia_Man_t * pNew1 = Gia_ManDupStopsAdd( p, vStops );
1439 Gia_Man_t * pNew2 = Gia_ManDupStopsRem( pNew1, vStops );
1440 Gia_ManStop( pNew1 );
1441 Vec_IntFree( vStops );
1442 return pNew2;
1443}
1444
1448
1449
1451
int nWords
Definition abcNpn.c:127
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRTP(a, t, T)
Definition abc_global.h:258
#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
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
int Cec_ManSimClassesPrepare(Cec_ManSim_t *p, int LevelMax)
Definition cecClass.c:867
int Cec_ManSimClassesRefine(Cec_ManSim_t *p)
Definition cecClass.c:939
int Cec_ManSimClassRemoveOne(Cec_ManSim_t *p, int i)
Definition cecClass.c:324
int Cec_ManResimulateCounterExamplesComb(Cec_ManSim_t *pSim, Vec_Int_t *vCexStore)
Definition cecCorr.c:583
void Cec_ManStartSimInfo(Vec_Ptr_t *vInfo, int nFlops)
Definition cecCorr.c:292
int Cec_ManResimulateCounterExamples(Cec_ManSim_t *pSim, Vec_Int_t *vCexStore, int nFrames)
Definition cecCorr.c:545
int Cec_ManLoadCounterExamples(Vec_Ptr_t *vInfo, Vec_Int_t *vCexStore, int iStart)
Definition cecCorr.c:458
Gia_Man_t * Gia_ManDupStopsAdd(Gia_Man_t *p, Vec_Int_t *vStops)
Definition cecCorr.c:1357
Gia_Man_t * Gia_ManCorrReduce(Gia_Man_t *p)
Definition cecCorr.c:690
int Cec_ManLoadCounterExamplesTry(Vec_Ptr_t *vInfo, Vec_Ptr_t *vPres, int iBit, int *pLits, int nLits)
Definition cecCorr.c:424
Gia_Man_t * Gia_ManDupStopsRem(Gia_Man_t *p, Vec_Int_t *vStops)
Definition cecCorr.c:1400
unsigned * Cec_ManComputeInitState(Gia_Man_t *pAig, int nFrames)
Definition cecCorr.c:1100
void Cec_ManRefinedClassPrintStats(Gia_Man_t *p, Vec_Str_t *vStatus, int iIter, abctime Time)
MACRO DEFINITIONS ///.
Definition cecCorr.c:725
int Cec_ManLSCorrespondenceClasses(Gia_Man_t *pAig, Cec_ParCor_t *pPars)
Definition cecCorr.c:924
void Cec_ManPrintFlopEquivs(Gia_Man_t *p)
Definition cecCorr.c:1145
int Cec_ManLSCorrAnalyzeDependence(Gia_Man_t *p, Vec_Int_t *vEquivs, Vec_Str_t *vStatus)
Definition cecCorr.c:854
Vec_Int_t * Gia_ManFindStopFlops(Gia_Man_t *p, int nFlopIncFreq, int fVerbose)
Definition cecCorr.c:1302
void Gia_ManCorrReduce_rec(Gia_Man_t *pNew, Gia_Man_t *p, Gia_Obj_t *pObj)
Definition cecCorr.c:662
Gia_Man_t * Gia_ManCorrSpecReduceInit(Gia_Man_t *p, int nFrames, int nPrefix, int fScorr, Vec_Int_t **pvOutputs, int fRings)
Definition cecCorr.c:223
Vec_Wec_t * Gia_ManCreateRegSupps(Gia_Man_t *p, int fVerbose)
Definition cecCorr.c:1283
int Cec_ManLoadCounterExamples2(Vec_Ptr_t *vInfo, Vec_Int_t *vCexStore, int iStart)
Definition cecCorr.c:504
void Gia_ManCorrPerformRemapping(Vec_Int_t *vPairs, Vec_Ptr_t *vInfo)
Definition cecCorr.c:395
Gia_Man_t * Gia_ManDupStopsTest(Gia_Man_t *p)
Definition cecCorr.c:1433
Vec_Int_t * Gia_ManCorrCreateRemapping(Gia_Man_t *p)
Definition cecCorr.c:362
void Cec_ManLSCorrespondenceBmc(Gia_Man_t *pAig, Cec_ParCor_t *pPars, int nPrefs)
Definition cecCorr.c:786
int Cec_ManCountLits(Gia_Man_t *p)
Definition cecCorr.c:759
Gia_Man_t * Cec_ManLSCorrespondence(Gia_Man_t *pAig, Cec_ParCor_t *pPars)
Definition cecCorr.c:1179
void Gia_ManCorrRemapSimInfo(Gia_Man_t *p, Vec_Ptr_t *vInfo)
Definition cecCorr.c:323
int Gia_ManCheckRefinements(Gia_Man_t *p, Vec_Str_t *vStatus, Vec_Int_t *vOutputs, Cec_ManSim_t *pSim, int fRings)
Definition cecCorr.c:612
void Gia_ManDupStopsRem_rec(Gia_Man_t *pNew, Gia_Man_t *p, Gia_Obj_t *pObj)
Definition cecCorr.c:1391
Gia_Man_t * Gia_ManCorrSpecReduce(Gia_Man_t *p, int nFrames, int fScorr, Vec_Int_t **pvOutputs, int fRings)
Definition cecCorr.c:106
void Cec_ManSimStop(Cec_ManSim_t *p)
Definition cecMan.c:233
Cec_ManSim_t * Cec_ManSimStart(Gia_Man_t *pAig, Cec_ParSim_t *pPars)
Definition cecMan.c:199
struct Cec_ManSim_t_ Cec_ManSim_t
Definition cecInt.h:113
int Cec_ManSeqResimulate(Cec_ManSim_t *p, Vec_Ptr_t *vInfo)
Definition cecSeq.c:137
Vec_Int_t * Cec_ManSatSolveMiter(Gia_Man_t *pAig, Cec_ParSat_t *pPars, Vec_Str_t **pvStatus)
Definition cecSolve.c:1070
void Cec_ManSatSetDefaultParams(Cec_ParSat_t *p)
DECLARATIONS ///.
Definition cecCore.c:45
void Cec_ManSimSetDefaultParams(Cec_ParSim_t *p)
Definition cecCore.c:71
typedefABC_NAMESPACE_HEADER_START struct Cec_ParSat_t_ Cec_ParSat_t
INCLUDES ///.
Definition cec.h:43
struct Cec_ParSim_t_ Cec_ParSim_t
Definition cec.h:60
struct Cec_ParCor_t_ Cec_ParCor_t
Definition cec.h:145
Cube * p
Definition exorList.c:222
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
Gia_Man_t * Gia_ManDupFlip(Gia_Man_t *p, int *pInitState)
Definition giaDup.c:628
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
void Gia_ManCreateValueRefs(Gia_Man_t *p)
Definition giaUtil.c:750
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
#define Gia_ClassForEachObj1(p, i, iObj)
Definition gia.h:1109
Vec_Int_t * Tas_ManSolveMiterNc(Gia_Man_t *pGia, int nConfs, Vec_Str_t **pvStatus, int fVerbose)
Definition giaCTas.c:1517
#define Gia_ManForEachPi(p, pObj, i)
Definition gia.h:1248
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:668
void Gia_ManFillValue(Gia_Man_t *p)
Definition giaUtil.c:369
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
#define Gia_ManForEachObj1(p, pObj, i)
Definition gia.h:1192
Vec_Int_t * Cbs_ManSolveMiterNc(Gia_Man_t *pGia, int nConfs, Vec_Str_t **pvStatus, int f0Proved, int fVerbose)
Definition giaCSat.c:1037
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
Gia_Man_t * Gia_ManEquivToChoices(Gia_Man_t *p, int nSnapshots)
Definition giaEquiv.c:2034
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
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_ManForEachCi(p, pObj, i)
Definition gia.h:1228
#define Gia_ManForEachRiRo(p, pObjRi, pObjRo, i)
Definition gia.h:1256
void Gia_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition giaUtil.c:49
#define Gia_ManForEachRi(p, pObj, i)
Definition gia.h:1254
Gia_Man_t * Gia_ManSeqCleanup(Gia_Man_t *p)
Definition giaScl.c:183
void Gia_ManCleanMark1(Gia_Man_t *p)
Definition giaUtil.c:313
Cec_ParSim_t * pPars
Definition cecInt.h:118
Gia_Man_t * pAig
Definition cecInt.h:117
int nFrames
Definition cec.h:150
int fMakeChoices
Definition cec.h:161
int fVerboseFlops
Definition cec.h:166
int nLevelMax
Definition cec.h:155
int fUseCSat
Definition cec.h:162
int fLatchCorr
Definition cec.h:158
int nStepsMax
Definition cec.h:156
int fUseRings
Definition cec.h:160
void * pFunc
Definition cec.h:171
int fConstCorr
Definition cec.h:159
int nWords
Definition cec.h:148
void * pData
Definition cec.h:170
int nLimitMax
Definition cec.h:157
int nBTLimit
Definition cec.h:152
int fStopWhenGone
Definition cec.h:165
int fVerbose
Definition cec.h:168
int nPrefix
Definition cec.h:151
int nRounds
Definition cec.h:149
int fVerbose
Definition cec.h:75
int fLatchCorr
Definition cec.h:72
int fSeqSimulate
Definition cec.h:71
int nFrames
Definition cec.h:64
int nWords
Definition cec.h:63
int fConstCorr
Definition cec.h:73
Vec_Ptr_t * vNamesIn
Definition gia.h:181
char * pSpec
Definition gia.h:100
Gia_Rpr_t * pReprs
Definition gia.h:126
int * pNexts
Definition gia.h:127
Vec_Ptr_t * vNamesOut
Definition gia.h:182
char * pName
Definition gia.h:99
unsigned fMark1
Definition gia.h:86
unsigned Value
Definition gia.h:89
#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
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_StrForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecStr.h:54
#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