diff options
Diffstat (limited to 'src/map/mpm/mpmTruth.c')
-rw-r--r-- | src/map/mpm/mpmTruth.c | 152 |
1 files changed, 127 insertions, 25 deletions
diff --git a/src/map/mpm/mpmTruth.c b/src/map/mpm/mpmTruth.c index 481c6c94..0d917f7e 100644 --- a/src/map/mpm/mpmTruth.c +++ b/src/map/mpm/mpmTruth.c @@ -19,7 +19,6 @@ ***********************************************************************/ #include "mpmInt.h" -#include "misc/util/utilTruth.h" ABC_NAMESPACE_IMPL_START @@ -28,13 +27,40 @@ ABC_NAMESPACE_IMPL_START /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// +//#define MPM_TRY_NEW + //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* - Synopsis [Performs truth table computation.] + Synopsis [Unifies variable order.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline void Mpm_TruthStretch( word * pTruth, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, int nLimit ) +{ + int i, k; + for ( i = (int)pCut->nLeaves - 1, k = (int)pCut0->nLeaves - 1; i >= 0 && k >= 0; i-- ) + { + if ( pCut0->pLeaves[k] < pCut->pLeaves[i] ) + continue; + assert( pCut0->pLeaves[k] == pCut->pLeaves[i] ); + if ( k < i ) + Abc_TtSwapVars( pTruth, nLimit, k, i ); + k--; + } +} + +/**Function************************************************************* + + Synopsis [Performs truth table support minimization.] Description [] @@ -80,22 +106,57 @@ static inline int Mpm_CutTruthMinimize6( Mpm_Man_t * p, Mpm_Cut_t * pCut ) pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert(p->vTtMem, &t), Abc_LitIsCompl(pCut->iFunc) ); return 1; } -static inline word Mpm_TruthStretch6( word Truth, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, int nLimit ) +static inline int Mpm_CutTruthMinimize7( Mpm_Man_t * p, Mpm_Cut_t * pCut ) { - int i, k; - for ( i = (int)pCut->nLeaves - 1, k = (int)pCut0->nLeaves - 1; i >= 0 && k >= 0; i-- ) + unsigned uSupport; + int i, k, nSuppSize; + // compute the support of the cut's function + word * pTruth = Mpm_CutTruth( p, Abc_Lit2Var(pCut->iFunc) ); + uSupport = Abc_TtSupportAndSize( pTruth, Mpm_CutLeafNum(pCut), &nSuppSize ); + if ( nSuppSize == Mpm_CutLeafNum(pCut) ) + return 0; + p->nSmallSupp += (int)(nSuppSize < 2); + // update leaves and signature + Abc_TtCopy( p->Truth, pTruth, p->nTruWords, 0 ); + for ( i = k = 0; i < Mpm_CutLeafNum(pCut); i++ ) { - if ( pCut0->pLeaves[k] < pCut->pLeaves[i] ) - continue; - assert( pCut0->pLeaves[k] == pCut->pLeaves[i] ); - if ( k < i ) - Abc_TtSwapVars( &Truth, nLimit, k, i ); - k--; + if ( ((uSupport >> i) & 1) ) + { + if ( k < i ) + { + pCut->pLeaves[k] = pCut->pLeaves[i]; + Abc_TtSwapVars( p->Truth, p->nLutSize, k, i ); + } + k++; + } + else + { + int iObj = Abc_Lit2Var( pCut->pLeaves[i] ); + int Res = Vec_IntRemove( &p->vObjPresUsed, iObj ); + assert( Res == 1 ); + p->pObjPres[iObj] = (unsigned char)0xFF; + } } - return Truth; + assert( k == nSuppSize ); + pCut->nLeaves = nSuppSize; + assert( nSuppSize == Abc_TtSupportSize(p->Truth, 6) ); + // save the result + pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert(p->vTtMem, p->Truth), Abc_LitIsCompl(pCut->iFunc) ); + return 1; } -//#define MPM_TRY_NEW -int Mpm_CutComputeTruth6( Mpm_Man_t * p, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, Mpm_Cut_t * pCut1, Mpm_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, int Type ) + +/**Function************************************************************* + + Synopsis [Performs truth table computation.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline int Mpm_CutComputeTruth6( Mpm_Man_t * p, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, Mpm_Cut_t * pCut1, Mpm_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, int Type ) { word * pTruth0 = Mpm_CutTruth( p, Abc_Lit2Var(pCut0->iFunc) ); word * pTruth1 = Mpm_CutTruth( p, Abc_Lit2Var(pCut1->iFunc) ); @@ -103,13 +164,13 @@ int Mpm_CutComputeTruth6( Mpm_Man_t * p, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, Mp word t0 = (fCompl0 ^ pCut0->fCompl ^ Abc_LitIsCompl(pCut0->iFunc)) ? ~*pTruth0 : *pTruth0; word t1 = (fCompl1 ^ pCut1->fCompl ^ Abc_LitIsCompl(pCut1->iFunc)) ? ~*pTruth1 : *pTruth1; word tC = 0, t = 0; - t0 = Mpm_TruthStretch6( t0, pCut, pCut0, p->nLutSize ); - t1 = Mpm_TruthStretch6( t1, pCut, pCut1, p->nLutSize ); + Mpm_TruthStretch( &t0, pCut, pCut0, p->nLutSize ); + Mpm_TruthStretch( &t1, pCut, pCut1, p->nLutSize ); if ( pCutC ) { pTruthC = Mpm_CutTruth( p, Abc_Lit2Var(pCutC->iFunc) ); tC = (fComplC ^ pCutC->fCompl ^ Abc_LitIsCompl(pCutC->iFunc)) ? ~*pTruthC : *pTruthC; - tC = Mpm_TruthStretch6( tC, pCut, pCutC, p->nLutSize ); + Mpm_TruthStretch( &tC, pCut, pCutC, p->nLutSize ); } assert( p->nLutSize <= 6 ); if ( Type == 1 ) @@ -127,19 +188,60 @@ int Mpm_CutComputeTruth6( Mpm_Man_t * p, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, Mp } else pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert( p->vTtMem, &t ), 0 ); - + if ( p->pPars->fCutMin ) + return Mpm_CutTruthMinimize6( p, pCut ); + return 1; +} +static inline int Mpm_CutComputeTruth7( Mpm_Man_t * p, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, Mpm_Cut_t * pCut1, Mpm_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, int Type ) +{ + word * pTruth0 = Mpm_CutTruth( p, Abc_Lit2Var(pCut0->iFunc) ); + word * pTruth1 = Mpm_CutTruth( p, Abc_Lit2Var(pCut1->iFunc) ); + word * pTruthC = NULL; + Abc_TtCopy( p->Truth0, pTruth0, p->nTruWords, fCompl0 ^ pCut0->fCompl ^ Abc_LitIsCompl(pCut0->iFunc) ); + Abc_TtCopy( p->Truth1, pTruth1, p->nTruWords, fCompl1 ^ pCut1->fCompl ^ Abc_LitIsCompl(pCut1->iFunc) ); + Mpm_TruthStretch( p->Truth0, pCut, pCut0, p->nLutSize ); + Mpm_TruthStretch( p->Truth1, pCut, pCut1, p->nLutSize ); + if ( pCutC ) + { + pTruthC = Mpm_CutTruth( p, Abc_Lit2Var(pCutC->iFunc) ); + Abc_TtCopy( p->TruthC, pTruthC, p->nTruWords, fComplC ^ pCutC->fCompl ^ Abc_LitIsCompl(pCutC->iFunc) ); + Mpm_TruthStretch( p->TruthC, pCut, pCutC, p->nLutSize ); + } + if ( Type == 1 ) + Abc_TtAnd( p->Truth, p->Truth0, p->Truth1, p->nTruWords, 0 ); + else if ( Type == 2 ) + Abc_TtXor( p->Truth, p->Truth0, p->Truth1, p->nTruWords, 0 ); + else if ( Type == 3 ) + Abc_TtMux( p->Truth, p->TruthC, p->Truth1, p->Truth0, p->nTruWords ); + else assert( 0 ); + // save the result + if ( p->Truth[0] & 1 ) + { + Abc_TtNot( p->Truth, p->nTruWords ); + pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert( p->vTtMem, p->Truth ), 1 ); + } + else + pCut->iFunc = Abc_Var2Lit( Vec_MemHashInsert( p->vTtMem, p->Truth ), 0 ); + if ( p->pPars->fCutMin ) + return Mpm_CutTruthMinimize7( p, pCut ); + return 1; +} +int Mpm_CutComputeTruth( Mpm_Man_t * p, Mpm_Cut_t * pCut, Mpm_Cut_t * pCut0, Mpm_Cut_t * pCut1, Mpm_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, int Type ) +{ + int RetValue; + if ( p->nLutSize <= 6 ) + RetValue = Mpm_CutComputeTruth6( p, pCut, pCut0, pCut1, pCutC, fCompl0, fCompl1, fComplC, Type ); + else + RetValue = Mpm_CutComputeTruth7( p, pCut, pCut0, pCut1, pCutC, fCompl0, fCompl1, fComplC, Type ); #ifdef MPM_TRY_NEW { - extern unsigned Abc_TtCanonicize( word * pTruth, int nVars, char * pCanonPerm ); - word tCopy = t; + extern unsigned Abc_TtCanonicize( word * pTruth, int nVars, char * pCanonPerm ); char pCanonPerm[16]; - Abc_TtCanonicize( &tCopy, p->nLutSize, pCanonPerm ); + memcpy( p->Truth0, p->Truth, sizeof(word) * p->nTruWords ); + Abc_TtCanonicize( p->Truth0, pCut->nLimit, pCanonPerm ); } #endif - - if ( p->pPars->fCutMin ) - return Mpm_CutTruthMinimize6( p, pCut ); - return 0; + return RetValue; } //////////////////////////////////////////////////////////////////////// |