diff options
author | Yen-Sheng Ho <ysho@berkeley.edu> | 2017-04-06 14:18:50 -0700 |
---|---|---|
committer | Yen-Sheng Ho <ysho@berkeley.edu> | 2017-04-06 14:18:50 -0700 |
commit | 72c23923da38d9e06b4a57816704fe1c0d37a2c4 (patch) | |
tree | 241b6111a7c72d18db73c58c7028da5c8b94802e /src/base | |
parent | 2761e5e35bdcb8591ccc445b907af95bd0b16357 (diff) | |
parent | efe5d1476af9e99c7a246d6d4de91abbc4274359 (diff) | |
download | abc-72c23923da38d9e06b4a57816704fe1c0d37a2c4.tar.gz abc-72c23923da38d9e06b4a57816704fe1c0d37a2c4.tar.bz2 abc-72c23923da38d9e06b4a57816704fe1c0d37a2c4.zip |
merge
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/abci/abc.c | 42 | ||||
-rw-r--r-- | src/base/acb/acb.h | 9 | ||||
-rw-r--r-- | src/base/acb/acbAbc.c | 55 | ||||
-rw-r--r-- | src/base/acb/acbMfs.c | 1272 | ||||
-rw-r--r-- | src/base/acb/acbPar.h | 4 | ||||
-rw-r--r-- | src/base/acb/acbUtil.c | 184 |
6 files changed, 1182 insertions, 384 deletions
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 |