Commit 7d81490f by Alan Mishchenko

Generating abstraction of standard cell library.

parent 9bfe2ad7
......@@ -52,6 +52,10 @@ Gia_Man_t * Lf_ManPerformMapping( Gia_Man_t * pGia, Jf_Par_t * pPars )
{
return Jf_ManPerformMapping( pGia, pPars );
}
Gia_Man_t * Gia_ManPerformLfMapping( Gia_Man_t * p, Jf_Par_t * pPars, int fNormalized )
{
return NULL;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
......
......@@ -10595,19 +10595,24 @@ int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
Bmc_EcoMiterTest();
}
*/
{
// extern void Nf_ManPrepareLibraryTest();
// Nf_ManPrepareLibraryTest();
// return 0;
}
if ( pNtk )
{
extern Abc_Ntk_t * Abc_NtkBarBufsOnOffTest( Abc_Ntk_t * pNtk );
Abc_Ntk_t * pNtkRes = Abc_NtkBarBufsOnOffTest( pNtk );
/*
extern Abc_Ntk_t * Abc_NtkPcmTest( Abc_Ntk_t * pNtk, int fNewAlgo, int fVerbose );
extern Abc_Ntk_t * Abc_NtkPcmTestAig( Abc_Ntk_t * pNtk, int fVerbose );
Abc_Ntk_t * pNtkRes;
if ( Abc_NtkIsLogic(pNtk) )
pNtkRes = Abc_NtkPcmTest( pNtk, fNewAlgo, fVerbose );
else
pNtkRes = Abc_NtkPcmTestAig( pNtk, fVerbose );
*/
// extern Abc_Ntk_t * Abc_NtkPcmTest( Abc_Ntk_t * pNtk, int fNewAlgo, int fVerbose );
// extern Abc_Ntk_t * Abc_NtkPcmTestAig( Abc_Ntk_t * pNtk, int fVerbose );
// Abc_Ntk_t * pNtkRes;
// if ( Abc_NtkIsLogic(pNtk) )
// pNtkRes = Abc_NtkPcmTest( pNtk, fNewAlgo, fVerbose );
// else
// pNtkRes = Abc_NtkPcmTestAig( pNtk, fVerbose );
if ( pNtkRes == NULL )
{
Abc_Print( -1, "Command has failed.\n" );
......@@ -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];
......
......@@ -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,
......
......@@ -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, " " );
......
......@@ -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
......
......@@ -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++;
}
......
......@@ -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.]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment