ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Fra_ManPartitionTest( Aig_Man_t * p, int nComLim ) { // Bar_Progress_t * pProgress; Vec_Vec_t * vSupps, * vSuppsIn; Vec_Ptr_t * vSuppsNew; Vec_Int_t * vSupNew, * vSup, * vSup2, * vTemp;//, * vSupIn; Vec_Int_t * vOverNew, * vQuantNew; Aig_Obj_t * pObj; int i, k, nCommon, CountOver, CountQuant; int nTotalSupp, nTotalSupp2, Entry, Largest;//, iVar; double Ratio, R; clock_t clk; nTotalSupp = 0; nTotalSupp2 = 0; Ratio = 0.0; // compute supports clk = clock(); vSupps = (Vec_Vec_t *)Aig_ManSupports( p ); ABC_PRT( "Supports", clock() - clk ); // remove last entry Aig_ManForEachCo( p, pObj, i ) { vSup = Vec_VecEntryInt( vSupps, i ); Vec_IntPop( vSup ); // remember support // pObj->pNext = (Aig_Obj_t *)vSup; }
Vec_Wec_t * Gia_ManComputeMffcs( Gia_Man_t * p, int LimitMin, int LimitMax, int SuppMax, int RatioBest ) { Gia_Obj_t * pObj; Vec_Wec_t * vMffcs; Vec_Int_t * vNodes, * vLeaves, * vInners, * vMffc; int i, iPivot; assert( p->pMuxes ); vNodes = Vec_IntAlloc( 2 * LimitMax ); vLeaves = Vec_IntAlloc( 2 * LimitMax ); vInners = Vec_IntAlloc( 2 * LimitMax ); vMffcs = Vec_WecAlloc( 1000 ); Gia_ManCreateRefs( p ); Gia_ManForEachAnd( p, pObj, i ) { if ( !Gia_ObjRefNum(p, pObj) ) continue; if ( !Gia_ObjCheckMffc(p, pObj, LimitMax, vNodes, vLeaves, vInners) ) continue; if ( Vec_IntSize(vInners) < LimitMin ) continue; if ( Vec_IntSize(vLeaves) > SuppMax ) continue; // improve cut // collect cut vMffc = Vec_WecPushLevel( vMffcs ); Vec_IntGrow( vMffc, Vec_IntSize(vLeaves) + Vec_IntSize(vInners) + 20 ); Vec_IntPush( vMffc, i ); Vec_IntPush( vMffc, Vec_IntSize(vLeaves) ); Vec_IntPush( vMffc, Vec_IntSize(vInners) ); Vec_IntAppend( vMffc, vLeaves ); // Vec_IntAppend( vMffc, vInners ); // add last entry equal to the ratio Vec_IntPush( vMffc, 1000 * Vec_IntSize(vInners) / Vec_IntSize(vLeaves) ); } Vec_IntFree( vNodes ); Vec_IntFree( vLeaves ); Vec_IntFree( vInners ); // sort MFFCs by their inner/leaf ratio Vec_WecSortByLastInt( vMffcs, 1 ); Vec_WecForEachLevel( vMffcs, vMffc, i ) Vec_IntPop( vMffc ); // remove those whose ratio is not good iPivot = RatioBest * Vec_WecSize(vMffcs) / 100; Vec_WecForEachLevelStart( vMffcs, vMffc, i, iPivot ) Vec_IntErase( vMffc ); assert( iPivot <= Vec_WecSize(vMffcs) ); Vec_WecShrink( vMffcs, iPivot ); return vMffcs; }
int Sfm_NtkCreateWindow( Sfm_Ntk_t * p, int iNode, int fVerbose ) { int i, k, iTemp; abctime clkDiv, clkWin = Abc_Clock(); assert( Sfm_ObjIsNode( p, iNode ) ); p->iPivotNode = iNode; Vec_IntClear( p->vNodes ); // internal Vec_IntClear( p->vDivs ); // divisors Vec_IntClear( p->vRoots ); // roots Vec_IntClear( p->vTfo ); // roots Vec_IntClear( p->vOrder ); // variable order // collect transitive fanin Sfm_NtkIncrementTravId( p ); if ( Sfm_NtkCollectTfi_rec( p, iNode, p->vNodes ) ) { p->nMaxDivs++; p->timeWin += Abc_Clock() - clkWin; return 0; } // create divisors clkDiv = Abc_Clock(); Vec_IntClear( p->vDivs ); Vec_IntAppend( p->vDivs, p->vNodes ); Vec_IntPop( p->vDivs ); // add non-topological divisors if ( Vec_IntSize(p->vDivs) < p->pPars->nWinSizeMax + 0 ) { Sfm_NtkIncrementTravId2( p ); Vec_IntForEachEntry( p->vDivs, iTemp, i ) if ( Vec_IntSize(p->vDivs) < p->pPars->nWinSizeMax + 0 ) // Sfm_NtkAddDivisors( p, iTemp, Sfm_ObjLevel(p, iNode) - 1 ); Sfm_NtkAddDivisors( p, iTemp, p->nLevelMax - Sfm_ObjLevelR(p, iNode) ); }
/**Function************************************************************* Synopsis [Performs resubstitution for the node.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Sfm_NodeResubSolve( Sfm_Ntk_t * p, int iNode, int f, int fRemoveOnly ) { int fSkipUpdate = 0; int fVeryVerbose = 0;//p->pPars->fVeryVerbose && Vec_IntSize(p->vDivs) < 200;// || pNode->Id == 556; int i, iFanin, iVar = -1; word uTruth, uSign, uMask; abctime clk; assert( Sfm_ObjIsNode(p, iNode) ); assert( f >= 0 && f < Sfm_ObjFaninNum(p, iNode) ); p->nTryRemoves++; // report init stats if ( p->pPars->fVeryVerbose ) printf( "%5d : Lev =%3d. Leaf =%3d. Node =%3d. Div=%3d. Fanin =%4d (%d/%d). MFFC = %d\n", iNode, Sfm_ObjLevel(p, iNode), 0, Vec_IntSize(p->vNodes), Vec_IntSize(p->vDivs), Sfm_ObjFanin(p, iNode, f), f, Sfm_ObjFaninNum(p, iNode), Sfm_ObjMffcSize(p, Sfm_ObjFanin(p, iNode, f)) ); // clean simulation info p->nCexes = 0; Vec_WrdFill( p->vDivCexes, Vec_IntSize(p->vDivs), 0 ); // try removing the critical fanin Vec_IntClear( p->vDivIds ); Sfm_ObjForEachFanin( p, iNode, iFanin, i ) if ( i != f ) Vec_IntPush( p->vDivIds, Sfm_ObjSatVar(p, iFanin) ); clk = Abc_Clock(); uTruth = Sfm_ComputeInterpolant( p ); p->timeSat += Abc_Clock() - clk; // analyze outcomes if ( uTruth == SFM_SAT_UNDEC ) { p->nTimeOuts++; return 0; } if ( uTruth != SFM_SAT_SAT ) goto finish; if ( fRemoveOnly || p->pPars->fRrOnly || Vec_IntSize(p->vDivs) == 0 ) return 0; p->nTryResubs++; if ( fVeryVerbose ) { for ( i = 0; i < 9; i++ ) printf( " " ); for ( i = 0; i < Vec_IntSize(p->vDivs); i++ ) printf( "%d", i % 10 ); printf( "\n" ); } while ( 1 ) { if ( fVeryVerbose ) { printf( "%3d: %3d ", p->nCexes, iVar ); Vec_WrdForEachEntry( p->vDivCexes, uSign, i ) printf( "%d", Abc_InfoHasBit((unsigned *)&uSign, p->nCexes-1) ); printf( "\n" ); } // find the next divisor to try uMask = (~(word)0) >> (64 - p->nCexes); Vec_WrdForEachEntry( p->vDivCexes, uSign, iVar ) if ( uSign == uMask ) break; if ( iVar == Vec_IntSize(p->vDivs) ) return 0; // try replacing the critical fanin Vec_IntPush( p->vDivIds, Sfm_ObjSatVar(p, Vec_IntEntry(p->vDivs, iVar)) ); clk = Abc_Clock(); uTruth = Sfm_ComputeInterpolant( p ); p->timeSat += Abc_Clock() - clk; // analyze outcomes if ( uTruth == SFM_SAT_UNDEC ) { p->nTimeOuts++; return 0; } if ( uTruth != SFM_SAT_SAT ) goto finish; if ( p->nCexes == 64 ) return 0; // remove the last variable Vec_IntPop( p->vDivIds ); } finish: if ( p->pPars->fVeryVerbose ) { if ( iVar == -1 ) printf( "Node %d: Fanin %d (%d) can be removed. ", iNode, f, Sfm_ObjFanin(p, iNode, f) ); else printf( "Node %d: Fanin %d (%d) can be replaced by divisor %d (%d). ", iNode, f, Sfm_ObjFanin(p, iNode, f), iVar, Vec_IntEntry(p->vDivs, iVar) ); Kit_DsdPrintFromTruth( (unsigned *)&uTruth, Vec_IntSize(p->vDivIds) ); printf( "\n" ); } if ( iVar == -1 ) p->nRemoves++; else p->nResubs++; if ( fSkipUpdate ) return 0; // update the network Sfm_NtkUpdate( p, iNode, f, (iVar == -1 ? iVar : Vec_IntEntry(p->vDivs, iVar)), uTruth ); return 1; }
/**Function************************************************************* Synopsis [Parser of the formula encountered in assign statements.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void * Ver_FormulaParser( char * pFormula, void * pMan, Vec_Ptr_t * vNames, Vec_Ptr_t * vStackFn, Vec_Int_t * vStackOp, char * pErrorMessage ) { char * pTemp; Hop_Obj_t * bFunc, * bTemp; int nParans, Flag; int Oper, Oper1, Oper2; int v; // clear the stacks and the names Vec_PtrClear( vNames ); Vec_PtrClear( vStackFn ); Vec_IntClear( vStackOp ); if ( !strcmp(pFormula, "0") || !strcmp(pFormula, "1\'b0") ) return Hop_ManConst0((Hop_Man_t *)pMan); if ( !strcmp(pFormula, "1") || !strcmp(pFormula, "1\'b1") ) return Hop_ManConst1((Hop_Man_t *)pMan); // make sure that the number of opening and closing parantheses is the same nParans = 0; for ( pTemp = pFormula; *pTemp; pTemp++ ) if ( *pTemp == '(' ) nParans++; else if ( *pTemp == ')' ) nParans--; if ( nParans != 0 ) { sprintf( pErrorMessage, "Parse_FormulaParser(): Different number of opening and closing parantheses ()." ); return NULL; } // add parantheses pTemp = pFormula + strlen(pFormula) + 2; *pTemp-- = 0; *pTemp = ')'; while ( --pTemp != pFormula ) *pTemp = *(pTemp - 1); *pTemp = '('; // perform parsing Flag = VER_PARSE_FLAG_START; for ( pTemp = pFormula; *pTemp; pTemp++ ) { switch ( *pTemp ) { // skip all spaces, tabs, and end-of-lines case ' ': case '\t': case '\r': case '\n': continue; /* // treat Constant 0 as a variable case VER_PARSE_SYM_CONST0: Vec_PtrPush( vStackFn, Hop_ManConst0(pMan) ); // Cudd_Ref( Hop_ManConst0(pMan) ); if ( Flag == VER_PARSE_FLAG_VAR ) { sprintf( pErrorMessage, "Parse_FormulaParser(): No operation symbol before constant 0." ); Flag = VER_PARSE_FLAG_ERROR; break; } Flag = VER_PARSE_FLAG_VAR; break; // the same for Constant 1 case VER_PARSE_SYM_CONST1: Vec_PtrPush( vStackFn, Hop_ManConst1(pMan) ); // Cudd_Ref( Hop_ManConst1(pMan) ); if ( Flag == VER_PARSE_FLAG_VAR ) { sprintf( pErrorMessage, "Parse_FormulaParser(): No operation symbol before constant 1." ); Flag = VER_PARSE_FLAG_ERROR; break; } Flag = VER_PARSE_FLAG_VAR; break; */ case VER_PARSE_SYM_NEGBEF1: case VER_PARSE_SYM_NEGBEF2: if ( Flag == VER_PARSE_FLAG_VAR ) {// if NEGBEF follows a variable, AND is assumed sprintf( pErrorMessage, "Parse_FormulaParser(): Variable before negation." ); Flag = VER_PARSE_FLAG_ERROR; break; } Vec_IntPush( vStackOp, VER_PARSE_OPER_NEG ); break; case VER_PARSE_SYM_AND: case VER_PARSE_SYM_OR: case VER_PARSE_SYM_XOR: case VER_PARSE_SYM_MUX1: case VER_PARSE_SYM_MUX2: if ( Flag != VER_PARSE_FLAG_VAR ) { sprintf( pErrorMessage, "Parse_FormulaParser(): There is no variable before AND, EXOR, or OR." ); Flag = VER_PARSE_FLAG_ERROR; break; } if ( *pTemp == VER_PARSE_SYM_AND ) Vec_IntPush( vStackOp, VER_PARSE_OPER_AND ); else if ( *pTemp == VER_PARSE_SYM_OR ) Vec_IntPush( vStackOp, VER_PARSE_OPER_OR ); else if ( *pTemp == VER_PARSE_SYM_XOR ) Vec_IntPush( vStackOp, VER_PARSE_OPER_XOR ); else if ( *pTemp == VER_PARSE_SYM_MUX1 ) Vec_IntPush( vStackOp, VER_PARSE_OPER_MUX ); // else if ( *pTemp == VER_PARSE_SYM_MUX2 ) // Vec_IntPush( vStackOp, VER_PARSE_OPER_MUX ); Flag = VER_PARSE_FLAG_OPER; break; case VER_PARSE_SYM_OPEN: if ( Flag == VER_PARSE_FLAG_VAR ) { sprintf( pErrorMessage, "Parse_FormulaParser(): Variable before a paranthesis." ); Flag = VER_PARSE_FLAG_ERROR; break; } Vec_IntPush( vStackOp, VER_PARSE_OPER_MARK ); // after an opening bracket, it feels like starting over again Flag = VER_PARSE_FLAG_START; break; case VER_PARSE_SYM_CLOSE: if ( Vec_IntSize( vStackOp ) ) { while ( 1 ) { if ( !Vec_IntSize( vStackOp ) ) { sprintf( pErrorMessage, "Parse_FormulaParser(): There is no opening paranthesis\n" ); Flag = VER_PARSE_FLAG_ERROR; break; } Oper = Vec_IntPop( vStackOp ); if ( Oper == VER_PARSE_OPER_MARK ) break; // skip the second MUX operation // if ( Oper == VER_PARSE_OPER_MUX2 ) // { // Oper = Vec_IntPop( vStackOp ); // assert( Oper == VER_PARSE_OPER_MUX1 ); // } // perform the given operation if ( Ver_FormulaParserTopOper( (Hop_Man_t *)pMan, vStackFn, Oper ) == NULL ) { sprintf( pErrorMessage, "Parse_FormulaParser(): Unknown operation\n" ); return NULL; } } } else { sprintf( pErrorMessage, "Parse_FormulaParser(): There is no opening paranthesis\n" ); Flag = VER_PARSE_FLAG_ERROR; break; } if ( Flag != VER_PARSE_FLAG_ERROR ) Flag = VER_PARSE_FLAG_VAR; break; default: // scan the next name v = Ver_FormulaParserFindVar( pTemp, vNames ); if ( *pTemp == '\\' ) pTemp++; pTemp += (int)(ABC_PTRUINT_T)Vec_PtrEntry( vNames, 2*v ) - 1; // assume operation AND, if vars follow one another if ( Flag == VER_PARSE_FLAG_VAR ) { sprintf( pErrorMessage, "Parse_FormulaParser(): Incorrect state." ); return NULL; } bTemp = Hop_IthVar( (Hop_Man_t *)pMan, v ); Vec_PtrPush( vStackFn, bTemp ); // Cudd_Ref( bTemp ); Flag = VER_PARSE_FLAG_VAR; break; } if ( Flag == VER_PARSE_FLAG_ERROR ) break; // error exit else if ( Flag == VER_PARSE_FLAG_START ) continue; // go on parsing else if ( Flag == VER_PARSE_FLAG_VAR ) while ( 1 ) { // check if there are negations in the OpStack if ( !Vec_IntSize(vStackOp) ) break; Oper = Vec_IntPop( vStackOp ); if ( Oper != VER_PARSE_OPER_NEG ) { Vec_IntPush( vStackOp, Oper ); break; } else { // Vec_PtrPush( vStackFn, Cudd_Not(Vec_PtrPop(vStackFn)) ); Vec_PtrPush( vStackFn, Hop_Not((Hop_Obj_t *)Vec_PtrPop(vStackFn)) ); } } else // if ( Flag == VER_PARSE_FLAG_OPER ) while ( 1 ) { // execute all the operations in the OpStack // with precedence higher or equal than the last one Oper1 = Vec_IntPop( vStackOp ); // the last operation if ( !Vec_IntSize(vStackOp) ) { // if it is the only operation, push it back Vec_IntPush( vStackOp, Oper1 ); break; } Oper2 = Vec_IntPop( vStackOp ); // the operation before the last one if ( Oper2 >= Oper1 && !(Oper1 == Oper2 && Oper1 == VER_PARSE_OPER_MUX) ) { // if Oper2 precedence is higher or equal, execute it if ( Ver_FormulaParserTopOper( (Hop_Man_t *)pMan, vStackFn, Oper2 ) == NULL ) { sprintf( pErrorMessage, "Parse_FormulaParser(): Unknown operation\n" ); return NULL; } Vec_IntPush( vStackOp, Oper1 ); // push the last operation back } else { // if Oper2 precedence is lower, push them back and done Vec_IntPush( vStackOp, Oper2 ); Vec_IntPush( vStackOp, Oper1 ); break; } } } if ( Flag != VER_PARSE_FLAG_ERROR ) { if ( Vec_PtrSize(vStackFn) ) { bFunc = (Hop_Obj_t *)Vec_PtrPop(vStackFn); if ( !Vec_PtrSize(vStackFn) ) if ( !Vec_IntSize(vStackOp) ) { // Cudd_Deref( bFunc ); return bFunc; } else sprintf( pErrorMessage, "Parse_FormulaParser(): Something is left in the operation stack\n" ); else sprintf( pErrorMessage, "Parse_FormulaParser(): Something is left in the function stack\n" ); } else sprintf( pErrorMessage, "Parse_FormulaParser(): The input string is empty\n" ); } // Cudd_Ref( bFunc ); // Cudd_RecursiveDeref( dd, bFunc ); return NULL; }
int Gia_SweeperCondPop( Gia_Man_t * p ) { Swp_Man_t * pSwp = (Swp_Man_t *)p->pData; return Vec_IntPop( pSwp->vCondProbes ); }