From 7d81490fe66c0deda91ef04be6d1f79be7025c6a Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Fri, 25 Jul 2014 20:02:56 -0700 Subject: Generating abstraction of standard cell library. --- src/map/mio/exp.h | 2 +- src/map/mio/mio.h | 13 ++++- src/map/mio/mioForm.c | 2 +- src/map/mio/mioFunc.c | 4 +- src/map/mio/mioRead.c | 8 +-- src/map/mio/mioUtils.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 163 insertions(+), 10 deletions(-) (limited to 'src/map/mio') diff --git a/src/map/mio/exp.h b/src/map/mio/exp.h index 73a8f683..1e14b1bd 100644 --- a/src/map/mio/exp.h +++ b/src/map/mio/exp.h @@ -175,7 +175,7 @@ static inline word Exp_Truth6Lit( int nVars, int Lit, word * puFanins, word * pu if ( Lit == EXP_CONST0 ) return 0; if ( Lit == EXP_CONST1 ) - return ~0; + return ~(word)0; if ( Lit < 2 * nVars ) return (Lit&1) ? ~puFanins[Lit/2] : puFanins[Lit/2]; return (Lit&1) ? ~puNodes[Lit/2-nVars] : puNodes[Lit/2-nVars]; diff --git a/src/map/mio/mio.h b/src/map/mio/mio.h index c7d90917..7c3aa396 100644 --- a/src/map/mio/mio.h +++ b/src/map/mio/mio.h @@ -43,7 +43,16 @@ typedef struct Mio_LibraryStruct_t_ Mio_Library_t; typedef struct Mio_GateStruct_t_ Mio_Gate_t; typedef struct Mio_PinStruct_t_ Mio_Pin_t; -static inline char * Mio_UtilStrsav( char * s ) { return s ? strcpy(ABC_ALLOC(char, strlen(s)+1), s) : NULL; } +typedef struct Mio_Cell_t_ Mio_Cell_t; +struct Mio_Cell_t_ +{ + char * pName; // name + word uTruth; // truth table + float Area; // area + unsigned Id : 28; // gate ID + unsigned nFanins : 4; // gate fanins + float Delays[6]; // delay +}; //////////////////////////////////////////////////////////////////////// /// GLOBAL VARIABLES /// @@ -151,6 +160,8 @@ extern void Mio_PinDelete( Mio_Pin_t * pPin ); extern Mio_Pin_t * Mio_PinDup( Mio_Pin_t * pPin ); extern void Mio_WriteLibrary( FILE * pFile, Mio_Library_t * pLib, int fPrintSops ); extern Mio_Gate_t ** Mio_CollectRoots( Mio_Library_t * pLib, int nInputs, float tDelay, int fSkipInv, int * pnGates, int fVerbose ); +extern Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGates, int fVerbose ); +extern Mio_Cell_t * Mio_CollectRootsNewDefault( int nInputs, int * pnGates, int fVerbose ); extern word Mio_DeriveTruthTable6( Mio_Gate_t * pGate ); extern void Mio_DeriveTruthTable( Mio_Gate_t * pGate, unsigned uTruthsIn[][2], int nSigns, int nInputs, unsigned uTruthRes[] ); extern void Mio_DeriveGateDelays( Mio_Gate_t * pGate, diff --git a/src/map/mio/mioForm.c b/src/map/mio/mioForm.c index b3b962c0..9c62212d 100644 --- a/src/map/mio/mioForm.c +++ b/src/map/mio/mioForm.c @@ -290,7 +290,7 @@ int Mio_GateCollectNames( char * pFormula, char * pPinNames[] ) break; if ( i == nPins ) { // cannot find this name; save it - pPinNames[nPins++] = Mio_UtilStrsav(pTemp); + pPinNames[nPins++] = Abc_UtilStrsav(pTemp); } // get the next name pTemp = strtok( NULL, " " ); diff --git a/src/map/mio/mioFunc.c b/src/map/mio/mioFunc.c index 67126749..59df45f5 100644 --- a/src/map/mio/mioFunc.c +++ b/src/map/mio/mioFunc.c @@ -101,7 +101,7 @@ int Mio_GateCollectNames( char * pFormula, char * pPinNames[] ) break; if ( i == nPins ) { // cannot find this name; save it - pPinNames[nPins++] = Mio_UtilStrsav(pTemp); + pPinNames[nPins++] = Abc_UtilStrsav(pTemp); } // get the next name pTemp = strtok( NULL, " " ); @@ -147,6 +147,7 @@ int Mio_GateParseFormula( Mio_Gate_t * pGate ) // pGate->bFunc = b0; pGate->vExpr = Exp_Const0(); pGate->pSop = Mio_SopRegister( (Mem_Flex_t *)pGate->pLib->pMmFlex, " 0\n" ); + pGate->uTruth = 0; pGate->pLib->pGate0 = pGate; } else if ( strcmp( pGate->pForm, MIO_STRING_CONST1 ) == 0 ) @@ -154,6 +155,7 @@ int Mio_GateParseFormula( Mio_Gate_t * pGate ) // pGate->bFunc = b1; pGate->vExpr = Exp_Const1(); pGate->pSop = Mio_SopRegister( (Mem_Flex_t *)pGate->pLib->pMmFlex, " 1\n" ); + pGate->uTruth = ~(word)0; pGate->pLib->pGate1 = pGate; } else diff --git a/src/map/mio/mioRead.c b/src/map/mio/mioRead.c index 860ce39c..b5b334da 100644 --- a/src/map/mio/mioRead.c +++ b/src/map/mio/mioRead.c @@ -207,7 +207,7 @@ Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st__ta pLib = Mio_LibraryReadBuffer( pBuffer, fExtendedFormat, tExcludeGate, fVerbose ); ABC_FREE( pBuffer ); if ( pLib ) - pLib->pName = Mio_UtilStrsav( FileName ); + pLib->pName = Abc_UtilStrsav( FileName ); return pLib; } @@ -340,7 +340,7 @@ Mio_Gate_t * Mio_LibraryReadGate( char ** ppToken, int fExtendedFormat ) // read the name pToken = strtok( NULL, " \t\r\n" ); - pGate->pName = Mio_UtilStrsav( pToken ); + pGate->pName = Abc_UtilStrsav( pToken ); // read the area pToken = strtok( NULL, " \t\r\n" ); @@ -407,7 +407,7 @@ Mio_Pin_t * Mio_LibraryReadPin( char ** ppToken, int fExtendedFormat ) // read the name pToken = strtok( NULL, " \t\r\n" ); - pPin->pName = Mio_UtilStrsav( pToken ); + pPin->pName = Abc_UtilStrsav( pToken ); // read the pin phase pToken = strtok( NULL, " \t\r\n" ); @@ -672,7 +672,7 @@ int Mio_LibraryReadExclude( char * ExcludeFile, st__table * tExcludeGate ) while (1 == fscanf( pEx, "%127s", buffer )) { //printf ("Read: '%s'\n", buffer ); - st__insert( tExcludeGate, Mio_UtilStrsav( buffer ), (char *)0 ); + st__insert( tExcludeGate, Abc_UtilStrsav( buffer ), (char *)0 ); nDel++; } diff --git a/src/map/mio/mioUtils.c b/src/map/mio/mioUtils.c index 781db6c0..21b61d75 100644 --- a/src/map/mio/mioUtils.c +++ b/src/map/mio/mioUtils.c @@ -126,7 +126,7 @@ Mio_Pin_t * Mio_PinDup( Mio_Pin_t * pPin ) pPinNew = ABC_ALLOC( Mio_Pin_t, 1 ); *pPinNew = *pPin; - pPinNew->pName = (pPinNew->pName ? Mio_UtilStrsav(pPinNew->pName) : NULL); + pPinNew->pName = (pPinNew->pName ? Abc_UtilStrsav(pPinNew->pName) : NULL); pPinNew->pNext = NULL; return pPinNew; @@ -313,7 +313,7 @@ Mio_Gate_t ** Mio_CollectRoots( Mio_Library_t * pLib, int nInputs, float tDelay, continue; if ( tDelay > 0.0 && pGate->dDelayMax > (double)tDelay ) continue; - if ( pGate->uTruth == 0 || pGate->uTruth == ~0 ) + if ( pGate->uTruth == 0 || pGate->uTruth == ~(word)0 ) continue; if ( pGate->uTruth == ABC_CONST(0xAAAAAAAAAAAAAAAA) ) continue; @@ -350,6 +350,146 @@ Mio_Gate_t ** Mio_CollectRoots( Mio_Library_t * pLib, int nInputs, float tDelay, return ppGates; } + +/**Function************************************************************* + + Synopsis [Compares the max delay of two gates.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Mio_DelayCompareNew( Mio_Cell_t * pG1, Mio_Cell_t * pG2 ) +{ + if ( (pG1)->nFanins < (pG2)->nFanins ) + return -1; + if ( (pG1)->nFanins > (pG2)->nFanins ) + return 1; + if ( (pG1)->Area < (pG2)->Area ) + return -1; + if ( (pG1)->Area > (pG2)->Area ) + return 1; + return 0; +} + +/**Function************************************************************* + + Synopsis [Collects the set of root gates.] + + Description [Only collects the gates with unique functionality, + which have fewer inputs and shorter delay than the given limits.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Mio_CollectCopy( Mio_Cell_t * pCell, Mio_Gate_t * pGate ) +{ + Mio_Pin_t * pPin; + int k; + pCell->pName = pGate->pName; + pCell->uTruth = pGate->uTruth; + pCell->Area = (float)pGate->dArea; + pCell->nFanins = pGate->nInputs; + for ( k = 0, pPin = pGate->pPins; pPin; pPin = pPin->pNext, k++ ) + pCell->Delays[k] = (float)(0.5 * pPin->dDelayBlockRise + 0.5 * pPin->dDelayBlockFall); +} + +Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGates, int fVerbose ) +{ + Mio_Gate_t * pGate; + Mio_Cell_t * ppCells; + int i, nGates, iCell = 4; + nGates = Mio_LibraryReadGateNum( pLib ); + ppCells = ABC_CALLOC( Mio_Cell_t, nGates + 4 ); + // for each functionality, select gate with the smallest area + // if equal areas, select gate with lexicographically smaller name + Mio_LibraryForEachGate( pLib, pGate ) + { + if ( pGate->nInputs > nInputs || pGate->pTwin ) // skip large and multi-output + continue; + // check if the gate with this functionality already exists + for ( i = 0; i < iCell; i++ ) + if ( ppCells[i].pName && ppCells[i].uTruth == pGate->uTruth ) + { + if ( ppCells[i].Area > pGate->dArea || + (ppCells[i].Area == pGate->dArea && strcmp(ppCells[i].pName, pGate->pName) > 0) ) + { + Mio_CollectCopy( ppCells + i, pGate ); + } + break; + } + if ( i < iCell ) + continue; + if ( pGate->uTruth == 0 || pGate->uTruth == ~(word)0 ) + { + int Idx = (int)(pGate->uTruth == ~(word)0); + assert( pGate->nInputs == 0 ); + Mio_CollectCopy( ppCells + Idx, pGate ); + continue; + } + if ( pGate->uTruth == ABC_CONST(0xAAAAAAAAAAAAAAAA) || pGate->uTruth == ~ABC_CONST(0xAAAAAAAAAAAAAAAA) ) + { + int Idx = 2 + (int)(pGate->uTruth == ~ABC_CONST(0xAAAAAAAAAAAAAAAA)); + assert( pGate->nInputs == 1 ); + Mio_CollectCopy( ppCells + Idx, pGate ); + continue; + } + Mio_CollectCopy( ppCells + iCell++, pGate ); + } + // sort by delay + if ( iCell > 1 ) + { + qsort( (void *)(ppCells + 4), iCell - 4, sizeof(Mio_Cell_t), + (int (*)(const void *, const void *)) Mio_DelayCompareNew ); + assert( Mio_DelayCompareNew( ppCells + 4, ppCells + iCell - 1 ) <= 0 ); + } + // assign IDs + for ( i = 0; i < iCell; i++ ) + ppCells[i].Id = ppCells[i].pName ? i : -1; + + // report + if ( fVerbose ) + { + // count gates + int * pCounts = ABC_CALLOC( int, nGates + 4 ); + Mio_LibraryForEachGate( pLib, pGate ) + { + if ( pGate->nInputs > nInputs || pGate->pTwin ) // skip large and multi-output + continue; + for ( i = 0; i < iCell; i++ ) + if ( ppCells[i].pName && ppCells[i].uTruth == pGate->uTruth ) + { + pCounts[i]++; + break; + } + assert( i < iCell ); + } + for ( i = 0; i < iCell; i++ ) + { + Mio_Cell_t * pCell = ppCells + i; + printf( "%4d : ", i ); + if ( pCell->pName == NULL ) + printf( "None\n" ); + else + printf( "%-20s In = %d N = %3d A = %7.2f D = %7.2f\n", + pCell->pName, pCell->nFanins, pCounts[i], pCell->Area, pCell->Delays[0] ); + } + ABC_FREE( pCounts ); + } + if ( pnGates ) + *pnGates = iCell; + return ppCells; +} +Mio_Cell_t * Mio_CollectRootsNewDefault( int nInputs, int * pnGates, int fVerbose ) +{ + return Mio_CollectRootsNew( (Mio_Library_t *)Abc_FrameReadLibGen(), nInputs, pnGates, fVerbose ); +} + /**Function************************************************************* Synopsis [Derives the truth table of the gate.] -- cgit v1.2.3