/**Function************************************************************* Synopsis [Replaces a fanin of the node.] Description [The node is pObj. An old fanin of this node (pFaninOld) has to be replaced by a new fanin (pFaninNew). Assumes that the node and the old fanin are not complemented. The new fanin can be complemented. In this case, the polarity of the new fanin will change, compared to the polarity of the old fanin.] SideEffects [] SeeAlso [] ***********************************************************************/ void Abc_ObjPatchFanin( Abc_Obj_t * pObj, Abc_Obj_t * pFaninOld, Abc_Obj_t * pFaninNew ) { Abc_Obj_t * pFaninNewR = Abc_ObjRegular(pFaninNew); int iFanin;//, nLats;//, fCompl; assert( !Abc_ObjIsComplement(pObj) ); assert( !Abc_ObjIsComplement(pFaninOld) ); assert( pFaninOld != pFaninNewR ); // assert( pObj != pFaninOld ); // assert( pObj != pFaninNewR ); assert( pObj->pNtk == pFaninOld->pNtk ); assert( pObj->pNtk == pFaninNewR->pNtk ); if ( (iFanin = Vec_IntFind( &pObj->vFanins, pFaninOld->Id )) == -1 ) { printf( "Node %s is not among", Abc_ObjName(pFaninOld) ); printf( " the fanins of node %s...\n", Abc_ObjName(pObj) ); return; } // remember the attributes of the old fanin // fCompl = Abc_ObjFaninC(pObj, iFanin); // replace the old fanin entry by the new fanin entry (removes attributes) Vec_IntWriteEntry( &pObj->vFanins, iFanin, pFaninNewR->Id ); // set the attributes of the new fanin // if ( fCompl ^ Abc_ObjIsComplement(pFaninNew) ) // Abc_ObjSetFaninC( pObj, iFanin ); if ( Abc_ObjIsComplement(pFaninNew) ) Abc_ObjXorFaninC( pObj, iFanin ); // if ( Abc_NtkIsSeq(pObj->pNtk) && (nLats = Seq_ObjFaninL(pObj, iFanin)) ) // Seq_ObjSetFaninL( pObj, iFanin, nLats ); // update the fanout of the fanin if ( !Vec_IntRemove( &pFaninOld->vFanouts, pObj->Id ) ) { printf( "Node %s is not among", Abc_ObjName(pObj) ); printf( " the fanouts of its old fanin %s...\n", Abc_ObjName(pFaninOld) ); // return; } Vec_IntPushMem( pObj->pNtk->pMmStep, &pFaninNewR->vFanouts, pObj->Id ); }
/**Function************************************************************* Synopsis [Solve the QBF problem EpAx[M(p,x)].] Description [The network should be a Boolean network where, the variables p go first, followed by variables x. The number of parameters is nPars. The number of iterations to try is nItersMax. The inputs to try are in vPiValues, and it will store the results if a model is found. The return value is 1 if the problem is false, 0 if the problem is true (and an assignment to p returned via vPiValeus), -1 if the iteration limit reached, and -2 if the sat solver times out. ] SideEffects [] SeeAlso [] ***********************************************************************/ int AbcBridge_NtkQbf( Abc_Ntk_t * pNtk, int nPars, int nItersMax, Vec_Int_t* vPiValues) { Abc_Ntk_t * pNtkVer, * pNtkSyn, * pNtkSyn2, * pNtkTemp; int nIters, nInputs, RetValue, fFound = 0; assert( Abc_NtkIsStrash(pNtk) ); assert( Abc_NtkIsComb(pNtk) ); assert( Abc_NtkPoNum(pNtk) == 1 ); assert( nPars > 0 && nPars < Abc_NtkPiNum(pNtk) ); // assert( Abc_NtkPiNum(pNtk)-nPars < 32 ); nInputs = Abc_NtkPiNum(pNtk) - nPars; assert(Vec_IntSize(vPiValues) == Abc_NtkPiNum(pNtk)); AbcBridge_NtkVectorClearPars( vPiValues, nPars ); pNtkSyn = Abc_NtkMiterCofactor( pNtk, vPiValues ); // iteratively solve for ( nIters = 0; nIters < nItersMax; nIters++ ) { // solve the synthesis instance // RetValue = Abc_NtkMiterSat( pNtkSyn, 0, 0, 0, NULL, NULL ); RetValue = Abc_NtkDSat( pNtkSyn, (ABC_INT64_T)0, (ABC_INT64_T)0, 0, 0, 0, 1, 0, 0, 0 ); if ( RetValue == 0 ) AbcBridge_NtkModelToVector( pNtkSyn, vPiValues ); // Formula is unsat when forall variables replaced with concrete inputs, and // thus unsat in general. if ( RetValue == 1 ) { Abc_NtkDelete(pNtkSyn); return 1; // Return UNSAT } // Synthesis timed out. if (RetValue == -1) { Abc_NtkDelete(pNtkSyn); return -2; } // there is a counter-example // construct the verification instance AbcBridge_NtkVectorClearVars( pNtk, vPiValues, nPars ); pNtkVer = Abc_NtkMiterCofactor( pNtk, vPiValues ); // complement the output Abc_ObjXorFaninC( Abc_NtkPo(pNtkVer,0), 0 ); // solve the verification instance RetValue = Abc_NtkMiterSat( pNtkVer, 0, 0, 0, NULL, NULL ); if ( RetValue == 0 ) AbcBridge_NtkModelToVector( pNtkVer, vPiValues ); Abc_NtkDelete( pNtkVer ); if ( RetValue == 1 ) { Abc_NtkDelete( pNtkSyn ); return 0; // Return sat } // If verification timed out. if ( RetValue == -1 ) { Abc_NtkDelete(pNtkSyn); return -2; } // there is a counter-example // create a new synthesis network AbcBridge_NtkVectorClearPars( vPiValues, nPars ); pNtkSyn2 = Abc_NtkMiterCofactor( pNtk, vPiValues ); // add to the synthesis instance pNtkSyn = Abc_NtkMiterAnd( pNtkTemp = pNtkSyn, pNtkSyn2, 0, 0 ); Abc_NtkDelete( pNtkSyn2 ); Abc_NtkDelete( pNtkTemp ); } Abc_NtkDelete( pNtkSyn ); // Limit reached. return -1; }
/**Function************************************************************* Synopsis [Verifies sequential equivalence by fraiging followed by SAT.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Abc_NtkCecFraigPart( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int nPartSize, int fVerbose ) { extern int Cmd_CommandExecute( void * pAbc, char * sCommand ); extern void * Abc_FrameGetGlobalFrame(); Prove_Params_t Params, * pParams = &Params; Abc_Ntk_t * pMiter, * pMiterPart; Abc_Obj_t * pObj; int i, RetValue, Status, nOutputs; // solve the CNF using the SAT solver Prove_ParamsSetDefault( pParams ); pParams->nItersMax = 5; // pParams->fVerbose = 1; assert( nPartSize > 0 ); // get the miter of the two networks pMiter = Abc_NtkMiter( pNtk1, pNtk2, 1, nPartSize ); if ( pMiter == NULL ) { printf( "Miter computation has failed.\n" ); return; } RetValue = Abc_NtkMiterIsConstant( pMiter ); if ( RetValue == 0 ) { printf( "Networks are NOT EQUIVALENT after structural hashing.\n" ); // report the error pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, 1 ); Abc_NtkVerifyReportError( pNtk1, pNtk2, pMiter->pModel ); FREE( pMiter->pModel ); Abc_NtkDelete( pMiter ); return; } if ( RetValue == 1 ) { printf( "Networks are equivalent after structural hashing.\n" ); Abc_NtkDelete( pMiter ); return; } Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "unset progressbar" ); // solve the problem iteratively for each output of the miter Status = 1; nOutputs = 0; Abc_NtkForEachPo( pMiter, pObj, i ) { if ( Abc_ObjFanin0(pObj) == Abc_AigConst1(pMiter) ) { if ( Abc_ObjFaninC0(pObj) ) // complemented -> const 0 RetValue = 1; else RetValue = 0; pMiterPart = NULL; } else { // get the cone of this output pMiterPart = Abc_NtkCreateCone( pMiter, Abc_ObjFanin0(pObj), Abc_ObjName(pObj), 0 ); if ( Abc_ObjFaninC0(pObj) ) Abc_ObjXorFaninC( Abc_NtkPo(pMiterPart,0), 0 ); // solve the cone // RetValue = Abc_NtkMiterProve( &pMiterPart, pParams ); RetValue = Abc_NtkIvyProve( &pMiterPart, pParams ); } if ( RetValue == -1 ) { printf( "Networks are undecided (resource limits is reached).\r" ); Status = -1; } else if ( RetValue == 0 ) { int * pSimInfo = Abc_NtkVerifySimulatePattern( pMiterPart, pMiterPart->pModel ); if ( pSimInfo[0] != 1 ) printf( "ERROR in Abc_NtkMiterProve(): Generated counter-example is invalid.\n" ); else printf( "Networks are NOT EQUIVALENT. \n" ); free( pSimInfo ); Status = 0; break; } else { printf( "Finished part %d (out of %d)\r", i+1, Abc_NtkPoNum(pMiter) ); nOutputs += nPartSize; } // if ( pMiter->pModel ) // Abc_NtkVerifyReportError( pNtk1, pNtk2, pMiter->pModel ); if ( pMiterPart ) Abc_NtkDelete( pMiterPart ); } Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "set progressbar" ); if ( Status == 1 ) printf( "Networks are equivalent. \n" ); else if ( Status == -1 ) printf( "Timed out after verifying %d outputs (out of %d).\n", nOutputs, Abc_NtkCoNum(pNtk1) ); Abc_NtkDelete( pMiter ); }