49static int Abc_NodeBuildCutLevelOne_int(
Vec_Ptr_t * vVisited,
Vec_Ptr_t * vLeaves,
int nSizeLimit,
int nFaninLimit );
50static int Abc_NodeBuildCutLevelTwo_int(
Vec_Ptr_t * vVisited,
Vec_Ptr_t * vLeaves,
int nFaninLimit );
68static inline void Abc_NodesMark(
Vec_Ptr_t * vVisited )
87static inline void Abc_NodesUnmark(
Vec_Ptr_t * vVisited )
106static inline void Abc_NodesUnmarkB(
Vec_Ptr_t * vVisited )
126static inline int Abc_NodeGetLeafCostOne(
Abc_Obj_t * pNode,
int nFaninLimit )
132 if ( Abc_ObjIsCi(pNode) )
135 Cost = (!Abc_ObjFanin0(pNode)->fMarkB) + (!Abc_ObjFanin1(pNode)->fMarkB);
140 if ( Abc_ObjFanoutNum(pNode) > nFaninLimit )
158static inline int Abc_NodeGetLeafCostTwo(
Abc_Obj_t * pNode,
int nFaninLimit,
166 if ( Abc_ObjIsCi(pNode) )
172 pFanin0 = Abc_ObjFanin0(pNode);
173 pFanin1 = Abc_ObjFanin1(pNode);
177 if ( Abc_ObjIsCi(pFanin0) && Abc_ObjIsCi(pFanin1) )
180 if ( !Abc_ObjIsCi(pFanin0) && Abc_ObjFanin0(pFanin0)->fMarkB && Abc_ObjFanin1(pFanin0)->fMarkB )
182 *ppLeafToAdd = pFanin1;
183 *pNodeToMark1 = pFanin0;
184 *pNodeToMark2 = NULL;
187 if ( !Abc_ObjIsCi(pFanin1) && Abc_ObjFanin0(pFanin1)->fMarkB && Abc_ObjFanin1(pFanin1)->fMarkB )
189 *ppLeafToAdd = pFanin0;
190 *pNodeToMark1 = pFanin1;
191 *pNodeToMark2 = NULL;
196 if ( Abc_ObjIsCi(pFanin1) )
197 pTemp = pFanin0, pFanin0 = pFanin1, pFanin1 = pTemp;
200 if ( Abc_ObjIsCi(pFanin0) )
202 *pNodeToMark1 = NULL;
203 pGrandToAdd = pFanin0;
207 *pNodeToMark1 = pFanin0;
208 pGrand = Abc_ObjFanin0(pFanin0);
211 if ( pGrandToAdd && pGrandToAdd != pGrand )
213 pGrandToAdd = pGrand;
215 pGrand = Abc_ObjFanin1(pFanin0);
218 if ( pGrandToAdd && pGrandToAdd != pGrand )
220 pGrandToAdd = pGrand;
224 *pNodeToMark2 = pFanin1;
225 pGrand = Abc_ObjFanin0(pFanin1);
228 if ( pGrandToAdd && pGrandToAdd != pGrand )
230 pGrandToAdd = pGrand;
232 pGrand = Abc_ObjFanin1(pFanin1);
235 if ( pGrandToAdd && pGrandToAdd != pGrand )
237 pGrandToAdd = pGrand;
239 assert( pGrandToAdd != NULL );
240 *ppLeafToAdd = pGrandToAdd;
261 assert( !Abc_ObjIsComplement(pRoot) );
262 assert( Abc_ObjIsNode(pRoot) );
265 Vec_PtrClear(
p->vVisited );
266 Vec_PtrPush(
p->vVisited, pRoot );
267 Vec_PtrPush(
p->vVisited, Abc_ObjFanin0(pRoot) );
268 Vec_PtrPush(
p->vVisited, Abc_ObjFanin1(pRoot) );
270 Abc_ObjFanin0(pRoot)->fMarkB = 1;
271 Abc_ObjFanin1(pRoot)->fMarkB = 1;
274 Vec_PtrClear(
p->vNodeLeaves );
275 Vec_PtrPush(
p->vNodeLeaves, Abc_ObjFanin0(pRoot) );
276 Vec_PtrPush(
p->vNodeLeaves, Abc_ObjFanin1(pRoot) );
279 while ( Abc_NodeBuildCutLevelOne_int(
p->vVisited,
p->vNodeLeaves,
p->nNodeSizeMax,
p->nNodeFanStop ) );
280 assert( Vec_PtrSize(
p->vNodeLeaves) <=
p->nNodeSizeMax );
286 Abc_NodesUnmarkB(
p->vVisited );
287 return p->vNodeLeaves;
292 assert(
p->nNodeSizeMax <
p->nConeSizeMax );
294 Vec_PtrClear(
p->vConeLeaves );
296 Vec_PtrPush(
p->vConeLeaves, pNode );
298 while ( Abc_NodeBuildCutLevelOne_int(
p->vVisited,
p->vConeLeaves,
p->nConeSizeMax,
p->nConeFanStop ) );
299 assert( Vec_PtrSize(
p->vConeLeaves) <=
p->nConeSizeMax );
301 Abc_NodesUnmarkB(
p->vVisited );
302 return p->vNodeLeaves;
319int Abc_NodeBuildCutLevelOne_int(
Vec_Ptr_t * vVisited,
Vec_Ptr_t * vLeaves,
int nSizeLimit,
int nFaninLimit )
321 Abc_Obj_t * pNode, * pFaninBest, * pNext;
322 int CostBest, CostCur, i;
329 CostCur = Abc_NodeGetLeafCostOne( pNode, nFaninLimit );
332 if ( CostBest > CostCur ||
333 (CostBest == CostCur && pNode->
Level > pFaninBest->
Level) )
341 if ( pFaninBest == NULL )
346 if ( vLeaves->nSize - 1 + CostBest > nSizeLimit )
350 assert( Abc_ObjIsNode(pFaninBest) );
352 Vec_PtrRemove( vLeaves, pFaninBest );
356 pNext = Abc_ObjFanin0(pFaninBest);
361 Vec_PtrPush( vLeaves, pNext );
362 Vec_PtrPush( vVisited, pNext );
365 pNext = Abc_ObjFanin1(pFaninBest);
370 Vec_PtrPush( vLeaves, pNext );
371 Vec_PtrPush( vVisited, pNext );
373 assert( vLeaves->nSize <= nSizeLimit );
392int Abc_NodeBuildCutLevelTwo_int(
Vec_Ptr_t * vVisited,
Vec_Ptr_t * vLeaves,
int nFaninLimit )
394 Abc_Obj_t * pNode = NULL, * pLeafToAdd, * pNodeToMark1, * pNodeToMark2;
399 CostCur = Abc_NodeGetLeafCostTwo( pNode, nFaninLimit, &pLeafToAdd, &pNodeToMark1, &pNodeToMark2 );
406 Vec_PtrRemove( vLeaves, pNode );
410 assert( !pLeafToAdd->fMarkB );
411 pLeafToAdd->fMarkB = 1;
412 Vec_PtrPush( vLeaves, pLeafToAdd );
413 Vec_PtrPush( vVisited, pLeafToAdd );
418 assert( !pNodeToMark1->fMarkB );
419 pNodeToMark1->fMarkB = 1;
420 Vec_PtrPush( vVisited, pNodeToMark1 );
424 assert( !pNodeToMark2->fMarkB );
425 pNodeToMark2->fMarkB = 1;
426 Vec_PtrPush( vVisited, pNodeToMark2 );
449 Abc_NodesMark( vLeaves );
451 Vec_PtrClear( vVisited );
453 if ( fIncludeFanins )
455 Vec_PtrPush( vVisited, pTemp );
457 for ( i = 0; i < nRoots; i++ )
458 Abc_NodeConeMarkCollect_rec( ppRoots[i], vVisited );
460 Abc_NodesUnmark( vLeaves );
461 Abc_NodesUnmark( vVisited );
480 if ( Abc_ObjIsNode(pNode) )
482 Abc_NodeConeMarkCollect_rec( Abc_ObjFanin0(pNode), vVisited );
483 Abc_NodeConeMarkCollect_rec( Abc_ObjFanin1(pNode), vVisited );
487 Vec_PtrPush( vVisited, pNode );
506 DdNode * bFunc0, * bFunc1, * bFunc = NULL;
516 assert( !Abc_ObjIsPi(pNode) );
517 bFunc0 = Cudd_NotCond( Abc_ObjFanin0(pNode)->pCopy, (
int)Abc_ObjFaninC0(pNode) );
518 bFunc1 = Cudd_NotCond( Abc_ObjFanin1(pNode)->pCopy, (
int)Abc_ObjFaninC1(pNode) );
519 bFunc = Cudd_bddAnd( dd, bFunc0, bFunc1 ); Cudd_Ref( bFunc );
526 Cudd_RecursiveDeref( dd, (DdNode *)pNode->
pCopy );
542DdNode * Abc_NodeConeDcs( DdManager * dd, DdNode ** pbVarsX, DdNode ** pbVarsY,
Vec_Ptr_t * vLeaves,
Vec_Ptr_t * vRoots,
Vec_Ptr_t * vVisited )
544 DdNode * bFunc0, * bFunc1, * bFunc, * bTrans, * bTemp, * bCube, * bResult;
555 bFunc0 = Cudd_NotCond( Abc_ObjFanin0(pNode)->pCopy, (
int)Abc_ObjFaninC0(pNode) );
556 bFunc1 = Cudd_NotCond( Abc_ObjFanin1(pNode)->pCopy, (
int)Abc_ObjFaninC1(pNode) );
557 bFunc = Cudd_bddAnd( dd, bFunc0, bFunc1 ); Cudd_Ref( bFunc );
561 bTrans =
b1; Cudd_Ref( bTrans );
564 bFunc = Cudd_bddXnor( dd, (DdNode *)pNode->
pCopy, pbVarsY[i] ); Cudd_Ref( bFunc );
565 bTrans = Cudd_bddAnd( dd, bTemp = bTrans, bFunc ); Cudd_Ref( bTrans );
566 Cudd_RecursiveDeref( dd, bTemp );
567 Cudd_RecursiveDeref( dd, bFunc );
571 Cudd_RecursiveDeref( dd, (DdNode *)pNode->
pCopy );
574 bResult = Cudd_bddExistAbstract( dd, bTrans, bCube ); Cudd_Ref( bResult );
575 bResult = Cudd_Not( bResult );
576 Cudd_RecursiveDeref( dd, bCube );
577 Cudd_RecursiveDeref( dd, bTrans );
578 Cudd_Deref( bResult );
600 p->vNodeLeaves = Vec_PtrAlloc( 100 );
601 p->vConeLeaves = Vec_PtrAlloc( 100 );
602 p->vVisited = Vec_PtrAlloc( 100 );
603 p->vLevels = Vec_VecAlloc( 100 );
604 p->vNodesTfo = Vec_PtrAlloc( 100 );
605 p->nNodeSizeMax = nNodeSizeMax;
606 p->nConeSizeMax = nConeSizeMax;
607 p->nNodeFanStop = nNodeFanStop;
608 p->nConeFanStop = nConeFanStop;
625 Vec_PtrFree(
p->vNodeLeaves );
626 Vec_PtrFree(
p->vConeLeaves );
627 Vec_PtrFree(
p->vVisited );
628 Vec_VecFree(
p->vLevels );
629 Vec_PtrFree(
p->vNodesTfo );
646 return p->vConeLeaves;
662 return p->vNodeLeaves;
704 int i, k, v, LevelMin;
705 assert( Abc_NtkIsStrash(pNtk) );
709 assert( vVec->nSize == 0 );
712 Abc_NtkIncrementTravId( pNtk );
716 if ( pNode->
Level > (
unsigned)LevelMax )
718 Abc_NodeSetTravIdCurrent( pNode );
719 Vec_VecPush(
p->vLevels, pNode->
Level, pNode );
720 if ( LevelMin < (
int)pNode->
Level )
721 LevelMin = pNode->
Level;
730 Vec_PtrClear(
p->vNodesTfo );
736 if ( !Abc_NodeIsTravIdCurrent(pNode) )
739 if ( !Abc_NodeIsTravIdCurrent(Abc_ObjFanin0(pNode)) ||
740 !Abc_NodeIsTravIdCurrent(Abc_ObjFanin1(pNode)) )
743 Vec_PtrPush(
p->vNodesTfo, pNode );
744 Abc_NodeSetTravIdCurrent( pNode );
750 if ( Abc_ObjIsCo(pFanout) || pFanout->
Level > (
unsigned)LevelMax )
753 if ( Abc_NodeIsTravIdCurrent(pFanout) )
756 Vec_VecPushUnique(
p->vLevels, pFanout->
Level, pFanout );
765 Vec_PtrClear( vVec );
Vec_Ptr_t * Abc_NtkManCutReadVisited(Abc_ManCut_t *p)
Vec_Ptr_t * Abc_NtkManCutReadCutSmall(Abc_ManCut_t *p)
Vec_Ptr_t * Abc_NodeCollectTfoCands(Abc_ManCut_t *p, Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, int LevelMax)
void Abc_NodeConeCollect(Abc_Obj_t **ppRoots, int nRoots, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVisited, int fIncludeFanins)
Vec_Ptr_t * Abc_NtkManCutReadCutLarge(Abc_ManCut_t *p)
Vec_Ptr_t * Abc_NodeFindCut(Abc_ManCut_t *p, Abc_Obj_t *pRoot, int fContain)
Abc_ManCut_t * Abc_NtkManCutStart(int nNodeSizeMax, int nConeSizeMax, int nNodeFanStop, int nConeFanStop)
void Abc_NtkManCutStop(Abc_ManCut_t *p)
struct Abc_Obj_t_ Abc_Obj_t
ABC_DLL int Abc_NodeMffcLabelAig(Abc_Obj_t *pNode)
#define Abc_ObjForEachFanout(pObj, pFanout, i)
struct Abc_ManCut_t_ Abc_ManCut_t
struct Abc_Ntk_t_ Abc_Ntk_t
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
#define Vec_VecForEachEntryStart(Type, vGlob, pEntry, i, k, LevelStart)
#define Vec_VecForEachLevelStart(vGlob, vVec, i, LevelStart)
#define Vec_VecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.