diff options
Diffstat (limited to 'src/map/mio')
-rw-r--r-- | src/map/mio/mio.c | 22 | ||||
-rw-r--r-- | src/map/mio/mio.h | 5 | ||||
-rw-r--r-- | src/map/mio/mioInt.h | 8 | ||||
-rw-r--r-- | src/map/mio/mioUtils.c | 177 |
4 files changed, 203 insertions, 9 deletions
diff --git a/src/map/mio/mio.c b/src/map/mio/mio.c index 1f7ff612..8648a604 100644 --- a/src/map/mio/mio.c +++ b/src/map/mio/mio.c @@ -286,18 +286,14 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) Amap_Lib_t * pLib2; char * pFileName; char * pExcludeFile = NULL; - int fVerbose; - double WireDelay; - int c; + double WireDelay = 0.0; + int fShortNames = 0; + int c, fVerbose = 1; 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 ) + while ( (c = Extra_UtilGetopt(argc, argv, "WEnvh")) != EOF ) { switch (c) { @@ -321,6 +317,9 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) pExcludeFile = argv[globalUtilOptind]; globalUtilOptind++; break; + case 'n': + fShortNames ^= 1; + break; case 'v': fVerbose ^= 1; break; @@ -358,6 +357,10 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) if ( fVerbose ) printf( "Entered genlib library with %d gates from file \"%s\".\n", Mio_LibraryReadGateNum(pLib), pFileName ); + // convert the library if needed + if ( fShortNames ) + Mio_LibraryShortNames( pLib ); + // add the fixed number (wire delay) to all delays in the library if ( WireDelay != 0.0 ) Mio_LibraryShiftDelay( pLib, WireDelay ); @@ -376,13 +379,14 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) return 0; usage: - fprintf( pErr, "usage: read_genlib [-W float] [-E filename] [-vh]\n"); + fprintf( pErr, "usage: read_genlib [-W float] [-E filename] [-nvh]\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-n : toggle replacing gate/pin names by short strings [default = %s]\n", fShortNames? "yes": "no" ); fprintf( pErr, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" ); fprintf( pErr, "\t-h : enable verbose output\n"); return 1; diff --git a/src/map/mio/mio.h b/src/map/mio/mio.h index 3f5df736..f45cce89 100644 --- a/src/map/mio/mio.h +++ b/src/map/mio/mio.h @@ -213,6 +213,11 @@ extern void Mio_LibraryTransferProfile( Mio_Library_t * pLibDst, Mi extern void Mio_LibraryTransferProfile2( Mio_Library_t * pLibDst, Mio_Library_t * pLibSrc ); extern int Mio_LibraryHasProfile( Mio_Library_t * pLib ); extern void Mio_LibraryCleanProfile2( Mio_Library_t * pLib ); +extern void Mio_LibraryShortNames( Mio_Library_t * pLib ); + +extern void Mio_LibraryMatchesStop( Mio_Library_t * pLib ); +extern void Mio_LibraryMatchesStart( Mio_Library_t * pLib, int fPinFilter, int fPinPerm, int fPinQuick ); +extern void Mio_LibraryMatchesFetch( Mio_Library_t * pLib, Vec_Mem_t ** pvTtMem, Vec_Wec_t ** pvTt2Match, Mio_Cell2_t ** ppCells, int * pnCells, int fPinFilter, int fPinPerm, int fPinQuick ); /*=== sclUtil.c =========================================================*/ extern Mio_Library_t * Abc_SclDeriveGenlibSimple( void * pScl ); diff --git a/src/map/mio/mioInt.h b/src/map/mio/mioInt.h index 541a7a7f..23f48b2f 100644 --- a/src/map/mio/mioInt.h +++ b/src/map/mio/mioInt.h @@ -76,6 +76,14 @@ struct Mio_LibraryStruct_t_ st__table * tName2Gate; // the mapping of gate names into their pointer Mem_Flex_t * pMmFlex; // the memory manaqer for SOPs Vec_Str_t * vCube; // temporary cube + // matching + int fPinFilter; // pin filtering + int fPinPerm; // pin permutation + int fPinQuick; // pin permutation + Vec_Mem_t * vTtMem; // truth tables + Vec_Wec_t * vTt2Match; // matches for truth tables + Mio_Cell2_t * pCells; // library gates + int nCells; // library gate count }; struct Mio_GateStruct_t_ diff --git a/src/map/mio/mioUtils.c b/src/map/mio/mioUtils.c index 101d5d0f..7572b27c 100644 --- a/src/map/mio/mioUtils.c +++ b/src/map/mio/mioUtils.c @@ -53,6 +53,7 @@ void Mio_LibraryDelete( Mio_Library_t * pLib ) Mio_Gate_t * pGate, * pGate2; if ( pLib == NULL ) return; + Mio_LibraryMatchesStop( pLib ); // free the bindings of nodes to gates from this library for all networks Abc_FrameUnmapAllNetworks( Abc_FrameGetGlobalFrame() ); // free the library @@ -732,8 +733,13 @@ Mio_Cell2_t * Mio_CollectRootsNew2( Mio_Library_t * pLib, int nInputs, int * pnG assert( Mio_AreaCompare2( ppCells + 4, ppCells + iCell - 1 ) <= 0 ); } // assign IDs + Mio_LibraryForEachGate( pLib, pGate0 ) + Mio_GateSetCell( pGate0, -1 ); for ( i = 0; i < iCell; i++ ) + { ppCells[i].Id = ppCells[i].pName ? i : -1; + Mio_GateSetCell( (Mio_Gate_t *)ppCells[i].pMioGate, i ); + } // report if ( fVerbose ) @@ -1465,6 +1471,177 @@ void Mio_LibraryCleanProfile2( Mio_Library_t * pLib ) Mio_GateSetProfile2( pGate, 0 ); } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Mio_LibraryHashGates( Mio_Library_t * pLib ) +{ + Mio_Gate_t * pGate; + Mio_LibraryForEachGate( pLib, pGate ) + if ( pGate->pTwin ) + { + printf( "Gates with multiple outputs are not supported.\n" ); + return; + } + if ( pLib->tName2Gate ) + st__free_table( pLib->tName2Gate ); + pLib->tName2Gate = st__init_table(strcmp, st__strhash); + Mio_LibraryForEachGate( pLib, pGate ) + st__insert( pLib->tName2Gate, pGate->pName, (char *)pGate ); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline int Abc_SclIsChar( char c ) +{ + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; +} +static inline int Abc_SclIsName( char c ) +{ + return Abc_SclIsChar(c) || (c >= '0' && c <= '9'); +} +static inline char * Abc_SclFindLimit( char * pName ) +{ + assert( Abc_SclIsChar(*pName) ); + while ( Abc_SclIsName(*pName) ) + pName++; + return pName; +} +static inline int Abc_SclAreEqual( char * pBase, char * pName, char * pLimit ) +{ + return !strncmp( pBase, pName, pLimit - pName ); +} +void Mio_LibraryShortFormula( Mio_Gate_t * pCell, char * pForm, char * pBuffer ) +{ + Mio_Pin_t * pPin; + char * pTemp, * pLimit; int i; + if ( !strncmp(pForm, "CONST", 5) ) + { + sprintf( pBuffer, "%s", pForm ); + return; + } + for ( pTemp = pForm; *pTemp; ) + { + if ( !Abc_SclIsChar(*pTemp) ) + { + *pBuffer++ = *pTemp++; + continue; + } + pLimit = Abc_SclFindLimit( pTemp ); + i = 0; + Mio_GateForEachPin( pCell, pPin ) + { + if ( Abc_SclAreEqual( pPin->pName, pTemp, pLimit ) ) + { + *pBuffer++ = 'a' + i; + break; + } + i++; + } + pTemp = pLimit; + } + *pBuffer++ = 0; +} +void Mio_LibraryShortNames( Mio_Library_t * pLib ) +{ + char Buffer[10000]; + Mio_Gate_t * pGate; Mio_Pin_t * pPin; + int c = 0, i, nDigits = Abc_Base10Log( Mio_LibraryReadGateNum(pLib) ); + // itereate through classes + Mio_LibraryForEachGate( pLib, pGate ) + { + ABC_FREE( pGate->pName ); + sprintf( Buffer, "g%0*d", nDigits, ++c ); + pGate->pName = Abc_UtilStrsav( Buffer ); + // update formula + Mio_LibraryShortFormula( pGate, pGate->pForm, Buffer ); + ABC_FREE( pGate->pForm ); + pGate->pForm = Abc_UtilStrsav( Buffer ); + // pin names + i = 0; + Mio_GateForEachPin( pGate, pPin ) + { + ABC_FREE( pPin->pName ); + sprintf( Buffer, "%c", 'a'+i ); + pPin->pName = Abc_UtilStrsav( Buffer ); + i++; + } + // output pin + ABC_FREE( pGate->pOutName ); + sprintf( Buffer, "z" ); + pGate->pOutName = Abc_UtilStrsav( Buffer ); + } + Mio_LibraryHashGates( pLib ); + // update library name + printf( "Renaming library \"%s\" into \"%s%d\".\n", pLib->pName, "lib", Mio_LibraryReadGateNum(pLib) ); + ABC_FREE( pLib->pName ); + sprintf( Buffer, "lib%d", Mio_LibraryReadGateNum(pLib) ); + pLib->pName = Abc_UtilStrsav( Buffer ); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Mio_LibraryMatchesStop( Mio_Library_t * pLib ) +{ + if ( !pLib->vTtMem ) + return; + Vec_WecFree( pLib->vTt2Match ); + Vec_MemHashFree( pLib->vTtMem ); + Vec_MemFree( pLib->vTtMem ); + ABC_FREE( pLib->pCells ); +} +void Mio_LibraryMatchesStart( Mio_Library_t * pLib, int fPinFilter, int fPinPerm, int fPinQuick ) +{ + extern Mio_Cell2_t * Nf_StoDeriveMatches( Vec_Mem_t * vTtMem, Vec_Wec_t * vTt2Match, int * pnCells, int fPinFilter, int fPinPerm, int fPinQuick ); + if ( pLib->vTtMem && pLib->fPinFilter == fPinFilter && pLib->fPinPerm == fPinPerm && pLib->fPinQuick == fPinQuick ) + return; + if ( pLib->vTtMem ) + Mio_LibraryMatchesStop( pLib ); + pLib->fPinFilter = fPinFilter; // pin filtering + pLib->fPinPerm = fPinPerm; // pin permutation + pLib->fPinQuick = fPinQuick; // pin permutation + pLib->vTtMem = Vec_MemAllocForTT( 6, 0 ); + pLib->vTt2Match = Vec_WecAlloc( 1000 ); + Vec_WecPushLevel( pLib->vTt2Match ); + Vec_WecPushLevel( pLib->vTt2Match ); + assert( Vec_WecSize(pLib->vTt2Match) == Vec_MemEntryNum(pLib->vTtMem) ); + pLib->pCells = Nf_StoDeriveMatches( pLib->vTtMem, pLib->vTt2Match, &pLib->nCells, fPinFilter, fPinPerm, fPinQuick ); +} +void Mio_LibraryMatchesFetch( Mio_Library_t * pLib, Vec_Mem_t ** pvTtMem, Vec_Wec_t ** pvTt2Match, Mio_Cell2_t ** ppCells, int * pnCells, int fPinFilter, int fPinPerm, int fPinQuick ) +{ + Mio_LibraryMatchesStart( pLib, fPinFilter, fPinPerm, fPinQuick ); + *pvTtMem = pLib->vTtMem; // truth tables + *pvTt2Match = pLib->vTt2Match; // matches for truth tables + *ppCells = pLib->pCells; // library gates + *pnCells = pLib->nCells; // library gate count +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// |