diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2009-01-18 08:01:00 -0800 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2009-01-18 08:01:00 -0800 |
commit | f936cc0680c98ffe51b3a1716c996072d5dbf76c (patch) | |
tree | 784a2a809fb6b972ec6a8e2758ab758ca590d01a /src/map/amap/amapLib.c | |
parent | c9ad5880cc61787dec6d018111b63023407ce0e6 (diff) | |
download | abc-f936cc0680c98ffe51b3a1716c996072d5dbf76c.tar.gz abc-f936cc0680c98ffe51b3a1716c996072d5dbf76c.tar.bz2 abc-f936cc0680c98ffe51b3a1716c996072d5dbf76c.zip |
Version abc90118
Diffstat (limited to 'src/map/amap/amapLib.c')
-rw-r--r-- | src/map/amap/amapLib.c | 361 |
1 files changed, 361 insertions, 0 deletions
diff --git a/src/map/amap/amapLib.c b/src/map/amap/amapLib.c new file mode 100644 index 00000000..816f0703 --- /dev/null +++ b/src/map/amap/amapLib.c @@ -0,0 +1,361 @@ +/**CFile**************************************************************** + + FileName [amapLib.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Technology mapper for standard cells.] + + Synopsis [Standard-cell library.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - June 20, 2005.] + + Revision [$Id: amapLib.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "amapInt.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Allocs a library.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Amap_Lib_t * Amap_LibAlloc() +{ + Amap_Lib_t * p; + p = (Amap_Lib_t *)ALLOC( Amap_Lib_t, 1 ); + memset( p, 0, sizeof(Amap_Lib_t) ); + p->vGates = Vec_PtrAlloc( 100 ); + p->pMemGates = Aig_MmFlexStart(); + p->pMemSet = Aig_MmFlexStart(); + return p; +} + +/**Function************************************************************* + + Synopsis [Deallocs a library.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Amap_LibFree( Amap_Lib_t * p ) +{ + if ( p == NULL ) + return; + if ( p->vSelect ) + Vec_PtrFree( p->vSelect ); + if ( p->vSorted ) + Vec_PtrFree( p->vSorted ); + if ( p->vGates ) + Vec_PtrFree( p->vGates ); + if ( p->vRules ) + Vec_VecFree( (Vec_Vec_t *)p->vRules ); + if ( p->vRulesX ) + Vec_VecFree( (Vec_Vec_t *)p->vRulesX ); + if ( p->vRules3 ) + Vec_IntFree( p->vRules3 ); + Aig_MmFlexStop( p->pMemGates, 0 ); + Aig_MmFlexStop( p->pMemSet, 0 ); + FREE( p->pRules ); + FREE( p->pRulesX ); + FREE( p->pNodes ); + free( p ); +} + +/**Function************************************************************* + + Synopsis [Returns the largest gate size.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Amap_LibNumPinsMax( Amap_Lib_t * p ) +{ + Amap_Gat_t * pGate; + int i, Counter = 0; + Amap_LibForEachGate( p, pGate, i ) + if ( Counter < (int)pGate->nPins ) + Counter = pGate->nPins; + return Counter; +} + +/**Function************************************************************* + + Synopsis [Writes one pin.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Amap_LibWritePin( FILE * pFile, Amap_Pin_t * pPin ) +{ + char * pPhaseNames[10] = { "UNKNOWN", "INV", "NONINV" }; + fprintf( pFile, " PIN " ); + fprintf( pFile, "%9s ", pPin->pName ); + fprintf( pFile, "%10s ", pPhaseNames[pPin->Phase] ); + fprintf( pFile, "%6d ", (int)pPin->dLoadInput ); + fprintf( pFile, "%6d ", (int)pPin->dLoadMax ); + fprintf( pFile, "%6.2f ", pPin->dDelayBlockRise ); + fprintf( pFile, "%6.2f ", pPin->dDelayFanoutRise ); + fprintf( pFile, "%6.2f ", pPin->dDelayBlockFall ); + fprintf( pFile, "%6.2f", pPin->dDelayFanoutFall ); + fprintf( pFile, "\n" ); +} + +/**Function************************************************************* + + Synopsis [Writes one gate.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Amap_LibWriteGate( FILE * pFile, Amap_Gat_t * pGate, int fPrintDsd ) +{ + Amap_Pin_t * pPin; + fprintf( pFile, "GATE " ); + fprintf( pFile, "%12s ", pGate->pName ); + fprintf( pFile, "%10.2f ", pGate->dArea ); + fprintf( pFile, "%s=%s;\n", pGate->pOutName, pGate->pForm ); + if ( fPrintDsd ) + { + if ( pGate->pFunc == NULL ) + printf( "Truth table is not available.\n" ); + else + Kit_DsdPrintFromTruth( pGate->pFunc, pGate->nPins ); + } + Amap_GateForEachPin( pGate, pPin ) + Amap_LibWritePin( pFile, pPin ); +} + +/**Function************************************************************* + + Synopsis [Writes library.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Amap_LibWrite( FILE * pFile, Amap_Lib_t * pLib, int fPrintDsd ) +{ + Amap_Gat_t * pGate; + int i; + fprintf( pFile, "# The genlib library \"%s\".\n", pLib->pName ); + Amap_LibForEachGate( pLib, pGate, i ) + Amap_LibWriteGate( pFile, pGate, fPrintDsd ); +} + +/**Function************************************************************* + + Synopsis [Compares two gates by area.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Amap_LibCompareGatesByArea( Amap_Gat_t ** pp1, Amap_Gat_t ** pp2 ) +{ + double Diff = (*pp1)->dArea - (*pp2)->dArea; + if ( Diff < 0.0 ) + return -1; + if ( Diff > 0.0 ) + return 1; + return 0; +} + +/**Function************************************************************* + + Synopsis [Compares gates by area.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Ptr_t * Amap_LibSortGatesByArea( Amap_Lib_t * pLib ) +{ + Vec_Ptr_t * vSorted; + vSorted = Vec_PtrDup( pLib->vGates ); + qsort( (void *)Vec_PtrArray(vSorted), Vec_PtrSize(vSorted), sizeof(void *), + (int (*)(const void *, const void *)) Amap_LibCompareGatesByArea ); + return vSorted; +} + +/**Function************************************************************* + + Synopsis [Finds min-area gate with the given function.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Amap_Gat_t * Amap_LibFindGate( Amap_Lib_t * p, unsigned uTruth ) +{ + Amap_Gat_t * pGate; + int i; + Vec_PtrForEachEntry( p->vSorted, pGate, i ) + if ( pGate->nPins <= 5 && pGate->pFunc[0] == uTruth ) + return pGate; + return NULL; +} + +/**Function************************************************************* + + Synopsis [Selects gates useful for area-only mapping.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Ptr_t * Amap_LibSelectGates( Amap_Lib_t * p, int fVerbose ) +{ + Vec_Ptr_t * vSelect; + Amap_Gat_t * pGate, * pGate2; + int i, k, clk = clock(); + p->pGate0 = Amap_LibFindGate( p, 0 ); + p->pGate1 = Amap_LibFindGate( p, ~0 ); + p->pGateBuf = Amap_LibFindGate( p, 0xAAAAAAAA ); + p->pGateInv = Amap_LibFindGate( p, ~0xAAAAAAAA ); + vSelect = Vec_PtrAlloc( 100 ); + Vec_PtrForEachEntry( p->vSorted, pGate, i ) + { + if ( pGate->pFunc == NULL ) + continue; + Vec_PtrForEachEntryStop( p->vSorted, pGate2, k, i ) + { + if ( pGate2->pFunc == NULL ) + continue; + if ( pGate2->nPins != pGate->nPins ) + continue; + if ( !memcmp( pGate2->pFunc, pGate->pFunc, sizeof(unsigned) * Aig_TruthWordNum(pGate->nPins) ) ) + break; + } + if ( k < i ) + continue; + Vec_PtrPush( vSelect, pGate ); + } + return vSelect; +} + +/**Function************************************************************* + + Synopsis [Selects gates useful for area-only mapping.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Amap_LibPrintSelectedGates( Amap_Lib_t * p, int fAllGates ) +{ + Vec_Ptr_t * vArray; + Amap_Gat_t * pGate; + int i; + vArray = fAllGates? p->vGates : p->vSelect; + Vec_PtrForEachEntry( vArray, pGate, i ) + { + printf( "Gate %4d : %15s Area = %9.2f\n", pGate->Id, pGate->pName, pGate->dArea ); + printf( " Formula: %s=%s\n", pGate->pOutName, pGate->pForm ); + printf( " DSD: " ); + Kit_DsdPrintFromTruth( pGate->pFunc, pGate->nPins ); + } +} + +/**Function************************************************************* + + Synopsis [Parses equations for the gates.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Amap_Lib_t * Amap_LibReadAndPrepare( char * pFileName, int fVerbose, int fVeryVerbose ) +{ + Amap_Lib_t * p; + int clk = clock(); + p = Amap_LibReadFile( pFileName, fVerbose ); + if ( fVerbose ) + printf( "Read %d gates from file \"%s\".\n", Vec_PtrSize(p->vGates), pFileName ); + if ( p == NULL ) + return NULL; + if ( !Amap_LibParseEquations( p, fVerbose ) ) + { + Amap_LibFree( p ); + return NULL; + } + p->vSorted = Amap_LibSortGatesByArea( p ); + p->vSelect = Amap_LibSelectGates( p, fVerbose ); + if ( fVerbose ) + { + printf( "Selected %d functionally unique gates. ", + Vec_PtrSize(p->vSelect), Vec_PtrSize(p->vSorted) ); + PRT( "Time", clock() - clk ); + } + clk = clock(); + Amap_LibCreateRules( p, fVeryVerbose ); + if ( fVerbose ) + { + printf( "Created %d rules and %d matches. ", + p->nNodes, p->nSets ); + PRT( "Time", clock() - clk ); + } + return p; +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + |