summaryrefslogtreecommitdiffstats
path: root/src/map/mio
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2015-04-17 21:02:15 +0900
committerAlan Mishchenko <alanmi@berkeley.edu>2015-04-17 21:02:15 +0900
commita78fb767ee8691154ac17908f6099f29526193f2 (patch)
tree57a900738f511d4f06875a3f6e295cfc476e9074 /src/map/mio
parentbc6c0837a18e21b4fbcb6e43c8328f42614e9277 (diff)
downloadabc-a78fb767ee8691154ac17908f6099f29526193f2.tar.gz
abc-a78fb767ee8691154ac17908f6099f29526193f2.tar.bz2
abc-a78fb767ee8691154ac17908f6099f29526193f2.zip
Adding platform-independent (alphabetic) way of sorting Genlib gates and selecting representatives based on area/delay.
Diffstat (limited to 'src/map/mio')
-rw-r--r--src/map/mio/mioRead.c16
-rw-r--r--src/map/mio/mioUtils.c60
2 files changed, 56 insertions, 20 deletions
diff --git a/src/map/mio/mioRead.c b/src/map/mio/mioRead.c
index edc2af40..6e067fa7 100644
--- a/src/map/mio/mioRead.c
+++ b/src/map/mio/mioRead.c
@@ -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 Diff = strcmp( (*pp1)->pName, (*pp2)->pName );
- if ( Diff < 0.0 )
+ if ( Diff < 0 )
return -1;
- if ( Diff > 0.0 )
+ if ( Diff > 0 )
return 1;
return 0;
}
@@ -559,22 +559,16 @@ void Mio_LibrarySortGates( Mio_Library_t * pLib )
Mio_LibraryForEachGate( pLib, pGate )
ppGates[i++] = pGate;
assert( i == pLib->nGates );
- // sort gates by area
+ // sort gates by name
pLib->ppGates0 = ABC_ALLOC( Mio_Gate_t *, pLib->nGates );
for ( i = 0; i < pLib->nGates; i++ )
pLib->ppGates0[i] = ppGates[i];
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++ )
ppGates[i]->pNext = (i < pLib->nGates-1)? ppGates[i+1] : NULL;
pLib->pGates = ppGates[0];
- ABC_FREE( 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 );
+ pLib->ppGatesName = ppGates;
}
/**Function*************************************************************
diff --git a/src/map/mio/mioUtils.c b/src/map/mio/mioUtils.c
index a8e11102..bc8e8993 100644
--- a/src/map/mio/mioUtils.c
+++ b/src/map/mio/mioUtils.c
@@ -389,10 +389,54 @@ int Mio_DelayCompareNew( Mio_Cell_t * pG1, Mio_Cell_t * pG2 )
SeeAlso []
***********************************************************************/
-void Mio_CollectCopy( Mio_Cell_t * pCell, Mio_Gate_t * pGate )
+static inline float Mio_CellDelayAve( Mio_Cell_t * pCell )
{
- Mio_Pin_t * pPin;
- int k;
+ 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_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->uTruth = pGate->uTruth;
pCell->Area = (float)pGate->dArea;
@@ -409,7 +453,8 @@ Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGat
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
+ // if equal areas, select gate with smaller average pin delay
+ // if these are also equal, select lexicographically smaller name
Mio_LibraryForEachGate( pLib, pGate )
{
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
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) )
- {
+ if ( Mio_CompareTwo( ppCells + i, pGate ) )
Mio_CollectCopy( ppCells + i, pGate );
- }
break;
}
if ( i < iCell )
@@ -487,7 +529,7 @@ Mio_Cell_t * Mio_CollectRootsNew( Mio_Library_t * pLib, int nInputs, int * pnGat
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] );
+ pCell->pName, pCell->nFanins, pCounts[i], pCell->Area, Mio_CellDelayAve(pCell) );
}
ABC_FREE( pCounts );
}