37 int Abc_NtkBddToMuxesPerformGlo(
Abc_Ntk_t * pNtk,
Abc_Ntk_t * pNtkNew,
int Limit,
int fReorder,
int fUseAdd );
41static DdNode * Abc_NodeGlobalBdds_rec( DdManager * dd,
Abc_Obj_t * pNode,
int nBddSizeMax,
int fDropInternal,
ProgressBar * pProgress,
int * pCounter,
int fVerbose );
65 DdManager * dd = (DdManager *)dd0;
69 DdNode * bSupp, * bTemp;
74 if ( pNamePo == NULL )
76 if ( vNamesPi == NULL )
79 vNamesPi = vNamesPiFake;
84 bSupp = Cudd_Support( dd, (DdNode *)bFunc ); Cudd_Ref( bSupp );
85 for ( bTemp = bSupp; bTemp != Cudd_ReadOne(dd); bTemp = cuddT(bTemp) )
86 if ( (
int)Cudd_NodeReadIndex(bTemp) >= Vec_PtrSize(vNamesPi) )
88 Cudd_RecursiveDeref( dd, bSupp );
89 if ( bTemp != Cudd_ReadOne(dd) )
96 Cudd_bddIthVar( (DdManager *)pNtk->
pManFunc, Vec_PtrSize(vNamesPi) );
101 pNode = Abc_NtkCreateNode( pNtk );
102 pNode->
pData = (DdNode *)Cudd_bddTransfer( dd, (DdManager *)pNtk->
pManFunc, (DdNode *)bFunc ); Cudd_Ref((DdNode *)pNode->
pData);
106 pNodePo = Abc_NtkCreatePo( pNtk );
114 fprintf( stdout,
"Abc_NtkDeriveFromBdd(): Network check has failed.\n" );
138 if ( !Abc_NtkBddToMuxesPerformGlo( pNtk, pNtkNew, Limit, 0, fUseAdd ) )
146 Abc_NtkBddToMuxesPerform( pNtk, pNtkNew );
152 printf(
"Abc_NtkBddToMuxes: The network check has failed.\n" );
176 assert( Abc_NtkIsBddLogic(pNtk) );
182 Extra_ProgressBarUpdate( pProgress, i, NULL );
184 assert( Abc_ObjIsNode(pNode) );
185 pNodeNew = Abc_NodeBddToMuxes( pNode, pNtkNew );
188 pNode->
pCopy = pNodeNew;
190 Vec_PtrFree( vNodes );
208 DdNode * bFunc = (DdNode *)pNodeOld->pData;
216 st__insert( tBdd2Node, (
char *)Cudd_bddIthVar(dd, i), (
char *)pFaninOld->
pCopy );
218 pNodeNew = Abc_NodeBddToMuxes_rec( dd, Cudd_Regular(bFunc), pNtkNew, tBdd2Node );
220 if ( Cudd_IsComplement(bFunc) )
238 Abc_Obj_t * pNodeNew, * pNodeNew0, * pNodeNew1, * pNodeNewC;
239 assert( !Cudd_IsComplement(bFunc) );
245 if (
st__lookup( tBdd2Node, (
char *)bFunc, (
char **)&pNodeNew ) )
248 pNodeNew0 = Abc_NodeBddToMuxes_rec( dd, Cudd_Regular(cuddE(bFunc)), pNtkNew, tBdd2Node );
249 if ( Cudd_IsComplement(cuddE(bFunc)) )
251 pNodeNew1 = Abc_NodeBddToMuxes_rec( dd, cuddT(bFunc), pNtkNew, tBdd2Node );
252 if ( !
st__lookup( tBdd2Node, (
char *)Cudd_bddIthVar(dd, bFunc->index), (
char **)&pNodeNewC ) )
256 st__insert( tBdd2Node, (
char *)bFunc, (
char *)pNodeNew );
271int Abc_NtkBddToMuxesPerformGlo(
Abc_Ntk_t * pNtk,
Abc_Ntk_t * pNtkNew,
int Limit,
int fReorder,
int fUseAdd )
274 Vec_Ptr_t * vAdds = fUseAdd ? Vec_PtrAlloc(100) : NULL;
277 assert( Abc_NtkIsStrash(pNtk) );
281 printf(
"Construction of global BDDs has failed.\n" );
288 st__insert( tBdd2Node, (
char *)Cudd_bddIthVar(dd, i), (
char *)pObjNew );
293 DdNode * bFunc = (DdNode *)Abc_ObjGlobalBdd(pObj);
296 DdNode * aFunc = Cudd_BddToAdd( dd, bFunc ); Cudd_Ref( aFunc );
297 pObjNew = Abc_NodeBddToMuxes_rec( dd, aFunc, pNtkNew, tBdd2Node );
298 Vec_PtrPush( vAdds, aFunc );
302 pObjNew = Abc_NodeBddToMuxes_rec( dd, Cudd_Regular(bFunc), pNtkNew, tBdd2Node );
303 if ( Cudd_IsComplement(bFunc) )
316 Cudd_RecursiveDeref( dd, aTemp );
317 Vec_PtrFree( vAdds );
348 assert( Abc_NtkGlobalBdd(pNtk) == NULL );
349 dd = Cudd_Init( Abc_NtkCiNum(pNtk), 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
350 pAttMan = Vec_AttAlloc( Abc_NtkObjNumMax(pNtk) + 1, dd, (
void (*)(
void*))
Extra_StopManager, NULL, (
void (*)(
void*,
void*))Cudd_RecursiveDeref );
355 Cudd_AutodynEnable( dd, CUDD_REORDER_SYMM_SIFT );
359 if ( Abc_ObjFanoutNum(pObj) > 0 )
362 Abc_ObjSetGlobalBdd( pObj, bFunc ); Cudd_Ref( bFunc );
366 if ( Abc_ObjFanoutNum(pObj) > 0 )
368 bFunc = fReverse ? dd->vars[Abc_NtkCiNum(pNtk) - 1 - i] : dd->vars[i];
369 Abc_ObjSetGlobalBdd( pObj, bFunc ); Cudd_Ref( bFunc );
378 bFunc = Abc_NodeGlobalBdds_rec( dd, Abc_ObjFanin0(pObj), nBddSizeMax, fDropInternal, pProgress, &Counter, fVerbose );
382 printf(
"Constructing global BDDs is aborted.\n" );
388 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBi(pObj) )
391 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBo(pObj) )
396 bFunc = Cudd_NotCond( bFunc, (
int)Abc_ObjFaninC0(pObj) ); Cudd_Ref( bFunc );
397 Abc_ObjSetGlobalBdd( pObj, bFunc );
422 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBi(pObj) )
425 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBo(pObj) )
432 Cudd_ReduceHeap( dd, CUDD_REORDER_SYMM_SIFT, 1 );
434 Cudd_AutodynDisable( dd );
437 Cudd_PrintInfo( dd, stdout );
452DdNode * Abc_NodeGlobalBdds_rec( DdManager * dd,
Abc_Obj_t * pNode,
int nBddSizeMax,
int fDropInternal,
ProgressBar * pProgress,
int * pCounter,
int fVerbose )
454 DdNode * bFunc, * bFunc0, * bFunc1, * bFuncC;
455 int fDetectMuxes = 0;
456 assert( !Abc_ObjIsComplement(pNode) );
457 if ( Cudd_ReadKeys(dd)-Cudd_ReadDead(dd) > (
unsigned)nBddSizeMax )
461 printf(
"The number of live nodes reached %d.\n", nBddSizeMax );
466 if ( Abc_ObjGlobalBdd(pNode) == NULL )
469 pNode0 = Abc_ObjFanin0(pNode);
470 pNode1 = Abc_ObjFanin1(pNode);
473 Abc_ObjGlobalBdd(pNode0) == NULL && Abc_ObjGlobalBdd(pNode1) == NULL &&
474 Abc_ObjIsNode(pNode0) && Abc_ObjFanoutNum(pNode0) == 1 &&
475 Abc_ObjIsNode(pNode1) && Abc_ObjFanoutNum(pNode1) == 1 &&
483 assert( Abc_ObjFanoutNum(pNodeC) > 1 );
488 bFuncC = Abc_NodeGlobalBdds_rec( dd, pNodeC, nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
489 if ( bFuncC == NULL )
492 bFunc0 = Abc_NodeGlobalBdds_rec( dd, Abc_ObjRegular(pNode0), nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
493 if ( bFunc0 == NULL )
496 bFunc1 = Abc_NodeGlobalBdds_rec( dd, Abc_ObjRegular(pNode1), nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
497 if ( bFunc1 == NULL )
502 bFunc0 = Cudd_NotCond( bFunc0, (
int)Abc_ObjIsComplement(pNode0) );
503 bFunc1 = Cudd_NotCond( bFunc1, (
int)Abc_ObjIsComplement(pNode1) );
505 bFunc = Cudd_bddIte( dd, bFuncC, bFunc1, bFunc0 ); Cudd_Ref( bFunc );
506 Cudd_RecursiveDeref( dd, bFunc0 );
507 Cudd_RecursiveDeref( dd, bFunc1 );
508 Cudd_RecursiveDeref( dd, bFuncC );
515 bFunc0 = Abc_NodeGlobalBdds_rec( dd, Abc_ObjFanin(pNode,0), nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
516 if ( bFunc0 == NULL )
519 bFunc1 = Abc_NodeGlobalBdds_rec( dd, Abc_ObjFanin(pNode,1), nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
520 if ( bFunc1 == NULL )
523 bFunc0 = Cudd_NotCond( bFunc0, (
int)Abc_ObjFaninC0(pNode) );
524 bFunc1 = Cudd_NotCond( bFunc1, (
int)Abc_ObjFaninC1(pNode) );
526 bFunc = Cudd_bddAndLimit( dd, bFunc0, bFunc1, nBddSizeMax );
530 Cudd_RecursiveDeref( dd, bFunc0 );
531 Cudd_RecursiveDeref( dd, bFunc1 );
536 assert( Abc_ObjGlobalBdd(pNode) == NULL );
537 Abc_ObjSetGlobalBdd( pNode, bFunc );
540 Extra_ProgressBarUpdate( pProgress, *pCounter, NULL );
543 bFunc = (DdNode *)Abc_ObjGlobalBdd(pNode);
545 if ( --pNode->
vFanouts.nSize == 0 && fDropInternal )
548 Abc_ObjSetGlobalBdd( pNode, NULL );
586 vFuncsGlob = Vec_PtrAlloc( Abc_NtkCoNum(pNtk) );
588 Vec_PtrPush( vFuncsGlob, Abc_ObjGlobalBdd(pObj) );
589 RetValue = Cudd_SharingSize( (DdNode **)Vec_PtrArray(vFuncsGlob), Vec_PtrSize(vFuncsGlob) );
590 Vec_PtrFree( vFuncsGlob );
656void Abc_NtkBddImplicationTest()
659 DdNode * bImp, * bSum, * bTemp;
665 dd = Cudd_Init( nVars, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
666 Cudd_AutodynEnable( dd, CUDD_REORDER_SIFT );
667 bSum =
b0; Cudd_Ref( bSum );
668 for ( i = 0; i < nImps; i++ )
671 bImp = Cudd_bddAnd( dd, dd->vars[rand()%nVars], dd->vars[rand()%nVars] ); Cudd_Ref( bImp );
672 bSum = Cudd_bddOr( dd, bTemp = bSum, bImp ); Cudd_Ref( bSum );
673 Cudd_RecursiveDeref( dd, bTemp );
674 Cudd_RecursiveDeref( dd, bImp );
676 printf(
"The BDD before = %d.\n", Cudd_DagSize(bSum) );
677 Cudd_ReduceHeap( dd, CUDD_REORDER_SIFT, 1 );
678 printf(
"The BDD after = %d.\n", Cudd_DagSize(bSum) );
679ABC_PRT(
"Time", Abc_Clock() - clk );
680 Cudd_RecursiveDeref( dd, bSum );
Abc_Ntk_t * Abc_NtkBddToMuxes(Abc_Ntk_t *pNtk, int fGlobal, int Limit, int fUseAdd)
ABC_NAMESPACE_IMPL_START double Abc_NtkSpacePercentage(Abc_Obj_t *pNode)
DECLARATIONS ///.
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachCo(pNtk, pCo, i)
ABC_DLL void * Abc_NtkAttrFree(Abc_Ntk_t *pNtk, int Attr, int fFreeMan)
DECLARATIONS ///.
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_NodeFreeNames(Vec_Ptr_t *vNames)
#define Abc_ObjForEachFanin(pObj, pFanin, i)
ABC_DLL Abc_Ntk_t * Abc_NtkDeriveFromBdd(void *dd, void *bFunc, char *pNamePo, Vec_Ptr_t *vNamesPi)
struct Abc_Aig_t_ Abc_Aig_t
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
ABC_DLL void * Abc_NtkFreeGlobalBdds(Abc_Ntk_t *pNtk, int fFreeMan)
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeMux(Abc_Ntk_t *pNtk, Abc_Obj_t *pNodeC, Abc_Obj_t *pNode1, Abc_Obj_t *pNode0)
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
#define Abc_NtkForEachPi(pNtk, pPi, i)
ABC_DLL void * Abc_NtkBuildGlobalBdds(Abc_Ntk_t *pNtk, int fBddSizeMax, int fDropInternal, int fReorder, int fReverse, int fVerbose)
ABC_DLL int Abc_NtkMinimumBase(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
#define Abc_NtkForEachCi(pNtk, pCi, i)
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
ABC_DLL Vec_Ptr_t * Abc_NodeGetFakeNames(int nNames)
ABC_DLL int Abc_NodeIsMuxType(Abc_Obj_t *pNode)
ABC_DLL Abc_Obj_t * Abc_NodeRecognizeMux(Abc_Obj_t *pNode, Abc_Obj_t **ppNodeT, Abc_Obj_t **ppNodeE)
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
ABC_DLL int Abc_NtkSizeOfGlobalBdds(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
int st__ptrhash(const char *, int)
int st__ptrcmp(const char *, const char *)
int st__lookup(st__table *table, const char *key, char **value)
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
int st__insert(st__table *table, const char *key, char *value)
void st__free_table(st__table *table)
struct Vec_Att_t_ Vec_Att_t
BASIC TYPES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.