36extern int Abc_NodeSupport( DdNode * bFunc,
Vec_Str_t * vSupport,
int nVars );
57 assert( Abc_NtkIsBddLogic(pNtk) );
75int Abc_NodeMinimumBase_buggy(
Abc_Obj_t * pNode )
83 assert( Abc_ObjIsNode(pNode) );
86 vSupport = Vec_StrAlloc( 10 );
87 nVars = Abc_NodeSupport( Cudd_Regular(pNode->
pData), vSupport, Abc_ObjFaninNum(pNode) );
88 if ( nVars == Abc_ObjFaninNum(pNode) )
90 Vec_StrFree( vSupport );
95 vFanins = Vec_PtrAlloc( Abc_ObjFaninNum(pNode) );
97 for ( i = 0; i < vFanins->nSize; i++ )
98 if ( vSupport->
pArray[i] == 0 )
100 assert( nVars == Abc_ObjFaninNum(pNode) );
104 Cudd_RecursiveDeref( (DdManager *)pNode->
pNtk->
pManFunc, bTemp );
105 Vec_PtrFree( vFanins );
106 Vec_StrFree( vSupport );
113 DdNode * bTemp, ** pbVars;
115 int i, nVars, j, iFanin, iFanin2, k = 0;
116 int ddSize, fDupFanins = 0;
119 assert( Abc_ObjIsNode(pNode) );
122 vSupport = Vec_StrAlloc( 10 );
123 nVars = Abc_NodeSupport( Cudd_Regular(pNode->
pData), vSupport, Abc_ObjFaninNum(pNode) );
124 if ( nVars == Abc_ObjFaninNum(pNode) )
126 Vec_StrFree( vSupport );
133 ddSize = Cudd_ReadSize( dd );
135 for (i = 0; i < ddSize; i += 1 ) {
136 pbVars[i] = Cudd_bddIthVar( dd, i );
141 if ( !Vec_StrEntry(vSupport, i) )
143 if ( !Vec_IntRemove( &pFanin->
vFanouts, pNode->
Id ) )
144 printf(
"The obj %d is not found among the fanouts of obj %d ...\n", pNode->
Id, iFanin );
148 if ( iFanin == iFanin2 )
150 fDupFanins |= (int)(j < k);
152 Vec_IntWriteEntry( &pNode->
vFanins, k++, iFanin );
153 else if ( !Vec_IntRemove( &pFanin->
vFanouts, pNode->
Id ) )
154 printf(
"The obj %d is not found among the fanouts of obj %d ...\n", pNode->
Id, iFanin );
157 pbVars[i] = Cudd_bddIthVar( dd, j );
159 Vec_IntShrink( &pNode->
vFanins, k );
162 if ( ! Cudd_IsConstant((DdNode *) pNode->
pData ) ) {
163 pNode->
pData = Cudd_bddVectorCompose( dd, bTemp = (DdNode *)pNode->
pData, pbVars );
164 Cudd_Ref( (DdNode *)pNode->
pData );
165 Cudd_RecursiveDeref( dd, bTemp );
167 Vec_StrFree( vSupport );
191 assert( Abc_NtkIsBddLogic(pNtk) );
209int Abc_NodeRemoveDupFanins_int(
Abc_Obj_t * pNode )
214 assert( Abc_ObjIsNode(pNode) );
222 if ( pFanin1 == pFanin2 )
225 DdNode * bVar1 = Cudd_bddIthVar( dd, i );
226 DdNode * bVar2 = Cudd_bddIthVar( dd, k );
227 DdNode * bTrans, * bTemp;
228 bTrans = Cudd_bddXnor( dd, bVar1, bVar2 ); Cudd_Ref( bTrans );
229 pNode->
pData = Cudd_bddAndAbstract( dd, bTemp = (DdNode *)pNode->
pData, bTrans, bVar2 ); Cudd_Ref( (DdNode *)pNode->
pData );
230 Cudd_RecursiveDeref( dd, bTemp );
231 Cudd_RecursiveDeref( dd, bTrans );
254 while ( Abc_NodeRemoveDupFanins_int(pNode) )
269void Abc_NodeSupport_rec( DdNode * bFunc,
Vec_Str_t * vSupport )
271 if ( cuddIsConstant(bFunc) || Cudd_IsComplement(bFunc->next) )
273 vSupport->
pArray[ bFunc->index ] = 1;
274 Abc_NodeSupport_rec( cuddT(bFunc), vSupport );
275 Abc_NodeSupport_rec( Cudd_Regular(cuddE(bFunc)), vSupport );
276 bFunc->next = Cudd_Not(bFunc->next);
290void Abc_NodeSupportClear_rec( DdNode * bFunc )
292 if ( !Cudd_IsComplement(bFunc->next) )
294 bFunc->next = Cudd_Regular(bFunc->next);
295 if ( cuddIsConstant(bFunc) )
297 Abc_NodeSupportClear_rec( cuddT(bFunc) );
298 Abc_NodeSupportClear_rec( Cudd_Regular(cuddE(bFunc)) );
312int Abc_NodeSupport( DdNode * bFunc,
Vec_Str_t * vSupport,
int nVars )
316 Vec_StrFill( vSupport, nVars, 0 );
317 Abc_NodeSupport_rec( bFunc, vSupport );
319 Abc_NodeSupportClear_rec( bFunc );
322 for ( i = 0; i < nVars; i++ )
323 Counter += vSupport->
pArray[i];
345 if ( pObj == pFanin )
369 Vec_PtrClear( vFanins );
371 if ( pObj != pFanin )
372 Vec_PtrPushUnique( vFanins, pObj );
374 Vec_PtrPushUnique( vFanins, pObj );
375 return Vec_PtrSize( vFanins );
394 if ( pObj == pFanin )
414 for ( i = 0; i < Vec_PtrSize(vFanins); i++ )
418 if ( pFanin == pSkip )
420 pPerm[i] = Abc_ObjFaninNumberNew( vFanins, pFanin );
421 if ( pPerm[i] == -1 )
443 DdNode * bVar, * bFunc0, * bFunc1, * bTemp, * bFanin, * bFanout;
444 int RetValue, nSize, iFanin;
446 if ( Abc_NodeCheckDupFanin( pFanin, pFanout, &iFanin ) != 1 )
449 nSize = Abc_NodeCollapseSuppSize( pFanin, pFanout, vFanins );
450 bVar = Cudd_bddIthVar( dd, nSize - 1 );
451 assert( nSize <= dd->size );
453 RetValue = Abc_NodeCollapsePermMap( pFanin, NULL, vFanins, pPermFanin );
455 RetValue = Abc_NodeCollapsePermMap( pFanout, pFanin, vFanins, pPermFanout );
458 bVar = Cudd_bddIthVar( dd, iFanin );
459 bFunc0 = Cudd_Cofactor( dd, (DdNode *)pFanout->
pData, Cudd_Not(bVar) ); Cudd_Ref( bFunc0 );
460 bFunc1 = Cudd_Cofactor( dd, (DdNode *)pFanout->
pData, bVar ); Cudd_Ref( bFunc1 );
462 bFunc0 = Cudd_bddPermute( dd, bTemp = bFunc0, pPermFanout ); Cudd_Ref( bFunc0 );
463 Cudd_RecursiveDeref( dd, bTemp );
464 bFunc1 = Cudd_bddPermute( dd, bTemp = bFunc1, pPermFanout ); Cudd_Ref( bFunc1 );
465 Cudd_RecursiveDeref( dd, bTemp );
466 bFanin = Cudd_bddPermute( dd, (DdNode *)pFanin->
pData, pPermFanin ); Cudd_Ref( bFanin );
468 bFanout = Cudd_bddIte( dd, bFanin, bFunc1, bFunc0 ); Cudd_Ref( bFanout );
469 Cudd_RecursiveDeref( dd, bFanin );
470 Cudd_RecursiveDeref( dd, bFunc1 );
471 Cudd_RecursiveDeref( dd, bFunc0 );
472 Cudd_Deref( bFanout );
481 assert( Abc_ObjIsNode(pFanin) );
482 assert( Abc_ObjIsNode(pFanout) );
483 bFanoutNew = Abc_NodeCollapseFunc( pFanin, pFanout, vFanins, pPermFanin, pPermFanout );
484 if ( bFanoutNew == NULL )
486 Cudd_Ref( bFanoutNew );
488 pFanoutNew = Abc_NtkCreateNode( pFanin->
pNtk );
491 pFanoutNew->
pData = bFanoutNew;
496 assert( Abc_ObjFanoutNum( pFanout ) == 0 );
503 Vec_Ptr_t * vFanouts, * vFanins, * vNodes;
505 int * pPermFanin, * pPermFanout;
508 assert( Abc_NtkIsLogic(pNtk) );
512 fprintf( stdout,
"Converting to BDD has failed.\n" );
522 pPermFanin =
ABC_ALLOC(
int, nMaxSize + 1000 );
523 pPermFanout =
ABC_ALLOC(
int, nMaxSize + 1000 );
524 vFanins = Vec_PtrAlloc( 1000 );
525 vFanouts = Vec_PtrAlloc( 1000 );
528 if ( !Abc_ObjIsNode(pNode) )
532 if ( Abc_ObjFaninNum(pNode) > nMaxSize )
535 if ( Abc_NodeCollapseSuppSize(pNode, pFanout, vFanins) > nMaxSize )
537 if ( k < Abc_ObjFanoutNum(pNode) )
544 printf(
"Collapsing fanin %5d (supp =%2d) into fanout %5d (supp =%2d) ",
545 Abc_ObjId(pNode), Abc_ObjFaninNum(pNode), Abc_ObjId(pFanout), Abc_ObjFaninNum(pFanout) );
546 RetValue = Abc_NodeCollapse( pNode, pFanout, vFanins, pPermFanin, pPermFanout );
550 Abc_Obj_t * pNodeNew = Abc_NtkObj( pNtk, Abc_NtkObjNumMax(pNtk) - 1 );
552 printf(
"resulting in node %5d (supp =%2d).\n", Abc_ObjId(pNodeNew), Abc_ObjFaninNum(pNodeNew) );
557 Vec_PtrFree( vFanins );
558 Vec_PtrFree( vFanouts );
559 Vec_PtrFree( vNodes );
582 assert( iFanin >= 0 && iFanin < Hop_ManPiNum(pMan) );
585int Abc_NodeCountAppearancesAll(
Abc_Obj_t * pNode )
590 Count += Abc_NodeCountAppearances( pNode, pFanout );
609 int RetValue, nSize, iFanin;
611 if ( Abc_NodeCheckDupFanin( pFanin, pFanout, &iFanin ) != 1 )
614 nSize = Abc_NodeCollapseSuppSize( pFanin, pFanout, vFanins );
616 assert( nSize + 1 <= Hop_ManPiNum(pMan) );
618 RetValue = Abc_NodeCollapsePermMap( pFanin, NULL, vFanins, pPermFanin );
620 RetValue = Abc_NodeCollapsePermMap( pFanout, pFanin, vFanins, pPermFanout );
623 pPermFanout[iFanin] = nSize;
628 return Hop_Compose( pMan, bFanout, bFanin, nSize );
636 assert( Abc_ObjIsNode(pFanin) );
637 assert( Abc_ObjIsNode(pFanout) );
638 bFanoutNew = Abc_NodeCollapseFunc1( pFanin, pFanout, vFanins, pPermFanin, pPermFanout );
639 if ( bFanoutNew == NULL )
642 pFanoutNew = Abc_NtkCreateNode( pFanin->
pNtk );
645 pFanoutNew->
pData = bFanoutNew;
648 assert( Abc_ObjFanoutNum( pFanout ) == 0 );
656 if ( Abc_ObjFaninNum(pNode) < 3 || Abc_ObjFaninNum(pNode) > 6 )
660 if ( Truth == 0x6666666666666666 || Truth == 0x9999999999999999 ||
661 Truth == 0x9696969696969696 || Truth == 0x6969696969696969 ||
662 Truth == 0x6996699669966996 || Truth == 0x9669966996699669 ||
663 Truth == 0x9669699696696996 || Truth == 0x6996966969969669 ||
664 Truth == 0x6996966996696996 || Truth == 0x9669699669969669 )
668int Abc_NtkEliminate1One(
Abc_Ntk_t * pNtk,
int ElimValue,
int nMaxSize,
int fReverse,
int fVerbose )
670 Vec_Ptr_t * vFanouts, * vFanins, * vNodes;
672 int * pPermFanin, * pPermFanout;
675 assert( Abc_NtkIsLogic(pNtk) );
679 fprintf( stdout,
"Converting to AIG has failed.\n" );
685 pPermFanin =
ABC_ALLOC(
int, nMaxSize + 1000 );
686 pPermFanout =
ABC_ALLOC(
int, nMaxSize + 1000 );
687 vFanins = Vec_PtrAlloc( 1000 );
688 vFanouts = Vec_PtrAlloc( 1000 );
691 if ( !Abc_ObjIsNode(pNode) )
695 if ( Abc_ObjFaninNum(pNode) > nMaxSize )
697 if ( Abc_NodeIsExor(pNode) )
703 if ( Abc_NodeCountAppearancesAll( pNode ) > ElimValue + 2 )
706 if ( Abc_NodeCollapseSuppSize(pNode, pFanout, vFanins) > nMaxSize )
708 if ( k < Abc_ObjFanoutNum(pNode) )
715 printf(
"Collapsing fanin %5d (supp =%2d) into fanout %5d (supp =%2d) ",
716 Abc_ObjId(pNode), Abc_ObjFaninNum(pNode), Abc_ObjId(pFanout), Abc_ObjFaninNum(pFanout) );
717 RetValue = Abc_NodeCollapse1( pNode, pFanout, vFanins, pPermFanin, pPermFanout );
721 Abc_Obj_t * pNodeNew = Abc_NtkObj( pNtk, Abc_NtkObjNumMax(pNtk) - 1 );
723 printf(
"resulting in node %5d (supp =%2d).\n", Abc_ObjId(pNodeNew), Abc_ObjFaninNum(pNodeNew) );
727 Vec_PtrFree( vFanins );
728 Vec_PtrFree( vFanouts );
729 Vec_PtrFree( vNodes );
737 for ( i = 0; i < nIterMax; i++ )
739 int nNodes = Abc_NtkNodeNum(pNtk);
741 if ( !Abc_NtkEliminate1One(pNtk, ElimValue, nMaxSize, fReverse, fVerbose) )
743 if ( nNodes == Abc_NtkNodeNum(pNtk) )
762 return Abc_ObjRegular(*pp1)->iTemp - Abc_ObjRegular(*pp2)->iTemp;
772 Vec_PtrSort( vNodes, (
int (*)(
const void *,
const void *))Abc_ObjCompareByNumber );
775 Vec_PtrFree( vOrder );
793 Vec_Ptr_t * vFanouts, * vFanins, * vNodes;
795 int * pPermFanin, * pPermFanout;
798 assert( Abc_NtkIsLogic(pNtk) );
804 fprintf( stdout,
"Converting to BDD has failed.\n" );
816 fprintf( stdout,
"Converting to SOP has failed.\n" );
821 vNodes = Vec_PtrAlloc( 1000 );
824 if ( Abc_ObjFanoutNum(pNode) != 1 )
826 pFanout = Abc_ObjFanout0(pNode);
827 if ( !Abc_ObjIsNode(pFanout) )
835 assert( RetValue >= 0 && RetValue < Abc_ObjFaninNum(pFanout) );
839 Vec_PtrPush( vNodes, pNode );
841 if ( Vec_PtrSize(vNodes) == 0 )
843 Vec_PtrFree( vNodes );
846 Abc_ObjSortInReverseOrder( pNtk, vNodes );
851 fprintf( stdout,
"Converting to BDD has failed.\n" );
856 pPermFanin =
ABC_ALLOC(
int, nMaxSize + 1000 );
857 pPermFanout =
ABC_ALLOC(
int, nMaxSize + 1000 );
858 vFanins = Vec_PtrAlloc( 1000 );
859 vFanouts = Vec_PtrAlloc( 1000 );
862 assert( Abc_ObjIsNode(pNode) );
869 printf(
"Collapsing fanin %5d (supp =%2d) into fanout %5d (supp =%2d) ",
870 Abc_ObjId(pNode), Abc_ObjFaninNum(pNode), Abc_ObjId(pFanout), Abc_ObjFaninNum(pFanout) );
871 RetValue = Abc_NodeCollapse( pNode, pFanout, vFanins, pPermFanin, pPermFanout );
875 Abc_Obj_t * pNodeNew = Abc_NtkObj( pNtk, Abc_NtkObjNumMax(pNtk) - 1 );
877 printf(
"resulting in node %5d (supp =%2d).\n", Abc_ObjId(pNodeNew), Abc_ObjFaninNum(pNodeNew) );
882 Vec_PtrFree( vFanins );
883 Vec_PtrFree( vFanouts );
884 Vec_PtrFree( vNodes );
void Abc_NtkBddReorder(Abc_Ntk_t *pNtk, int fVerbose)
DECLARATIONS ///.
int Abc_NodeMinimumBase(Abc_Obj_t *pNode)
int Abc_NtkEliminate(Abc_Ntk_t *pNtk, int nMaxSize, int fReverse, int fVerbose)
int Abc_NtkRemoveDupFanins(Abc_Ntk_t *pNtk)
int Abc_NtkEliminateSpecial(Abc_Ntk_t *pNtk, int nMaxSize, int fVerbose)
ABC_NAMESPACE_IMPL_START int Abc_NtkMinimumBase(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
int Abc_NtkEliminate1(Abc_Ntk_t *pNtk, int ElimValue, int nMaxSize, int nIterMax, int fReverse, int fVerbose)
struct Abc_Obj_t_ Abc_Obj_t
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
ABC_DLL int Abc_NtkCleanup(Abc_Ntk_t *pNtk, int fVerbose)
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
#define Abc_ObjForEachFanin(pObj, pFanin, i)
ABC_DLL int Abc_NtkToBdd(Abc_Ntk_t *pNtk)
#define Abc_ObjForEachFanout(pObj, pFanout, i)
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
ABC_DLL void Abc_NodeCollectFanouts(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL int Abc_NodeRemoveDupFanins(Abc_Obj_t *pNode)
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
ABC_DLL void Abc_ObjDeleteFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
ABC_DLL void Abc_NodeCollectFanins(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
ABC_DLL int Abc_NtkToAig(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_SopGetIthCareLit(char *pSop, int i)
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fMode, int nCubeLimit)
ABC_DLL int Abc_SopIsComplement(char *pSop)
ABC_DLL Abc_Obj_t * Abc_NodeFindCoFanout(Abc_Obj_t *pNode)
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
ABC_DLL Vec_Ptr_t * Abc_NtkDfsReverse(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_NodeFindFanin(Abc_Obj_t *pNode, Abc_Obj_t *pFanin)
#define Abc_NtkForEachNode(pNtk, pNode, i)
#define ABC_ALLOC(type, num)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
struct Vec_Str_t_ Vec_Str_t
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Hop_Obj_t * Hop_Compose(Hop_Man_t *p, Hop_Obj_t *pRoot, Hop_Obj_t *pFunc, int iVar)
Hop_Obj_t * Hop_Permute(Hop_Man_t *p, Hop_Obj_t *pRoot, int nRootVars, int *pPermute)
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
int Hop_ObjFanoutCount(Hop_Obj_t *pObj, Hop_Obj_t *pPivot)
word Hop_ManComputeTruth6(Hop_Man_t *p, Hop_Obj_t *pObj, int nVars)
struct Hop_Obj_t_ Hop_Obj_t
unsigned __int64 word
DECLARATIONS ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStop(vVec, Entry, i, Stop)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.