diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/aig/gia/giaIf.c | 56 | ||||
-rw-r--r-- | src/base/abci/abc.c | 4 | ||||
-rw-r--r-- | src/base/abci/abcIf.c | 17 | ||||
-rw-r--r-- | src/map/if/if.h | 32 | ||||
-rw-r--r-- | src/map/if/ifDelay.c | 111 | ||||
-rw-r--r-- | src/map/if/ifDsd.c | 19 | ||||
-rw-r--r-- | src/map/if/ifMan.c | 13 | ||||
-rw-r--r-- | src/map/if/ifMap.c | 10 | ||||
-rw-r--r-- | src/map/if/ifTime.c | 670 | ||||
-rw-r--r-- | src/map/if/ifTruth.c | 17 |
10 files changed, 179 insertions, 770 deletions
diff --git a/src/aig/gia/giaIf.c b/src/aig/gia/giaIf.c index e60cbeae..c795f5f5 100644 --- a/src/aig/gia/giaIf.c +++ b/src/aig/gia/giaIf.c @@ -618,58 +618,6 @@ If_Man_t * Gia_ManToIf( Gia_Man_t * p, If_Par_t * pPars ) return pIfMan; } - -/**Function************************************************************* - - Synopsis [Derives node's AIG after SOP balancing] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Gia_ManNodeIfSopToGiaInt( Gia_Man_t * pNew, Vec_Wrd_t * vAnds, int nVars, Vec_Int_t * vLeaves, int fHash ) -{ - Vec_Int_t * vResults; - int iRes0, iRes1, iRes = -1; - If_And_t This; - word Entry; - int i; - if ( Vec_WrdSize(vAnds) == 0 ) - return 0; - if ( Vec_WrdSize(vAnds) == 1 && Vec_WrdEntry(vAnds,0) == 0 ) - return 1; - vResults = Vec_IntAlloc( Vec_WrdSize(vAnds) ); - for ( i = 0; i < nVars; i++ ) - Vec_IntPush( vResults, Vec_IntEntry(vLeaves, i) ); - Vec_WrdForEachEntryStart( vAnds, Entry, i, nVars ) - { - This = If_WrdToAnd( Entry ); - iRes0 = Abc_LitNotCond( Vec_IntEntry(vResults, This.iFan0), This.fCompl0 ); - iRes1 = Abc_LitNotCond( Vec_IntEntry(vResults, This.iFan1), This.fCompl1 ); - if ( fHash ) - iRes = Gia_ManHashAnd( pNew, iRes0, iRes1 ); - else if ( iRes0 == iRes1 ) - iRes = iRes0; - else - iRes = Gia_ManAppendAnd( pNew, iRes0, iRes1 ); - Vec_IntPush( vResults, iRes ); - } - Vec_IntFree( vResults ); - return Abc_LitNotCond( iRes, This.fCompl ); -} -int Gia_ManNodeIfSopToGia( Gia_Man_t * pNew, If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vLeaves, int fHash ) -{ - int iResult; - Vec_Wrd_t * vArray; - vArray = If_CutDelaySopArray( p, pCut ); - iResult = Gia_ManNodeIfSopToGiaInt( pNew, vArray, If_CutLeaveNum(pCut), vLeaves, fHash ); -// Vec_WrdFree( vArray ); - return iResult; -} - /**Function************************************************************* Synopsis [Rebuilds GIA from mini AIG.] @@ -722,9 +670,9 @@ int Gia_ManBuildFromMiniInt( Gia_Man_t * pNew, Vec_Int_t * vLeaves, Vec_Int_t * int Gia_ManBuildFromMini( Gia_Man_t * pNew, If_Man_t * pIfMan, If_Cut_t * pCut, Vec_Int_t * vLeaves, Vec_Int_t * vAig, int fHash, int fUseDsd ) { if ( fUseDsd ) - If_DsdCutBalanceAig( pIfMan, pCut, vAig ); + If_CutDsdBalanceEval( pIfMan, pCut, vAig ); else - If_CutDelaySopArray3( pIfMan, pCut, vAig ); + If_CutSopBalanceEval( pIfMan, pCut, vAig ); return Gia_ManBuildFromMiniInt( pNew, vLeaves, vAig, fHash ); } diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 602b24b3..2e2c4e73 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -15102,7 +15102,7 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv ) pPars->fTruth = 1; pPars->fCutMin = 1; pPars->fExpRed = 0; - pPars->fUsePerm = 1; + pPars->fUsePerm = 0; pPars->pLutLib = NULL; } // modify for delay optimization @@ -29855,7 +29855,7 @@ int Abc_CommandAbc9If( Abc_Frame_t * pAbc, int argc, char ** argv ) pPars->fTruth = 1; pPars->fCutMin = 1; pPars->fExpRed = 0; - pPars->fUsePerm = 1; + pPars->fUsePerm = 0; pPars->pLutLib = NULL; } // modify for delay optimization diff --git a/src/base/abci/abcIf.c b/src/base/abci/abcIf.c index 80412c9a..8a52260a 100644 --- a/src/base/abci/abcIf.c +++ b/src/base/abci/abcIf.c @@ -391,14 +391,13 @@ Hop_Obj_t * Abc_NodeBuildFromMiniInt( Hop_Man_t * pMan, Vec_Int_t * vAig, int nL return piLit; } } -Hop_Obj_t * Abc_NodeBuildFromMini( Hop_Man_t * pMan, If_Man_t * p, If_Cut_t * pCut ) +Hop_Obj_t * Abc_NodeBuildFromMini( Hop_Man_t * pMan, If_Man_t * p, If_Cut_t * pCut, int fUseDsd ) { - Hop_Obj_t * pResult; - if ( p->vArray == NULL ) - p->vArray = Vec_IntAlloc(1000); - If_CutDelaySopArray3( p, pCut, p->vArray ); - pResult = Abc_NodeBuildFromMiniInt( pMan, p->vArray, If_CutLeaveNum(pCut) ); - return pResult; + if ( fUseDsd ) + If_CutDsdBalanceEval( p, pCut, p->vArray ); + else + If_CutSopBalanceEval( p, pCut, p->vArray ); + return Abc_NodeBuildFromMiniInt( pMan, p->vArray, If_CutLeaveNum(pCut) ); } /**Function************************************************************* @@ -477,9 +476,9 @@ Abc_Obj_t * Abc_NodeFromIf_rec( Abc_Ntk_t * pNtkNew, If_Man_t * pIfMan, If_Obj_t } } else if ( pIfMan->pPars->fDelayOpt ) - pNodeNew->pData = Abc_NodeBuildFromMini( (Hop_Man_t *)pNtkNew->pManFunc, pIfMan, pCutBest ); + pNodeNew->pData = Abc_NodeBuildFromMini( (Hop_Man_t *)pNtkNew->pManFunc, pIfMan, pCutBest, 0 ); else if ( pIfMan->pPars->fDsdBalance ) - pNodeNew->pData = Abc_NodeBuildFromMini( (Hop_Man_t *)pNtkNew->pManFunc, pIfMan, pCutBest ); + pNodeNew->pData = Abc_NodeBuildFromMini( (Hop_Man_t *)pNtkNew->pManFunc, pIfMan, pCutBest, 1 ); else if ( pIfMan->pPars->fUserRecLib ) { extern Hop_Obj_t * Abc_RecToHop3( Hop_Man_t * pMan, If_Man_t * pIfMan, If_Cut_t * pCut, If_Obj_t * pIfObj ); diff --git a/src/map/if/if.h b/src/map/if/if.h index 2184b08b..0e86ff2b 100644 --- a/src/map/if/if.h +++ b/src/map/if/if.h @@ -39,6 +39,7 @@ #include "misc/util/utilTruth.h" #include "opt/dau/dau.h" #include "misc/vec/vecHash.h" +#include "misc/vec/vecWec.h" ABC_NAMESPACE_HEADER_START @@ -237,6 +238,7 @@ struct If_Man_t_ int nCuts5, nCuts5a; If_DsdMan_t * pIfDsdMan; // DSD manager Vec_Mem_t * vTtMem[IF_MAX_FUNC_LUTSIZE+1]; // truth table memory and hash table + Vec_Wec_t * vTtIsops[IF_MAX_FUNC_LUTSIZE+1]; // mapping of truth table into DSD Vec_Int_t * vTtDsds[IF_MAX_FUNC_LUTSIZE+1]; // mapping of truth table into DSD Vec_Str_t * vTtPerms[IF_MAX_FUNC_LUTSIZE+1]; // mapping of truth table into permutations Hash_IntMan_t * vPairHash; // hashing pairs of truth tables @@ -327,18 +329,6 @@ struct If_Obj_t_ If_Cut_t CutBest; // the best cut selected }; -typedef struct If_And_t_ If_And_t; -struct If_And_t_ -{ - unsigned iFan0 : 15; // fanin0 - unsigned fCompl0 : 1; // compl fanin0 - unsigned iFan1 : 15; // fanin1 - unsigned fCompl1 : 1; // compl fanin1 - unsigned Id : 15; // Id - unsigned fCompl : 1; // compl output - unsigned Delay : 16; // delay -}; - typedef struct If_Box_t_ If_Box_t; struct If_Box_t_ { @@ -428,11 +418,6 @@ static inline If_Obj_t * If_CutLeaf( If_Man_t * p, If_Cut_t * pCut, int i ) { a static inline float If_CutLutArea( If_Man_t * p, If_Cut_t * pCut ) { return pCut->fUser? (float)pCut->Cost : (p->pPars->pLutLib? p->pPars->pLutLib->pLutAreas[pCut->nLeaves] : (float)1.0); } static inline float If_CutLutDelay( If_LibLut_t * p, int Size, int iPin ) { return p ? (p->fVarPinDelays ? p->pLutDelays[Size][iPin] : p->pLutDelays[Size][0]) : 1.0; } -static inline word If_AndToWrd( If_And_t m ) { union { If_And_t x; word y; } v; v.x = m; return v.y; } -static inline If_And_t If_WrdToAnd( word m ) { union { If_And_t x; word y; } v; v.y = m; return v.x; } -static inline void If_AndClear( If_And_t * pNode ) { *pNode = If_WrdToAnd(0); } - - //////////////////////////////////////////////////////////////////////// /// MACRO DEFINITIONS /// @@ -536,8 +521,9 @@ extern int If_CluCheckExt( void * p, word * pTruth, int nVars, int n extern int If_CluCheckExt3( void * p, word * pTruth, int nVars, int nLutLeaf, int nLutLeaf2, int nLutRoot, char * pLut0, char * pLut1, char * pLut2, word * pFunc0, word * pFunc1, word * pFunc2 ); /*=== ifDelay.c =============================================================*/ -extern int If_CutDelaySopArray3( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vAig ); -extern int If_CutPinDelaysSopArray3( If_Man_t * p, If_Cut_t * pCut, char * pPerm ); +extern int If_CutDelaySop( If_Man_t * p, If_Cut_t * pCut ); +extern int If_CutSopBalanceEval( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vAig ); +extern int If_CutSopBalancePinDelays( If_Man_t * p, If_Cut_t * pCut, char * pPerm ); /*=== ifDsd.c =============================================================*/ extern If_DsdMan_t * If_DsdManAlloc( int nVars, int nLutSize ); extern void If_DsdManPrint( If_DsdMan_t * p, char * pFileName, int Number, int Support, int fOccurs, int fTtDump, int fVerbose ); @@ -554,8 +540,8 @@ extern int If_DsdManLutSize( If_DsdMan_t * p ); extern int If_DsdManSuppSize( If_DsdMan_t * p, int iDsd ); extern int If_DsdManCheckDec( If_DsdMan_t * p, int iDsd ); extern unsigned If_DsdManCheckXY( If_DsdMan_t * p, int iDsd, int LutSize, int fDerive, int fHighEffort, int fVerbose ); -extern int If_DsdCutBalanceCost( If_Man_t * pIfMan, If_Cut_t * pCut ); -extern int If_DsdCutBalanceAig( If_Man_t * pIfMan, If_Cut_t * pCut, Vec_Int_t * vAig ); +extern int If_CutDsdBalanceEval( If_Man_t * pIfMan, If_Cut_t * pCut, Vec_Int_t * vAig ); +extern int If_CutDsdBalancePinDelays( If_Man_t * p, If_Cut_t * pCut, char * pPerm ); /*=== ifLib.c =============================================================*/ extern If_LibLut_t * If_LibLutRead( char * FileName ); extern If_LibLut_t * If_LibLutDup( If_LibLut_t * p ); @@ -608,10 +594,6 @@ extern unsigned If_ManSatCheckXYall( void * pSat, int nLutSize, word * pT /*=== ifSeq.c =============================================================*/ extern int If_ManPerformMappingSeq( If_Man_t * p ); /*=== ifTime.c ============================================================*/ -extern int If_CutDelaySopCost( If_Man_t * p, If_Cut_t * pCut ); -extern int If_CutDelaySopCost2( If_Man_t * p, If_Cut_t * pCut ); -extern int If_CutDelaySop( If_Man_t * p, If_Cut_t * pCut ); -extern Vec_Wrd_t * If_CutDelaySopArray( If_Man_t * p, If_Cut_t * pCut ); extern float If_CutDelay( If_Man_t * p, If_Obj_t * pObj, If_Cut_t * pCut ); extern void If_CutPropagateRequired( If_Man_t * p, If_Obj_t * pObj, If_Cut_t * pCut, float Required ); /*=== ifTruth.c ===========================================================*/ diff --git a/src/map/if/ifDelay.c b/src/map/if/ifDelay.c index dc4afee0..61b3e6f1 100644 --- a/src/map/if/ifDelay.c +++ b/src/map/if/ifDelay.c @@ -19,7 +19,6 @@ ***********************************************************************/ #include "if.h" -#include "bool/kit/kit.h" ABC_NAMESPACE_IMPL_START @@ -33,6 +32,77 @@ ABC_NAMESPACE_IMPL_START /**Function************************************************************* + Synopsis [Computes the SOP delay using balanced AND decomposition.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline int If_CutMaxCubeSize( Vec_Int_t * vCover, int nVars ) +{ + int i, k, Entry, Literal, Count, CountMax = 0; + Vec_IntForEachEntry( vCover, Entry, i ) + { + Count = 0; + for ( k = 0; k < nVars; k++ ) + { + Literal = (3 & (Entry >> (k << 1))); + if ( Literal == 1 || Literal == 2 ) + Count++; + } + CountMax = Abc_MaxInt( CountMax, Count ); + } + return CountMax; +} +int If_CutDelaySop( If_Man_t * p, If_Cut_t * pCut ) +{ + // delay is calculated using 1+log2(NumFanins) + static double GateDelays[20] = { 1.00, 1.00, 2.00, 2.58, 3.00, 3.32, 3.58, 3.81, 4.00, 4.17, 4.32, 4.46, 4.58, 4.70, 4.81, 4.91, 5.00, 5.09, 5.17, 5.25 }; + Vec_Int_t * vCover; + If_Obj_t * pLeaf; + int i, nLitMax, Delay, DelayMax; + // mark cut as a user cut + pCut->fUser = 1; + if ( pCut->nLeaves == 0 ) + return 0; + if ( pCut->nLeaves == 1 ) + return (int)If_ObjCutBest(If_CutLeaf(p, pCut, 0))->Delay; + vCover = Vec_WecEntry( p->vTtIsops[pCut->nLeaves], Abc_Lit2Var(If_CutTruthLit(pCut)) ); + if ( Vec_IntSize(vCover) == 0 ) + return -1; + // mark the output as complemented +// vAnds = If_CutDelaySopAnds( p, pCut, p->vCover, RetValue ^ pCut->fCompl ); + if ( Vec_IntSize(p->vCover) > p->pPars->nGateSize ) + return ABC_INFINITY; + // set the area cost + assert( If_CutLeaveNum(pCut) >= 0 && If_CutLeaveNum(pCut) <= 16 ); + // compute the gate delay + nLitMax = If_CutMaxCubeSize( p->vCover, If_CutLeaveNum(pCut) ); + if ( Vec_IntSize(p->vCover) < 2 ) + { + pCut->Cost = Vec_IntSize(p->vCover); + Delay = (int)(GateDelays[If_CutLeaveNum(pCut)] + 0.5); + DelayMax = 0; + If_CutForEachLeaf( p, pCut, pLeaf, i ) + DelayMax = Abc_MaxInt( DelayMax, If_ObjCutBest(pLeaf)->Delay + (pCut->pPerm[i] = (char)Delay) ); + } + else + { + pCut->Cost = Vec_IntSize(p->vCover) + 1; + Delay = (int)(GateDelays[If_CutLeaveNum(pCut)] + GateDelays[nLitMax] + 0.5); + DelayMax = 0; + If_CutForEachLeaf( p, pCut, pLeaf, i ) + DelayMax = Abc_MaxInt( DelayMax, If_ObjCutBest(pLeaf)->Delay + (pCut->pPerm[i] = (char)Delay) ); + } + return DelayMax; +} + + +/**Function************************************************************* + Synopsis [Naive implementation of log-counter.] Description [Incrementally computes [log2(SUMi(2^di)).] @@ -453,7 +523,7 @@ static inline word If_LogPinDelaysMulti( word * pPinDels, int nFanins, int nSupp pPinDels[i-1] = If_CutPinDelayMax( pPinDels[i], pPinDels[i-1], nSuppAll, 1 + fXor ); return pPinDels[0]; } -int If_CutPinDelaysSopArray3IntInt( Vec_Int_t * vCover, int * pTimes, int nSuppAll, char * pPerm ) +int If_CutSopBalancePinDelaysInt( Vec_Int_t * vCover, int * pTimes, int nSuppAll, char * pPerm ) { word pPinDelsAnd[IF_MAX_FUNC_LUTSIZE], pPinDelsOr[32]; int nCounterAnd, pCounterAnd[IF_MAX_FUNC_LUTSIZE]; @@ -483,18 +553,8 @@ int If_CutPinDelaysSopArray3IntInt( Vec_Int_t * vCover, int * pTimes, int nSuppA If_CutPinDelayTranslate( ResOr, nSuppAll, pPerm ); return Delay; } -int If_CutPinDelaysSopArray3Int( unsigned * pTruth, int nLeaves, int * pTimes, Vec_Int_t * vCover, char * pPerm ) -{ - int RetValue = Kit_TruthIsop( pTruth, nLeaves, vCover, 1 ); - if ( RetValue == -1 ) - return -1; -// Kit_TruthIsopPrint( pTruth, nLeaves, vCover, 1 ); - return If_CutPinDelaysSopArray3IntInt( vCover, pTimes, nLeaves, pPerm ); -} -int If_CutPinDelaysSopArray3( If_Man_t * p, If_Cut_t * pCut, char * pPerm ) +int If_CutSopBalancePinDelays( If_Man_t * p, If_Cut_t * pCut, char * pPerm ) { - if ( p->vCover == NULL ) - p->vCover = Vec_IntAlloc(0); if ( pCut->nLeaves == 0 ) // const return 0; if ( pCut->nLeaves == 1 ) // variable @@ -504,10 +564,14 @@ int If_CutPinDelaysSopArray3( If_Man_t * p, If_Cut_t * pCut, char * pPerm ) } else { + Vec_Int_t * vCover; int i, pTimes[IF_MAX_FUNC_LUTSIZE]; + vCover = Vec_WecEntry( p->vTtIsops[pCut->nLeaves], Abc_Lit2Var(If_CutTruthLit(pCut)) ); + if ( Vec_IntSize(vCover) == 0 ) + return -1; for ( i = 0; i < If_CutLeaveNum(pCut); i++ ) pTimes[i] = (int)If_ObjCutBest(If_CutLeaf(p, pCut, i))->Delay; - return If_CutPinDelaysSopArray3Int( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), pTimes, p->vCover, pPerm ); + return If_CutSopBalancePinDelaysInt( vCover, pTimes, If_CutLeaveNum(pCut), pPerm ); } } @@ -522,7 +586,7 @@ int If_CutPinDelaysSopArray3( If_Man_t * p, If_Cut_t * pCut, char * pPerm ) SeeAlso [] ***********************************************************************/ -int If_CutDelaySopArray3IntInt( Vec_Int_t * vCover, int * pTimes, Vec_Int_t * vAig, int * piRes, int nSuppAll, int * pArea ) +int If_CutSopBalanceEvalIntInt( Vec_Int_t * vCover, int * pTimes, Vec_Int_t * vAig, int * piRes, int nSuppAll, int * pArea ) { int nCounterAnd, pCounterAnd[IF_MAX_FUNC_LUTSIZE], pFaninLitsAnd[IF_MAX_FUNC_LUTSIZE]; int nCounterOr, pCounterOr[32], pFaninLitsOr[32]; @@ -558,24 +622,21 @@ int If_CutDelaySopArray3IntInt( Vec_Int_t * vCover, int * pTimes, Vec_Int_t * vA *pArea += Vec_IntSize(vCover) == 1 ? 0 : Vec_IntSize(vCover) - 1; return Delay; } -int If_CutDelaySopArray3Int( unsigned * pTruth, int nLeaves, int * pTimes, Vec_Int_t * vCover, Vec_Int_t * vAig, int fCompl, int * pArea ) +int If_CutSopBalanceEvalInt( Vec_Int_t * vCover, int nLeaves, int * pTimes, Vec_Int_t * vAig, int fCompl, int * pArea ) { int iRes = 0, Res; - int RetValue = Kit_TruthIsop( pTruth, nLeaves, vCover, 1 ); - if ( RetValue == -1 ) + if ( Vec_IntSize(vCover) == 0 ) return -1; - Res = If_CutDelaySopArray3IntInt( vCover, pTimes, vAig, &iRes, nLeaves, pArea ); + Res = If_CutSopBalanceEvalIntInt( vCover, pTimes, vAig, &iRes, nLeaves, pArea ); assert( vAig == NULL || Abc_Lit2Var(iRes) == nLeaves + Abc_Lit2Var(Vec_IntSize(vAig)) - 1 ); if ( vAig ) - Vec_IntPush( vAig, RetValue ^ Abc_LitIsCompl(iRes) ^ fCompl ); + Vec_IntPush( vAig, Abc_LitIsCompl(iRes) ^ fCompl ); assert( vAig == NULL || (Vec_IntSize(vAig) & 1) ); return Res; } -int If_CutDelaySopArray3( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vAig ) +int If_CutSopBalanceEval( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vAig ) { pCut->fUser = 1; - if ( p->vCover == NULL ) - p->vCover = Vec_IntAlloc(0); if ( vAig ) Vec_IntClear( vAig ); if ( pCut->nLeaves == 0 ) // const @@ -596,11 +657,13 @@ int If_CutDelaySopArray3( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vAig ) } else { + Vec_Int_t * vCover = Vec_WecEntry( p->vTtIsops[pCut->nLeaves], Abc_Lit2Var(If_CutTruthLit(pCut)) ); + int fCompl = Abc_LitIsCompl(If_CutTruthLit(pCut)) ^ ((vCover->nCap >> 16) & 1); // hack to remember complemented attribute int Delay, Area = 0; int i, pTimes[IF_MAX_FUNC_LUTSIZE]; for ( i = 0; i < If_CutLeaveNum(pCut); i++ ) pTimes[i] = (int)If_ObjCutBest(If_CutLeaf(p, pCut, i))->Delay; - Delay = If_CutDelaySopArray3Int( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), pTimes, p->vCover, vAig, 0, &Area ); + Delay = If_CutSopBalanceEvalInt( vCover, If_CutLeaveNum(pCut), pTimes, vAig, fCompl, &Area ); pCut->Cost = Area; return Delay; } diff --git a/src/map/if/ifDsd.c b/src/map/if/ifDsd.c index 83dec183..6bcc44be 100644 --- a/src/map/if/ifDsd.c +++ b/src/map/if/ifDsd.c @@ -2025,7 +2025,7 @@ static inline int If_LogCounterAddAig( int * pTimes, int * pnTimes, int * pFanin SeeAlso [] ***********************************************************************/ -int If_DsdCutBalanceAig_rec( If_DsdMan_t * p, int Id, int * pTimes, int * pnSupp, Vec_Int_t * vAig, int * piLit, int nSuppAll, int * pArea ) +int If_CutDsdBalanceEval_rec( If_DsdMan_t * p, int Id, int * pTimes, int * pnSupp, Vec_Int_t * vAig, int * piLit, int nSuppAll, int * pArea ) { If_DsdObj_t * pObj = If_DsdVecObj( &p->vObjs, Id ); if ( If_DsdObjType(pObj) == IF_DSD_PRIME ) @@ -2041,7 +2041,7 @@ int If_DsdCutBalanceAig_rec( If_DsdMan_t * p, int Id, int * pTimes, int * pnSupp int i, iFanin, Delay[3], pFaninLits[3]; If_DsdObjForEachFaninLit( &p->vObjs, pObj, iFanin, i ) { - Delay[i] = If_DsdCutBalanceAig_rec( p, Abc_Lit2Var(iFanin), pTimes, pnSupp, vAig, pFaninLits+i, nSuppAll, pArea ); + Delay[i] = If_CutDsdBalanceEval_rec( p, Abc_Lit2Var(iFanin), pTimes, pnSupp, vAig, pFaninLits+i, nSuppAll, pArea ); if ( Delay[i] == -1 ) return -1; } @@ -2058,7 +2058,7 @@ int If_DsdCutBalanceAig_rec( If_DsdMan_t * p, int Id, int * pTimes, int * pnSupp int nCounter = 0, pCounter[IF_MAX_FUNC_LUTSIZE], pFaninLits[IF_MAX_FUNC_LUTSIZE]; If_DsdObjForEachFaninLit( &p->vObjs, pObj, iFanin, i ) { - Delay = If_DsdCutBalanceAig_rec( p, Abc_Lit2Var(iFanin), pTimes, pnSupp, vAig, pFaninLits+i, nSuppAll, pArea ); + Delay = If_CutDsdBalanceEval_rec( p, Abc_Lit2Var(iFanin), pTimes, pnSupp, vAig, pFaninLits+i, nSuppAll, pArea ); if ( Delay == -1 ) return -1; Result = If_LogCounterAddAig( pCounter, &nCounter, pFaninLits, Delay, pFaninLits[i], vAig, nSuppAll, fXor ); @@ -2070,11 +2070,11 @@ int If_DsdCutBalanceAig_rec( If_DsdMan_t * p, int Id, int * pTimes, int * pnSupp return Result; } } -int If_DsdCutBalanceAigInt( If_DsdMan_t * p, int iDsd, int * pTimes, Vec_Int_t * vAig, int * pArea ) +int If_CutDsdBalanceEvalInt( If_DsdMan_t * p, int iDsd, int * pTimes, Vec_Int_t * vAig, int * pArea ) { int nSupp = 0, iLit = 0; int nSuppAll = If_DsdVecLitSuppSize( &p->vObjs, iDsd ); - int Res = If_DsdCutBalanceAig_rec( p, Abc_Lit2Var(iDsd), pTimes, &nSupp, vAig, &iLit, nSuppAll, pArea ); + int Res = If_CutDsdBalanceEval_rec( p, Abc_Lit2Var(iDsd), pTimes, &nSupp, vAig, &iLit, nSuppAll, pArea ); assert( nSupp == nSuppAll ); assert( vAig == NULL || Abc_Lit2Var(iLit) == nSupp + Abc_Lit2Var(Vec_IntSize(vAig)) - 1 ); if ( vAig ) @@ -2082,7 +2082,7 @@ int If_DsdCutBalanceAigInt( If_DsdMan_t * p, int iDsd, int * pTimes, Vec_Int_t * assert( vAig == NULL || (Vec_IntSize(vAig) & 1) ); return Res; } -int If_DsdCutBalanceAig( If_Man_t * pIfMan, If_Cut_t * pCut, Vec_Int_t * vAig ) +int If_CutDsdBalanceEval( If_Man_t * pIfMan, If_Cut_t * pCut, Vec_Int_t * vAig ) { pCut->fUser = 1; if ( vAig ) @@ -2110,12 +2110,17 @@ int If_DsdCutBalanceAig( If_Man_t * pIfMan, If_Cut_t * pCut, Vec_Int_t * vAig ) int Delay, Area = 0; If_CutForEachLeaf( pIfMan, pCut, pLeaf, i ) pTimes[i] = (int)If_ObjCutBest(pLeaf)->Delay; - Delay = If_DsdCutBalanceAigInt( pIfMan->pIfDsdMan, If_CutDsdLit(pCut), pTimes, vAig, &Area ); + Delay = If_CutDsdBalanceEvalInt( pIfMan->pIfDsdMan, If_CutDsdLit(pCut), pTimes, vAig, &Area ); pCut->Cost = Area; return Delay; } } +int If_CutDsdBalancePinDelays( If_Man_t * p, If_Cut_t * pCut, char * pPerm ) +{ + return 0; +} + /**Function************************************************************* diff --git a/src/map/if/ifMan.c b/src/map/if/ifMan.c index 29d648ef..53eea1a7 100644 --- a/src/map/if/ifMan.c +++ b/src/map/if/ifMan.c @@ -73,6 +73,17 @@ If_Man_t * If_ManStart( If_Par_t * pPars ) p->vTtMem[v] = Vec_MemAllocForTT( v, pPars->fUseTtPerm ); for ( v = 0; v < 6; v++ ) p->vTtMem[v] = p->vTtMem[6]; + if ( p->pPars->fDelayOpt ) + { + p->vCover = Vec_IntAlloc( 0 ); + p->vArray = Vec_IntAlloc( 1000 ); + for ( v = 6; v <= p->pPars->nLutSize; v++ ) + p->vTtIsops[v] = Vec_WecAlloc( 1000 ); + for ( v = 6; v <= p->pPars->nLutSize; v++ ) + Vec_WecInit( p->vTtIsops[v], 2 ); + for ( v = 0; v < 6; v++ ) + p->vTtIsops[v] = p->vTtIsops[6]; + } } p->nPermWords = p->pPars->fUsePerm? If_CutPermWords( p->pPars->nLutSize ) : 0; p->nObjBytes = sizeof(If_Obj_t) + sizeof(int) * (p->pPars->nLutSize + p->nPermWords/* + p->nTruthWords*/); @@ -226,6 +237,8 @@ void If_ManStop( If_Man_t * p ) Vec_MemHashFree( p->vTtMem[i] ); for ( i = 6; i <= p->pPars->nLutSize; i++ ) Vec_MemFreeP( &p->vTtMem[i] ); + for ( i = 6; i <= p->pPars->nLutSize; i++ ) + Vec_WecFreeP( &p->vTtIsops[i] ); Mem_FixedStop( p->pMemObj, 0 ); ABC_FREE( p->pMemCi ); ABC_FREE( p->pMemAnd ); diff --git a/src/map/if/ifMap.c b/src/map/if/ifMap.c index 24fc6b9b..a497b37e 100644 --- a/src/map/if/ifMap.c +++ b/src/map/if/ifMap.c @@ -124,10 +124,9 @@ void If_ObjPerformMappingAnd( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPrep { // recompute the parameters of the best cut if ( p->pPars->fDelayOpt ) -// pCut->Delay = If_CutDelaySopCost( p, pCut ); - pCut->Delay = If_CutDelaySopArray3( p, pCut, NULL ); + pCut->Delay = If_CutSopBalanceEval( p, pCut, NULL ); else if ( p->pPars->fDsdBalance ) - pCut->Delay = If_DsdCutBalanceCost( p, pCut ); + pCut->Delay = If_CutDsdBalanceEval( p, pCut, NULL ); else if ( p->pPars->fUserRecLib ) pCut->Delay = If_CutDelayRecCost3( p, pCut, pObj ); else if( p->pPars->nGateSize > 0 ) @@ -281,10 +280,9 @@ void If_ObjPerformMappingAnd( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPrep continue; // check if the cut satisfies the required times if ( p->pPars->fDelayOpt ) -// pCut->Delay = If_CutDelaySopCost( p, pCut ); - pCut->Delay = If_CutDelaySopArray3( p, pCut, NULL ); + pCut->Delay = If_CutSopBalanceEval( p, pCut, NULL ); else if ( p->pPars->fDsdBalance ) - pCut->Delay = If_DsdCutBalanceCost( p, pCut ); + pCut->Delay = If_CutDsdBalanceEval( p, pCut, NULL ); else if ( p->pPars->fUserRecLib ) pCut->Delay = If_CutDelayRecCost3( p, pCut, pObj ); else if( p->pPars->nGateSize > 0 ) diff --git a/src/map/if/ifTime.c b/src/map/if/ifTime.c index 6d8a3805..f2c9c833 100644 --- a/src/map/if/ifTime.c +++ b/src/map/if/ifTime.c @@ -19,144 +19,20 @@ ***********************************************************************/ #include "if.h" -#include "bool/kit/kit.h" ABC_NAMESPACE_IMPL_START - //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -//static float s_ExtraDel[2][3] = { {1.0, 1.0, (float)0.1}, {1.0, 1.0, (float)0.1} }; - -static void If_CutSortInputPins( If_Man_t * p, If_Cut_t * pCut, int * pPinPerm, float * pPinDelays ); - -int s_timeNew; -int s_timeOld; - //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* - Synopsis [Inserts the entry while sorting them by delay.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -word If_AndVerifyArray( Vec_Wrd_t * vAnds, int nVars ) -{ - Vec_Wrd_t * vTruths; - If_And_t This; - word Entry, Truth0, Truth1, TruthR = 0; - int i; - static word Truth[8] = { - ABC_CONST(0xAAAAAAAAAAAAAAAA), - ABC_CONST(0xCCCCCCCCCCCCCCCC), - ABC_CONST(0xF0F0F0F0F0F0F0F0), - ABC_CONST(0xFF00FF00FF00FF00), - ABC_CONST(0xFFFF0000FFFF0000), - ABC_CONST(0xFFFFFFFF00000000), - ABC_CONST(0x0000000000000000), - ABC_CONST(0xFFFFFFFFFFFFFFFF) - }; - if ( Vec_WrdSize(vAnds) == 0 ) - return Truth[6]; - if ( Vec_WrdSize(vAnds) == 1 && Vec_WrdEntry(vAnds,0) == 0 ) - return Truth[7]; - vTruths = Vec_WrdAlloc( Vec_WrdSize(vAnds) ); - for ( i = 0; i < nVars; i++ ) - Vec_WrdPush( vTruths, Truth[i] ); - Vec_WrdForEachEntryStart( vAnds, Entry, i, nVars ) - { - This = If_WrdToAnd(Entry); - Truth0 = Vec_WrdEntry( vTruths, This.iFan0 ); - Truth0 = This.fCompl0 ? ~Truth0 : Truth0; - Truth1 = Vec_WrdEntry( vTruths, This.iFan1 ); - Truth1 = This.fCompl1 ? ~Truth1 : Truth1; - TruthR = Truth0 & Truth1; - Vec_WrdPush( vTruths, TruthR ); - } - Vec_WrdFree( vTruths ); - TruthR = This.fCompl ? ~TruthR : TruthR; - return TruthR; -} - -/**Function************************************************************* - - Synopsis [Inserts the entry while sorting them by delay.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void If_AndInsertSorted( Vec_Wrd_t * vAnds, If_And_t And ) -{ - If_And_t This, Prev; - int i; - Vec_WrdPush( vAnds, If_AndToWrd(And) ); - for ( i = Vec_WrdSize(vAnds) - 1; i > 0; i-- ) - { - This = If_WrdToAnd( Vec_WrdEntry(vAnds, i) ); - Prev = If_WrdToAnd( Vec_WrdEntry(vAnds, i-1) ); - if ( This.Delay <= Prev.Delay ) - break; - Vec_WrdWriteEntry( vAnds, i, If_AndToWrd(Prev) ); - Vec_WrdWriteEntry( vAnds, i-1, If_AndToWrd(This) ); - } -} - -/**Function************************************************************* - - Synopsis [Decomposes the cube into a bunch of AND gates.] - - Description [Records the result of decomposition into vLits. Returns - the last AND gate of the decomposition.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -If_And_t If_CutDelaySopCube( Vec_Wrd_t * vCube, Vec_Wrd_t * vAnds, int fOrGate ) -{ - If_And_t This, Prev, Next; - assert( Vec_WrdSize(vCube) > 0 ); - while ( Vec_WrdSize(vCube) > 1 ) - { - // get last - This = If_WrdToAnd( Vec_WrdPop(vCube) ); - Prev = If_WrdToAnd( Vec_WrdPop(vCube) ); - // create new - If_AndClear( &Next ); - Next.iFan0 = Prev.Id; - Next.fCompl0 = Prev.fCompl ^ fOrGate; - Next.iFan1 = This.Id; - Next.fCompl1 = This.fCompl ^ fOrGate; - Next.Id = Vec_WrdSize(vAnds); - Next.fCompl = fOrGate; - Next.Delay = 1 + Abc_MaxInt( This.Delay, Prev.Delay ); - // add new - If_AndInsertSorted( vCube, Next ); - Vec_WrdPush( vAnds, If_AndToWrd(Next) ); - } - return If_WrdToAnd( Vec_WrdPop(vCube) ); -} - - - -/**Function************************************************************* - - Synopsis [Returns the well-balanced structure of AIG nodes.] + Synopsis [Sorts the pins in the decreasing order of delays.] Description [] @@ -165,459 +41,42 @@ If_And_t If_CutDelaySopCube( Vec_Wrd_t * vCube, Vec_Wrd_t * vAnds, int fOrGate ) SeeAlso [] ***********************************************************************/ -Vec_Wrd_t * If_CutDelaySopAnds( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vCover, int fCompl ) +void If_CutSortInputPins( If_Man_t * p, If_Cut_t * pCut, int * pPinPerm, float * pPinDelays ) { If_Obj_t * pLeaf; - If_And_t Leaf; - int i, k, Entry, Literal; - Vec_WrdClear( p->vAnds ); - if ( Vec_IntSize(vCover) == 0 ) // const 0 - { - assert( fCompl == 0 ); - return p->vAnds; - } - if ( Vec_IntSize(vCover) == 1 && Vec_IntEntry(vCover, 0) == 0 ) // const 1 - { - assert( fCompl == 0 ); - Vec_WrdPush( p->vAnds, 0 ); - return p->vAnds; - } - If_CutForEachLeaf( p, pCut, pLeaf, k ) - { - If_AndClear( &Leaf ); - Leaf.Id = k; - Leaf.Delay = (int)If_ObjCutBest(pLeaf)->Delay; - Vec_WrdPush( p->vAnds, If_AndToWrd(Leaf) ); - } - // iterate through the cubes - Vec_WrdClear( p->vOrGate ); - Vec_WrdClear( p->vAndGate ); - Vec_IntForEachEntry( vCover, Entry, i ) - { - Vec_WrdClear( p->vAndGate ); - If_CutForEachLeaf( p, pCut, pLeaf, k ) - { - Literal = 3 & (Entry >> (k << 1)); - if ( Literal == 1 ) // neg literal - { - If_AndClear( &Leaf ); - Leaf.fCompl = 1; - Leaf.Id = k; - Leaf.Delay = (int)If_ObjCutBest(pLeaf)->Delay; - If_AndInsertSorted( p->vAndGate, Leaf ); - } - else if ( Literal == 2 ) // pos literal - { - If_AndClear( &Leaf ); - Leaf.Id = k; - Leaf.Delay = (int)If_ObjCutBest(pLeaf)->Delay; - If_AndInsertSorted( p->vAndGate, Leaf ); - } - else if ( Literal != 0 ) - assert( 0 ); - } - Leaf = If_CutDelaySopCube( p->vAndGate, p->vAnds, 0 ); - If_AndInsertSorted( p->vOrGate, Leaf ); - } - Leaf = If_CutDelaySopCube( p->vOrGate, p->vAnds, 1 ); - if ( Vec_WrdSize(p->vAnds) == (int)pCut->nLeaves ) - { -// Extra_PrintBinary( stdout, If_CutTruth(pCut), 32 ); printf( "\n" ); - assert( Leaf.Id < pCut->nLeaves ); - Leaf.iFan0 = Leaf.iFan1 = Leaf.Id; - Leaf.Id = Vec_WrdSize(p->vAnds); - Vec_WrdPush( p->vAnds, If_AndToWrd(Leaf) ); - } - if ( fCompl ) - { - Leaf = If_WrdToAnd( Vec_WrdPop(p->vAnds) ); - Leaf.fCompl ^= 1; - Vec_WrdPush( p->vAnds, If_AndToWrd(Leaf) ); - } - return p->vAnds; -} - -/**Function************************************************************* - - Synopsis [Computes balanced AND decomposition.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Wrd_t * If_CutDelaySopArray( If_Man_t * p, If_Cut_t * pCut ) -{ - abctime clk; - Vec_Wrd_t * vAnds; - int RetValue; - printf( "Running old code!!!\n" ); - if ( p->vCover == NULL ) - p->vCover = Vec_IntAlloc(0); - if ( p->vAnds == NULL ) - p->vAnds = Vec_WrdAlloc(100); - if ( p->vAndGate == NULL ) - p->vAndGate = Vec_WrdAlloc(100); - if ( p->vOrGate == NULL ) - p->vOrGate = Vec_WrdAlloc(100); - RetValue = Kit_TruthIsop( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), p->vCover, 1 ); - if ( RetValue == -1 ) - return NULL; - assert( RetValue == 0 || RetValue == 1 ); - clk = Abc_Clock(); - vAnds = If_CutDelaySopAnds( p, pCut, p->vCover, RetValue ); - s_timeOld += Abc_Clock() - clk; - return vAnds; -} - - -/**Function************************************************************* - - Synopsis [Derives the maximum depth from the leaf to the root.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int If_CutDelayLeafDepth_rec( Vec_Wrd_t * vAnds, If_And_t And, int iLeaf ) -{ - int Depth0, Depth1, Depth; - if ( (int)And.Id == iLeaf ) - return 0; - if ( And.iFan0 == And.iFan1 ) - return -IF_BIG_CHAR; - Depth0 = If_CutDelayLeafDepth_rec( vAnds, If_WrdToAnd(Vec_WrdEntry(vAnds, And.iFan0)), iLeaf ); - Depth1 = If_CutDelayLeafDepth_rec( vAnds, If_WrdToAnd(Vec_WrdEntry(vAnds, And.iFan1)), iLeaf ); - Depth = Abc_MaxInt( Depth0, Depth1 ); - Depth = (Depth == -IF_BIG_CHAR) ? -IF_BIG_CHAR : Depth + 1; - return Depth; -} - -/**Function************************************************************* - - Synopsis [Derives the maximum depth from the leaf to the root.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int If_CutDelayLeafDepth( Vec_Wrd_t * vAnds, int iLeaf ) -{ - If_And_t Leaf; - if ( Vec_WrdSize(vAnds) == 0 ) // const 0 - return -IF_BIG_CHAR; - if ( Vec_WrdSize(vAnds) == 1 && Vec_WrdEntry(vAnds, 0) == 0 ) // const 1 - return -IF_BIG_CHAR; - Leaf = If_WrdToAnd(Vec_WrdEntryLast(vAnds)); - if ( Leaf.iFan0 == Leaf.iFan1 ) - { - if ( (int)Leaf.iFan0 == iLeaf ) - return 0; - return -IF_BIG_CHAR; - } - return If_CutDelayLeafDepth_rec( vAnds, Leaf, iLeaf ); -} - - -/**Function************************************************************* - - Synopsis [Computes the SOP delay using balanced AND decomposition.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int If_CutDelaySopCost( If_Man_t * p, If_Cut_t * pCut ) -{ - If_And_t Leaf; - Vec_Wrd_t * vAnds; - int i, Delay; -// char pPerm[16]; -// int Delay2, TestArea; - // mark cut as a user cut - pCut->fUser = 1; - vAnds = If_CutDelaySopArray( p, pCut ); - if ( vAnds == NULL ) + int i, j, best_i, temp; + // start the trivial permutation and collect pin delays + If_CutForEachLeaf( p, pCut, pLeaf, i ) { - assert( 0 ); - return ABC_INFINITY; + pPinPerm[i] = i; + pPinDelays[i] = If_ObjCutBest(pLeaf)->Delay; } - // get the cost - If_AndClear( &Leaf ); - if ( Vec_WrdSize(vAnds) > 0 ) - Leaf = If_WrdToAnd( Vec_WrdEntryLast(vAnds) ); - else - Leaf.Delay = 0; - if ( pCut->nLeaves == 0 ) - pCut->Cost = 0; - else if ( pCut->nLeaves == 1 ) - pCut->Cost = 0; - else if ( Vec_WrdSize(vAnds) > (int)pCut->nLeaves ) - pCut->Cost = Vec_WrdSize(vAnds) - pCut->nLeaves; - else assert( 0 ); - // get the permutation - for ( i = 0; i < (int)pCut->nLeaves; i++ ) + // selection sort the pins in the decreasible order of delays + // this order will match the increasing order of LUT input pins + for ( i = 0; i < (int)pCut->nLeaves-1; i++ ) { - Delay = If_CutDelayLeafDepth( vAnds, i ); - pCut->pPerm[i] = (char)(Delay == -IF_BIG_CHAR ? IF_BIG_CHAR : Delay); -//printf( "%d ", pCut->pPerm[i] ); + best_i = i; + for ( j = i+1; j < (int)pCut->nLeaves; j++ ) + if ( pPinDelays[pPinPerm[j]] > pPinDelays[pPinPerm[best_i]] ) + best_i = j; + if ( best_i == i ) + continue; + temp = pPinPerm[i]; + pPinPerm[i] = pPinPerm[best_i]; + pPinPerm[best_i] = temp; } -//printf( " (%d)\n", Leaf.Delay ); - // verify the delay -// Delay = If_CutDelay( p, pObj, pCut ); -// assert( (int)Leaf.Delay == Delay ); /* - TestArea = pCut->Cost; - Delay = If_CutDelaySopArray3( p, pCut, NULL ); - if ( Delay != (int)Leaf.Delay || (int)pCut->Cost != TestArea ) - { - int s = 0; - Kit_DsdPrintFromTruth( If_CutTruth(p, pCut), pCut->nLeaves ); printf( "\n" ); - Delay = If_CutDelaySopArray3( p, pCut, NULL ); - } - Delay2 = If_CutPinDelaysSopArray3( p, pCut, pPerm ); - assert( Delay == Delay2 ); - for ( i = 0; i < (int)pCut->nLeaves; i++ ) + // verify + assert( pPinPerm[0] < (int)pCut->nLeaves ); + for ( i = 1; i < (int)pCut->nLeaves; i++ ) { - if ( pPerm[i] != pCut->pPerm[i] ) - { - int s = 0; - Kit_DsdPrintFromTruth( If_CutTruth(p, pCut), pCut->nLeaves ); printf( "\n" ); - Delay2 = If_CutPinDelaysSopArray3( p, pCut, pPerm ); - } - assert( pPerm[i] == pCut->pPerm[i] ); + assert( pPinPerm[i] < (int)pCut->nLeaves ); + assert( pPinDelays[pPinPerm[i-1]] >= pPinDelays[pPinPerm[i]] ); } - printf( "Corrrect\n" ); -// printf( "%d ", Delay ); */ - return Leaf.Delay; -} - - -/**Function************************************************************* - - Synopsis [Alternative computation of delay.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -word If_CutDelayCountFormula( Vec_Int_t * vNums ) -{ - word Count = 0; - int i, Entry; - Vec_IntForEachEntry( vNums, Entry, i ) - { - if ( Entry < 0 ) - continue; - assert( Entry < 60 ); - Count += ((word)1) << Entry; - } - return Count; -} -int If_CutDelayUseFormula( Vec_Int_t * vNums ) -{ - int i, k, fChanges = 1; -// word Count = If_CutDelayCountFormula( vNums ); -// Vec_IntPrint( vNums ); - while ( fChanges ) - { - fChanges = 0; - for ( i = Vec_IntSize(vNums) - 1; i > 0; i-- ) - if ( vNums->pArray[i] == vNums->pArray[i-1] ) - { - vNums->pArray[i-1]++; - for ( k = i; k < Vec_IntSize(vNums) - 1; k++ ) - vNums->pArray[k] = vNums->pArray[k+1]; - Vec_IntShrink( vNums, Vec_IntSize(vNums)-1 ); - fChanges = 1; - } - } -// assert( Count == If_CutDelayCountFormula(vNums) ); -// Vec_IntPrint( vNums ); -// printf( "\n" ); - if ( Vec_IntSize(vNums) == 1 ) - return vNums->pArray[0]; - return Vec_IntEntryLast(vNums) + 1; -} -int If_CutDelaySopAnds2( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vCover, int fCompl, int * pArea ) -{ - Vec_Int_t * vOrGate2 = (Vec_Int_t *)p->vOrGate; - Vec_Int_t * vAndGate2 = (Vec_Int_t *)p->vAndGate; - int Arrivals[16]; - If_Obj_t * pLeaf; - int i, k, Entry, Literal; - *pArea = 0; - if ( Vec_IntSize(vCover) == 0 ) // const 0 - { - assert( fCompl == 0 ); - return 0; - } - if ( Vec_IntSize(vCover) == 1 && Vec_IntEntry(vCover, 0) == 0 ) // const 1 - { - assert( fCompl == 0 ); - return 0; - } - If_CutForEachLeaf( p, pCut, pLeaf, k ) - Arrivals[k] = (int)If_ObjCutBest(pLeaf)->Delay; - // iterate through the cubes - Vec_IntClear( vOrGate2 ); - Vec_IntForEachEntry( vCover, Entry, i ) - { - Vec_IntClear( vAndGate2 ); - for ( k = 0; k < (int)pCut->nLeaves; k++ ) - { - Literal = 3 & (Entry >> (k << 1)); - if ( Literal == 1 ) // neg literal - Vec_IntPushOrder( vAndGate2, Arrivals[k] ); - else if ( Literal == 2 ) // pos literal - Vec_IntPushOrder( vAndGate2, Arrivals[k] ); - else if ( Literal != 0 ) - assert( 0 ); - } - *pArea += Vec_IntSize(vAndGate2) - 1; - Vec_IntPushOrder( vOrGate2, If_CutDelayUseFormula(vAndGate2) ); - } - *pArea += Vec_IntSize(vOrGate2) - 1; - return If_CutDelayUseFormula(vOrGate2); -} -int If_CutDelaySopArray2( If_Man_t * p, If_Cut_t * pCut, int * pArea ) -{ - abctime clk; - int RetValue; - if ( p->vCover == NULL ) - p->vCover = Vec_IntAlloc(0); - if ( p->vAndGate == NULL ) - p->vAndGate = Vec_WrdAlloc(100); - if ( p->vOrGate == NULL ) - p->vOrGate = Vec_WrdAlloc(100); - RetValue = Kit_TruthIsop( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), p->vCover, 1 ); - if ( RetValue == -1 ) - return -1; - assert( RetValue == 0 || RetValue == 1 ); - - clk = Abc_Clock(); - RetValue = If_CutDelaySopAnds2( p, pCut, p->vCover, RetValue ^ pCut->fCompl, pArea ); -// RetValue = If_CutDelaySopAnds2_( p, pCut, p->vCover, RetValue ^ pCut->fCompl, pArea ); - s_timeNew += Abc_Clock() - clk; - return RetValue; -} -int If_CutDelaySopCost2( If_Man_t * p, If_Cut_t * pCut ) -{ - If_Obj_t * pLeaf; - int i, DelayMax, Area; - // mark cut as a user cut - pCut->fUser = 1; - DelayMax = If_CutDelaySopArray2( p, pCut, &Area ); - if ( DelayMax == -1 ) - { - assert( 0 ); - return ABC_INFINITY; - } - // get the cost - if ( pCut->nLeaves > 2 ) - pCut->Cost = Area; - else - pCut->Cost = 1; - // get the permutation - If_CutForEachLeaf( p, pCut, pLeaf, i ) - { - assert( DelayMax == 0 || DelayMax >= (int)If_ObjCutBest(pLeaf)->Delay ); - pCut->pPerm[i] = (char)(DelayMax - (int)If_ObjCutBest(pLeaf)->Delay); -// printf( "%d ", pCut->pPerm[i] ); - } -// printf( "(%d) ", DelayMax ); - // verify the delay -// Delay = If_CutDelay( p, pObj, pCut ); -// assert( (int)Leaf.Delay == Delay ); - return DelayMax; } - -/**Function************************************************************* - - Synopsis [Computes the SOP delay using balanced AND decomposition.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int If_CutMaxCubeSize( Vec_Int_t * vCover, int nVars ) -{ - int i, k, Entry, Literal, Count, CountMax = 0; - Vec_IntForEachEntry( vCover, Entry, i ) - { - Count = 0; - for ( k = 0; k < nVars; k++ ) - { - Literal = (3 & (Entry >> (k << 1))); - if ( Literal == 1 || Literal == 2 ) - Count++; - } - CountMax = Abc_MaxInt( CountMax, Count ); - } - return CountMax; -} -int If_CutDelaySop( If_Man_t * p, If_Cut_t * pCut ) -{ - // delay is calculated using 1+log2(NumFanins) - static double GateDelays[20] = { 1.00, 1.00, 2.00, 2.58, 3.00, 3.32, 3.58, 3.81, 4.00, 4.17, 4.32, 4.46, 4.58, 4.70, 4.81, 4.91, 5.00, 5.09, 5.17, 5.25 }; - If_Obj_t * pLeaf; - int Delay, DelayMax; - int i, nLitMax, RetValue; - // mark cut as a user cut - pCut->fUser = 1; - if ( p->vCover == NULL ) - p->vCover = Vec_IntAlloc(0); - RetValue = Kit_TruthIsop( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), p->vCover, 1 ); - if ( RetValue == -1 ) - return ABC_INFINITY; - assert( RetValue == 0 || RetValue == 1 ); - // mark the output as complemented -// vAnds = If_CutDelaySopAnds( p, pCut, p->vCover, RetValue ^ pCut->fCompl ); - if ( Vec_IntSize(p->vCover) > p->pPars->nGateSize ) - return ABC_INFINITY; - // set the area cost - assert( If_CutLeaveNum(pCut) >= 0 && If_CutLeaveNum(pCut) <= 16 ); - // compute the gate delay - nLitMax = If_CutMaxCubeSize( p->vCover, If_CutLeaveNum(pCut) ); - if ( Vec_IntSize(p->vCover) < 2 ) - { - pCut->Cost = Vec_IntSize(p->vCover); - Delay = (int)(GateDelays[If_CutLeaveNum(pCut)] + 0.5); - DelayMax = 0; - If_CutForEachLeaf( p, pCut, pLeaf, i ) - DelayMax = Abc_MaxInt( DelayMax, If_ObjCutBest(pLeaf)->Delay + (pCut->pPerm[i] = (char)Delay) ); - } - else - { - pCut->Cost = Vec_IntSize(p->vCover) + 1; - Delay = (int)(GateDelays[If_CutLeaveNum(pCut)] + GateDelays[nLitMax] + 0.5); - DelayMax = 0; - If_CutForEachLeaf( p, pCut, pLeaf, i ) - DelayMax = Abc_MaxInt( DelayMax, If_ObjCutBest(pLeaf)->Delay + (pCut->pPerm[i] = (char)Delay) ); - } - return DelayMax; -} - /**Function************************************************************* Synopsis [Computes delay.] @@ -743,14 +202,13 @@ void If_CutPropagateRequired( If_Man_t * p, If_Obj_t * pObj, If_Cut_t * pCut, fl { if ( pCut->fUser ) { + char Perm[IF_MAX_FUNC_LUTSIZE]; + char * pPerm = p->pPars->fDelayOpt ? Perm : pCut->pPerm; if ( p->pPars->fDelayOpt ) - { - int Del = If_CutPinDelaysSopArray3( p, pCut, pCut->pPerm ); - assert( Del == pCut->Delay ); - } + If_CutSopBalancePinDelays( p, pCut, pPerm ); If_CutForEachLeaf( p, pCut, pLeaf, i ) { - Pin2PinDelay = pCut->pPerm ? (pCut->pPerm[i] == IF_BIG_CHAR ? -IF_BIG_CHAR : pCut->pPerm[i]) : 1; + Pin2PinDelay = pPerm ? (pPerm[i] == IF_BIG_CHAR ? -IF_BIG_CHAR : pPerm[i]) : 1; Required = ObjRequired - (float)Pin2PinDelay; pLeaf->Required = IF_MIN( pLeaf->Required, Required ); } @@ -764,78 +222,6 @@ void If_CutPropagateRequired( If_Man_t * p, If_Obj_t * pObj, If_Cut_t * pCut, fl } } -/**Function************************************************************* - - Synopsis [Sorts the pins in the decreasing order of delays.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void If_CutSortInputPins( If_Man_t * p, If_Cut_t * pCut, int * pPinPerm, float * pPinDelays ) -{ - If_Obj_t * pLeaf; - int i, j, best_i, temp; - // start the trivial permutation and collect pin delays - If_CutForEachLeaf( p, pCut, pLeaf, i ) - { - pPinPerm[i] = i; - pPinDelays[i] = If_ObjCutBest(pLeaf)->Delay; - } - // selection sort the pins in the decreasible order of delays - // this order will match the increasing order of LUT input pins - for ( i = 0; i < (int)pCut->nLeaves-1; i++ ) - { - best_i = i; - for ( j = i+1; j < (int)pCut->nLeaves; j++ ) - if ( pPinDelays[pPinPerm[j]] > pPinDelays[pPinPerm[best_i]] ) - best_i = j; - if ( best_i == i ) - continue; - temp = pPinPerm[i]; - pPinPerm[i] = pPinPerm[best_i]; - pPinPerm[best_i] = temp; - } -/* - // verify - assert( pPinPerm[0] < (int)pCut->nLeaves ); - for ( i = 1; i < (int)pCut->nLeaves; i++ ) - { - assert( pPinPerm[i] < (int)pCut->nLeaves ); - assert( pPinDelays[pPinPerm[i-1]] >= pPinDelays[pPinPerm[i]] ); - } -*/ -} - -/**Function************************************************************* - - Synopsis [Sorts the pins in the decreasing order of delays.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -/* -void If_CutRotatePins( If_Man_t * p, If_Cut_t * pCut ) -{ - If_Obj_t * pLeaf; - float PinDelays[32]; -// int PinPerm[32]; - int i; -// assert( p->pPars->pLutLib && p->pPars->pLutLib->fVarPinDelays && p->pPars->fTruth ); - If_CutForEachLeaf( p, pCut, pLeaf, i ) - PinDelays[i] = If_ObjCutBest(pLeaf)->Delay; - If_CutTruthPermute( p->puTemp[0], If_CutTruth(p, pCut), If_CutLeaveNum(pCut), PinDelays, If_CutLeaves(pCut) ); -// If_CutSortInputPins( p, pCut, PinPerm, PinDelays ); -} -*/ - //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/map/if/ifTruth.c b/src/map/if/ifTruth.c index ad641a47..657a739b 100644 --- a/src/map/if/ifTruth.c +++ b/src/map/if/ifTruth.c @@ -19,6 +19,7 @@ ***********************************************************************/ #include "if.h" +#include "bool/kit/kit.h" ABC_NAMESPACE_IMPL_START @@ -97,7 +98,7 @@ void If_CutRotatePins( If_Man_t * p, If_Cut_t * pCut ) int If_CutComputeTruth( If_Man_t * p, If_Cut_t * pCut, If_Cut_t * pCut0, If_Cut_t * pCut1, int fCompl0, int fCompl1 ) { int fCompl, truthId, nLeavesNew, RetValue = 0; - int nWords = Abc_TtWordNum( pCut->nLeaves ); + int PrevSize, nWords = Abc_TtWordNum( pCut->nLeaves ); word * pTruth0s = Vec_MemReadEntry( p->vTtMem[pCut0->nLeaves], Abc_Lit2Var(pCut0->iCutFunc) ); word * pTruth1s = Vec_MemReadEntry( p->vTtMem[pCut1->nLeaves], Abc_Lit2Var(pCut1->iCutFunc) ); word * pTruth0 = (word *)p->puTemp[0]; @@ -121,6 +122,7 @@ int If_CutComputeTruth( If_Man_t * p, If_Cut_t * pCut, If_Cut_t * pCut0, If_Cut_ RetValue = 1; } } + PrevSize = Vec_MemEntryNum( p->vTtMem[pCut->nLeaves] ); truthId = Vec_MemHashInsert( p->vTtMem[pCut->nLeaves], pTruth ); pCut->iCutFunc = Abc_Var2Lit( truthId, fCompl ); assert( (pTruth[0] & 1) == 0 ); @@ -132,6 +134,19 @@ int If_CutComputeTruth( If_Man_t * p, If_Cut_t * pCut, If_Cut_t * pCut0, If_Cut_ Abc_TtCanonicize( pCopy, pCut->nLeaves, pCanonPerm ); } #endif + if ( p->vTtIsops[pCut->nLeaves] && PrevSize != Vec_MemEntryNum(p->vTtMem[pCut->nLeaves]) ) + { + Vec_Int_t * vLevel = Vec_WecPushLevel( p->vTtIsops[pCut->nLeaves] ); + fCompl = Kit_TruthIsop( (unsigned *)pTruth, pCut->nLeaves, p->vCover, 1 ); + if ( fCompl >= 0 ) + { + Vec_IntGrow( vLevel, Vec_IntSize(p->vCover) ); + Vec_IntAppend( vLevel, p->vCover ); + if ( fCompl ) + vLevel->nCap ^= (1<<16); // hack to remember complemented attribute + } + assert( Vec_WecSize(p->vTtIsops[pCut->nLeaves]) == Vec_MemEntryNum(p->vTtMem[pCut->nLeaves]) ); + } return RetValue; } |