ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
fraSim.c
Go to the documentation of this file.
1
20
21#include "fra.h"
22#include "aig/saig/saig.h"
23
25
26
30
34
46int Fra_SmlNodeHash( Aig_Obj_t * pObj, int nTableSize )
47{
48 Fra_Man_t * p = (Fra_Man_t *)pObj->pData;
49 static int s_FPrimes[128] = {
50 1009, 1049, 1093, 1151, 1201, 1249, 1297, 1361, 1427, 1459,
51 1499, 1559, 1607, 1657, 1709, 1759, 1823, 1877, 1933, 1997,
52 2039, 2089, 2141, 2213, 2269, 2311, 2371, 2411, 2467, 2543,
53 2609, 2663, 2699, 2741, 2797, 2851, 2909, 2969, 3037, 3089,
54 3169, 3221, 3299, 3331, 3389, 3461, 3517, 3557, 3613, 3671,
55 3719, 3779, 3847, 3907, 3943, 4013, 4073, 4129, 4201, 4243,
56 4289, 4363, 4441, 4493, 4549, 4621, 4663, 4729, 4793, 4871,
57 4933, 4973, 5021, 5087, 5153, 5227, 5281, 5351, 5417, 5471,
58 5519, 5573, 5651, 5693, 5749, 5821, 5861, 5923, 6011, 6073,
59 6131, 6199, 6257, 6301, 6353, 6397, 6481, 6563, 6619, 6689,
60 6737, 6803, 6863, 6917, 6977, 7027, 7109, 7187, 7237, 7309,
61 7393, 7477, 7523, 7561, 7607, 7681, 7727, 7817, 7877, 7933,
62 8011, 8039, 8059, 8081, 8093, 8111, 8123, 8147
63 };
64 unsigned * pSims;
65 unsigned uHash;
66 int i;
67// assert( p->pSml->nWordsTotal <= 128 );
68 uHash = 0;
69 pSims = Fra_ObjSim(p->pSml, pObj->Id);
70 for ( i = p->pSml->nWordsPref; i < p->pSml->nWordsTotal; i++ )
71 uHash ^= pSims[i] * s_FPrimes[i & 0x7F];
72 return uHash % nTableSize;
73}
74
87{
88 Fra_Man_t * p = (Fra_Man_t *)pObj->pData;
89 unsigned * pSims;
90 int i;
91 pSims = Fra_ObjSim(p->pSml, pObj->Id);
92 for ( i = p->pSml->nWordsPref; i < p->pSml->nWordsTotal; i++ )
93 if ( pSims[i] )
94 return 0;
95 return 1;
96}
97
110{
111 Fra_Man_t * p = (Fra_Man_t *)pObj0->pData;
112 unsigned * pSims0, * pSims1;
113 int i;
114 pSims0 = Fra_ObjSim(p->pSml, pObj0->Id);
115 pSims1 = Fra_ObjSim(p->pSml, pObj1->Id);
116 for ( i = p->pSml->nWordsPref; i < p->pSml->nWordsTotal; i++ )
117 if ( pSims0[i] != pSims1[i] )
118 return 0;
119 return 1;
120}
121
133int Fra_SmlNodeNotEquWeight( Fra_Sml_t * p, int Left, int Right )
134{
135 unsigned * pSimL, * pSimR;
136 int k, Counter = 0;
137 pSimL = Fra_ObjSim( p, Left );
138 pSimR = Fra_ObjSim( p, Right );
139 for ( k = p->nWordsPref; k < p->nWordsTotal; k++ )
140 Counter += Aig_WordCountOnes( pSimL[k] ^ pSimR[k] );
141 return Counter;
142}
143
156{
157 unsigned * pSims;
158 int i;
159 pSims = Fra_ObjSim(p, pObj->Id);
160 for ( i = p->nWordsPref; i < p->nWordsTotal; i++ )
161 if ( pSims[i] )
162 return 0;
163 return 1;
164}
165
178{
179 unsigned * pSims;
180 int i, Counter = 0;
181 pSims = Fra_ObjSim(p, pObj->Id);
182 for ( i = 0; i < p->nWordsTotal; i++ )
183 Counter += Aig_WordCountOnes( pSims[i] );
184 return Counter;
185}
186
187
188
200void Fra_SmlSavePattern0( Fra_Man_t * p, int fInit )
201{
202 memset( p->pPatWords, 0, sizeof(unsigned) * p->nPatWords );
203}
204
216void Fra_SmlSavePattern1( Fra_Man_t * p, int fInit )
217{
218 Aig_Obj_t * pObj;
219 int i, k, nTruePis;
220 memset( p->pPatWords, 0xff, sizeof(unsigned) * p->nPatWords );
221 if ( !fInit )
222 return;
223 // clear the state bits to correspond to all-0 initial state
224 nTruePis = Aig_ManCiNum(p->pManAig) - Aig_ManRegNum(p->pManAig);
225 k = 0;
226 Aig_ManForEachLoSeq( p->pManAig, pObj, i )
227 Abc_InfoXorBit( p->pPatWords, nTruePis * p->nFramesAll + k++ );
228}
229
242{
243 Aig_Obj_t * pObj;
244 int i;
245 memset( p->pPatWords, 0, sizeof(unsigned) * p->nPatWords );
246 Aig_ManForEachCi( p->pManFraig, pObj, i )
247// if ( p->pSat->model.ptr[Fra_ObjSatNum(pObj)] == l_True )
248 if ( sat_solver_var_value(p->pSat, Fra_ObjSatNum(pObj)) )
249 Abc_InfoSetBit( p->pPatWords, i );
250
251 if ( p->vCex )
252 {
253 Vec_IntClear( p->vCex );
254 for ( i = 0; i < Aig_ManCiNum(p->pManAig) - Aig_ManRegNum(p->pManAig); i++ )
255 Vec_IntPush( p->vCex, Abc_InfoHasBit( p->pPatWords, i ) );
256 for ( i = Aig_ManCiNum(p->pManFraig) - Aig_ManRegNum(p->pManFraig); i < Aig_ManCiNum(p->pManFraig); i++ )
257 Vec_IntPush( p->vCex, Abc_InfoHasBit( p->pPatWords, i ) );
258 }
259
260/*
261 printf( "Pattern: " );
262 Aig_ManForEachCi( p->pManFraig, pObj, i )
263 printf( "%d", Abc_InfoHasBit( p->pPatWords, i ) );
264 printf( "\n" );
265*/
266}
267
268
269
282{
283 Aig_Obj_t * pFanin, * pObjPi;
284 unsigned * pSims;
285 int i, k, BestPat, * pModel;
286 // find the word of the pattern
287 pFanin = Aig_ObjFanin0(pObjPo);
288 pSims = Fra_ObjSim(p->pSml, pFanin->Id);
289 for ( i = 0; i < p->pSml->nWordsTotal; i++ )
290 if ( pSims[i] )
291 break;
292 assert( i < p->pSml->nWordsTotal );
293 // find the bit of the pattern
294 for ( k = 0; k < 32; k++ )
295 if ( pSims[i] & (1 << k) )
296 break;
297 assert( k < 32 );
298 // determine the best pattern
299 BestPat = i * 32 + k;
300 // fill in the counter-example data
301 pModel = ABC_ALLOC( int, Aig_ManCiNum(p->pManFraig)+1 );
302 Aig_ManForEachCi( p->pManAig, pObjPi, i )
303 {
304 pModel[i] = Abc_InfoHasBit(Fra_ObjSim(p->pSml, pObjPi->Id), BestPat);
305// printf( "%d", pModel[i] );
306 }
307 pModel[Aig_ManCiNum(p->pManAig)] = pObjPo->Id;
308// printf( "\n" );
309 // set the model
310 assert( p->pManFraig->pData == NULL );
311 p->pManFraig->pData = pModel;
312 return;
313}
314
327{
328 Aig_Obj_t * pObj;
329 int i;
330 // make sure the reference simulation pattern does not detect the bug
331 pObj = Aig_ManCo( p->pManAig, 0 );
332 assert( Aig_ObjFanin0(pObj)->fPhase == (unsigned)Aig_ObjFaninC0(pObj) );
333 Aig_ManForEachCo( p->pManAig, pObj, i )
334 {
335 if ( !Fra_SmlNodeIsConst( Aig_ObjFanin0(pObj) ) )
336 {
337 // create the counter-example from this pattern
339 return 1;
340 }
341 }
342 return 0;
343}
344
345
346
359{
360 unsigned * pSims;
361 int i;
362 assert( Aig_ObjIsCi(pObj) );
363 pSims = Fra_ObjSim( p, pObj->Id );
364 for ( i = 0; i < p->nWordsTotal; i++ )
365 pSims[i] = Fra_ObjRandomSim();
366}
367
379void Fra_SmlAssignConst( Fra_Sml_t * p, Aig_Obj_t * pObj, int fConst1, int iFrame )
380{
381 unsigned * pSims;
382 int i;
383 assert( Aig_ObjIsCi(pObj) || Aig_ObjIsConst1(pObj) );
384 pSims = Fra_ObjSim( p, pObj->Id ) + p->nWordsFrame * iFrame;
385 for ( i = 0; i < p->nWordsFrame; i++ )
386 pSims[i] = fConst1? ~(unsigned)0 : 0;
387}
388
400void Fra_SmlInitialize( Fra_Sml_t * p, int fInit )
401{
402 Aig_Obj_t * pObj;
403 int i;
404 if ( fInit )
405 {
406 assert( Aig_ManRegNum(p->pAig) > 0 );
407 assert( Aig_ManRegNum(p->pAig) < Aig_ManCiNum(p->pAig) );
408 // assign random info for primary inputs
409 Aig_ManForEachPiSeq( p->pAig, pObj, i )
410 Fra_SmlAssignRandom( p, pObj );
411 // assign the initial state for the latches
412 Aig_ManForEachLoSeq( p->pAig, pObj, i )
413 Fra_SmlAssignConst( p, pObj, 0, 0 );
414 }
415 else
416 {
417 Aig_ManForEachCi( p->pAig, pObj, i )
418 Fra_SmlAssignRandom( p, pObj );
419 }
420}
421
433void Fra_SmlAssignDist1( Fra_Sml_t * p, unsigned * pPat )
434{
435 Aig_Obj_t * pObj;
436 int f, i, k, Limit, nTruePis;
437 assert( p->nFrames > 0 );
438 if ( p->nFrames == 1 )
439 {
440 // copy the PI info
441 Aig_ManForEachCi( p->pAig, pObj, i )
442 Fra_SmlAssignConst( p, pObj, Abc_InfoHasBit(pPat, i), 0 );
443 // flip one bit
444 Limit = Abc_MinInt( Aig_ManCiNum(p->pAig), p->nWordsTotal * 32 - 1 );
445 for ( i = 0; i < Limit; i++ )
446 Abc_InfoXorBit( Fra_ObjSim( p, Aig_ManCi(p->pAig,i)->Id ), i+1 );
447 }
448 else
449 {
450 int fUseDist1 = 0;
451
452 // copy the PI info for each frame
453 nTruePis = Aig_ManCiNum(p->pAig) - Aig_ManRegNum(p->pAig);
454 for ( f = 0; f < p->nFrames; f++ )
455 Aig_ManForEachPiSeq( p->pAig, pObj, i )
456 Fra_SmlAssignConst( p, pObj, Abc_InfoHasBit(pPat, nTruePis * f + i), f );
457 // copy the latch info
458 k = 0;
459 Aig_ManForEachLoSeq( p->pAig, pObj, i )
460 Fra_SmlAssignConst( p, pObj, Abc_InfoHasBit(pPat, nTruePis * p->nFrames + k++), 0 );
461// assert( p->pManFraig == NULL || nTruePis * p->nFrames + k == Aig_ManCiNum(p->pManFraig) );
462
463 // flip one bit of the last frame
464 if ( fUseDist1 ) //&& p->nFrames == 2 )
465 {
466 Limit = Abc_MinInt( nTruePis, p->nWordsFrame * 32 - 1 );
467 for ( i = 0; i < Limit; i++ )
468 Abc_InfoXorBit( Fra_ObjSim( p, Aig_ManCi(p->pAig, i)->Id ) + p->nWordsFrame*(p->nFrames-1), i+1 );
469 }
470 }
471}
472
473
485void Fra_SmlNodeSimulate( Fra_Sml_t * p, Aig_Obj_t * pObj, int iFrame )
486{
487 unsigned * pSims, * pSims0, * pSims1;
488 int fCompl, fCompl0, fCompl1, i;
489 assert( !Aig_IsComplement(pObj) );
490 assert( Aig_ObjIsNode(pObj) );
491 assert( iFrame == 0 || p->nWordsFrame < p->nWordsTotal );
492 // get hold of the simulation information
493 pSims = Fra_ObjSim(p, pObj->Id) + p->nWordsFrame * iFrame;
494 pSims0 = Fra_ObjSim(p, Aig_ObjFanin0(pObj)->Id) + p->nWordsFrame * iFrame;
495 pSims1 = Fra_ObjSim(p, Aig_ObjFanin1(pObj)->Id) + p->nWordsFrame * iFrame;
496 // get complemented attributes of the children using their random info
497 fCompl = pObj->fPhase;
498 fCompl0 = Aig_ObjPhaseReal(Aig_ObjChild0(pObj));
499 fCompl1 = Aig_ObjPhaseReal(Aig_ObjChild1(pObj));
500 // simulate
501 if ( fCompl0 && fCompl1 )
502 {
503 if ( fCompl )
504 for ( i = 0; i < p->nWordsFrame; i++ )
505 pSims[i] = (pSims0[i] | pSims1[i]);
506 else
507 for ( i = 0; i < p->nWordsFrame; i++ )
508 pSims[i] = ~(pSims0[i] | pSims1[i]);
509 }
510 else if ( fCompl0 && !fCompl1 )
511 {
512 if ( fCompl )
513 for ( i = 0; i < p->nWordsFrame; i++ )
514 pSims[i] = (pSims0[i] | ~pSims1[i]);
515 else
516 for ( i = 0; i < p->nWordsFrame; i++ )
517 pSims[i] = (~pSims0[i] & pSims1[i]);
518 }
519 else if ( !fCompl0 && fCompl1 )
520 {
521 if ( fCompl )
522 for ( i = 0; i < p->nWordsFrame; i++ )
523 pSims[i] = (~pSims0[i] | pSims1[i]);
524 else
525 for ( i = 0; i < p->nWordsFrame; i++ )
526 pSims[i] = (pSims0[i] & ~pSims1[i]);
527 }
528 else // if ( !fCompl0 && !fCompl1 )
529 {
530 if ( fCompl )
531 for ( i = 0; i < p->nWordsFrame; i++ )
532 pSims[i] = ~(pSims0[i] & pSims1[i]);
533 else
534 for ( i = 0; i < p->nWordsFrame; i++ )
535 pSims[i] = (pSims0[i] & pSims1[i]);
536 }
537}
538
550int Fra_SmlNodesCompareInFrame( Fra_Sml_t * p, Aig_Obj_t * pObj0, Aig_Obj_t * pObj1, int iFrame0, int iFrame1 )
551{
552 unsigned * pSims0, * pSims1;
553 int i;
554 assert( !Aig_IsComplement(pObj0) );
555 assert( !Aig_IsComplement(pObj1) );
556 assert( iFrame0 == 0 || p->nWordsFrame < p->nWordsTotal );
557 assert( iFrame1 == 0 || p->nWordsFrame < p->nWordsTotal );
558 // get hold of the simulation information
559 pSims0 = Fra_ObjSim(p, pObj0->Id) + p->nWordsFrame * iFrame0;
560 pSims1 = Fra_ObjSim(p, pObj1->Id) + p->nWordsFrame * iFrame1;
561 // compare
562 for ( i = 0; i < p->nWordsFrame; i++ )
563 if ( pSims0[i] != pSims1[i] )
564 return 0;
565 return 1;
566}
567
579void Fra_SmlNodeCopyFanin( Fra_Sml_t * p, Aig_Obj_t * pObj, int iFrame )
580{
581 unsigned * pSims, * pSims0;
582 int fCompl, fCompl0, i;
583 assert( !Aig_IsComplement(pObj) );
584 assert( Aig_ObjIsCo(pObj) );
585 assert( iFrame == 0 || p->nWordsFrame < p->nWordsTotal );
586 // get hold of the simulation information
587 pSims = Fra_ObjSim(p, pObj->Id) + p->nWordsFrame * iFrame;
588 pSims0 = Fra_ObjSim(p, Aig_ObjFanin0(pObj)->Id) + p->nWordsFrame * iFrame;
589 // get complemented attributes of the children using their random info
590 fCompl = pObj->fPhase;
591 fCompl0 = Aig_ObjPhaseReal(Aig_ObjChild0(pObj));
592 // copy information as it is
593// if ( Aig_ObjFaninC0(pObj) )
594 if ( fCompl0 )
595 for ( i = 0; i < p->nWordsFrame; i++ )
596 pSims[i] = ~pSims0[i];
597 else
598 for ( i = 0; i < p->nWordsFrame; i++ )
599 pSims[i] = pSims0[i];
600}
601
613void Fra_SmlNodeTransferNext( Fra_Sml_t * p, Aig_Obj_t * pOut, Aig_Obj_t * pIn, int iFrame )
614{
615 unsigned * pSims0, * pSims1;
616 int i;
617 assert( !Aig_IsComplement(pOut) );
618 assert( !Aig_IsComplement(pIn) );
619 assert( Aig_ObjIsCo(pOut) );
620 assert( Aig_ObjIsCi(pIn) );
621 assert( iFrame == 0 || p->nWordsFrame < p->nWordsTotal );
622 // get hold of the simulation information
623 pSims0 = Fra_ObjSim(p, pOut->Id) + p->nWordsFrame * iFrame;
624 pSims1 = Fra_ObjSim(p, pIn->Id) + p->nWordsFrame * (iFrame+1);
625 // copy information as it is
626 for ( i = 0; i < p->nWordsFrame; i++ )
627 pSims1[i] = pSims0[i];
628}
629
630
643{
644 Aig_Obj_t * pObj;
645 int i;
646 Aig_ManForEachPoSeq( p->pAig, pObj, i )
647 if ( !Fra_SmlNodeIsZero(p, pObj) )
648 return 1;
649 return 0;
650}
651
664{
665 Aig_Obj_t * pObj, * pObjLi, * pObjLo;
666 int f, i;
667 abctime clk;
668clk = Abc_Clock();
669 for ( f = 0; f < p->nFrames; f++ )
670 {
671 // simulate the nodes
672 Aig_ManForEachNode( p->pAig, pObj, i )
673 Fra_SmlNodeSimulate( p, pObj, f );
674 // copy simulation info into outputs
675 Aig_ManForEachPoSeq( p->pAig, pObj, i )
676 Fra_SmlNodeCopyFanin( p, pObj, f );
677 // quit if this is the last timeframe
678 if ( f == p->nFrames - 1 )
679 break;
680 // copy simulation info into outputs
681 Aig_ManForEachLiSeq( p->pAig, pObj, i )
682 Fra_SmlNodeCopyFanin( p, pObj, f );
683 // copy simulation info into the inputs
684 Aig_ManForEachLiLoSeq( p->pAig, pObjLi, pObjLo, i )
685 Fra_SmlNodeTransferNext( p, pObjLi, pObjLo, f );
686 }
687p->timeSim += Abc_Clock() - clk;
688p->nSimRounds++;
689}
690
691
704{
705 int nChanges;
706 abctime clk;
707 Fra_SmlAssignDist1( p->pSml, p->pPatWords );
708 Fra_SmlSimulateOne( p->pSml );
709// if ( p->pPars->fPatScores )
710// Fra_CleanPatScores( p );
711 if ( p->pPars->fProve && Fra_SmlCheckOutput(p) )
712 return;
713clk = Abc_Clock();
714 nChanges = Fra_ClassesRefine( p->pCla );
715 nChanges += Fra_ClassesRefine1( p->pCla, 1, NULL );
716 if ( p->pCla->vImps )
717 nChanges += Fra_ImpRefineUsingCex( p, p->pCla->vImps );
718 if ( p->vOneHots )
719 nChanges += Fra_OneHotRefineUsingCex( p, p->vOneHots );
720p->timeRef += Abc_Clock() - clk;
721 if ( !p->pPars->nFramesK && nChanges < 1 )
722 printf( "Error: A counter-example did not refine classes!\n" );
723// assert( nChanges >= 1 );
724//printf( "Refined classes = %5d. Changes = %4d.\n", Vec_PtrSize(p->vClasses), nChanges );
725}
726
738void Fra_SmlSimulate( Fra_Man_t * p, int fInit )
739{
740 int fVerbose = 0;
741 int nChanges, nClasses;
742 abctime clk;
743 assert( !fInit || Aig_ManRegNum(p->pManAig) );
744 // start the classes
745 Fra_SmlInitialize( p->pSml, fInit );
746 Fra_SmlSimulateOne( p->pSml );
747 if ( p->pPars->fProve && Fra_SmlCheckOutput(p) )
748 return;
749 Fra_ClassesPrepare( p->pCla, p->pPars->fLatchCorr, 0 );
750// Fra_ClassesPrint( p->pCla, 0 );
751if ( fVerbose )
752printf( "Starting classes = %5d. Lits = %6d.\n", Vec_PtrSize(p->pCla->vClasses), Fra_ClassesCountLits(p->pCla) );
753
754//return;
755
756 // refine classes by walking 0/1 patterns
757 Fra_SmlSavePattern0( p, fInit );
758 Fra_SmlAssignDist1( p->pSml, p->pPatWords );
759 Fra_SmlSimulateOne( p->pSml );
760 if ( p->pPars->fProve && Fra_SmlCheckOutput(p) )
761 return;
762clk = Abc_Clock();
763 nChanges = Fra_ClassesRefine( p->pCla );
764 nChanges += Fra_ClassesRefine1( p->pCla, 1, NULL );
765p->timeRef += Abc_Clock() - clk;
766if ( fVerbose )
767printf( "Refined classes = %5d. Changes = %4d. Lits = %6d.\n", Vec_PtrSize(p->pCla->vClasses), nChanges, Fra_ClassesCountLits(p->pCla) );
768 Fra_SmlSavePattern1( p, fInit );
769 Fra_SmlAssignDist1( p->pSml, p->pPatWords );
770 Fra_SmlSimulateOne( p->pSml );
771 if ( p->pPars->fProve && Fra_SmlCheckOutput(p) )
772 return;
773clk = Abc_Clock();
774 nChanges = Fra_ClassesRefine( p->pCla );
775 nChanges += Fra_ClassesRefine1( p->pCla, 1, NULL );
776p->timeRef += Abc_Clock() - clk;
777
778if ( fVerbose )
779printf( "Refined classes = %5d. Changes = %4d. Lits = %6d.\n", Vec_PtrSize(p->pCla->vClasses), nChanges, Fra_ClassesCountLits(p->pCla) );
780 // refine classes by random simulation
781 do {
782 Fra_SmlInitialize( p->pSml, fInit );
783 Fra_SmlSimulateOne( p->pSml );
784 nClasses = Vec_PtrSize(p->pCla->vClasses);
785 if ( p->pPars->fProve && Fra_SmlCheckOutput(p) )
786 return;
787clk = Abc_Clock();
788 nChanges = Fra_ClassesRefine( p->pCla );
789 nChanges += Fra_ClassesRefine1( p->pCla, 1, NULL );
790p->timeRef += Abc_Clock() - clk;
791if ( fVerbose )
792printf( "Refined classes = %5d. Changes = %4d. Lits = %6d.\n", Vec_PtrSize(p->pCla->vClasses), nChanges, Fra_ClassesCountLits(p->pCla) );
793 } while ( (double)nChanges / nClasses > p->pPars->dSimSatur );
794
795// if ( p->pPars->fVerbose )
796// printf( "Consts = %6d. Classes = %6d. Literals = %6d.\n",
797// Vec_PtrSize(p->pCla->vClasses1), Vec_PtrSize(p->pCla->vClasses), Fra_ClassesCountLits(p->pCla) );
798// Fra_ClassesPrint( p->pCla, 0 );
799}
800
801
813Fra_Sml_t * Fra_SmlStart( Aig_Man_t * pAig, int nPref, int nFrames, int nWordsFrame )
814{
815 Fra_Sml_t * p;
816 p = (Fra_Sml_t *)ABC_ALLOC( char, sizeof(Fra_Sml_t) + sizeof(unsigned) * Aig_ManObjNumMax(pAig) * (nPref + nFrames) * nWordsFrame );
817 memset( p, 0, sizeof(Fra_Sml_t) + sizeof(unsigned) * (nPref + nFrames) * nWordsFrame );
818 p->pAig = pAig;
819 p->nPref = nPref;
820 p->nFrames = nPref + nFrames;
821 p->nWordsFrame = nWordsFrame;
822 p->nWordsTotal = (nPref + nFrames) * nWordsFrame;
823 p->nWordsPref = nPref * nWordsFrame;
824 // constant 1 is initialized to 0 because we store values modulus phase (pObj->fPhase)
825 return p;
826}
827
840{
841 ABC_FREE( p );
842}
843
844
856Fra_Sml_t * Fra_SmlSimulateComb( Aig_Man_t * pAig, int nWords, int fCheckMiter )
857{
858 Fra_Sml_t * p;
859 p = Fra_SmlStart( pAig, 0, 1, nWords );
860 Fra_SmlInitialize( p, 0 );
862 if ( fCheckMiter )
863 p->fNonConstOut = Fra_SmlCheckNonConstOutputs( p );
864 return p;
865}
866
880{
881 Vec_Str_t * vRes;
882 FILE * pFile;
883 int c;
884 pFile = fopen( pFileName, "rb" );
885 if ( pFile == NULL )
886 {
887 printf( "Cannot open file \"%s\" with simulation patterns.\n", pFileName );
888 return NULL;
889 }
890 vRes = Vec_StrAlloc( 1000 );
891 while ( (c = fgetc(pFile)) != EOF )
892 {
893 if ( c == '0' || c == '1' )
894 Vec_StrPush( vRes, (char)(c - '0') );
895 else if ( c != ' ' && c != '\r' && c != '\n' && c != '\t' )
896 {
897 printf( "File \"%s\" contains symbol (%c) other than \'0\' or \'1\'.\n", pFileName, (char)c );
898 Vec_StrFreeP( &vRes );
899 break;
900 }
901 }
902 fclose( pFile );
903 return vRes;
904}
905
918{
919 Aig_Obj_t * pObj;
920 unsigned * pSims;
921 int i, k, nPats = Vec_StrSize(vSimInfo) / Aig_ManCiNum(p->pAig);
922 int nPatsPadded = p->nWordsTotal * 32;
923 assert( Aig_ManRegNum(p->pAig) == 0 );
924 assert( Vec_StrSize(vSimInfo) % Aig_ManCiNum(p->pAig) == 0 );
925 assert( nPats <= nPatsPadded );
926 Aig_ManForEachCi( p->pAig, pObj, i )
927 {
928 pSims = Fra_ObjSim( p, pObj->Id );
929 // clean data
930 for ( k = 0; k < p->nWordsTotal; k++ )
931 pSims[k] = 0;
932 // load patterns
933 for ( k = 0; k < nPats; k++ )
934 if ( Vec_StrEntry(vSimInfo, k * Aig_ManCiNum(p->pAig) + i) )
935 Abc_InfoSetBit( pSims, k );
936 // pad the remaining bits with the value of the last pattern
937 for ( ; k < nPatsPadded; k++ )
938 if ( Vec_StrEntry(vSimInfo, (nPats-1) * Aig_ManCiNum(p->pAig) + i) )
939 Abc_InfoSetBit( pSims, k );
940 }
941}
942
954void Fra_SmlPrintOutputs( Fra_Sml_t * p, int nPatterns )
955{
956 Aig_Obj_t * pObj;
957 unsigned * pSims;
958 int i, k;
959 for ( k = 0; k < nPatterns; k++ )
960 {
961 Aig_ManForEachCi( p->pAig, pObj, i )
962 {
963 pSims = Fra_ObjSim( p, pObj->Id );
964 printf( "%d", Abc_InfoHasBit( pSims, k ) );
965 }
966 printf( " " ); ;
967 Aig_ManForEachCo( p->pAig, pObj, i )
968 {
969 pSims = Fra_ObjSim( p, pObj->Id );
970 printf( "%d", Abc_InfoHasBit( pSims, k ) );
971 }
972 printf( "\n" ); ;
973 }
974}
975
987Fra_Sml_t * Fra_SmlSimulateCombGiven( Aig_Man_t * pAig, char * pFileName, int fCheckMiter, int fVerbose )
988{
989 Vec_Str_t * vSimInfo;
990 Fra_Sml_t * p;
991 int nPatterns;
992 assert( Aig_ManRegNum(pAig) == 0 );
993 // read comb patterns from file
994 vSimInfo = Fra_SmlSimulateReadFile( pFileName );
995 if ( vSimInfo == NULL )
996 return NULL;
997 if ( Vec_StrSize(vSimInfo) % Aig_ManCiNum(pAig) != 0 )
998 {
999 printf( "File \"%s\": The number of binary digits (%d) is not divisible by the number of primary inputs (%d).\n",
1000 pFileName, Vec_StrSize(vSimInfo), Aig_ManCiNum(pAig) );
1001 Vec_StrFree( vSimInfo );
1002 return NULL;
1003 }
1004 p = Fra_SmlStart( pAig, 0, 1, Abc_BitWordNum(Vec_StrSize(vSimInfo) / Aig_ManCiNum(pAig)) );
1005 Fra_SmlInitializeGiven( p, vSimInfo );
1006 nPatterns = Vec_StrSize(vSimInfo) / Aig_ManCiNum(pAig);
1007 Vec_StrFree( vSimInfo );
1009 if ( fCheckMiter )
1010 p->fNonConstOut = Fra_SmlCheckNonConstOutputs( p );
1011 if ( fVerbose )
1012 Fra_SmlPrintOutputs( p, nPatterns );
1013 return p;
1014}
1015
1027Fra_Sml_t * Fra_SmlSimulateSeq( Aig_Man_t * pAig, int nPref, int nFrames, int nWords, int fCheckMiter )
1028{
1029 Fra_Sml_t * p;
1030 p = Fra_SmlStart( pAig, nPref, nFrames, nWords );
1031 Fra_SmlInitialize( p, 1 );
1033 if ( fCheckMiter )
1034 p->fNonConstOut = Fra_SmlCheckNonConstOutputs( p );
1035 return p;
1036}
1037
1050{
1051 Abc_Cex_t * pCex;
1052 Aig_Obj_t * pObj;
1053 unsigned * pSims;
1054 int iPo, iFrame, iBit, i, k;
1055
1056 // make sure the simulation manager has it
1057 assert( p->fNonConstOut );
1058
1059 // find the first output that failed
1060 iPo = -1;
1061 iBit = -1;
1062 iFrame = -1;
1063 Aig_ManForEachPoSeq( p->pAig, pObj, iPo )
1064 {
1065 if ( Fra_SmlNodeIsZero(p, pObj) )
1066 continue;
1067 pSims = Fra_ObjSim( p, pObj->Id );
1068 for ( i = p->nWordsPref; i < p->nWordsTotal; i++ )
1069 if ( pSims[i] )
1070 {
1071 iFrame = i / p->nWordsFrame;
1072 iBit = 32 * (i % p->nWordsFrame) + Aig_WordFindFirstBit( pSims[i] );
1073 break;
1074 }
1075 break;
1076 }
1077 assert( iPo < Aig_ManCoNum(p->pAig)-Aig_ManRegNum(p->pAig) );
1078 assert( iFrame < p->nFrames );
1079 assert( iBit < 32 * p->nWordsFrame );
1080
1081 // allocate the counter example
1082 pCex = Abc_CexAlloc( Aig_ManRegNum(p->pAig), Aig_ManCiNum(p->pAig) - Aig_ManRegNum(p->pAig), iFrame + 1 );
1083 pCex->iPo = iPo;
1084 pCex->iFrame = iFrame;
1085
1086 // copy the bit data
1087 Aig_ManForEachLoSeq( p->pAig, pObj, k )
1088 {
1089 pSims = Fra_ObjSim( p, pObj->Id );
1090 if ( Abc_InfoHasBit( pSims, iBit ) )
1091 Abc_InfoSetBit( pCex->pData, k );
1092 }
1093 for ( i = 0; i <= iFrame; i++ )
1094 {
1095 Aig_ManForEachPiSeq( p->pAig, pObj, k )
1096 {
1097 pSims = Fra_ObjSim( p, pObj->Id );
1098 if ( Abc_InfoHasBit( pSims, 32 * p->nWordsFrame * i + iBit ) )
1099 Abc_InfoSetBit( pCex->pData, pCex->nRegs + pCex->nPis * i + k );
1100 }
1101 }
1102 // verify the counter example
1103 if ( !Saig_ManVerifyCex( p->pAig, pCex ) )
1104 {
1105 printf( "Fra_SmlGetCounterExample(): Counter-example is invalid.\n" );
1106 Abc_CexFree( pCex );
1107 pCex = NULL;
1108 }
1109 return pCex;
1110}
1111
1123Abc_Cex_t * Fra_SmlCopyCounterExample( Aig_Man_t * pAig, Aig_Man_t * pFrames, int * pModel )
1124{
1125 Abc_Cex_t * pCex;
1126 Aig_Obj_t * pObj;
1127 int i, nFrames, nTruePis, nTruePos, iPo, iFrame;
1128 // get the number of frames
1129 assert( Aig_ManRegNum(pAig) > 0 );
1130 assert( Aig_ManRegNum(pFrames) == 0 );
1131 nTruePis = Aig_ManCiNum(pAig)-Aig_ManRegNum(pAig);
1132 nTruePos = Aig_ManCoNum(pAig)-Aig_ManRegNum(pAig);
1133 nFrames = Aig_ManCiNum(pFrames) / nTruePis;
1134 assert( nTruePis * nFrames == Aig_ManCiNum(pFrames) );
1135 assert( nTruePos * nFrames == Aig_ManCoNum(pFrames) );
1136 // find the PO that failed
1137 iPo = -1;
1138 iFrame = -1;
1139 Aig_ManForEachCo( pFrames, pObj, i )
1140 if ( pObj->Id == pModel[Aig_ManCiNum(pFrames)] )
1141 {
1142 iPo = i % nTruePos;
1143 iFrame = i / nTruePos;
1144 break;
1145 }
1146 assert( iPo >= 0 );
1147 // allocate the counter example
1148 pCex = Abc_CexAlloc( Aig_ManRegNum(pAig), nTruePis, iFrame + 1 );
1149 pCex->iPo = iPo;
1150 pCex->iFrame = iFrame;
1151
1152 // copy the bit data
1153 for ( i = 0; i < Aig_ManCiNum(pFrames); i++ )
1154 {
1155 if ( pModel[i] )
1156 Abc_InfoSetBit( pCex->pData, pCex->nRegs + i );
1157 if ( pCex->nRegs + i == pCex->nBits - 1 )
1158 break;
1159 }
1160
1161 // verify the counter example
1162 if ( !Saig_ManVerifyCex( pAig, pCex ) )
1163 {
1164 printf( "Fra_SmlGetCounterExample(): Counter-example is invalid.\n" );
1165 Abc_CexFree( pCex );
1166 pCex = NULL;
1167 }
1168 return pCex;
1169
1170}
1171
1172
1176
1177
1179
int nWords
Definition abcNpn.c:127
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define Aig_ManForEachLiSeq(p, pObj, i)
Definition aig.h:447
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition aig.h:393
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
#define Aig_ManForEachNode(p, pObj, i)
Definition aig.h:413
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
#define Aig_ManForEachPiSeq(p, pObj, i)
SEQUENTIAL ITERATORS ///.
Definition aig.h:438
#define Aig_ManForEachCo(p, pObj, i)
Definition aig.h:398
#define Aig_ManForEachPoSeq(p, pObj, i)
Definition aig.h:444
#define Aig_ManForEachLoSeq(p, pObj, i)
Definition aig.h:441
#define Aig_ManForEachLiLoSeq(p, pObjLi, pObjLo, k)
Definition aig.h:450
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
Cube * p
Definition exorList.c:222
void Fra_SmlPrintOutputs(Fra_Sml_t *p, int nPatterns)
Definition fraSim.c:954
void Fra_SmlNodeCopyFanin(Fra_Sml_t *p, Aig_Obj_t *pObj, int iFrame)
Definition fraSim.c:579
int Fra_SmlNodeIsConst(Aig_Obj_t *pObj)
Definition fraSim.c:86
void Fra_SmlNodeTransferNext(Fra_Sml_t *p, Aig_Obj_t *pOut, Aig_Obj_t *pIn, int iFrame)
Definition fraSim.c:613
void Fra_SmlAssignDist1(Fra_Sml_t *p, unsigned *pPat)
Definition fraSim.c:433
int Fra_SmlCheckNonConstOutputs(Fra_Sml_t *p)
Definition fraSim.c:642
void Fra_SmlSimulate(Fra_Man_t *p, int fInit)
Definition fraSim.c:738
void Fra_SmlAssignConst(Fra_Sml_t *p, Aig_Obj_t *pObj, int fConst1, int iFrame)
Definition fraSim.c:379
void Fra_SmlCheckOutputSavePattern(Fra_Man_t *p, Aig_Obj_t *pObjPo)
Definition fraSim.c:281
void Fra_SmlStop(Fra_Sml_t *p)
Definition fraSim.c:839
void Fra_SmlInitializeGiven(Fra_Sml_t *p, Vec_Str_t *vSimInfo)
Definition fraSim.c:917
void Fra_SmlAssignRandom(Fra_Sml_t *p, Aig_Obj_t *pObj)
Definition fraSim.c:358
Fra_Sml_t * Fra_SmlStart(Aig_Man_t *pAig, int nPref, int nFrames, int nWordsFrame)
Definition fraSim.c:813
int Fra_SmlCheckOutput(Fra_Man_t *p)
Definition fraSim.c:326
int Fra_SmlNodeNotEquWeight(Fra_Sml_t *p, int Left, int Right)
Definition fraSim.c:133
int Fra_SmlNodesCompareInFrame(Fra_Sml_t *p, Aig_Obj_t *pObj0, Aig_Obj_t *pObj1, int iFrame0, int iFrame1)
Definition fraSim.c:550
void Fra_SmlSimulateOne(Fra_Sml_t *p)
Definition fraSim.c:663
int Fra_SmlNodeIsZero(Fra_Sml_t *p, Aig_Obj_t *pObj)
Definition fraSim.c:155
Fra_Sml_t * Fra_SmlSimulateComb(Aig_Man_t *pAig, int nWords, int fCheckMiter)
Definition fraSim.c:856
Abc_Cex_t * Fra_SmlCopyCounterExample(Aig_Man_t *pAig, Aig_Man_t *pFrames, int *pModel)
Definition fraSim.c:1123
void Fra_SmlNodeSimulate(Fra_Sml_t *p, Aig_Obj_t *pObj, int iFrame)
Definition fraSim.c:485
Fra_Sml_t * Fra_SmlSimulateCombGiven(Aig_Man_t *pAig, char *pFileName, int fCheckMiter, int fVerbose)
Definition fraSim.c:987
int Fra_SmlNodesAreEqual(Aig_Obj_t *pObj0, Aig_Obj_t *pObj1)
Definition fraSim.c:109
void Fra_SmlResimulate(Fra_Man_t *p)
Definition fraSim.c:703
int Fra_SmlNodeCountOnes(Fra_Sml_t *p, Aig_Obj_t *pObj)
Definition fraSim.c:177
void Fra_SmlSavePattern1(Fra_Man_t *p, int fInit)
Definition fraSim.c:216
void Fra_SmlInitialize(Fra_Sml_t *p, int fInit)
Definition fraSim.c:400
ABC_NAMESPACE_IMPL_START int Fra_SmlNodeHash(Aig_Obj_t *pObj, int nTableSize)
DECLARATIONS ///.
Definition fraSim.c:46
Fra_Sml_t * Fra_SmlSimulateSeq(Aig_Man_t *pAig, int nPref, int nFrames, int nWords, int fCheckMiter)
Definition fraSim.c:1027
Vec_Str_t * Fra_SmlSimulateReadFile(char *pFileName)
Definition fraSim.c:879
Abc_Cex_t * Fra_SmlGetCounterExample(Fra_Sml_t *p)
Definition fraSim.c:1049
void Fra_SmlSavePattern(Fra_Man_t *p)
Definition fraSim.c:241
void Fra_SmlSavePattern0(Fra_Man_t *p, int fInit)
Definition fraSim.c:200
int Fra_ClassesRefine1(Fra_Cla_t *p, int fRefineNewClass, int *pSkipped)
Definition fraClass.c:527
void Fra_ClassesPrepare(Fra_Cla_t *p, int fLatchCorr, int nMaxLevs)
Definition fraClass.c:276
struct Fra_Man_t_ Fra_Man_t
Definition fra.h:56
int Fra_SmlCheckOutput(Fra_Man_t *p)
Definition fraSim.c:326
int Fra_OneHotRefineUsingCex(Fra_Man_t *p, Vec_Int_t *vOneHots)
Definition fraHot.c:266
int Fra_ClassesRefine(Fra_Cla_t *p)
Definition fraClass.c:493
int Fra_ClassesCountLits(Fra_Cla_t *p)
Definition fraClass.c:164
struct Fra_Sml_t_ Fra_Sml_t
Definition fra.h:58
int Fra_ImpRefineUsingCex(Fra_Man_t *p, Vec_Int_t *vImps)
Definition fraImp.c:575
int Saig_ManVerifyCex(Aig_Man_t *pAig, Abc_Cex_t *p)
Definition saigDup.c:281
int Id
Definition aig.h:85
void * pData
Definition aig.h:87
unsigned int fPhase
Definition aig.h:78
void Abc_CexFree(Abc_Cex_t *p)
Definition utilCex.c:382
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
Definition utilCex.c:51
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition utilCex.h:39
#define assert(ex)
Definition util_old.h:213
char * memset()