summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYen-Sheng Ho <ysho@berkeley.edu>2017-04-06 14:18:50 -0700
committerYen-Sheng Ho <ysho@berkeley.edu>2017-04-06 14:18:50 -0700
commit72c23923da38d9e06b4a57816704fe1c0d37a2c4 (patch)
tree241b6111a7c72d18db73c58c7028da5c8b94802e /src
parent2761e5e35bdcb8591ccc445b907af95bd0b16357 (diff)
parentefe5d1476af9e99c7a246d6d4de91abbc4274359 (diff)
downloadabc-72c23923da38d9e06b4a57816704fe1c0d37a2c4.tar.gz
abc-72c23923da38d9e06b4a57816704fe1c0d37a2c4.tar.bz2
abc-72c23923da38d9e06b4a57816704fe1c0d37a2c4.zip
merge
Diffstat (limited to 'src')
-rw-r--r--src/aig/gia/giaCut.c646
-rw-r--r--src/aig/gia/module.make1
-rw-r--r--src/base/abci/abc.c42
-rw-r--r--src/base/acb/acb.h9
-rw-r--r--src/base/acb/acbAbc.c55
-rw-r--r--src/base/acb/acbMfs.c1272
-rw-r--r--src/base/acb/acbPar.h4
-rw-r--r--src/base/acb/acbUtil.c184
-rw-r--r--src/misc/vec/vecHsh.h6
-rw-r--r--src/opt/sfm/sfmCore.c4
-rw-r--r--src/sat/bsat/satSolver.c11
-rw-r--r--src/sat/bsat/satSolver.h4
-rw-r--r--src/sat/bsat/satUtil.c4
-rw-r--r--src/sat/cnf/cnf.h2
-rw-r--r--src/sat/cnf/cnfMan.c8
15 files changed, 1858 insertions, 394 deletions
diff --git a/src/aig/gia/giaCut.c b/src/aig/gia/giaCut.c
new file mode 100644
index 00000000..f70f0fc0
--- /dev/null
+++ b/src/aig/gia/giaCut.c
@@ -0,0 +1,646 @@
+/**CFile****************************************************************
+
+ FileName [giaCut.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [Scalable AIG package.]
+
+ Synopsis [Stand-alone cut computation.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: giaCut.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "gia.h"
+#include "misc/util/utilTruth.h"
+
+ABC_NAMESPACE_IMPL_START
+
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+#define GIA_MAX_CUTSIZE 8
+#define GIA_MAX_CUTNUM 51
+#define GIA_MAX_TT_WORDS ((GIA_MAX_CUTSIZE > 6) ? 1 << (GIA_MAX_CUTSIZE-6) : 1)
+
+#define GIA_CUT_NO_LEAF 0xF
+
+typedef struct Gia_Cut_t_ Gia_Cut_t;
+struct Gia_Cut_t_
+{
+ word Sign; // signature
+ int iFunc; // functionality
+ int Cost; // cut cost
+ int CostLev; // cut cost
+ unsigned nTreeLeaves : 28; // tree leaves
+ unsigned nLeaves : 4; // leaf count
+ int pLeaves[GIA_MAX_CUTSIZE]; // leaves
+};
+
+typedef struct Gia_Sto_t_ Gia_Sto_t;
+struct Gia_Sto_t_
+{
+ int nCutSize;
+ int nCutNum;
+ int fCutMin;
+ int fTruthMin;
+ int fVerbose;
+ Gia_Man_t * pGia; // user's AIG manager (will be modified by adding nodes)
+ Vec_Int_t * vRefs; // refs for each node
+ Vec_Wec_t * vCuts; // cuts for each node
+ Vec_Mem_t * vTtMem; // truth tables
+ Gia_Cut_t pCuts[3][GIA_MAX_CUTNUM]; // temporary cuts
+ Gia_Cut_t * ppCuts[GIA_MAX_CUTNUM]; // temporary cut pointers
+ int nCutsR; // the number of cuts
+ int Pivot; // current object
+ int iCutBest; // best-delay cut
+ int nCutsOver; // overflow cuts
+ double CutCount[4]; // cut counters
+ abctime clkStart; // starting time
+};
+
+static inline word * Gia_CutTruth( Gia_Sto_t * p, Gia_Cut_t * pCut ) { return Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut->iFunc)); }
+
+#define Sdb_ForEachCut( pList, pCut, i ) for ( i = 0, pCut = pList + 1; i < pList[0]; i++, pCut += pCut[0] + 2 )
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Check correctness of cuts.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline word Gia_CutGetSign( Gia_Cut_t * pCut )
+{
+ word Sign = 0; int i;
+ for ( i = 0; i < (int)pCut->nLeaves; i++ )
+ Sign |= ((word)1) << (pCut->pLeaves[i] & 0x3F);
+ return Sign;
+}
+static inline int Gia_CutCheck( Gia_Cut_t * pBase, Gia_Cut_t * pCut ) // check if pCut is contained in pBase
+{
+ int nSizeB = pBase->nLeaves;
+ int nSizeC = pCut->nLeaves;
+ int i, * pB = pBase->pLeaves;
+ int k, * pC = pCut->pLeaves;
+ for ( i = 0; i < nSizeC; i++ )
+ {
+ for ( k = 0; k < nSizeB; k++ )
+ if ( pC[i] == pB[k] )
+ break;
+ if ( k == nSizeB )
+ return 0;
+ }
+ return 1;
+}
+static inline int Gia_CutSetCheckArray( Gia_Cut_t ** ppCuts, int nCuts )
+{
+ Gia_Cut_t * pCut0, * pCut1;
+ int i, k, m, n, Value;
+ assert( nCuts > 0 );
+ for ( i = 0; i < nCuts; i++ )
+ {
+ pCut0 = ppCuts[i];
+ assert( pCut0->nLeaves <= GIA_MAX_CUTSIZE );
+ assert( pCut0->Sign == Gia_CutGetSign(pCut0) );
+ // check duplicates
+ for ( m = 0; m < (int)pCut0->nLeaves; m++ )
+ for ( n = m + 1; n < (int)pCut0->nLeaves; n++ )
+ assert( pCut0->pLeaves[m] < pCut0->pLeaves[n] );
+ // check pairs
+ for ( k = 0; k < nCuts; k++ )
+ {
+ pCut1 = ppCuts[k];
+ if ( pCut0 == pCut1 )
+ continue;
+ // check containments
+ Value = Gia_CutCheck( pCut0, pCut1 );
+ assert( Value == 0 );
+ }
+ }
+ return 1;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Gia_CutMergeOrder( Gia_Cut_t * pCut0, Gia_Cut_t * pCut1, Gia_Cut_t * pCut, int nCutSize )
+{
+ int nSize0 = pCut0->nLeaves;
+ int nSize1 = pCut1->nLeaves;
+ int i, * pC0 = pCut0->pLeaves;
+ int k, * pC1 = pCut1->pLeaves;
+ int c, * pC = pCut->pLeaves;
+ // the case of the largest cut sizes
+ if ( nSize0 == nCutSize && nSize1 == nCutSize )
+ {
+ for ( i = 0; i < nSize0; i++ )
+ {
+ if ( pC0[i] != pC1[i] ) return 0;
+ pC[i] = pC0[i];
+ }
+ pCut->nLeaves = nCutSize;
+ pCut->iFunc = -1;
+ pCut->Sign = pCut0->Sign | pCut1->Sign;
+ return 1;
+ }
+ // compare two cuts with different numbers
+ i = k = c = 0;
+ if ( nSize0 == 0 ) goto FlushCut1;
+ if ( nSize1 == 0 ) goto FlushCut0;
+ while ( 1 )
+ {
+ if ( c == nCutSize ) return 0;
+ if ( pC0[i] < pC1[k] )
+ {
+ pC[c++] = pC0[i++];
+ if ( i >= nSize0 ) goto FlushCut1;
+ }
+ else if ( pC0[i] > pC1[k] )
+ {
+ pC[c++] = pC1[k++];
+ if ( k >= nSize1 ) goto FlushCut0;
+ }
+ else
+ {
+ pC[c++] = pC0[i++]; k++;
+ if ( i >= nSize0 ) goto FlushCut1;
+ if ( k >= nSize1 ) goto FlushCut0;
+ }
+ }
+
+FlushCut0:
+ if ( c + nSize0 > nCutSize + i ) return 0;
+ while ( i < nSize0 )
+ pC[c++] = pC0[i++];
+ pCut->nLeaves = c;
+ pCut->iFunc = -1;
+ pCut->Sign = pCut0->Sign | pCut1->Sign;
+ return 1;
+
+FlushCut1:
+ if ( c + nSize1 > nCutSize + k ) return 0;
+ while ( k < nSize1 )
+ pC[c++] = pC1[k++];
+ pCut->nLeaves = c;
+ pCut->iFunc = -1;
+ pCut->Sign = pCut0->Sign | pCut1->Sign;
+ return 1;
+}
+static inline int Gia_CutMergeOrder2( Gia_Cut_t * pCut0, Gia_Cut_t * pCut1, Gia_Cut_t * pCut, int nCutSize )
+{
+ int x0, i0 = 0, nSize0 = pCut0->nLeaves, * pC0 = pCut0->pLeaves;
+ int x1, i1 = 0, nSize1 = pCut1->nLeaves, * pC1 = pCut1->pLeaves;
+ int xMin, c = 0, * pC = pCut->pLeaves;
+ while ( 1 )
+ {
+ x0 = (i0 == nSize0) ? ABC_INFINITY : pC0[i0];
+ x1 = (i1 == nSize1) ? ABC_INFINITY : pC1[i1];
+ xMin = Abc_MinInt(x0, x1);
+ if ( xMin == ABC_INFINITY ) break;
+ if ( c == nCutSize ) return 0;
+ pC[c++] = xMin;
+ if (x0 == xMin) i0++;
+ if (x1 == xMin) i1++;
+ }
+ pCut->nLeaves = c;
+ pCut->iFunc = -1;
+ pCut->Sign = pCut0->Sign | pCut1->Sign;
+ return 1;
+}
+static inline int Gia_CutSetCutIsContainedOrder( Gia_Cut_t * pBase, Gia_Cut_t * pCut ) // check if pCut is contained in pBase
+{
+ int i, nSizeB = pBase->nLeaves;
+ int k, nSizeC = pCut->nLeaves;
+ if ( nSizeB == nSizeC )
+ {
+ for ( i = 0; i < nSizeB; i++ )
+ if ( pBase->pLeaves[i] != pCut->pLeaves[i] )
+ return 0;
+ return 1;
+ }
+ assert( nSizeB > nSizeC );
+ if ( nSizeC == 0 )
+ return 1;
+ for ( i = k = 0; i < nSizeB; i++ )
+ {
+ if ( pBase->pLeaves[i] > pCut->pLeaves[k] )
+ return 0;
+ if ( pBase->pLeaves[i] == pCut->pLeaves[k] )
+ {
+ if ( ++k == nSizeC )
+ return 1;
+ }
+ }
+ return 0;
+}
+static inline int Gia_CutSetLastCutIsContained( Gia_Cut_t ** pCuts, int nCuts )
+{
+ int i;
+ for ( i = 0; i < nCuts; i++ )
+ if ( pCuts[i]->nLeaves <= pCuts[nCuts]->nLeaves && (pCuts[i]->Sign & pCuts[nCuts]->Sign) == pCuts[i]->Sign && Gia_CutSetCutIsContainedOrder(pCuts[nCuts], pCuts[i]) )
+ return 1;
+ return 0;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Gia_CutCompare( Gia_Cut_t * pCut0, Gia_Cut_t * pCut1 )
+{
+ if ( pCut0->nTreeLeaves < pCut1->nTreeLeaves ) return -1;
+ if ( pCut0->nTreeLeaves > pCut1->nTreeLeaves ) return 1;
+ if ( pCut0->nLeaves < pCut1->nLeaves ) return -1;
+ if ( pCut0->nLeaves > pCut1->nLeaves ) return 1;
+ return 0;
+}
+static inline int Gia_CutSetLastCutContains( Gia_Cut_t ** pCuts, int nCuts )
+{
+ int i, k, fChanges = 0;
+ for ( i = 0; i < nCuts; i++ )
+ if ( pCuts[nCuts]->nLeaves < pCuts[i]->nLeaves && (pCuts[nCuts]->Sign & pCuts[i]->Sign) == pCuts[nCuts]->Sign && Gia_CutSetCutIsContainedOrder(pCuts[i], pCuts[nCuts]) )
+ pCuts[i]->nLeaves = GIA_CUT_NO_LEAF, fChanges = 1;
+ if ( !fChanges )
+ return nCuts;
+ for ( i = k = 0; i <= nCuts; i++ )
+ {
+ if ( pCuts[i]->nLeaves == GIA_CUT_NO_LEAF )
+ continue;
+ if ( k < i )
+ ABC_SWAP( Gia_Cut_t *, pCuts[k], pCuts[i] );
+ k++;
+ }
+ return k - 1;
+}
+static inline void Gia_CutSetSortByCost( Gia_Cut_t ** pCuts, int nCuts )
+{
+ int i;
+ for ( i = nCuts; i > 0; i-- )
+ {
+ if ( Gia_CutCompare(pCuts[i - 1], pCuts[i]) < 0 )//!= 1 )
+ return;
+ ABC_SWAP( Gia_Cut_t *, pCuts[i - 1], pCuts[i] );
+ }
+}
+static inline int Gia_CutSetAddCut( Gia_Cut_t ** pCuts, int nCuts, int nCutNum )
+{
+ if ( nCuts == 0 )
+ return 1;
+ nCuts = Gia_CutSetLastCutContains(pCuts, nCuts);
+ assert( nCuts >= 0 );
+ Gia_CutSetSortByCost( pCuts, nCuts );
+ // add new cut if there is room
+ return Abc_MinInt( nCuts + 1, nCutNum - 1 );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Gia_CutComputeTruth6( Gia_Sto_t * p, Gia_Cut_t * pCut0, Gia_Cut_t * pCut1, int fCompl0, int fCompl1, Gia_Cut_t * pCutR, int fIsXor )
+{
+ int nOldSupp = pCutR->nLeaves, truthId, fCompl; word t;
+ word t0 = *Gia_CutTruth(p, pCut0);
+ word t1 = *Gia_CutTruth(p, pCut1);
+ if ( Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 ) t0 = ~t0;
+ if ( Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 ) t1 = ~t1;
+ t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
+ t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
+ t = fIsXor ? t0 ^ t1 : t0 & t1;
+ if ( (fCompl = (int)(t & 1)) ) t = ~t;
+ if ( p->fTruthMin )
+ pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
+ assert( (int)(t & 1) == 0 );
+ truthId = Vec_MemHashInsert(p->vTtMem, &t);
+ pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
+ assert( (int)pCutR->nLeaves <= nOldSupp );
+ return (int)pCutR->nLeaves < nOldSupp;
+}
+static inline int Gia_CutComputeTruth( Gia_Sto_t * p, Gia_Cut_t * pCut0, Gia_Cut_t * pCut1, int fCompl0, int fCompl1, Gia_Cut_t * pCutR, int fIsXor )
+{
+ if ( p->nCutSize <= 6 )
+ return Gia_CutComputeTruth6( p, pCut0, pCut1, fCompl0, fCompl1, pCutR, fIsXor );
+ {
+ word uTruth[GIA_MAX_TT_WORDS], uTruth0[GIA_MAX_TT_WORDS], uTruth1[GIA_MAX_TT_WORDS];
+ int nOldSupp = pCutR->nLeaves, truthId;
+ int nCutSize = p->nCutSize, fCompl;
+ int nWords = Abc_Truth6WordNum(nCutSize);
+ word * pTruth0 = Gia_CutTruth(p, pCut0);
+ word * pTruth1 = Gia_CutTruth(p, pCut1);
+ Abc_TtCopy( uTruth0, pTruth0, nWords, Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 );
+ Abc_TtCopy( uTruth1, pTruth1, nWords, Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 );
+ Abc_TtExpand( uTruth0, nCutSize, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
+ Abc_TtExpand( uTruth1, nCutSize, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
+ if ( fIsXor )
+ Abc_TtXor( uTruth, uTruth0, uTruth1, nWords, (fCompl = (int)((uTruth0[0] ^ uTruth1[0]) & 1)) );
+ else
+ Abc_TtAnd( uTruth, uTruth0, uTruth1, nWords, (fCompl = (int)((uTruth0[0] & uTruth1[0]) & 1)) );
+ if ( p->fTruthMin )
+ pCutR->nLeaves = Abc_TtMinBase( uTruth, pCutR->pLeaves, pCutR->nLeaves, nCutSize );
+ assert( (uTruth[0] & 1) == 0 );
+//Kit_DsdPrintFromTruth( uTruth, pCutR->nLeaves ), printf("\n" ), printf("\n" );
+ truthId = Vec_MemHashInsert(p->vTtMem, uTruth);
+ pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
+ assert( (int)pCutR->nLeaves <= nOldSupp );
+ return (int)pCutR->nLeaves < nOldSupp;
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Gia_CutCountBits( word i )
+{
+ i = i - ((i >> 1) & 0x5555555555555555);
+ i = (i & 0x3333333333333333) + ((i >> 2) & 0x3333333333333333);
+ i = ((i + (i >> 4)) & 0x0F0F0F0F0F0F0F0F);
+ return (i*(0x0101010101010101))>>56;
+}
+static inline void Gia_CutAddUnit( Gia_Sto_t * p, int iObj )
+{
+ Vec_Int_t * vThis = Vec_WecEntry( p->vCuts, iObj );
+ if ( Vec_IntSize(vThis) == 0 )
+ Vec_IntPush( vThis, 1 );
+ else
+ Vec_IntAddToEntry( vThis, 0, 1 );
+ Vec_IntPush( vThis, 1 );
+ Vec_IntPush( vThis, iObj );
+ Vec_IntPush( vThis, 2 );
+}
+static inline void Gia_CutAddZero( Gia_Sto_t * p, int iObj )
+{
+ Vec_Int_t * vThis = Vec_WecEntry( p->vCuts, iObj );
+ assert( Vec_IntSize(vThis) == 0 );
+ Vec_IntPush( vThis, 1 );
+ Vec_IntPush( vThis, 0 );
+ Vec_IntPush( vThis, 0 );
+}
+static inline int Gia_CutTreeLeaves( Gia_Sto_t * p, Gia_Cut_t * pCut )
+{
+ int i, Cost = 0;
+ for ( i = 0; i < (int)pCut->nLeaves; i++ )
+ Cost += Vec_IntEntry( p->vRefs, pCut->pLeaves[i] ) == 1;
+ return Cost;
+}
+static inline int Gia_StoPrepareSet( Gia_Sto_t * p, int iObj, int Index )
+{
+ Vec_Int_t * vThis = Vec_WecEntry( p->vCuts, iObj );
+ int i, v, * pCut, * pList = Vec_IntArray( vThis );
+ Sdb_ForEachCut( pList, pCut, i )
+ {
+ Gia_Cut_t * pCutTemp = &p->pCuts[Index][i];
+ pCutTemp->nLeaves = pCut[0];
+ for ( v = 1; v <= pCut[0]; v++ )
+ pCutTemp->pLeaves[v-1] = pCut[v];
+ pCutTemp->iFunc = pCut[pCut[0]+1];
+ pCutTemp->Sign = Gia_CutGetSign( pCutTemp );
+ pCutTemp->nTreeLeaves = Gia_CutTreeLeaves( p, pCutTemp );
+ }
+ return pList[0];
+}
+static inline void Gia_StoInitResult( Gia_Sto_t * p )
+{
+ int i;
+ for ( i = 0; i < GIA_MAX_CUTNUM; i++ )
+ p->ppCuts[i] = &p->pCuts[2][i];
+}
+static inline void Gia_StoStoreResult( Gia_Sto_t * p, int iObj, Gia_Cut_t ** pCuts, int nCuts )
+{
+ int i, v;
+ Vec_Int_t * vList = Vec_WecEntry( p->vCuts, iObj );
+ Vec_IntPush( vList, nCuts );
+ for ( i = 0; i < nCuts; i++ )
+ {
+ Vec_IntPush( vList, pCuts[i]->nLeaves );
+ for ( v = 0; v < (int)pCuts[i]->nLeaves; v++ )
+ Vec_IntPush( vList, pCuts[i]->pLeaves[v] );
+ Vec_IntPush( vList, pCuts[i]->iFunc );
+ }
+}
+static inline void Gia_CutPrint( Gia_Sto_t * p, int iObj, Gia_Cut_t * pCut )
+{
+ int i, nDigits = Abc_Base10Log(Gia_ManObjNum(p->pGia));
+ if ( pCut == NULL ) { printf( "No cut.\n" ); return; }
+ printf( "%d {", pCut->nLeaves );
+ for ( i = 0; i < (int)pCut->nLeaves; i++ )
+ printf( " %*d", nDigits, pCut->pLeaves[i] );
+ for ( ; i < (int)p->nCutSize; i++ )
+ printf( " %*s", nDigits, " " );
+ printf( " } Cost = %3d CostL = %3d Tree = %d ",
+ pCut->Cost, pCut->CostLev, pCut->nTreeLeaves );
+ printf( "\n" );
+}
+void Gia_StoMergeCuts( Gia_Sto_t * p, int iObj )
+{
+ Gia_Obj_t * pObj = Gia_ManObj(p->pGia, iObj);
+ int fIsXor = Gia_ObjIsXor(pObj);
+ int nCutSize = p->nCutSize;
+ int nCutNum = p->nCutNum;
+ int fComp0 = Gia_ObjFaninC0(pObj);
+ int fComp1 = Gia_ObjFaninC1(pObj);
+ int Fan0 = Gia_ObjFaninId0(pObj, iObj);
+ int Fan1 = Gia_ObjFaninId1(pObj, iObj);
+ int nCuts0 = Gia_StoPrepareSet( p, Fan0, 0 );
+ int nCuts1 = Gia_StoPrepareSet( p, Fan1, 1 );
+ int i, k, nCutsR = 0;
+ Gia_Cut_t * pCut0, * pCut1, ** pCutsR = p->ppCuts;
+ assert( !Gia_ObjIsBuf(pObj) );
+ assert( !Gia_ObjIsMux(p->pGia, pObj) );
+ Gia_StoInitResult( p );
+ p->CutCount[0] += nCuts0 * nCuts1;
+ for ( i = 0, pCut0 = p->pCuts[0]; i < nCuts0; i++, pCut0++ )
+ for ( k = 0, pCut1 = p->pCuts[1]; k < nCuts1; k++, pCut1++ )
+ {
+ if ( (int)(pCut0->nLeaves + pCut1->nLeaves) > nCutSize && Gia_CutCountBits(pCut0->Sign | pCut1->Sign) > nCutSize )
+ continue;
+ p->CutCount[1]++;
+ if ( !Gia_CutMergeOrder(pCut0, pCut1, pCutsR[nCutsR], nCutSize) )
+ continue;
+ if ( Gia_CutSetLastCutIsContained(pCutsR, nCutsR) )
+ continue;
+ p->CutCount[2]++;
+ if ( p->fCutMin && Gia_CutComputeTruth(p, pCut0, pCut1, fComp0, fComp1, pCutsR[nCutsR], fIsXor) )
+ pCutsR[nCutsR]->Sign = Gia_CutGetSign(pCutsR[nCutsR]);
+ pCutsR[nCutsR]->nTreeLeaves = Gia_CutTreeLeaves( p, pCutsR[nCutsR] );
+ nCutsR = Gia_CutSetAddCut( pCutsR, nCutsR, nCutNum );
+ }
+ p->CutCount[3] += nCutsR;
+ p->nCutsOver += nCutsR == nCutNum-1;
+ p->nCutsR = nCutsR;
+ p->Pivot = iObj;
+ // debug printout
+ if ( 0 )
+ {
+ printf( "*** Obj = %4d NumCuts = %4d\n", iObj, nCutsR );
+ for ( i = 0; i < nCutsR; i++ )
+ Gia_CutPrint( p, iObj, pCutsR[i] );
+ printf( "\n" );
+ }
+ // verify
+ assert( nCutsR > 0 && nCutsR < nCutNum );
+ assert( Gia_CutSetCheckArray(pCutsR, nCutsR) );
+ // store the cutset
+ Gia_StoStoreResult( p, iObj, pCutsR, nCutsR );
+ if ( nCutsR > 1 || pCutsR[0]->nLeaves > 1 )
+ Gia_CutAddUnit( p, iObj );
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Incremental cut computation.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Gia_Sto_t * Gia_StoAlloc( Gia_Man_t * pGia, int nCutSize, int nCutNum, int fCutMin, int fTruthMin, int fVerbose )
+{
+ Gia_Sto_t * p;
+ assert( nCutSize < GIA_CUT_NO_LEAF );
+ assert( nCutSize > 1 && nCutSize <= GIA_MAX_CUTSIZE );
+ assert( nCutNum > 1 && nCutNum < GIA_MAX_CUTNUM );
+ p = ABC_CALLOC( Gia_Sto_t, 1 );
+ p->clkStart = Abc_Clock();
+ p->nCutSize = nCutSize;
+ p->nCutNum = nCutNum;
+ p->fCutMin = fCutMin;
+ p->fTruthMin = fTruthMin;
+ p->fVerbose = fVerbose;
+ p->pGia = pGia;
+ p->vRefs = Vec_IntAlloc( Gia_ManObjNum(pGia) );
+ p->vCuts = Vec_WecStart( Gia_ManObjNum(pGia) );
+ p->vTtMem = fCutMin ? Vec_MemAllocForTT( nCutSize, 0 ) : NULL;
+ return p;
+}
+void Gia_StoFree( Gia_Sto_t * p )
+{
+ Vec_IntFree( p->vRefs );
+ Vec_WecFree( p->vCuts );
+ if ( p->fCutMin )
+ Vec_MemHashFree( p->vTtMem );
+ if ( p->fCutMin )
+ Vec_MemFree( p->vTtMem );
+ ABC_FREE( p );
+}
+void Gia_StoComputeCutsConst0( Gia_Sto_t * p, int iObj )
+{
+ Gia_CutAddZero( p, iObj );
+}
+void Gia_StoComputeCutsCi( Gia_Sto_t * p, int iObj )
+{
+ Gia_CutAddUnit( p, iObj );
+}
+void Gia_StoComputeCutsNode( Gia_Sto_t * p, int iObj )
+{
+ Gia_StoMergeCuts( p, iObj );
+}
+void Gia_StoRefObj( Gia_Sto_t * p, int iObj )
+{
+ Gia_Obj_t * pObj = Gia_ManObj(p->pGia, iObj);
+ assert( iObj == Vec_IntSize(p->vRefs) );
+ Vec_IntPush( p->vRefs, 0 );
+ if ( Gia_ObjIsAnd(pObj) )
+ {
+ Vec_IntAddToEntry( p->vRefs, Gia_ObjFaninId0(pObj, iObj), 1 );
+ Vec_IntAddToEntry( p->vRefs, Gia_ObjFaninId1(pObj, iObj), 1 );
+ }
+ else if ( Gia_ObjIsCo(pObj) )
+ Vec_IntAddToEntry( p->vRefs, Gia_ObjFaninId0(pObj, iObj), 1 );
+}
+void Gia_StoComputeCuts( Gia_Man_t * pGia )
+{
+ int nCutSize = 6;
+ int nCutNum = 25;
+ int fCutMin = 1;
+ int fTruthMin = 1;
+ int fVerbose = 1;
+ Gia_Sto_t * p = Gia_StoAlloc( pGia, nCutSize, nCutNum, fCutMin, fTruthMin, fVerbose );
+ Gia_Obj_t * pObj; int i, iObj;
+ assert( nCutSize <= GIA_MAX_CUTSIZE );
+ assert( nCutNum < GIA_MAX_CUTNUM );
+ // prepare references
+ Gia_ManForEachObj( p->pGia, pObj, iObj )
+ Gia_StoRefObj( p, iObj );
+ // compute cuts
+ Gia_StoComputeCutsConst0( p, 0 );
+ Gia_ManForEachCiId( p->pGia, iObj, i )
+ Gia_StoComputeCutsCi( p, iObj );
+ Gia_ManForEachAnd( p->pGia, pObj, iObj )
+ Gia_StoComputeCutsNode( p, iObj );
+ if ( p->fVerbose )
+ {
+ printf( "Running cut computation with CutSize = %d CutNum = %d CutMin = %s TruthMin = %s\n",
+ p->nCutSize, p->nCutNum, p->fCutMin ? "yes":"no", p->fTruthMin ? "yes":"no" );
+ printf( "CutPair = %.0f ", p->CutCount[0] );
+ printf( "Merge = %.0f (%.2f %%) ", p->CutCount[1], 100.0*p->CutCount[1]/p->CutCount[0] );
+ printf( "Eval = %.0f (%.2f %%) ", p->CutCount[2], 100.0*p->CutCount[2]/p->CutCount[0] );
+ printf( "Cut = %.0f (%.2f %%) ", p->CutCount[3], 100.0*p->CutCount[3]/p->CutCount[0] );
+ printf( "Cut/Node = %.2f ", p->CutCount[3] / Gia_ManAndNum(p->pGia) );
+ printf( "\n" );
+ printf( "The number of nodes with cut count over the limit (%d cuts) = %d nodes (out of %d). ",
+ p->nCutNum, p->nCutsOver, Gia_ManAndNum(pGia) );
+ Abc_PrintTime( 0, "Time", Abc_Clock() - p->clkStart );
+ }
+ Gia_StoFree( p );
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
+ABC_NAMESPACE_IMPL_END
+
diff --git a/src/aig/gia/module.make b/src/aig/gia/module.make
index 0ee41e8b..1f4c4c07 100644
--- a/src/aig/gia/module.make
+++ b/src/aig/gia/module.make
@@ -14,6 +14,7 @@ SRC += src/aig/gia/giaAig.c \
src/aig/gia/giaCSatOld.c \
src/aig/gia/giaCSat.c \
src/aig/gia/giaCTas.c \
+ src/aig/gia/giaCut.c \
src/aig/gia/giaDfs.c \
src/aig/gia/giaDup.c \
src/aig/gia/giaEdge.c \
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c
index 01bffece..b7c9e0cd 100644
--- a/src/base/abci/abc.c
+++ b/src/base/abci/abc.c
@@ -5676,41 +5676,41 @@ int Abc_CommandMfse( Abc_Frame_t * pAbc, int argc, char ** argv )
Acb_Par_t Pars, * pPars = &Pars; int c;
Acb_ParSetDefault( pPars );
Extra_UtilGetoptReset();
- while ( ( c = Extra_UtilGetopt( argc, argv, "MDOFLCavwh" ) ) != EOF )
+ while ( ( c = Extra_UtilGetopt( argc, argv, "IOWFLCadvwh" ) ) != EOF )
{
switch ( c )
{
- case 'M':
+ case 'I':
if ( globalUtilOptind >= argc )
{
- Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
+ Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
goto usage;
}
- pPars->nTabooMax = atoi(argv[globalUtilOptind]);
+ pPars->nTfiLevMax = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
- if ( pPars->nTabooMax < 0 )
+ if ( pPars->nTfiLevMax < 0 )
goto usage;
break;
- case 'D':
+ case 'O':
if ( globalUtilOptind >= argc )
{
- Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
+ Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
goto usage;
}
- pPars->nDivMax = atoi(argv[globalUtilOptind]);
+ pPars->nTfoLevMax = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
- if ( pPars->nDivMax < 0 )
+ if ( pPars->nTfoLevMax < 0 )
goto usage;
break;
- case 'O':
+ case 'W':
if ( globalUtilOptind >= argc )
{
- Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
+ Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
goto usage;
}
- pPars->nTfoLevMax = atoi(argv[globalUtilOptind]);
+ pPars->nWinNodeMax = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
- if ( pPars->nTfoLevMax < 0 )
+ if ( pPars->nWinNodeMax < 0 )
goto usage;
break;
case 'F':
@@ -5749,6 +5749,9 @@ int Abc_CommandMfse( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'a':
pPars->fArea ^= 1;
break;
+ case 'd':
+ pPars->fUseAshen ^= 1;
+ break;
case 'v':
pPars->fVerbose ^= 1;
break;
@@ -5777,6 +5780,7 @@ int Abc_CommandMfse( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "Command is only applicable to LUT size no more than 6.\n" );
return 1;
}
+ Abc_NtkToSop( pNtk, -1, ABC_INFINITY );
pNtkNew = Abc_NtkOptMfse( pNtk, pPars );
if ( pNtkNew == NULL )
{
@@ -5787,15 +5791,16 @@ int Abc_CommandMfse( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;
usage:
- Abc_Print( -2, "usage: mfse [-MDOFLC <num>] [-avwh]\n" );
+ Abc_Print( -2, "usage: mfse [-IOWFLC <num>] [-advwh]\n" );
Abc_Print( -2, "\t performs don't-care-based optimization of logic networks\n" );
- Abc_Print( -2, "\t-M <num> : the max number of fanin nodes to skip (num >= 1) [default = %d]\n", pPars->nTabooMax );
- Abc_Print( -2, "\t-D <num> : the max number of divisors [default = %d]\n", pPars->nDivMax );
+ Abc_Print( -2, "\t-I <num> : the number of levels in the TFI cone (2 <= num) [default = %d]\n", pPars->nTfiLevMax );
Abc_Print( -2, "\t-O <num> : the number of levels in the TFO cone (0 <= num) [default = %d]\n", pPars->nTfoLevMax );
+ Abc_Print( -2, "\t-W <num> : the max number of nodes in the window (1 <= num) [default = %d]\n", pPars->nWinNodeMax );
Abc_Print( -2, "\t-F <num> : the max number of fanouts to skip (1 <= num) [default = %d]\n", pPars->nFanoutMax );
Abc_Print( -2, "\t-L <num> : the max increase in node level after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel );
Abc_Print( -2, "\t-C <num> : the max number of conflicts in one SAT run (0 = no limit) [default = %d]\n", pPars->nBTLimit );
Abc_Print( -2, "\t-a : toggle minimizing area [default = %s]\n", pPars->fArea? "area": "delay" );
+ Abc_Print( -2, "\t-d : toggle using Ashenhurst decomposition [default = %s]\n", pPars->fUseAshen? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing optimization summary [default = %s]\n", pPars->fVerbose? "yes": "no" );
Abc_Print( -2, "\t-w : toggle printing detailed stats for each node [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
@@ -12379,6 +12384,7 @@ int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
// extern void Cba_PrsReadBlifTest();
// Cba_PrsReadBlifTest();
}
+// Abc_NtkComputePaths( Abc_FrameReadNtk(pAbc) );
return 0;
usage:
Abc_Print( -2, "usage: test [-CKDNM] [-aovwh] <file_name>\n" );
@@ -43485,7 +43491,7 @@ int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv )
// extern void Gia_ManCheckFalseTest( Gia_Man_t * p, int nSlackMax );
// extern void Gia_ParTest( Gia_Man_t * p, int nWords, int nProcs );
// extern void Gia_ManTisTest( Gia_Man_t * pInit );
- extern void Gia_Iso3Test( Gia_Man_t * p );
+ extern void Gia_StoComputeCuts( Gia_Man_t * p );
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "WPFsvh" ) ) != EOF )
@@ -43589,7 +43595,7 @@ int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv )
// Jf_ManTestCnf( pAbc->pGia );
// Gia_ManCheckFalseTest( pAbc->pGia, nFrames );
// Gia_ParTest( pAbc->pGia, nWords, nProcs );
-//Cec2_ManSimulateTest( pAbc->pGia );
+ Gia_StoComputeCuts( pAbc->pGia );
// printf( "\nThis command is currently disabled.\n\n" );
return 0;
usage:
diff --git a/src/base/acb/acb.h b/src/base/acb/acb.h
index 6954010b..17962dc8 100644
--- a/src/base/acb/acb.h
+++ b/src/base/acb/acb.h
@@ -91,6 +91,7 @@ struct Acb_Ntk_t_
Vec_Flt_t vCounts; // priority counts
Vec_Wec_t vFanouts; // fanouts
Vec_Wec_t vCnfs; // CNF
+ Vec_Str_t vCnf; // CNF
// other
Vec_Que_t * vQue; // temporary
Vec_Int_t vCover; // temporary
@@ -503,7 +504,10 @@ static inline void Acb_ObjRemoveFaninFanout( Acb_Ntk_t * p, int iObj )
{
int k, iFanin, * pFanins;
Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
- Vec_IntRemove( Vec_WecEntry(&p->vFanouts, iFanin), iObj );
+ {
+ int RetValue = Vec_IntRemove( Vec_WecEntry(&p->vFanouts, iFanin), iObj );
+ assert( RetValue );
+ }
}
static inline void Acb_NtkCreateFanout( Acb_Ntk_t * p )
{
@@ -569,6 +573,7 @@ static inline void Acb_NtkFree( Acb_Ntk_t * p )
Vec_FltErase( &p->vCounts );
Vec_WecErase( &p->vFanouts );
Vec_WecErase( &p->vCnfs );
+ Vec_StrErase( &p->vCnf );
// other
Vec_QueFreeP( &p->vQue );
Vec_IntErase( &p->vCover );
@@ -967,7 +972,7 @@ extern int Acb_NtkComputeLevelD( Acb_Ntk_t * p, Vec_Int_t * vTfo );
extern void Acb_NtkUpdateLevelD( Acb_Ntk_t * p, int iObj );
extern void Acb_NtkUpdateTiming( Acb_Ntk_t * p, int iObj );
-extern void Acb_NtkCreateNode( Acb_Ntk_t * p, word uTruth, Vec_Int_t * vSupp );
+extern int Acb_NtkCreateNode( Acb_Ntk_t * p, word uTruth, Vec_Int_t * vSupp );
extern void Acb_NtkUpdateNode( Acb_Ntk_t * p, int Pivot, word uTruth, Vec_Int_t * vSupp );
ABC_NAMESPACE_HEADER_END
diff --git a/src/base/acb/acbAbc.c b/src/base/acb/acbAbc.c
index 9be3bdab..2b07a202 100644
--- a/src/base/acb/acbAbc.c
+++ b/src/base/acb/acbAbc.c
@@ -44,27 +44,18 @@ ABC_NAMESPACE_IMPL_START
SeeAlso []
***********************************************************************/
-Acb_Ntk_t * Acb_NtkFromAbc( Abc_Ntk_t * p )
+Acb_Ntk_t * Acb_NtkFromAbc2( Abc_Ntk_t * p )
{
- int fTrack = 1;
Acb_Man_t * pMan = Acb_ManAlloc( Abc_NtkSpec(p), 1, NULL, NULL, NULL, NULL );
int i, k, NameId = Abc_NamStrFindOrAdd( pMan->pStrs, Abc_NtkName(p), NULL );
Acb_Ntk_t * pNtk = Acb_NtkAlloc( pMan, NameId, Abc_NtkCiNum(p), Abc_NtkCoNum(p), Abc_NtkObjNum(p) );
Abc_Obj_t * pObj, * pFanin;
assert( Abc_NtkIsSopLogic(p) );
pNtk->nFaninMax = 6;
- if ( fTrack ) Vec_IntFill( &pNtk->vArray2, Abc_NtkObjNumMax(p), -1 );
Abc_NtkForEachCi( p, pObj, i )
- {
pObj->iTemp = Acb_ObjAlloc( pNtk, ABC_OPER_CI, 0, 0 );
- if ( fTrack ) Vec_IntWriteEntry( &pNtk->vArray2, pObj->iTemp, Abc_ObjId(pObj) );
- }
Abc_NtkForEachNode( p, pObj, i )
- {
pObj->iTemp = Acb_ObjAlloc( pNtk, ABC_OPER_LUT, Abc_ObjFaninNum(pObj), 0 );
- if ( fTrack ) Vec_IntWriteEntry( &pNtk->vArray2, pObj->iTemp, Abc_ObjId(pObj) );
-// printf( "%d -> %d\n%s", i, pObj->iTemp, (char *)pObj->pData );
- }
Abc_NtkForEachCo( p, pObj, i )
pObj->iTemp = Acb_ObjAlloc( pNtk, ABC_OPER_CO, 1, 0 );
Abc_NtkForEachNode( p, pObj, i )
@@ -79,6 +70,40 @@ Acb_Ntk_t * Acb_NtkFromAbc( Abc_Ntk_t * p )
Acb_NtkAdd( pMan, pNtk );
return pNtk;
}
+Acb_Ntk_t * Acb_NtkFromAbc( Abc_Ntk_t * p )
+{
+ Acb_Man_t * pMan = Acb_ManAlloc( Abc_NtkSpec(p), 1, NULL, NULL, NULL, NULL );
+ int i, k, NameId = Abc_NamStrFindOrAdd( pMan->pStrs, Abc_NtkName(p), NULL );
+ Acb_Ntk_t * pNtk = Acb_NtkAlloc( pMan, NameId, Abc_NtkCiNum(p), Abc_NtkCoNum(p), Abc_NtkObjNumMax(p)-1 );
+ Abc_Obj_t * pObj, * pFanin;
+ assert( Abc_NtkIsSopLogic(p) );
+ pNtk->nFaninMax = 6;
+ for ( i = 1; i < Abc_NtkObjNumMax(p); i++ )
+ {
+ pObj = Abc_NtkObj( p, i );
+ if ( pObj == NULL )
+ Acb_ObjAlloc( pNtk, ABC_OPER_NONE, 0, 0 );
+ else if ( Abc_ObjIsCi(pObj) )
+ pObj->iTemp = Acb_ObjAlloc( pNtk, ABC_OPER_CI, 0, 0 );
+ else if ( Abc_ObjIsCo(pObj) )
+ pObj->iTemp = Acb_ObjAlloc( pNtk, ABC_OPER_CO, 1, 0 );
+ else if ( Abc_ObjIsNode(pObj) )
+ pObj->iTemp = Acb_ObjAlloc( pNtk, ABC_OPER_LUT, Abc_ObjFaninNum(pObj), 0 );
+ else assert( 0 );
+ assert( pObj == NULL || pObj->iTemp == (int)Abc_ObjId(pObj) );
+ }
+ Abc_NtkForEachNode( p, pObj, i )
+ Abc_ObjForEachFanin( pObj, pFanin, k )
+ Acb_ObjAddFanin( pNtk, pObj->iTemp, pFanin->iTemp );
+ Abc_NtkForEachCo( p, pObj, i )
+ Acb_ObjAddFanin( pNtk, pObj->iTemp, Abc_ObjFanin(pObj, 0)->iTemp );
+ Acb_NtkCleanObjTruths( pNtk );
+ Abc_NtkForEachNode( p, pObj, i )
+ Acb_ObjSetTruth( pNtk, pObj->iTemp, Abc_SopToTruth((char *)pObj->pData, Abc_ObjFaninNum(pObj)) );
+ Acb_NtkSetRegNum( pNtk, Abc_NtkLatchNum(p) );
+ Acb_NtkAdd( pMan, pNtk );
+ return pNtk;
+}
/**Function*************************************************************
@@ -209,16 +234,16 @@ void Acb_ParSetDefault( Acb_Par_t * pPars )
{
memset( pPars, 0, sizeof(Acb_Par_t) );
pPars->nLutSize = 4; // LUT size
- pPars->nTfoLevMax = 1; // the maximum fanout levels
- pPars->nTfiLevMax = 2; // the maximum fanin levels
- pPars->nFanoutMax = 10; // the maximum number of fanouts
- pPars->nDivMax = 16; // the maximum divisor count
- pPars->nTabooMax = 4; // the minimum MFFC size
+ pPars->nTfoLevMax = 2; // the maximum fanout levels
+ pPars->nTfiLevMax = 3; // the maximum fanin levels
+ pPars->nFanoutMax = 20; // the maximum number of fanouts
+ pPars->nWinNodeMax = 100; // the maximum number of nodes in the window
pPars->nGrowthLevel = 0; // the maximum allowed growth in level
pPars->nBTLimit = 0; // the maximum number of conflicts in one SAT run
pPars->nNodesMax = 0; // the maximum number of nodes to try
pPars->iNodeOne = 0; // one particular node to try
pPars->fArea = 1; // performs optimization for area
+ pPars->fUseAshen = 0; // use Ashenhurst decomposition
pPars->fMoreEffort = 0; // enables using more effort
pPars->fVerbose = 0; // enable basic stats
pPars->fVeryVerbose = 0; // enable detailed stats
diff --git a/src/base/acb/acbMfs.c b/src/base/acb/acbMfs.c
index a536a08b..a17a179a 100644
--- a/src/base/acb/acbMfs.c
+++ b/src/base/acb/acbMfs.c
@@ -31,6 +31,10 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
+static inline int Acb_ObjIsDelayCriticalFanin( Acb_Ntk_t * p, int i, int f ) { return !Acb_ObjIsCi(p, f) && Acb_ObjLevelR(p, i) + Acb_ObjLevelD(p, f) == p->LevelMax; }
+static inline int Acb_ObjIsAreaCritical( Acb_Ntk_t * p, int f ) { return !Acb_ObjIsCi(p, f) && Acb_ObjFanoutNum(p, f) == 1; }
+static inline int Acb_ObjIsCritical( Acb_Ntk_t * p, int i, int f, int fDel ) { return fDel ? Acb_ObjIsDelayCriticalFanin(p, i, f) : Acb_ObjIsAreaCritical(p, f); }
+
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
@@ -85,10 +89,22 @@ int Acb_DeriveCnfFromTruth( word Truth, int nVars, Vec_Int_t * vCover, Vec_Str_t
return nCubes;
}
}
+
+void Acb_DeriveCnfForWindowOne( Acb_Ntk_t * p, int iObj )
+{
+ Vec_Wec_t * vCnfs = &p->vCnfs;
+ Vec_Str_t * vCnfBase = Acb_ObjCnfs( p, iObj );
+ assert( Vec_StrSize(vCnfBase) == 0 ); // unassigned
+ assert( Vec_WecSize(vCnfs) == Acb_NtkObjNumMax(p) );
+ Acb_DeriveCnfFromTruth( Acb_ObjTruth(p, iObj), Acb_ObjFaninNum(p, iObj), &p->vCover, &p->vCnf );
+ Vec_StrGrow( vCnfBase, Vec_StrSize(&p->vCnf) );
+ memcpy( Vec_StrArray(vCnfBase), Vec_StrArray(&p->vCnf), Vec_StrSize(&p->vCnf) );
+ vCnfBase->nSize = Vec_StrSize(&p->vCnf);
+}
Vec_Wec_t * Acb_DeriveCnfForWindow( Acb_Ntk_t * p, Vec_Int_t * vWin, int PivotVar )
{
Vec_Wec_t * vCnfs = &p->vCnfs;
- Vec_Str_t * vCnfBase, * vCnf = NULL; int i, iObj;
+ Vec_Str_t * vCnfBase; int i, iObj;
assert( Vec_WecSize(vCnfs) == Acb_NtkObjNumMax(p) );
Vec_IntForEachEntry( vWin, iObj, i )
{
@@ -98,14 +114,8 @@ Vec_Wec_t * Acb_DeriveCnfForWindow( Acb_Ntk_t * p, Vec_Int_t * vWin, int PivotVa
vCnfBase = Acb_ObjCnfs( p, iObj );
if ( Vec_StrSize(vCnfBase) > 0 )
continue;
- if ( vCnf == NULL )
- vCnf = Vec_StrAlloc( 1000 );
- Acb_DeriveCnfFromTruth( Acb_ObjTruth(p, iObj), Acb_ObjFaninNum(p, iObj), &p->vCover, vCnf );
- Vec_StrGrow( vCnfBase, Vec_StrSize(vCnf) );
- memcpy( Vec_StrArray(vCnfBase), Vec_StrArray(vCnf), Vec_StrSize(vCnf) );
- vCnfBase->nSize = Vec_StrSize(vCnf);
- }
- Vec_StrFreeP( &vCnf );
+ Acb_DeriveCnfForWindowOne( p, iObj );
+ }
return vCnfs;
}
@@ -149,6 +159,34 @@ int Acb_NtkCountRoots( Vec_Int_t * vWinObjs, int PivotVar )
nRoots += Abc_LitIsCompl(iObjLit);
return nRoots;
}
+void Acb_DeriveCnfForNode( Acb_Ntk_t * p, int iObj, sat_solver * pSat, int OutVar )
+{
+ Vec_Wec_t * vCnfs = &p->vCnfs;
+ Vec_Int_t * vFaninVars = &p->vCover;
+ Vec_Int_t * vClas = Vec_IntAlloc( 100 );
+ Vec_Int_t * vLits = Vec_IntAlloc( 100 );
+ int k, iFanin, * pFanins, Prev, This;
+ // collect SAT variables
+ Vec_IntClear( vFaninVars );
+ Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
+ {
+ assert( Acb_ObjFunc(p, iFanin) >= 0 );
+ Vec_IntPush( vFaninVars, Acb_ObjFunc(p, iFanin) );
+ }
+ Vec_IntPush( vFaninVars, OutVar );
+ // derive CNF for the node
+ Acb_TranslateCnf( vClas, vLits, (Vec_Str_t *)Vec_WecEntry(vCnfs, iObj), vFaninVars, -1 );
+ // add clauses
+ Prev = 0;
+ Vec_IntForEachEntry( vClas, This, k )
+ {
+ if ( !sat_solver_addclause( pSat, Vec_IntArray(vLits) + Prev, Vec_IntArray(vLits) + This ) )
+ printf( "Error: SAT solver became UNSAT at a wrong place (while adding new CNF).\n" );
+ Prev = This;
+ }
+ Vec_IntFree( vClas );
+ Vec_IntFree( vLits );
+}
Cnf_Dat_t * Acb_NtkWindow2Cnf( Acb_Ntk_t * p, Vec_Int_t * vWinObjs, int Pivot )
{
Cnf_Dat_t * pCnf;
@@ -164,10 +202,7 @@ Cnf_Dat_t * Acb_NtkWindow2Cnf( Acb_Ntk_t * p, Vec_Int_t * vWinObjs, int Pivot )
Vec_Int_t * vLits = Vec_IntAlloc( 1000 );
// mark new SAT variables
Vec_IntForEachEntry( vWinObjs, iObj, i )
- {
Acb_ObjSetFunc( p, Abc_Lit2Var(iObj), i );
-//printf( "Node %d -> SAT var %d\n", Vec_IntEntry(&p->vArray2, Abc_Lit2Var(iObj)), i );
- }
// add clauses for all nodes
Vec_IntPush( vClas, Vec_IntSize(vLits) );
Vec_IntForEachEntry( vWinObjs, iObjLit, i )
@@ -224,9 +259,6 @@ Cnf_Dat_t * Acb_NtkWindow2Cnf( Acb_Ntk_t * p, Vec_Int_t * vWinObjs, int Pivot )
assert( nVars == nVarsAll );
}
Vec_IntFree( vFaninVars );
- // undo SAT variables
- Vec_IntForEachEntry( vWinObjs, iObj, i )
- Vec_IntWriteEntry( &p->vObjFunc, Abc_Lit2Var(iObj), -1 );
// create CNF structure
pCnf = ABC_CALLOC( Cnf_Dat_t, 1 );
pCnf->nVars = nVarsAll;
@@ -242,7 +274,15 @@ Cnf_Dat_t * Acb_NtkWindow2Cnf( Acb_Ntk_t * p, Vec_Int_t * vWinObjs, int Pivot )
//Cnf_DataPrint( pCnf, 1 );
return pCnf;
}
-
+void Acb_NtkWindowUndo( Acb_Ntk_t * p, Vec_Int_t * vWin )
+{
+ int i, iObj;
+ Vec_IntForEachEntry( vWin, iObj, i )
+ {
+ assert( Vec_IntEntry(&p->vObjFunc, Abc_Lit2Var(iObj)) != -1 );
+ Vec_IntWriteEntry( &p->vObjFunc, Abc_Lit2Var(iObj), -1 );
+ }
+}
/**Function*************************************************************
@@ -255,34 +295,29 @@ Cnf_Dat_t * Acb_NtkWindow2Cnf( Acb_Ntk_t * p, Vec_Int_t * vWinObjs, int Pivot )
SeeAlso []
***********************************************************************/
-sat_solver * Acb_NtkWindow2Solver( Cnf_Dat_t * pCnf, int PivotVar, int nDivs, int nTimes )
+int Acb_NtkWindow2Solver( sat_solver * pSat, Cnf_Dat_t * pCnf, Vec_Int_t * vFlip, int PivotVar, int nDivs, int nTimes )
{
- int n, i, RetValue, nRounds = nTimes <= 2 ? nTimes-1 : 2;
- Vec_Int_t * vFlips = Cnf_DataCollectFlipLits( pCnf, PivotVar );
- sat_solver * pSat = sat_solver_new();
- sat_solver_setnvars( pSat, nTimes * pCnf->nVars + nRounds * nDivs + 1 );
+ int n, i, RetValue, Test = pCnf->pClauses[0][0];
+ int nGroups = nTimes <= 2 ? nTimes-1 : 2;
+ int nRounds = nTimes <= 2 ? nTimes-1 : nTimes;
+ assert( sat_solver_nvars(pSat) == 0 );
+ sat_solver_setnvars( pSat, nTimes * pCnf->nVars + nGroups * nDivs + 2 );
assert( nTimes == 1 || nTimes == 2 || nTimes == 6 );
for ( n = 0; n < nTimes; n++ )
{
if ( n & 1 )
- Cnf_DataLiftAndFlipLits( pCnf, -pCnf->nVars, vFlips );
+ Cnf_DataLiftAndFlipLits( pCnf, -pCnf->nVars, vFlip );
for ( i = 0; i < pCnf->nClauses; i++ )
- {
if ( !sat_solver_addclause( pSat, pCnf->pClauses[i], pCnf->pClauses[i+1] ) )
- {
- Vec_IntFree( vFlips );
- sat_solver_delete( pSat );
- return NULL;
- }
- }
+ printf( "Error: SAT solver became UNSAT at a wrong place.\n" );
if ( n & 1 )
- Cnf_DataLiftAndFlipLits( pCnf, pCnf->nVars, vFlips );
+ Cnf_DataLiftAndFlipLits( pCnf, pCnf->nVars, vFlip );
if ( n < nTimes - 1 )
Cnf_DataLift( pCnf, pCnf->nVars );
else if ( n ) // if ( n == nTimes - 1 )
Cnf_DataLift( pCnf, -(nTimes - 1) * pCnf->nVars );
}
- Vec_IntFree( vFlips );
+ assert( Test == pCnf->pClauses[0][0] );
// add conditional buffers
for ( n = 0; n < nRounds; n++ )
{
@@ -294,17 +329,91 @@ sat_solver * Acb_NtkWindow2Solver( Cnf_Dat_t * pCnf, int PivotVar, int nDivs, in
}
// finalize
RetValue = sat_solver_simplify( pSat );
- if ( RetValue == 0 )
+ if ( !RetValue ) printf( "Error: SAT solver became UNSAT at a wrong place.\n" );
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Computes function of the node]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+word Acb_ComputeFunction( sat_solver * pSat, int PivotVar, int FreeVar, Vec_Int_t * vDivVars, int fCompl )
+{
+ int fExpand = 0;
+ word uCube, uTruth = 0;
+ Vec_Int_t * vTempLits = Vec_IntAlloc( 100 );
+ int status, i, iVar, iLit, nFinal, * pFinal, pLits[2];
+ assert( FreeVar < sat_solver_nvars(pSat) );
+// if ( fCompl )
+// pLits[0] = Abc_Var2Lit( sat_solver_nvars(pSat)-2, 0 ); // F = 1
+// else
+ pLits[0] = Abc_Var2Lit( PivotVar, fCompl ); // F = 1
+ pLits[1] = Abc_Var2Lit( FreeVar, 0 ); // iNewLit
+ while ( 1 )
{
- sat_solver_delete( pSat );
- return NULL;
+ // find onset minterm
+ status = sat_solver_solve( pSat, pLits, pLits + 2, 0, 0, 0, 0 );
+ if ( status == l_False )
+ {
+ Vec_IntFree( vTempLits );
+ return uTruth;
+ }
+ assert( status == l_True );
+ if ( fExpand )
+ {
+ // collect divisor literals
+ Vec_IntFill( vTempLits, 1, Abc_LitNot(pLits[0]) ); // F = 0
+ Vec_IntForEachEntry( vDivVars, iVar, i )
+ Vec_IntPush( vTempLits, sat_solver_var_literal(pSat, iVar) );
+ // check against offset
+ status = sat_solver_solve( pSat, Vec_IntArray(vTempLits), Vec_IntLimit(vTempLits), 0, 0, 0, 0 );
+ if ( status != l_False )
+ printf( "Failed internal check during function comptutation.\n" );
+ assert( status == l_False );
+ // compute cube and add clause
+ nFinal = sat_solver_final( pSat, &pFinal );
+ Vec_IntFill( vTempLits, 1, Abc_LitNot(pLits[1]) ); // NOT(iNewLit)
+ for ( i = 0; i < nFinal; i++ )
+ if ( pFinal[i] != pLits[0] )
+ Vec_IntPush( vTempLits, pFinal[i] );
+ }
+ else
+ {
+ // collect divisor literals
+ Vec_IntFill( vTempLits, 1, Abc_LitNot(pLits[1]) );// NOT(iNewLit)
+ Vec_IntForEachEntry( vDivVars, iVar, i )
+ Vec_IntPush( vTempLits, Abc_LitNot(sat_solver_var_literal(pSat, iVar)) );
+ }
+ uCube = ~(word)0;
+ Vec_IntForEachEntryStart( vTempLits, iLit, i, 1 )
+ {
+ iVar = Vec_IntFind( vDivVars, Abc_Lit2Var(iLit) ); assert( iVar >= 0 );
+ uCube &= Abc_LitIsCompl(iLit) ? s_Truths6[iVar] : ~s_Truths6[iVar];
+ }
+ uTruth |= uCube;
+ status = sat_solver_addclause( pSat, Vec_IntArray(vTempLits), Vec_IntLimit(vTempLits) );
+ if ( status == 0 )
+ {
+ Vec_IntFree( vTempLits );
+ return uTruth;
+ }
}
- return pSat;
+ Vec_IntFree( vTempLits );
+ assert( 0 );
+ return ~(word)0;
}
+
/**Function*************************************************************
Synopsis []
@@ -321,7 +430,31 @@ void Acb_NtkPrintVec( Acb_Ntk_t * p, Vec_Int_t * vVec, char * pName )
int i;
printf( "%s: ", pName );
for ( i = 0; i < vVec->nSize; i++ )
- printf( "%d ", Vec_IntEntry(&p->vArray2, vVec->pArray[i]) );
+ printf( "%d ", vVec->pArray[i] );
+ printf( "\n" );
+}
+void Acb_NtkPrintNode( Acb_Ntk_t * p, int Node )
+{
+ int k, iFanin, * pFanins;
+ printf( "Node %d : ", Node );
+ Acb_ObjForEachFaninFast( p, Node, pFanins, iFanin, k )
+ printf( "%d ", iFanin );
+ printf( "\n" );
+}
+void Acb_NtkPrintVec2( Acb_Ntk_t * p, Vec_Int_t * vVec, char * pName )
+{
+ int i;
+ printf( "%s: \n", pName );
+ for ( i = 0; i < vVec->nSize; i++ )
+ Acb_NtkPrintNode( p, vVec->pArray[i] );
+ printf( "\n" );
+}
+void Acb_NtkPrintVecWin( Acb_Ntk_t * p, Vec_Int_t * vVec, char * pName )
+{
+ int i;
+ printf( "%s: \n", pName );
+ for ( i = 0; i < vVec->nSize; i++ )
+ Acb_NtkPrintNode( p, Abc_Lit2Var(vVec->pArray[i]) );
printf( "\n" );
}
@@ -336,56 +469,58 @@ void Acb_NtkPrintVec( Acb_Ntk_t * p, Vec_Int_t * vVec, char * pName )
SeeAlso []
***********************************************************************/
-Vec_Int_t * Acb_NtkDivisors( Acb_Ntk_t * p, int Pivot, int * pTaboo, int nTaboo, int nDivsMax )
+void Acb_NtkDivisors_rec( Acb_Ntk_t * p, int iObj, int nTfiLevMin, Vec_Int_t * vDivs )
{
+ int k, iFanin, * pFanins;
+// if ( !Acb_ObjIsCi(p, iObj) && Acb_ObjLevelD(p, iObj) < nTfiLevMin )
+ if ( !Acb_ObjIsCi(p, iObj) && nTfiLevMin < 0 )
+ return;
+ if ( Acb_ObjSetTravIdCur(p, iObj) )
+ return;
+ Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
+ Acb_NtkDivisors_rec( p, iFanin, nTfiLevMin-1, vDivs );
+ Vec_IntPush( vDivs, iObj );
+}
+Vec_Int_t * Acb_NtkDivisors( Acb_Ntk_t * p, int Pivot, int nTfiLevMin, int fDelay )
+{
+ int k, iFanin, * pFanins;
Vec_Int_t * vDivs = Vec_IntAlloc( 100 );
- Vec_Int_t * vFront = Vec_IntAlloc( 100 );
- int i, k, iFanin, * pFanins;
- // mark taboo nodes
Acb_NtkIncTravId( p );
- assert( !Acb_ObjIsCio(p, Pivot) );
- Acb_ObjSetTravIdCur( p, Pivot );
- for ( i = 0; i < nTaboo; i++ )
+ if ( fDelay ) // delay-oriented
{
- assert( !Acb_ObjIsCio(p, pTaboo[i]) );
- if ( Acb_ObjSetTravIdCur( p, pTaboo[i] ) )
- assert( 0 );
+ // start from critical fanins
+ assert( Acb_ObjLevelD( p, Pivot ) > 1 );
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ if ( Acb_ObjIsDelayCriticalFanin( p, Pivot, iFanin ) )
+ Acb_NtkDivisors_rec( p, iFanin, nTfiLevMin, vDivs );
+ // add non-critical fanins
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ if ( !Acb_ObjIsDelayCriticalFanin( p, Pivot, iFanin ) )
+ if ( !Acb_ObjSetTravIdCur(p, iFanin) )
+ Vec_IntPush( vDivs, iFanin );
}
- // collect non-taboo fanins of pivot but do not use them as frontier
- Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
- if ( !Acb_ObjSetTravIdCur( p, iFanin ) )
- Vec_IntPush( vDivs, iFanin );
- // collect non-taboo fanins of taboo nodes and use them as frontier
- for ( i = 0; i < nTaboo; i++ )
- Acb_ObjForEachFaninFast( p, pTaboo[i], pFanins, iFanin, k )
- if ( !Acb_ObjSetTravIdCur( p, iFanin ) )
- {
- Vec_IntPush( vDivs, iFanin );
- if ( !Acb_ObjIsCio(p, iFanin) )
- Vec_IntPush( vFront, iFanin );
- }
- // select divisors incrementally
- while ( Vec_IntSize(vFront) > 0 && Vec_IntSize(vDivs) < nDivsMax )
- {
- // select the topmost
- int iObj, iObjMax = -1, LevelMax = -1;
- Vec_IntForEachEntry( vFront, iObj, k )
- if ( LevelMax < Acb_ObjLevelD(p, iObj) )
- LevelMax = Acb_ObjLevelD(p, (iObjMax = iObj));
- assert( iObjMax > 0 );
- Vec_IntRemove( vFront, iObjMax );
- // expand the topmost
- Acb_ObjForEachFaninFast( p, iObjMax, pFanins, iFanin, k )
- if ( !Acb_ObjSetTravIdCur( p, iFanin ) )
- {
+ else
+ {
+ Acb_NtkDivisors_rec( p, Pivot, nTfiLevMin, vDivs );
+ assert( Vec_IntEntryLast(vDivs) == Pivot );
+ Vec_IntPop( vDivs );
+ // add remaining fanins of the node
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ if ( !Acb_ObjSetTravIdCur(p, iFanin) )
Vec_IntPush( vDivs, iFanin );
- if ( !Acb_ObjIsCio(p, iFanin) )
- Vec_IntPush( vFront, iFanin );
- }
+/*
+ // start from critical fanins
+ assert( Acb_ObjLevelD( p, Pivot ) > 1 );
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ if ( Acb_ObjIsAreaCritical( p, iFanin ) )
+ Acb_NtkDivisors_rec( p, iFanin, nTfiLevMin, vDivs );
+ // add non-critical fanins
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ if ( !Acb_ObjIsAreaCritical( p, iFanin ) )
+ if ( !Acb_ObjSetTravIdCur(p, iFanin) )
+ Vec_IntPush( vDivs, iFanin );
+*/
}
- Vec_IntFree( vFront );
- // sort them by level
- Vec_IntSelectSortCost( Vec_IntArray(vDivs), Vec_IntSize(vDivs), &p->vLevelD );
return vDivs;
}
@@ -400,24 +535,34 @@ Vec_Int_t * Acb_NtkDivisors( Acb_Ntk_t * p, int Pivot, int * pTaboo, int nTaboo,
SeeAlso []
***********************************************************************/
-void Acb_ObjMarkTfo_rec( Acb_Ntk_t * p, int iObj, int Pivot, int nTfoLevMax, int nFanMax )
+void Acb_ObjMarkTfo_rec( Acb_Ntk_t * p, int iObj, int nTfoLevMax, int nFanMax, Vec_Int_t * vMarked )
{
int iFanout, i;
if ( Acb_ObjSetTravIdCur(p, iObj) )
return;
-//printf( "Labeling %d.\n", Vec_IntEntry(&p->vArray2, iObj) );
- if ( Acb_ObjLevelD(p, iObj) > nTfoLevMax || Acb_ObjFanoutNum(p, iObj) > nFanMax || iObj == Pivot )
+ Vec_IntPush( vMarked, iObj );
+ if ( Acb_ObjLevelD(p, iObj) > nTfoLevMax || Acb_ObjFanoutNum(p, iObj) > nFanMax )
return;
Acb_ObjForEachFanout( p, iObj, iFanout, i )
- Acb_ObjMarkTfo_rec( p, iFanout, Pivot, nTfoLevMax, nFanMax );
+ Acb_ObjMarkTfo_rec( p, iFanout, nTfoLevMax, nFanMax, vMarked );
}
-void Acb_ObjMarkTfo( Acb_Ntk_t * p, Vec_Int_t * vDivs, int Pivot, int nTfoLevMax, int nFanMax )
+Vec_Int_t * Acb_ObjMarkTfo( Acb_Ntk_t * p, Vec_Int_t * vDivs, int Pivot, int nTfoLevMax, int nFanMax )
{
+ Vec_Int_t * vMarked = Vec_IntAlloc( 1000 );
int i, iObj;
Acb_NtkIncTravId( p );
Acb_ObjSetTravIdCur( p, Pivot );
+ Vec_IntPush( vMarked, Pivot );
Vec_IntForEachEntry( vDivs, iObj, i )
- Acb_ObjMarkTfo_rec( p, iObj, Pivot, nTfoLevMax, nFanMax );
+ Acb_ObjMarkTfo_rec( p, iObj, nTfoLevMax, nFanMax, vMarked );
+ return vMarked;
+}
+void Acb_ObjMarkTfo2( Acb_Ntk_t * p, Vec_Int_t * vMarked )
+{
+ int i, Node;
+ Acb_NtkIncTravId( p );
+ Vec_IntForEachEntry( vMarked, Node, i )
+ Acb_ObjSetTravIdCur( p, Node );
}
/**Function*************************************************************
@@ -431,36 +576,36 @@ void Acb_ObjMarkTfo( Acb_Ntk_t * p, Vec_Int_t * vDivs, int Pivot, int nTfoLevMax
SeeAlso []
***********************************************************************/
-int Acb_ObjLabelTfo_rec( Acb_Ntk_t * p, int iObj, int nTfoLevMax, int nFanMax )
+int Acb_ObjLabelTfo_rec( Acb_Ntk_t * p, int iObj, int nTfoLevMax, int nFanMax, int fFirst )
{
int iFanout, i, Diff, fHasNone = 0;
-//printf( "Visiting %d\n", Vec_IntEntry(&p->vArray2, iObj) );
if ( (Diff = Acb_ObjTravIdDiff(p, iObj)) <= 2 )
return Diff;
Acb_ObjSetTravIdDiff( p, iObj, 2 );
if ( Acb_ObjIsCo(p, iObj) || Acb_ObjLevelD(p, iObj) > nTfoLevMax )
return 2;
- if ( Acb_ObjLevelD(p, iObj) == nTfoLevMax || Acb_ObjFanoutNum(p, iObj) >= nFanMax )
+ if ( Acb_ObjLevelD(p, iObj) == nTfoLevMax || Acb_ObjFanoutNum(p, iObj) > nFanMax )
{
if ( Diff == 3 ) // belongs to TFO of TFI
Acb_ObjSetTravIdDiff( p, iObj, 1 ); // root
return Acb_ObjTravIdDiff(p, iObj);
}
Acb_ObjForEachFanout( p, iObj, iFanout, i )
- fHasNone |= 2 == Acb_ObjLabelTfo_rec( p, iFanout, nTfoLevMax, nFanMax );
+ if ( !fFirst || Acb_ObjIsDelayCriticalFanin(p, iFanout, iObj) )
+ fHasNone |= 2 == Acb_ObjLabelTfo_rec( p, iFanout, nTfoLevMax, nFanMax, 0 );
if ( fHasNone && Diff == 3 ) // belongs to TFO of TFI
Acb_ObjSetTravIdDiff( p, iObj, 1 ); // root
else if ( !fHasNone )
Acb_ObjSetTravIdDiff( p, iObj, 0 ); // inner
return Acb_ObjTravIdDiff(p, iObj);
}
-int Acb_ObjLabelTfo( Acb_Ntk_t * p, int Root, int nTfoLevMax, int nFanMax )
+int Acb_ObjLabelTfo( Acb_Ntk_t * p, int Root, int nTfoLevMax, int nFanMax, int fDelay )
{
Acb_NtkIncTravId( p ); // none (2) marked (3) unmarked (4)
Acb_NtkIncTravId( p ); // root (1)
Acb_NtkIncTravId( p ); // inner (0)
assert( Acb_ObjTravIdDiff(p, Root) > 2 );
- return Acb_ObjLabelTfo_rec( p, Root, nTfoLevMax, nFanMax );
+ return Acb_ObjLabelTfo_rec( p, Root, nTfoLevMax, nFanMax, fDelay );
}
/**Function*************************************************************
@@ -474,7 +619,7 @@ int Acb_ObjLabelTfo( Acb_Ntk_t * p, int Root, int nTfoLevMax, int nFanMax )
SeeAlso []
***********************************************************************/
-void Acb_ObjDeriveTfo_rec( Acb_Ntk_t * p, int iObj, Vec_Int_t * vTfo, Vec_Int_t * vRoots )
+void Acb_ObjDeriveTfo_rec( Acb_Ntk_t * p, int iObj, Vec_Int_t * vTfo, Vec_Int_t * vRoots, int fFirst )
{
int iFanout, i, Diff = Acb_ObjTravIdDiff(p, iObj);
if ( Acb_ObjSetTravIdCur(p, iObj) )
@@ -487,18 +632,19 @@ void Acb_ObjDeriveTfo_rec( Acb_Ntk_t * p, int iObj, Vec_Int_t * vTfo, Vec_Int_t
}
assert( Diff == 1 );
Acb_ObjForEachFanout( p, iObj, iFanout, i )
- Acb_ObjDeriveTfo_rec( p, iFanout, vTfo, vRoots );
+ if ( !fFirst || Acb_ObjIsDelayCriticalFanin(p, iFanout, iObj) )
+ Acb_ObjDeriveTfo_rec( p, iFanout, vTfo, vRoots, 0 );
Vec_IntPush( vTfo, iObj );
}
-void Acb_ObjDeriveTfo( Acb_Ntk_t * p, int Pivot, int nTfoLevMax, int nFanMax, Vec_Int_t ** pvTfo, Vec_Int_t ** pvRoots )
+void Acb_ObjDeriveTfo( Acb_Ntk_t * p, int Pivot, int nTfoLevMax, int nFanMax, Vec_Int_t ** pvTfo, Vec_Int_t ** pvRoots, int fDelay )
{
- int Res = Acb_ObjLabelTfo( p, Pivot, nTfoLevMax, nFanMax );
+ int Res = Acb_ObjLabelTfo( p, Pivot, nTfoLevMax, nFanMax, fDelay );
Vec_Int_t * vTfo = *pvTfo = Vec_IntAlloc( 10 );
Vec_Int_t * vRoots = *pvRoots = Vec_IntAlloc( 10 );
if ( Res ) // none or root
return;
Acb_NtkIncTravId( p ); // root (2) inner (1) visited (0)
- Acb_ObjDeriveTfo_rec( p, Pivot, vTfo, vRoots );
+ Acb_ObjDeriveTfo_rec( p, Pivot, vTfo, vRoots, fDelay );
assert( Vec_IntEntryLast(vTfo) == Pivot );
Vec_IntPop( vTfo );
assert( Vec_IntEntryLast(vRoots) != Pivot );
@@ -572,15 +718,22 @@ Vec_Int_t * Acb_NtkCollectNewTfi( Acb_Ntk_t * p, int Pivot, Vec_Int_t * vDivs, V
Vec_Int_t * vTfiNew = Vec_IntAlloc( 100 );
int i, Node;
Acb_NtkIncTravId( p );
-//Acb_NtkPrintVec( p, vDivs, "vDivs" );
+ //Acb_NtkPrintVec( p, vDivs, "vDivs" );
Vec_IntForEachEntry( vDivs, Node, i )
Acb_NtkCollectNewTfi1_rec( p, Node, vTfiNew );
- *pnDivs = Vec_IntSize(vTfiNew);
//Acb_NtkPrintVec( p, vTfiNew, "vTfiNew" );
Acb_NtkCollectNewTfi1_rec( p, Pivot, vTfiNew );
//Acb_NtkPrintVec( p, vTfiNew, "vTfiNew" );
assert( Vec_IntEntryLast(vTfiNew) == Pivot );
Vec_IntPop( vTfiNew );
+/*
+ Vec_IntForEachEntry( vDivs, Node, i )
+ {
+ Acb_ObjSetTravIdCur( p, Node );
+ Vec_IntPush( vTfiNew, Node );
+ }
+*/
+ *pnDivs = Vec_IntSize(vTfiNew);
Vec_IntForEachEntry( vSide, Node, i )
Acb_NtkCollectNewTfi2_rec( p, Node, vTfiNew );
Vec_IntPush( vTfiNew, Pivot );
@@ -640,25 +793,28 @@ Vec_Int_t * Acb_NtkCollectWindow( Acb_Ntk_t * p, int Pivot, Vec_Int_t * vTfi, Ve
SeeAlso []
***********************************************************************/
-Vec_Int_t * Acb_NtkWindow( Acb_Ntk_t * p, int Pivot, int * pTaboo, int nTaboo, int nDivsMax, int nTfoLevs, int nFanMax, int * pnDivs )
+Vec_Int_t * Acb_NtkWindow( Acb_Ntk_t * p, int Pivot, int nTfiLevs, int nTfoLevs, int nFanMax, int fDelay, int * pnDivs )
{
int fVerbose = 0;
+ //int nTfiLevMin = Acb_ObjLevelD(p, Pivot) - nTfiLevs;
int nTfoLevMax = Acb_ObjLevelD(p, Pivot) + nTfoLevs;
- Vec_Int_t * vWin, * vDivs, * vTfo, * vRoots, * vSide, * vTfi;
+ Vec_Int_t * vWin, * vDivs, * vMarked, * vTfo, * vRoots, * vSide, * vTfi;
// collect divisors by traversing limited TFI
- vDivs = Acb_NtkDivisors( p, Pivot, pTaboo, nTaboo, nDivsMax );
+ vDivs = Acb_NtkDivisors( p, Pivot, nTfiLevs, fDelay );
if ( fVerbose ) Acb_NtkPrintVec( p, vDivs, "vDivs" );
// mark limited TFO of the divisors
- Acb_ObjMarkTfo( p, vDivs, Pivot, nTfoLevMax, nFanMax );
+ vMarked = Acb_ObjMarkTfo( p, vDivs, Pivot, nTfoLevMax, nFanMax );
// collect TFO and roots
- Acb_ObjDeriveTfo( p, Pivot, nTfoLevMax, nFanMax, &vTfo, &vRoots );
+ Acb_ObjDeriveTfo( p, Pivot, nTfoLevMax, nFanMax, &vTfo, &vRoots, fDelay );
if ( fVerbose ) Acb_NtkPrintVec( p, vTfo, "vTfo" );
if ( fVerbose ) Acb_NtkPrintVec( p, vRoots, "vRoots" );
// collect side inputs of the TFO
vSide = Acb_NtkCollectTfoSideInputs( p, Pivot, vTfo );
if ( fVerbose ) Acb_NtkPrintVec( p, vSide, "vSide" );
// mark limited TFO of the divisors
- Acb_ObjMarkTfo( p, vDivs, Pivot, nTfoLevMax, nFanMax );
+ //Acb_ObjMarkTfo( p, vDivs, Pivot, nTfoLevMax, nFanMax );
+ Acb_ObjMarkTfo2( p, vMarked );
+ Vec_IntFree( vMarked );
// collect new TFI
vTfi = Acb_NtkCollectNewTfi( p, Pivot, vDivs, vSide, pnDivs );
if ( fVerbose ) Acb_NtkPrintVec( p, vTfi, "vTfi" );
@@ -677,7 +833,7 @@ Vec_Int_t * Acb_NtkWindow( Acb_Ntk_t * p, int Pivot, int * pTaboo, int nTaboo, i
/**Function*************************************************************
- Synopsis [Computes function of the node]
+ Synopsis []
Description []
@@ -686,70 +842,74 @@ Vec_Int_t * Acb_NtkWindow( Acb_Ntk_t * p, int Pivot, int * pTaboo, int nTaboo, i
SeeAlso []
***********************************************************************/
-word Acb_ComputeFunction( sat_solver * pSat, int PivotVar, int FreeVar, Vec_Int_t * vDivVars )
+static inline void Vec_IntVars2Vars( Vec_Int_t * p, int Shift )
{
- int fExpand = 1;
- word uCube, uTruth = 0;
- Vec_Int_t * vTempLits = Vec_IntAlloc( 100 );
- int status, i, iVar, iLit, nFinal, * pFinal, pLits[2];
- assert( FreeVar < sat_solver_nvars(pSat) );
- pLits[0] = Abc_Var2Lit( PivotVar, 0 ); // F = 1
- pLits[1] = Abc_Var2Lit( FreeVar, 0 ); // iNewLit
- while ( 1 )
+ int i;
+ for ( i = 0; i < p->nSize; i++ )
+ p->pArray[i] += Shift;
+}
+static inline void Vec_IntVars2Lits( Vec_Int_t * p, int Shift, int fCompl )
+{
+ int i;
+ for ( i = 0; i < p->nSize; i++ )
+ p->pArray[i] = Abc_Var2Lit( p->pArray[i] + Shift, fCompl );
+}
+static inline void Vec_IntLits2Vars( Vec_Int_t * p, int Shift )
+{
+ int i;
+ for ( i = 0; i < p->nSize; i++ )
+ p->pArray[i] = Abc_Lit2Var( p->pArray[i] ) + Shift;
+}
+static inline void Vec_IntRemap( Vec_Int_t * p, Vec_Int_t * vMap )
+{
+ int i;
+ for ( i = 0; i < p->nSize; i++ )
+ p->pArray[i] = Vec_IntEntry(vMap, p->pArray[i]);
+}
+
+static inline void Acb_WinPrint( Acb_Ntk_t * p, Vec_Int_t * vWin, int Pivot, int nDivs )
+{
+ int i, Node;
+ printf( "Window for node %d with %d divisors:\n", Pivot, nDivs );
+ Vec_IntForEachEntry( vWin, Node, i )
{
- // find onset minterm
- status = sat_solver_solve( pSat, pLits, pLits + 2, 0, 0, 0, 0 );
- if ( status == l_False )
- {
- Vec_IntFree( vTempLits );
- return uTruth;
- }
- assert( status == l_True );
- if ( fExpand )
- {
- // collect divisor literals
- Vec_IntFill( vTempLits, 1, Abc_LitNot(pLits[0]) ); // F = 0
- Vec_IntForEachEntry( vDivVars, iVar, i )
- Vec_IntPush( vTempLits, sat_solver_var_literal(pSat, iVar) );
- // check against offset
- status = sat_solver_solve( pSat, Vec_IntArray(vTempLits), Vec_IntLimit(vTempLits), 0, 0, 0, 0 );
- assert( status == l_False );
- // compute cube and add clause
- nFinal = sat_solver_final( pSat, &pFinal );
- Vec_IntFill( vTempLits, 1, Abc_LitNot(pLits[1]) ); // NOT(iNewLit)
- for ( i = 0; i < nFinal; i++ )
- if ( pFinal[i] != pLits[0] )
- Vec_IntPush( vTempLits, pFinal[i] );
- }
+ if ( i == nDivs )
+ printf( " | " );
+ if ( Abc_Lit2Var(Node) == Pivot )
+ printf( "(%d) ", Pivot );
else
- {
- // collect divisor literals
- Vec_IntFill( vTempLits, 1, Abc_LitNot(pLits[1]) );// NOT(iNewLit)
- Vec_IntForEachEntry( vDivVars, iVar, i )
- Vec_IntPush( vTempLits, Abc_LitNot(sat_solver_var_literal(pSat, iVar)) );
- }
- uCube = ~(word)0;
- Vec_IntForEachEntryStart( vTempLits, iLit, i, 1 )
- {
- iVar = Vec_IntFind( vDivVars, Abc_Lit2Var(iLit) ); assert( iVar >= 0 );
- uCube &= Abc_LitIsCompl(iLit) ? s_Truths6[iVar] : ~s_Truths6[iVar];
- }
- uTruth |= uCube;
- status = sat_solver_addclause( pSat, Vec_IntArray(vTempLits), Vec_IntLimit(vTempLits) );
- if ( status == 0 )
- {
- Vec_IntFree( vTempLits );
- return uTruth;
- }
+ printf( "%s%d ", Abc_LitIsCompl(Node) ? "*":"", Abc_Lit2Var(Node) );
}
- assert( 0 );
- return ~(word)0;
+ printf( "\n" );
}
+static inline void Acb_NtkOrderByRefCount( Acb_Ntk_t * p, Vec_Int_t * vSupp )
+{
+ int i, j, best_i, nSize = Vec_IntSize(vSupp);
+ int * pArray = Vec_IntArray(vSupp);
+ for ( i = 0; i < nSize-1; i++ )
+ {
+ best_i = i;
+ for ( j = i+1; j < nSize; j++ )
+ if ( Acb_ObjFanoutNum(p, pArray[j]) > Acb_ObjFanoutNum(p, pArray[best_i]) )
+ best_i = j;
+ ABC_SWAP( int, pArray[i], pArray[best_i] );
+ }
+}
+
+static inline void Acb_NtkRemapIntoSatVariables( Acb_Ntk_t * p, Vec_Int_t * vSupp )
+{
+ int k, iFanin;
+ Vec_IntForEachEntry( vSupp, iFanin, k )
+ {
+ assert( Acb_ObjFunc(p, iFanin) >= 0 );
+ Vec_IntWriteEntry( vSupp, k, Acb_ObjFunc(p, iFanin) );
+ }
+}
/**Function*************************************************************
- Synopsis [Collects the taboo nodes (nodes that cannot be divisors).]
+ Synopsis []
Description []
@@ -758,68 +918,233 @@ word Acb_ComputeFunction( sat_solver * pSat, int PivotVar, int FreeVar, Vec_Int_
SeeAlso []
***********************************************************************/
-static inline int Acb_ObjIsCritFanin( Acb_Ntk_t * p, int i, int f ) { return Acb_ObjLevelR(p, i) + Acb_ObjLevelD(p, f) == p->LevelMax; }
-
-static inline void Acb_ObjUpdateFanoutCount( Acb_Ntk_t * p, int iObj, int AddOn )
+int Acb_NtkFindSupp1( Acb_Ntk_t * p, int Pivot, sat_solver * pSat, int nVars, int nDivs, Vec_Int_t * vWin, Vec_Int_t * vSupp )
{
- int k, iFanin, * pFanins;
- Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
- Acb_ObjFanoutVec(p, iFanin)->nSize += AddOn;
+ int nSuppNew, status, k, iFanin, * pFanins;
+ Vec_IntClear( vSupp );
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ Vec_IntPush( vSupp, iFanin );
+ Acb_NtkOrderByRefCount( p, vSupp );
+ Acb_NtkRemapIntoSatVariables( p, vSupp );
+ Vec_IntVars2Lits( vSupp, 2*nVars, 0 );
+ status = sat_solver_solve( pSat, Vec_IntArray(vSupp), Vec_IntLimit(vSupp), 0, 0, 0, 0 );
+ if ( status != l_False )
+ printf( "Failed internal check at node %d.\n", Pivot );
+ assert( status == l_False );
+ nSuppNew = sat_solver_minimize_assumptions( pSat, Vec_IntArray(vSupp), Vec_IntSize(vSupp), 0 );
+ Vec_IntShrink( vSupp, nSuppNew );
+ Vec_IntLits2Vars( vSupp, -2*nVars );
+ return Vec_IntSize(vSupp) < Acb_ObjFaninNum(p, Pivot);
}
-int Acb_NtkCollectTaboo( Acb_Ntk_t * p, int Pivot, int nTabooMax, int * pTaboo )
+static int StrCount = 0;
+
+int Acb_NtkFindSupp2( Acb_Ntk_t * p, int Pivot, sat_solver * pSat, int nVars, int nDivs, Vec_Int_t * vWin, Vec_Int_t * vSupp, int nLutSize, int fDelay )
{
- int i, k, iFanin, * pFanins, nTaboo = 0;
- if ( nTabooMax == 0 ) // delay optimization
+ int nSuppNew, status, k, iFanin, * pFanins, k2, iFanin2, * pFanins2;
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ assert( Acb_ObjFunc(p, iFanin) >= 0 && Acb_ObjFunc(p, iFanin) < nDivs );
+ if ( fDelay )
{
- // collect delay critical fanins of the pivot node
+ // add non-timing-critical fanins
+ int nNonCrits, k2, iFanin2 = 0, * pFanins2;
+ assert( Acb_ObjLevelD( p, Pivot ) > 1 );
+ Vec_IntClear( vSupp );
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ if ( !Acb_ObjIsDelayCriticalFanin( p, Pivot, iFanin ) )
+ Vec_IntPush( vSupp, iFanin );
+ nNonCrits = Vec_IntSize(vSupp);
+ // add fanins of timing critical fanins
Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
- if ( !Acb_ObjIsCi(p, iFanin) && Acb_ObjIsCritFanin( p, Pivot, iFanin ) )
- pTaboo[ nTaboo++ ] = iFanin;
+ if ( Acb_ObjIsDelayCriticalFanin( p, Pivot, iFanin ) )
+ Acb_ObjForEachFaninFast( p, iFanin, pFanins2, iFanin2, k2 )
+ Vec_IntPushUnique( vSupp, iFanin2 );
+ assert( nNonCrits < Vec_IntSize(vSupp) );
+ // sort additional fanins by level
+ Vec_IntSelectSortCost( Vec_IntArray(vSupp) + nNonCrits, Vec_IntSize(vSupp) - nNonCrits, &p->vLevelD );
+ // translate to SAT vars
+ Vec_IntForEachEntry( vSupp, iFanin, k )
+ {
+ assert( Acb_ObjFunc(p, iFanin) >= 0 );
+ Vec_IntWriteEntry( vSupp, k, Acb_ObjFunc(p, iFanin) );
+ }
+ // solve for these fanins
+ Vec_IntVars2Lits( vSupp, 2*nVars, 0 );
+ status = sat_solver_solve( pSat, Vec_IntArray(vSupp), Vec_IntLimit(vSupp), 0, 0, 0, 0 );
+ if ( status != l_False )
+ printf( "Failed internal check at node %d.\n", Pivot );
+ assert( status == l_False );
+ nSuppNew = sat_solver_minimize_assumptions( pSat, Vec_IntArray(vSupp), Vec_IntSize(vSupp), 0 );
+ Vec_IntShrink( vSupp, nSuppNew );
+ Vec_IntLits2Vars( vSupp, -2*nVars );
+ return Vec_IntSize(vSupp) <= nLutSize;
+ }
+ // iterate through different fanout free cones
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ {
+ if ( !Acb_ObjIsAreaCritical(p, iFanin) )
+ continue;
+ // collect fanins of the root node
+ Vec_IntClear( vSupp );
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins2, iFanin2, k2 )
+ if ( iFanin != iFanin2 )
+ Vec_IntPush( vSupp, iFanin2 );
+ // collect fanins of the selected node
+ Acb_ObjForEachFaninFast( p, iFanin, pFanins2, iFanin2, k2 )
+ Vec_IntPushUnique( vSupp, iFanin2 );
+ // sort fanins by level
+ Vec_IntSelectSortCost( Vec_IntArray(vSupp), Vec_IntSize(vSupp), &p->vLevelD );
+ //Acb_NtkOrderByRefCount( p, vSupp );
+ Acb_NtkRemapIntoSatVariables( p, vSupp );
+ // solve for these fanins
+ Vec_IntVars2Lits( vSupp, 2*nVars, 0 );
+ status = sat_solver_solve( pSat, Vec_IntArray(vSupp), Vec_IntLimit(vSupp), 0, 0, 0, 0 );
+ if ( status != l_False )
+ printf( "Failed internal check at node %d.\n", Pivot );
+ assert( status == l_False );
+ nSuppNew = sat_solver_minimize_assumptions( pSat, Vec_IntArray(vSupp), Vec_IntSize(vSupp), 0 );
+ Vec_IntShrink( vSupp, nSuppNew );
+ Vec_IntLits2Vars( vSupp, -2*nVars );
+ if ( Vec_IntSize(vSupp) <= nLutSize )
+ return 1;
}
- else // area optimization
+ return 0;
+}
+
+int Acb_NtkFindSupp3( Acb_Ntk_t * p, int Pivot, sat_solver * pSat, int nVars, int nDivs, Vec_Int_t * vWin, Vec_Int_t * vSupp, int nLutSize, int fDelay )
+{
+ int nSuppNew, status, k, iFanin, * pFanins, k2, iFanin2, * pFanins2, k3, iFanin3, * pFanins3, NodeMark;
+
+ if ( fDelay )
+ return 0;
+
+ // iterate through pairs of fanins with one fanouts
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
{
- // check if the node has any area critical fanins
- Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
- if ( !Acb_ObjIsCi(p, iFanin) && Acb_ObjFanoutNum(p, iFanin) == 1 )
- break;
- if ( k < Acb_ObjFaninNum(p, Pivot) ) // there is fanin
+ if ( !Acb_ObjIsAreaCritical(p, iFanin) )
+ continue;
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins2, iFanin2, k2 )
{
- // mark pivot
- Acb_NtkIncTravId( p );
- Acb_ObjSetTravIdCur( p, Pivot );
- Acb_ObjUpdateFanoutCount( p, Pivot, -1 );
- // add the first taboo node
- assert( Acb_ObjFanoutNum(p, iFanin) == 0 );
- pTaboo[ nTaboo++ ] = iFanin;
- Acb_ObjSetTravIdCur( p, iFanin );
- Acb_ObjUpdateFanoutCount( p, iFanin, -1 );
- while ( nTaboo < nTabooMax )
- {
- // select the first unrefed fanin
- for ( i = 0; i < nTaboo; i++ )
+ if ( !Acb_ObjIsAreaCritical(p, iFanin2) || k2 == k )
+ continue;
+ // iFanin and iFanin2 have 1 fanout
+ assert( iFanin != iFanin2 );
+
+ // collect fanins of the root node
+ Vec_IntClear( vSupp );
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins3, iFanin3, k3 )
+ if ( iFanin3 != iFanin && iFanin3 != iFanin2 )
{
- Acb_ObjForEachFaninFast( p, pTaboo[i], pFanins, iFanin, k )
- if ( !Acb_ObjIsCi(p, iFanin) && !Acb_ObjIsTravIdCur(p, iFanin) && Acb_ObjFanoutNum(p, iFanin) == 0 )
- {
- pTaboo[ nTaboo++ ] = iFanin;
- Acb_ObjSetTravIdCur( p, iFanin );
- Acb_ObjUpdateFanoutCount( p, iFanin, -1 );
- break;
- }
- if ( k < Acb_ObjFaninNum(p, pTaboo[i]) )
- break;
+ assert( Acb_ObjFunc(p, iFanin3) >= 0 );
+ Vec_IntPush( vSupp, Abc_Var2Lit(Acb_ObjFunc(p, iFanin3) + 6*nVars, 0) );
}
- if ( i == nTaboo ) // no change
- break;
+ NodeMark = Vec_IntSize(vSupp);
+
+ // collect fanins of the second node
+ Acb_ObjForEachFaninFast( p, iFanin, pFanins3, iFanin3, k3 )
+ {
+ assert( Acb_ObjFunc(p, iFanin3) >= 0 );
+ Vec_IntPush( vSupp, Abc_Var2Lit(Acb_ObjFunc(p, iFanin3) + 6*nVars + nDivs, 0) );
+ }
+ // collect fanins of the third node
+ Acb_ObjForEachFaninFast( p, iFanin2, pFanins3, iFanin3, k3 )
+ {
+ assert( Acb_ObjFunc(p, iFanin3) >= 0 );
+ Vec_IntPushUnique( vSupp, Abc_Var2Lit(Acb_ObjFunc(p, iFanin3) + 6*nVars + nDivs, 0) );
+ }
+ assert( Vec_IntCheckUniqueSmall(vSupp) );
+
+ // sort fanins by level
+ //Vec_IntSelectSortCost( Vec_IntArray(vSupp) + NodeMark, Vec_IntSize(vSupp) - NodeMark, &p->vLevelD );
+ // solve for these fanins
+ status = sat_solver_solve( pSat, Vec_IntArray(vSupp), Vec_IntLimit(vSupp), 0, 0, 0, 0 );
+ if ( status != l_False )
+ continue;
+ assert( status == l_False );
+ nSuppNew = sat_solver_minimize_assumptions( pSat, Vec_IntArray(vSupp), Vec_IntSize(vSupp), 0 );
+ Vec_IntShrink( vSupp, nSuppNew );
+ Vec_IntLits2Vars( vSupp, -6*nVars );
+ Vec_IntSort( vSupp, 1 );
+ // count how many belong to H; the rest belong to G
+ NodeMark = 0;
+ Vec_IntForEachEntry( vSupp, iFanin3, k3 )
+ if ( iFanin3 >= nDivs )
+ Vec_IntWriteEntry( vSupp, k3, iFanin3 - nDivs );
+ else
+ NodeMark++;
+ if ( NodeMark == 0 )
+ {
+ //printf( "Obj %d: Special case 1 (vars = %d)\n", Pivot, Vec_IntSize(vSupp) );
+ continue;
}
- // reference nodes back
- Acb_ObjUpdateFanoutCount( p, Pivot, 1 );
- for ( i = 0; i < nTaboo; i++ )
- Acb_ObjUpdateFanoutCount( p, pTaboo[i], 1 );
+ assert( NodeMark > 0 );
+ if ( Vec_IntSize(vSupp) - NodeMark <= nLutSize )
+ return NodeMark;
}
}
- return nTaboo;
+
+ // iterate through fanins with one fanout and their fanins with one fanout
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ {
+ if ( !Acb_ObjIsAreaCritical(p, iFanin) )
+ continue;
+ Acb_ObjForEachFaninFast( p, iFanin, pFanins2, iFanin2, k2 )
+ {
+ if ( !Acb_ObjIsAreaCritical(p, iFanin2) )
+ continue;
+ // iFanin and iFanin2 have 1 fanout
+ assert( iFanin != iFanin2 );
+
+ // collect fanins of the root node
+ Vec_IntClear( vSupp );
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins3, iFanin3, k3 )
+ if ( iFanin3 != iFanin && iFanin3 != iFanin2 )
+ Vec_IntPush( vSupp, Abc_Var2Lit(Acb_ObjFunc(p, iFanin3) + 6*nVars, 0) );
+ NodeMark = Vec_IntSize(vSupp);
+
+ // collect fanins of the second node
+ Acb_ObjForEachFaninFast( p, iFanin, pFanins3, iFanin3, k3 )
+ if ( iFanin3 != iFanin2 )
+ Vec_IntPush( vSupp, Abc_Var2Lit(Acb_ObjFunc(p, iFanin3) + 6*nVars + nDivs, 0) );
+ // collect fanins of the third node
+ Acb_ObjForEachFaninFast( p, iFanin2, pFanins3, iFanin3, k3 )
+ {
+ assert( Acb_ObjFunc(p, iFanin3) >= 0 );
+ Vec_IntPushUnique( vSupp, Abc_Var2Lit(Acb_ObjFunc(p, iFanin3) + 6*nVars + nDivs, 0) );
+ }
+ assert( Vec_IntCheckUniqueSmall(vSupp) );
+
+ // sort fanins by level
+ //Vec_IntSelectSortCost( Vec_IntArray(vSupp) + NodeMark, Vec_IntSize(vSupp) - NodeMark, &p->vLevelD );
+ //Sat_SolverWriteDimacs( pSat, NULL, Vec_IntArray(vSupp), Vec_IntLimit(vSupp), 0 );
+ // solve for these fanins
+ status = sat_solver_solve( pSat, Vec_IntArray(vSupp), Vec_IntLimit(vSupp), 0, 0, 0, 0 );
+ if ( status != l_False )
+ printf( "Failed internal check at node %d.\n", Pivot );
+ assert( status == l_False );
+ nSuppNew = sat_solver_minimize_assumptions( pSat, Vec_IntArray(vSupp), Vec_IntSize(vSupp), 0 );
+ Vec_IntShrink( vSupp, nSuppNew );
+ Vec_IntLits2Vars( vSupp, -6*nVars );
+ Vec_IntSort( vSupp, 1 );
+ // count how many belong to H; the rest belong to G
+ NodeMark = 0;
+ Vec_IntForEachEntry( vSupp, iFanin3, k3 )
+ if ( iFanin3 >= nDivs )
+ Vec_IntWriteEntry( vSupp, k3, iFanin3 - nDivs );
+ else
+ NodeMark++;
+ if ( NodeMark == 0 )
+ {
+ //printf( "Obj %d: Special case 2 (vars = %d)\n", Pivot, Vec_IntSize(vSupp) );
+ continue;
+ }
+ assert( NodeMark > 0 );
+ if ( Vec_IntSize(vSupp) - NodeMark <= nLutSize )
+ return NodeMark;
+ }
+ }
+
+ return 0;
}
/**Function*************************************************************
@@ -833,128 +1158,417 @@ int Acb_NtkCollectTaboo( Acb_Ntk_t * p, int Pivot, int nTabooMax, int * pTaboo )
SeeAlso []
***********************************************************************/
-static inline void Vec_IntVars2Vars( Vec_Int_t * p, int Shift )
+typedef struct Acb_Mfs_t_ Acb_Mfs_t;
+struct Acb_Mfs_t_
{
- int i;
- for ( i = 0; i < p->nSize; i++ )
- p->pArray[i] += Shift;
-}
-static inline void Vec_IntVars2Lits( Vec_Int_t * p, int Shift, int fCompl )
+ Acb_Ntk_t * pNtk; // network
+ Acb_Par_t * pPars; // parameters
+ sat_solver * pSat[3]; // SAT solvers
+ Vec_Int_t * vSupp; // support
+ Vec_Int_t * vFlip; // support
+ Vec_Int_t * vValues; // support
+ int nNodes; // nodes
+ int nWins; // windows
+ int nWinsAll; // windows
+ int nDivsAll; // windows
+ int nChanges[8]; // changes
+ int nOvers; // overflows
+ int nTwoNodes; // two nodes
+ abctime timeTotal;
+ abctime timeCnf;
+ abctime timeSol;
+ abctime timeWin;
+ abctime timeSat;
+ abctime timeSatU;
+ abctime timeSatS;
+};
+Acb_Mfs_t * Acb_MfsStart( Acb_Ntk_t * pNtk, Acb_Par_t * pPars )
{
- int i;
- for ( i = 0; i < p->nSize; i++ )
- p->pArray[i] = Abc_Var2Lit( p->pArray[i] + Shift, fCompl );
+ Acb_Mfs_t * p = ABC_CALLOC( Acb_Mfs_t, 1 );
+ p->pNtk = pNtk;
+ p->pPars = pPars;
+ p->timeTotal = Abc_Clock();
+ p->pSat[0] = sat_solver_new();
+ p->pSat[1] = sat_solver_new();
+ p->pSat[2] = sat_solver_new();
+ p->vSupp = Vec_IntAlloc(100);
+ p->vFlip = Vec_IntAlloc(100);
+ p->vValues = Vec_IntAlloc(100);
+ return p;
}
-static inline void Vec_IntLits2Vars( Vec_Int_t * p, int Shift )
+void Acb_MfsStop( Acb_Mfs_t * p )
{
- int i;
- for ( i = 0; i < p->nSize; i++ )
- p->pArray[i] = Abc_Lit2Var( p->pArray[i] ) + Shift;
+ Vec_IntFree( p->vFlip );
+ Vec_IntFree( p->vSupp );
+ Vec_IntFree( p->vValues );
+ sat_solver_delete( p->pSat[0] );
+ sat_solver_delete( p->pSat[1] );
+ sat_solver_delete( p->pSat[2] );
+ ABC_FREE( p );
}
-static inline void Vec_IntRemap( Vec_Int_t * p, Vec_Int_t * vMap )
+static inline int Acb_NtkObjMffcEstimate( Acb_Ntk_t * pNtk, int iObj )
{
- int i;
- for ( i = 0; i < p->nSize; i++ )
- p->pArray[i] = Vec_IntEntry(vMap, p->pArray[i]);
+ int k, iFanin, * pFanins, Count = 0, iFaninCrit = -1;
+ Acb_ObjForEachFaninFast( pNtk, iObj, pFanins, iFanin, k )
+ if ( Acb_ObjIsAreaCritical(pNtk, iFanin) )
+ iFaninCrit = iFanin, Count++;
+ if ( Count != 1 )
+ return Count;
+ Acb_ObjForEachFaninFast( pNtk, iFaninCrit, pFanins, iFanin, k )
+ if ( Acb_ObjIsAreaCritical(pNtk, iFanin) )
+ Count++;
+ return Count;
}
-void Acb_WinPrint( Acb_Ntk_t * p, Vec_Int_t * vWin, int Pivot, int nDivs )
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Acb_NtkOptNodeAnalyze( Acb_Mfs_t * p, int PivotVar, int nDivs, int nValues, int * pValues, Vec_Int_t * vSupp )
{
- int i, Node;
- printf( "Window for node %d with %d divisors:\n", Vec_IntEntry(&p->vArray2, Pivot), nDivs );
- Vec_IntForEachEntry( vWin, Node, i )
+ word OnSet[64] = {0};
+ word OffSet[64] = {0};
+ word Diffs[64] = {0};
+ int s, nScope = 1 + 2*nDivs, d, i;
+ int f, nFrames = nValues / nScope;
+ int start = nDivs < 64 ? 0 : nDivs - 64;
+ int stop = nDivs < 64 ? nDivs : 64;
+ assert( nValues % nScope == 0 );
+ assert( nFrames <= 16 );
+ for ( f = 0; f < nFrames; f++ )
{
- if ( i == nDivs )
- printf( " | " );
- if ( Abc_Lit2Var(Node) == Pivot )
- printf( "(%d) ", Vec_IntEntry(&p->vArray2, Pivot) );
- else
- printf( "%s%d ", Abc_LitIsCompl(Node) ? "*":"", Vec_IntEntry(&p->vArray2, Abc_Lit2Var(Node)) );
+ int * pStart = pValues + f * nScope;
+ int * pOnSet = pStart + 1 + (pStart[0] ? 0 : nDivs);
+ int * pOffSet = pStart + 1 + (pStart[0] ? nDivs : 0);
+
+ printf( "%2d:", f );
+ for ( s = start; s < stop; s++ )
+ printf( "%d", pOnSet[s] );
+ printf( "\n" );
+
+ printf( "%2d:", f );
+ for ( s = start; s < stop; s++ )
+ printf( "%d", pOffSet[s] );
+ printf( "\n" );
+
+ for ( s = start; s < stop; s++ )
+ {
+ if ( pOnSet[s] ) OnSet[f] |= (((word)1) << (s-start));
+ if ( pOffSet[s] ) OffSet[f] |= (((word)1) << (s-start));
+ }
+ }
+ d = 0;
+ for ( f = 0; f < nFrames; f++ )
+ for ( s = 0; s < nFrames; s++ )
+ {
+ for ( i = 0; i < d; i++ )
+ if ( Diffs[i] == (OnSet[f] ^ OffSet[s]) )
+ break;
+ if ( i < d )
+ continue;
+ if ( d < 64 )
+ Diffs[d++] = OnSet[f] ^ OffSet[s];
}
- printf( "\n" );
-}
-Vec_Int_t * Acb_NtkFindSupp( Acb_Ntk_t * p, sat_solver * pSat2, int nVars, int nDivs )
-{
- int nSuppNew;
- Vec_Int_t * vSupp = Vec_IntStartNatural( nDivs );
- Vec_IntReverseOrder( vSupp );
- Vec_IntVars2Lits( vSupp, 2*nVars, 0 );
- nSuppNew = sat_solver_minimize_assumptions( pSat2, Vec_IntArray(vSupp), Vec_IntSize(vSupp), 0 );
- Vec_IntShrink( vSupp, nSuppNew );
- Vec_IntLits2Vars( vSupp, -2*nVars );
- return vSupp;
+ printf( "Divisors = %d. Frames = %d. Patterns = %d.\n", nDivs, nFrames, d );
+ printf( " " );
+ for ( s = start; s < stop; s++ )
+ printf( "%d", s / 10 );
+ printf( "\n" );
+ printf( " " );
+ for ( s = start; s < stop; s++ )
+ printf( "%d", s % 10 );
+ printf( "\n" );
+ printf( " " );
+ for ( s = start; s < stop; s++ )
+ printf( "%c", Vec_IntFind(vSupp, s) >= 0 ? 'a' + Vec_IntFind(vSupp, s) : ' ' );
+ printf( "\n" );
+ for ( s = 0; s < d; s++ )
+ {
+ printf( "%2d:", s );
+ for ( f = 0; f < stop; f++ )
+ printf( "%c", ((Diffs[s] >> f) & 1) ? '*' : ' ' );
+ printf( "\n" );
+ }
}
-void Acb_NtkOptNode( Acb_Ntk_t * p, int Pivot, int nTabooMax, int nDivMax, int nTfoLevs, int nFanMax, int nLutSize, int fVerbose )
+int Acb_NtkOptNode( Acb_Mfs_t * p, int Pivot )
{
- Cnf_Dat_t * pCnf;
- Vec_Int_t * vWin, * vSupp = NULL;
- sat_solver * pSat1 = NULL, * pSat2 = NULL, * pSat3 = NULL;
- int c, PivotVar, nDivs = 0; word uTruth;
- int pTaboo[16], nTaboo = Acb_NtkCollectTaboo( p, Pivot, nTabooMax, pTaboo );
- if ( nTaboo == 0 )
- return;
- assert( nTabooMax == 0 || nTaboo <= nTabooMax );
- assert( nTaboo <= 16 );
+ Cnf_Dat_t * pCnf = NULL; abctime clk;
+ Vec_Int_t * vWin = NULL; word uTruth;
+ int Result, PivotVar, nDivs = 0, RetValue = 0, c;
+ assert( Acb_ObjFanoutNum(p->pNtk, Pivot) > 0 );
+ p->nWins++;
// compute divisors and window for this target node with these taboo nodes
- vWin = Acb_NtkWindow( p, Pivot, pTaboo, nTaboo, nDivMax, nTfoLevs, nFanMax, &nDivs );
+ clk = Abc_Clock();
+ vWin = Acb_NtkWindow( p->pNtk, Pivot, p->pPars->nTfiLevMax, p->pPars->nTfoLevMax, p->pPars->nFanoutMax, !p->pPars->fArea, &nDivs );
+ p->nWinsAll += Vec_IntSize(vWin);
+ p->nDivsAll += nDivs;
+ p->timeWin += Abc_Clock() - clk;
PivotVar = Vec_IntFind( vWin, Abc_Var2Lit(Pivot, 0) );
- if ( fVerbose )
- printf( "Node %d: Window contains %d objects and %d divisors. ", Vec_IntEntry(&p->vArray2, Pivot), Vec_IntSize(vWin), nDivs );
-// Acb_WinPrint( p, vWin, Pivot, nDivs );
-// return;
-
- // derive CNF and SAT solvers
- pCnf = Acb_NtkWindow2Cnf( p, vWin, Pivot );
- pSat1 = Acb_NtkWindow2Solver( pCnf, PivotVar, nDivs, 1 );
+ if ( p->pPars->fVerbose )
+ printf( "Node %d: Window contains %d objects and %d divisors. ", Pivot, Vec_IntSize(vWin), nDivs );
+// Acb_WinPrint( p->pNtk, vWin, Pivot, nDivs );
+// Acb_NtkPrintVecWin( p->pNtk, vWin, "Win" );
+ if ( Vec_IntSize(vWin) > p->pPars->nWinNodeMax )
+ {
+ p->nOvers++;
+ if ( p->pPars->fVerbose )
+ printf( "Too many divisors.\n" );
+ goto cleanup;
+ }
+
+ // derive CNF
+ clk = Abc_Clock();
+ pCnf = Acb_NtkWindow2Cnf( p->pNtk, vWin, Pivot );
+ assert( PivotVar == Acb_ObjFunc(p->pNtk, Pivot) );
+ Cnf_DataCollectFlipLits( pCnf, PivotVar, p->vFlip );
+ p->timeCnf += Abc_Clock() - clk;
+
+ // derive SAT solver
+ clk = Abc_Clock();
+ Acb_NtkWindow2Solver( p->pSat[0], pCnf, p->vFlip, PivotVar, nDivs, 1 );
+ p->timeSol += Abc_Clock() - clk;
// check constants
for ( c = 0; c < 2; c++ )
{
int Lit = Abc_Var2Lit( PivotVar, c );
- int status = sat_solver_solve( pSat1, &Lit, &Lit + 1, 0, 0, 0, 0 );
+ int status = sat_solver_solve( p->pSat[0], &Lit, &Lit + 1, 0, 0, 0, 0 );
if ( status == l_False )
{
- if ( fVerbose )
+ p->nChanges[0]++;
+ if ( p->pPars->fVerbose )
printf( "Found constant %d.\n", c );
- Acb_NtkUpdateNode( p, Pivot, c ? ~(word)0 : 0, NULL );
+ Acb_NtkUpdateNode( p->pNtk, Pivot, c ? ~(word)0 : 0, NULL );
+ RetValue = 1;
goto cleanup;
}
assert( status == l_True );
}
- // check for one-node implementation
- pSat2 = Acb_NtkWindow2Solver( pCnf, PivotVar, nDivs, 2 );
- vSupp = Acb_NtkFindSupp( p, pSat2, pCnf->nVars, nDivs );
- if ( Vec_IntSize(vSupp) <= nLutSize )
+ // derive SAT solver
+ clk = Abc_Clock();
+ Acb_NtkWindow2Solver( p->pSat[1], pCnf, p->vFlip, PivotVar, nDivs, 2 );
+ p->timeSol += Abc_Clock() - clk;
+
+ // try to remove useless fanins
+ if ( p->pPars->fArea )
{
- if ( fVerbose )
- printf( "Found %d inputs: ", Vec_IntSize(vSupp) );
- uTruth = Acb_ComputeFunction( pSat1, PivotVar, sat_solver_nvars(pSat1)-1, vSupp );
- if ( fVerbose )
- Extra_PrintHex( stdout, (unsigned *)&uTruth, Vec_IntSize(vSupp) );
- if ( fVerbose )
- printf( "\n" );
- // create support in terms of nodes
- Vec_IntRemap( vSupp, vWin );
- Vec_IntLits2Vars( vSupp, 0 );
- Acb_NtkUpdateNode( p, Pivot, uTruth, vSupp );
- goto cleanup;
+ int fEnableProfile = 0;
+ if ( fEnableProfile )
+ {
+ // alloc
+ if ( p->pSat[1]->user_values.cap == 0 )
+ veci_new(&p->pSat[1]->user_values);
+ else
+ p->pSat[1]->user_values.size = 0;
+ if ( p->pSat[1]->user_vars.cap == 0 )
+ veci_new(&p->pSat[1]->user_vars);
+ else
+ p->pSat[1]->user_vars.size = 0;
+ // set variables
+ veci_push(&p->pSat[1]->user_vars, PivotVar);
+ for ( c = 0; c < nDivs; c++ )
+ veci_push(&p->pSat[1]->user_vars, c);
+ for ( c = 0; c < nDivs; c++ )
+ veci_push(&p->pSat[1]->user_vars, c+pCnf->nVars);
+ }
+
+ // perform solving
+ clk = Abc_Clock();
+ Result = Acb_NtkFindSupp1( p->pNtk, Pivot, p->pSat[1], pCnf->nVars, nDivs, vWin, p->vSupp );
+ p->timeSat += Abc_Clock() - clk;
+ // undo variables
+ p->pSat[1]->user_vars.size = 0;
+ if ( Result )
+ {
+ if ( Vec_IntSize(p->vSupp) == 0 )
+ p->nChanges[0]++;
+ else
+ p->nChanges[1]++;
+ assert( Vec_IntSize(p->vSupp) < p->pPars->nLutSize );
+ if ( p->pPars->fVerbose )
+ printf( "Found %d inputs: ", Vec_IntSize(p->vSupp) );
+ uTruth = Acb_ComputeFunction( p->pSat[0], PivotVar, sat_solver_nvars(p->pSat[0])-1, p->vSupp, 0 );
+ if ( p->pPars->fVerbose )
+ Extra_PrintHex( stdout, (unsigned *)&uTruth, Vec_IntSize(p->vSupp) );
+ if ( p->pPars->fVerbose )
+ printf( "\n" );
+ // create support in terms of nodes
+ Vec_IntRemap( p->vSupp, vWin );
+ Vec_IntLits2Vars( p->vSupp, 0 );
+ Acb_NtkUpdateNode( p->pNtk, Pivot, uTruth, p->vSupp );
+ RetValue = 1;
+ goto cleanup;
+ }
+ if ( fEnableProfile )
+ {
+ // analyze the resulting values
+ Acb_NtkOptNodeAnalyze( p, PivotVar, nDivs, p->pSat[1]->user_values.size, p->pSat[1]->user_values.ptr, p->vSupp );
+ p->pSat[1]->user_values.size = 0;
+ }
+ }
+
+ if ( Acb_NtkObjMffcEstimate(p->pNtk, Pivot) >= 1 )
+ {
+ // check for one-node implementation
+ clk = Abc_Clock();
+ Result = Acb_NtkFindSupp2( p->pNtk, Pivot, p->pSat[1], pCnf->nVars, nDivs, vWin, p->vSupp, p->pPars->nLutSize, !p->pPars->fArea );
+ p->timeSat += Abc_Clock() - clk;
+ if ( Result )
+ {
+ p->nChanges[2]++;
+ assert( Vec_IntSize(p->vSupp) <= p->pPars->nLutSize );
+ if ( p->pPars->fVerbose )
+ printf( "Found %d inputs: ", Vec_IntSize(p->vSupp) );
+ uTruth = Acb_ComputeFunction( p->pSat[0], PivotVar, sat_solver_nvars(p->pSat[0])-1, p->vSupp, 0 );
+ if ( p->pPars->fVerbose )
+ Extra_PrintHex( stdout, (unsigned *)&uTruth, Vec_IntSize(p->vSupp) );
+ if ( p->pPars->fVerbose )
+ printf( "\n" );
+ // create support in terms of nodes
+ Vec_IntRemap( p->vSupp, vWin );
+ Vec_IntLits2Vars( p->vSupp, 0 );
+ Acb_NtkUpdateNode( p->pNtk, Pivot, uTruth, p->vSupp );
+ RetValue = 1;
+ goto cleanup;
+ }
+ }
+
+//#if 0
+ if ( p->pPars->fUseAshen && Acb_NtkObjMffcEstimate(p->pNtk, Pivot) >= 2 )// && Pivot != 70 )
+ {
+ p->nTwoNodes++;
+ // derive SAT solver
+ clk = Abc_Clock();
+ Acb_NtkWindow2Solver( p->pSat[2], pCnf, p->vFlip, PivotVar, nDivs, 6 );
+ p->timeSol += Abc_Clock() - clk;
+
+ // check for two-node implementation
+ clk = Abc_Clock();
+ Result = Acb_NtkFindSupp3( p->pNtk, Pivot, p->pSat[2], pCnf->nVars, nDivs, vWin, p->vSupp, p->pPars->nLutSize, !p->pPars->fArea );
+ p->timeSat += Abc_Clock() - clk;
+ if ( Result )
+ {
+ int fVerbose = 1;
+ int i, k, Lit, Var, Var2, status, NodeNew, fBecameUnsat = 0, fCompl = 0;
+ assert( Result < p->pPars->nLutSize );
+ assert( Vec_IntSize(p->vSupp)-Result <= p->pPars->nLutSize );
+ if ( fVerbose || p->pPars->fVerbose )
+ printf( "Obj %5d: Found %d Hvars and %d Gvars: ", Pivot, Result, Vec_IntSize(p->vSupp)-Result );
+ // p->vSupp contains G variables (Vec_IntSize(p->vSupp)-Result) followed by H variables (Result)
+ //sat_solver_restart( p->pSat[1] );
+ //Acb_NtkWindow2Solver( p->pSat[1], pCnf, p->vFlip, PivotVar, nDivs, 2 );
+
+ // constrain H-variables to be equal
+ Vec_IntForEachEntryStart( p->vSupp, Var, i, Vec_IntSize(p->vSupp)-Result ) // H variables
+ {
+ assert( Var >= 0 && Var < nDivs );
+ assert( Var + 2*pCnf->nVars < sat_solver_nvars(p->pSat[1]) );
+ Lit = Abc_Var2Lit( Var + 2*pCnf->nVars, 0 ); // HVars are the same
+ if ( !sat_solver_addclause( p->pSat[1], &Lit, &Lit + 1 ) )
+ { if ( fVerbose || p->pPars->fVerbose ) printf( "Error: SAT solver became UNSAT at a wrong place (place 2). " ); fBecameUnsat = 1; }
+ }
+ // find one satisfying assighment
+ status = sat_solver_solve( p->pSat[1], NULL, NULL, 0, 0, 0, 0 );
+ assert( status == l_True );
+ // get assignment of the function
+ fCompl = !sat_solver_var_value( p->pSat[1], PivotVar );
+ // constrain second set of G-vars to have values equal to the assignment
+ Vec_IntForEachEntryStop( p->vSupp, Var, i, Vec_IntSize(p->vSupp)-Result ) // G variables
+ {
+ // check if this is a C-var
+ Vec_IntForEachEntryStart( p->vSupp, Var2, k, Vec_IntSize(p->vSupp)-Result ) // G variables
+ if ( Var == Var2 )
+ break;
+ if ( k < Vec_IntSize(p->vSupp) ) // do not constrain a C-var
+ {
+ if ( fVerbose || p->pPars->fVerbose )
+ printf( "Found C-var in object %d. ", Pivot );
+ continue;
+ }
+ assert( Var >= 0 && Var < nDivs );
+ Lit = sat_solver_var_literal( p->pSat[1], Var + pCnf->nVars );
+ if ( !sat_solver_addclause( p->pSat[1], &Lit, &Lit + 1 ) )
+ { if ( fVerbose || p->pPars->fVerbose ) printf( "Error: SAT solver became UNSAT at a wrong place (place 1). " ); fBecameUnsat = 1; }
+ }
+ if ( fBecameUnsat )
+ {
+ StrCount++;
+ if ( fVerbose || p->pPars->fVerbose )
+ printf( " Quitting.\n" );
+ goto cleanup;
+ }
+ // consider only G variables
+ p->vSupp->nSize -= Result;
+ // truth table
+ uTruth = Acb_ComputeFunction( p->pSat[1], PivotVar, sat_solver_nvars(p->pSat[1])-1, p->vSupp, fCompl );
+ if ( fVerbose || p->pPars->fVerbose )
+ Extra_PrintHex( stdout, (unsigned *)&uTruth, Vec_IntSize(p->vSupp) );
+ if ( uTruth == 0 || ~uTruth == 0 )
+ {
+ if ( fVerbose || p->pPars->fVerbose )
+ printf( " Quitting.\n" );
+ goto cleanup;
+ }
+ p->nChanges[3]++;
+ // create new node
+ Vec_IntRemap( p->vSupp, vWin );
+ Vec_IntLits2Vars( p->vSupp, 0 );
+ NodeNew = Acb_NtkCreateNode( p->pNtk, uTruth, p->vSupp );
+ Acb_DeriveCnfForWindowOne( p->pNtk, NodeNew );
+ Acb_DeriveCnfForNode( p->pNtk, NodeNew, p->pSat[0], sat_solver_nvars(p->pSat[0])-2 );
+ p->vSupp->nSize += Result;
+ // collect new variables
+ Vec_IntForEachEntryStart( p->vSupp, Var, i, Vec_IntSize(p->vSupp)-Result )
+ Vec_IntWriteEntry( p->vSupp, i-(Vec_IntSize(p->vSupp)-Result), Var );
+ Vec_IntShrink( p->vSupp, Result );
+ Vec_IntPush( p->vSupp, sat_solver_nvars(p->pSat[0])-2 );
+ // truth table
+ uTruth = Acb_ComputeFunction( p->pSat[0], PivotVar, sat_solver_nvars(p->pSat[0])-1, p->vSupp, 0 );
+ // create new fanins of the node
+ if ( fVerbose || p->pPars->fVerbose )
+ printf( " " );
+ if ( fVerbose || p->pPars->fVerbose )
+ Extra_PrintHex( stdout, (unsigned *)&uTruth, Vec_IntSize(p->vSupp) );
+ if ( fVerbose || p->pPars->fVerbose )
+ printf( "\n" );
+ // create support in terms of nodes
+ Vec_IntPop( p->vSupp );
+ Vec_IntRemap( p->vSupp, vWin );
+ Vec_IntLits2Vars( p->vSupp, 0 );
+ Vec_IntPush( p->vSupp, NodeNew );
+ Acb_NtkUpdateNode( p->pNtk, Pivot, uTruth, p->vSupp );
+ RetValue = 2;
+ goto cleanup;
+ }
}
- if ( fVerbose )
+//#endif
+
+ if ( p->pPars->fVerbose )
printf( "\n" );
cleanup:
- if ( pSat1 ) sat_solver_delete( pSat1 );
- if ( pSat2 ) sat_solver_delete( pSat2 );
- if ( pSat3 ) sat_solver_delete( pSat3 );
- Cnf_DataFree( pCnf );
- Vec_IntFree( vWin );
- Vec_IntFreeP( &vSupp );
+ sat_solver_restart( p->pSat[0] );
+ sat_solver_restart( p->pSat[1] );
+ sat_solver_restart( p->pSat[2] );
+ if ( pCnf )
+ {
+ Cnf_DataFree( pCnf );
+ Acb_NtkWindowUndo( p->pNtk, vWin );
+ }
+ Vec_IntFreeP( &vWin );
+ return RetValue;
}
-
/**Function*************************************************************
Synopsis []
@@ -966,36 +1580,64 @@ cleanup:
SeeAlso []
***********************************************************************/
-void Acb_NtkOpt( Acb_Ntk_t * p, Acb_Par_t * pPars )
-{
- if ( pPars->fVerbose )
- printf( "Performing %s-oriented optimization with DivMax = %d. TfoLev = %d. LutSize = %d.\n",
- pPars->fArea ? "area" : "delay", pPars->nDivMax, pPars->nTfoLevMax, pPars->nLutSize );
- Acb_NtkCreateFanout( p ); // fanout data structure
- Acb_NtkCleanObjFuncs( p ); // SAT variables
- Acb_NtkCleanObjCnfs( p ); // CNF representations
- if ( pPars->fArea )
- {
- int iObj;
- Acb_NtkUpdateLevelD( p, -1 ); // compute forward logic level
- Acb_NtkForEachNode( p, iObj )
- {
- //if ( iObj != 433 )
- // continue;
- Acb_NtkOptNode( p, iObj, pPars->nTabooMax, pPars->nDivMax, pPars->nTfoLevMax, pPars->nFanoutMax, pPars->nLutSize, pPars->fVerbose );
- }
+void Acb_NtkOpt( Acb_Ntk_t * pNtk, Acb_Par_t * pPars )
+{
+ Acb_Mfs_t * pMan = Acb_MfsStart( pNtk, pPars );
+ //if ( pPars->fVerbose )
+ printf( "%s-optimization parameters: TfiLev(I) = %d TfoLev(O) = %d WinMax(W) = %d LutSize = %d\n",
+ pMan->pPars->fArea ? "Area" : "Delay", pMan->pPars->nTfiLevMax, pMan->pPars->nTfoLevMax, pMan->pPars->nWinNodeMax, pMan->pPars->nLutSize );
+ Acb_NtkCreateFanout( pNtk ); // fanout data structure
+ Acb_NtkCleanObjFuncs( pNtk ); // SAT variables
+ Acb_NtkCleanObjCnfs( pNtk ); // CNF representations
+ if ( pMan->pPars->fArea )
+ {
+ int n = 0, iObj, RetValue, nNodes = Acb_NtkObjNumMax(pNtk);
+ Vec_Bit_t * vVisited = Vec_BitStart( Acb_NtkObjNumMax(pNtk) );
+ Acb_NtkUpdateLevelD( pNtk, -1 ); // compute forward logic level
+ for ( n = 2; n >= 0; n-- )
+ Acb_NtkForEachNode( pNtk, iObj )
+ if ( iObj < nNodes && !Vec_BitEntry(vVisited, iObj) && Acb_NtkObjMffcEstimate(pNtk, iObj) >= n )
+ {
+ pMan->nNodes++;
+ //if ( iObj != 7 )
+ // continue;
+ //Acb_NtkOptNode( pMan, iObj );
+ while ( (RetValue = Acb_NtkOptNode(pMan, iObj)) && Acb_ObjFaninNum(pNtk, iObj) );
+ Vec_BitWriteEntry( vVisited, iObj, 1 );
+ }
+ Vec_BitFree( vVisited );
}
else
{
- Acb_NtkUpdateTiming( p, -1 ); // compute delay information
- while ( Vec_QueTopPriority(p->vQue) > 0 )
+ Acb_NtkUpdateTiming( pNtk, -1 ); // compute delay information
+ while ( Vec_QueTopPriority(pNtk->vQue) > 0 )
{
- int iObj = Vec_QuePop(p->vQue);
+ int iObj = Vec_QuePop(pNtk->vQue);
+ if ( !Acb_ObjType(pNtk, iObj) )
+ continue;
//if ( iObj != 28 )
// continue;
- Acb_NtkOptNode( p, iObj, 0, pPars->nDivMax, pPars->nTfoLevMax, pPars->nFanoutMax, pPars->nLutSize, pPars->fVerbose );
+ Acb_NtkOptNode( pMan, iObj );
}
}
+ //if ( pPars->fVerbose )
+ {
+ pMan->timeTotal = Abc_Clock() - pMan->timeTotal;
+ printf( "Node = %d Win = %d (Ave = %d) DivAve = %d Change = %d C = %d N1 = %d N2 = %d N3 = %d Over = %d Str = %d 2Node = %d.\n",
+ pMan->nNodes, pMan->nWins, pMan->nWinsAll/Abc_MaxInt(1, pMan->nWins), pMan->nDivsAll/Abc_MaxInt(1, pMan->nWins),
+ pMan->nChanges[0] + pMan->nChanges[1] + pMan->nChanges[2] + pMan->nChanges[3],
+ pMan->nChanges[0], pMan->nChanges[1], pMan->nChanges[2], pMan->nChanges[3], pMan->nOvers, StrCount, pMan->nTwoNodes );
+ ABC_PRTP( "Windowing ", pMan->timeWin, pMan->timeTotal );
+ ABC_PRTP( "CNF compute", pMan->timeCnf, pMan->timeTotal );
+ ABC_PRTP( "Make solver", pMan->timeSol, pMan->timeTotal );
+ ABC_PRTP( "SAT solving", pMan->timeSat, pMan->timeTotal );
+// ABC_PRTP( " unsat ", pMan->timeSatU, pMan->timeTotal );
+// ABC_PRTP( " sat ", pMan->timeSatS, pMan->timeTotal );
+ ABC_PRTP( "TOTAL ", pMan->timeTotal, pMan->timeTotal );
+ fflush( stdout );
+ }
+ Acb_MfsStop( pMan );
+ StrCount = 0;
}
////////////////////////////////////////////////////////////////////////
diff --git a/src/base/acb/acbPar.h b/src/base/acb/acbPar.h
index 4855170c..a3c21e47 100644
--- a/src/base/acb/acbPar.h
+++ b/src/base/acb/acbPar.h
@@ -42,11 +42,11 @@ struct Acb_Par_t_
int nTfoLevMax; // the maximum fanout levels
int nTfiLevMax; // the maximum fanin levels
int nFanoutMax; // the maximum number of fanouts
- int nDivMax; // the maximum divisor count
- int nTabooMax; // the minimum MFFC size
+ int nWinNodeMax; // the maximum number of nodes in the window
int nGrowthLevel; // the maximum allowed growth in level
int nBTLimit; // the maximum number of conflicts in one SAT run
int nNodesMax; // the maximum number of nodes to try
+ int fUseAshen; // user Ashenhurst decomposition
int iNodeOne; // one particular node to try
int fArea; // performs optimization for area
int fMoreEffort; // performs high-affort minimization
diff --git a/src/base/acb/acbUtil.c b/src/base/acb/acbUtil.c
index cc8b9f11..4b839ec2 100644
--- a/src/base/acb/acbUtil.c
+++ b/src/base/acb/acbUtil.c
@@ -133,13 +133,14 @@ int Acb_NtkComputeLevelR( Acb_Ntk_t * p, Vec_Int_t * vTfi )
{
// it is assumed that vTfi contains CI nodes
int i, iObj, Level = 0;
- if ( !Acb_NtkHasObjLevelD( p ) )
- Acb_NtkCleanObjLevelD( p );
+ if ( !Acb_NtkHasObjLevelR( p ) )
+ Acb_NtkCleanObjLevelR( p );
Vec_IntForEachEntryReverse( vTfi, iObj, i )
Acb_ObjComputeLevelR( p, iObj );
Acb_NtkForEachCi( p, iObj, i )
Level = Abc_MaxInt( Level, Acb_ObjLevelR(p, iObj) );
- assert( p->LevelMax == Level );
+// assert( p->LevelMax == Level );
+ p->LevelMax = Level;
return Level;
}
@@ -176,16 +177,38 @@ int Acb_ObjComputePathD( Acb_Ntk_t * p, int iObj )
Path += Acb_ObjPathD(p, iFanin);
return Acb_ObjSetPathD( p, iObj, Path );
}
-int Acb_NtkComputePathsD( Acb_Ntk_t * p, Vec_Int_t * vTfo )
+int Acb_NtkComputePathsD( Acb_Ntk_t * p, Vec_Int_t * vTfo, int fReverse )
{
int i, iObj, Path = 0;
- // it is assumed that vTfo contains CO nodes
+ //Vec_IntPrint( vTfo );
+ if ( !Acb_NtkHasObjPathD( p ) )
+ Acb_NtkCleanObjPathD( p );
+ // it is assumed that vTfo contains CI nodes
//assert( Acb_ObjSlack(p, Vec_IntEntry(vTfo, 0)) );
- Vec_IntForEachEntryReverse( vTfo, iObj, i )
- if ( !Acb_ObjSlack(p, iObj) )
- Acb_ObjComputePathD( p, iObj );
- else
- Acb_ObjSetPathD( p, iObj, 0 );
+ if ( fReverse )
+ {
+ Vec_IntForEachEntryReverse( vTfo, iObj, i )
+ {
+ if ( Acb_ObjIsCi(p, iObj) )
+ Acb_ObjSetPathD( p, iObj, Acb_ObjSlack(p, iObj) == 0 );
+ else if ( Acb_ObjSlack(p, iObj) )
+ Acb_ObjSetPathD( p, iObj, 0 );
+ else
+ Acb_ObjComputePathD( p, iObj );
+ }
+ }
+ else
+ {
+ Vec_IntForEachEntry( vTfo, iObj, i )
+ {
+ if ( Acb_ObjIsCi(p, iObj) )
+ Acb_ObjSetPathD( p, iObj, Acb_ObjSlack(p, iObj) == 0 );
+ else if ( Acb_ObjSlack(p, iObj) )
+ Acb_ObjSetPathD( p, iObj, 0 );
+ else
+ Acb_ObjComputePathD( p, iObj );
+ }
+ }
Acb_NtkForEachCo( p, iObj, i )
Path += Acb_ObjPathD(p, iObj);
p->nPaths = Path;
@@ -201,30 +224,69 @@ int Acb_ObjComputePathR( Acb_Ntk_t * p, int iObj )
Path += Acb_ObjPathR(p, iFanout);
return Acb_ObjSetPathR( p, iObj, Path );
}
-int Acb_NtkComputePathsR( Acb_Ntk_t * p, Vec_Int_t * vTfi )
+int Acb_NtkComputePathsR( Acb_Ntk_t * p, Vec_Int_t * vTfi, int fReverse )
{
int i, iObj, Path = 0;
- // it is assumed that vTfi contains CI nodes
+ if ( !Acb_NtkHasObjPathR( p ) )
+ Acb_NtkCleanObjPathR( p );
+ // it is assumed that vTfi contains CO nodes
//assert( Acb_ObjSlack(p, Vec_IntEntry(vTfi, 0)) );
- Vec_IntForEachEntryReverse( vTfi, iObj, i )
- if ( !Acb_ObjSlack(p, iObj) )
- Acb_ObjComputePathR( p, iObj );
- else
- Acb_ObjSetPathR( p, iObj, 0 );
+ if ( fReverse )
+ {
+ Vec_IntForEachEntryReverse( vTfi, iObj, i )
+ {
+ if ( Acb_ObjIsCo(p, iObj) )
+ Acb_ObjSetPathR( p, iObj, Acb_ObjSlack(p, iObj) == 0 );
+ else if ( Acb_ObjSlack(p, iObj) )
+ Acb_ObjSetPathR( p, iObj, 0 );
+ else
+ Acb_ObjComputePathR( p, iObj );
+ }
+ }
+ else
+ {
+ Vec_IntForEachEntry( vTfi, iObj, i )
+ {
+ if ( Acb_ObjIsCo(p, iObj) )
+ Acb_ObjSetPathR( p, iObj, Acb_ObjSlack(p, iObj) == 0 );
+ else if ( Acb_ObjSlack(p, iObj) )
+ Acb_ObjSetPathR( p, iObj, 0 );
+ else
+ Acb_ObjComputePathR( p, iObj );
+ }
+ }
Acb_NtkForEachCi( p, iObj, i )
Path += Acb_ObjPathR(p, iObj);
- assert( p->nPaths == Path );
+// assert( p->nPaths == Path );
+ p->nPaths = Path;
return Path;
}
+void Acb_NtkPrintPaths( Acb_Ntk_t * p )
+{
+ int iObj;
+ Acb_NtkForEachObj( p, iObj )
+ {
+ printf( "Obj = %5d : ", iObj );
+ printf( "PathD = %5d ", Acb_ObjPathD(p, iObj) );
+ printf( "PathR = %5d ", Acb_ObjPathR(p, iObj) );
+ printf( "Paths = %5d ", Acb_ObjPathD(p, iObj) + Acb_ObjPathR(p, iObj) );
+ printf( "\n" );
+ }
+}
+
int Acb_NtkComputePaths( Acb_Ntk_t * p )
{
+ int LevelD, LevelR;
Vec_Int_t * vTfi = Acb_ObjCollectTfi( p, -1, 1 );
Vec_Int_t * vTfo = Acb_ObjCollectTfo( p, -1, 1 );
- Acb_NtkComputeLevelD( p, vTfi );
- Acb_NtkComputeLevelR( p, vTfo );
- Acb_NtkComputePathsD( p, vTfi );
- Acb_NtkComputePathsR( p, vTfo );
+ Acb_NtkComputeLevelD( p, vTfo );
+ LevelD = p->LevelMax;
+ Acb_NtkComputeLevelR( p, vTfi );
+ LevelR = p->LevelMax;
+ assert( LevelD == LevelR );
+ Acb_NtkComputePathsD( p, vTfo, 1 );
+ Acb_NtkComputePathsR( p, vTfi, 1 );
return p->nPaths;
}
void Abc_NtkComputePaths( Abc_Ntk_t * p )
@@ -232,7 +294,9 @@ void Abc_NtkComputePaths( Abc_Ntk_t * p )
extern Acb_Ntk_t * Acb_NtkFromAbc( Abc_Ntk_t * p );
Acb_Ntk_t * pNtk = Acb_NtkFromAbc( p );
Acb_NtkCreateFanout( pNtk );
+ Acb_NtkCleanObjCounts( pNtk );
printf( "Computed %d paths.\n", Acb_NtkComputePaths(pNtk) );
+ Acb_NtkPrintPaths( pNtk );
Acb_ManFree( pNtk->pDesign );
}
@@ -251,6 +315,8 @@ void Abc_NtkComputePaths( Abc_Ntk_t * p )
void Acb_ObjUpdatePriority( Acb_Ntk_t * p, int iObj )
{
int nPaths;
+ if ( Acb_ObjIsCio(p, iObj) || Acb_ObjLevelD(p, iObj) == 1 )
+ return;
if ( p->vQue == NULL )
{
Acb_NtkCleanObjCounts( p );
@@ -258,35 +324,63 @@ void Acb_ObjUpdatePriority( Acb_Ntk_t * p, int iObj )
Vec_QueSetPriority( p->vQue, Vec_FltArrayP(&p->vCounts) );
}
nPaths = Acb_ObjPathD(p, iObj) + Acb_ObjPathR(p, iObj);
- if ( nPaths == 0 )
- return;
Acb_ObjSetCounts( p, iObj, (float)nPaths );
if ( Vec_QueIsMember( p->vQue, iObj ) )
+ {
+//printf( "Updating object %d with count %d\n", iObj, nPaths );
Vec_QueUpdate( p->vQue, iObj );
- else
+ }
+ else if ( nPaths )
+ {
+//printf( "Adding object %d with count %d\n", iObj, nPaths );
Vec_QuePush( p->vQue, iObj );
+ }
}
void Acb_NtkUpdateTiming( Acb_Ntk_t * p, int iObj )
{
int i, Entry, LevelMax = p->LevelMax;
- // assuming that level of the new nodes is up to date
+ int LevelD, LevelR, nPaths1, nPaths2;
+ // assuming that direct level of the new nodes (including iObj) is up to date
Vec_Int_t * vTfi = Acb_ObjCollectTfi( p, iObj, 1 );
Vec_Int_t * vTfo = Acb_ObjCollectTfo( p, iObj, 1 );
+ if ( iObj > 0 )
+ {
+ assert( Vec_IntEntryLast(vTfi) == iObj );
+ assert( Vec_IntEntryLast(vTfo) == iObj );
+ Vec_IntPop( vTfo );
+ }
Acb_NtkComputeLevelD( p, vTfo );
+ LevelD = p->LevelMax;
Acb_NtkComputeLevelR( p, vTfi );
+ LevelR = p->LevelMax;
+ assert( LevelD == LevelR );
if ( iObj > 0 && LevelMax > p->LevelMax ) // reduced level
{
+ iObj = -1;
vTfi = Acb_ObjCollectTfi( p, -1, 1 );
vTfo = Acb_ObjCollectTfo( p, -1, 1 );
Vec_QueClear( p->vQue );
// add backup here
}
- Acb_NtkComputePathsD( p, vTfo );
- Acb_NtkComputePathsR( p, vTfi );
+ if ( iObj > 0 )
+ Acb_NtkComputePathsD( p, vTfi, 0 );
+ Acb_NtkComputePathsD( p, vTfo, 1 );
+ nPaths1 = p->nPaths;
+ if ( iObj > 0 )
+ Acb_NtkComputePathsR( p, vTfo, 0 );
+ Acb_NtkComputePathsR( p, vTfi, 1 );
+ nPaths2 = p->nPaths;
+ assert( nPaths1 == nPaths2 );
Vec_IntForEachEntry( vTfi, Entry, i )
Acb_ObjUpdatePriority( p, Entry );
+ if ( iObj > 0 )
Vec_IntForEachEntry( vTfo, Entry, i )
Acb_ObjUpdatePriority( p, Entry );
+
+// printf( "Updating timing for object %d.\n", iObj );
+// Acb_NtkPrintPaths( p );
+// while ( (Entry = (int)Vec_QueTopPriority(p->vQue)) > 0 )
+// printf( "Obj = %5d : Prio = %d.\n", Vec_QuePop(p->vQue), Entry );
}
/**Function*************************************************************
@@ -300,22 +394,48 @@ void Acb_NtkUpdateTiming( Acb_Ntk_t * p, int iObj )
SeeAlso []
***********************************************************************/
-void Acb_NtkCreateNode( Acb_Ntk_t * p, word uTruth, Vec_Int_t * vSupp )
+int Acb_NtkCreateNode( Acb_Ntk_t * p, word uTruth, Vec_Int_t * vSupp )
{
int Pivot = Acb_ObjAlloc( p, ABC_OPER_LUT, Vec_IntSize(vSupp), 0 );
Acb_ObjSetTruth( p, Pivot, uTruth );
Acb_ObjAddFanins( p, Pivot, vSupp );
Acb_ObjAddFaninFanout( p, Pivot );
Acb_ObjComputeLevelD( p, Pivot );
+ return Pivot;
}
-void Acb_NtkUpdateNode( Acb_Ntk_t * p, int Pivot, word uTruth, Vec_Int_t * vSupp )
+void Acb_NtkResetNode( Acb_Ntk_t * p, int Pivot, word uTruth, Vec_Int_t * vSupp )
{
+ // remember old fanins
+ int k, iFanin, * pFanins;
+ Vec_Int_t * vFanins = Vec_IntAlloc( 6 );
+ assert( !Acb_ObjIsCio(p, Pivot) );
+ Acb_ObjForEachFaninFast( p, Pivot, pFanins, iFanin, k )
+ Vec_IntPush( vFanins, iFanin );
+ // update function
Vec_WrdSetEntry( &p->vObjTruth, Pivot, uTruth );
Vec_IntErase( Vec_WecEntry(&p->vCnfs, Pivot) );
+ // remove old fanins
Acb_ObjRemoveFaninFanout( p, Pivot );
Acb_ObjRemoveFanins( p, Pivot );
- Acb_ObjAddFanins( p, Pivot, vSupp );
- Acb_ObjAddFaninFanout( p, Pivot );
+ // add new fanins
+ if ( vSupp != NULL )
+ {
+ assert( Acb_ObjFanoutNum(p, Pivot) > 0 );
+ Acb_ObjAddFanins( p, Pivot, vSupp );
+ Acb_ObjAddFaninFanout( p, Pivot );
+ }
+ else if ( Acb_ObjFanoutNum(p, Pivot) == 0 )
+ Acb_ObjCleanType( p, Pivot );
+ // delete dangling fanins
+ Vec_IntForEachEntry( vFanins, iFanin, k )
+ if ( !Acb_ObjIsCio(p, iFanin) && Acb_ObjFanoutNum(p, iFanin) == 0 )
+ Acb_NtkResetNode( p, iFanin, 0, NULL );
+ Vec_IntFree( vFanins );
+}
+void Acb_NtkUpdateNode( Acb_Ntk_t * p, int Pivot, word uTruth, Vec_Int_t * vSupp )
+{
+ Acb_NtkResetNode( p, Pivot, uTruth, vSupp );
+ Acb_ObjComputeLevelD( p, Pivot );
if ( p->vQue == NULL )
Acb_NtkUpdateLevelD( p, Pivot );
else
diff --git a/src/misc/vec/vecHsh.h b/src/misc/vec/vecHsh.h
index 52289231..de9a038a 100644
--- a/src/misc/vec/vecHsh.h
+++ b/src/misc/vec/vecHsh.h
@@ -124,6 +124,10 @@ static inline void Hsh_IntManStop( Hsh_IntMan_t * p )
Vec_WrdFree( p->vObjs );
ABC_FREE( p );
}
+static inline int Hsh_IntManEntryNum( Hsh_IntMan_t * p )
+{
+ return Vec_WrdSize(p->vObjs);
+}
/**Function*************************************************************
@@ -164,7 +168,7 @@ static inline int Hsh_IntManAdd( Hsh_IntMan_t * p, int iData )
Vec_IntFill( p->vTable, Abc_PrimeCudd(2*Vec_IntSize(p->vTable)), -1 );
for ( i = 0; i < Vec_WrdSize(p->vObjs); i++ )
{
- pPlace = Vec_IntEntryP( p->vTable, Hsh_IntManHash(Hsh_IntData(p, i), p->nSize, Vec_IntSize(p->vTable)) );
+ pPlace = Vec_IntEntryP( p->vTable, Hsh_IntManHash(Hsh_IntData(p, Hsh_IntObj(p, i)->iData), p->nSize, Vec_IntSize(p->vTable)) );
Hsh_IntObj(p, i)->iNext = *pPlace; *pPlace = i;
}
}
diff --git a/src/opt/sfm/sfmCore.c b/src/opt/sfm/sfmCore.c
index 7d9db709..48019c15 100644
--- a/src/opt/sfm/sfmCore.c
+++ b/src/opt/sfm/sfmCore.c
@@ -73,8 +73,8 @@ void Sfm_ParSetDefault( Sfm_Par_t * pPars )
void Sfm_NtkPrintStats( Sfm_Ntk_t * p )
{
p->timeOther = p->timeTotal - p->timeWin - p->timeDiv - p->timeCnf - p->timeSat;
- printf( "Nodes = %d. Try = %d. Resub = %d. Div = %d. SAT calls = %d. Timeouts = %d. MaxDivs = %d.\n",
- Sfm_NtkNodeNum(p), p->nNodesTried, p->nRemoves + p->nResubs, p->nTotalDivs, p->nSatCalls, p->nTimeOuts, p->nMaxDivs );
+ printf( "Nodes = %d. Try = %d. Resub = %d. Div = %d (ave = %d). SAT calls = %d. Timeouts = %d. MaxDivs = %d.\n",
+ Sfm_NtkNodeNum(p), p->nNodesTried, p->nRemoves + p->nResubs, p->nTotalDivs, p->nTotalDivs/Abc_MaxInt(1, p->nNodesTried), p->nSatCalls, p->nTimeOuts, p->nMaxDivs );
printf( "Attempts : " );
printf( "Remove %6d out of %6d (%6.2f %%) ", p->nRemoves, p->nTryRemoves, 100.0*p->nRemoves/Abc_MaxInt(1, p->nTryRemoves) );
diff --git a/src/sat/bsat/satSolver.c b/src/sat/bsat/satSolver.c
index 787626d6..673a6b66 100644
--- a/src/sat/bsat/satSolver.c
+++ b/src/sat/bsat/satSolver.c
@@ -1334,6 +1334,9 @@ void sat_solver_delete(sat_solver* s)
veci_delete(&s->temp_clause);
veci_delete(&s->conf_final);
+ veci_delete(&s->user_vars);
+ veci_delete(&s->user_values);
+
// delete arrays
if (s->reasons != 0){
int i;
@@ -1963,6 +1966,13 @@ int sat_solver_solve_internal(sat_solver* s)
printf("==============================================================================\n");
sat_solver_canceluntil(s,s->root_level);
+ // save variable values
+ if ( status == l_True && s->user_vars.size )
+ {
+ int v;
+ for ( v = 0; v < s->user_vars.size; v++ )
+ veci_push(&s->user_values, sat_solver_var_value(s, s->user_vars.ptr[v]));
+ }
return status;
}
@@ -2186,6 +2196,7 @@ int sat_solver_minimize_assumptions( sat_solver* s, int * pLits, int nLits, int
s->nConfLimit = nConfLimit;
status = sat_solver_solve_internal( s );
s->nConfLimit = Temp;
+ //printf( "%c", status == l_False ? 'u' : 's' );
return (int)(status != l_False); // return 1 if the problem is not UNSAT
}
assert( nLits >= 2 );
diff --git a/src/sat/bsat/satSolver.h b/src/sat/bsat/satSolver.h
index e8a350ca..6ec437f7 100644
--- a/src/sat/bsat/satSolver.h
+++ b/src/sat/bsat/satSolver.h
@@ -193,6 +193,10 @@ struct sat_solver_t
veci temp_clause; // temporary storage for a CNF clause
+ // assignment storage
+ veci user_vars; // variable IDs
+ veci user_values; // values of these variables
+
// CNF loading
void * pCnfMan; // external CNF manager
int(*pCnfFunc)(void * p, int); // external callback
diff --git a/src/sat/bsat/satUtil.c b/src/sat/bsat/satUtil.c
index 1d94d685..a8cd3f7e 100644
--- a/src/sat/bsat/satUtil.c
+++ b/src/sat/bsat/satUtil.c
@@ -85,7 +85,7 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumpBegin,
nUnits++;
// start the file
- pFile = fopen( pFileName, "wb" );
+ pFile = pFileName ? fopen( pFileName, "wb" ) : stdout;
if ( pFile == NULL )
{
printf( "Sat_SolverWriteDimacs(): Cannot open the ouput file.\n" );
@@ -121,7 +121,7 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumpBegin,
}
fprintf( pFile, "\n" );
- fclose( pFile );
+ if ( pFileName ) fclose( pFile );
}
void Sat_Solver2WriteDimacs( sat_solver2 * p, char * pFileName, lit* assumpBegin, lit* assumpEnd, int incrementVars )
{
diff --git a/src/sat/cnf/cnf.h b/src/sat/cnf/cnf.h
index 6c6cbeb3..01728c81 100644
--- a/src/sat/cnf/cnf.h
+++ b/src/sat/cnf/cnf.h
@@ -156,7 +156,7 @@ extern Cnf_Dat_t * Cnf_DataAlloc( Aig_Man_t * pAig, int nVars, int nClauses,
extern Cnf_Dat_t * Cnf_DataDup( Cnf_Dat_t * p );
extern void Cnf_DataFree( Cnf_Dat_t * p );
extern void Cnf_DataLift( Cnf_Dat_t * p, int nVarsPlus );
-extern Vec_Int_t * Cnf_DataCollectFlipLits( Cnf_Dat_t * p, int iFlipVar );
+extern void Cnf_DataCollectFlipLits( Cnf_Dat_t * p, int iFlipVar, Vec_Int_t * vFlips );
extern void Cnf_DataLiftAndFlipLits( Cnf_Dat_t * p, int nVarsPlus, Vec_Int_t * vLits );
extern void Cnf_DataPrint( Cnf_Dat_t * p, int fReadable );
extern void Cnf_DataWriteIntoFile( Cnf_Dat_t * p, char * pFileName, int fReadable, Vec_Int_t * vForAlls, Vec_Int_t * vExists );
diff --git a/src/sat/cnf/cnfMan.c b/src/sat/cnf/cnfMan.c
index d3a8aa9c..5a125ec3 100644
--- a/src/sat/cnf/cnfMan.c
+++ b/src/sat/cnf/cnfMan.c
@@ -215,14 +215,14 @@ void Cnf_DataLift( Cnf_Dat_t * p, int nVarsPlus )
for ( v = 0; v < p->nLiterals; v++ )
p->pClauses[0][v] += 2*nVarsPlus;
}
-Vec_Int_t * Cnf_DataCollectFlipLits( Cnf_Dat_t * p, int iFlipVar )
+void Cnf_DataCollectFlipLits( Cnf_Dat_t * p, int iFlipVar, Vec_Int_t * vFlips )
{
- Vec_Int_t * vLits = Vec_IntAlloc( 100 ); int v;
+ int v;
assert( p->pMan == NULL );
+ Vec_IntClear( vFlips );
for ( v = 0; v < p->nLiterals; v++ )
if ( Abc_Lit2Var(p->pClauses[0][v]) == iFlipVar )
- Vec_IntPush( vLits, v );
- return vLits;
+ Vec_IntPush( vFlips, v );
}
void Cnf_DataLiftAndFlipLits( Cnf_Dat_t * p, int nVarsPlus, Vec_Int_t * vLits )
{