diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2015-12-14 00:44:33 -0800 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2015-12-14 00:44:33 -0800 |
commit | 19586f105cd15279084541a5edf033724a32be49 (patch) | |
tree | 1a468a5de4856992b461532b3cc78911e363ff03 | |
parent | 64afe6e9f861f8c570ba68c3a2d47ec92ebad96f (diff) | |
download | abc-19586f105cd15279084541a5edf033724a32be49.tar.gz abc-19586f105cd15279084541a5edf033724a32be49.tar.bz2 abc-19586f105cd15279084541a5edf033724a32be49.zip |
Adding code to support gate profiles.
-rw-r--r-- | src/base/abci/abc.c | 32 | ||||
-rw-r--r-- | src/base/abci/abcMap.c | 11 | ||||
-rw-r--r-- | src/base/abci/abcPrint.c | 18 | ||||
-rw-r--r-- | src/base/wlc/wlcReadVer.c | 5 | ||||
-rw-r--r-- | src/map/mapper/mapper.h | 1 | ||||
-rw-r--r-- | src/map/mapper/mapperCreate.c | 1 | ||||
-rw-r--r-- | src/map/mapper/mapperInt.h | 5 | ||||
-rw-r--r-- | src/map/mapper/mapperMatch.c | 29 | ||||
-rw-r--r-- | src/map/mapper/mapperRefs.c | 41 | ||||
-rw-r--r-- | src/map/mio/mio.h | 5 | ||||
-rw-r--r-- | src/map/mio/mioApi.c | 54 | ||||
-rw-r--r-- | src/map/mio/mioUtils.c | 42 | ||||
-rw-r--r-- | src/map/scl/sclLibUtil.c | 79 |
13 files changed, 252 insertions, 71 deletions
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 878d9a99..a26f67db 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -2209,19 +2209,24 @@ int Abc_CommandPrintGates( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc); int c; int fUseLibrary; + int fUpdateProfile; - extern void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary ); + extern void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary, int fUpdateProfile ); // set defaults fUseLibrary = 1; + fUpdateProfile = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "lh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "luh" ) ) != EOF ) { switch ( c ) { case 'l': fUseLibrary ^= 1; break; + case 'u': + fUpdateProfile ^= 1; + break; case 'h': goto usage; default: @@ -2240,13 +2245,14 @@ int Abc_CommandPrintGates( Abc_Frame_t * pAbc, int argc, char ** argv ) return 1; } - Abc_NtkPrintGates( pNtk, fUseLibrary ); + Abc_NtkPrintGates( pNtk, fUseLibrary, fUpdateProfile ); return 0; usage: - Abc_Print( -2, "usage: print_gates [-lh]\n" ); + Abc_Print( -2, "usage: print_gates [-luh]\n" ); Abc_Print( -2, "\t prints statistics about gates used in the network\n" ); Abc_Print( -2, "\t-l : used library gate names (if mapped) [default = %s]\n", fUseLibrary? "yes": "no" ); + Abc_Print( -2, "\t-u : update profile before printing it[default = %s]\n", fUpdateProfile? "yes": "no" ); Abc_Print( -2, "\t-h : print the command usage\n"); return 1; } @@ -14851,15 +14857,16 @@ int Abc_CommandMap( Abc_Frame_t * pAbc, int argc, char ** argv ) float LogFan = 0; float Slew = 0; // choose based on the library float Gain = 250; - int nGatesMin = 4; + int nGatesMin = 0; int fAreaOnly; int fRecovery; int fSweep; int fSwitching; int fSkipFanout; + int fUseProfile; int fVerbose; int c; - extern Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti, double DelayMulti, float LogFan, float Slew, float Gain, int nGatesMin, int fRecovery, int fSwitching, int fSkipFanout, int fVerbose ); + extern Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti, double DelayMulti, float LogFan, float Slew, float Gain, int nGatesMin, int fRecovery, int fSwitching, int fSkipFanout, int fUseProfile, int fVerbose ); extern int Abc_NtkFraigSweep( Abc_Ntk_t * pNtk, int fUseInv, int fExdc, int fVerbose, int fVeryVerbose ); pNtk = Abc_FrameReadNtk(pAbc); @@ -14872,9 +14879,10 @@ int Abc_CommandMap( Abc_Frame_t * pAbc, int argc, char ** argv ) fSweep = 0; fSwitching = 0; fSkipFanout = 0; + fUseProfile = 0; fVerbose = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "DABFSGMarspfvh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "DABFSGMarspfuvh" ) ) != EOF ) { switch ( c ) { @@ -14966,6 +14974,9 @@ int Abc_CommandMap( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'f': fSkipFanout ^= 1; break; + case 'u': + fUseProfile ^= 1; + break; case 'v': fVerbose ^= 1; break; @@ -15002,7 +15013,7 @@ int Abc_CommandMap( Abc_Frame_t * pAbc, int argc, char ** argv ) } Abc_Print( 0, "The network was strashed and balanced before mapping.\n" ); // get the new network - pNtkRes = Abc_NtkMap( pNtk, DelayTarget, AreaMulti, DelayMulti, LogFan, Slew, Gain, nGatesMin, fRecovery, fSwitching, fSkipFanout, fVerbose ); + pNtkRes = Abc_NtkMap( pNtk, DelayTarget, AreaMulti, DelayMulti, LogFan, Slew, Gain, nGatesMin, fRecovery, fSwitching, fSkipFanout, fUseProfile, fVerbose ); if ( pNtkRes == NULL ) { Abc_NtkDelete( pNtk ); @@ -15014,7 +15025,7 @@ int Abc_CommandMap( Abc_Frame_t * pAbc, int argc, char ** argv ) else { // get the new network - pNtkRes = Abc_NtkMap( pNtk, DelayTarget, AreaMulti, DelayMulti, LogFan, Slew, Gain, nGatesMin, fRecovery, fSwitching, fSkipFanout, fVerbose ); + pNtkRes = Abc_NtkMap( pNtk, DelayTarget, AreaMulti, DelayMulti, LogFan, Slew, Gain, nGatesMin, fRecovery, fSwitching, fSkipFanout, fUseProfile, fVerbose ); if ( pNtkRes == NULL ) { Abc_Print( -1, "Mapping has failed.\n" ); @@ -15041,7 +15052,7 @@ usage: sprintf(Buffer, "not used" ); else sprintf(Buffer, "%.3f", DelayTarget ); - Abc_Print( -2, "usage: map [-DABFSG float] [-M num] [-arspfvh]\n" ); + Abc_Print( -2, "usage: map [-DABFSG float] [-M num] [-arspfuvh]\n" ); Abc_Print( -2, "\t performs standard cell mapping of the current network\n" ); Abc_Print( -2, "\t-D float : sets the global required times [default = %s]\n", Buffer ); Abc_Print( -2, "\t-A float : \"area multiplier\" to bias gate selection [default = %.2f]\n", AreaMulti ); @@ -15055,6 +15066,7 @@ usage: Abc_Print( -2, "\t-s : toggles sweep after mapping [default = %s]\n", fSweep? "yes": "no" ); Abc_Print( -2, "\t-p : optimizes power by minimizing switching [default = %s]\n", fSwitching? "yes": "no" ); Abc_Print( -2, "\t-f : do not use large gates to map high-fanout nodes [default = %s]\n", fSkipFanout? "yes": "no" ); + Abc_Print( -2, "\t-u : use standard-cell profile [default = %s]\n", fUseProfile? "yes": "no" ); Abc_Print( -2, "\t-v : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" ); Abc_Print( -2, "\t-h : print the command usage\n"); return 1; diff --git a/src/base/abci/abcMap.c b/src/base/abci/abcMap.c index ac7bd0f4..9098c71f 100644 --- a/src/base/abci/abcMap.c +++ b/src/base/abci/abcMap.c @@ -56,7 +56,7 @@ static Abc_Obj_t * Abc_NodeFromMapSuperChoice_rec( Abc_Ntk_t * pNtkNew, Map_Sup SeeAlso [] ***********************************************************************/ -Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti, double DelayMulti, float LogFan, float Slew, float Gain, int nGatesMin, int fRecovery, int fSwitching, int fSkipFanout, int fVerbose ) +Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti, double DelayMulti, float LogFan, float Slew, float Gain, int nGatesMin, int fRecovery, int fSwitching, int fSkipFanout, int fUseProfile, int fVerbose ) { static int fUseMulti = 0; int fShowSwitching = 1; @@ -72,7 +72,10 @@ Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti, // if the library is created here, it will be deleted when pSuperLib is deleted in Map_SuperLibFree() if ( Abc_FrameReadLibScl() && Abc_SclHasDelayInfo( Abc_FrameReadLibScl() ) ) { - pLib = Abc_SclDeriveGenlib( Abc_FrameReadLibScl(), Slew, Gain, nGatesMin, fVerbose ); + if ( pLib && Mio_LibraryHasProfile(pLib) ) + pLib = Abc_SclDeriveGenlib( Abc_FrameReadLibScl(), pLib, Slew, Gain, nGatesMin, fVerbose ); + else + pLib = Abc_SclDeriveGenlib( Abc_FrameReadLibScl(), NULL, Slew, Gain, nGatesMin, fVerbose ); if ( Abc_FrameReadLibGen() ) { Mio_LibraryTransferDelays( (Mio_Library_t *)Abc_FrameReadLibGen(), pLib ); @@ -138,6 +141,8 @@ Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti, clk = Abc_Clock(); Map_ManSetSwitching( pMan, fSwitching ); Map_ManSetSkipFanout( pMan, fSkipFanout ); + if ( fUseProfile ) + Map_ManSetUseProfile( pMan ); if ( LogFan != 0 ) Map_ManCreateNodeDelays( pMan, LogFan ); if ( !Map_Mapping( pMan ) ) @@ -149,6 +154,8 @@ clk = Abc_Clock(); // reconstruct the network after mapping pNtkNew = Abc_NtkFromMap( pMan, pNtk ); + if ( Mio_LibraryHasProfile(pLib) ) + Mio_LibraryTransferProfile2( (Mio_Library_t *)Abc_FrameReadLibGen(), pLib ); Map_ManFree( pMan ); if ( pNtkNew == NULL ) return NULL; diff --git a/src/base/abci/abcPrint.c b/src/base/abci/abcPrint.c index a577b807..bbb4060b 100644 --- a/src/base/abci/abcPrint.c +++ b/src/base/abci/abcPrint.c @@ -1322,11 +1322,11 @@ void Abc_NodePrintKMap( Abc_Obj_t * pNode, int fUseRealNames ) SeeAlso [] ***********************************************************************/ -void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary ) +void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary, int fUpdateProfile ) { Abc_Obj_t * pObj; int fHasBdds, i; - int CountConst, CountBuf, CountInv, CountAnd, CountOr, CountOther, CounterTotal; + int CountConst, CountBuf, CountInv, CountAnd, CountOr, CountOther, CounterTotal, TotalDiff = 0; char * pSop; if ( fUseLibrary && Abc_NtkHasMapping(pNtk) ) @@ -1341,7 +1341,8 @@ void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary ) for ( i = 0; i < nGates; i++ ) { Mio_GateSetValue( ppGates[i], 0 ); - Mio_GateSetProfile2( ppGates[i], 0 ); + if ( fUpdateProfile ) + Mio_GateSetProfile2( ppGates[i], 0 ); } // count the gates by name @@ -1350,7 +1351,8 @@ void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary ) { if ( i == 0 ) continue; Mio_GateSetValue( (Mio_Gate_t *)pObj->pData, 1 + Mio_GateReadValue((Mio_Gate_t *)pObj->pData) ); - Mio_GateIncProfile2( (Mio_Gate_t *)pObj->pData ); + if ( fUpdateProfile ) + Mio_GateIncProfile2( (Mio_Gate_t *)pObj->pData ); CounterTotal++; // assuming that twin gates follow each other if ( Abc_NtkFetchTwinNode(pObj) ) @@ -1372,8 +1374,10 @@ void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary ) for ( i = 0; i < nGates; i++ ) { Counter = Mio_GateReadValue( ppGates[i] ); - if ( Counter == 0 ) + if ( Counter == 0 && Mio_GateReadProfile(ppGates[i]) == 0 ) continue; + if ( Mio_GateReadPinNum(ppGates[i]) > 1 ) + TotalDiff += Abc_AbsInt( Mio_GateReadProfile(ppGates[i]) - Mio_GateReadProfile2(ppGates[i]) ); Area = Counter * Mio_GateReadArea( ppGates[i] ); printf( "%-*s Fanin = %2d Instance = %8d Area = %10.2f %6.2f %% %8d %8d %s\n", nGateNameLen, Mio_GateReadName( ppGates[i] ), @@ -1383,9 +1387,9 @@ void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary ) Mio_GateReadProfile2(ppGates[i]), Mio_GateReadForm(ppGates[i]) ); } - printf( "%-*s Instance = %8d Area = %10.2f %6.2f %%\n", + printf( "%-*s Instance = %8d Area = %10.2f %6.2f %% AbsDiff = %d\n", nGateNameLen, "TOTAL", - CounterTotal, AreaTotal, 100.0 ); + CounterTotal, AreaTotal, 100.0, TotalDiff ); return; } diff --git a/src/base/wlc/wlcReadVer.c b/src/base/wlc/wlcReadVer.c index dcafc014..eb704211 100644 --- a/src/base/wlc/wlcReadVer.c +++ b/src/base/wlc/wlcReadVer.c @@ -1085,7 +1085,10 @@ startword: if ( fDefaultFound ) { int EntryLast = Vec_IntEntryLast( p->vFanins ); - Vec_IntFillExtra( p->vFanins, nValues + 1, EntryLast ); + if (nValues != Vec_IntSize(p->vFanins)-2) + Vec_IntFillExtra( p->vFanins, nValues + 1, EntryLast ); + else + Vec_IntPop(p->vFanins); // get next line and check its opening character pStart = Wlc_PrsStr(p, Vec_IntEntry(p->vStarts, ++i)); pStart = Wlc_PrsSkipSpaces( pStart ); diff --git a/src/map/mapper/mapper.h b/src/map/mapper/mapper.h index 169223d8..f0fcea83 100644 --- a/src/map/mapper/mapper.h +++ b/src/map/mapper/mapper.h @@ -109,6 +109,7 @@ extern void Map_ManSetChoiceNum( Map_Man_t * p, int nChoices ); extern void Map_ManSetVerbose( Map_Man_t * p, int fVerbose ); extern void Map_ManSetSwitching( Map_Man_t * p, int fSwitching ); extern void Map_ManSetSkipFanout( Map_Man_t * p, int fSkipFanout ); +extern void Map_ManSetUseProfile( Map_Man_t * p ); extern Map_Man_t * Map_NodeReadMan( Map_Node_t * p ); extern char * Map_NodeReadData( Map_Node_t * p, int fPhase ); diff --git a/src/map/mapper/mapperCreate.c b/src/map/mapper/mapperCreate.c index e7ad4819..d3e574f3 100644 --- a/src/map/mapper/mapperCreate.c +++ b/src/map/mapper/mapperCreate.c @@ -74,6 +74,7 @@ void Map_ManSetChoiceNum( Map_Man_t * p, int nChoices ) { p-> void Map_ManSetVerbose( Map_Man_t * p, int fVerbose ) { p->fVerbose = fVerbose; } void Map_ManSetSwitching( Map_Man_t * p, int fSwitching ) { p->fSwitching = fSwitching; } void Map_ManSetSkipFanout( Map_Man_t * p, int fSkipFanout ) { p->fSkipFanout = fSkipFanout; } +void Map_ManSetUseProfile( Map_Man_t * p ) { p->fUseProfile = 1; } /**Function************************************************************* diff --git a/src/map/mapper/mapperInt.h b/src/map/mapper/mapperInt.h index 28f40a82..79c8d61a 100644 --- a/src/map/mapper/mapperInt.h +++ b/src/map/mapper/mapperInt.h @@ -123,6 +123,7 @@ struct Map_ManStruct_t_ int nTravIds; // the traversal counter int fSwitching; // use switching activity int fSkipFanout; // skip large gates when mapping high-fanout nodes + int fUseProfile; // use standard-cell profile // the supergate library Map_SuperLib_t * pSuperLib; // the current supergate library @@ -385,8 +386,8 @@ extern void Map_MappingEstimateRefs( Map_Man_t * p ); extern float Map_CutGetAreaFlow( Map_Cut_t * pCut, int fPhase ); extern float Map_CutGetAreaRefed( Map_Cut_t * pCut, int fPhase ); extern float Map_CutGetAreaDerefed( Map_Cut_t * pCut, int fPhase ); -extern float Map_CutRef( Map_Cut_t * pCut, int fPhase ); -extern float Map_CutDeref( Map_Cut_t * pCut, int fPhase ); +extern float Map_CutRef( Map_Cut_t * pCut, int fPhase, int fProfile ); +extern float Map_CutDeref( Map_Cut_t * pCut, int fPhase, int fProfile ); extern void Map_MappingSetRefs( Map_Man_t * pMan ); extern float Map_MappingGetArea( Map_Man_t * pMan ); /*=== mapperSwitch.c =============================================================*/ diff --git a/src/map/mapper/mapperMatch.c b/src/map/mapper/mapperMatch.c index e5e12fa8..f7f6c613 100644 --- a/src/map/mapper/mapperMatch.c +++ b/src/map/mapper/mapperMatch.c @@ -76,6 +76,8 @@ void Map_MatchClean( Map_Match_t * pMatch ) ***********************************************************************/ int Map_MatchCompare( Map_Man_t * pMan, Map_Match_t * pM1, Map_Match_t * pM2, int fDoingArea ) { +// if ( pM1->pSuperBest == pM2->pSuperBest ) +// return 0; if ( !fDoingArea ) { // compare the arrival times @@ -108,6 +110,21 @@ int Map_MatchCompare( Map_Man_t * pMan, Map_Match_t * pM1, Map_Match_t * pM2, in return 0; if ( pM1->AreaFlow > pM2->AreaFlow + pMan->fEpsilon ) return 1; + + // make decision based on cell profile + if ( pMan->fUseProfile && pM1->pSuperBest && pM1->pSuperBest ) + { + int M1req = Mio_GateReadProfile(pM1->pSuperBest->pRoot); + int M2req = Mio_GateReadProfile(pM2->pSuperBest->pRoot); + int M1act = Mio_GateReadProfile2(pM1->pSuperBest->pRoot); + int M2act = Mio_GateReadProfile2(pM2->pSuperBest->pRoot); + //printf( "%d %d ", M1req, M2req ); + if ( M1act < M1req && M2act > M2req ) + return 0; + if ( M2act < M2req && M1act > M1req ) + return 1; + } + // compare the arrival times if ( pM1->tArrive.Worst < pM2->tArrive.Worst - pMan->fEpsilon ) return 0; @@ -266,7 +283,7 @@ int Map_MatchNodePhase( Map_Man_t * p, Map_Node_t * pNode, int fPhase ) pMatch = pCutBest->M + fPhase; if ( pNode->nRefAct[fPhase] > 0 || (pNode->pCutBest[!fPhase] == NULL && pNode->nRefAct[!fPhase] > 0) ) - pMatch->AreaFlow = Area1 = Map_CutDeref( pCutBest, fPhase ); + pMatch->AreaFlow = Area1 = Map_CutDeref( pCutBest, fPhase, p->fUseProfile ); else pMatch->AreaFlow = Area1 = Map_CutGetAreaDerefed( pCutBest, fPhase ); } @@ -326,7 +343,7 @@ int Map_MatchNodePhase( Map_Man_t * p, Map_Node_t * pNode, int fPhase ) (pNode->pCutBest[!fPhase] == NULL && pNode->nRefAct[!fPhase] > 0)) ) { if ( p->fMappingMode == 2 || p->fMappingMode == 3 ) - Area2 = Map_CutRef( pNode->pCutBest[fPhase], fPhase ); + Area2 = Map_CutRef( pNode->pCutBest[fPhase], fPhase, p->fUseProfile ); else if ( p->fMappingMode == 4 ) Area2 = Map_SwitchCutRef( pNode, pNode->pCutBest[fPhase], fPhase ); else @@ -479,23 +496,23 @@ void Map_NodeTryDroppingOnePhase( Map_Man_t * p, Map_Node_t * pNode ) { // deref phase 1 cut if necessary if ( p->fMappingMode >= 2 && pNode->nRefAct[1] > 0 ) - Map_CutDeref( pNode->pCutBest[1], 1 ); + Map_CutDeref( pNode->pCutBest[1], 1, p->fUseProfile ); // get rid of the cut pNode->pCutBest[1] = NULL; // ref phase 0 cut if necessary if ( p->fMappingMode >= 2 && pNode->nRefAct[0] == 0 ) - Map_CutRef( pNode->pCutBest[0], 0 ); + Map_CutRef( pNode->pCutBest[0], 0, p->fUseProfile ); } else { // deref phase 0 cut if necessary if ( p->fMappingMode >= 2 && pNode->nRefAct[0] > 0 ) - Map_CutDeref( pNode->pCutBest[0], 0 ); + Map_CutDeref( pNode->pCutBest[0], 0, p->fUseProfile ); // get rid of the cut pNode->pCutBest[0] = NULL; // ref phase 1 cut if necessary if ( p->fMappingMode >= 2 && pNode->nRefAct[1] == 0 ) - Map_CutRef( pNode->pCutBest[1], 1 ); + Map_CutRef( pNode->pCutBest[1], 1, p->fUseProfile ); } } diff --git a/src/map/mapper/mapperRefs.c b/src/map/mapper/mapperRefs.c index 6d6ff121..e1387262 100644 --- a/src/map/mapper/mapperRefs.c +++ b/src/map/mapper/mapperRefs.c @@ -226,7 +226,7 @@ float Map_CutGetAreaFlow( Map_Cut_t * pCut, int fPhase ) seealso [] ***********************************************************************/ -float Map_CutRefDeref( Map_Cut_t * pCut, int fPhase, int fReference ) +float Map_CutRefDeref( Map_Cut_t * pCut, int fPhase, int fReference, int fUpdateProf ) { Map_Node_t * pNodeChild; Map_Cut_t * pCutChild; @@ -239,6 +239,13 @@ float Map_CutRefDeref( Map_Cut_t * pCut, int fPhase, int fReference ) return 0; // start the area of this cut aArea = Map_CutGetRootArea( pCut, fPhase ); + if ( fUpdateProf ) + { + if ( fReference ) + Mio_GateIncProfile2( pCut->M[fPhase].pSuperBest->pRoot ); + else + Mio_GateDecProfile2( pCut->M[fPhase].pSuperBest->pRoot ); + } // go through the children for ( i = 0; i < pCut->nLeaves; i++ ) { @@ -309,7 +316,7 @@ float Map_CutRefDeref( Map_Cut_t * pCut, int fPhase, int fReference ) pCutChild = pNodeChild->pCutBest[fPhaseChild]; } // reference and compute area recursively - aArea += Map_CutRefDeref( pCutChild, fPhaseChild, fReference ); + aArea += Map_CutRefDeref( pCutChild, fPhaseChild, fReference, fUpdateProf ); } return aArea; } @@ -328,8 +335,8 @@ float Map_CutRefDeref( Map_Cut_t * pCut, int fPhase, int fReference ) float Map_CutGetAreaRefed( Map_Cut_t * pCut, int fPhase ) { float aResult, aResult2; - aResult2 = Map_CutRefDeref( pCut, fPhase, 0 ); // dereference - aResult = Map_CutRefDeref( pCut, fPhase, 1 ); // reference + aResult2 = Map_CutRefDeref( pCut, fPhase, 0, 0 ); // dereference + aResult = Map_CutRefDeref( pCut, fPhase, 1, 0 ); // reference // assert( aResult == aResult2 ); return aResult; } @@ -348,8 +355,8 @@ float Map_CutGetAreaRefed( Map_Cut_t * pCut, int fPhase ) float Map_CutGetAreaDerefed( Map_Cut_t * pCut, int fPhase ) { float aResult, aResult2; - aResult2 = Map_CutRefDeref( pCut, fPhase, 1 ); // reference - aResult = Map_CutRefDeref( pCut, fPhase, 0 ); // dereference + aResult2 = Map_CutRefDeref( pCut, fPhase, 1, 0 ); // reference + aResult = Map_CutRefDeref( pCut, fPhase, 0, 0 ); // dereference // assert( aResult == aResult2 ); return aResult; } @@ -365,9 +372,9 @@ float Map_CutGetAreaDerefed( Map_Cut_t * pCut, int fPhase ) seealso [] ***********************************************************************/ -float Map_CutRef( Map_Cut_t * pCut, int fPhase ) +float Map_CutRef( Map_Cut_t * pCut, int fPhase, int fProfile ) { - return Map_CutRefDeref( pCut, fPhase, 1 ); // reference + return Map_CutRefDeref( pCut, fPhase, 1, fProfile ); // reference } /**function************************************************************* @@ -381,9 +388,9 @@ float Map_CutRef( Map_Cut_t * pCut, int fPhase ) seealso [] ***********************************************************************/ -float Map_CutDeref( Map_Cut_t * pCut, int fPhase ) +float Map_CutDeref( Map_Cut_t * pCut, int fPhase, int fProfile ) { - return Map_CutRefDeref( pCut, fPhase, 0 ); // dereference + return Map_CutRefDeref( pCut, fPhase, 0, fProfile ); // dereference } @@ -430,6 +437,8 @@ void Map_MappingSetRefs_rec( Map_Man_t * pMan, Map_Node_t * pNode ) fPhase = !fPhase; pCut = pNodeR->pCutBest[fPhase]; } + if ( pMan->fUseProfile ) + Mio_GateIncProfile2( pCut->M[fPhase].pSuperBest->pRoot ); // visit the transitive fanin uPhase = pCut->M[fPhase].uPhaseBest; for ( i = 0; i < pCut->nLeaves; i++ ) @@ -442,6 +451,8 @@ void Map_MappingSetRefs( Map_Man_t * pMan ) { Map_Node_t * pNode; int i; + if ( pMan->fUseProfile ) + Mio_LibraryCleanProfile2( pMan->pSuperLib->pGenlib ); // clean all references for ( i = 0; i < pMan->vMapObjs->nSize; i++ ) { @@ -476,6 +487,8 @@ float Map_MappingGetArea( Map_Man_t * pMan ) Map_Node_t * pNode; float Area = 0.0; int i; + if ( pMan->fUseProfile ) + Mio_LibraryCleanProfile2( pMan->pSuperLib->pGenlib ); for ( i = 0; i < pMan->vMapObjs->nSize; i++ ) { pNode = pMan->vMapObjs->pArray[i]; @@ -492,10 +505,18 @@ float Map_MappingGetArea( Map_Man_t * pMan ) { // count area of the negative phase if ( pNode->pCutBest[0] && (pNode->nRefAct[0] > 0 || pNode->pCutBest[1] == NULL) ) + { Area += pNode->pCutBest[0]->M[0].pSuperBest->Area; + if ( pMan->fUseProfile ) + Mio_GateIncProfile2( pNode->pCutBest[0]->M[0].pSuperBest->pRoot ); + } // count area of the positive phase if ( pNode->pCutBest[1] && (pNode->nRefAct[1] > 0 || pNode->pCutBest[0] == NULL) ) + { Area += pNode->pCutBest[1]->M[1].pSuperBest->Area; + if ( pMan->fUseProfile ) + Mio_GateIncProfile2( pNode->pCutBest[1]->M[1].pSuperBest->pRoot ); + } } // count area of the interver if we need to implement one phase with another phase if ( (pNode->pCutBest[0] == NULL && pNode->nRefAct[0] > 0) || diff --git a/src/map/mio/mio.h b/src/map/mio/mio.h index 35b5641c..e4e15c6f 100644 --- a/src/map/mio/mio.h +++ b/src/map/mio/mio.h @@ -162,6 +162,8 @@ extern void Mio_GateSetProfile ( Mio_Gate_t * pGate, int Pro extern void Mio_GateSetProfile2 ( Mio_Gate_t * pGate, int Prof ); extern void Mio_GateIncProfile2 ( Mio_Gate_t * pGate ); extern void Mio_GateDecProfile2 ( Mio_Gate_t * pGate ); +extern void Mio_GateAddToProfile ( Mio_Gate_t * pGate, int Prof ); +extern void Mio_GateAddToProfile2 ( Mio_Gate_t * pGate, int Prof ); extern int Mio_GateIsInv ( Mio_Gate_t * pGate ); extern char * Mio_PinReadName ( Mio_Pin_t * pPin ); extern Mio_PinPhase_t Mio_PinReadPhase ( Mio_Pin_t * pPin ); @@ -209,12 +211,13 @@ extern void Mio_LibraryTransferCellIds(); extern void Mio_LibraryReadProfile( FILE * pFile, Mio_Library_t * pLib ); extern void Mio_LibraryWriteProfile( FILE * pFile, Mio_Library_t * pLib ); extern void Mio_LibraryTransferProfile( Mio_Library_t * pLibDst, Mio_Library_t * pLibSrc ); +extern void Mio_LibraryTransferProfile2( Mio_Library_t * pLibDst, Mio_Library_t * pLibSrc ); extern int Mio_LibraryHasProfile( Mio_Library_t * pLib ); extern void Mio_LibraryCleanProfile2( Mio_Library_t * pLib ); /*=== sclUtil.c =========================================================*/ extern Mio_Library_t * Abc_SclDeriveGenlibSimple( void * pScl ); -extern Mio_Library_t * Abc_SclDeriveGenlib( void * pScl, float Slew, float Gain, int nGatesMin, int fVerbose ); +extern Mio_Library_t * Abc_SclDeriveGenlib( void * pScl, void * pMio, float Slew, float Gain, int nGatesMin, int fVerbose ); extern int Abc_SclHasDelayInfo( void * pScl ); diff --git a/src/map/mio/mioApi.c b/src/map/mio/mioApi.c index 3d24f4d6..82b76a27 100644 --- a/src/map/mio/mioApi.c +++ b/src/map/mio/mioApi.c @@ -163,31 +163,33 @@ char * Mio_LibraryReadSopByName( Mio_Library_t * pLib, char * pName ) SeeAlso [] ***********************************************************************/ -char * Mio_GateReadName ( Mio_Gate_t * pGate ) { return pGate->pName; } -char * Mio_GateReadOutName ( Mio_Gate_t * pGate ) { return pGate->pOutName; } -double Mio_GateReadArea ( Mio_Gate_t * pGate ) { return pGate->dArea; } -char * Mio_GateReadForm ( Mio_Gate_t * pGate ) { return pGate->pForm; } -Mio_Pin_t * Mio_GateReadPins ( Mio_Gate_t * pGate ) { return pGate->pPins; } -Mio_Library_t * Mio_GateReadLib ( Mio_Gate_t * pGate ) { return pGate->pLib; } -Mio_Gate_t * Mio_GateReadNext ( Mio_Gate_t * pGate ) { return pGate->pNext; } -Mio_Gate_t * Mio_GateReadTwin ( Mio_Gate_t * pGate ) { return pGate->pTwin; } -int Mio_GateReadPinNum ( Mio_Gate_t * pGate ) { return pGate->nInputs; } -double Mio_GateReadDelayMax( Mio_Gate_t * pGate ) { return pGate->dDelayMax; } -char * Mio_GateReadSop ( Mio_Gate_t * pGate ) { return pGate->pSop; } -Vec_Int_t * Mio_GateReadExpr ( Mio_Gate_t * pGate ) { return pGate->vExpr; } -word Mio_GateReadTruth ( Mio_Gate_t * pGate ) { return pGate->nInputs <= 6 ? pGate->uTruth : 0; } -word * Mio_GateReadTruthP ( Mio_Gate_t * pGate ) { return pGate->nInputs <= 6 ? NULL: pGate->pTruth; } -int Mio_GateReadValue ( Mio_Gate_t * pGate ) { return pGate->Value; } -int Mio_GateReadCell ( Mio_Gate_t * pGate ) { return pGate->Cell; } -int Mio_GateReadProfile ( Mio_Gate_t * pGate ) { return pGate->Profile; } -int Mio_GateReadProfile2( Mio_Gate_t * pGate ) { return pGate->Profile2; } -void Mio_GateSetValue ( Mio_Gate_t * pGate, int Value ) { pGate->Value = Value; } -void Mio_GateSetCell ( Mio_Gate_t * pGate, int Cell ) { pGate->Cell = Cell; } -void Mio_GateSetProfile ( Mio_Gate_t * pGate, int Prof ) { pGate->Profile = Prof; } -void Mio_GateSetProfile2 ( Mio_Gate_t * pGate, int Prof ) { pGate->Profile2 = Prof; } -void Mio_GateIncProfile2 ( Mio_Gate_t * pGate ) { pGate->Profile2++; } -void Mio_GateDecProfile2 ( Mio_Gate_t * pGate ) { pGate->Profile2--; } -int Mio_GateIsInv ( Mio_Gate_t * pGate ) { return pGate->uTruth == ABC_CONST(0x5555555555555555); } +char * Mio_GateReadName ( Mio_Gate_t * pGate ) { return pGate->pName; } +char * Mio_GateReadOutName ( Mio_Gate_t * pGate ) { return pGate->pOutName; } +double Mio_GateReadArea ( Mio_Gate_t * pGate ) { return pGate->dArea; } +char * Mio_GateReadForm ( Mio_Gate_t * pGate ) { return pGate->pForm; } +Mio_Pin_t * Mio_GateReadPins ( Mio_Gate_t * pGate ) { return pGate->pPins; } +Mio_Library_t * Mio_GateReadLib ( Mio_Gate_t * pGate ) { return pGate->pLib; } +Mio_Gate_t * Mio_GateReadNext ( Mio_Gate_t * pGate ) { return pGate->pNext; } +Mio_Gate_t * Mio_GateReadTwin ( Mio_Gate_t * pGate ) { return pGate->pTwin; } +int Mio_GateReadPinNum ( Mio_Gate_t * pGate ) { return pGate->nInputs; } +double Mio_GateReadDelayMax ( Mio_Gate_t * pGate ) { return pGate->dDelayMax; } +char * Mio_GateReadSop ( Mio_Gate_t * pGate ) { return pGate->pSop; } +Vec_Int_t * Mio_GateReadExpr ( Mio_Gate_t * pGate ) { return pGate->vExpr; } +word Mio_GateReadTruth ( Mio_Gate_t * pGate ) { return pGate->nInputs <= 6 ? pGate->uTruth : 0; } +word * Mio_GateReadTruthP ( Mio_Gate_t * pGate ) { return pGate->nInputs <= 6 ? NULL: pGate->pTruth; } +int Mio_GateReadValue ( Mio_Gate_t * pGate ) { return pGate->Value; } +int Mio_GateReadCell ( Mio_Gate_t * pGate ) { return pGate->Cell; } +int Mio_GateReadProfile ( Mio_Gate_t * pGate ) { return pGate->Profile; } +int Mio_GateReadProfile2 ( Mio_Gate_t * pGate ) { return pGate->Profile2; } +void Mio_GateSetValue ( Mio_Gate_t * pGate, int Value ) { pGate->Value = Value; } +void Mio_GateSetCell ( Mio_Gate_t * pGate, int Cell ) { pGate->Cell = Cell; } +void Mio_GateSetProfile ( Mio_Gate_t * pGate, int Prof ) { pGate->Profile = Prof; } +void Mio_GateSetProfile2 ( Mio_Gate_t * pGate, int Prof ) { pGate->Profile2 = Prof; } +void Mio_GateIncProfile2 ( Mio_Gate_t * pGate ) { pGate->Profile2++; } +void Mio_GateDecProfile2 ( Mio_Gate_t * pGate ) { pGate->Profile2--; } +void Mio_GateAddToProfile ( Mio_Gate_t * pGate, int Prof ) { pGate->Profile += Prof; } +void Mio_GateAddToProfile2( Mio_Gate_t * pGate, int Prof ) { pGate->Profile2 += Prof; } +int Mio_GateIsInv ( Mio_Gate_t * pGate ) { return pGate->uTruth == ABC_CONST(0x5555555555555555); } /**Function************************************************************* @@ -208,7 +210,7 @@ double Mio_PinReadDelayBlockRise ( Mio_Pin_t * pPin ) { return p double Mio_PinReadDelayFanoutRise( Mio_Pin_t * pPin ) { return pPin->dDelayFanoutRise;} double Mio_PinReadDelayBlockFall ( Mio_Pin_t * pPin ) { return pPin->dDelayBlockFall; } double Mio_PinReadDelayFanoutFall( Mio_Pin_t * pPin ) { return pPin->dDelayFanoutFall;} -double Mio_PinReadDelayBlockMax ( Mio_Pin_t * pPin ) { return pPin->dDelayBlockMax; } +double Mio_PinReadDelayBlockMax ( Mio_Pin_t * pPin ) { return pPin->dDelayBlockMax; } Mio_Pin_t * Mio_PinReadNext ( Mio_Pin_t * pPin ) { return pPin->pNext; } /**Function************************************************************* diff --git a/src/map/mio/mioUtils.c b/src/map/mio/mioUtils.c index 14b8b45d..c7c6c6dc 100644 --- a/src/map/mio/mioUtils.c +++ b/src/map/mio/mioUtils.c @@ -1403,19 +1403,55 @@ int Mio_LibraryHasProfile( Mio_Library_t * pLib ) return 0; } + void Mio_LibraryTransferProfile( Mio_Library_t * pLibDst, Mio_Library_t * pLibSrc ) { Mio_Gate_t * pGateSrc, * pGateDst; + Mio_LibraryForEachGate( pLibDst, pGateDst ) + Mio_GateSetProfile( pGateDst, 0 ); Mio_LibraryForEachGate( pLibSrc, pGateSrc ) if ( Mio_GateReadProfile(pGateSrc) > 0 ) { + // find gate by name pGateDst = Mio_LibraryReadGateByName( pLibDst, Mio_GateReadName(pGateSrc), NULL ); if ( pGateDst == NULL ) { - printf( "Cannot find gate \"%s\" in library \"%s\".\n", Mio_GateReadName(pGateSrc), Mio_LibraryReadName(pLibDst) ); - continue; + // find gate by function + Mio_LibraryForEachGate( pLibDst, pGateDst ) + if ( pGateDst->uTruth == pGateSrc->uTruth ) + break; + if ( pGateDst == NULL ) + { + printf( "Cannot find gate \"%s\" in library \"%s\".\n", Mio_GateReadName(pGateSrc), Mio_LibraryReadName(pLibDst) ); + continue; + } + } + Mio_GateAddToProfile( pGateDst, Mio_GateReadProfile(pGateSrc) ); + } +} +void Mio_LibraryTransferProfile2( Mio_Library_t * pLibDst, Mio_Library_t * pLibSrc ) +{ + Mio_Gate_t * pGateSrc, * pGateDst; + Mio_LibraryForEachGate( pLibDst, pGateDst ) + Mio_GateSetProfile2( pGateDst, 0 ); + Mio_LibraryForEachGate( pLibSrc, pGateSrc ) + if ( Mio_GateReadProfile2(pGateSrc) > 0 ) + { + // find gate by name + pGateDst = Mio_LibraryReadGateByName( pLibDst, Mio_GateReadName(pGateSrc), NULL ); + if ( pGateDst == NULL ) + { + // find gate by function + Mio_LibraryForEachGate( pLibDst, pGateDst ) + if ( pGateDst->uTruth == pGateSrc->uTruth ) + break; + if ( pGateDst == NULL ) + { + printf( "Cannot find gate \"%s\" in library \"%s\".\n", Mio_GateReadName(pGateSrc), Mio_LibraryReadName(pLibDst) ); + continue; + } } - Mio_GateSetProfile( pGateDst, Mio_GateReadProfile(pGateSrc) ); + Mio_GateAddToProfile2( pGateDst, Mio_GateReadProfile2(pGateSrc) ); } } diff --git a/src/map/scl/sclLibUtil.c b/src/map/scl/sclLibUtil.c index cb1655f6..ebd9cbc7 100644 --- a/src/map/scl/sclLibUtil.c +++ b/src/map/scl/sclLibUtil.c @@ -925,6 +925,74 @@ Vec_Str_t * Abc_SclProduceGenlibStr( SC_Lib * p, float Slew, float Gain, int nGa *pnCellCount = Count; return vStr; } +Vec_Str_t * Abc_SclProduceGenlibStrProfile( SC_Lib * p, Mio_Library_t * pLib, float Slew, float Gain, int nGatesMin, int * pnCellCount ) +{ + char Buffer[200]; + Vec_Str_t * vStr; + SC_Cell * pRepr; + SC_Pin * pPin; + int i, k, Count = 2, nClassMax = 0; + // find the largest number of cells in a class + SC_LibForEachCellClass( p, pRepr, i ) + if ( pRepr->n_outputs == 1 ) + nClassMax = Abc_MaxInt( nClassMax, Abc_SclClassCellNum(pRepr) ); + // update the number + if ( nGatesMin && nGatesMin >= nClassMax ) + nGatesMin = 0; + // mark skipped cells + Abc_SclMarkSkippedCells( p ); + vStr = Vec_StrAlloc( 1000 ); + Vec_StrPrintStr( vStr, "GATE _const0_ 0.00 z=CONST0;\n" ); + Vec_StrPrintStr( vStr, "GATE _const1_ 0.00 z=CONST1;\n" ); + SC_LibForEachCell( p, pRepr, i ) + { + if ( pRepr->n_inputs == 0 ) + continue; + if ( pRepr->n_outputs > 1 ) + continue; + if ( nGatesMin && pRepr->n_inputs > 2 && Abc_SclClassCellNum(pRepr) < nGatesMin ) + continue; + // check if the gate is in the profile + if ( pRepr->n_inputs > 1 ) + { + Mio_Gate_t * pGate = Mio_LibraryReadGateByName( pLib, pRepr->pName, NULL ); + if ( pGate == NULL || Mio_GateReadProfile(pGate) == 0 ) + continue; + } + // process gate + assert( strlen(pRepr->pName) < 200 ); + Vec_StrPrintStr( vStr, "GATE " ); + sprintf( Buffer, "%-16s", pRepr->pName ); + Vec_StrPrintStr( vStr, Buffer ); + Vec_StrPrintStr( vStr, " " ); +// sprintf( Buffer, "%7.2f", Abc_SclComputeAreaClass(pRepr) ); + sprintf( Buffer, "%7.2f", pRepr->area ); + Vec_StrPrintStr( vStr, Buffer ); + Vec_StrPrintStr( vStr, " " ); + Vec_StrPrintStr( vStr, SC_CellPinName(pRepr, pRepr->n_inputs) ); + Vec_StrPrintStr( vStr, "=" ); + Vec_StrPrintStr( vStr, SC_CellPinOutFunc(pRepr, 0) ? SC_CellPinOutFunc(pRepr, 0) : "?" ); + Vec_StrPrintStr( vStr, ";\n" ); + SC_CellForEachPinIn( pRepr, pPin, k ) + { + float Delay = Abc_SclComputeDelayClassPin( p, pRepr, k, Slew, Gain ); + assert( Delay > 0 ); + Vec_StrPrintStr( vStr, " PIN " ); + sprintf( Buffer, "%-4s", pPin->pName ); + Vec_StrPrintStr( vStr, Buffer ); + sprintf( Buffer, " UNKNOWN 1 999 %7.2f 0.00 %7.2f 0.00\n", Delay, Delay ); + Vec_StrPrintStr( vStr, Buffer ); + } + Count++; + } + Vec_StrPrintStr( vStr, "\n.end\n" ); + Vec_StrPush( vStr, '\0' ); +// printf( "GENLIB library with %d gates is produced:\n", Count ); +// printf( "%s", Vec_StrArray(vStr) ); + if ( pnCellCount ) + *pnCellCount = Count; + return vStr; +} void Abc_SclDumpGenlib( char * pFileName, SC_Lib * p, float SlewInit, float Gain, int nGatesMin ) { int nCellCount = 0; @@ -948,13 +1016,18 @@ void Abc_SclDumpGenlib( char * pFileName, SC_Lib * p, float SlewInit, float Gain fclose( pFile ); printf( "Written GENLIB library with %d gates into file \"%s\".\n", nCellCount, FileName ); } -Mio_Library_t * Abc_SclDeriveGenlib( void * pScl, float SlewInit, float Gain, int nGatesMin, int fVerbose ) +Mio_Library_t * Abc_SclDeriveGenlib( void * pScl, void * pMio, float SlewInit, float Gain, int nGatesMin, int fVerbose ) { int nCellCount = 0; SC_Lib * p = (SC_Lib *)pScl; float Slew = (SlewInit == 0) ? Abc_SclComputeAverageSlew(p) : SlewInit; - Vec_Str_t * vStr = Abc_SclProduceGenlibStr( p, Slew, Gain, nGatesMin, &nCellCount ); - Mio_Library_t * pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0 ); + Vec_Str_t * vStr; + Mio_Library_t * pLib; + if ( pMio == NULL ) + vStr = Abc_SclProduceGenlibStr( p, Slew, Gain, nGatesMin, &nCellCount ); + else + vStr = Abc_SclProduceGenlibStrProfile( p, (Mio_Library_t *)pMio, Slew, Gain, nGatesMin, &nCellCount ); + pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0 ); Vec_StrFree( vStr ); if ( !pLib ) printf( "Reading library has filed.\n" ); |