/**Function************************************************************* Synopsis [Starts the process of returning values for internal nodes.] Description [Should be called when pCex is available, before probing any object for its value using Gia_ManCounterExampleValueLookup().] SideEffects [] SeeAlso [] ***********************************************************************/ void Gia_ManCounterExampleValueStart( Gia_Man_t * pGia, Abc_Cex_t * pCex ) { Gia_Obj_t * pObj, * pObjRi, * pObjRo; int Val0, Val1, nObjs, i, k, iBit = 0; assert( Gia_ManRegNum(pGia) > 0 ); // makes sense only for sequential AIGs assert( pGia->pData2 == NULL ); // if this fail, there may be a memory leak // allocate memory to store simulation bits for internal nodes pGia->pData2 = ABC_CALLOC( unsigned, Abc_BitWordNum( (pCex->iFrame + 1) * Gia_ManObjNum(pGia) ) ); // the register values in the counter-example should be zero Gia_ManForEachRo( pGia, pObj, k ) assert( Abc_InfoHasBit(pCex->pData, iBit++) == 0 ); // iterate through the timeframes nObjs = Gia_ManObjNum(pGia); for ( i = 0; i <= pCex->iFrame; i++ ) { // no need to set constant-0 node // set primary inputs according to the counter-example Gia_ManForEachPi( pGia, pObj, k ) if ( Abc_InfoHasBit(pCex->pData, iBit++) ) Abc_InfoSetBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjId(pGia, pObj) ); // compute values for each node Gia_ManForEachAnd( pGia, pObj, k ) { Val0 = Abc_InfoHasBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjFaninId0p(pGia, pObj) ); Val1 = Abc_InfoHasBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjFaninId1p(pGia, pObj) ); if ( (Val0 ^ Gia_ObjFaninC0(pObj)) & (Val1 ^ Gia_ObjFaninC1(pObj)) ) Abc_InfoSetBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjId(pGia, pObj) ); } // derive values for combinational outputs Gia_ManForEachCo( pGia, pObj, k ) { Val0 = Abc_InfoHasBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjFaninId0p(pGia, pObj) ); if ( Val0 ^ Gia_ObjFaninC0(pObj) ) Abc_InfoSetBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjId(pGia, pObj) ); }
/**Function************************************************************* Synopsis [Prints stats for the AIG.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Gia_ManPrintPlacement( Gia_Man_t * p ) { int i, nFixed = 0, nUndef = 0; if ( p->pPlacement == NULL ) return; for ( i = 0; i < Gia_ManObjNum(p); i++ ) { nFixed += p->pPlacement[i].fFixed; nUndef += p->pPlacement[i].fUndef; } printf( "Placement: Objects = %8d. Fixed = %8d. Undef = %8d.\n", Gia_ManObjNum(p), nFixed, nUndef ); }
/**Function************************************************************* Synopsis [Transforms edge assignment.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Gia_ManEdgeFromArray( Gia_Man_t * p, Vec_Int_t * vArray ) { int i, iObj1, iObj2, Count = 0; Vec_IntFreeP( &p->vEdge1 ); Vec_IntFreeP( &p->vEdge2 ); p->vEdge1 = Vec_IntStart( Gia_ManObjNum(p) ); p->vEdge2 = Vec_IntStart( Gia_ManObjNum(p) ); Vec_IntForEachEntryDouble( vArray, iObj1, iObj2, i ) { assert( iObj1 < iObj2 ); Count += Gia_ObjEdgeAdd( iObj1, iObj2, p->vEdge1, p->vEdge2 ); Count += Gia_ObjEdgeAdd( iObj2, iObj1, p->vEdge1, p->vEdge2 ); }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Gia_ManFaultUnfold( Gia_Man_t * p, int fUseMuxes ) { Gia_Man_t * pNew, * pTemp; Gia_Obj_t * pObj; int i, iCtrl, iThis; pNew = Gia_ManStart( (2 + 3 * fUseMuxes) * Gia_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); Gia_ManHashAlloc( pNew ); Gia_ManConst0(p)->Value = 0; // add first timeframe Gia_ManForEachRo( p, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); Gia_ManForEachPi( p, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); Gia_ManForEachAnd( p, pObj, i ) pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachCo( p, pObj, i ) pObj->Value = Gia_ObjFanin0Copy(pObj); // add second timeframe Gia_ManForEachRo( p, pObj, i ) pObj->Value = Gia_ObjRoToRi(p, pObj)->Value; Gia_ManForEachPi( p, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); Gia_ManForEachAnd( p, pObj, i ) { iCtrl = Gia_ManAppendCi(pNew); iThis = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); if ( fUseMuxes ) pObj->Value = Gia_ManHashMux( pNew, iCtrl, pObj->Value, iThis ); else pObj->Value = iThis; }
Gia_Man_t * Gia_ManFromAigChoices( Aig_Man_t * p ) { Gia_Man_t * pNew; Aig_Obj_t * pObj; int i; assert( p->pEquivs != NULL ); // create the new manager pNew = Gia_ManStart( Aig_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); pNew->nConstrs = p->nConstrs; // create room to store equivalences pNew->pSibls = ABC_CALLOC( int, Aig_ManObjNum(p) ); // create the PIs Aig_ManCleanData( p ); Aig_ManConst1(p)->iData = 1; Aig_ManForEachCi( p, pObj, i ) pObj->iData = Gia_ManAppendCi( pNew ); // add logic for the POs Aig_ManForEachCo( p, pObj, i ) Gia_ManFromAigChoices_rec( pNew, p, Aig_ObjFanin0(pObj) ); Aig_ManForEachCo( p, pObj, i ) Gia_ManAppendCo( pNew, Gia_ObjChild0Copy(pObj) ); Gia_ManSetRegNum( pNew, Aig_ManRegNum(p) ); assert( Gia_ManObjNum(pNew) == Aig_ManObjNum(p) ); return pNew; }
/**Function************************************************************* Synopsis [Performs targe enlargement of the given size.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Bmc_CexTargetEnlarge( Gia_Man_t * p, int nFrames ) { Gia_Man_t * pNew, * pOne; Gia_Obj_t * pObj, * pObjRo; int i, k; pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); Gia_ManHashAlloc( pNew ); Gia_ManConst0(p)->Value = 0; for ( k = 0; k < nFrames; k++ ) Gia_ManForEachPi( p, pObj, i ) Gia_ManAppendCi( pNew ); Gia_ManForEachRo( p, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); for ( k = 0; k < nFrames; k++ ) { Gia_ManForEachPi( p, pObj, i ) pObj->Value = Gia_ManCiLit( pNew, (nFrames - 1 - k) * Gia_ManPiNum(p) + i ); Gia_ManForEachAnd( p, pObj, i ) pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachRi( p, pObj, i ) pObj->Value = Gia_ObjFanin0Copy(pObj); Gia_ManForEachRiRo( p, pObj, pObjRo, i ) pObjRo->Value = pObj->Value; } pObj = Gia_ManPo( p, 0 ); pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManHashStop( pNew ); pNew = Gia_ManCleanup( pOne = pNew ); Gia_ManStop( pOne ); return pNew; }
/**Function************************************************************* Synopsis [Duplicates AIG according to the timing manager.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Gia_ManDupUnnormalize( Gia_Man_t * p ) { Vec_Int_t * vNodes; Gia_Man_t * pNew; Gia_Obj_t * pObj; int i; vNodes = Gia_ManOrderWithBoxes( p ); if ( vNodes == NULL ) return NULL; Gia_ManFillValue( p ); pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); if ( p->pSibls ) pNew->pSibls = ABC_CALLOC( int, Gia_ManObjNum(p) ); Gia_ManForEachObjVec( vNodes, p, pObj, i ) { if ( Gia_ObjIsAnd(pObj) ) { pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); if ( Gia_ObjSibl(p, Gia_ObjId(p, pObj)) ) pNew->pSibls[Abc_Lit2Var(pObj->Value)] = Abc_Lit2Var(Gia_ObjSiblObj(p, Gia_ObjId(p, pObj))->Value); } else if ( Gia_ObjIsCi(pObj) ) pObj->Value = Gia_ManAppendCi( pNew ); else if ( Gia_ObjIsCo(pObj) ) pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); else if ( Gia_ObjIsConst0(pObj) ) pObj->Value = 0; else assert( 0 ); } Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) ); Vec_IntFree( vNodes ); return pNew; }
void Gia_ManPrintTents( Gia_Man_t * p ) { Vec_Int_t * vObjs; Gia_Obj_t * pObj; int t, i, iObjId, nSizePrev, nSizeCurr; assert( Gia_ManPoNum(p) > 0 ); vObjs = Vec_IntAlloc( 100 ); // save constant class Gia_ManIncrementTravId( p ); Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) ); Vec_IntPush( vObjs, 0 ); // create starting root nSizePrev = Vec_IntSize(vObjs); Gia_ManForEachPo( p, pObj, i ) Gia_ManPrintTents_rec( p, pObj, vObjs ); // build tents printf( "Tents: " ); for ( t = 1; nSizePrev < Vec_IntSize(vObjs); t++ ) { nSizeCurr = Vec_IntSize(vObjs); Vec_IntForEachEntryStartStop( vObjs, iObjId, i, nSizePrev, nSizeCurr ) if ( Gia_ObjIsRo(p, Gia_ManObj(p, iObjId)) ) Gia_ManPrintTents_rec( p, Gia_ObjRoToRi(p, Gia_ManObj(p, iObjId)), vObjs ); printf( "%d=%d ", t, nSizeCurr - nSizePrev ); nSizePrev = nSizeCurr; } printf( " Unused=%d\n", Gia_ManObjNum(p) - Vec_IntSize(vObjs) ); Vec_IntFree( vObjs ); // the remaining objects are PIs without fanout // Gia_ManForEachObj( p, pObj, i ) // if ( !Gia_ObjIsTravIdCurrent(p, pObj) ) // Gia_ObjPrint( p, pObj ); }
Gia_Man_t * Gia_ManDomDerive( Gia_Man_t * p, Gia_Obj_t * pRoot, Vec_Int_t * vSupp, int nVars ) { Gia_Man_t * pNew, * pTemp; int nMints = 1 << nVars; int i, m, iResLit; assert( nVars >= 0 && nVars <= 5 ); pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); Gia_ManConst0(p)->Value = 0; Gia_ManHashAlloc( pNew ); for ( i = 0; i < Vec_IntSize(vSupp); i++ ) Gia_ManAppendCi(pNew); for ( m = 0; m < nMints; m++ ) { Gia_Obj_t * pObj; Gia_ManIncrementTravId( p ); Gia_ManForEachObjVec( vSupp, p, pObj, i ) { if ( i < nVars ) pObj->Value = (m >> i) & 1; else pObj->Value = Gia_ObjToLit(pNew, Gia_ManCi(pNew, i)); Gia_ObjSetTravIdCurrent( p, pObj ); } iResLit = Gia_ManDomDerive_rec( pNew, p, pRoot ); Gia_ManAppendCo( pNew, iResLit ); }
void Gia_SweeperPrintStats( Gia_Man_t * pGia ) { Swp_Man_t * p = (Swp_Man_t *)pGia->pData; double nMemSwp = Gia_SweeperMemUsage(pGia); double nMemGia = (double)Gia_ManObjNum(pGia)*(sizeof(Gia_Obj_t) + sizeof(int)); double nMemSat = sat_solver_memory(p->pSat); double nMemTot = nMemSwp + nMemGia + nMemSat; printf( "SAT sweeper statistics:\n" ); printf( "Memory usage:\n" ); ABC_PRMP( "Sweeper ", nMemSwp, nMemTot ); ABC_PRMP( "AIG manager ", nMemGia, nMemTot ); ABC_PRMP( "SAT solver ", nMemSat, nMemTot ); ABC_PRMP( "TOTAL ", nMemTot, nMemTot ); printf( "Runtime usage:\n" ); p->timeTotal = Abc_Clock() - p->timeStart; ABC_PRTP( "CNF construction", p->timeCnf, p->timeTotal ); ABC_PRTP( "SAT solving ", p->timeSat, p->timeTotal ); ABC_PRTP( " Sat ", p->timeSatSat, p->timeTotal ); ABC_PRTP( " Unsat ", p->timeSatUnsat, p->timeTotal ); ABC_PRTP( " Undecided ", p->timeSatUndec, p->timeTotal ); ABC_PRTP( "TOTAL RUNTIME ", p->timeTotal, p->timeTotal ); printf( "GIA: " ); Gia_ManPrintStats( pGia, 0, 0, 0 ); printf( "SAT calls = %d. Sat = %d. Unsat = %d. Undecided = %d. Proofs = %d.\n", p->nSatCalls, p->nSatCallsSat, p->nSatCallsUnsat, p->nSatCallsUndec, p->nSatProofs ); Sat_SolverPrintStats( stdout, p->pSat ); }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Bal_Man_t * Bal_ManAlloc( Gia_Man_t * pGia, Gia_Man_t * pNew, int nLutSize, int nCutNum, int fVerbose ) { Bal_Man_t * p; p = ABC_CALLOC( Bal_Man_t, 1 ); p->clkStart = Abc_Clock(); p->pGia = pGia; p->pNew = pNew; p->nLutSize = nLutSize; p->nCutNum = nCutNum; p->fVerbose = fVerbose; p->vCosts = Vec_IntAlloc( 3 * Gia_ManObjNum(pGia) / 2 ); p->vCutSets = Vec_PtrAlloc( 3 * Gia_ManObjNum(pGia) / 2 ); Vec_IntFill( p->vCosts, Gia_ManObjNum(pNew), 0 ); Vec_PtrFill( p->vCutSets, Gia_ManObjNum(pNew), NULL ); pNew->pData = p; return p; }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ static inline Vec_Int_t * Gia_Iso3Save( Gia_Man_t * p ) { Vec_Int_t * vSign; Gia_Obj_t * pObj; int i; vSign = Vec_IntAlloc( Gia_ManObjNum(p) ); Gia_ManForEachObj( p, pObj, i ) Vec_IntPush( vSign, pObj->Value ); return vSign; }
/**Function************************************************************* Synopsis [Creates logic network isomorphic to the given AIG.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Cof_Man_t * Cof_ManCreateLogicSimple( Gia_Man_t * pGia ) { Cof_Man_t * p; Cof_Obj_t * pObjLog, * pFanLog; Gia_Obj_t * pObj; int * pMuxRefs; int i, iHandle = 0; p = ABC_CALLOC( Cof_Man_t, 1 ); p->pGia = pGia; p->vCis = Vec_IntAlloc( Gia_ManCiNum(pGia) ); p->vCos = Vec_IntAlloc( Gia_ManCoNum(pGia) ); p->nObjData = (sizeof(Cof_Obj_t) / 4) * Gia_ManObjNum(pGia) + 4 * Gia_ManAndNum(pGia) + 2 * Gia_ManCoNum(pGia); p->pObjData = ABC_CALLOC( int, p->nObjData ); ABC_FREE( pGia->pRefs ); Gia_ManCreateRefs( pGia ); Gia_ManForEachObj( pGia, pObj, i ) { pObj->Value = iHandle; pObjLog = Cof_ManObj( p, iHandle ); pObjLog->nFanins = 0; pObjLog->nFanouts = Gia_ObjRefNum( pGia, pObj ); pObjLog->Id = i; pObjLog->Value = 0; if ( Gia_ObjIsAnd(pObj) ) { pFanLog = Cof_ManObj( p, Gia_ObjHandle(Gia_ObjFanin0(pObj)) ); pFanLog->Fanios[pFanLog->nFanins + pFanLog->Value++].iFan = pObjLog->Fanios[pObjLog->nFanins].iFan = Cof_ObjHandleDiff( pObjLog, pFanLog ); pObjLog->Fanios[pObjLog->nFanins++].fCompl = Gia_ObjFaninC0(pObj); pFanLog = Cof_ManObj( p, Gia_ObjHandle(Gia_ObjFanin1(pObj)) ); pFanLog->Fanios[pFanLog->nFanins + pFanLog->Value++].iFan = pObjLog->Fanios[pObjLog->nFanins].iFan = Cof_ObjHandleDiff( pObjLog, pFanLog ); pObjLog->Fanios[pObjLog->nFanins++].fCompl = Gia_ObjFaninC1(pObj); p->nNodes++; } else if ( Gia_ObjIsCo(pObj) ) { pFanLog = Cof_ManObj( p, Gia_ObjHandle(Gia_ObjFanin0(pObj)) ); pFanLog->Fanios[pFanLog->nFanins + pFanLog->Value++].iFan = pObjLog->Fanios[pObjLog->nFanins].iFan = Cof_ObjHandleDiff( pObjLog, pFanLog ); pObjLog->Fanios[pObjLog->nFanins++].fCompl = Gia_ObjFaninC0(pObj); pObjLog->fTerm = 1; Vec_IntPush( p->vCos, iHandle ); } else if ( Gia_ObjIsCi(pObj) ) { pObjLog->fTerm = 1; Vec_IntPush( p->vCis, iHandle ); } iHandle += Cof_ObjSize( pObjLog ); p->nObjs++; }
word Gia_ObjComputeTruthTable6Lut( Gia_Man_t * p, int iObj, Vec_Wrd_t * vTemp ) { int i, Fanin; assert( Vec_WrdSize(vTemp) == Gia_ManObjNum(p) ); assert( Gia_ObjIsLut(p, iObj) ); Gia_LutForEachFanin( p, iObj, Fanin, i ) Vec_WrdWriteEntry( vTemp, Fanin, s_Truth6[i] ); assert( i <= 6 ); Gia_ObjComputeTruthTable6Lut_rec( p, iObj, vTemp ); return Vec_WrdEntry( vTemp, iObj ); }
/**Function************************************************************* Synopsis [Duplicates AIG in the DFS order while putting CIs first.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Gia_ManDupNormalize( Gia_Man_t * p ) { int fHashMapping = 0; Gia_Man_t * pNew; Gia_Obj_t * pObj; int i; Gia_ManFillValue( p ); pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); Gia_ManConst0(p)->Value = 0; if ( !Gia_ManIsSeqWithBoxes(p) ) { Gia_ManForEachCi( p, pObj, i ) pObj->Value = Gia_ManAppendCi(pNew); } else { // current CI order: PIs + FOs + NewCIs // desired reorder: PIs + NewCIs + FOs int nCIs = Tim_ManPiNum( (Tim_Man_t *)p->pManTime ); int nAll = Tim_ManCiNum( (Tim_Man_t *)p->pManTime ); int nPis = nCIs - Gia_ManRegNum(p); assert( nAll == Gia_ManCiNum(p) ); assert( nPis > 0 ); // copy PIs first for ( i = 0; i < nPis; i++ ) Gia_ManCi(p, i)->Value = Gia_ManAppendCi(pNew); // copy new CIs second for ( i = nCIs; i < nAll; i++ ) Gia_ManCi(p, i)->Value = Gia_ManAppendCi(pNew); // copy flops last for ( i = nCIs - Gia_ManRegNum(p); i < nCIs; i++ ) Gia_ManCi(p, i)->Value = Gia_ManAppendCi(pNew); printf( "Warning: Shuffled CI order to be correct sequential AIG.\n" ); } if ( fHashMapping ) Gia_ManHashAlloc( pNew ); Gia_ManForEachAnd( p, pObj, i ) if ( Gia_ObjIsBuf(pObj) ) pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) ); else if ( fHashMapping ) pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); else pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); if ( fHashMapping ) Gia_ManHashStop( pNew ); Gia_ManForEachCo( p, pObj, i ) pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) ); pNew->nConstrs = p->nConstrs; assert( Gia_ManIsNormalized(pNew) ); Gia_ManDupRemapEquiv( pNew, p ); return pNew; }
ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [Specialized duplication.] Description [Replaces registers by PIs/POs and PIs by registers.] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Gia_ManDupIn2Ff( Gia_Man_t * p ) { Vec_Int_t * vPiOuts; Gia_Man_t * pNew; Gia_Obj_t * pObj; int i; vPiOuts = Vec_IntAlloc( Gia_ManPiNum(p) ); pNew = Gia_ManStart( Gia_ManObjNum(p) + 2 * Gia_ManPiNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); Gia_ManFillValue( p ); Gia_ManConst0(p)->Value = 0; Gia_ManForEachPi( p, pObj, i ) Vec_IntPush( vPiOuts, Gia_ManAppendCi(pNew) ); Gia_ManForEachRo( p, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); Gia_ManForEachPi( p, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); Gia_ManForEachAnd( p, pObj, i ) pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachPo( p, pObj, i ) pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManForEachRi( p, pObj, i ) pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManForEachPi( p, pObj, i ) Gia_ManAppendCo( pNew, Vec_IntEntry(vPiOuts, i) ); Gia_ManSetRegNum( pNew, Gia_ManPiNum(p) ); Vec_IntFree( vPiOuts ); return pNew; }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Gia_ManPrintSignals( Gia_Man_t * p, int * pFreq, char * pStr ) { Vec_Int_t * vObjs; int i, Counter = 0, nTotal = 0; vObjs = Vec_IntAlloc( 100 ); for ( i = 0; i < Gia_ManObjNum(p); i++ ) if ( pFreq[i] > 1 ) { nTotal += pFreq[i]; Counter++; } printf( "%s (total = %d driven = %d)\n", pStr, Counter, nTotal ); Counter = 0; for ( i = 0; i < Gia_ManObjNum(p); i++ ) if ( pFreq[i] > 10 ) { printf( "%3d : Obj = %6d Refs = %6d Freq = %6d\n", ++Counter, i, Gia_ObjRefs(p, Gia_ManObj(p,i)), pFreq[i] ); Vec_IntPush( vObjs, i ); } Vec_IntFree( vObjs ); }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Agi_Man_t * Agi_ManFromGia( Gia_Man_t * p ) { Agi_Man_t * pNew; Gia_Obj_t * pObj; int i; pNew = Agi_ManAlloc( Gia_ManObjNum(p) ); Gia_ManForEachObj1( p, pObj, i ) if ( Gia_ObjIsAnd(pObj) ) pObj->Value = Agi_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); else if ( Gia_ObjIsCo(pObj) ) pObj->Value = Agi_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); else if ( Gia_ObjIsCi(pObj) ) pObj->Value = Agi_ManAppendCi( pNew ); else assert( 0 ); return pNew; }
ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [Duplicates AIG in the DFS order while putting CIs first.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Gia_ManDupNormalize( Gia_Man_t * p ) { Gia_Man_t * pNew; Gia_Obj_t * pObj; int i; Gia_ManFillValue( p ); pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); Gia_ManConst0(p)->Value = 0; Gia_ManForEachCi( p, pObj, i ) pObj->Value = Gia_ManAppendCi(pNew); Gia_ManForEachAnd( p, pObj, i ) pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachCo( p, pObj, i ) pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) ); pNew->nConstrs = p->nConstrs; assert( Gia_ManIsNormalized(pNew) ); Gia_ManDupRemapEquiv( pNew, p ); return pNew; }
/**Function************************************************************* Synopsis [Reorders flops for sequential AIGs with boxes.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Gia_ManDupUnshuffleInputs( Gia_Man_t * p ) { Gia_Man_t * pNew; Gia_Obj_t * pObj; int i, nCIs, nAll, nPis; // sanity checks assert( Gia_ManIsNormalized(p) ); assert( Gia_ManIsSeqWithBoxes(p) ); Gia_ManFillValue( p ); pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); Gia_ManConst0(p)->Value = 0; // change input order // desired reorder: PIs + NewCIs + FOs // current CI order: PIs + FOs + NewCIs nCIs = Tim_ManPiNum( (Tim_Man_t *)p->pManTime ); nAll = Tim_ManCiNum( (Tim_Man_t *)p->pManTime ); nPis = nCIs - Gia_ManRegNum(p); assert( nAll == Gia_ManCiNum(p) ); assert( nPis > 0 ); // copy PIs first for ( i = 0; i < nPis; i++ ) Gia_ManCi(p, i)->Value = Gia_ManAppendCi(pNew); // copy flops second for ( i = nAll - Gia_ManRegNum(p); i < nAll; i++ ) Gia_ManCi(p, i)->Value = Gia_ManAppendCi(pNew); // copy new CIs last for ( i = nPis; i < nAll - Gia_ManRegNum(p); i++ ) Gia_ManCi(p, i)->Value = Gia_ManAppendCi(pNew); printf( "Warning: Unshuffled CI order to be correct AIG with boxes.\n" ); // other things Gia_ManForEachAnd( p, pObj, i ) pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachCo( p, pObj, i ) pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) ); pNew->nConstrs = p->nConstrs; assert( Gia_ManIsNormalized(pNew) ); Gia_ManDupRemapEquiv( pNew, p ); return pNew; }
Vec_Ptr_t * Wlc_NtkSimulate( Wlc_Ntk_t * p, Vec_Int_t * vNodes, int nWords, int nFrames ) { Gia_Obj_t * pObj; Vec_Ptr_t * vOne, * vRes; Gia_Man_t * pGia = Wlc_NtkBitBlast( p, NULL, 0, 0 ); Wlc_Obj_t * pWlcObj; int f, i, k, w, nBits, Counter = 0; // allocate simulation info for one timeframe Vec_WrdFreeP( &pGia->vSims ); pGia->vSims = Vec_WrdStart( Gia_ManObjNum(pGia) * nWords ); pGia->iPatsPi = nWords; // allocate resulting simulation info vRes = Vec_PtrAlloc( Vec_IntSize(vNodes) ); Wlc_NtkForEachObjVec( vNodes, p, pWlcObj, i ) { nBits = Wlc_ObjRange(pWlcObj); vOne = Vec_PtrAlloc( nBits ); for ( k = 0; k < nBits; k++ ) Vec_PtrPush( vOne, ABC_CALLOC(word, nWords * nFrames) ); Vec_PtrPush( vRes, vOne ); }
/**Function************************************************************* Synopsis [Reverses the above step.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Gia_ManDupFf2In( Gia_Man_t * p, int nFlopsOld ) { Gia_Man_t * pNew; Gia_Obj_t * pObj; int i; pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); Gia_ManFillValue( p ); Gia_ManConst0(p)->Value = 0; Gia_ManForEachRo( p, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); for ( i = Gia_ManPiNum(p) - nFlopsOld; i < Gia_ManPiNum(p); i++ ) Gia_ManPi(p, i)->Value = Gia_ManAppendCi( pNew ); Gia_ManForEachPo( p, pObj, i ) Gia_ManDupFf2In_rec( pNew, Gia_ObjFanin0(pObj) ); Gia_ManForEachPo( p, pObj, i ) Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManSetRegNum( pNew, nFlopsOld ); return pNew; }
/**Function************************************************************* Synopsis [Duplicates the AIG while retiming the registers to the cut.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Gia_ManRetimeDupForward( Gia_Man_t * p, Vec_Ptr_t * vCut ) { Gia_Man_t * pNew, * pTemp; Gia_Obj_t * pObj, * pObjRi, * pObjRo; int i; // create the new manager pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew->pName = Gia_UtilStrsav( p->pName ); Gia_ManHashAlloc( pNew ); // create the true PIs Gia_ManFillValue( p ); Gia_ManSetPhase( p ); Gia_ManConst0(p)->Value = 0; Gia_ManForEachPi( p, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); // create the registers Vec_PtrForEachEntry( Gia_Obj_t *, vCut, pObj, i ) pObj->Value = Gia_LitNotCond( Gia_ManAppendCi(pNew), pObj->fPhase ); // duplicate logic above the cut Gia_ManForEachCo( p, pObj, i ) Gia_ManRetimeDup_rec( pNew, Gia_ObjFanin0(pObj) ); // create the true POs Gia_ManForEachPo( p, pObj, i ) Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); // remember value in LI Gia_ManForEachRi( p, pObj, i ) pObj->Value = Gia_ObjFanin0Copy(pObj); // transfer values from the LIs to the LOs Gia_ManForEachRiRo( p, pObjRi, pObjRo, i ) pObjRo->Value = pObjRi->Value; // erase the data values on the internal nodes of the cut Vec_PtrForEachEntry( Gia_Obj_t *, vCut, pObj, i ) if ( Gia_ObjIsAnd(pObj) ) pObj->Value = ~0; // duplicate logic below the cut Vec_PtrForEachEntry( Gia_Obj_t *, vCut, pObj, i ) { Gia_ManRetimeDup_rec( pNew, pObj ); Gia_ManAppendCo( pNew, Gia_LitNotCond( pObj->Value, pObj->fPhase ) ); }
static inline void Gia_ManComputeDoms( Gia_Man_t * p ) { Gia_Obj_t * pObj; int i; if ( p->vDoms == NULL ) p->vDoms = Vec_IntAlloc( 0 ); Vec_IntFill( p->vDoms, Gia_ManObjNum(p), -1 ); Gia_ManForEachObjReverse( p, pObj, i ) { if ( i == 0 || Gia_ObjIsCi(pObj) ) continue; if ( Gia_ObjIsCo(pObj) ) { Gia_ObjSetDom( p, pObj, i ); Gia_ManAddDom( p, Gia_ObjFanin0(pObj), i ); continue; } assert( Gia_ObjIsAnd(pObj) ); Gia_ManAddDom( p, Gia_ObjFanin0(pObj), i ); Gia_ManAddDom( p, Gia_ObjFanin1(pObj), i ); } }
Gia_Man_t * Gia_ManInsertWin( Gia_Man_t * p, Vec_Int_t * vOuts, Gia_Man_t * pWin ) { Vec_Int_t * vPos, * vPis, * vAnds; Gia_Man_t * pNew, * pTemp; Gia_Obj_t * pObj; int i; Gia_ManPrepareWin( p, vOuts, &vPis, &vPos, &vAnds ); // create AIG pNew = Gia_ManStart( Gia_ManObjNum(p) - Vec_IntSize(vAnds) + Gia_ManAndNum(pWin) ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); // inputs Gia_ManConst0(p)->Value = 0; Gia_ManForEachCi( p, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); Gia_ManConst0(pWin)->Value = 0; Gia_ManForEachCi( pWin, pObj, i ) pObj->Value = Gia_ManObj(p, Vec_IntEntry(vPis, i))->Value; // internal nodes Gia_ManHashAlloc( pNew ); Gia_ManForEachAnd( pWin, pObj, i ) pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachCo( pWin, pObj, i ) Gia_ManObj( p, Vec_IntEntry(vPos, i) )->Value = Gia_ObjFanin0Copy(pObj); Gia_ManForEachAnd( p, pObj, i ) if ( !Gia_ObjIsTravIdCurrentId(p, i) ) pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachCo( p, pObj, i ) Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManHashStop( pNew ); // cleanup Vec_IntFree( vPis ); Vec_IntFree( vPos ); Vec_IntFree( vAnds ); pNew = Gia_ManCleanup( pTemp = pNew ); Gia_ManStop( pTemp ); return pNew; }
Entry = Vec_IntFind( p->vMap, Entry ); assert( Entry >= 0 ); Vec_IntPush( vPpi2Map, Entry ); } // collect nodes between selected PPIs and CIs vFlops = Vec_IntAlloc( 100 ); vVisited = Vec_IntAlloc( 100 ); Gia_ManIncrementTravId( p->pGia ); Gia_ManForEachObjVec( vPPIs, p->pGia, pObj, i ) // if ( !Gia_ObjIsRo(p->pGia, pObj) ) // SKIP PPIs that are flops Rnm_ManRefineCollect_rec( p->pGia, pObj, vVisited, vFlops ); // create SAT variables and SAT solver Vec_IntFill( p->vSat2Ids, 1, -1 ); assert( p->pSat == NULL ); p->pSat = sat_solver2_new(); Vec_IntFill( p->vSatVars, Gia_ManObjNum(p->pGia), 0 ); // NO NEED TO CLEAN EACH TIME // assign PPI variables Gia_ManForEachObjVec( vFlops, p->pGia, pObj, i ) Rnm_ObjFindOrAddSatVar( p, pObj ); // assign other variables Gia_ManForEachObjVec( vVisited, p->pGia, pObj, i ) { vLeaves = Ga2_ObjLeaves( p->pGia, pObj ); Gia_ManForEachObjVec( vLeaves, p->pGia, pFanin, k ) pLits[k] = Rnm_ObjFindOrAddSatVar( p, pFanin ); vCnf0 = Ga2_ManCnfCompute( Ga2_ObjTruth(p->pGia, pObj), Vec_IntSize(vLeaves), p->vIsopMem ); vCnf1 = Ga2_ManCnfCompute( ~Ga2_ObjTruth(p->pGia, pObj), Vec_IntSize(vLeaves), p->vIsopMem ); Ga2_ManCnfAddStatic( p->pSat, vCnf0, vCnf1, pLits, Rnm_ObjFindOrAddSatVar(p, pObj), Rnm_ObjFindOrAddSatVar(p, pObj)/2 ); Vec_IntFree( vCnf0 ); Vec_IntFree( vCnf1 ); }
ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [Computes miter for ECO with given root node and fanins.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Gia_Man_t * Bmc_EcoMiter( Gia_Man_t * pGold, Gia_Man_t * pOld, Vec_Int_t * vFans ) { Gia_Man_t * pNew, * pTemp; Gia_Obj_t * pRoot = Gia_ObjFanin0( Gia_ManPo(pOld, Gia_ManPoNum(pOld)-1) ); // fanin of the last PO Gia_Obj_t * pObj; int i, NewPi, Miter; assert( Gia_ManCiNum(pGold) == Gia_ManCiNum(pOld) ); assert( Gia_ManCoNum(pGold) == Gia_ManCoNum(pOld) - 1 ); assert( Gia_ObjIsAnd(pRoot) ); // create the miter pNew = Gia_ManStart( 3 * Gia_ManObjNum(pGold) ); pNew->pName = Abc_UtilStrsav( pGold->pName ); Gia_ManHashAlloc( pNew ); // copy gold Gia_ManConst0(pGold)->Value = 0; Gia_ManForEachCi( pGold, pObj, i ) pObj->Value = Gia_ManAppendCi( pNew ); NewPi = Gia_ManAppendCi( pNew ); Gia_ManForEachAnd( pGold, pObj, i ) pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachCo( pGold, pObj, i ) pObj->Value = Gia_ObjFanin0Copy( pObj ); // create onset Gia_ManConst0(pOld)->Value = 0; Gia_ManForEachCi( pOld, pObj, i ) pObj->Value = Gia_ManCi(pGold, i)->Value; Gia_ManForEachAnd( pOld, pObj, i ) if ( pObj == pRoot ) pObj->Value = NewPi; else pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachCo( pOld, pObj, i ) pObj->Value = Gia_ObjFanin0Copy( pObj ); Gia_ManForEachCo( pGold, pObj, i ) Gia_ManAppendCo( pNew, Gia_ManHashXor(pNew, pObj->Value, Gia_ManCo(pOld, i)->Value) ); // create offset Gia_ManForEachAnd( pOld, pObj, i ) if ( pObj == pRoot ) pObj->Value = Abc_LitNot(NewPi); else pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); Gia_ManForEachCo( pOld, pObj, i ) pObj->Value = Gia_ObjFanin0Copy( pObj ); Miter = 0; Gia_ManForEachCo( pGold, pObj, i ) Miter = Gia_ManHashOr( pNew, Miter, Gia_ManHashXor(pNew, pObj->Value, Gia_ManCo(pOld, i)->Value) ); Gia_ManAppendCo( pNew, Miter ); // add outputs for the nodes Gia_ManForEachObjVec( vFans, pOld, pObj, i ) Gia_ManAppendCo( pNew, pObj->Value ); // cleanup pNew = Gia_ManCleanup( pTemp = pNew ); Gia_ManStop( pTemp ); assert( Gia_ManPiNum(pNew) == Gia_ManCiNum(pGold) + 1 ); assert( Gia_ManPoNum(pNew) == Gia_ManCoNum(pGold) + 1 + Vec_IntSize(vFans) ); return pNew; }
int Dau_DsdToGia_rec( Gia_Man_t * pGia, char * pStr, char ** p, int * pMatches, int * pLits, Vec_Int_t * vCover ) { int fCompl = 0; if ( **p == '!' ) (*p)++, fCompl = 1; if ( **p >= 'a' && **p < 'a' + DAU_DSD_MAX_VAR ) // var return Abc_LitNotCond( pLits[**p - 'a'], fCompl ); if ( **p == '(' ) // and/or { char * q = pStr + pMatches[ *p - pStr ]; int pFans[DAU_DSD_MAX_VAR], nFans = 0, Fan; assert( **p == '(' && *q == ')' ); for ( (*p)++; *p < q; (*p)++ ) { Fan = Dau_DsdToGia_rec( pGia, pStr, p, pMatches, pLits, vCover ); Dau_DsdAddToArray( pGia, pFans, nFans++, Fan ); } Fan = Dau_DsdBalance( pGia, pFans, nFans, 1 ); assert( *p == q ); return Abc_LitNotCond( Fan, fCompl ); } if ( **p == '[' ) // xor { char * q = pStr + pMatches[ *p - pStr ]; int pFans[DAU_DSD_MAX_VAR], nFans = 0, Fan; assert( **p == '[' && *q == ']' ); for ( (*p)++; *p < q; (*p)++ ) { Fan = Dau_DsdToGia_rec( pGia, pStr, p, pMatches, pLits, vCover ); Dau_DsdAddToArray( pGia, pFans, nFans++, Fan ); } Fan = Dau_DsdBalance( pGia, pFans, nFans, 0 ); assert( *p == q ); return Abc_LitNotCond( Fan, fCompl ); } if ( **p == '<' ) // mux { Gia_Obj_t * pObj; int nVars = 0; int Temp[3], * pTemp = Temp, Res; int Fanins[DAU_DSD_MAX_VAR], * pLits2; char * pOld = *p; char * q = pStr + pMatches[ *p - pStr ]; // read fanins if ( *(q+1) == '{' ) { char * q2; *p = q+1; q2 = pStr + pMatches[ *p - pStr ]; assert( **p == '{' && *q2 == '}' ); for ( nVars = 0, (*p)++; *p < q2; (*p)++, nVars++ ) Fanins[nVars] = Dau_DsdToGia_rec( pGia, pStr, p, pMatches, pLits, vCover ); assert( *p == q2 ); pLits2 = Fanins; } else pLits2 = pLits; // read MUX *p = pOld; q = pStr + pMatches[ *p - pStr ]; assert( **p == '<' && *q == '>' ); // verify internal variables if ( nVars ) for ( ; pOld < q; pOld++ ) if ( *pOld >= 'a' && *pOld <= 'z' ) assert( *pOld - 'a' < nVars ); // derive MUX components for ( (*p)++; *p < q; (*p)++ ) *pTemp++ = Dau_DsdToGia_rec( pGia, pStr, p, pMatches, pLits2, vCover ); assert( pTemp == Temp + 3 ); assert( *p == q ); if ( *(q+1) == '{' ) // and/or { char * q = pStr + pMatches[ ++(*p) - pStr ]; assert( **p == '{' && *q == '}' ); *p = q; } if ( pGia->pMuxes ) Res = Gia_ManHashMuxReal( pGia, Temp[0], Temp[1], Temp[2] ); else Res = Gia_ManHashMux( pGia, Temp[0], Temp[1], Temp[2] ); pObj = Gia_ManObj(pGia, Abc_Lit2Var(Res)); if ( Gia_ObjIsAnd(pObj) ) { if ( pGia->pMuxes ) Gia_ObjSetMuxLevel( pGia, pObj ); else { if ( Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) ) Gia_ObjSetAndLevel( pGia, Gia_ObjFanin0(pObj) ); if ( Gia_ObjIsAnd(Gia_ObjFanin1(pObj)) ) Gia_ObjSetAndLevel( pGia, Gia_ObjFanin1(pObj) ); Gia_ObjSetAndLevel( pGia, pObj ); } } return Abc_LitNotCond( Res, fCompl ); } if ( (**p >= 'A' && **p <= 'F') || (**p >= '0' && **p <= '9') ) { Vec_Int_t vLeaves; char * q; word pFunc[DAU_DSD_MAX_VAR > 6 ? (1 << (DAU_DSD_MAX_VAR-6)) : 1]; int Fanins[DAU_DSD_MAX_VAR], Res, nObjOld; int i, nVars = Abc_TtReadHex( pFunc, *p ); *p += Abc_TtHexDigitNum( nVars ); q = pStr + pMatches[ *p - pStr ]; assert( **p == '{' && *q == '}' ); for ( i = 0, (*p)++; *p < q; (*p)++, i++ ) Fanins[i] = Dau_DsdToGia_rec( pGia, pStr, p, pMatches, pLits, vCover ); assert( i == nVars ); assert( *p == q ); vLeaves.nCap = nVars; vLeaves.nSize = nVars; vLeaves.pArray = Fanins; nObjOld = Gia_ManObjNum(pGia); Res = Kit_TruthToGia( pGia, (unsigned *)pFunc, nVars, vCover, &vLeaves, 1 ); // assert( nVars <= 6 ); // Res = Dau_DsdToGiaCompose_rec( pGia, pFunc[0], Fanins, nVars ); for ( i = nObjOld; i < Gia_ManObjNum(pGia); i++ ) Gia_ObjSetGateLevel( pGia, Gia_ManObj(pGia, i) ); m_Non1Step++; return Abc_LitNotCond( Res, fCompl ); } assert( 0 ); return 0; }
ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ /* Vec_Int_t * Gia_WriteDotAigMarks( Gia_Man_t * p, Vec_Int_t * vFadds, Vec_Int_t * vHadds ) { int i; Vec_Int_t * vMarks = Vec_IntStart( Gia_ManObjNum(p) ); for ( i = 0; i < Vec_IntSize(vHadds)/2; i++ ) { Vec_IntWriteEntry( vMarks, Vec_IntEntry(vHadds, 2*i+0), Abc_Var2Lit(i+1, 0) ); Vec_IntWriteEntry( vMarks, Vec_IntEntry(vHadds, 2*i+1), Abc_Var2Lit(i+1, 0) ); } for ( i = 0; i < Vec_IntSize(vFadds)/5; i++ ) { Vec_IntWriteEntry( vMarks, Vec_IntEntry(vFadds, 5*i+3), Abc_Var2Lit(i+1, 1) ); Vec_IntWriteEntry( vMarks, Vec_IntEntry(vFadds, 5*i+4), Abc_Var2Lit(i+1, 1) ); } return vMarks; } int Gia_WriteDotAigLevel_rec( Gia_Man_t * p, Vec_Int_t * vMarks, Vec_Int_t * vFadds, Vec_Int_t * vHadds, int Id, Vec_Int_t * vLevel ) { int Level = Vec_IntEntry(vLevel, Id), Mark = Vec_IntEntry(vMarks, Id); if ( Level || Mark == -1 ) return Level; if ( Mark == 0 ) { Gia_Obj_t * pObj = Gia_ManObj( p, Id ); int Level0 = Gia_WriteDotAigLevel_rec( p, vMarks, vFadds, vHadds, Gia_ObjFaninId0(pObj, Id), vLevel ); int Level1 = Gia_WriteDotAigLevel_rec( p, vMarks, vFadds, vHadds, Gia_ObjFaninId1(pObj, Id), vLevel ); Level = Abc_MaxInt(Level0, Level1) + 1; Vec_IntWriteEntry( vLevel, Id, Level ); Vec_IntWriteEntry( vMarks, Id, -1 ); } else if ( Abc_LitIsCompl(Mark) ) // FA { int i, * pFanins = Vec_IntEntryP( vFadds, 5*(Abc_Lit2Var(Mark)-1) ); assert( pFanins[3] == Id || pFanins[4] == Id ); for ( i = 0; i < 3; i++ ) Level = Abc_MaxInt( Level, Gia_WriteDotAigLevel_rec( p, vMarks, vFadds, vHadds, pFanins[i], vLevel ) ); Vec_IntWriteEntry( vLevel, pFanins[3], Level+1 ); Vec_IntWriteEntry( vLevel, pFanins[4], Level+1 ); } else // HA { int * pFanins = Vec_IntEntryP( vHadds, 2*(Abc_Lit2Var(Mark)-1) ); Gia_Obj_t * pObj = Gia_ManObj( p, pFanins[1] ); int Level0 = Gia_WriteDotAigLevel_rec( p, vMarks, vFadds, vHadds, Gia_ObjFaninId0(pObj, Id), vLevel ); int Level1 = Gia_WriteDotAigLevel_rec( p, vMarks, vFadds, vHadds, Gia_ObjFaninId1(pObj, Id), vLevel ); assert( pFanins[0] == Id || pFanins[1] == Id ); Level = Abc_MaxInt(Level0, Level1) + 1; Vec_IntWriteEntry( vLevel, pFanins[0], Level ); Vec_IntWriteEntry( vLevel, pFanins[1], Level ); } return Level; } int Gia_WriteDotAigLevel( Gia_Man_t * p, Vec_Int_t * vFadds, Vec_Int_t * vHadds, Vec_Int_t ** pvMarks, Vec_Int_t ** pvLevel ) { Vec_Int_t * vMarks = Gia_WriteDotAigMarks( p, vFadds, vHadds ); Vec_Int_t * vLevel = Vec_IntStart( Gia_ManObjNum(p) ); int i, Id, Level = 0; Vec_IntWriteEntry( vMarks, 0, -1 ); Gia_ManForEachCiId( p, Id, i ) Vec_IntWriteEntry( vMarks, Id, -1 ); Gia_ManForEachCoDriverId( p, Id, i ) Level = Abc_MaxInt( Level, Gia_WriteDotAigLevel_rec(p, vMarks, vFadds, vHadds, Id, vLevel) ); Gia_ManForEachCoId( p, Id, i ) Vec_IntWriteEntry( vMarks, Id, -1 ); *pvMarks = vMarks; *pvLevel = vLevel; return Level; } */ int Gia_WriteDotAigLevel( Gia_Man_t * p, Vec_Int_t * vFadds, Vec_Int_t * vHadds, Vec_Int_t * vRecord, Vec_Int_t ** pvLevel, Vec_Int_t ** pvMarks, Vec_Int_t ** pvRemap ) { Vec_Int_t * vLevel = Vec_IntStart( Gia_ManObjNum(p) ); Vec_Int_t * vMarks = Vec_IntStart( Gia_ManObjNum(p) ); Vec_Int_t * vRemap = Vec_IntStartNatural( Gia_ManObjNum(p) ); int i, k, Id, Entry, LevelMax = 0; Vec_IntWriteEntry( vMarks, 0, -1 ); Gia_ManForEachCiId( p, Id, i ) Vec_IntWriteEntry( vMarks, Id, -1 ); Gia_ManForEachCoId( p, Id, i ) Vec_IntWriteEntry( vMarks, Id, -1 ); Vec_IntForEachEntry( vRecord, Entry, i ) { int Level = 0; int Node = Abc_Lit2Var2(Entry); int Attr = Abc_Lit2Att2(Entry); if ( Attr == 2 ) { int * pFanins = Vec_IntEntryP( vFadds, 5*Node ); for ( k = 0; k < 3; k++ ) Level = Abc_MaxInt( Level, Vec_IntEntry(vLevel, pFanins[k]) ); Vec_IntWriteEntry( vLevel, pFanins[3], Level+1 ); Vec_IntWriteEntry( vLevel, pFanins[4], Level+1 ); Vec_IntWriteEntry( vMarks, pFanins[4], Entry ); Vec_IntWriteEntry( vRemap, pFanins[3], pFanins[4] ); //printf( "Making FA output %d.\n", pFanins[4] ); } else if ( Attr == 1 ) { int * pFanins = Vec_IntEntryP( vHadds, 2*Node ); Gia_Obj_t * pObj = Gia_ManObj( p, pFanins[1] ); int pFaninsIn[2] = { Gia_ObjFaninId0(pObj, pFanins[1]), Gia_ObjFaninId1(pObj, pFanins[1]) }; for ( k = 0; k < 2; k++ ) Level = Abc_MaxInt( Level, Vec_IntEntry(vLevel, pFaninsIn[k]) ); Vec_IntWriteEntry( vLevel, pFanins[0], Level+1 ); Vec_IntWriteEntry( vLevel, pFanins[1], Level+1 ); Vec_IntWriteEntry( vMarks, pFanins[1], Entry ); Vec_IntWriteEntry( vRemap, pFanins[0], pFanins[1] ); //printf( "Making HA output %d.\n", pFanins[1] ); } else // if ( Attr == 3 || Attr == 0 ) { Gia_Obj_t * pObj = Gia_ManObj( p, Node ); int pFaninsIn[2] = { Gia_ObjFaninId0(pObj, Node), Gia_ObjFaninId1(pObj, Node) }; for ( k = 0; k < 2; k++ ) Level = Abc_MaxInt( Level, Vec_IntEntry(vLevel, pFaninsIn[k]) ); Vec_IntWriteEntry( vLevel, Node, Level+1 ); Vec_IntWriteEntry( vMarks, Node, -1 ); //printf( "Making node %d.\n", Node ); } LevelMax = Abc_MaxInt( LevelMax, Level+1 ); }
/**Function************************************************************* Synopsis [Performs structural hashing on the LUT functions.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void * Dsm_ManDeriveGia( void * pGia, int fUseMuxes ) { Gia_Man_t * p = (Gia_Man_t *)pGia; Gia_Man_t * pNew, * pTemp; Vec_Int_t * vCover, * vLeaves; Gia_Obj_t * pObj; int k, i, iLut, iVar; word * pTruth; assert( Gia_ManHasMapping(p) ); // create new manager pNew = Gia_ManStart( 6*Gia_ManObjNum(p)/5 + 100 ); pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pSpec = Abc_UtilStrsav( p->pSpec ); pNew->vLevels = Vec_IntStart( 6*Gia_ManObjNum(p)/5 + 100 ); if ( fUseMuxes ) pNew->pMuxes = ABC_CALLOC( unsigned, pNew->nObjsAlloc ); // map primary inputs Gia_ManFillValue(p); Gia_ManConst0(p)->Value = 0; Gia_ManForEachCi( p, pObj, i ) pObj->Value = Gia_ManAppendCi(pNew); // iterate through nodes used in the mapping vLeaves = Vec_IntAlloc( 16 ); vCover = Vec_IntAlloc( 1 << 16 ); Gia_ManHashStart( pNew ); Gia_ObjComputeTruthTableStart( p, Gia_ManLutSizeMax(p) ); Gia_ManForEachAnd( p, pObj, iLut ) { if ( Gia_ObjIsBuf(pObj) ) { pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) ); continue; } if ( !Gia_ObjIsLut(p, iLut) ) continue; // collect leaves Vec_IntClear( vLeaves ); Gia_LutForEachFanin( p, iLut, iVar, k ) Vec_IntPush( vLeaves, iVar ); pTruth = Gia_ObjComputeTruthTableCut( p, Gia_ManObj(p, iLut), vLeaves ); // collect incoming literals Vec_IntClear( vLeaves ); Gia_LutForEachFanin( p, iLut, iVar, k ) Vec_IntPush( vLeaves, Gia_ManObj(p, iVar)->Value ); Gia_ManObj(p, iLut)->Value = Dsm_ManTruthToGia( pNew, pTruth, vLeaves, vCover ); } Gia_ObjComputeTruthTableStop( p ); Gia_ManForEachCo( p, pObj, i ) pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManHashStop( pNew ); Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) ); Vec_IntFree( vLeaves ); Vec_IntFree( vCover ); /* Gia_ManForEachAnd( pNew, pObj, i ) { int iLev = Gia_ObjLevelId(pNew, i); int iLev0 = Gia_ObjLevelId(pNew, Gia_ObjFaninId0(pObj, i)); int iLev1 = Gia_ObjLevelId(pNew, Gia_ObjFaninId1(pObj, i)); assert( iLev == 1 + Abc_MaxInt(iLev0, iLev1) ); } */ // perform cleanup pNew = Gia_ManCleanup( pTemp = pNew ); Gia_ManStop( pTemp ); return pNew; }