ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cecPat.c
Go to the documentation of this file.
1
20
21#include "cecInt.h"
22
24
25
29
33
45static inline void Cec_ManPatStoreNum( Cec_ManPat_t * p, int Num )
46{
47 unsigned x = (unsigned)Num;
48 assert( Num >= 0 );
49 while ( x & ~0x7f )
50 {
51 Vec_StrPush( p->vStorage, (char)((x & 0x7f) | 0x80) );
52 x >>= 7;
53 }
54 Vec_StrPush( p->vStorage, (char)x );
55}
56
68static inline int Cec_ManPatRestoreNum( Cec_ManPat_t * p )
69{
70 int ch, i, x = 0;
71 for ( i = 0; (ch = Vec_StrEntry(p->vStorage, p->iStart++)) & 0x80; i++ )
72 x |= (ch & 0x7f) << (7 * i);
73 return x | (ch << (7 * i));
74}
75
87static inline void Cec_ManPatStore( Cec_ManPat_t * p, Vec_Int_t * vPat )
88{
89 int i, Number, NumberPrev;
90 assert( Vec_IntSize(vPat) > 0 );
91 Cec_ManPatStoreNum( p, Vec_IntSize(vPat) );
92 NumberPrev = Vec_IntEntry( vPat, 0 );
93 Cec_ManPatStoreNum( p, NumberPrev );
94 Vec_IntForEachEntryStart( vPat, Number, i, 1 )
95 {
96 assert( NumberPrev < Number );
97 Cec_ManPatStoreNum( p, Number - NumberPrev );
98 NumberPrev = Number;
99 }
100}
101
113static inline void Cec_ManPatRestore( Cec_ManPat_t * p, Vec_Int_t * vPat )
114{
115 int i, Size, Number;
116 Vec_IntClear( vPat );
117 Size = Cec_ManPatRestoreNum( p );
118 Number = Cec_ManPatRestoreNum( p );
119 Vec_IntPush( vPat, Number );
120 for ( i = 1; i < Size; i++ )
121 {
122 Number += Cec_ManPatRestoreNum( p );
123 Vec_IntPush( vPat, Number );
124 }
125 assert( Vec_IntSize(vPat) == Size );
126}
127
128
141{
142 int Counter = 0;
143 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
144 return 0;
145 Gia_ObjSetTravIdCurrent(p, pObj);
146 if ( Gia_ObjIsCi(pObj) )
147 {
148 pObj->fMark1 = Cec_ObjSatVarValue( pSat, pObj );
149 return 1;
150 }
151 assert( Gia_ObjIsAnd(pObj) );
152 Counter += Cec_ManPatComputePattern_rec( pSat, p, Gia_ObjFanin0(pObj) );
153 Counter += Cec_ManPatComputePattern_rec( pSat, p, Gia_ObjFanin1(pObj) );
154 pObj->fMark1 = (Gia_ObjFanin0(pObj)->fMark1 ^ Gia_ObjFaninC0(pObj)) &
155 (Gia_ObjFanin1(pObj)->fMark1 ^ Gia_ObjFaninC1(pObj));
156 return Counter;
157}
158
171{
172 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
173 return;
174 Gia_ObjSetTravIdCurrent(p, pObj);
175 if ( Gia_ObjIsCi(pObj) )
176 {
177 Vec_IntPush( vPat, Abc_Var2Lit( Gia_ObjCioId(pObj), pObj->fMark1==0 ) );
178 return;
179 }
180 assert( Gia_ObjIsAnd(pObj) );
181 if ( pObj->fMark1 == 1 )
182 {
183 Cec_ManPatComputePattern1_rec( p, Gia_ObjFanin0(pObj), vPat );
184 Cec_ManPatComputePattern1_rec( p, Gia_ObjFanin1(pObj), vPat );
185 }
186 else
187 {
188 assert( (Gia_ObjFanin0(pObj)->fMark1 ^ Gia_ObjFaninC0(pObj)) == 0 ||
189 (Gia_ObjFanin1(pObj)->fMark1 ^ Gia_ObjFaninC1(pObj)) == 0 );
190 if ( (Gia_ObjFanin0(pObj)->fMark1 ^ Gia_ObjFaninC0(pObj)) == 0 )
191 Cec_ManPatComputePattern1_rec( p, Gia_ObjFanin0(pObj), vPat );
192 else
193 Cec_ManPatComputePattern1_rec( p, Gia_ObjFanin1(pObj), vPat );
194 }
195}
196
209{
210 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
211 return;
212 Gia_ObjSetTravIdCurrent(p, pObj);
213 if ( Gia_ObjIsCi(pObj) )
214 {
215 Vec_IntPush( vPat, Abc_Var2Lit( Gia_ObjCioId(pObj), pObj->fMark1==0 ) );
216 return;
217 }
218 assert( Gia_ObjIsAnd(pObj) );
219 if ( pObj->fMark1 == 1 )
220 {
221 Cec_ManPatComputePattern2_rec( p, Gia_ObjFanin0(pObj), vPat );
222 Cec_ManPatComputePattern2_rec( p, Gia_ObjFanin1(pObj), vPat );
223 }
224 else
225 {
226 assert( (Gia_ObjFanin0(pObj)->fMark1 ^ Gia_ObjFaninC0(pObj)) == 0 ||
227 (Gia_ObjFanin1(pObj)->fMark1 ^ Gia_ObjFaninC1(pObj)) == 0 );
228 if ( (Gia_ObjFanin1(pObj)->fMark1 ^ Gia_ObjFaninC1(pObj)) == 0 )
229 Cec_ManPatComputePattern2_rec( p, Gia_ObjFanin1(pObj), vPat );
230 else
231 Cec_ManPatComputePattern2_rec( p, Gia_ObjFanin0(pObj), vPat );
232 }
233}
234
247{
248 int Value0, Value1, Value;
249 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
250 return (pObj->fMark1 << 1) | pObj->fMark0;
251 Gia_ObjSetTravIdCurrent(p, pObj);
252 if ( Gia_ObjIsCi(pObj) )
253 {
254 pObj->fMark0 = 1;
255 pObj->fMark1 = 1;
256 return GIA_UND;
257 }
258 assert( Gia_ObjIsAnd(pObj) );
259 Value0 = Cec_ManPatComputePattern3_rec( p, Gia_ObjFanin0(pObj) );
260 Value1 = Cec_ManPatComputePattern3_rec( p, Gia_ObjFanin1(pObj) );
261 Value = Gia_XsimAndCond( Value0, Gia_ObjFaninC0(pObj), Value1, Gia_ObjFaninC1(pObj) );
262 pObj->fMark0 = (Value & 1);
263 pObj->fMark1 = ((Value >> 1) & 1);
264 return Value;
265}
266
279{
280 Gia_Obj_t * pTemp;
281 int i, Value;
283 Vec_IntForEachEntry( vPat, Value, i )
284 {
285 pTemp = Gia_ManCi( p, Abc_Lit2Var(Value) );
286// assert( Abc_LitIsCompl(Value) != (int)pTemp->fMark1 );
287 if ( pTemp->fMark1 )
288 {
289 pTemp->fMark0 = 0;
290 pTemp->fMark1 = 1;
291 }
292 else
293 {
294 pTemp->fMark0 = 1;
295 pTemp->fMark1 = 0;
296 }
297 Gia_ObjSetTravIdCurrent( p, pTemp );
298 }
299 Value = Cec_ManPatComputePattern3_rec( p, Gia_ObjFanin0(pObj) );
300 Value = Gia_XsimNotCond( Value, Gia_ObjFaninC0(pObj) );
301 if ( Value != GIA_ONE )
302 Abc_Print( 1, "Cec_ManPatVerifyPattern(): Verification failed.\n" );
303 assert( Value == GIA_ONE );
304}
305
318{
319 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
320 return;
321 Gia_ObjSetTravIdCurrent(p, pObj);
322 pObj->fMark0 = 0;
323 if ( Gia_ObjIsCi(pObj) )
324 return;
325 assert( Gia_ObjIsAnd(pObj) );
326 Cec_ManPatComputePattern4_rec( p, Gia_ObjFanin0(pObj) );
327 Cec_ManPatComputePattern4_rec( p, Gia_ObjFanin1(pObj) );
328}
329
342{
343 assert( Gia_ObjIsCo(pObj) );
345 Cec_ManPatComputePattern4_rec( p, Gia_ObjFanin0(pObj) );
346}
347
360{
361 Vec_Int_t * vPat;
362 int nPatLits;
363 abctime clkTotal = Abc_Clock();
364// abctime clk;
365 assert( Gia_ObjIsCo(pObj) );
366 pMan->nPats++;
367 pMan->nPatsAll++;
368 // compute values in the cone of influence
369//clk = Abc_Clock();
370 Gia_ManIncrementTravId( p->pAig );
371 nPatLits = Cec_ManPatComputePattern_rec( p, p->pAig, Gia_ObjFanin0(pObj) );
372 assert( (Gia_ObjFanin0(pObj)->fMark1 ^ Gia_ObjFaninC0(pObj)) == 1 );
373 pMan->nPatLits += nPatLits;
374 pMan->nPatLitsAll += nPatLits;
375//pMan->timeFind += Abc_Clock() - clk;
376 // compute sensitizing path
377//clk = Abc_Clock();
378 Vec_IntClear( pMan->vPattern1 );
379 Gia_ManIncrementTravId( p->pAig );
380 Cec_ManPatComputePattern1_rec( p->pAig, Gia_ObjFanin0(pObj), pMan->vPattern1 );
381 // compute sensitizing path
382 Vec_IntClear( pMan->vPattern2 );
383 Gia_ManIncrementTravId( p->pAig );
384 Cec_ManPatComputePattern2_rec( p->pAig, Gia_ObjFanin0(pObj), pMan->vPattern2 );
385 // compare patterns
386 vPat = Vec_IntSize(pMan->vPattern1) < Vec_IntSize(pMan->vPattern2) ? pMan->vPattern1 : pMan->vPattern2;
387 pMan->nPatLitsMin += Vec_IntSize(vPat);
388 pMan->nPatLitsMinAll += Vec_IntSize(vPat);
389//pMan->timeShrink += Abc_Clock() - clk;
390 // verify pattern using ternary simulation
391//clk = Abc_Clock();
392// Cec_ManPatVerifyPattern( p->pAig, pObj, vPat );
393//pMan->timeVerify += Abc_Clock() - clk;
394 // sort pattern
395//clk = Abc_Clock();
396 Vec_IntSort( vPat, 0 );
397//pMan->timeSort += Abc_Clock() - clk;
398 // save pattern
399 Cec_ManPatStore( pMan, vPat );
400 pMan->timeTotal += Abc_Clock() - clkTotal;
401}
403{
404 // sort pattern
405 Vec_IntSort( vPat, 0 );
406 // save pattern
407 Cec_ManPatStore( pMan, vPat );
408}
409
421int Cec_ManPatCollectTry( Vec_Ptr_t * vInfo, Vec_Ptr_t * vPres, int iBit, int * pLits, int nLits )
422{
423 unsigned * pInfo, * pPres;
424 int i;
425 for ( i = 0; i < nLits; i++ )
426 {
427 pInfo = (unsigned *)Vec_PtrEntry(vInfo, Abc_Lit2Var(pLits[i]));
428 pPres = (unsigned *)Vec_PtrEntry(vPres, Abc_Lit2Var(pLits[i]));
429 if ( Abc_InfoHasBit( pPres, iBit ) &&
430 Abc_InfoHasBit( pInfo, iBit ) == Abc_LitIsCompl(pLits[i]) )
431 return 0;
432 }
433 for ( i = 0; i < nLits; i++ )
434 {
435 pInfo = (unsigned *)Vec_PtrEntry(vInfo, Abc_Lit2Var(pLits[i]));
436 pPres = (unsigned *)Vec_PtrEntry(vPres, Abc_Lit2Var(pLits[i]));
437 Abc_InfoSetBit( pPres, iBit );
438 if ( Abc_InfoHasBit( pInfo, iBit ) == Abc_LitIsCompl(pLits[i]) )
439 Abc_InfoXorBit( pInfo, iBit );
440 }
441 return 1;
442}
443
455Vec_Ptr_t * Cec_ManPatCollectPatterns( Cec_ManPat_t * pMan, int nInputs, int nWordsInit )
456{
457 Vec_Int_t * vPat = pMan->vPattern1;
458 Vec_Ptr_t * vInfo, * vPres;
459 int k, kMax = -1, nPatterns = 0;
460 int iStartOld = pMan->iStart;
461 int nWords = nWordsInit;
462 int nBits = 32 * nWords;
463 abctime clk = Abc_Clock();
464 vInfo = Vec_PtrAllocSimInfo( nInputs, nWords );
465 Gia_ManRandomInfo( vInfo, 0, 0, nWords );
466 vPres = Vec_PtrAllocSimInfo( nInputs, nWords );
467 Vec_PtrCleanSimInfo( vPres, 0, nWords );
468 while ( pMan->iStart < Vec_StrSize(pMan->vStorage) )
469 {
470 nPatterns++;
471 Cec_ManPatRestore( pMan, vPat );
472 for ( k = 1; k < nBits; k++, k += ((k % (32 * nWordsInit)) == 0) )
473 if ( Cec_ManPatCollectTry( vInfo, vPres, k, (int *)Vec_IntArray(vPat), Vec_IntSize(vPat) ) )
474 break;
475 kMax = Abc_MaxInt( kMax, k );
476 if ( k == nBits-1 )
477 {
478 Vec_PtrReallocSimInfo( vInfo );
479 Gia_ManRandomInfo( vInfo, 0, nWords, 2*nWords );
480 Vec_PtrReallocSimInfo( vPres );
481 Vec_PtrCleanSimInfo( vPres, nWords, 2*nWords );
482 nWords *= 2;
483 nBits *= 2;
484 }
485 }
486 Vec_PtrFree( vPres );
487 pMan->nSeries = Vec_PtrReadWordsSimInfo(vInfo) / nWordsInit;
488 pMan->timePack += Abc_Clock() - clk;
489 pMan->timeTotal += Abc_Clock() - clk;
490 pMan->iStart = iStartOld;
491 if ( pMan->fVerbose )
492 {
493 Abc_Print( 1, "Total = %5d. Max used = %5d. Full = %5d. Series = %d. ",
494 nPatterns, kMax, nWordsInit*32, pMan->nSeries );
495 ABC_PRT( "Time", Abc_Clock() - clk );
496 Cec_ManPatPrintStats( pMan );
497 }
498 return vInfo;
499}
500
501
513Vec_Ptr_t * Cec_ManPatPackPatterns( Vec_Int_t * vCexStore, int nInputs, int nRegs, int nWordsInit )
514{
515 Vec_Int_t * vPat;
516 Vec_Ptr_t * vInfo, * vPres;
517 int k, nSize, iStart, kMax = 0, nPatterns = 0;
518 int nWords = nWordsInit;
519 int nBits = 32 * nWords;
520// int RetValue;
521 assert( nRegs <= nInputs );
522 vPat = Vec_IntAlloc( 100 );
523
524 vInfo = Vec_PtrAllocSimInfo( nInputs, nWords );
525 Vec_PtrCleanSimInfo( vInfo, 0, nWords );
526 Gia_ManRandomInfo( vInfo, nRegs, 0, nWords );
527
528 vPres = Vec_PtrAllocSimInfo( nInputs, nWords );
529 Vec_PtrCleanSimInfo( vPres, 0, nWords );
530 iStart = 0;
531 while ( iStart < Vec_IntSize(vCexStore) )
532 {
533 nPatterns++;
534 // skip the output number
535 iStart++;
536 // get the number of items
537 nSize = Vec_IntEntry( vCexStore, iStart++ );
538 if ( nSize <= 0 )
539 continue;
540 // extract pattern
541 Vec_IntClear( vPat );
542 for ( k = 0; k < nSize; k++ )
543 Vec_IntPush( vPat, Vec_IntEntry( vCexStore, iStart++ ) );
544 // add pattern to storage
545 for ( k = 1; k < nBits; k++, k += ((k % (32 * nWordsInit)) == 0) )
546 if ( Cec_ManPatCollectTry( vInfo, vPres, k, (int *)Vec_IntArray(vPat), Vec_IntSize(vPat) ) )
547 break;
548
549// k = kMax + 1;
550// RetValue = Cec_ManPatCollectTry( vInfo, vPres, k, (int *)Vec_IntArray(vPat), Vec_IntSize(vPat) );
551// assert( RetValue == 1 );
552
553 kMax = Abc_MaxInt( kMax, k );
554 if ( k == nBits-1 )
555 {
556 Vec_PtrReallocSimInfo( vInfo );
557 Vec_PtrCleanSimInfo( vInfo, nWords, 2*nWords );
558 Gia_ManRandomInfo( vInfo, nRegs, nWords, 2*nWords );
559
560 Vec_PtrReallocSimInfo( vPres );
561 Vec_PtrCleanSimInfo( vPres, nWords, 2*nWords );
562 nWords *= 2;
563 nBits *= 2;
564 }
565 }
566// Abc_Print( 1, "packed %d patterns into %d vectors (out of %d)\n", nPatterns, kMax, nBits );
567 Vec_PtrFree( vPres );
568 Vec_IntFree( vPat );
569 return vInfo;
570}
571
575
576
578
int nWords
Definition abcNpn.c:127
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#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
void Cec_ManPatPrintStats(Cec_ManPat_t *p)
Definition cecMan.c:151
typedefABC_NAMESPACE_HEADER_START struct Cec_ManPat_t_ Cec_ManPat_t
INCLUDES ///.
Definition cecInt.h:49
int Cec_ObjSatVarValue(Cec_ManSat_t *p, Gia_Obj_t *pObj)
FUNCTION DEFINITIONS ///.
Definition cecSolve.c:48
struct Cec_ManSat_t_ Cec_ManSat_t
Definition cecInt.h:75
void Cec_ManPatComputePattern1_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vPat)
Definition cecPat.c:170
void Cec_ManPatComputePattern2_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vPat)
Definition cecPat.c:208
void Cec_ManPatCleanMark0(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition cecPat.c:341
void Cec_ManPatSavePatternCSat(Cec_ManPat_t *pMan, Vec_Int_t *vPat)
Definition cecPat.c:402
Vec_Ptr_t * Cec_ManPatCollectPatterns(Cec_ManPat_t *pMan, int nInputs, int nWordsInit)
Definition cecPat.c:455
void Cec_ManPatComputePattern4_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition cecPat.c:317
void Cec_ManPatSavePattern(Cec_ManPat_t *pMan, Cec_ManSat_t *p, Gia_Obj_t *pObj)
Definition cecPat.c:359
void Cec_ManPatVerifyPattern(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vPat)
Definition cecPat.c:278
int Cec_ManPatComputePattern_rec(Cec_ManSat_t *pSat, Gia_Man_t *p, Gia_Obj_t *pObj)
Definition cecPat.c:140
int Cec_ManPatCollectTry(Vec_Ptr_t *vInfo, Vec_Ptr_t *vPres, int iBit, int *pLits, int nLits)
Definition cecPat.c:421
Vec_Ptr_t * Cec_ManPatPackPatterns(Vec_Int_t *vCexStore, int nInputs, int nRegs, int nWordsInit)
Definition cecPat.c:513
int Cec_ManPatComputePattern3_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition cecPat.c:246
Cube * p
Definition exorList.c:222
void Gia_ManRandomInfo(Vec_Ptr_t *vInfo, int iInputStart, int iWordStart, int iWordStop)
Definition giaUtil.c:85
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
#define GIA_UND
Definition gia.h:923
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
#define GIA_ONE
Definition gia.h:922
unsigned fMark1
Definition gia.h:86
unsigned fMark0
Definition gia.h:81
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42