Exemple #1
0
int Mio_UpdateGenlib2( Vec_Str_t * vStr, Vec_Str_t * vStr2, char * pFileName, int fVerbose )
{
    Mio_Library_t * pLib;
    // set the new network
    pLib = Mio_LibraryRead( pFileName, Vec_StrArray(vStr), NULL, fVerbose );  
    if ( pLib == NULL )
        return 0;

    // free the current superlib because it depends on the old Mio library
    if ( Abc_FrameReadLibSuper() )
    {
        Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
        Abc_FrameSetLibSuper( NULL );
    }

    // replace the current library
    Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
    Abc_FrameSetLibGen( pLib );

    // set the new network
    pLib = (Mio_Library_t *)Amap_LibReadAndPrepare( pFileName, Vec_StrArray(vStr2), 0, 0 );  
    if ( pLib == NULL )
        return 0;

    // replace the current library
    Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() );
    Abc_FrameSetLibGen2( pLib );
    return 1;
}
Exemple #2
0
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mio_Init( Abc_Frame_t * pAbc )
{
    char * pFileTemp = "mcnc_temp.genlib";
    Mio_Library_t * pLibGen;
    FILE * pFile;
    int i;

    // write genlib into file
    pFile = fopen( pFileTemp, "w" );
    for ( i = 0; pMcncGenlib[i]; i++ )
        fputs( pMcncGenlib[i], pFile );
    fclose( pFile );
    // read genlib from file
    pLibGen = Mio_LibraryRead( pAbc, pFileTemp, NULL, 0 );
    Abc_FrameSetLibGen( pLibGen );
#ifdef WIN32
        _unlink( pFileTemp );
#else
        unlink( pFileTemp );
#endif

    Cmd_CommandAdd( pAbc, "SC mapping", "read_library",   Mio_CommandReadLibrary,  0 ); 
    Cmd_CommandAdd( pAbc, "SC mapping", "print_library",  Mio_CommandPrintLibrary, 0 ); 
}
Exemple #3
0
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
{
    FILE * pFile;
    FILE * pOut, * pErr;
    Mio_Library_t * pLib;
    Abc_Ntk_t * pNet;
    char * FileName;
    int fVerbose;
    int c;

    pNet = Abc_FrameReadNtk(pAbc);
    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
    fVerbose = 1;
    Extra_UtilGetoptReset();
    while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF ) 
    {
        switch (c) 
        {
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }


    if ( argc != globalUtilOptind + 1 )
    {
        goto usage;
    }

    // get the input file name
    FileName = argv[globalUtilOptind];
    if ( (pFile = Io_FileOpen( FileName, "open_path", "r", 0 )) == NULL )
    {
        fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
        if ( (FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL )) )
            fprintf( pErr, "Did you mean \"%s\"?", FileName );
        fprintf( pErr, "\n" );
        return 1;
    }
    fclose( pFile );

    // set the new network
    pLib = Mio_LibraryRead( pAbc, FileName, 0, fVerbose );  
    if ( pLib == NULL )
    {
        fprintf( pErr, "Reading GENLIB library has failed.\n" );
        return 1;
    }
    // free the current superlib because it depends on the old Mio library
    if ( Abc_FrameReadLibSuper() )
    {
        extern void Map_SuperLibFree( Map_SuperLib_t * p );
//        Map_SuperLibFree( s_pSuperLib );
//        s_pSuperLib = NULL;
        Map_SuperLibFree( Abc_FrameReadLibSuper() );
        Abc_FrameSetLibSuper( NULL );
    }

    // replace the current library
//    Mio_LibraryDelete( s_pLib );
//    s_pLib = pLib;
    Mio_LibraryDelete( Abc_FrameReadLibGen() );
    Abc_FrameSetLibGen( pLib );
    return 0;

usage:
    fprintf( pErr, "usage: read_library [-vh]\n");
    fprintf( pErr, "\t         read the library from a genlib file\n" );  
    fprintf( pErr, "\t-h     : enable verbose output\n");
    return 1;       /* error exit */
}
Exemple #4
0
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv )
{
    FILE * pFile;
    FILE * pOut, * pErr;
    Mio_Library_t * pLib;
    char * FileName, * ExcludeFile;
    float DelayLimit;
    float AreaLimit;
    int fSkipInvs;
    int fWriteOldFormat; 
    int nVarsMax, nLevels, TimeLimit;
    int fVerbose;
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
    nVarsMax   = 5;
    nLevels    = 3;
    DelayLimit = 3.5;
    AreaLimit  = 9;
    TimeLimit  = 10;
    fSkipInvs  = 1;
    fVerbose   = 0;
    fWriteOldFormat = 0;
    ExcludeFile = 0;

    Extra_UtilGetoptReset();
    while ( (c = Extra_UtilGetopt(argc, argv, "eiltdasovh")) != EOF ) 
    {
        switch (c) 
        {
            case 'e':
                ExcludeFile = argv[globalUtilOptind];
                if ( ExcludeFile == 0 )
                    goto usage;
                globalUtilOptind++;
                break;
            case 'i':
                nVarsMax = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
                if ( nVarsMax < 0 ) 
                    goto usage;
                break;
            case 'l':
                nLevels = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
                if ( nLevels < 0 ) 
                    goto usage;
                break;
            case 't':
                TimeLimit = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
                if ( TimeLimit < 0 ) 
                    goto usage;
                break;
			case 'd':
				DelayLimit = (float)atof(argv[globalUtilOptind]);
				globalUtilOptind++;
				if ( DelayLimit <= 0.0 ) 
					goto usage;
				break;
			case 'a':
				AreaLimit = (float)atof(argv[globalUtilOptind]);
				globalUtilOptind++;
				if ( AreaLimit <= 0.0 ) 
					goto usage;
				break;
            case 's':
                fSkipInvs ^= 1;
                break;
            case 'o':
                fWriteOldFormat ^= 1;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }


    if ( argc != globalUtilOptind + 1 )
    {
        fprintf( pErr, "The GENLIB library file should be given on the command line.\n" );
        goto usage;
    }

    if ( nVarsMax < 2 || nVarsMax > 6 )
    {
        fprintf( pErr, "The max number of variables (%d) should be more than 1 and less than 7.\n", nVarsMax );
        goto usage;
    }

    // get the input file name
    FileName = argv[globalUtilOptind];
    if ( (pFile = Io_FileOpen( FileName, "open_path", "r", 0 )) == NULL )
//    if ( (pFile = fopen( FileName, "r" )) == NULL )
    {
        fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
        if (( FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL ) ))
            fprintf( pErr, "Did you mean \"%s\"?", FileName );
        fprintf( pErr, "\n" );
        return 1;
    }
    fclose( pFile );

    // set the new network
    pLib = Mio_LibraryRead( FileName, ExcludeFile, fVerbose );
    if ( pLib == NULL )
    {
        fprintf( pErr, "Reading library has failed.\n" );
        goto usage;
    }

    // compute the gates
    Super_Precompute( pLib, nVarsMax, nLevels, DelayLimit, AreaLimit, TimeLimit, fSkipInvs, fWriteOldFormat, fVerbose );

    // delete the library
    Mio_LibraryDelete( pLib );
    return 0;

usage:
    fprintf( pErr, "usage: super [-i num] [-l num] [-d float] [-a float] [-t num] [-sovh] <genlib_file>\n");
    fprintf( pErr, "\t         precomputes the supergates for the given GENLIB library\n" );  
    fprintf( pErr, "\t-i num   : the max number of supergate inputs [default = %d]\n", nVarsMax );
    fprintf( pErr, "\t-l num   : the max number of levels of gates [default = %d]\n", nLevels );
	fprintf( pErr, "\t-d float : the max delay of the supergates [default = %.2f]\n", DelayLimit );
	fprintf( pErr, "\t-a float : the max area of the supergates [default = %.2f]\n", AreaLimit );
    fprintf( pErr, "\t-t num   : the approximate runtime limit in seconds [default = %d]\n", TimeLimit );
    fprintf( pErr, "\t-s       : toggle the use of inverters at the inputs [default = %s]\n", (fSkipInvs? "no": "yes") );
    fprintf( pErr, "\t-o       : toggle dumping the supergate library in old format [default = %s]\n", (fWriteOldFormat? "yes": "no") );
    fprintf( pErr, "\t-e file  : file contains list of genlib gates to exclude\n" );
    fprintf( pErr, "\t-v       : enable verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
    fprintf( pErr, "\t-h       : print the help message\n");
    fprintf( pErr, "\n");
    fprintf( pErr, "\tHere is a piece of advice on precomputing supergate libraries:\n");
    fprintf( pErr, "\t\n");
    fprintf( pErr, "\tStart with the number of inputs equal to 5 (-i 5), the number of \n");
    fprintf( pErr, "\tlevels equal to 3 (-l 3), the delay equal to 2-3 delays of inverter, \n");
    fprintf( pErr, "\tthe area equal to 3-4 areas of two input NAND, and runtime limit equal \n");
    fprintf( pErr, "\tto 10 seconds (-t 10). Run precomputation and learn from the result.\n");
    fprintf( pErr, "\tDetermine what parameter is most constraining and try to increase \n");
    fprintf( pErr, "\tthe value of that parameter. The goal is to have a well-balanced\n");
    fprintf( pErr, "\tset of constraints and the resulting supergate library containing\n");
    fprintf( pErr, "\tapproximately 100K-200K supergates. Typically, it is better to increase\n");
    fprintf( pErr, "\tdelay limit rather than area limit, because having large-area supergates\n");
    fprintf( pErr, "\tmay result in a considerable increase in area.\n");
    fprintf( pErr, "\t\n");
    fprintf( pErr, "\tNote that a good supergate library for experiments typically can be \n");
    fprintf( pErr, "\tprecomputed in 30 sec. Increasing the runtime limit makes sense when\n");
    fprintf( pErr, "\tother parameters are well-balanced and it is needed to enumerate more\n");
    fprintf( pErr, "\tchoices to have a good result. In the end, to compute the final library\n");
    fprintf( pErr, "\tthe runtime can be set to 300 sec to ensure the ultimate quality.\n");
    fprintf( pErr, "\tIn some cases, the runtime has to be reduced if the supergate library\n");
    fprintf( pErr, "\tcontains too many supergates (> 500K).\n");
    fprintf( pErr, "\t\n");
    fprintf( pErr, "\tWhen precomputing libraries of 6 inputs (-i 6), start with even more \n");
    fprintf( pErr, "\trestricted parameters and gradually increase them until the goal is met.\n");
    fprintf( pErr, "\t\n");
    return 1;       /* error exit */
}
Exemple #5
0
/**Function*************************************************************

  Synopsis    [Reads the library file.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Map_LibraryReadFile( Map_SuperLib_t * pLib, FILE * pFile )
{
    ProgressBar * pProgress;
    char pBuffer[5000];
    FILE * pFileGen;
    Map_Super_t * pGate;
    char * pTemp = NULL; // Suppress "might be used uninitialized"
    char * pLibName;
    int nCounter, nGatesTotal;
    unsigned uCanon[2];
    int RetValue;

    // skip empty and comment lines
    while ( fgets( pBuffer, 2000, pFile ) != NULL )
    {
        // skip leading spaces
        for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
        // skip comment lines and empty lines
        if ( *pTemp != 0 && *pTemp != '#' )
            break;
    }

    // get the genlib file name
    pLibName = strtok( pTemp, " \t\r\n" );
    if ( strcmp( pLibName, "GATE" ) == 0 )
    {
        printf( "The input file \"%s\" looks like a genlib file and not a supergate library file.\n", pLib->pName );
        return 0;
    }
    pFileGen = fopen( pLibName, "r" );
    if ( pFileGen == NULL )
    {
        printf( "Cannot open the genlib file \"%s\".\n", pLibName );
        return 0;
    }
    fclose( pFileGen );

    // read the genlib library
    pLib->pGenlib = Mio_LibraryRead( pLibName, NULL, 0, 0 );
    if ( pLib->pGenlib == NULL )
    {
        printf( "Cannot read genlib file \"%s\".\n", pLibName );
        return 0;
    }

    // read the number of variables
    RetValue = fscanf( pFile, "%d\n", &pLib->nVarsMax );
    if ( pLib->nVarsMax < 2 || pLib->nVarsMax > 10 )
    {
        printf( "Suspicious number of variables (%d).\n", pLib->nVarsMax );
        return 0;
    }

    // read the number of gates
    RetValue = fscanf( pFile, "%d\n", &nGatesTotal );
    if ( nGatesTotal < 1 || nGatesTotal > 10000000 )
    {
        printf( "Suspicious number of gates (%d).\n", nGatesTotal );
        return 0;
    }

    // read the lines
    nCounter = 0;
    pProgress = Extra_ProgressBarStart( stdout, nGatesTotal );
    while ( fgets( pBuffer, 5000, pFile ) != NULL )
    {
        for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
        if ( pTemp[0] == '\0' )
            continue;
        // get the gate
        pGate = Map_LibraryReadGate( pLib, pTemp, pLib->nVarsMax );
        assert( pGate->Num == nCounter + 1 );
        // count the number of parentheses in the formula - this is the number of gates
        for ( pTemp = pGate->pFormula; *pTemp; pTemp++ )
            pGate->nGates += (*pTemp == '(');
        // verify the truth table
        assert( Map_LibraryTruthVerify(pLib, pGate) );

        // find the N-canonical form of this supergate
        pGate->nPhases = Map_CanonComputeSlow( pLib->uTruths, pLib->nVarsMax, pLib->nVarsMax, pGate->uTruth, pGate->uPhases, uCanon );
        // add the supergate into the table by its N-canonical table
        Map_SuperTableInsertC( pLib->tTableC, uCanon, pGate );
        // update the progress bar
        Extra_ProgressBarUpdate( pProgress, ++nCounter, NULL );
    }
    Extra_ProgressBarStop( pProgress );
    pLib->nSupersAll = nCounter;
    if ( nCounter != nGatesTotal )
        printf( "The number of gates read (%d) is different what the file says (%d).\n", nGatesTotal, nCounter );
    return 1;
}
Exemple #6
0
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
{
    FILE * pFile;
    FILE * pOut, * pErr;
    Mio_Library_t * pLib;
    Amap_Lib_t * pLib2;
    char * pFileName;
    char * pExcludeFile = NULL;
    int fVerbose;
    double WireDelay;
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
    WireDelay   = 0.0;
    fVerbose = 1;
    Extra_UtilGetoptReset();
    while ( (c = Extra_UtilGetopt(argc, argv, "WEvh")) != EOF ) 
    {
        switch (c) 
        {
            case 'W':
                if ( globalUtilOptind >= argc )
                {
                    Abc_Print( -1, "Command line switch \"-W\" should be followed by a floating point number.\n" );
                    goto usage;
                }
                WireDelay = (float)atof(argv[globalUtilOptind]);
                globalUtilOptind++;
                if ( WireDelay <= 0.0 ) 
                    goto usage;
                break;
            case 'E':
                if ( globalUtilOptind >= argc )
                {
                    Abc_Print( -1, "Command line switch \"-E\" should be followed by a file name.\n" );
                    goto usage;
                }
                pExcludeFile = argv[globalUtilOptind];
                globalUtilOptind++;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
    {
        goto usage;
    }

    // get the input file name
    pFileName = argv[globalUtilOptind];
    if ( (pFile = Io_FileOpen( pFileName, "open_path", "r", 0 )) == NULL )
    {
        fprintf( pErr, "Cannot open input file \"%s\". ", pFileName );
        if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".genlib", ".lib", ".scl", ".g", NULL )) )
            fprintf( pErr, "Did you mean \"%s\"?", pFileName );
        fprintf( pErr, "\n" );
        return 1;
    }
    fclose( pFile );

    // set the new network
    pLib = Mio_LibraryRead( pFileName, NULL, pExcludeFile, fVerbose );  
    if ( pLib == NULL )
    {
        fprintf( pErr, "Reading genlib library has failed.\n" );
        return 1;
    }
    if ( fVerbose )
        printf( "Entered genlib library with %d gates from file \"%s\".\n", Mio_LibraryReadGateNum(pLib), pFileName );

    // add the fixed number (wire delay) to all delays in the library
    if ( WireDelay != 0.0 )
        Mio_LibraryShiftDelay( pLib, WireDelay );

    // prepare libraries
    Mio_UpdateGenlib( pLib );

    // replace the current library
    pLib2 = Amap_LibReadAndPrepare( pFileName, NULL, 0, 0 );  
    if ( pLib2 == NULL )
    {
        fprintf( pErr, "Reading second genlib library has failed.\n" );
        return 1;
    }
    Abc_FrameSetLibGen2( pLib2 );
    return 0;

usage:
    fprintf( pErr, "usage: read_genlib [-W float] [-E filename] [-vh]\n");
    fprintf( pErr, "\t           read the library from a genlib file\n" );  
    fprintf( pErr, "\t           (if the library contains more than one gate\n" );  
    fprintf( pErr, "\t           with the same Boolean function, only the gate\n" );  
    fprintf( pErr, "\t           with the smallest area will be used)\n" );  
    fprintf( pErr, "\t-W float : wire delay (added to pin-to-pin gate delays) [default = %g]\n", WireDelay );  
    fprintf( pErr, "\t-E file :  the file name with gates to be excluded [default = none]\n" );
    fprintf( pErr, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
    fprintf( pErr, "\t-h       : enable verbose output\n");
    return 1;       
}