34#define FFTEST_MAX_VARS 2
35#define FFTEST_MAX_PARS 8
54 Gia_Obj_t * pObj = Gia_ManObj( pGia, Abc_Lit2Var(iLit) );
55 int fCompl = Abc_LitIsCompl(iLit);
56 if ( Gia_ObjIsAnd(pObj) )
58 Vec_StrPush( vStr,
'(' );
59 if ( Gia_ObjIsMux(pGia, pObj) )
62 Vec_StrPush( vStr,
'?' );
63 Gia_DeriveFormula_rec( pGia, ppNamesIn, vStr, Abc_LitNotCond( Gia_ObjFaninLit1p(pGia, pObj), fCompl ) );
64 Vec_StrPush( vStr,
':' );
65 Gia_DeriveFormula_rec( pGia, ppNamesIn, vStr, Abc_LitNotCond( Gia_ObjFaninLit2p(pGia, pObj), fCompl ) );
69 Gia_DeriveFormula_rec( pGia, ppNamesIn, vStr, Abc_LitNotCond( Gia_ObjFaninLit0p(pGia, pObj), fCompl ) );
70 Vec_StrPush( vStr, (
char)(Gia_ObjIsXor(pObj) ?
'^' : (
char)(fCompl ?
'|' :
'&')) );
71 Gia_DeriveFormula_rec( pGia, ppNamesIn, vStr, Abc_LitNotCond( Gia_ObjFaninLit1p(pGia, pObj), fCompl ) );
73 Vec_StrPush( vStr,
')' );
77 if ( fCompl ) Vec_StrPush( vStr,
'~' );
78 Vec_StrPrintF( vStr,
"%s", ppNamesIn[Gia_ObjCioId(pObj)] );
87 Vec_StrPush( vStr,
'(' );
89 Vec_StrPush( vStr,
')' );
90 Vec_StrPush( vStr,
'\0' );
92 pResult = Vec_StrReleaseArray( vStr );
136static inline void Cnf_AddSorder(
sat_solver *
p,
int * pVars,
int i,
int k,
int * pnVars )
138 int iVar1 = (*pnVars)++;
139 int iVar2 = (*pnVars)++;
145static inline void Cnf_AddCardinConstrMerge(
sat_solver *
p,
int * pVars,
int lo,
int hi,
int r,
int * pnVars )
148 if ( step < hi - lo )
150 Cnf_AddCardinConstrMerge(
p, pVars, lo, hi-r, step, pnVars );
151 Cnf_AddCardinConstrMerge(
p, pVars, lo+r, hi, step, pnVars );
152 for ( i = lo+r; i < hi-r; i += step )
153 Cnf_AddSorder(
p, pVars, i, i+r, pnVars );
156static inline void Cnf_AddCardinConstrRange(
sat_solver *
p,
int * pVars,
int lo,
int hi,
int * pnVars )
160 int i, mid = lo + (hi - lo) / 2;
161 for ( i = lo; i <= mid; i++ )
162 Cnf_AddSorder(
p, pVars, i, i + (hi - lo + 1) / 2, pnVars );
163 Cnf_AddCardinConstrRange(
p, pVars, lo, mid, pnVars );
164 Cnf_AddCardinConstrRange(
p, pVars, mid+1, hi, pnVars );
165 Cnf_AddCardinConstrMerge(
p, pVars, lo, hi, 1, pnVars );
171 int nSizeOld = Vec_IntSize(vVars);
172 int i, iVar, nSize, Lit, nVarsOld;
176 assert( iVar >= 0 && iVar < nVars );
178 for ( nSize = 1; nSize < nSizeOld; nSize *= 2 );
181 if ( nSize != nSizeOld )
184 Vec_IntFillExtra( vVars, nSize, nVars );
186 Lit = Abc_Var2Lit( nVars++, 1 );
192 Cnf_AddCardinConstrRange(
p, Vec_IntArray(vVars), 0, nSize - 1, &nVars );
194 assert( K > 0 && K < nSizeOld );
195 Lit = Abc_Var2Lit( Vec_IntEntry(vVars, K), 1 );
200 Lit = Abc_Var2Lit( Vec_IntEntry(vVars, K-1), 0 );
205 Vec_IntShrink( vVars, 0 );
221static inline int Cnf_AddCardinVar(
int Level,
int Base,
Vec_Int_t * vVars,
int k )
223 return Level ? Base + k : Vec_IntEntry( vVars, k );
227 int i, k, iCur, iNext, iVar, Lit;
229 int nBits = Vec_IntSize(vVars);
231 assert( iVar >= 0 && iVar < nVars );
233 for ( i = 0; i < nBits; i++ )
235 iCur = nVars + nBits * (i-1);
236 iNext = nVars + nBits * i;
238 sat_solver_add_buffer(
p, iNext, Cnf_AddCardinVar(i, iCur, vVars, 0), 0 );
239 for ( k = i & 1; k + 1 < nBits; k += 2 )
241 sat_solver_add_and(
p, iNext+k , Cnf_AddCardinVar(i, iCur, vVars, k), Cnf_AddCardinVar(i, iCur, vVars, k+1), 1, 1, 1 );
242 sat_solver_add_and(
p, iNext+k+1, Cnf_AddCardinVar(i, iCur, vVars, k), Cnf_AddCardinVar(i, iCur, vVars, k+1), 0, 0, 0 );
244 if ( k == nBits - 1 )
245 sat_solver_add_buffer(
p, iNext + nBits-1, Cnf_AddCardinVar(i, iCur, vVars, nBits-1), 0 );
248 assert( K > 0 && K < nBits );
249 Lit = Abc_Var2Lit( nVars + nBits * (nBits - 1) + K, 1 );
254 Lit = Abc_Var2Lit( nVars + nBits * (nBits - 1) + K - 1, 0 );
274 assert( iVar >= 0 && iVar < nVars );
277 while ( Vec_IntSize(vVars) > 1 )
279 for ( k = i = 0; i < Vec_IntSize(vVars)/2; i++ )
281 pLits[0] = Abc_Var2Lit( Vec_IntEntry(vVars, 2*i), 1 );
282 pLits[1] = Abc_Var2Lit( Vec_IntEntry(vVars, 2*i+1), 1 );
284 sat_solver_add_and(
p, iVar, Vec_IntEntry(vVars, 2*i), Vec_IntEntry(vVars, 2*i+1), 1, 1, 1 );
285 Vec_IntWriteEntry( vVars, k++, iVar++ );
287 if ( Vec_IntSize(vVars) & 1 )
288 Vec_IntWriteEntry( vVars, k++, Vec_IntEntryLast(vVars) );
289 Vec_IntShrink( vVars, k );
295 int i, status, Count = 1, nVars = 8;
296 Vec_Int_t * vVars = Vec_IntStartNatural( nVars );
306 Vec_IntClear( vVars );
307 printf(
"%3d : ", Count++ );
308 for ( i = 0; i < nVars; i++ )
310 Vec_IntPush( vVars, Abc_Var2Lit(i, sat_solver_var_value(pSat, i)) );
311 printf(
"%d", sat_solver_var_value(pSat, i) );
314 status =
sat_solver_addclause( pSat, Vec_IntArray(vVars), Vec_IntArray(vVars) + Vec_IntSize(vVars) );
319 Vec_IntFree( vVars );
338 pCnf =
Cnf_Derive( pAig, Aig_ManCoNum(pAig) );
360 if (
p->pVarNums[Gia_ObjId(pGia, pObj)] >= 0 )
361 p->pVarNums[Gia_ObjId(pGia, pObj)] += nVarsPlus;
362 for ( v = 0; v <
p->nLiterals; v++ )
363 p->pClauses[0][v] += 2*nVarsPlus;
382 pNew =
Gia_ManStart( (2 + 3 * fUseMuxes) * Gia_ManObjNum(
p) );
383 pNew->
pName = Abc_UtilStrsav(
p->pName );
385 Gia_ManConst0(
p)->Value = 0;
388 pObj->
Value = Gia_ManAppendCi( pNew );
390 pObj->
Value = Gia_ManAppendCi( pNew );
394 pObj->
Value = Gia_ObjFanin0Copy(pObj);
397 pObj->
Value = Gia_ObjRoToRi(
p, pObj)->Value;
399 pObj->
Value = Gia_ManAppendCi( pNew );
405 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
408 iCtrl = Gia_ManAppendCi(pNew);
409 iThis = Gia_ObjFanin0Copy(pObj);
414 pObj->
Value = Gia_ManAppendCo( pNew, pObj->
Value );
421 iCtrl = Gia_ManAppendCi(pNew);
422 iThis =
Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
429 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
433 assert( Gia_ManPiNum(pNew) == Gia_ManRegNum(
p) + 2 * Gia_ManPiNum(
p) + (fFfOnly ? Gia_ManRegNum(
p) : Gia_ManAndNum(
p)) );
452 int i, iFuncVars = 0;
454 pNew->
pName = Abc_UtilStrsav(
p->pName );
456 Gia_ManConst0(
p)->Value = 0;
458 pObj->
Value = Gia_ManAppendCi( pNew );
463 if ( Vec_IntEntry(vMap, iFuncVars++) )
466 Gia_ManAppendCi(pNew);
468 if ( Vec_IntEntry(vMap, iFuncVars++) )
471 Gia_ManAppendCi(pNew);
473 assert( iFuncVars == Vec_IntSize(vMap) );
475 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
478 assert( Gia_ManPiNum(pNew) == Gia_ManCiNum(
p) + 2 * Gia_ManAndNum(
p) );
497 int i, iFuncVars = 0;
499 pNew->
pName = Abc_UtilStrsav(
p->pName );
501 Gia_ManConst0(
p)->Value = 0;
503 pObj->
Value = Gia_ManAppendCi( pNew );
507 if ( Vec_IntEntry(vMap, iFuncVars++) )
510 Gia_ManAppendCi(pNew);
512 assert( iFuncVars == Vec_IntSize(vMap) );
514 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
517 assert( Gia_ManPiNum(pNew) == Gia_ManCiNum(
p) + Gia_ManAndNum(
p) );
536 int i, iCtrl0, iCtrl1, iCtrl2, iCtrl3, iMuxA, iMuxB, iFuncVars = 0;
537 int VarLimit = 4 * Gia_ManAndNum(
p);
539 pNew->
pName = Abc_UtilStrsav(
p->pName );
541 Gia_ManConst0(
p)->Value = 0;
543 pObj->
Value = Gia_ManAppendCi( pNew );
546 if ( Vec_IntEntry(vMap, iFuncVars++) && iFuncVars < VarLimit )
547 iCtrl0 = Gia_ManAppendCi(pNew);
549 iCtrl0 = 0, Gia_ManAppendCi(pNew);
551 if ( Vec_IntEntry(vMap, iFuncVars++) && iFuncVars < VarLimit )
552 iCtrl1 = Gia_ManAppendCi(pNew);
554 iCtrl1 = 0, Gia_ManAppendCi(pNew);
556 if ( Vec_IntEntry(vMap, iFuncVars++) && iFuncVars < VarLimit )
557 iCtrl2 = Gia_ManAppendCi(pNew);
559 iCtrl2 = 0, Gia_ManAppendCi(pNew);
561 if ( Vec_IntEntry(vMap, iFuncVars++) && iFuncVars < VarLimit )
562 iCtrl3 = Gia_ManAppendCi(pNew);
564 iCtrl3 = 0, Gia_ManAppendCi(pNew);
566 if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
567 iCtrl0 = Abc_LitNot(iCtrl0);
568 else if ( !Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
569 iCtrl1 = Abc_LitNot(iCtrl1);
570 else if ( Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) )
571 iCtrl2 = Abc_LitNot(iCtrl2);
573 iCtrl3 = Abc_LitNot(iCtrl3);
575 iMuxA =
Gia_ManHashMux( pNew, Gia_ObjFanin0(pObj)->Value, iCtrl1, iCtrl0 );
576 iMuxB =
Gia_ManHashMux( pNew, Gia_ObjFanin0(pObj)->Value, iCtrl3, iCtrl2 );
579 assert( iFuncVars == Vec_IntSize(vMap) );
581 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
584 assert( Gia_ManPiNum(pNew) == Gia_ManCiNum(
p) + 4 * Gia_ManAndNum(
p) );
602 if ( pStr[0] !=
'(' )
604 printf(
"The first symbol should be the opening parenthesis \"(\".\n" );
607 if ( pStr[
strlen(pStr)-1] !=
')' )
609 printf(
"The last symbol should be the closing parenthesis \")\".\n" );
612 for ( i = 0; pStr[i]; i++ )
613 if ( pStr[i] ==
'(' )
615 else if ( pStr[i] ==
')' )
619 printf(
"The number of opening and closing parentheses is not equal.\n" );
624 for ( i = 0; pStr[i]; i++ )
626 if ( pStr[i] >=
'a' && pStr[i] <=
'b' )
627 *pnVars = Abc_MaxInt( *pnVars, pStr[i] -
'a' + 1 );
628 else if ( pStr[i] >=
'p' && pStr[i] <=
's' )
629 *pnPars = Abc_MaxInt( *pnPars, pStr[i] -
'p' + 1 );
630 else if ( pStr[i] ==
'(' || pStr[i] ==
')' )
632 else if ( pStr[i] ==
'&' || pStr[i] ==
'|' || pStr[i] ==
'^' )
634 else if ( pStr[i] ==
'?' || pStr[i] ==
':' )
636 else if ( pStr[i] ==
'~' )
638 if ( pStr[i+1] <
'a' || pStr[i+1] >
'z' )
640 printf(
"Expecting alphabetic symbol (instead of \"%c\") after negation (~)\n", pStr[i+1] );
646 printf(
"Unknown symbol (%c) in the formula (%s)\n", pStr[i], pStr );
651 { printf(
"The number of input variables (%d) should be 2\n", *pnVars );
return 1; }
653 { printf(
"The number of parameters should be between 1 and %d\n",
FFTEST_MAX_PARS );
return 1; }
659 for ( k = i = 0; pForm[i]; i++ )
661 if ( pForm[i] ==
'~' )
664 assert( pForm[i] >=
'a' && pForm[i] <=
'z' );
665 pStr[k++] =
'A' + pForm[i] -
'a';
668 pStr[k++] = pForm[i];
688 for ( pThis = pForm; *pThis; pThis++ )
693 else if ( *pThis ==
')' )
705 if ( pBeg + 1 == pEnd )
707 if ( pBeg[0] >=
'a' && pBeg[0] <=
'b' )
708 printf(
"%c", pBeg[0] );
709 else if ( pBeg[0] >=
'A' && pBeg[0] <=
'B' )
710 printf(
"~%c", pBeg[0]-
'A'+
'a' );
711 else if ( pBeg[0] >=
'p' && pBeg[0] <=
'w' )
712 printf(
"%c", pBeg[0] );
713 else if ( pBeg[0] >=
'P' && pBeg[0] <=
'W' )
714 printf(
"~%c", pBeg[0]-
'A'+
'a' );
717 if ( pBeg[0] ==
'(' )
720 if ( pEndNew == pEnd )
723 assert( pBeg[pEnd-pBeg-1] ==
')' );
737 else if ( Oper ==
'|' )
739 else if ( Oper ==
'^' )
741 else if ( Oper ==
'?' )
755 assert( pEndNew[0] ==
':' );
765 printf(
"Using formula: " );
785 int iFans[3], Oper = -1;
787 if ( pBeg + 1 == pEnd )
789 if ( pBeg[0] >=
'a' && pBeg[0] <=
'b' )
790 return pVars[pBeg[0] -
'a'];
791 if ( pBeg[0] >=
'A' && pBeg[0] <=
'B' )
792 return Abc_LitNot( pVars[pBeg[0] -
'A'] );
793 if ( pBeg[0] >=
'p' && pBeg[0] <=
'w' )
794 return pPars[pBeg[0] -
'p'];
795 if ( pBeg[0] >=
'P' && pBeg[0] <=
'W' )
796 return Abc_LitNot( pPars[pBeg[0] -
'P'] );
800 if ( pBeg[0] ==
'(' )
803 if ( pEndNew == pEnd )
806 assert( pBeg[pEnd-pBeg-1] ==
')' );
827 assert( pEndNew[0] ==
':' );
851 pNew->
pName = Abc_UtilStrsav(
p->pName );
853 Gia_ManConst0(
p)->Value = 0;
855 pObj->
Value = Gia_ManAppendCi( pNew );
860 Gia_ObjFanin0(pObj)->fMark0 = 1;
865 for ( k = 0; k < nPars; k++ )
866 iCtrl[k] = Gia_ManAppendCi(pNew);
867 iFans[0] = Gia_ObjFanin0Copy(pObj);
868 iFans[1] = Gia_ObjFanin1Copy(pObj);
876 Gia_ObjFanin0(pObj)->fMark0 = 0;
882 for ( k = 0; k < nPars; k++ )
883 iCtrl[k] = Gia_ManAppendCi(pNew);
884 iFans[0] = Gia_ObjFanin0Copy(pObj);
885 iFans[1] = Gia_ObjFanin1Copy(pObj);
890 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
893 assert( Gia_ManPiNum(pNew) == Gia_ManCiNum(
p) + nPars * (fFfOnly ? Count : Gia_ManAndNum(
p)) );
916 pNew->
pName = Abc_UtilStrsav(
p->pName );
918 Gia_ManConst0(
p)->Value = 0;
921 pObj->
Value = Gia_ManAppendCi( pNew );
922 if ( i < Vec_IntSize(vValues) )
923 pObj->
Value = Vec_IntEntry( vValues, i );
928 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
931 assert( Gia_ManPiNum(pNew) == Gia_ManPiNum(
p) );
949 FILE * pFile = fopen( pFileName,
"wb" );
950 int i, k, v, nVars = Vec_IntSize(vTests) / nIter;
951 assert( Vec_IntSize(vTests) % nIter == 0 );
952 for ( v = i = 0; i < nIter; i++, fprintf(pFile,
"\n") )
953 for ( k = 0; k < nVars; k++ )
954 fprintf( pFile,
"%d", Vec_IntEntry(vTests, v++) );
972 assert( Vec_IntSize(vValues) == Gia_ManCiNum(
p) );
973 Gia_ManConst0(
p)->fMark0 = 0;
975 pObj->
fMark0 = Vec_IntEntry( vValues, k );
977 pObj->
fMark0 = (Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj)) &
978 (Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj));
980 pObj->
fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
982 Vec_IntClear( vValues );
984 Vec_IntPush( vValues, pObj->
fMark0 );
985 assert( Vec_IntSize(vValues) == Gia_ManRegNum(
p) );
989 FILE * pFile = fopen( pFileName,
"wb" );
990 Vec_Int_t * vValues = Vec_IntAlloc( Gia_ManCiNum(
p) );
991 int i, v, nVars = Vec_IntSize(vTests) / nIter;
992 assert( Vec_IntSize(vTests) % nIter == 0 );
993 assert( nVars == 2 * Gia_ManPiNum(
p) + Gia_ManRegNum(
p) );
994 for ( i = 0; i < nIter; i++ )
997 Vec_IntClear( vValues );
998 for ( v = Gia_ManRegNum(
p); v < Gia_ManCiNum(
p); v++ )
1000 fprintf( pFile,
"%d", Vec_IntEntry(vTests, i * nVars + v) );
1001 Vec_IntPush( vValues, Vec_IntEntry(vTests, i * nVars + v) );
1003 for ( v = 0; v < Gia_ManRegNum(
p); v++ )
1005 fprintf( pFile,
"%d", Vec_IntEntry(vTests, i * nVars + v) );
1006 Vec_IntPush( vValues, Vec_IntEntry(vTests, i * nVars + v) );
1008 fprintf( pFile,
"\n" );
1012 for ( v = Gia_ManCiNum(
p); v < nVars; v++ )
1013 fprintf( pFile,
"%d", Vec_IntEntry(vTests, i * nVars + v) );
1014 for ( v = 0; v < Vec_IntSize(vValues); v++ )
1015 fprintf( pFile,
"%d", Vec_IntEntry(vValues, v) );
1016 fprintf( pFile,
"\n" );
1020 Vec_IntFree( vValues );
1036 FILE * pTable = fopen(
"fault_stats.txt",
"a+" );
1038 fprintf( pTable,
"%s ", Gia_ManName(
p) );
1039 fprintf( pTable,
"%d ", Gia_ManPiNum(
p) );
1040 fprintf( pTable,
"%d ", Gia_ManPoNum(
p) );
1041 fprintf( pTable,
"%d ", Gia_ManRegNum(
p) );
1042 fprintf( pTable,
"%d ", Gia_ManAndNum(
p) );
1048 fprintf( pTable,
"%d ", nIter );
1049 fprintf( pTable,
"%.2f", 1.0*clk/CLOCKS_PER_SEC );
1050 fprintf( pTable,
"\n" );
1074 pCnf2 = Cnf_DeriveGiaRemapped( pC );
1077 for ( i = 0; i < pCnf2->
nClauses; i++ )
1088 Vec_Int_t * vOrGate = Vec_IntAlloc( Gia_ManPoNum(pC) );
1091 Lit = Abc_Var2Lit( pCnf2->
pVarNums[Gia_ObjId(pC, pObj)], 0 );
1092 Vec_IntPush( vOrGate, Lit );
1094 if ( !
sat_solver_addclause( pSat, Vec_IntArray(vOrGate), Vec_IntArray(vOrGate) + Vec_IntSize(vOrGate) ) )
1096 Vec_IntFree( vOrGate );
1103 Lit = Abc_Var2Lit( pCnf2->
pVarNums[Gia_ObjId(pC, pObj)], 1 );
1116 if ( i >= nFuncVars )
1117 sat_solver_add_buffer( pSat, pCnf->
pVarNums[Gia_ObjId(pGiaCnf, pObj)], pCnf2->
pVarNums[Gia_ObjId(pC, Gia_ManPi(pC, i))], 0 );
1138 FILE * pFile = fopen( pFileName,
"wb" );
1141 int nItersMax = 10000;
1142 int i, nIters, status, Value, Count = 0;
1143 vLits = Vec_IntAlloc( Gia_ManPiNum(pM) - nFuncVars );
1144 for ( nIters = 0; nIters < nItersMax; nIters++ )
1146 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
1148 printf(
"Timeout reached after dumping %d untestable faults.\n", nIters );
1154 Vec_IntClear( vLits );
1156 if ( i >= nFuncVars )
1157 Vec_IntPush( vLits, Abc_Var2Lit(pCnf->
pVarNums[Gia_ObjId(pM, pObj)], sat_solver_var_value(pSat, pCnf->
pVarNums[Gia_ObjId(pM, pObj)])) );
1160 if ( Abc_LitIsCompl(Value) )
1162 if ( i < Vec_IntSize(vLits) )
1166 printf(
"Untestable fault %4d : ", ++Count );
1168 if ( Abc_LitIsCompl(Value) )
1173 if ( Abc_LitIsCompl(Value) )
1174 fprintf( pFile,
"%d ", i );
1175 fprintf( pFile,
"\n" );
1178 if ( !
sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits) ) )
1181 Vec_IntFree( vLits );
1199 FILE * pFile = fopen( pFileName,
"rb" );
1201 if ( pFile == NULL )
1203 printf(
"Cannot open input file \"%s\".\n", pFileName );
1206 vTests = Vec_IntAlloc( 10000 );
1207 while ( (c = fgetc(pFile)) != EOF )
1209 if ( c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n' )
1211 if ( c !=
'0' && c !=
'1' )
1213 printf(
"Wrong symbol (%c) in the input file.\n", c );
1214 Vec_IntFreeP( &vTests );
1217 Vec_IntPush( vTests, c -
'0' );
1238 for ( i = 0; i < nPisNew; i++ )
1239 Gia_ManAppendCi( pNew );
1256 int nConfLimit = 100;
1257 int status, i, v, iVar, Lit;
1258 int nUnsats = 0, nRuns = 0;
1260 assert( Vec_IntSize(vPars) == Vec_IntSize(vMap) );
1262 Vec_IntClear( vLits );
1263 Vec_IntAppend( vLits, vMap );
1264 for ( v = 0; v < Vec_IntSize(vPars); v++ )
1266 if ( !Vec_IntEntry(vLits, v) )
1268 assert( Vec_IntEntry(vLits, v) == 1 );
1270 Lit = Abc_Var2Lit( Vec_IntEntry(vPars, v), 0 );
1271 status =
sat_solver_solve( pSat, &Lit, &Lit+1, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
1277 assert( Vec_IntEntry(vMap, v) == 1 );
1278 Vec_IntWriteEntry( vMap, v, 0 );
1279 Lit = Abc_LitNot(Lit);
1285 if ( Vec_IntEntry(vLits, i) && sat_solver_var_value(pSat, iVar) )
1286 Vec_IntWriteEntry( vLits, i, 0 );
1287 assert( Vec_IntEntry(vLits, v) == 0 );
1289 printf(
"Iteration %3d has determined %5d (out of %5d) parameters after %6d SAT calls. ", Iter, Vec_IntSize(vMap) - Vec_IntCountPositive(vMap), Vec_IntSize(vPars), nRuns );
1290 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
1307 char * pFileName =
"newfaults.txt";
1313 int i, Iter, IterMax, nNewFaults;
1318 pCnf2 = Cnf_DeriveGiaRemapped( pC );
1323 sat_solver_set_runtime_limit( pSat, pPars->
nTimeOut ? pPars->
nTimeOut * CLOCKS_PER_SEC + Abc_Clock(): 0 );
1328 assert( Vec_IntSize(vTests) % nFuncVars == 0 );
1329 IterMax = Vec_IntSize(vTests) / nFuncVars;
1330 vLits = Vec_IntAlloc( nFuncVars );
1331 for ( Iter = 0; Iter < IterMax; Iter++ )
1334 Vec_IntClear( vLits );
1335 for ( i = 0; i < nFuncVars; i++ )
1336 Vec_IntPush( vLits, Vec_IntEntry(vTests, Iter*nFuncVars + i) );
1342 Vec_IntFree( vLits );
1347 printf(
"Dumped %d new multiple faults into file \"%s\". ", nNewFaults, pFileName );
1348 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
1368int Gia_ManFaultPrepare(
Gia_Man_t *
p,
Gia_Man_t * pG,
Bmc_ParFf_t * pPars,
int nFuncVars,
Vec_Int_t * vMap,
Vec_Int_t * vTests,
Vec_Int_t * vLits,
Gia_Man_t ** ppMiter,
Cnf_Dat_t ** ppCnf,
sat_solver ** ppSat,
int fWarmUp )
1370 Gia_Man_t * p0 = NULL, * p1 = NULL, * pM;
1374 int i, Iter, status;
1377 if ( Vec_IntSize(vTests) && (Vec_IntSize(vTests) % nFuncVars != 0) )
1379 printf(
"The number of symbols in the input patterns (%d) does not divide evenly on the number of test variables (%d).\n", Vec_IntSize(vTests), nFuncVars );
1380 Vec_IntFree( vTests );
1385 if ( pPars->
Algo == 0 )
1387 else if ( pPars->
Algo == 1 )
1389 assert( Gia_ManRegNum(
p) > 0 );
1393 else if ( pPars->
Algo == 2 )
1395 else if ( pPars->
Algo == 3 )
1397 else if ( pPars->
Algo == 4 )
1399 if ( pPars->
Algo != 1 )
1406 pCnf = Cnf_DeriveGiaRemapped( pM );
1413 sat_solver_set_runtime_limit( pSat, pPars->
nTimeOut ? pPars->
nTimeOut * CLOCKS_PER_SEC + Abc_Clock(): 0 );
1415 for ( i = 0; i < pCnf->
nClauses; i++ )
1420 Vec_IntClear( vLits );
1422 Vec_IntPush( vLits, Abc_Var2Lit(pCnf->
pVarNums[Gia_ObjId(pM, pObj)], 0) );
1433 Vec_IntClear( vLits );
1435 if ( i >= nFuncVars )
1436 Vec_IntPush( vLits, pCnf->
pVarNums[Gia_ObjId(pM, pObj)] );
1437 Cnf_AddCardinConstr( pSat, vLits );
1441 Vec_IntClear( vLits );
1443 if ( i >= nFuncVars )
1444 Vec_IntPush( vLits, pCnf->
pVarNums[Gia_ObjId(pM, pObj)] );
1449 if ( Vec_IntSize(vTests) > 0 )
1451 int nTests = Vec_IntSize(vTests) / nFuncVars;
1452 assert( Vec_IntSize(vTests) % nFuncVars == 0 );
1454 printf(
"Reading %d pre-computed test patterns from file \"%s\".\n", Vec_IntSize(vTests) / nFuncVars, pPars->
pFileName );
1456 printf(
"Reading %d pre-computed test patterns from previous rounds.\n", Vec_IntSize(vTests) / nFuncVars );
1457 for ( Iter = 0; Iter < nTests; Iter++ )
1462 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
1463 clkSat += Abc_Clock() - clk;
1468 printf(
"Timeout reached after %d seconds and adding %d tests.\n", pPars->
nTimeOut, Iter );
1469 Vec_IntShrink( vTests, Iter * nFuncVars );
1476 printf(
"The problem is UNSAT after adding %d tests.\n", Iter );
1477 Vec_IntShrink( vTests, Iter * nFuncVars );
1482 Vec_IntClear( vLits );
1483 for ( i = 0; i < nFuncVars; i++ )
1484 Vec_IntPush( vLits, Vec_IntEntry(vTests, Iter*nFuncVars + i) );
1489 printf(
"The problem is UNSAT after adding %d tests.\n", Iter );
1490 Vec_IntShrink( vTests, Iter * nFuncVars );
1495 printf(
"Iter%6d : ", Iter );
1506 for ( Iter = 0; Iter < 2; Iter++ )
1508 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
1513 printf(
"Timeout reached after %d seconds and %d iterations.\n", pPars->
nTimeOut, Iter );
1514 Vec_IntShrink( vTests, Iter * nFuncVars );
1521 printf(
"The problem is UNSAT after %d iterations.\n", Iter );
1522 Vec_IntShrink( vTests, Iter * nFuncVars );
1526 Vec_IntFill( vLits, nFuncVars, Iter );
1527 Vec_IntAppend( vTests, vLits );
1532 printf(
"The problem is UNSAT after adding %d tests.\n", Iter );
1533 Vec_IntShrink( vTests, Iter * nFuncVars );
1539 printf(
"Using miter with: AIG nodes = %6d. CNF variables = %6d. CNF clauses = %8d.\n", Gia_ManAndNum(pM), pCnf->
nVars, pCnf->
nClauses );
1556 int nIterMax = 1000000, nVars, nPars;
1557 int i, Iter, Iter2, status, nFuncVars = -1;
1558 abctime clk, clkSat = 0, clkTotal = Abc_Clock();
1559 Vec_Int_t * vLits, * vMap = NULL, * vTests, * vPars = NULL;
1569 if ( pPars->
Algo == 0 )
1570 printf(
"FFTEST is computing test patterns for fault model \"%s\"...\n", pPars->
pFormStr );
1571 else if ( pPars->
Algo == 1 )
1572 printf(
"FFTEST is computing test patterns for %sdelay faults...\n", pPars->
fBasic ?
"single " :
"" );
1573 else if ( pPars->
Algo == 2 )
1574 printf(
"FFTEST is computing test patterns for %sstuck-at faults...\n", pPars->
fBasic ?
"single " :
"" );
1575 else if ( pPars->
Algo == 3 )
1576 printf(
"FFTEST is computing test patterns for %scomplement faults...\n", pPars->
fBasic ?
"single " :
"" );
1577 else if ( pPars->
Algo == 4 )
1578 printf(
"FFTEST is computing test patterns for %sfunctionally observable faults...\n", pPars->
fBasic ?
"single " :
"" );
1581 printf(
"Unrecognized algorithm (%d).\n", pPars->
Algo );
1585 printf(
"Options: " );
1590 printf(
"Faults at FF outputs only = yes. " );
1592 printf(
"Runtime limit = %d sec. ", pPars->
nTimeOut );
1593 if (
p != pG && pG->
pSpec )
1594 printf(
"Golden model = %s. ", pG->
pSpec );
1595 printf(
"Verbose = %s. ", pPars->
fVerbose ?
"yes":
"no" );
1599 if ( pPars->
Algo == 0 )
1600 nFuncVars = Gia_ManCiNum(
p);
1601 else if ( pPars->
Algo == 1 )
1602 nFuncVars = Gia_ManRegNum(
p) + 2 * Gia_ManPiNum(
p);
1603 else if ( pPars->
Algo == 2 )
1604 nFuncVars = Gia_ManCiNum(
p);
1605 else if ( pPars->
Algo == 3 )
1606 nFuncVars = Gia_ManCiNum(
p);
1607 else if ( pPars->
Algo == 4 )
1608 nFuncVars = Gia_ManCiNum(
p);
1614 vTests = Vec_IntAlloc( 10000 );
1615 if ( vTests == NULL )
1619 vMap = Vec_IntAlloc( 0 );
1620 if ( pPars->
Algo == 2 )
1621 Vec_IntFill( vMap, 2 * Gia_ManAndNum(
p), 1 );
1622 else if ( pPars->
Algo == 3 )
1623 Vec_IntFill( vMap, Gia_ManAndNum(
p), 1 );
1624 else if ( pPars->
Algo == 4 )
1625 Vec_IntFill( vMap, 4 * Gia_ManAndNum(
p), 1 );
1628 vLits = Vec_IntAlloc( Gia_ManCoNum(
p) );
1631 if (
Gia_ManFaultPrepare(
p, pG, pPars, nFuncVars, vMap, vTests, vLits, &pM, &pCnf, &pSat, 1) )
1632 for ( Iter = pPars->
fStartPats ? 2 : Vec_IntSize(vTests) / nFuncVars; Iter < nIterMax; Iter++ )
1637 vPars = Vec_IntAlloc( Gia_ManPiNum(pM) - nFuncVars );
1639 if ( i >= nFuncVars )
1640 Vec_IntPush( vPars, pCnf->
pVarNums[Gia_ObjId(pM, pObj)] );
1641 assert( Vec_IntSize(vPars) == Gia_ManPiNum(pM) - nFuncVars );
1652 if ( !
Gia_ManFaultPrepare(
p, pG, pPars, nFuncVars, vMap, vTests, vLits, &pM, &pCnf, &pSat, 0) )
1654 printf(
"This should never happen.\n" );
1657 Vec_IntFreeP( &vPars );
1661 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
1662 clkSat += Abc_Clock() - clk;
1665 printf(
"Iter%6d : ", Iter );
1676 printf(
"Timeout reached after %d seconds and %d iterations.\n", pPars->
nTimeOut, Iter );
1683 printf(
"The problem is UNSAT after %d iterations. ", Iter );
1688 Vec_IntClear( vLits );
1690 if ( i < nFuncVars )
1691 Vec_IntPush( vLits, sat_solver_var_value(pSat, pCnf->
pVarNums[Gia_ObjId(pM, pObj)]) );
1696 if ( Vec_IntSize(vTests) == 0 )
1697 printf(
"The input test patterns are not given.\n" );
1702 Vec_IntAppend( vTests, vLits );
1708 printf(
"The problem is UNSAT after adding %d tests.\n", Iter );
1712 else Iter = Vec_IntSize(vTests) / nFuncVars;
1718 Abc_PrintTime( 1,
"Testing runtime", Abc_Clock() - clkTotal );
1726 printf(
"Dumping %d pairs of test patterns (total %d pattern) into file \"%s\".\n", Vec_IntSize(vTests) / nFuncVars, 2*Vec_IntSize(vTests) / nFuncVars, pFileName );
1731 printf(
"Dumping %d test patterns into file \"%s\".\n", Vec_IntSize(vTests) / nFuncVars, pFileName );
1738 abctime clkTotal = Abc_Clock();
1743 sat_solver_set_runtime_limit( pSat, pPars->
nTimeOut ? pPars->
nTimeOut * CLOCKS_PER_SEC + Abc_Clock(): 0 );
1745 for ( i = 0; i < pCnf->
nClauses; i++ )
1751 Vec_IntClear( vLits );
1753 if ( i >= nFuncVars )
1754 Vec_IntPush( vLits, Abc_Var2Lit(pCnf->
pVarNums[Gia_ObjId(pM, pObj)], 0) );
1760 Vec_IntClear( vLits );
1762 if ( i >= nFuncVars )
1763 Vec_IntPush( vLits, pCnf->
pVarNums[Gia_ObjId(pM, pObj)] );
1764 Cnf_AddCardinConstr( pSat, vLits );
1769 int Lit = Abc_Var2Lit( pCnf->
pVarNums[Gia_ObjId(pM, pObj)], 1 );
1777 assert( Vec_IntSize(vTests) == Iter * nFuncVars );
1778 for ( Iter2 = 0; ; Iter2++ )
1781 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
1782 clkSat += Abc_Clock() - clk;
1785 printf(
"Iter%6d : ", Iter2 );
1796 printf(
"Timeout reached after %d seconds and %d iterations.\n", pPars->
nTimeOut, Iter2 );
1799 if ( Iter2 == Iter )
1803 Vec_IntClear( vLits );
1804 for ( i = 0; i < nFuncVars; i++ )
1805 Vec_IntPush( vLits, Vec_IntEntry(vTests, Iter2*nFuncVars + i) );
1808 printf(
"The problem is UNSAT after adding %d tests.\n", Iter2 );
1818 printf(
"There are untestable faults. " );
1820 printf(
"There is no untestable faults. " );
1822 Abc_PrintTime( 1,
"Fault computation runtime", Abc_Clock() - clkTotal );
1827 printf(
"The circuit is rectifiable. " );
1829 printf(
"The circuit is not rectifiable (or equivalent to the golden one). " );
1831 Abc_PrintTime( 1,
"Rectification runtime", Abc_Clock() - clkTotal );
1840 printf(
"Dumped %d untestable multiple faults into file \"%s\". ", nUntests, pFileName );
1842 printf(
"Dumped %d ways of rectifying the circuit into file \"%s\". ", nUntests, pFileName );
1843 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
1850 Vec_IntFree( vTests );
1851 Vec_IntFree( vMap );
1852 Vec_IntFree( vLits );
1853 Vec_IntFreeP( &vPars );
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManStop(Aig_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
void Gia_ParFfSetDefault(Bmc_ParFf_t *p)
char * Gia_ManFormulaEndToken(char *pForm)
void Gia_DeriveFormula_rec(Gia_Man_t *pGia, char **ppNamesIn, Vec_Str_t *vStr, int iLit)
FUNCTION DEFINITIONS ///.
int Gia_ManDumpUntests(Gia_Man_t *pM, Cnf_Dat_t *pCnf, sat_solver *pSat, int nFuncVars, char *pFileName, int fVerbose)
Gia_Man_t * Gia_ManFaultUnfold(Gia_Man_t *p, int fUseMuxes, int fFfOnly)
int Gia_ManRealizeFormula(Gia_Man_t *p, int *pVars, int *pPars, char *pStr, int nPars)
int Gia_FormStrCount(char *pStr, int *pnVars, int *pnPars)
void Gia_ManPrintFormula_rec(char *pBeg, char *pEnd)
Gia_Man_t * Gia_ManDeriveDup(Gia_Man_t *p, int nPisNew)
Gia_Man_t * Gia_ManFormulaUnfold(Gia_Man_t *p, char *pForm, int fFfOnly)
int Gia_ManFaultPrepare(Gia_Man_t *p, Gia_Man_t *pG, Bmc_ParFf_t *pPars, int nFuncVars, Vec_Int_t *vMap, Vec_Int_t *vTests, Vec_Int_t *vLits, Gia_Man_t **ppMiter, Cnf_Dat_t **ppCnf, sat_solver **ppSat, int fWarmUp)
char * Gia_DeriveFormula(Gia_Man_t *pGia, char **ppNamesIn)
void Gia_ManPrintFormula(char *pStr)
Gia_Man_t * Gia_ManFlipUnfold(Gia_Man_t *p, Vec_Int_t *vMap)
void Gia_FormStrTransform(char *pStr, char *pForm)
void Cnf_AddCardinConstrPairWise(sat_solver *p, Vec_Int_t *vVars, int K, int fStrict)
void Cnf_AddCardinConstrGeneral(sat_solver *p, Vec_Int_t *vVars, int K, int fStrict)
void Gia_ManPrintResults(Gia_Man_t *p, sat_solver *pSat, int nIter, abctime clk)
Gia_Man_t * Gia_ManFaultCofactor(Gia_Man_t *p, Vec_Int_t *vValues)
#define FFTEST_MAX_VARS
DECLARATIONS ///.
int Gia_ManFaultDumpNewFaults(Gia_Man_t *pM, int nFuncVars, Vec_Int_t *vTests, Vec_Int_t *vTestNew, Bmc_ParFf_t *pPars)
Gia_Man_t * Gia_ManStuckAtUnfold(Gia_Man_t *p, Vec_Int_t *vMap)
void Cnf_AddCardinConstrTest()
void Gia_ManDumpTestsSimulate(Gia_Man_t *p, Vec_Int_t *vValues)
int Gia_ManFaultAnalyze(sat_solver *pSat, Vec_Int_t *vPars, Vec_Int_t *vMap, Vec_Int_t *vLits, int Iter)
void Gia_ManDumpTestsDelay(Vec_Int_t *vTests, int nIter, char *pFileName, Gia_Man_t *p)
void Gia_ManDumpTests(Vec_Int_t *vTests, int nIter, char *pFileName)
int Gia_ManRealizeFormula_rec(Gia_Man_t *p, int *pVars, int *pPars, char *pBeg, char *pEnd, int nPars)
Gia_Man_t * Gia_ManFOFUnfold(Gia_Man_t *p, Vec_Int_t *vMap)
int Gia_ManFaultAddOne(Gia_Man_t *pM, Cnf_Dat_t *pCnf, sat_solver *pSat, Vec_Int_t *vLits, int nFuncVars, int fAddOr, Gia_Man_t *pGiaCnf)
Vec_Int_t * Gia_ManGetTestPatterns(char *pFileName)
void Gia_ManFaultTest(Gia_Man_t *p, Gia_Man_t *pG, Bmc_ParFf_t *pPars)
struct Bmc_ParFf_t_ Bmc_ParFf_t
#define sat_solver_addclause
#define sat_solver_add_and
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
struct Cnf_Dat_t_ Cnf_Dat_t
void Cnf_DataFree(Cnf_Dat_t *p)
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
void Gia_ManStop(Gia_Man_t *p)
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Gia_Man_t * Gia_ManDupMuxes(Gia_Man_t *p, int Limit)
#define Gia_ManForEachRo(p, pObj, i)
#define Gia_ManForEachPo(p, pObj, i)
#define Gia_ManForEachAnd(p, pObj, i)
void Gia_ManHashAlloc(Gia_Man_t *p)
#define Gia_ManForEachPi(p, pObj, i)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
struct Gia_Obj_t_ Gia_Obj_t
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
struct Gia_Man_t_ Gia_Man_t
int Gia_ManHashMux(Gia_Man_t *p, int iCtrl, int iData1, int iData0)
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
void Gia_ManCleanMark0(Gia_Man_t *p)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Gia_Man_t * Gia_ManMiter(Gia_Man_t *pAig0, Gia_Man_t *pAig1, int nInsDup, int fDualOut, int fSeq, int fImplic, int fVerbose)
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
#define Gia_ManForEachCo(p, pObj, i)
#define Gia_ManForEachCi(p, pObj, i)
#define Gia_ManForEachRi(p, pObj, i)
sat_solver * sat_solver_new(void)
int sat_solver_simplify(sat_solver *s)
int sat_solver_nconflicts(sat_solver *s)
int sat_solver_nclauses(sat_solver *s)
void sat_solver_setnvars(sat_solver *s, int n)
int sat_solver_nvars(sat_solver *s)
void sat_solver_delete(sat_solver *s)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.