00001
00021 #include "abc.h"
00022 #include "fraig.h"
00023 #include "sim.h"
00024
00028
00029 static void Abc_NtkVerifyReportError( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int * pModel );
00030 extern void Abc_NtkVerifyReportErrorSeq( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int * pModel, int nFrames );
00031
00035
00047 void Abc_NtkCecSat( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConfLimit, int nInsLimit )
00048 {
00049 extern Abc_Ntk_t * Abc_NtkMulti( Abc_Ntk_t * pNtk, int nThresh, int nFaninMax, int fCnf, int fMulti, int fSimple, int fFactor );
00050 Abc_Ntk_t * pMiter;
00051 Abc_Ntk_t * pCnf;
00052 int RetValue;
00053
00054
00055 pMiter = Abc_NtkMiter( pNtk1, pNtk2, 1, 0 );
00056 if ( pMiter == NULL )
00057 {
00058 printf( "Miter computation has failed.\n" );
00059 return;
00060 }
00061 RetValue = Abc_NtkMiterIsConstant( pMiter );
00062 if ( RetValue == 0 )
00063 {
00064 printf( "Networks are NOT EQUIVALENT after structural hashing.\n" );
00065
00066 pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, 1 );
00067 Abc_NtkVerifyReportError( pNtk1, pNtk2, pMiter->pModel );
00068 FREE( pMiter->pModel );
00069 Abc_NtkDelete( pMiter );
00070 return;
00071 }
00072 if ( RetValue == 1 )
00073 {
00074 Abc_NtkDelete( pMiter );
00075 printf( "Networks are equivalent after structural hashing.\n" );
00076 return;
00077 }
00078
00079
00080 pCnf = Abc_NtkMulti( pMiter, 0, 100, 1, 0, 0, 0 );
00081 Abc_NtkDelete( pMiter );
00082 if ( pCnf == NULL )
00083 {
00084 printf( "Renoding for CNF has failed.\n" );
00085 return;
00086 }
00087
00088
00089 RetValue = Abc_NtkMiterSat( pCnf, (sint64)nConfLimit, (sint64)nInsLimit, 0, NULL, NULL );
00090 if ( RetValue == -1 )
00091 printf( "Networks are undecided (SAT solver timed out).\n" );
00092 else if ( RetValue == 0 )
00093 printf( "Networks are NOT EQUIVALENT after SAT.\n" );
00094 else
00095 printf( "Networks are equivalent after SAT.\n" );
00096 if ( pCnf->pModel )
00097 Abc_NtkVerifyReportError( pNtk1, pNtk2, pCnf->pModel );
00098 FREE( pCnf->pModel );
00099 Abc_NtkDelete( pCnf );
00100 }
00101
00102
00114 void Abc_NtkCecFraig( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int fVerbose )
00115 {
00116 Prove_Params_t Params, * pParams = &Params;
00117
00118
00119 Abc_Ntk_t * pMiter;
00120 int RetValue;
00121
00122
00123 pMiter = Abc_NtkMiter( pNtk1, pNtk2, 1, 0 );
00124 if ( pMiter == NULL )
00125 {
00126 printf( "Miter computation has failed.\n" );
00127 return;
00128 }
00129 RetValue = Abc_NtkMiterIsConstant( pMiter );
00130 if ( RetValue == 0 )
00131 {
00132 printf( "Networks are NOT EQUIVALENT after structural hashing.\n" );
00133
00134 pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, 1 );
00135 Abc_NtkVerifyReportError( pNtk1, pNtk2, pMiter->pModel );
00136 FREE( pMiter->pModel );
00137 Abc_NtkDelete( pMiter );
00138 return;
00139 }
00140 if ( RetValue == 1 )
00141 {
00142 printf( "Networks are equivalent after structural hashing.\n" );
00143 Abc_NtkDelete( pMiter );
00144 return;
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 Prove_ParamsSetDefault( pParams );
00177 pParams->nItersMax = 5;
00178
00179
00180 RetValue = Abc_NtkIvyProve( &pMiter, pParams );
00181 if ( RetValue == -1 )
00182 printf( "Networks are undecided (resource limits is reached).\n" );
00183 else if ( RetValue == 0 )
00184 {
00185 int * pSimInfo = Abc_NtkVerifySimulatePattern( pMiter, pMiter->pModel );
00186 if ( pSimInfo[0] != 1 )
00187 printf( "ERROR in Abc_NtkMiterProve(): Generated counter-example is invalid.\n" );
00188 else
00189 printf( "Networks are NOT EQUIVALENT.\n" );
00190 free( pSimInfo );
00191 }
00192 else
00193 printf( "Networks are equivalent.\n" );
00194 if ( pMiter->pModel )
00195 Abc_NtkVerifyReportError( pNtk1, pNtk2, pMiter->pModel );
00196 Abc_NtkDelete( pMiter );
00197 }
00198
00210 void Abc_NtkCecFraigPart( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int nPartSize, int fVerbose )
00211 {
00212 extern int Cmd_CommandExecute( void * pAbc, char * sCommand );
00213 extern void * Abc_FrameGetGlobalFrame();
00214
00215 Prove_Params_t Params, * pParams = &Params;
00216 Abc_Ntk_t * pMiter, * pMiterPart;
00217 Abc_Obj_t * pObj;
00218 int i, RetValue, Status, nOutputs;
00219
00220
00221 Prove_ParamsSetDefault( pParams );
00222 pParams->nItersMax = 5;
00223
00224
00225 assert( nPartSize > 0 );
00226
00227
00228 pMiter = Abc_NtkMiter( pNtk1, pNtk2, 1, nPartSize );
00229 if ( pMiter == NULL )
00230 {
00231 printf( "Miter computation has failed.\n" );
00232 return;
00233 }
00234 RetValue = Abc_NtkMiterIsConstant( pMiter );
00235 if ( RetValue == 0 )
00236 {
00237 printf( "Networks are NOT EQUIVALENT after structural hashing.\n" );
00238
00239 pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, 1 );
00240 Abc_NtkVerifyReportError( pNtk1, pNtk2, pMiter->pModel );
00241 FREE( pMiter->pModel );
00242 Abc_NtkDelete( pMiter );
00243 return;
00244 }
00245 if ( RetValue == 1 )
00246 {
00247 printf( "Networks are equivalent after structural hashing.\n" );
00248 Abc_NtkDelete( pMiter );
00249 return;
00250 }
00251
00252 Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "unset progressbar" );
00253
00254
00255 Status = 1;
00256 nOutputs = 0;
00257 Abc_NtkForEachPo( pMiter, pObj, i )
00258 {
00259 if ( Abc_ObjFanin0(pObj) == Abc_AigConst1(pMiter) )
00260 {
00261 if ( Abc_ObjFaninC0(pObj) )
00262 RetValue = 1;
00263 else
00264 RetValue = 0;
00265 pMiterPart = NULL;
00266 }
00267 else
00268 {
00269
00270 pMiterPart = Abc_NtkCreateCone( pMiter, Abc_ObjFanin0(pObj), Abc_ObjName(pObj), 0 );
00271 if ( Abc_ObjFaninC0(pObj) )
00272 Abc_ObjXorFaninC( Abc_NtkPo(pMiterPart,0), 0 );
00273
00274
00275 RetValue = Abc_NtkIvyProve( &pMiterPart, pParams );
00276 }
00277
00278 if ( RetValue == -1 )
00279 {
00280 printf( "Networks are undecided (resource limits is reached).\r" );
00281 Status = -1;
00282 }
00283 else if ( RetValue == 0 )
00284 {
00285 int * pSimInfo = Abc_NtkVerifySimulatePattern( pMiterPart, pMiterPart->pModel );
00286 if ( pSimInfo[0] != 1 )
00287 printf( "ERROR in Abc_NtkMiterProve(): Generated counter-example is invalid.\n" );
00288 else
00289 printf( "Networks are NOT EQUIVALENT. \n" );
00290 free( pSimInfo );
00291 Status = 0;
00292 break;
00293 }
00294 else
00295 {
00296 printf( "Finished part %5d (out of %5d)\r", i+1, Abc_NtkPoNum(pMiter) );
00297 nOutputs += nPartSize;
00298 }
00299
00300
00301 if ( pMiterPart )
00302 Abc_NtkDelete( pMiterPart );
00303 }
00304
00305 Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "set progressbar" );
00306
00307 if ( Status == 1 )
00308 printf( "Networks are equivalent. \n" );
00309 else if ( Status == -1 )
00310 printf( "Timed out after verifying %d outputs (out of %d).\n", nOutputs, Abc_NtkCoNum(pNtk1) );
00311 Abc_NtkDelete( pMiter );
00312 }
00313
00325 void Abc_NtkCecFraigPartAuto( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int fVerbose )
00326 {
00327 extern int Abc_NtkCombinePos( Abc_Ntk_t * pNtk, int fAnd );
00328 extern Vec_Ptr_t * Abc_NtkPartitionSmart( Abc_Ntk_t * pNtk, int nPartSizeLimit, int fVerbose );
00329 extern void Abc_NtkConvertCos( Abc_Ntk_t * pNtk, Vec_Int_t * vOuts, Vec_Ptr_t * vOnePtr );
00330 extern int Cmd_CommandExecute( void * pAbc, char * sCommand );
00331 extern void * Abc_FrameGetGlobalFrame();
00332
00333 Vec_Ptr_t * vParts, * vOnePtr;
00334 Vec_Int_t * vOne;
00335 Prove_Params_t Params, * pParams = &Params;
00336 Abc_Ntk_t * pMiter, * pMiterPart;
00337 int i, RetValue, Status, nOutputs;
00338
00339
00340 Prove_ParamsSetDefault( pParams );
00341 pParams->nItersMax = 5;
00342
00343
00344
00345 pMiter = Abc_NtkMiter( pNtk1, pNtk2, 1, 1 );
00346 if ( pMiter == NULL )
00347 {
00348 printf( "Miter computation has failed.\n" );
00349 return;
00350 }
00351 RetValue = Abc_NtkMiterIsConstant( pMiter );
00352 if ( RetValue == 0 )
00353 {
00354 printf( "Networks are NOT EQUIVALENT after structural hashing.\n" );
00355
00356 pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, 1 );
00357 Abc_NtkVerifyReportError( pNtk1, pNtk2, pMiter->pModel );
00358 FREE( pMiter->pModel );
00359 Abc_NtkDelete( pMiter );
00360 return;
00361 }
00362 if ( RetValue == 1 )
00363 {
00364 printf( "Networks are equivalent after structural hashing.\n" );
00365 Abc_NtkDelete( pMiter );
00366 return;
00367 }
00368
00369 Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "unset progressbar" );
00370
00371
00372 vParts = Abc_NtkPartitionSmart( pMiter, 300, 0 );
00373
00374
00375 Status = 1;
00376 nOutputs = 0;
00377 vOnePtr = Vec_PtrAlloc( 1000 );
00378 Vec_PtrForEachEntry( vParts, vOne, i )
00379 {
00380
00381 Abc_NtkConvertCos( pMiter, vOne, vOnePtr );
00382 pMiterPart = Abc_NtkCreateConeArray( pMiter, vOnePtr, 0 );
00383 Abc_NtkCombinePos( pMiterPart, 0 );
00384
00385 RetValue = Abc_NtkMiterIsConstant( pMiterPart );
00386 if ( RetValue == 0 )
00387 {
00388 printf( "Networks are NOT EQUIVALENT after partitioning.\n" );
00389 Abc_NtkDelete( pMiterPart );
00390 break;
00391 }
00392 if ( RetValue == 1 )
00393 {
00394 Abc_NtkDelete( pMiterPart );
00395 continue;
00396 }
00397 printf( "Verifying part %4d (out of %4d) PI = %5d. PO = %5d. And = %6d. Lev = %4d.\r",
00398 i+1, Vec_PtrSize(vParts), Abc_NtkPiNum(pMiterPart), Abc_NtkPoNum(pMiterPart),
00399 Abc_NtkNodeNum(pMiterPart), Abc_AigLevel(pMiterPart) );
00400
00401 RetValue = Abc_NtkIvyProve( &pMiterPart, pParams );
00402 if ( RetValue == -1 )
00403 {
00404 printf( "Networks are undecided (resource limits is reached).\r" );
00405 Status = -1;
00406 }
00407 else if ( RetValue == 0 )
00408 {
00409 int * pSimInfo = Abc_NtkVerifySimulatePattern( pMiterPart, pMiterPart->pModel );
00410 if ( pSimInfo[0] != 1 )
00411 printf( "ERROR in Abc_NtkMiterProve(): Generated counter-example is invalid.\n" );
00412 else
00413 printf( "Networks are NOT EQUIVALENT. \n" );
00414 free( pSimInfo );
00415 Status = 0;
00416 Abc_NtkDelete( pMiterPart );
00417 break;
00418 }
00419 else
00420 {
00421
00422 nOutputs += Vec_IntSize(vOne);
00423 }
00424 Abc_NtkDelete( pMiterPart );
00425 }
00426 printf( " \r" );
00427 Vec_VecFree( (Vec_Vec_t *)vParts );
00428 Vec_PtrFree( vOnePtr );
00429
00430 Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "set progressbar" );
00431
00432 if ( Status == 1 )
00433 printf( "Networks are equivalent. \n" );
00434 else if ( Status == -1 )
00435 printf( "Timed out after verifying %d outputs (out of %d).\n", nOutputs, Abc_NtkCoNum(pNtk1) );
00436 Abc_NtkDelete( pMiter );
00437 }
00438
00450 void Abc_NtkSecSat( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConfLimit, int nInsLimit, int nFrames )
00451 {
00452 extern Abc_Ntk_t * Abc_NtkMulti( Abc_Ntk_t * pNtk, int nThresh, int nFaninMax, int fCnf, int fMulti, int fSimple, int fFactor );
00453 Abc_Ntk_t * pMiter;
00454 Abc_Ntk_t * pFrames;
00455 Abc_Ntk_t * pCnf;
00456 int RetValue;
00457
00458
00459 pMiter = Abc_NtkMiter( pNtk1, pNtk2, 0, 0 );
00460 if ( pMiter == NULL )
00461 {
00462 printf( "Miter computation has failed.\n" );
00463 return;
00464 }
00465 RetValue = Abc_NtkMiterIsConstant( pMiter );
00466 if ( RetValue == 0 )
00467 {
00468 Abc_NtkDelete( pMiter );
00469 printf( "Networks are NOT EQUIVALENT after structural hashing.\n" );
00470 return;
00471 }
00472 if ( RetValue == 1 )
00473 {
00474 Abc_NtkDelete( pMiter );
00475 printf( "Networks are equivalent after structural hashing.\n" );
00476 return;
00477 }
00478
00479
00480 pFrames = Abc_NtkFrames( pMiter, nFrames, 1 );
00481 Abc_NtkDelete( pMiter );
00482 if ( pFrames == NULL )
00483 {
00484 printf( "Frames computation has failed.\n" );
00485 return;
00486 }
00487 RetValue = Abc_NtkMiterIsConstant( pFrames );
00488 if ( RetValue == 0 )
00489 {
00490 Abc_NtkDelete( pFrames );
00491 printf( "Networks are NOT EQUIVALENT after framing.\n" );
00492 return;
00493 }
00494 if ( RetValue == 1 )
00495 {
00496 Abc_NtkDelete( pFrames );
00497 printf( "Networks are equivalent after framing.\n" );
00498 return;
00499 }
00500
00501
00502 pCnf = Abc_NtkMulti( pFrames, 0, 100, 1, 0, 0, 0 );
00503 Abc_NtkDelete( pFrames );
00504 if ( pCnf == NULL )
00505 {
00506 printf( "Renoding for CNF has failed.\n" );
00507 return;
00508 }
00509
00510
00511 RetValue = Abc_NtkMiterSat( pCnf, (sint64)nConfLimit, (sint64)nInsLimit, 0, NULL, NULL );
00512 if ( RetValue == -1 )
00513 printf( "Networks are undecided (SAT solver timed out).\n" );
00514 else if ( RetValue == 0 )
00515 printf( "Networks are NOT EQUIVALENT after SAT.\n" );
00516 else
00517 printf( "Networks are equivalent after SAT.\n" );
00518 Abc_NtkDelete( pCnf );
00519 }
00520
00532 int Abc_NtkSecFraig( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int nFrames, int fVerbose )
00533 {
00534 Fraig_Params_t Params;
00535 Fraig_Man_t * pMan;
00536 Abc_Ntk_t * pMiter;
00537 Abc_Ntk_t * pFrames;
00538 int RetValue;
00539
00540
00541 pMiter = Abc_NtkMiter( pNtk1, pNtk2, 0, 0 );
00542 if ( pMiter == NULL )
00543 {
00544 printf( "Miter computation has failed.\n" );
00545 return 0;
00546 }
00547 RetValue = Abc_NtkMiterIsConstant( pMiter );
00548 if ( RetValue == 0 )
00549 {
00550 printf( "Networks are NOT EQUIVALENT after structural hashing.\n" );
00551
00552 pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, nFrames );
00553 Abc_NtkVerifyReportErrorSeq( pNtk1, pNtk2, pMiter->pModel, nFrames );
00554 FREE( pMiter->pModel );
00555 Abc_NtkDelete( pMiter );
00556 return 0;
00557 }
00558 if ( RetValue == 1 )
00559 {
00560 Abc_NtkDelete( pMiter );
00561 printf( "Networks are equivalent after structural hashing.\n" );
00562 return 1;
00563 }
00564
00565
00566 pFrames = Abc_NtkFrames( pMiter, nFrames, 1 );
00567 Abc_NtkDelete( pMiter );
00568 if ( pFrames == NULL )
00569 {
00570 printf( "Frames computation has failed.\n" );
00571 return 0;
00572 }
00573 RetValue = Abc_NtkMiterIsConstant( pFrames );
00574 if ( RetValue == 0 )
00575 {
00576 printf( "Networks are NOT EQUIVALENT after framing.\n" );
00577
00578 pFrames->pModel = Abc_NtkVerifyGetCleanModel( pFrames, 1 );
00579
00580 FREE( pFrames->pModel );
00581 Abc_NtkDelete( pFrames );
00582 return 0;
00583 }
00584 if ( RetValue == 1 )
00585 {
00586 Abc_NtkDelete( pFrames );
00587 printf( "Networks are equivalent after framing.\n" );
00588 return 1;
00589 }
00590
00591
00592 Fraig_ParamsSetDefault( &Params );
00593 Params.fVerbose = fVerbose;
00594 Params.nSeconds = nSeconds;
00595
00596
00597
00598 pMan = Abc_NtkToFraig( pFrames, &Params, 0, 0 );
00599 Fraig_ManProveMiter( pMan );
00600
00601
00602 RetValue = Fraig_ManCheckMiter( pMan );
00603
00604 if ( RetValue == -1 )
00605 printf( "Networks are undecided (SAT solver timed out on the final miter).\n" );
00606 else if ( RetValue == 1 )
00607 printf( "Networks are equivalent after fraiging.\n" );
00608 else if ( RetValue == 0 )
00609 {
00610 printf( "Networks are NOT EQUIVALENT after fraiging.\n" );
00611
00612 }
00613 else assert( 0 );
00614
00615 Fraig_ManFree( pMan );
00616
00617 Abc_NtkDelete( pFrames );
00618 return RetValue == 1;
00619 }
00620
00632 int * Abc_NtkVerifyGetCleanModel( Abc_Ntk_t * pNtk, int nFrames )
00633 {
00634 int * pModel = ALLOC( int, Abc_NtkCiNum(pNtk) * nFrames );
00635 memset( pModel, 0, sizeof(int) * Abc_NtkCiNum(pNtk) * nFrames );
00636 return pModel;
00637 }
00638
00650 int * Abc_NtkVerifySimulatePattern( Abc_Ntk_t * pNtk, int * pModel )
00651 {
00652 Abc_Obj_t * pNode;
00653 int * pValues, Value0, Value1, i;
00654 int fStrashed = 0;
00655 if ( !Abc_NtkIsStrash(pNtk) )
00656 {
00657 pNtk = Abc_NtkStrash(pNtk, 0, 0, 0);
00658 fStrashed = 1;
00659 }
00660
00661
00662
00663
00664
00665
00666
00667 Abc_NtkIncrementTravId( pNtk );
00668
00669 Abc_AigConst1(pNtk)->pCopy = (void *)1;
00670 Abc_NtkForEachCi( pNtk, pNode, i )
00671 pNode->pCopy = (void *)pModel[i];
00672
00673 Abc_NtkForEachNode( pNtk, pNode, i )
00674 {
00675 Value0 = ((int)Abc_ObjFanin0(pNode)->pCopy) ^ Abc_ObjFaninC0(pNode);
00676 Value1 = ((int)Abc_ObjFanin1(pNode)->pCopy) ^ Abc_ObjFaninC1(pNode);
00677 pNode->pCopy = (void *)(Value0 & Value1);
00678 }
00679
00680 pValues = ALLOC( int, Abc_NtkCoNum(pNtk) );
00681 Abc_NtkForEachCo( pNtk, pNode, i )
00682 pValues[i] = ((int)Abc_ObjFanin0(pNode)->pCopy) ^ Abc_ObjFaninC0(pNode);
00683 if ( fStrashed )
00684 Abc_NtkDelete( pNtk );
00685 return pValues;
00686 }
00687
00688
00700 void Abc_NtkVerifyReportError( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int * pModel )
00701 {
00702 Vec_Ptr_t * vNodes;
00703 Abc_Obj_t * pNode;
00704 int * pValues1, * pValues2;
00705 int nErrors, nPrinted, i, iNode = -1;
00706
00707 assert( Abc_NtkCiNum(pNtk1) == Abc_NtkCiNum(pNtk2) );
00708 assert( Abc_NtkCoNum(pNtk1) == Abc_NtkCoNum(pNtk2) );
00709
00710 pValues1 = Abc_NtkVerifySimulatePattern( pNtk1, pModel );
00711 pValues2 = Abc_NtkVerifySimulatePattern( pNtk2, pModel );
00712
00713 nErrors = 0;
00714 for ( i = 0; i < Abc_NtkCoNum(pNtk1); i++ )
00715 nErrors += (int)( pValues1[i] != pValues2[i] );
00716 printf( "Verification failed for at least %d outputs: ", nErrors );
00717
00718 nPrinted = 0;
00719 for ( i = 0; i < Abc_NtkCoNum(pNtk1); i++ )
00720 if ( pValues1[i] != pValues2[i] )
00721 {
00722 if ( iNode == -1 )
00723 iNode = i;
00724 printf( " %s", Abc_ObjName(Abc_NtkCo(pNtk1,i)) );
00725 if ( ++nPrinted == 3 )
00726 break;
00727 }
00728 if ( nPrinted != nErrors )
00729 printf( " ..." );
00730 printf( "\n" );
00731
00732 if ( iNode >= 0 )
00733 {
00734 printf( "Output %s: Value in Network1 = %d. Value in Network2 = %d.\n",
00735 Abc_ObjName(Abc_NtkCo(pNtk1,iNode)), pValues1[iNode], pValues2[iNode] );
00736 printf( "Input pattern: " );
00737
00738 pNode = Abc_NtkCo(pNtk1,iNode);
00739 vNodes = Abc_NtkNodeSupport( pNtk1, &pNode, 1 );
00740
00741 Abc_NtkForEachCi( pNtk1, pNode, i )
00742 pNode->pCopy = (void*)i;
00743
00744 pNode = Vec_PtrEntry( vNodes, 0 );
00745 if ( Abc_ObjIsCi(pNode) )
00746 {
00747 Vec_PtrForEachEntry( vNodes, pNode, i )
00748 {
00749 assert( Abc_ObjIsCi(pNode) );
00750 printf( " %s=%d", Abc_ObjName(pNode), pModel[(int)pNode->pCopy] );
00751 }
00752 }
00753 printf( "\n" );
00754 Vec_PtrFree( vNodes );
00755 }
00756 free( pValues1 );
00757 free( pValues2 );
00758 }
00759
00760
00772 void Abc_NtkGetSeqPoSupp( Abc_Ntk_t * pNtk, int iFrame, int iNumPo )
00773 {
00774 Abc_Ntk_t * pFrames;
00775 Abc_Obj_t * pObj, * pNodePo;
00776 Vec_Ptr_t * vSupp;
00777 int i, k;
00778
00779 pFrames = Abc_NtkFrames( pNtk, iFrame + 1, 0 );
00780
00781
00782
00783 pNodePo = Abc_NtkPo( pFrames, iFrame * Abc_NtkPoNum(pNtk) + iNumPo );
00784
00785 vSupp = Abc_NtkNodeSupport( pFrames, &pNodePo, 1 );
00786
00787 Abc_NtkForEachCi( pFrames, pObj, i )
00788 pObj->pCopy = NULL;
00789 Vec_PtrForEachEntry( vSupp, pObj, i )
00790 pObj->pCopy = (void *)1;
00791
00792 Abc_NtkForEachCi( pNtk, pObj, i )
00793 pObj->pCopy = NULL;
00794 Abc_NtkForEachLatch( pNtk, pObj, i )
00795 if ( Abc_NtkBox(pFrames, i)->pCopy )
00796 pObj->pCopy = (void *)1;
00797 Abc_NtkForEachPi( pNtk, pObj, i )
00798 for ( k = 0; k <= iFrame; k++ )
00799 if ( Abc_NtkPi(pFrames, k*Abc_NtkPiNum(pNtk) + i)->pCopy )
00800 pObj->pCopy = (void *)1;
00801
00802 Vec_PtrFree( vSupp );
00803 Abc_NtkDelete( pFrames );
00804 }
00805
00817 void Abc_NtkVerifyReportErrorSeq( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int * pModel, int nFrames )
00818 {
00819 Vec_Ptr_t * vInfo1, * vInfo2;
00820 Abc_Obj_t * pObj, * pObjError, * pObj1, * pObj2;
00821 int ValueError1, ValueError2;
00822 unsigned * pPats1, * pPats2;
00823 int i, o, k, nErrors, iFrameError, iNodePo, nPrinted;
00824 int fRemove1 = 0, fRemove2 = 0;
00825
00826 if ( !Abc_NtkIsStrash(pNtk1) )
00827 fRemove1 = 1, pNtk1 = Abc_NtkStrash( pNtk1, 0, 0, 0 );
00828 if ( !Abc_NtkIsStrash(pNtk2) )
00829 fRemove2 = 1, pNtk2 = Abc_NtkStrash( pNtk2, 0, 0, 0 );
00830
00831
00832 vInfo1 = Sim_SimulateSeqModel( pNtk1, nFrames, pModel );
00833 vInfo2 = Sim_SimulateSeqModel( pNtk2, nFrames, pModel );
00834
00835
00836 nErrors = 0;
00837 pObjError = NULL;
00838 for ( i = 0; i < nFrames; i++ )
00839 {
00840 if ( pObjError )
00841 break;
00842 Abc_NtkForEachPo( pNtk1, pObj1, o )
00843 {
00844 pObj2 = Abc_NtkPo( pNtk2, o );
00845 pPats1 = Sim_SimInfoGet(vInfo1, pObj1);
00846 pPats2 = Sim_SimInfoGet(vInfo2, pObj2);
00847 if ( pPats1[i] == pPats2[i] )
00848 continue;
00849 nErrors++;
00850 if ( pObjError == NULL )
00851 {
00852 pObjError = pObj1;
00853 iFrameError = i;
00854 iNodePo = o;
00855 ValueError1 = (pPats1[i] > 0);
00856 ValueError2 = (pPats2[i] > 0);
00857 }
00858 }
00859 }
00860
00861 if ( pObjError == NULL )
00862 {
00863 printf( "No output mismatches detected.\n" );
00864 Sim_UtilInfoFree( vInfo1 );
00865 Sim_UtilInfoFree( vInfo2 );
00866 if ( fRemove1 ) Abc_NtkDelete( pNtk1 );
00867 if ( fRemove2 ) Abc_NtkDelete( pNtk2 );
00868 return;
00869 }
00870
00871 printf( "Verification failed for at least %d output%s of frame %d: ", nErrors, (nErrors>1? "s":""), iFrameError+1 );
00872
00873 nPrinted = 0;
00874 Abc_NtkForEachPo( pNtk1, pObj1, o )
00875 {
00876 pObj2 = Abc_NtkPo( pNtk2, o );
00877 pPats1 = Sim_SimInfoGet(vInfo1, pObj1);
00878 pPats2 = Sim_SimInfoGet(vInfo2, pObj2);
00879 if ( pPats1[iFrameError] == pPats2[iFrameError] )
00880 continue;
00881 printf( " %s", Abc_ObjName(pObj1) );
00882 if ( ++nPrinted == 3 )
00883 break;
00884 }
00885 if ( nPrinted != nErrors )
00886 printf( " ..." );
00887 printf( "\n" );
00888
00889
00890 Abc_NtkGetSeqPoSupp( pNtk1, iFrameError, iNodePo );
00891 Abc_NtkGetSeqPoSupp( pNtk2, iFrameError, iNodePo );
00892
00893
00894 printf( "Output %s: Value in Network1 = %d. Value in Network2 = %d.\n",
00895 Abc_ObjName(pObjError), ValueError1, ValueError2 );
00896
00897 printf( "The cone of influence of output %s in Network1:\n", Abc_ObjName(pObjError) );
00898 printf( "PIs: " );
00899 Abc_NtkForEachPi( pNtk1, pObj, i )
00900 if ( pObj->pCopy )
00901 printf( "%s ", Abc_ObjName(pObj) );
00902 printf( "\n" );
00903 printf( "Latches: " );
00904 Abc_NtkForEachLatch( pNtk1, pObj, i )
00905 if ( pObj->pCopy )
00906 printf( "%s ", Abc_ObjName(pObj) );
00907 printf( "\n" );
00908
00909 printf( "The cone of influence of output %s in Network2:\n", Abc_ObjName(pObjError) );
00910 printf( "PIs: " );
00911 Abc_NtkForEachPi( pNtk2, pObj, i )
00912 if ( pObj->pCopy )
00913 printf( "%s ", Abc_ObjName(pObj) );
00914 printf( "\n" );
00915 printf( "Latches: " );
00916 Abc_NtkForEachLatch( pNtk2, pObj, i )
00917 if ( pObj->pCopy )
00918 printf( "%s ", Abc_ObjName(pObj) );
00919 printf( "\n" );
00920
00921
00922 for ( i = 0; i <= iFrameError; i++ )
00923 {
00924 printf( "Frame %d: ", i+1 );
00925
00926 printf( "PI(1):" );
00927 Abc_NtkForEachPi( pNtk1, pObj, k )
00928 if ( pObj->pCopy )
00929 printf( "%d", Sim_SimInfoGet(vInfo1, pObj)[i] > 0 );
00930 printf( " " );
00931 printf( "L(1):" );
00932 Abc_NtkForEachLatch( pNtk1, pObj, k )
00933 if ( pObj->pCopy )
00934 printf( "%d", Sim_SimInfoGet(vInfo1, pObj)[i] > 0 );
00935 printf( " " );
00936 printf( "%s(1):", Abc_ObjName(pObjError) );
00937 printf( "%d", Sim_SimInfoGet(vInfo1, pObjError)[i] > 0 );
00938
00939 printf( " " );
00940
00941 printf( "PI(2):" );
00942 Abc_NtkForEachPi( pNtk2, pObj, k )
00943 if ( pObj->pCopy )
00944 printf( "%d", Sim_SimInfoGet(vInfo2, pObj)[i] > 0 );
00945 printf( " " );
00946 printf( "L(2):" );
00947 Abc_NtkForEachLatch( pNtk2, pObj, k )
00948 if ( pObj->pCopy )
00949 printf( "%d", Sim_SimInfoGet(vInfo2, pObj)[i] > 0 );
00950 printf( " " );
00951 printf( "%s(2):", Abc_ObjName(pObjError) );
00952 printf( "%d", Sim_SimInfoGet(vInfo2, pObjError)[i] > 0 );
00953
00954 printf( "\n" );
00955 }
00956 Abc_NtkForEachCi( pNtk1, pObj, i )
00957 pObj->pCopy = NULL;
00958 Abc_NtkForEachCi( pNtk2, pObj, i )
00959 pObj->pCopy = NULL;
00960
00961 Sim_UtilInfoFree( vInfo1 );
00962 Sim_UtilInfoFree( vInfo2 );
00963 if ( fRemove1 ) Abc_NtkDelete( pNtk1 );
00964 if ( fRemove2 ) Abc_NtkDelete( pNtk2 );
00965 }
00966
00978 void Abc_NtkSimulteBuggyMiter( Abc_Ntk_t * pNtk )
00979 {
00980 Abc_Obj_t * pObj;
00981 int i;
00982 int * pModel1, * pModel2, * pResult1, * pResult2;
00983 char * vPiValues1 = "01001011100000000011010110101000000";
00984 char * vPiValues2 = "11001101011101011111110100100010001";
00985
00986 assert( strlen(vPiValues1) == (unsigned)Abc_NtkPiNum(pNtk) );
00987 assert( 1 == Abc_NtkPoNum(pNtk) );
00988
00989 pModel1 = ALLOC( int, Abc_NtkCiNum(pNtk) );
00990 Abc_NtkForEachPi( pNtk, pObj, i )
00991 pModel1[i] = vPiValues1[i] - '0';
00992 Abc_NtkForEachLatch( pNtk, pObj, i )
00993 pModel1[Abc_NtkPiNum(pNtk)+i] = ((int)pObj->pData) - 1;
00994
00995 pResult1 = Abc_NtkVerifySimulatePattern( pNtk, pModel1 );
00996 printf( "Value = %d\n", pResult1[0] );
00997
00998 pModel2 = ALLOC( int, Abc_NtkCiNum(pNtk) );
00999 Abc_NtkForEachPi( pNtk, pObj, i )
01000 pModel2[i] = vPiValues2[i] - '0';
01001 Abc_NtkForEachLatch( pNtk, pObj, i )
01002 pModel2[Abc_NtkPiNum(pNtk)+i] = pResult1[Abc_NtkPoNum(pNtk)+i];
01003
01004 pResult2 = Abc_NtkVerifySimulatePattern( pNtk, pModel2 );
01005 printf( "Value = %d\n", pResult2[0] );
01006
01007 free( pModel1 );
01008 free( pModel2 );
01009 free( pResult1 );
01010 free( pResult2 );
01011 }
01012
01013
01017
01018