Commit a78fb767 by Alan Mishchenko

Adding platform-independent (alphabetic) way of sorting Genlib gates and…

Adding platform-independent (alphabetic) way of sorting Genlib gates and selecting representatives based on area/delay.
parent bc6c0837
...@@ -533,9 +533,9 @@ int Mio_LibraryCompareGatesByArea( Mio_Gate_t ** pp1, Mio_Gate_t ** pp2 ) ...@@ -533,9 +533,9 @@ int Mio_LibraryCompareGatesByArea( Mio_Gate_t ** pp1, Mio_Gate_t ** pp2 )
int Mio_LibraryCompareGatesByName( Mio_Gate_t ** pp1, Mio_Gate_t ** pp2 ) int Mio_LibraryCompareGatesByName( Mio_Gate_t ** pp1, Mio_Gate_t ** pp2 )
{ {
int Diff = strcmp( (*pp1)->pName, (*pp2)->pName ); int Diff = strcmp( (*pp1)->pName, (*pp2)->pName );
if ( Diff < 0.0 ) if ( Diff < 0 )
return -1; return -1;
if ( Diff > 0.0 ) if ( Diff > 0 )
return 1; return 1;
return 0; return 0;
} }
...@@ -559,22 +559,16 @@ void Mio_LibrarySortGates( Mio_Library_t * pLib ) ...@@ -559,22 +559,16 @@ void Mio_LibrarySortGates( Mio_Library_t * pLib )
Mio_LibraryForEachGate( pLib, pGate ) Mio_LibraryForEachGate( pLib, pGate )
ppGates[i++] = pGate; ppGates[i++] = pGate;
assert( i == pLib->nGates ); assert( i == pLib->nGates );
// sort gates by area // sort gates by name
pLib->ppGates0 = ABC_ALLOC( Mio_Gate_t *, pLib->nGates ); pLib->ppGates0 = ABC_ALLOC( Mio_Gate_t *, pLib->nGates );
for ( i = 0; i < pLib->nGates; i++ ) for ( i = 0; i < pLib->nGates; i++ )
pLib->ppGates0[i] = ppGates[i]; pLib->ppGates0[i] = ppGates[i];
qsort( (void *)ppGates, pLib->nGates, sizeof(void *), qsort( (void *)ppGates, pLib->nGates, sizeof(void *),
(int (*)(const void *, const void *)) Mio_LibraryCompareGatesByArea ); (int (*)(const void *, const void *)) Mio_LibraryCompareGatesByName );
for ( i = 0; i < pLib->nGates; i++ ) for ( i = 0; i < pLib->nGates; i++ )
ppGates[i]->pNext = (i < pLib->nGates-1)? ppGates[i+1] : NULL; ppGates[i]->pNext = (i < pLib->nGates-1)? ppGates[i+1] : NULL;
pLib->pGates = ppGates[0]; pLib->pGates = ppGates[0];
ABC_FREE( ppGates ); pLib->ppGatesName = ppGates;
// sort gates by name
pLib->ppGatesName = ABC_ALLOC( Mio_Gate_t *, pLib->nGates );
for ( i = 0; i < pLib->nGates; i++ )
pLib->ppGatesName[i] = pLib->ppGates0[i];
qsort( (void *)pLib->ppGatesName, pLib->nGates, sizeof(void *),
(int (*)(const void *, const void *)) Mio_LibraryCompareGatesByName );
} }
/**Function************************************************************* /**Function*************************************************************
......
...@@ -389,10 +389,54 @@ int Mio_DelayCompareNew( Mio_Cell_t * pG1, Mio_Cell_t * pG2 ) ...@@ -389,10 +389,54 @@ int Mio_DelayCompareNew( Mio_Cell_t * pG1, Mio_Cell_t * pG2 )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Mio_CollectCopy( Mio_Cell_t * pCell, Mio_Gate_t * pGate ) static inline float Mio_CellDelayAve( Mio_Cell_t * pCell )
{ {
float CellDelay = 0; int k;
for ( k = 0; k < (int)pCell->nFanins; k++ )
CellDelay += pCell->Delays[k];
if ( pCell->nFanins )
CellDelay /= pCell->nFanins;
return CellDelay;
}
static inline float Mio_GateDelayAve( Mio_Gate_t * pGate )
{
float GateDelay = 0;
Mio_Pin_t * pPin; Mio_Pin_t * pPin;
int k; Mio_GateForEachPin( pGate, pPin )
GateDelay += (float)(0.5 * pPin->dDelayBlockRise + 0.5 * pPin->dDelayBlockFall);
if ( pGate->nInputs )
GateDelay /= pGate->nInputs;
return GateDelay;
}
static inline int Mio_CompareTwo( Mio_Cell_t * pCell, Mio_Gate_t * pGate )
{
int Comp;
float Eps = (float)0.01;
float CellDelay, GateDelay;
// compare areas
if ( pCell->Area > (float)pGate->dArea + Eps )
return 1;
if ( pCell->Area < (float)pGate->dArea - Eps )
return 0;
// compare delays
CellDelay = Mio_CellDelayAve( pCell );
GateDelay = Mio_GateDelayAve( pGate );
if ( CellDelay > GateDelay + Eps )
return 1;
if ( CellDelay < GateDelay - Eps )
return 0;
// compare names
Comp = strcmp( pCell->pName, pGate->pName );
if ( Comp > 0 )
return 1;
if ( Comp < 0 )
return 0;
assert( 0 );
return 0;
}
static inline void Mio_CollectCopy( Mio_Cell_t * pCell, Mio_Gate_t * pGate )
{
Mio_Pin_t * pPin; int k;
pCell->pName = pGate->pName; pCell->pName = pGate->pName;
pCell->uTruth = pGate->uTruth; pCell->uTruth = pGate->uTruth;
pCell->Area = (float)pGate->dArea; pCell->Area = (float)pGate->dArea;
...@@ -409,7 +453,8 @@ Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGat ...@@ -409,7 +453,8 @@ Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGat
nGates = Mio_LibraryReadGateNum( pLib ); nGates = Mio_LibraryReadGateNum( pLib );
ppCells = ABC_CALLOC( Mio_Cell_t, nGates + 4 ); ppCells = ABC_CALLOC( Mio_Cell_t, nGates + 4 );
// for each functionality, select gate with the smallest area // for each functionality, select gate with the smallest area
// if equal areas, select gate with lexicographically smaller name // if equal areas, select gate with smaller average pin delay
// if these are also equal, select lexicographically smaller name
Mio_LibraryForEachGate( pLib, pGate ) Mio_LibraryForEachGate( pLib, pGate )
{ {
if ( pGate->nInputs > nInputs || pGate->pTwin ) // skip large and multi-output if ( pGate->nInputs > nInputs || pGate->pTwin ) // skip large and multi-output
...@@ -418,11 +463,8 @@ Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGat ...@@ -418,11 +463,8 @@ Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGat
for ( i = 0; i < iCell; i++ ) for ( i = 0; i < iCell; i++ )
if ( ppCells[i].pName && ppCells[i].uTruth == pGate->uTruth ) if ( ppCells[i].pName && ppCells[i].uTruth == pGate->uTruth )
{ {
if ( ppCells[i].Area > pGate->dArea || if ( Mio_CompareTwo( ppCells + i, pGate ) )
(ppCells[i].Area == pGate->dArea && strcmp(ppCells[i].pName, pGate->pName) > 0) )
{
Mio_CollectCopy( ppCells + i, pGate ); Mio_CollectCopy( ppCells + i, pGate );
}
break; break;
} }
if ( i < iCell ) if ( i < iCell )
...@@ -487,7 +529,7 @@ Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGat ...@@ -487,7 +529,7 @@ Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGat
printf( "None\n" ); printf( "None\n" );
else else
printf( "%-20s In = %d N = %3d A = %7.2f D = %7.2f\n", printf( "%-20s In = %d N = %3d A = %7.2f D = %7.2f\n",
pCell->pName, pCell->nFanins, pCounts[i], pCell->Area, pCell->Delays[0] ); pCell->pName, pCell->nFanins, pCounts[i], pCell->Area, Mio_CellDelayAve(pCell) );
} }
ABC_FREE( pCounts ); ABC_FREE( pCounts );
} }
......
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