コード例 #1
0
ファイル: verFormula.c プロジェクト: aakarsh/ABC
/**Function*************************************************************

  Synopsis    [Performs the operation on the top entries in the stack.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Hop_Obj_t * Ver_FormulaParserTopOper( Hop_Man_t * pMan, Vec_Ptr_t * vStackFn, int Oper )
{
    Hop_Obj_t * bArg0, * bArg1, * bArg2, * bFunc;
    // perform the given operation
    bArg2 = (Hop_Obj_t *)Vec_PtrPop( vStackFn );
    bArg1 = (Hop_Obj_t *)Vec_PtrPop( vStackFn );
	if ( Oper == VER_PARSE_OPER_AND )
		bFunc = Hop_And( pMan, bArg1, bArg2 );
	else if ( Oper == VER_PARSE_OPER_XOR )
		bFunc = Hop_Exor( pMan, bArg1, bArg2 );
	else if ( Oper == VER_PARSE_OPER_OR )
		bFunc = Hop_Or( pMan, bArg1, bArg2 );
	else if ( Oper == VER_PARSE_OPER_EQU )
		bFunc = Hop_Not( Hop_Exor( pMan, bArg1, bArg2 ) );
	else if ( Oper == VER_PARSE_OPER_MUX )
    {
        bArg0 = (Hop_Obj_t *)Vec_PtrPop( vStackFn );
//		bFunc = Cudd_bddIte( dd, bArg0, bArg1, bArg2 );  Cudd_Ref( bFunc );
		bFunc = Hop_Mux( pMan, bArg0, bArg1, bArg2 ); 
//        Cudd_RecursiveDeref( dd, bArg0 );
//        Cudd_Deref( bFunc );
    }
	else
		return NULL;
//    Cudd_Ref( bFunc );
//    Cudd_RecursiveDeref( dd, bArg1 );
//    Cudd_RecursiveDeref( dd, bArg2 );
	Vec_PtrPush( vStackFn,  bFunc );
    return bFunc;
}
コード例 #2
0
/**Function*************************************************************

  Synopsis    [Reproduces script "compress2".]

  Description [Consumes the input AIG to reduce memory usage.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Man_t * Dar_ManChoiceNewAig( Aig_Man_t * pAig, Dch_Pars_t * pPars )
{
//    extern Aig_Man_t * Dch_DeriveTotalAig( Vec_Ptr_t * vAigs );
    extern Aig_Man_t * Dch_ComputeChoices( Aig_Man_t * pAig, Dch_Pars_t * pPars );
    int fVerbose = pPars->fVerbose;
    Aig_Man_t * pMan, * pTemp;
    Vec_Ptr_t * vAigs;
    Vec_Ptr_t * vPios;
    void * pManTime;
    char * pName, * pSpec;
    int i;
    abctime clk;

clk = Abc_Clock();
    vAigs = Dar_ManChoiceSynthesis( pAig, 1, 1, pPars->fPower, fVerbose );
pPars->timeSynth = Abc_Clock() - clk;
    // swap the first and last network
    // this should lead to the primary choice being "better" because of synthesis
    // (it is also important when constructing choices)
    pMan = (Aig_Man_t *)Vec_PtrPop( vAigs );
    Vec_PtrPush( vAigs, Vec_PtrEntry(vAigs,0) );
    Vec_PtrWriteEntry( vAigs, 0, pMan );

    // derive the total AIG
    pMan = Dch_DeriveTotalAig( vAigs );
    // cleanup
    Vec_PtrForEachEntry( Aig_Man_t *, vAigs, pTemp, i )
        Aig_ManStop( pTemp );
    Vec_PtrFree( vAigs );

    // compute choices
    pMan = Dch_ComputeChoices( pTemp = pMan, pPars );
    Aig_ManStop( pTemp );

    // save useful things
    pManTime = pAig->pManTime; pAig->pManTime = NULL;
    pName = Abc_UtilStrsav( pAig->pName );
    pSpec = Abc_UtilStrsav( pAig->pSpec );

    // create guidence
    vPios = Aig_ManOrderPios( pMan, pAig ); 
    Aig_ManStop( pAig );

    // reconstruct the network
    pMan = Aig_ManDupDfsGuided( pTemp = pMan, vPios );
    Aig_ManStop( pTemp );
    Vec_PtrFree( vPios );

    // reset levels
    pMan->pManTime = pManTime;
    Aig_ManChoiceLevel( pMan );

    // copy names
    ABC_FREE( pMan->pName );
    ABC_FREE( pMan->pSpec );
    pMan->pName = pName;
    pMan->pSpec = pSpec;
    return pMan;
}
コード例 #3
0
ファイル: darBalance.c プロジェクト: rubund/berkeley-abc
/**Function*************************************************************

  Synopsis    [Builds implication supergate.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Obj_t * Dar_BalanceBuildSuper( Aig_Man_t * p, Vec_Ptr_t * vSuper, Aig_Type_t Type, int fUpdateLevel )
{
    Aig_Obj_t * pObj1, * pObj2;
    int LeftBound;
    assert( vSuper->nSize > 1 );
    // sort the new nodes by level in the decreasing order
    Vec_PtrSort( vSuper, (int (*)(void))Aig_NodeCompareLevelsDecrease );
    // balance the nodes
    while ( vSuper->nSize > 1 )
    {
        // find the left bound on the node to be paired
        LeftBound = (!fUpdateLevel)? 0 : Dar_BalanceFindLeft( vSuper );
        // find the node that can be shared (if no such node, randomize choice)
        Dar_BalancePermute( p, vSuper, LeftBound, Type == AIG_OBJ_EXOR );
        // pull out the last two nodes
        pObj1 = (Aig_Obj_t *)Vec_PtrPop(vSuper);
        pObj2 = (Aig_Obj_t *)Vec_PtrPop(vSuper);
        Dar_BalancePushUniqueOrderByLevel( vSuper, Aig_Oper(p, pObj1, pObj2, Type), Type == AIG_OBJ_EXOR );
    }
    return (Aig_Obj_t *)Vec_PtrEntry(vSuper, 0);
}
コード例 #4
0
/**Function*************************************************************

  Synopsis    [Reproduces script "compress2".]

  Description [Takes AIG manager, consumes it, and produces GIA manager.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Gia_Man_t * Dar_NewChoiceSynthesis( Aig_Man_t * pAig, int fBalance, int fUpdateLevel, int fPower, int fLightSynth, int fVerbose )
//alias resyn    "b; rw; rwz; b; rwz; b"
//alias resyn2   "b; rw; rf; b; rw; rwz; b; rfz; rwz; b"
{
    Vec_Ptr_t * vGias;
    Gia_Man_t * pGia, * pTemp;
    int i;

    if ( fUpdateLevel && Dar_NewChoiceSynthesisGuard(pAig) )
    {
        if ( fVerbose )
            printf( "Warning: Due to high fanout count of some nodes, level updating is disabled.\n" );
        fUpdateLevel = 0;
    }

    vGias = Vec_PtrAlloc( 3 );
    pGia = Gia_ManFromAig(pAig);
    Vec_PtrPush( vGias, pGia );

    pAig = Dar_NewCompress( pAig, fBalance, fUpdateLevel, fPower, fVerbose );
    pGia = Gia_ManFromAig(pAig);
    Vec_PtrPush( vGias, pGia );
//Aig_ManPrintStats( pAig );

    pAig = Dar_NewCompress2( pAig, fBalance, fUpdateLevel, 1, fPower, fLightSynth, fVerbose );
    pGia = Gia_ManFromAig(pAig);
    Vec_PtrPush( vGias, pGia );
//Aig_ManPrintStats( pAig );

    Aig_ManStop( pAig );

    // swap around the first and the last
    pTemp = (Gia_Man_t *)Vec_PtrPop( vGias );
    Vec_PtrPush( vGias, Vec_PtrEntry(vGias,0) );
    Vec_PtrWriteEntry( vGias, 0, pTemp );

//    Aig_Man_t * pAig;
//    int i;
//    printf( "Choicing will be performed with %d AIGs:\n", Vec_PtrSize(p->vAigs) );
//    Vec_PtrForEachEntry( Aig_Man_t *, p->vAigs, pAig, i )
//        Aig_ManPrintStats( pAig );

    // derive the miter
    pGia = Gia_ManChoiceMiter( vGias );

    // cleanup
    Vec_PtrForEachEntry( Gia_Man_t *, vGias, pTemp, i )
        Gia_ManStop( pTemp );
    Vec_PtrFree( vGias );
    return pGia;
}
コード例 #5
0
/**Function*************************************************************

  Synopsis    [Reproduces script "compress2".]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Man_t * Dar_ManChoice( Aig_Man_t * pAig, int fBalance, int fUpdateLevel, int fConstruct, int nConfMax, int nLevelMax, int fVerbose )
{
    Aig_Man_t * pMan, * pTemp;
    Vec_Ptr_t * vAigs;
    int i;
    abctime clk;

clk = Abc_Clock();
//    vAigs = Dar_ManChoiceSynthesisExt();
    vAigs = Dar_ManChoiceSynthesis( pAig, fBalance, fUpdateLevel, 0, fVerbose );

    // swap the first and last network
    // this should lead to the primary choice being "better" because of synthesis
    // (it is also important when constructing choices)
    if ( !fConstruct )
    {
        pMan = (Aig_Man_t *)Vec_PtrPop( vAigs );
        Vec_PtrPush( vAigs, Vec_PtrEntry(vAigs,0) );
        Vec_PtrWriteEntry( vAigs, 0, pMan );
    }

if ( fVerbose )
{
ABC_PRT( "Synthesis time", Abc_Clock() - clk );
}
clk = Abc_Clock();
    if ( fConstruct )
        pMan = Aig_ManChoiceConstructive( vAigs, fVerbose );
    else
        pMan = Aig_ManChoicePartitioned( vAigs, 300, nConfMax, nLevelMax, fVerbose );
    Vec_PtrForEachEntry( Aig_Man_t *, vAigs, pTemp, i )
        Aig_ManStop( pTemp );
    Vec_PtrFree( vAigs );
if ( fVerbose )
{
ABC_PRT( "Choicing time ", Abc_Clock() - clk );
}
    return pMan;
//    return NULL;
}
コード例 #6
0
ファイル: abcTim.c プロジェクト: Shubhankar007/ECEN-699
Vec_Ptr_t * Abc_NtkTestTimCollectCone( Abc_Ntk_t * pNtk, Abc_Obj_t * pObj )
{
    Vec_Ptr_t * vCone = Vec_PtrAlloc( 1000 );
    if ( pObj != NULL )
    {
        // collect for one node
        assert( Abc_ObjIsNode(pObj) );
        assert( !Abc_NodeIsTravIdCurrent( pObj ) );
        Abc_NtkTestTimCollectCone_rec( pObj, vCone );
        // remove the node because it is a white box
        Vec_PtrPop( vCone );
    }
    else
    {
        // collect for all COs
        Abc_Obj_t * pObj;
        int i;
        Abc_NtkForEachCo( pNtk, pObj, i )
            Abc_NtkTestTimCollectCone_rec( Abc_ObjFanin0(pObj), vCone );
    }
    return vCone;

}
コード例 #7
0
ファイル: verFormula.c プロジェクト: aakarsh/ABC
/**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;
}