diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/if/if.h | 27 | ||||
-rw-r--r-- | src/map/if/ifCom.c | 366 | ||||
-rw-r--r-- | src/map/if/ifLibBox.c | 254 | ||||
-rw-r--r-- | src/map/if/ifLibLut.c (renamed from src/map/if/ifLib.c) | 6 | ||||
-rw-r--r-- | src/map/if/module.make | 6 |
5 files changed, 653 insertions, 6 deletions
diff --git a/src/map/if/if.h b/src/map/if/if.h index 4505f6d4..a2d047af 100644 --- a/src/map/if/if.h +++ b/src/map/if/if.h @@ -312,6 +312,23 @@ struct If_And_t_ unsigned Delay : 16; // delay }; +typedef struct If_Box_t_ If_Box_t; +struct If_Box_t_ +{ + char * pName; + int Id; + int fWhite; + int nPis; + int nPos; + int * pDelays; +}; + +typedef struct If_LibBox_t_ If_LibBox_t; +struct If_LibBox_t_ +{ + Vec_Ptr_t * vBoxes; +}; + static inline If_Obj_t * If_Regular( If_Obj_t * p ) { return (If_Obj_t *)((ABC_PTRUINT_T)(p) & ~01); } static inline If_Obj_t * If_Not( If_Obj_t * p ) { return (If_Obj_t *)((ABC_PTRUINT_T)(p) ^ 01); } static inline If_Obj_t * If_NotCond( If_Obj_t * p, int c ) { return (If_Obj_t *)((ABC_PTRUINT_T)(p) ^ (c)); } @@ -481,9 +498,17 @@ extern void If_LutLibFree( If_Lib_t * pLutLib ); extern void If_LutLibPrint( If_Lib_t * pLutLib ); extern int If_LutLibDelaysAreDiscrete( If_Lib_t * pLutLib ); extern int If_LutLibDelaysAreDifferent( If_Lib_t * pLutLib ); -extern If_Lib_t * If_SetSimpleLutLib( int nLutSize ); +extern If_Lib_t * If_LutLibSetSimple( int nLutSize ); extern float If_LutLibFastestPinDelay( If_Lib_t * p ); extern float If_LutLibSlowestPinDelay( If_Lib_t * p ); +/*=== ifLibBox.c =============================================================*/ +extern If_LibBox_t * If_LibBoxStart(); +extern void If_LibBoxFree( If_LibBox_t * p ); +extern If_Box_t * If_LibBoxReadBox( If_LibBox_t * p, int Id ); +extern void If_LibBoxAdd( If_LibBox_t * p, If_Box_t * pBox ); +extern If_LibBox_t * If_LibBoxRead( char * pFileName ); +extern void If_LibBoxPrint( FILE * pFile, If_LibBox_t * p ); +extern void If_LibBoxWrite( char * pFileName, If_LibBox_t * p ); /*=== ifMan.c =============================================================*/ extern If_Man_t * If_ManStart( If_Par_t * pPars ); extern void If_ManRestart( If_Man_t * p ); diff --git a/src/map/if/ifCom.c b/src/map/if/ifCom.c new file mode 100644 index 00000000..a6af038f --- /dev/null +++ b/src/map/if/ifCom.c @@ -0,0 +1,366 @@ +/**CFile**************************************************************** + + FileName [ifCom.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [FPGA mapping based on priority cuts.] + + Synopsis [Command handlers.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - November 21, 2006.] + + Revision [$Id: ifCom.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "if.h" +#include "base/main/main.h" + +ABC_NAMESPACE_IMPL_START + + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +static int If_CommandReadLut ( Abc_Frame_t * pAbc, int argc, char **argv ); +static int If_CommandPrintLut( Abc_Frame_t * pAbc, int argc, char **argv ); +static int If_CommandReadBox ( Abc_Frame_t * pAbc, int argc, char **argv ); +static int If_CommandPrintBox( Abc_Frame_t * pAbc, int argc, char **argv ); + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Package initialization procedure.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void If_Init( Abc_Frame_t * pAbc ) +{ + // set the default library + If_Lib_t s_LutLib = { "lutlib", 4, 0, {0,1,1,1,1}, {{0},{1},{1},{1},{1}} }; + Abc_FrameSetLibLut( If_LutLibDup(&s_LutLib) ); + + Cmd_CommandAdd( pAbc, "FPGA mapping", "read_lut", If_CommandReadLut, 0 ); + Cmd_CommandAdd( pAbc, "FPGA mapping", "print_lut", If_CommandPrintLut, 0 ); + + Cmd_CommandAdd( pAbc, "FPGA mapping", "read_box", If_CommandReadBox, 0 ); + Cmd_CommandAdd( pAbc, "FPGA mapping", "print_box", If_CommandPrintBox, 0 ); +} + +/**Function************************************************************* + + Synopsis [Package ending procedure.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void If_End( Abc_Frame_t * pAbc ) +{ + If_LutLibFree( (If_Lib_t *) Abc_FrameReadLibLut() ); + If_LibBoxFree( (If_LibBox_t *)Abc_FrameReadLibBox() ); +} + +/**Function************************************************************* + + Synopsis [Command procedure to read LUT libraries.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int If_CommandReadLut( Abc_Frame_t * pAbc, int argc, char **argv ) +{ + FILE * pFile; + FILE * pOut, * pErr; + If_Lib_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 = 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 = If_LutLibRead( FileName ); + if ( pLib == NULL ) + { + fprintf( pErr, "Reading LUT library has failed.\n" ); + goto usage; + } + // replace the current library + If_LutLibFree( (If_Lib_t *)Abc_FrameReadLibLut() ); + Abc_FrameSetLibLut( pLib ); + return 0; + +usage: + fprintf( pErr, "\nusage: read_lut [-vh]\n"); + fprintf( pErr, "\t read the LUT library from the file\n" ); + fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") ); + fprintf( pErr, "\t-h : print the command usage\n"); + fprintf( pErr, "\t \n"); + fprintf( pErr, "\t File format for a LUT library:\n"); + fprintf( pErr, "\t (the default library is shown)\n"); + fprintf( pErr, "\t \n"); + fprintf( pErr, "\t # The area/delay of k-variable LUTs:\n"); + fprintf( pErr, "\t # k area delay\n"); + fprintf( pErr, "\t 1 1 1\n"); + fprintf( pErr, "\t 2 2 2\n"); + fprintf( pErr, "\t 3 4 3\n"); + fprintf( pErr, "\t 4 8 4\n"); + fprintf( pErr, "\t 5 16 5\n"); + fprintf( pErr, "\t 6 32 6\n"); + return 1; /* error exit */ +} + +/**Function************************************************************* + + Synopsis [Command procedure to read LUT libraries.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int If_CommandPrintLut( Abc_Frame_t * pAbc, int argc, char **argv ) +{ + FILE * pOut, * pErr; + Abc_Ntk_t * pNet; + 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 ) + goto usage; + + // set the new network + If_LutLibPrint( (If_Lib_t *)Abc_FrameReadLibLut() ); + return 0; + +usage: + fprintf( pErr, "\nusage: print_lut [-vh]\n"); + fprintf( pErr, "\t print the current LUT library\n" ); + fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") ); + fprintf( pErr, "\t-h : print the command usage\n"); + return 1; /* error exit */ +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int If_CommandReadBox( Abc_Frame_t * pAbc, int argc, char **argv ) +{ + FILE * pFile; + FILE * pOut, * pErr; + If_LibBox_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 = 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 = If_LibBoxRead( FileName ); + if ( pLib == NULL ) + { + fprintf( pErr, "Reading LUT library has failed.\n" ); + goto usage; + } + // replace the current library + If_LibBoxFree( (If_LibBox_t *)Abc_FrameReadLibBox() ); + Abc_FrameSetLibBox( pLib ); + return 0; + +usage: + fprintf( pErr, "\nusage: read_box [-vh]\n"); + fprintf( pErr, "\t read the box library from the file\n" ); + fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") ); + fprintf( pErr, "\t-h : print the command usage\n"); + return 1; /* error exit */ +} + +/**Function************************************************************* + + Synopsis [Command procedure to read LUT libraries.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int If_CommandPrintBox( Abc_Frame_t * pAbc, int argc, char **argv ) +{ + FILE * pOut, * pErr; + Abc_Ntk_t * pNet; + 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 ) + goto usage; + + // set the new network + If_LibBoxPrint( stdout, (If_LibBox_t *)Abc_FrameReadLibBox() ); + return 0; + +usage: + fprintf( pErr, "\nusage: print_box [-vh]\n"); + fprintf( pErr, "\t print the current box library\n" ); + fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") ); + fprintf( pErr, "\t-h : print the command usage\n"); + return 1; /* error exit */ +} + + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + +ABC_NAMESPACE_IMPL_END + diff --git a/src/map/if/ifLibBox.c b/src/map/if/ifLibBox.c new file mode 100644 index 00000000..678f4e68 --- /dev/null +++ b/src/map/if/ifLibBox.c @@ -0,0 +1,254 @@ +/**CFile**************************************************************** + + FileName [ifLibBox.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [FPGA mapping based on priority cuts.] + + Synopsis [Box library.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - November 21, 2006.] + + Revision [$Id: ifLibBox.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "if.h" +#include "misc/extra/extra.h" + +ABC_NAMESPACE_IMPL_START + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +#define If_LibBoxForEachBox( p, pBox, i ) \ + Vec_PtrForEachEntry( If_Box_t *, p->vBoxes, pBox, i ) if ( pBox == NULL ) {} else + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +If_Box_t * If_BoxStart( char * pName, int Id, int fWhite, int nPis, int nPos ) +{ + If_Box_t * p; + p = ABC_CALLOC( If_Box_t, 1 ); + p->pName = pName; // consumes memory + p->Id = Id; + p->fWhite = fWhite; + p->nPis = nPis; + p->nPos = nPos; + p->pDelays = ABC_CALLOC( int, nPis * nPos ); + return p; +} +If_Box_t * If_BoxDup( If_Box_t * p ) +{ + If_Box_t * pNew = NULL; + return pNew; +} +void If_BoxFree( If_Box_t * p ) +{ + ABC_FREE( p->pDelays ); + ABC_FREE( p->pName ); + ABC_FREE( p ); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +If_LibBox_t * If_LibBoxStart() +{ + If_LibBox_t * p; + p = ABC_CALLOC( If_LibBox_t, 1 ); + p->vBoxes = Vec_PtrAlloc( 100 ); + return p; +} +If_LibBox_t * If_LibBoxDup( If_Box_t * p ) +{ + If_LibBox_t * pNew = NULL; + return pNew; +} +void If_LibBoxFree( If_LibBox_t * p ) +{ + If_Box_t * pBox; + int i; + if ( p == NULL ) + return; + If_LibBoxForEachBox( p, pBox, i ) + If_BoxFree( pBox ); + Vec_PtrFree( p->vBoxes ); + ABC_FREE( p ); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +If_Box_t * If_LibBoxReadBox( If_LibBox_t * p, int Id ) +{ + return (If_Box_t *)Vec_PtrEntry( p->vBoxes, Id ); +} +void If_LibBoxAdd( If_LibBox_t * p, If_Box_t * pBox ) +{ + if ( pBox->Id >= Vec_PtrSize(p->vBoxes) ) + Vec_PtrFillExtra( p->vBoxes, 2 * pBox->Id + 10, NULL ); + assert( Vec_PtrEntry( p->vBoxes, pBox->Id ) == NULL ); + Vec_PtrWriteEntry( p->vBoxes, pBox->Id, pBox ); +} + + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +char * If_LibBoxGetToken( FILE * pFile ) +{ + static char pBuffer[1000]; + char c, * pTemp = pBuffer; + while ( (c = fgetc(pFile)) != EOF ) + { + if ( c == '#' ) + { + while ( (c = fgetc(pFile)) != EOF ) + if ( c == '\n' ) + break; + } + if ( c == ' ' || c == '\t' || c == '\n' || c == '\r' ) + { + if ( pTemp > pBuffer ) + break; + continue; + } + *pTemp++ = c; + } + *pTemp = 0; + return pTemp > pBuffer ? pBuffer : NULL; +} +If_LibBox_t * If_LibBoxRead( char * pFileName ) +{ + FILE * pFile; + If_LibBox_t * p; + If_Box_t * pBox; + char * pToken; + char * pName; + int i, Id, fWhite, nPis, nPos; + pFile = fopen( pFileName, "rb" ); + if ( pFile == NULL ) + { + printf( "Cannot open file \"%s\".\n", pFileName ); + return NULL; + } + // get the library name + pToken = If_LibBoxGetToken( pFile ); + if ( pToken == NULL ) + { + printf( "Cannot read library name from file \"%s\".\n", pFileName ); + return NULL; + } + // create library + p = If_LibBoxStart(); + while ( pToken ) + { + // save name + pName = Abc_UtilStrsav(pToken); + // save ID + pToken = If_LibBoxGetToken( pFile ); + Id = atoi( pToken ); + // save white/black + pToken = If_LibBoxGetToken( pFile ); + fWhite = atoi( pToken ); + // save PIs + pToken = If_LibBoxGetToken( pFile ); + nPis = atoi( pToken ); + // save POs + pToken = If_LibBoxGetToken( pFile ); + nPos = atoi( pToken ); + // create box + pBox = If_BoxStart( pName, Id, fWhite, nPis, nPos ); + If_LibBoxAdd( p, pBox ); + // read the table + for ( i = 0; i < nPis * nPos; i++ ) + { + pToken = If_LibBoxGetToken( pFile ); + pBox->pDelays[i] = (pToken[0] == '-') ? -1 : atoi(pToken); + } + // extract next name + pToken = If_LibBoxGetToken( pFile ); + } + fclose( pFile ); + return p; +} +void If_LibBoxPrint( FILE * pFile, If_LibBox_t * p ) +{ + If_Box_t * pBox; + int i, j, k; + fprintf( pFile, "# Box library written by ABC on %s.\n", Extra_TimeStamp() ); + If_LibBoxForEachBox( p, pBox, i ) + { + fprintf( pFile, "%s %d %d %d %d\n", pBox->pName, pBox->Id, pBox->fWhite, pBox->nPis, pBox->nPos ); + for ( j = 0; j < pBox->nPos; j++, printf("\n") ) + for ( k = 0; k < pBox->nPis; k++ ) + if ( pBox->pDelays[j * pBox->nPis + k] == -1 ) + fprintf( pFile, " - " ); + else + fprintf( pFile, "%5d ", pBox->pDelays[j * pBox->nPis + k] ); + } +} +void If_LibBoxWrite( char * pFileName, If_LibBox_t * p ) +{ + FILE * pFile; + pFile = fopen( pFileName, "wb" ); + if ( pFile == NULL ) + { + printf( "Cannot open file \"%s\".\n", pFileName ); + return; + } + If_LibBoxPrint( pFile, p ); + fclose( pFile ); +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + +ABC_NAMESPACE_IMPL_END + diff --git a/src/map/if/ifLib.c b/src/map/if/ifLibLut.c index 3822302e..b1e6c680 100644 --- a/src/map/if/ifLib.c +++ b/src/map/if/ifLibLut.c @@ -1,6 +1,6 @@ /**CFile**************************************************************** - FileName [ifLib.c] + FileName [ifLibLut.c] SystemName [ABC: Logic synthesis and verification system.] @@ -14,7 +14,7 @@ Date [Ver. 1.0. Started - November 21, 2006.] - Revision [$Id: ifLib.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $] + Revision [$Id: ifLibLut.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $] ***********************************************************************/ @@ -276,7 +276,7 @@ int If_LutLibDelaysAreDifferent( If_Lib_t * pLutLib ) SeeAlso [] ***********************************************************************/ -If_Lib_t * If_SetSimpleLutLib( int nLutSize ) +If_Lib_t * If_LutLibSetSimple( int nLutSize ) { If_Lib_t s_LutLib10= { "lutlib",10, 0, {0,1,1,1,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1},{1},{1},{1}} }; If_Lib_t s_LutLib9 = { "lutlib", 9, 0, {0,1,1,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1},{1},{1}} }; diff --git a/src/map/if/module.make b/src/map/if/module.make index eda5e13e..2ae46fc0 100644 --- a/src/map/if/module.make +++ b/src/map/if/module.make @@ -1,10 +1,12 @@ -SRC += src/map/if/ifCore.c \ +SRC += src/map/if/ifCom.c \ + src/map/if/ifCore.c \ src/map/if/ifCut.c \ src/map/if/ifDec07.c \ src/map/if/ifDec08.c \ src/map/if/ifDec10.c \ src/map/if/ifDec16.c \ - src/map/if/ifLib.c \ + src/map/if/ifLibBox.c \ + src/map/if/ifLibLut.c \ src/map/if/ifMan.c \ src/map/if/ifMap.c \ src/map/if/ifReduce.c \ |