34 #define RST_RANDOM_UNSIGNED ((((unsigned)rand()) << 24) ^ (((unsigned)rand()) << 12) ^ ((unsigned)rand()))
126 pManRst->
pNtk = pNtk;
166 if ( pGraph == NULL )
195 printf(
"Abc_NtkRefactor: The network check has failed.\n" );
298 for ( pCut = pCutList; pCut; pCut = pCut->
pNext )
326 int nNodesSaved, nNodesAdded;
327 int Required, nMaxSize, clk, i;
328 int fVeryVerbose = 0;
337 for ( i = 0; i < (int)pCut->
nLeaves; i++ )
433 if ( pGraph == NULL || nNodesAdded == -1 || (nNodesAdded == nNodesSaved && !p->
fUseZeros) )
450 p->
nLastGain = nNodesSaved - nNodesAdded;
458 printf(
"Cone = %2d. ", p->
vLeaves->nSize );
461 printf(
"MFFC = %2d. ", nNodesSaved );
462 printf(
"Add = %2d. ", nNodesAdded );
486 Abc_Obj_t * pNode1, * pNode2, * pNode3, * pTemp;
487 int LeftBound = 0, RightBound, i;
490 assert( LeftBound <= RightBound );
491 if ( LeftBound == RightBound )
501 if ( pNode1 == NULL )
504 for ( i = RightBound; i >= LeftBound; i-- )
510 if ( pNode3 == NULL )
515 if ( pNode1 && pNode3 )
521 if ( pNode3 == pNode2 )
530 if ( pNode1 && pNode3 )
536 if ( eNode3.Node == eNode2.Node )
559 int i, NodeOld, NodeNew;
561 for ( i = vEdges->nSize-2; i >= 0; i-- )
567 vEdges->pArray[i+1] = vEdges->pArray[i];
571 vEdges->pArray[i+1] = Edge;
587 Dec_Edge_t eNode1, eNode2, eNode3, eResult, eQuit = { 0, 2006 };
588 Abc_Obj_t * pNode1, * pNode2, * pNode3, * pNode4, * pTemp;
592 int Level1, Level2, Level3, Level4;
593 int i, Index, fCompl, Type;
615 if ( eResult.Node == eQuit.Node )
648 if ( pNode1 && pNode2 )
669 if ( *pnNodesAdded > nNodesSaved )
682 eResult.fCompl ^= fCompl;
704 if ( pNode1 && pNode2 )
722 if ( !pNode1 || !pNode2 )
723 (*pnNodesAdded) += 2;
724 else if ( Type == 0 )
742 if ( *pnNodesAdded > nNodesSaved )
755 eResult.fCompl ^= fCompl;
760 DdNode * bLocal, * bVar, * bCofT, * bCofE;
764 bVar = pManRst->
dd->
vars[0];
771 bVar = pManRst->
dd->
vars[1];
778 bVar = pManRst->
dd->
vars[2];
817 if ( pNode1 && pNode2 && pNode3 )
840 if ( !pNode1 || !pNode2 )
848 if ( !pNode1 || !pNode3 )
859 if ( !pNode1 || !pNode2 )
867 if ( !pNode1 || !pNode3 )
876 if ( *pnNodesAdded > nNodesSaved )
885 eResult.fCompl ^= fCompl;
916 pNode->
pFunc = pLeaf;
923 if ( gEdge.Node > 1000 )
970 pParams->
fDag = fDag;
975 if ( pParams->
fDrop )
1023 for ( i = 0; i < 20; i++ )
1069 printf(
"Refactoring statistics:\n" );
1103 for ( i = 0; i < (int)pCut->
nLeaves; i++ )
1106 if ( pNode == NULL )
1202 unsigned uData0, uData1, uData;
1209 pObj->
pData = (
void *)(ABC_PTRUINT_T)uData;
1218 pObj->
pData = (
void *)(ABC_PTRUINT_T)uData;
1258 else if ( uRoot == ~(
unsigned)0 )
1282 unsigned uRoot, uNode;
1288 for ( i = 0; i < nNodes; i++ )
1291 if ( uRoot == uNode || uRoot == ~uNode )
1301 if ( (uRoot & uNode) == 0 )
1303 else if ( (uRoot & ~uNode) == 0 )
1329 for ( i = 0; i < vOnes->nSize; i++ )
1330 for ( k = i+1; k < vOnes->nSize; k++ )
1331 if ( ~uRoot == ((
unsigned)vOnes->pArray[i] | (
unsigned)vOnes->pArray[k]) )
1390 assert( nNodesSaved > 0 );
1412 if ( nNodesSaved == 1 )
1423 if ( nNodesSaved == 2 )
1434 if ( nNodesSaved == 3 )
1469 for ( pCut = pCutList; pCut; pCut = pCut->
pNext )
1470 nCuts += (
int)(pCut->
nLeaves > 3);
1471 printf(
"-----------------------------------\n" );
1472 printf(
"Node %6d : Factor-cuts = %5d.\n", pNode->
Id, nCuts );
1475 for ( pCut = pCutList; pCut; pCut = pCut->
pNext )
1480 if ( pGraph == NULL )
1486 pGraphBest = pGraph;
DdNode * Abc_NodeConeBdd(DdManager *dd, DdNode **pbVars, Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVisited)
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
static unsigned Dec_EdgeToInt(Dec_Edge_t eEdge)
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
#define CUDD_UNIQUE_SLOTS
ABC_DLL Abc_Obj_t * Abc_AigAndLookup(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Dec_Graph_t * Abc_NodeMffcSingleVar(Abc_ManRst_t *p, Vec_Int_t *vSims, int nNodes, Vec_Int_t *vOnes)
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
static int Dec_GraphNodeNum(Dec_Graph_t *pGraph)
void Dsd_ManagerStop(Dsd_Manager_t *dMan)
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
static Dec_Edge_t Dec_GraphAddNodeMux(Dec_Graph_t *pGraph, Dec_Edge_t eEdgeC, Dec_Edge_t eEdgeT, Dec_Edge_t eEdgeE, int Type)
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
#define Cudd_IsConstant(node)
#define Cudd_Regular(node)
static Abc_ManRst_t * Abc_NtkManRstStart(int nCutMax, int fUpdateLevel, int fUseZeros, int fVerbose)
int Dsd_NodeReadDecsNum(Dsd_Node_t *p)
int Abc_NodeCheckFull(Abc_ManRst_t *p, Dec_Graph_t *pGraph)
static Dec_Edge_t Dec_EdgeCreate(int Node, int fCompl)
FUNCTION DEFINITIONS ///.
void Dec_GraphUpdateNetwork(Abc_Obj_t *pRoot, Dec_Graph_t *pGraph, int fUpdateLevel, int nGain)
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
ABC_DLL Abc_Obj_t * Abc_AigMuxLookup(Abc_Aig_t *pMan, Abc_Obj_t *pC, Abc_Obj_t *pT, Abc_Obj_t *pE, int *pType)
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
#define ABC_ALLOC(type, num)
typedefABC_NAMESPACE_HEADER_START struct Dec_Edge_t_ Dec_Edge_t
INCLUDES ///.
static Dec_Graph_t * Abc_NodeRestructureCut(Abc_ManRst_t *p, Abc_Obj_t *pNode, Cut_Cut_t *pCut)
ABC_DLL int Abc_NodeMffcLabelAig(Abc_Obj_t *pNode)
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
static abctime Abc_Clock()
static int Abc_NodeIsTravIdPrevious(Abc_Obj_t *p)
void Cut_NodeSetTriv(Cut_Man_t *p, int Node)
static int Abc_MaxInt(int a, int b)
#define RST_RANDOM_UNSIGNED
DECLARATIONS ///.
static Abc_Obj_t * Abc_NtkObj(Abc_Ntk_t *pNtk, int i)
void Abc_NodeEdgeDsdPushOrdered(Dec_Graph_t *pGraph, Vec_Int_t *vEdges, int Edge)
static int Vec_PtrSize(Vec_Ptr_t *p)
void Abc_NodeEdgeDsdPermute(Dec_Graph_t *pGraph, Abc_ManRst_t *pManRst, Vec_Int_t *vEdges, int fExor)
int Abc_NodeResubMffc_rec(Abc_Obj_t *pNode)
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
void Cut_ManSetFanoutCounts(Cut_Man_t *p, Vec_Int_t *vFanCounts)
static Dec_Edge_t Dec_IntToEdge(unsigned Edge)
static Dec_Graph_t * Dec_GraphCreateConst1()
ABC_DLL void Abc_NtkStopReverseLevels(Abc_Ntk_t *pNtk)
static Dec_Graph_t * Abc_NodeRestructure(Abc_ManRst_t *p, Abc_Obj_t *pNode, Cut_Cut_t *pCutList)
static Dec_Edge_t Dec_GraphAddNodeAnd(Dec_Graph_t *pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1)
ABC_DLL void Abc_NtkReassignIds(Abc_Ntk_t *pNtk)
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
#define Cudd_IsComplement(node)
DdNode * Cudd_Cofactor(DdManager *dd, DdNode *f, DdNode *g)
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
void Abc_RestructNodeDivisors(Abc_ManRst_t *p, Abc_Obj_t *pRoot, int nNodesSaved)
ABC_DLL int Abc_ObjRequiredLevel(Abc_Obj_t *pObj)
static void * Vec_PtrEntryLast(Vec_Ptr_t *p)
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
void Cut_ManStop(Cut_Man_t *p)
static int Vec_IntEntry(Vec_Int_t *p, int i)
static Dec_Graph_t * Dec_GraphCreateConst0()
Cut_Man_t * Cut_ManStart(Cut_Params_t *pParams)
FUNCTION DEFINITIONS ///.
static Cut_Man_t * Abc_NtkStartCutManForRestruct(Abc_Ntk_t *pNtk, int nCutMax, int fDag)
#define ABC_NAMESPACE_IMPL_END
ABC_DLL int Abc_NodeMffcSize(Abc_Obj_t *pNode)
FUNCTION DEFINITIONS ///.
Dec_Graph_t * Abc_NodeMffcConstants(Abc_ManRst_t *p, Vec_Int_t *vSims)
DdManager * Cudd_Init(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int cacheSize, unsigned long maxMemory)
int Abc_NodeResubMffc(Abc_ManRst_t *p, Vec_Ptr_t *vDecs, int nLeaves, Abc_Obj_t *pRoot)
ABC_DLL void * Abc_NodeGetCutsRecursive(void *p, Abc_Obj_t *pObj, int fDag, int fTree)
static void Vec_IntPush(Vec_Int_t *p, int Entry)
STRUCTURE DEFINITIONS ///.
static Dec_Edge_t Dec_GraphAddNodeXor(Dec_Graph_t *pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1, int Type)
static Dec_Graph_t * Abc_NodeEvaluateDsd(Abc_ManRst_t *pManRst, Dsd_Node_t *pNodeDsd, Abc_Obj_t *pRoot, int Required, int nNodesSaved, int *pnNodesAdded)
ABC_DLL void Abc_NtkStartReverseLevels(Abc_Ntk_t *pNtk, int nMaxLevelIncrease)
Dsd_Manager_t * Dsd_ManagerStart(DdManager *dd, int nSuppMax, int fVerbose)
FUNCTION DECLARATIONS ///.
Dec_Edge_t Abc_NodeEvaluateDsd_rec(Dec_Graph_t *pGraph, Abc_ManRst_t *pManRst, Dsd_Node_t *pNodeDsd, int Required, int nNodesSaved, int *pnNodesAdded)
void Abc_NodeMffcSimulate(Vec_Ptr_t *vDecs, int nLeaves, Vec_Int_t *vRands, Vec_Int_t *vSims)
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
#define Abc_NtkForEachNode(pNtk, pNode, i)
Dec_Graph_t * Abc_NodeResubEval(Abc_ManRst_t *p, Abc_Obj_t *pRoot, Cut_Cut_t *pCut)
static int Abc_NodeIsPersistant(Abc_Obj_t *pNode)
static void Dec_GraphSetRoot(Dec_Graph_t *pGraph, Dec_Edge_t eRoot)
#define Dsd_IsComplement(p)
MACRO DEFINITIONS ///.
#define ABC_NAMESPACE_IMPL_START
DdNode * Dsd_TreeGetPrimeFunction(DdManager *dd, Dsd_Node_t *pNode)
FUNCTION DEFINITIONS ///.
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Dec_Graph_t * Abc_NodeMffcSingleNode(Abc_ManRst_t *p, Vec_Int_t *vSims, int nNodes, Vec_Int_t *vOnes)
static Dec_Graph_t * Dec_GraphCreate(int nLeaves)
#define Dsd_NodeForEachChild(Node, Index, Child)
ITERATORS ///.
static Dec_Edge_t Dec_GraphAddNodeOr(Dec_Graph_t *pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1)
static int Vec_IntEntryLast(Vec_Int_t *p)
static int Abc_NodeIsTravIdCurrent(Abc_Obj_t *p)
DdNode * Dsd_NodeReadFunc(Dsd_Node_t *p)
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
int Abc_NtkRestructure(Abc_Ntk_t *pNtk, int nCutMax, int fUpdateLevel, int fUseZeros, int fVerbose)
FUNCTION DEFINITIONS ///.
static int Vec_IntSize(Vec_Int_t *p)
#define Vec_PtrForEachEntryStop(Type, vVec, pEntry, i, Stop)
#define Abc_ObjForEachFanout(pObj, pFanout, i)
#define Abc_NtkForEachCi(pNtk, pCi, i)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
#define Dec_GraphForEachLeaf(pGraph, pLeaf, i)
ITERATORS ///.
Dec_Graph_t * Abc_NodeMffcDoubleNode(Abc_ManRst_t *p, Vec_Int_t *vSims, int nNodes, Vec_Int_t *vOnes)
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
static void Abc_NtkIncrementTravId(Abc_Ntk_t *p)
static int Dec_GraphLeaveNum(Dec_Graph_t *pGraph)
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
static void Dec_GraphFree(Dec_Graph_t *pGraph)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
static Dec_Graph_t * Abc_NodeResubstitute(Abc_ManRst_t *p, Abc_Obj_t *pNode, Cut_Cut_t *pCutList)
ABC_DLL Vec_Int_t * Abc_NtkFanoutCounts(Abc_Ntk_t *pNtk)
int Cudd_zddVarsFromBddVars(DdManager *dd, int multiplicity)
static Abc_Obj_t * Abc_ObjNotCond(Abc_Obj_t *p, int c)
static void Vec_PtrClear(Vec_Ptr_t *p)
static Dec_Node_t * Dec_GraphNode(Dec_Graph_t *pGraph, int i)
enum Dsd_Type_t_ Dsd_Type_t
static Abc_Obj_t * Abc_ObjNot(Abc_Obj_t *p)
ABC_DLL Abc_Obj_t * Abc_AigXorLookup(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1, int *pType)
static void Vec_IntFree(Vec_Int_t *p)
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Dsd_Type_t Dsd_NodeReadType(Dsd_Node_t *p)
FUNCTION DEFINITIONS ///.
Dsd_Node_t * Dsd_DecomposeOne(Dsd_Manager_t *pDsdMan, DdNode *bFunc)
static void Vec_IntClear(Vec_Int_t *p)
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
void Dsd_TreeNodeGetInfoOne(Dsd_Node_t *pNode, int *DepthMax, int *GateSizeMax)
static void Abc_NtkManRstPrintStats(Abc_ManRst_t *p)
int Abc_Abc_NodeResubCollectDivs(Abc_ManRst_t *p, Abc_Obj_t *pRoot, Cut_Cut_t *pCut)
static void Abc_NodeSetTravIdCurrent(Abc_Obj_t *p)
int Cudd_DagSize(DdNode *node)
static void Vec_PtrFree(Vec_Ptr_t *p)
static void Abc_NtkManRstStop(Abc_ManRst_t *p)