74static int Abc_NtkRRTfi_int(
Vec_Ptr_t * vLeaves,
int LevelLimit );
80static void Abc_NtkRRSimulateStart(
Abc_Ntk_t * pNtk );
81static void Abc_NtkRRSimulateStop(
Abc_Ntk_t * pNtk );
98int Abc_NtkRR(
Abc_Ntk_t * pNtk,
int nFaninLevels,
int nFanoutLevels,
int fUseFanouts,
int fVerbose )
103 int i, k, m, nNodes, RetValue;
104 abctime clk, clkTotal = Abc_Clock();
106 p = Abc_RRManStart();
108 p->nFaninLevels = nFaninLevels;
109 p->nFanoutLevels = nFanoutLevels;
110 p->nNodesOld = Abc_NtkNodeNum(pNtk);
117 nNodes = Abc_NtkObjNumMax(pNtk);
118 Abc_NtkRRSimulateStart(pNtk);
122 Extra_ProgressBarUpdate( pProgress, i, NULL );
130 if ( Abc_NodeIsPersistant(pNode) )
133 if ( Abc_ObjFanoutNum(pNode) > 1000 )
141 if ( Abc_ObjFanoutNum(pFanin) == 1 )
156 RetValue = Abc_NtkRRWindow(
p );
157 p->timeWindow += Abc_Clock() - clk;
167 RetValue = Abc_NtkRRProve(
p );
168 p->timeMiter += Abc_Clock() - clk;
174 Abc_NtkRRUpdate( pNtk,
p->pNode,
p->pFanin,
p->pFanout );
175 p->timeUpdate += Abc_Clock() - clk;
194 p->pFanout = pFanout;
197 RetValue = Abc_NtkRRWindow(
p );
198 p->timeWindow += Abc_Clock() - clk;
203 RetValue = Abc_NtkRRProve(
p );
204 p->timeMiter += Abc_Clock() - clk;
209 Abc_NtkRRUpdate( pNtk,
p->pNode,
p->pFanin,
p->pFanout );
210 p->timeUpdate += Abc_Clock() - clk;
216 Abc_NtkRRSimulateStop(pNtk);
218 p->timeTotal = Abc_Clock() - clkTotal;
220 Abc_RRManPrintStats(
p );
231 printf(
"Abc_NtkRR: The network check has failed.\n" );
253 p->vFaninLeaves = Vec_PtrAlloc( 100 );
254 p->vFanoutRoots = Vec_PtrAlloc( 100 );
255 p->vLeaves = Vec_PtrAlloc( 100 );
256 p->vCone = Vec_PtrAlloc( 100 );
257 p->vRoots = Vec_PtrAlloc( 100 );
278 Vec_PtrFree(
p->vFaninLeaves );
279 Vec_PtrFree(
p->vFanoutRoots );
280 Vec_PtrFree(
p->vLeaves );
281 Vec_PtrFree(
p->vCone );
282 Vec_PtrFree(
p->vRoots );
300 double Ratio = 100.0*(
p->nNodesOld - Abc_NtkNodeNum(
p->pNtk))/
p->nNodesOld;
301 printf(
"Redundancy removal statistics:\n" );
302 printf(
"Edges tried = %6d.\n",
p->nEdgesTried );
303 printf(
"Edges removed = %6d. (%5.2f %%)\n",
p->nEdgesRemoved, 100.0*
p->nEdgesRemoved/
p->nEdgesTried );
304 printf(
"Node gain = %6d. (%5.2f %%)\n",
p->nNodesOld - Abc_NtkNodeNum(
p->pNtk), Ratio );
305 printf(
"Level gain = %6d.\n",
p->nLevelsOld -
Abc_AigLevel(
p->pNtk) );
306 ABC_PRT(
"Windowing ",
p->timeWindow );
308 ABC_PRT(
" Construct ",
p->timeMiter -
p->timeProve );
310 ABC_PRT(
"Update ",
p->timeUpdate );
330 Vec_PtrClear(
p->vFaninLeaves );
331 Vec_PtrClear(
p->vFanoutRoots );
332 Vec_PtrClear(
p->vLeaves );
333 Vec_PtrClear(
p->vCone );
334 Vec_PtrClear(
p->vRoots );
359 Abc_NtkRRUpdate( pWndCopy,
p->pNode->pCopy->pCopy,
p->pFanin->pCopy->pCopy,
p->pFanout?
p->pFanout->pCopy->pCopy : NULL );
366p->timeProve += Abc_Clock() - clk;
387 Abc_Obj_t * pNodeNew = NULL, * pFanoutNew = NULL;
388 assert( pFanout == NULL );
389 assert( !Abc_ObjIsComplement(pNode) );
390 assert( !Abc_ObjIsComplement(pFanin) );
391 assert( !Abc_ObjIsComplement(pFanout) );
393 if ( pFanin == Abc_ObjFanin0(pNode) )
394 pNodeNew = Abc_ObjChild1(pNode);
395 else if ( pFanin == Abc_ObjFanin1(pNode) )
396 pNodeNew = Abc_ObjChild0(pNode);
399 if ( pFanout == NULL )
402 if ( pNode == Abc_ObjFanin0(pFanout) )
404 else if ( pNode == Abc_ObjFanin1(pFanout) )
428 Abc_Obj_t * pObj, * pEdgeFanin, * pEdgeFanout;
429 int i, LevelMin, LevelMax, RetValue;
432 pEdgeFanout =
p->pFanout?
p->pFanout :
p->pNode;
433 pEdgeFanin =
p->pFanout?
p->pNode :
p->pFanin;
435 LevelMin = Abc_MaxInt( 0, ((
int)
p->pFanin->Level) -
p->nFaninLevels );
436 LevelMax = (int)pEdgeFanout->
Level +
p->nFanoutLevels;
439 Abc_NtkIncrementTravId(
p->pNtk );
440 Abc_NodeSetTravIdCurrent(
p->pFanin );
441 Vec_PtrPush(
p->vFaninLeaves,
p->pFanin );
443 while ( Abc_NtkRRTfi_int(
p->vFaninLeaves, LevelMin) );
446 Abc_NtkIncrementTravId(
p->pNtk );
448 Abc_NodeSetTravIdCurrent( pObj );
452 while ( Abc_NtkRRTfo_int(
p->vFaninLeaves,
p->vFanoutRoots, LevelMax, pEdgeFanin, pEdgeFanout) );
458 RetValue = Abc_NtkRRTfo_rec( pEdgeFanout,
p->vRoots, LevelMax + 1 );
469 Abc_NtkIncrementTravId(
p->pNtk );
471 Abc_NtkRRTfi_rec( pObj,
p->vLeaves,
p->vCone, LevelMin );
474 p->pWnd = Abc_NtkWindow(
p->pNtk,
p->vLeaves,
p->vCone,
p->vRoots );
489int Abc_NtkRRTfi_int(
Vec_Ptr_t * vLeaves,
int LevelLimit )
492 int i, k, LevelMax, nSize;
493 assert( LevelLimit >= 0 );
497 if ( LevelMax < (
int)pObj->
Level )
498 LevelMax = pObj->
Level;
500 if ( LevelMax <= LevelLimit )
503 nSize = Vec_PtrSize(vLeaves);
506 if ( LevelMax != (
int)pObj->
Level )
510 if ( Abc_NodeIsTravIdCurrent(pNext) )
512 Abc_NodeSetTravIdCurrent( pNext );
513 Vec_PtrPush( vLeaves, pNext );
520 if ( LevelMax == (
int)pObj->
Level )
522 Vec_PtrWriteEntry( vLeaves, k++, pObj );
524 Vec_PtrShrink( vLeaves, k );
525 if ( Vec_PtrSize(vLeaves) > 2000 )
544 int i, k, LevelMin, nSize, fObjIsRoot;
548 if ( LevelMin > (
int)pObj->
Level )
549 LevelMin = pObj->
Level;
551 if ( LevelMin > LevelLimit )
554 nSize = Vec_PtrSize(vLeaves);
557 if ( LevelMin != (
int)pObj->
Level )
563 if ( Abc_ObjIsCo(pNext) || pNext->
Level > (
unsigned)LevelLimit )
569 if ( pObj == pEdgeFanin && pNext == pEdgeFanout )
572 if ( Abc_NodeIsTravIdCurrent(pNext) )
574 Abc_NodeSetTravIdCurrent( pNext );
575 Vec_PtrPush( vLeaves, pNext );
578 Vec_PtrPush( vRoots, pObj );
584 if ( LevelMin == (
int)pObj->
Level )
586 Vec_PtrWriteEntry( vLeaves, k++, pObj );
588 Vec_PtrShrink( vLeaves, k );
589 if ( Vec_PtrSize(vLeaves) > 2000 )
611 if ( Abc_ObjIsCo(pNode) || pNode->
Level > (
unsigned)LevelLimit )
616 Vec_PtrPushUnique( vRoots, pNode );
620 Abc_NodeSetTravIdCurrent( pNode );
623 if ( !Abc_NtkRRTfo_rec( pFanout, vRoots, LevelLimit ) )
644 if ( Abc_NodeIsTravIdCurrent(pNode) )
647 if ( !Abc_NodeIsTravIdPrevious(pNode) || (
int)pNode->
Level <= LevelLimit )
649 Abc_NodeSetTravIdCurrent( pNode );
650 Vec_PtrPush( vLeaves, pNode );
654 Abc_NodeSetTravIdCurrent( pNode );
657 Abc_NtkRRTfi_rec( pFanin, vLeaves, vCone, LevelLimit );
659 Vec_PtrPush( vCone, pNode );
679 assert( Abc_NtkIsStrash(pNtk) );
688 pObj->
pCopy = Abc_NtkCreatePi(pNtkNew);
693 if ( Vec_PtrSize(vCone) != Abc_NtkNodeNum(pNtkNew) )
694 printf(
"Warning: Structural hashing during windowing reduced %d nodes (this is a bug).\n",
695 Vec_PtrSize(vCone) - Abc_NtkNodeNum(pNtkNew) );
708 printf(
"Abc_NtkWindow: The network check has failed.\n" );
726void Abc_NtkRRSimulateStart(
Abc_Ntk_t * pNtk )
729 unsigned uData, uData0, uData1;
736 if ( i == 0 )
continue;
737 uData0 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->pData;
738 uData1 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin1(pObj)->pData;
739 uData = Abc_ObjFaninC0(pObj)? ~uData0 : uData0;
740 uData &= Abc_ObjFaninC1(pObj)? ~uData1 : uData1;
742 pObj->
pData = (
void *)(ABC_PTRUINT_T)uData;
757void Abc_NtkRRSimulateStop(
Abc_Ntk_t * pNtk )
791 unsigned uData, uData0, uData1;
792 int PrevCi, Phase, i, k;
795 vTargets = Vec_StrStart( Abc_NtkObjNumMax(pNtk) + 1 );
798 Phase = ((Abc_ObjFanoutNum(Abc_ObjFanin1(pObj)) > 1) << 1);
799 Phase |= (Abc_ObjFanoutNum(Abc_ObjFanin0(pObj)) > 1);
800 Vec_StrWriteEntry( vTargets, pObj->
Id, (
char)Phase );
809 if ( i == 0 )
continue;
810 uData0 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->pData;
811 uData1 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin1(pObj)->pData;
812 uData = Abc_ObjFaninC0(pObj)? ~uData0 : uData0;
813 uData &= Abc_ObjFaninC1(pObj)? ~uData1 : uData1;
819 uData0 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->
pData;
820 if ( Abc_ObjFaninC0(pObj) )
821 pObj->
pData = (
void *)(ABC_PTRUINT_T)~uData0;
823 pObj->
pData = (
void *)(ABC_PTRUINT_T)uData0;
827 for ( PrevCi = 0; PrevCi < Abc_NtkCiNum(pNtk); PrevCi = i )
829 vNodes = Vec_PtrAlloc( 10 );
830 Abc_NtkIncrementTravId( pNtk );
831 for ( i = PrevCi; i < Abc_NtkCiNum(pNtk); i++ )
833 Sim_TraverseNodes_rec( Abc_NtkCi(pNtk, i), vTargets, vNodes );
834 if ( Vec_PtrSize(vNodes) > 128 )
838 vField = Vec_PtrAlloc( 10 );
839 Abc_NtkIncrementTravId( pNtk );
841 Sim_CollectNodes_rec( pObj, vField );
844 Sim_SimulateCollected( vTargets, vNodes, vField );
846 Vec_PtrFree( vNodes );
871 if ( Abc_NodeIsTravIdCurrent(pRoot) )
873 Abc_NodeSetTravIdCurrent( pRoot );
875 Entry = Vec_StrEntry(vTargets, pRoot->
Id);
877 Vec_PtrPush( vNodes, Abc_ObjNot(pRoot) );
879 Vec_PtrPush( vNodes, pRoot );
882 Sim_TraverseNodes_rec( pFanout, vTargets, vNodes );
900 if ( Abc_NodeIsTravIdCurrent(pRoot) )
902 if ( !Abc_NodeIsTravIdPrevious(pRoot) )
904 Abc_NodeSetTravIdCurrent( pRoot );
906 Sim_CollectNodes_rec( pFanin, vField );
907 if ( !Abc_ObjIsCo(pRoot) )
908 pRoot->
pData = (
void *)(ABC_PTRUINT_T)Vec_PtrSize(vField);
909 Vec_PtrPush( vField, pRoot );
925 Abc_Obj_t * pObj, * pFanin0, * pFanin1, * pDisproved;
927 unsigned * pUnsigned, * pUnsignedF;
928 int i, k, Phase, fCompl;
934 if ( Abc_ObjIsCi(pObj) )
936 pUnsigned = (
unsigned *)Vec_PtrEntry( vSims, i );
937 for ( k = 0; k < Vec_PtrSize(vNodes); k++ )
938 pUnsigned[k] = (
unsigned)(ABC_PTRUINT_T)pObj->
pCopy;
941 if ( Abc_ObjIsCo(pObj) )
943 pUnsigned = (
unsigned *)Vec_PtrEntry( vSims, i );
944 pUnsignedF = (
unsigned *)Vec_PtrEntry( vSims, (
int)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->pData );
945 if ( Abc_ObjFaninC0(pObj) )
946 for ( k = 0; k < Vec_PtrSize(vNodes); k++ )
947 pUnsigned[k] = ~pUnsignedF[k];
949 for ( k = 0; k < Vec_PtrSize(vNodes); k++ )
950 pUnsigned[k] = pUnsignedF[k];
952 for ( k = 0; k < Vec_PtrSize(vNodes); k++ )
954 if ( pUnsigned[k] == (
unsigned)(ABC_PTRUINT_T)pObj->
pData )
956 pDisproved = (
Abc_Obj_t *)Vec_PtrEntry( vNodes, k );
957 fCompl = Abc_ObjIsComplement(pDisproved);
958 pDisproved = Abc_ObjRegular(pDisproved);
959 Phase = Vec_StrEntry( vTargets, pDisproved->
Id );
964 Vec_StrWriteEntry( vTargets, pDisproved->
Id, (
char)Phase );
969 pFanin0 = Abc_ObjFanin0(pObj);
970 pFanin1 = Abc_ObjFanin1(pObj);
typedefABC_NAMESPACE_IMPL_START struct Abc_RRMan_t_ Abc_RRMan_t
DECLARATIONS ///.
int Abc_NtkRR(Abc_Ntk_t *pNtk, int nFaninLevels, int nFanoutLevels, int fUseFanouts, int fVerbose)
FUNCTION DEFINITIONS ///.
Vec_Str_t * Abc_NtkRRSimulate(Abc_Ntk_t *pNtk)
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachCo(pNtk, pCo, i)
ABC_DLL int Abc_NtkIsDfsOrdered(Abc_Ntk_t *pNtk)
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 int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
#define Abc_ObjForEachFanin(pObj, pFanin, i)
#define Abc_ObjForEachFanout(pObj, pFanout, i)
struct Abc_Aig_t_ Abc_Aig_t
ABC_DLL int Abc_NtkMiterProve(Abc_Ntk_t **ppNtk, void *pParams)
FUNCTION DEFINITIONS ///.
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL void Abc_NtkAddDummyPoNames(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
ABC_DLL Abc_Ntk_t * Abc_NtkMiter(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fComb, int nPartSize, int fImplic, int fMulti)
FUNCTION DEFINITIONS ///.
ABC_DLL int Abc_AigLevel(Abc_Ntk_t *pNtk)
#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 void Abc_NtkReassignIds(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_AigReplace(Abc_Aig_t *pMan, Abc_Obj_t *pOld, Abc_Obj_t *pNew, int fUpdateLevel)
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_NtkAddDummyPiNames(Abc_Ntk_t *pNtk)
#define Abc_NtkForEachNode(pNtk, pNode, i)
#define ABC_ALLOC(type, num)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
struct Vec_Str_t_ Vec_Str_t
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
void Prove_ParamsSetDefault(Prove_Params_t *pParams)
FUNCTION DEFINITIONS ///.
struct Prove_ParamsStruct_t_ Prove_Params_t
Vec_Ptr_t * Sim_UtilInfoAlloc(int nSize, int nWords, int fClean)
FUNCTION DEFINITIONS ///.
#define SIM_RANDOM_UNSIGNED
#define Vec_PtrForEachEntryStop(Type, vVec, pEntry, i, Stop)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.