diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2013-09-17 13:16:20 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2013-09-17 13:16:20 -0700 |
commit | 7d3976a76353b4a89588925285e80ea33efa0797 (patch) | |
tree | 017fa2a4eda34a7b53078ab44c55850cc4136815 /src/map/scl | |
parent | 5df166fce17e7729b590d799da753f6ab811886b (diff) | |
download | abc-7d3976a76353b4a89588925285e80ea33efa0797.tar.gz abc-7d3976a76353b4a89588925285e80ea33efa0797.tar.bz2 abc-7d3976a76353b4a89588925285e80ea33efa0797.zip |
Unifying standard cell library representations.
Diffstat (limited to 'src/map/scl')
-rw-r--r-- | src/map/scl/scl.c | 214 | ||||
-rw-r--r-- | src/map/scl/sclLib.h | 4 | ||||
-rw-r--r-- | src/map/scl/sclLibScl.c | 6 | ||||
-rw-r--r-- | src/map/scl/sclLibUtil.c | 122 | ||||
-rw-r--r-- | src/map/scl/sclLiberty.c | 2 |
5 files changed, 255 insertions, 93 deletions
diff --git a/src/map/scl/scl.c b/src/map/scl/scl.c index f8545646..2957a325 100644 --- a/src/map/scl/scl.c +++ b/src/map/scl/scl.c @@ -29,8 +29,9 @@ ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// static int Scl_CommandReadLib ( Abc_Frame_t * pAbc, int argc, char **argv ); -static int Scl_CommandRead ( Abc_Frame_t * pAbc, int argc, char **argv ); -static int Scl_CommandWrite ( Abc_Frame_t * pAbc, int argc, char **argv ); +static int Scl_CommandWriteLib( Abc_Frame_t * pAbc, int argc, char **argv ); +static int Scl_CommandReadScl ( Abc_Frame_t * pAbc, int argc, char **argv ); +static int Scl_CommandWriteScl( Abc_Frame_t * pAbc, int argc, char **argv ); static int Scl_CommandPrintLib( Abc_Frame_t * pAbc, int argc, char **argv ); static int Scl_CommandDumpGen ( Abc_Frame_t * pAbc, int argc, char **argv ); static int Scl_CommandPrintGS ( Abc_Frame_t * pAbc, int argc, char **argv ); @@ -87,9 +88,10 @@ void Abc_SclLoad( SC_Lib * pLib, SC_Lib ** ppScl ) void Scl_Init( Abc_Frame_t * pAbc ) { Cmd_CommandAdd( pAbc, "SCL mapping", "read_lib", Scl_CommandReadLib, 0 ); - Cmd_CommandAdd( pAbc, "SCL mapping", "read_scl", Scl_CommandRead, 0 ); - Cmd_CommandAdd( pAbc, "SCL mapping", "write_scl", Scl_CommandWrite, 0 ); + Cmd_CommandAdd( pAbc, "SCL mapping", "write_lib", Scl_CommandWriteLib, 0 ); Cmd_CommandAdd( pAbc, "SCL mapping", "print_lib", Scl_CommandPrintLib, 0 ); + Cmd_CommandAdd( pAbc, "SCL mapping", "read_scl", Scl_CommandReadScl, 0 ); + Cmd_CommandAdd( pAbc, "SCL mapping", "write_scl", Scl_CommandWriteScl, 0 ); Cmd_CommandAdd( pAbc, "SCL mapping", "dump_genlib", Scl_CommandDumpGen, 0 ); Cmd_CommandAdd( pAbc, "SCL mapping", "print_gs", Scl_CommandPrintGS, 0 ); Cmd_CommandAdd( pAbc, "SCL mapping", "stime", Scl_CommandStime, 0 ); @@ -128,9 +130,9 @@ int Scl_CommandReadLib( Abc_Frame_t * pAbc, int argc, char ** argv ) FILE * pFile; SC_Lib * pLib; int c, fDump = 0; - float Slew = 200; - float Gain = 100; - int nGatesMin = 4; + float Slew = 0; + float Gain = 0; + int nGatesMin = 0; int fVerbose = 1; int fVeryVerbose = 0; @@ -210,7 +212,7 @@ int Scl_CommandReadLib( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_SclWriteLiberty( Extra_FileNameGenericAppend(pFileName, "_temp.lib"), (SC_Lib *)pAbc->pLibScl ); // extract genlib library if ( pAbc->pLibScl ) - Abc_SclDeriveGenlib( pAbc->pLibScl, Slew, Gain, nGatesMin ); + Abc_SclInstallGenlib( pAbc->pLibScl, Slew, Gain, nGatesMin ); return 0; usage: @@ -227,72 +229,6 @@ usage: return 1; } - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Scl_CommandRead( Abc_Frame_t * pAbc, int argc, char ** argv ) -{ - FILE * pFile; - SC_Lib * pLib; - char * pFileName; - int c, fDump = 0; - - Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "dh" ) ) != EOF ) - { - switch ( c ) - { - case 'd': - fDump ^= 1; - break; - case 'h': - goto usage; - default: - goto usage; - } - } - if ( argc != globalUtilOptind + 1 ) - goto usage; - - // get the input file name - pFileName = argv[globalUtilOptind]; - if ( (pFile = fopen( pFileName, "rb" )) == NULL ) - { - fprintf( pAbc->Err, "Cannot open input file \"%s\". \n", pFileName ); - return 1; - } - fclose( pFile ); - - // read new library - pLib = Abc_SclReadFromFile( pFileName ); - if ( pLib == NULL ) - { - fprintf( pAbc->Err, "Reading SCL library from file \"%s\" has failed. \n", pFileName ); - return 1; - } - Abc_SclLoad( pLib, (SC_Lib **)&pAbc->pLibScl ); - if ( fDump ) - Abc_SclWriteLiberty( Extra_FileNameGenericAppend(pFileName, "_temp.lib"), (SC_Lib *)pAbc->pLibScl ); - return 0; - -usage: - fprintf( pAbc->Err, "usage: read_scl [-dh] <file>\n" ); - fprintf( pAbc->Err, "\t reads extracted Liberty library from file\n" ); - fprintf( pAbc->Err, "\t-d : toggle dumping the parsed library into file \"*_temp.lib\" [default = %s]\n", fDump? "yes": "no" ); - fprintf( pAbc->Err, "\t-h : prints the command summary\n" ); - fprintf( pAbc->Err, "\t<file> : the name of a file to read\n" ); - return 1; -} - /**Function************************************************************* Synopsis [] @@ -304,7 +240,7 @@ usage: SeeAlso [] ***********************************************************************/ -int Scl_CommandWrite( Abc_Frame_t * pAbc, int argc, char **argv ) +int Scl_CommandWriteLib( Abc_Frame_t * pAbc, int argc, char **argv ) { FILE * pFile; char * pFileName; @@ -338,12 +274,12 @@ int Scl_CommandWrite( Abc_Frame_t * pAbc, int argc, char **argv ) fclose( pFile ); // save current library - Abc_SclWriteScl( pFileName, (SC_Lib *)pAbc->pLibScl ); + Abc_SclWriteLiberty( pFileName, (SC_Lib *)pAbc->pLibScl ); return 0; usage: - fprintf( pAbc->Err, "usage: write_scl [-h] <file>\n" ); - fprintf( pAbc->Err, "\t write extracted Liberty library into file\n" ); + fprintf( pAbc->Err, "usage: write_lib [-h] <file>\n" ); + fprintf( pAbc->Err, "\t write current Liberty library into file\n" ); fprintf( pAbc->Err, "\t-h : print the help massage\n" ); fprintf( pAbc->Err, "\t<file> : the name of the file to write\n" ); return 1; @@ -427,6 +363,128 @@ usage: return 1; } + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Scl_CommandReadScl( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + FILE * pFile; + SC_Lib * pLib; + char * pFileName; + int c, fDump = 0; + + Extra_UtilGetoptReset(); + while ( ( c = Extra_UtilGetopt( argc, argv, "dh" ) ) != EOF ) + { + switch ( c ) + { + case 'd': + fDump ^= 1; + break; + case 'h': + goto usage; + default: + goto usage; + } + } + if ( argc != globalUtilOptind + 1 ) + goto usage; + + // get the input file name + pFileName = argv[globalUtilOptind]; + if ( (pFile = fopen( pFileName, "rb" )) == NULL ) + { + fprintf( pAbc->Err, "Cannot open input file \"%s\". \n", pFileName ); + return 1; + } + fclose( pFile ); + + // read new library + pLib = Abc_SclReadFromFile( pFileName ); + if ( pLib == NULL ) + { + fprintf( pAbc->Err, "Reading SCL library from file \"%s\" has failed. \n", pFileName ); + return 1; + } + Abc_SclLoad( pLib, (SC_Lib **)&pAbc->pLibScl ); + if ( fDump ) + Abc_SclWriteLiberty( Extra_FileNameGenericAppend(pFileName, "_temp.lib"), (SC_Lib *)pAbc->pLibScl ); + return 0; + +usage: + fprintf( pAbc->Err, "usage: read_scl [-dh] <file>\n" ); + fprintf( pAbc->Err, "\t reads extracted Liberty library from file\n" ); + fprintf( pAbc->Err, "\t-d : toggle dumping the parsed library into file \"*_temp.lib\" [default = %s]\n", fDump? "yes": "no" ); + fprintf( pAbc->Err, "\t-h : prints the command summary\n" ); + fprintf( pAbc->Err, "\t<file> : the name of a file to read\n" ); + return 1; +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Scl_CommandWriteScl( Abc_Frame_t * pAbc, int argc, char **argv ) +{ + FILE * pFile; + char * pFileName; + int c; + + Extra_UtilGetoptReset(); + while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF ) + { + switch ( c ) + { + case 'h': + goto usage; + default: + goto usage; + } + } + if ( argc != globalUtilOptind + 1 ) + goto usage; + if ( pAbc->pLibScl == NULL ) + { + fprintf( pAbc->Err, "There is no Liberty library available.\n" ); + return 1; + } + // get the input file name + pFileName = argv[globalUtilOptind]; + if ( (pFile = fopen( pFileName, "wb" )) == NULL ) + { + fprintf( pAbc->Err, "Cannot open output file \"%s\". \n", pFileName ); + return 1; + } + fclose( pFile ); + + // save current library + Abc_SclWriteScl( pFileName, (SC_Lib *)pAbc->pLibScl ); + return 0; + +usage: + fprintf( pAbc->Err, "usage: write_scl [-h] <file>\n" ); + fprintf( pAbc->Err, "\t write extracted Liberty library into file\n" ); + fprintf( pAbc->Err, "\t-h : print the help massage\n" ); + fprintf( pAbc->Err, "\t<file> : the name of the file to write\n" ); + return 1; +} + /**Function************************************************************* Synopsis [] diff --git a/src/map/scl/sclLib.h b/src/map/scl/sclLib.h index 0beece23..09f30dd4 100644 --- a/src/map/scl/sclLib.h +++ b/src/map/scl/sclLib.h @@ -234,6 +234,7 @@ static inline void SC_PairMove( SC_Pair * d, SC_Pair * s ) { *d = *s; s static inline int SC_PairEqual( SC_Pair * d, SC_Pair * s ) { return d->rise == s->rise && d->fall == s->fall; } static inline int SC_PairEqualE( SC_Pair * d, SC_Pair * s, float E ) { return d->rise - s->rise < E && s->rise - d->rise < E && d->fall - s->fall < E && s->fall - d->fall < E; } +static inline int SC_LibCellNum( SC_Lib * p ) { return Vec_PtrSize(p->vCells); } static inline SC_Cell * SC_LibCell( SC_Lib * p, int i ) { return (SC_Cell *)Vec_PtrEntry(p->vCells, i); } static inline SC_Pin * SC_CellPin( SC_Cell * p, int i ) { return (SC_Pin *)Vec_PtrEntry(p->vPins, i); } static inline Vec_Wrd_t * SC_CellFunc( SC_Cell * p ) { return SC_CellPin(p, p->n_inputs)->vFunc; } @@ -598,8 +599,7 @@ extern SC_Cell * Abc_SclFindSmallestGate( SC_Cell * p, float CinMin ); extern SC_WireLoad * Abc_SclFindWireLoadModel( SC_Lib * p, float Area ); extern SC_WireLoad * Abc_SclFetchWireLoadModel( SC_Lib * p, char * pName ); extern void Abc_SclDumpGenlib( char * pFileName, SC_Lib * p, float Slew, float Gain, int nGatesMin ); -extern void Abc_SclDeriveGenlib( void * pScl, float Slew, float Gain, int nGatesMin ); - +extern void Abc_SclInstallGenlib( void * pScl, float Slew, float Gain, int nGatesMin ); ABC_NAMESPACE_HEADER_END diff --git a/src/map/scl/sclLibScl.c b/src/map/scl/sclLibScl.c index b08105cb..8f726d1e 100644 --- a/src/map/scl/sclLibScl.c +++ b/src/map/scl/sclLibScl.c @@ -122,7 +122,7 @@ static void Abc_SclReadLibrary( Vec_Str_t * vOut, int * pPos, SC_Lib * p ) for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- ) { SC_Cell * pCell = Abc_SclCellAlloc(); - pCell->Id = Vec_PtrSize(p->vCells); + pCell->Id = SC_LibCellNum(p); Vec_PtrPush( p->vCells, pCell ); pCell->pName = Vec_StrGetS(vOut, pPos); @@ -530,7 +530,7 @@ static void Abc_SclWriteLibraryText( FILE * s, SC_Lib * p ) SC_Pin * pPin; int n_valid_cells; int i, j, k; - fprintf( s, "/* This Liberty file was generated by ABC on %s. */\n", Extra_TimeStamp() ); + fprintf( s, "/* This Liberty file was generated by ABC on %s */\n", Extra_TimeStamp() ); fprintf( s, "/* The original unabridged library came from file \"%s\".*/\n\n", p->pFileName ); // fprintf( s, "%d", ABC_SCL_CUR_VERSION ); @@ -569,7 +569,7 @@ static void Abc_SclWriteLibraryText( FILE * s, SC_Lib * p ) { fprintf( s, " wire_load_selection(\"%s\") {\n", pWLS->pName ); for ( j = 0; j < Vec_FltSize(pWLS->vAreaFrom); j++) - fprintf( s, " wire_load_from_area( %f, %f, \"%s\" );\n", + fprintf( s, " wire_load_from_area( %f, %f, %s );\n", Vec_FltEntry(pWLS->vAreaFrom, j), Vec_FltEntry(pWLS->vAreaTo, j), (char *)Vec_PtrEntry(pWLS->vWireLoadModel, j) ); diff --git a/src/map/scl/sclLibUtil.c b/src/map/scl/sclLibUtil.c index 53792098..48c62512 100644 --- a/src/map/scl/sclLibUtil.c +++ b/src/map/scl/sclLibUtil.c @@ -67,7 +67,7 @@ void Abc_SclHashCells( SC_Lib * p ) SC_Cell * pCell; int i, * pPlace; assert( p->nBins == 0 ); - p->nBins = Abc_PrimeCudd( 5 * Vec_PtrSize(p->vCells) ); + p->nBins = Abc_PrimeCudd( 5 * SC_LibCellNum(p) ); p->pBins = ABC_FALLOC( int, p->nBins ); SC_LibForEachCell( p, pCell, i ) { @@ -494,6 +494,78 @@ void Abc_SclPrintCells( SC_Lib * p, float Slew, float Gain, int fInvOnly, int fS /**Function************************************************************* + Synopsis [Derives simple GENLIB library.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Str_t * Abc_SclProduceGenlibStrSimple( SC_Lib * p ) +{ + char Buffer[200]; + Vec_Str_t * vStr; + SC_Cell * pCell; + SC_Pin * pPin, * pPinOut; + int i, j, k, Count = 2; + // mark skipped cells +// Abc_SclMarkSkippedCells( p ); + vStr = Vec_StrAlloc( 1000 ); + Vec_StrPrintStr( vStr, "GATE _const0_ 0.00 z=CONST0;\n" ); + Vec_StrPrintStr( vStr, "GATE _const1_ 0.00 z=CONST1;\n" ); + SC_LibForEachCell( p, pCell, i ) + { + if ( pCell->n_inputs == 0 ) + continue; + assert( strlen(pCell->pName) < 200 ); + SC_CellForEachPinOut( pCell, pPinOut, j ) + { + Vec_StrPrintStr( vStr, "GATE " ); + sprintf( Buffer, "%-16s", pCell->pName ); + Vec_StrPrintStr( vStr, Buffer ); + Vec_StrPrintStr( vStr, " " ); + sprintf( Buffer, "%7.2f", pCell->area ); + Vec_StrPrintStr( vStr, Buffer ); + Vec_StrPrintStr( vStr, " " ); + Vec_StrPrintStr( vStr, pPinOut->pName ); + Vec_StrPrintStr( vStr, "=" ); + Vec_StrPrintStr( vStr, pPinOut->func_text ? pPinOut->func_text : "?" ); + Vec_StrPrintStr( vStr, ";\n" ); + SC_CellForEachPinIn( pCell, pPin, k ) + { + Vec_StrPrintStr( vStr, " PIN " ); + sprintf( Buffer, "%-4s", pPin->pName ); + Vec_StrPrintStr( vStr, Buffer ); + sprintf( Buffer, " UNKNOWN 1 999 1.00 0.00 1.00 0.00\n" ); + Vec_StrPrintStr( vStr, Buffer ); + } + Count++; + } + } + Vec_StrPrintStr( vStr, "\n.end\n" ); + Vec_StrPush( vStr, '\0' ); +// printf( "GENLIB library with %d gates is produced:\n", Count ); +// printf( "%s", Vec_StrArray(vStr) ); + return vStr; +} +Mio_Library_t * Abc_SclDeriveGenlibSimple( void * pScl ) +{ + SC_Lib * p = (SC_Lib *)pScl; + Vec_Str_t * vStr = Abc_SclProduceGenlibStrSimple( p ); + Mio_Library_t * pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0 ); + Vec_StrFree( vStr ); + if ( pLib ) + printf( "Internally derived GENLIB library \"%s\" with %d gates.\n", p->pName, SC_LibCellNum(p) ); + else + printf( "Reading library has filed.\n" ); + return pLib; +} + + +/**Function************************************************************* + Synopsis [Derive GENLIB library.] Description [] @@ -503,7 +575,7 @@ void Abc_SclPrintCells( SC_Lib * p, float Slew, float Gain, int fInvOnly, int fS SeeAlso [] ***********************************************************************/ -Vec_Str_t * Abc_SclDeriveGenlibStr( SC_Lib * p, float Slew, float Gain, int nGatesMin, int * pnCellCount ) +Vec_Str_t * Abc_SclProduceGenlibStr( SC_Lib * p, float Slew, float Gain, int nGatesMin, int * pnCellCount ) { char Buffer[200]; Vec_Str_t * vStr; @@ -565,8 +637,8 @@ Vec_Str_t * Abc_SclDeriveGenlibStr( SC_Lib * p, float Slew, float Gain, int nGat } void Abc_SclDumpGenlib( char * pFileName, SC_Lib * p, float Slew, float Gain, int nGatesMin ) { - char FileName[1000]; int nCellCount = 0; + char FileName[1000]; Vec_Str_t * vStr; FILE * pFile; if ( pFileName == NULL ) @@ -579,22 +651,52 @@ void Abc_SclDumpGenlib( char * pFileName, SC_Lib * p, float Slew, float Gain, in printf( "Cannot open file \"%s\" for writing.\n", FileName ); return; } - vStr = Abc_SclDeriveGenlibStr( p, Slew, Gain, nGatesMin, &nCellCount ); + vStr = Abc_SclProduceGenlibStr( p, Slew, Gain, nGatesMin, &nCellCount ); fprintf( pFile, "%s", Vec_StrArray(vStr) ); Vec_StrFree( vStr ); fclose( pFile ); printf( "Written GENLIB library with %d gates into file \"%s\".\n", nCellCount, FileName ); } -void Abc_SclDeriveGenlib( void * pScl, float Slew, float Gain, int nGatesMin ) +Mio_Library_t * Abc_SclDeriveGenlib( void * pScl, float Slew, float Gain, int nGatesMin ) { - int nGateCount = 0; - Vec_Str_t * vStr = Abc_SclDeriveGenlibStr( (SC_Lib *)pScl, Slew, Gain, nGatesMin, &nGateCount ); - Vec_Str_t * vStr2 = Vec_StrDup( vStr ); - int RetValue = Mio_UpdateGenlib2( vStr, vStr2, ((SC_Lib *)pScl)->pName, 0 ); + int nCellCount = 0; + SC_Lib * p = (SC_Lib *)pScl; + Vec_Str_t * vStr = Abc_SclProduceGenlibStr( p, Slew, Gain, nGatesMin, &nCellCount ); + Mio_Library_t * pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0 ); + Vec_StrFree( vStr ); + if ( pLib ) + printf( "Internally derived GENLIB library \"%s\" with %d gates.\n", p->pName, nCellCount ); + else + printf( "Reading library has filed.\n" ); + return pLib; +} + +/**Function************************************************************* + + Synopsis [Install library.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_SclInstallGenlib( void * pScl, float Slew, float Gain, int nGatesMin ) +{ + SC_Lib * p = (SC_Lib *)pScl; + Vec_Str_t * vStr, * vStr2; + int RetValue, nGateCount = SC_LibCellNum(p); + if ( Gain == 0 ) + vStr = Abc_SclProduceGenlibStrSimple(p); + else + vStr = Abc_SclProduceGenlibStr( p, Slew, Gain, nGatesMin, &nGateCount ); + vStr2 = Vec_StrDup( vStr ); + RetValue = Mio_UpdateGenlib2( vStr, vStr2, p->pName, 0 ); Vec_StrFree( vStr ); Vec_StrFree( vStr2 ); if ( RetValue ) - printf( "Internally derived GENLIB library \"%s\" with %d gates.\n", ((SC_Lib *)pScl)->pName, nGateCount ); + printf( "Internally derived GENLIB library \"%s\" with %d gates.\n", p->pName, nGateCount ); else printf( "Reading library has filed.\n" ); } diff --git a/src/map/scl/sclLiberty.c b/src/map/scl/sclLiberty.c index e4b14405..f3f31224 100644 --- a/src/map/scl/sclLiberty.c +++ b/src/map/scl/sclLiberty.c @@ -848,6 +848,8 @@ void Scl_LibertyReadWireLoadSelect( Scl_Tree_t * p, Vec_Str_t * vOut ) float First = atof( strtok(pHead, " ,") ); float Second = atof( strtok(NULL, " ,") ); char * pThird = strtok(NULL, " "); + if ( pThird[0] == '\"' ) + assert(pThird[strlen(pThird)-1] == '\"'), pThird[strlen(pThird)-1] = 0, pThird++; Vec_StrPutF_( vOut, First ); Vec_StrPutF_( vOut, Second ); Vec_StrPutS_( vOut, pThird ); |