summaryrefslogtreecommitdiffstats
path: root/src/opt/res/resDivs.c
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2007-01-15 20:01:00 -0800
committerAlan Mishchenko <alanmi@berkeley.edu>2007-01-15 20:01:00 -0800
commit76bcf6b25411e1b0d73e5dff6c8fd3e2f4bab9e1 (patch)
tree5956241cd46a10ca868092acec7f94a3fa6df2ad /src/opt/res/resDivs.c
parent93aedd2c5155478de7602db4db2c2df4c73e32e0 (diff)
downloadabc-76bcf6b25411e1b0d73e5dff6c8fd3e2f4bab9e1.tar.gz
abc-76bcf6b25411e1b0d73e5dff6c8fd3e2f4bab9e1.tar.bz2
abc-76bcf6b25411e1b0d73e5dff6c8fd3e2f4bab9e1.zip
Version abc70115_2
Diffstat (limited to 'src/opt/res/resDivs.c')
-rw-r--r--src/opt/res/resDivs.c199
1 files changed, 199 insertions, 0 deletions
diff --git a/src/opt/res/resDivs.c b/src/opt/res/resDivs.c
new file mode 100644
index 00000000..42ec8955
--- /dev/null
+++ b/src/opt/res/resDivs.c
@@ -0,0 +1,199 @@
+/**CFile****************************************************************
+
+ FileName [resDivs.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [Resynthesis package.]
+
+ Synopsis [Collect divisors for the given window.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - January 15, 2007.]
+
+ Revision [$Id: resDivs.c,v 1.00 2007/01/15 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "abc.h"
+#include "res.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+static int Res_WinVisitMffc( Res_Win_t * p );
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Adds candidate divisors of the node to its window.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Res_WinDivisors( Res_Win_t * p, int nLevDivMax )
+{
+ Abc_Obj_t * pObj, * pFanout, * pFanin;
+ int i, k, f, m;
+
+ p->nLevDivMax = nLevDivMax;
+
+ // mark the leaves and the internal nodes
+ Vec_PtrForEachEntry( p->vLeaves, pObj, i )
+ pObj->fMarkA = 1;
+ Vec_VecForEachEntry( p->vLevels, pObj, i, k )
+ pObj->fMarkA = 1;
+
+ // prepare the new trav ID
+ Abc_NtkIncrementTravId( p->pNode->pNtk );
+ // mark the TFO of the node (does not increment trav ID)
+ Res_WinVisitNodeTfo( p );
+ // mark the MFFC of the node (does not increment trav ID)
+ Res_WinVisitMffc( p );
+
+ // go through all the legal levels and check if their fanouts can be divisors
+ Vec_VecForEachEntryStartStop( p->vLevels, pObj, i, k, 0, p->nLevDivMax - 1 )
+ {
+ // skip nodes in the TFO or in the MFFC of node
+ if ( Abc_NodeIsTravIdCurrent(pObj) )
+ continue;
+ // consider fanouts of this node
+ Abc_ObjForEachFanout( pObj, pFanout, f )
+ {
+ // skip COs
+ if ( !Abc_ObjIsNode(pFanout) )
+ continue;
+ // skip nodes in the TFO or in the MFFC of node
+ if ( Abc_NodeIsTravIdCurrent(pFanout) )
+ continue;
+ // skip nodes that are already added
+ if ( pFanout->fMarkA )
+ continue;
+ // skip nodes with large level
+ if ( (int)pFanout->Level > p->nLevDivMax )
+ continue;
+ // skip nodes whose fanins are not in the cone
+ Abc_ObjForEachFanin( pFanout, pFanin, m )
+ if ( !pFanin->fMarkA )
+ break;
+ if ( m < Abc_ObjFaninNum(pFanin) )
+ continue;
+ // add the node
+ Res_WinAddNode( p, pFanout );
+ }
+ }
+
+ // unmark the leaves and the internal nodes
+ Vec_PtrForEachEntry( p->vLeaves, pObj, i )
+ pObj->fMarkA = 0;
+ Vec_VecForEachEntry( p->vLevels, pObj, i, k )
+ pObj->fMarkA = 0;
+
+ // collect the divisors below the line
+ Vec_PtrClear( p->vDivs );
+ // collect the node fanins first
+ Abc_ObjForEachFanin( pObj, pFanin, m )
+ {
+ Vec_PtrPush( p->vDivs, pFanin );
+ Abc_NodeSetTravIdCurrent( pFanin );
+ }
+ // collect the remaining leaves
+ Vec_PtrForEachEntry( p->vLeaves, pObj, i )
+ if ( !Abc_NodeIsTravIdCurrent(pObj) )
+ Vec_PtrPush( p->vDivs, pObj );
+ // collect remaining unvisited divisors
+ Vec_VecForEachEntryStartStop( p->vLevels, pObj, i, k, p->nLevLeaves, p->nLevDivMax )
+ if ( !Abc_NodeIsTravIdCurrent(pObj) )
+ Vec_PtrPush( p->vDivs, pObj );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Dereferences the node's MFFC.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Res_NodeDeref_rec( Abc_Obj_t * pNode )
+{
+ Abc_Obj_t * pFanin;
+ int i, Counter = 1;
+ if ( Abc_ObjIsCi(pNode) )
+ return 0;
+ Abc_NodeSetTravIdCurrent( pNode );
+ Abc_ObjForEachFanin( pNode, pFanin, i )
+ {
+ assert( pFanin->vFanouts.nSize > 0 );
+ if ( --pFanin->vFanouts.nSize == 0 )
+ Counter += Res_NodeDeref_rec( pFanin );
+ }
+ return Counter;
+}
+
+/**Function*************************************************************
+
+ Synopsis [References the node's MFFC.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Res_NodeRef_rec( Abc_Obj_t * pNode )
+{
+ Abc_Obj_t * pFanin;
+ int i, Counter = 1;
+ if ( Abc_ObjIsCi(pNode) )
+ return 0;
+ Abc_ObjForEachFanin( pNode, pFanin, i )
+ {
+ if ( pFanin->vFanouts.nSize++ == 0 )
+ Counter += Res_NodeRef_rec( pFanin );
+ }
+ return Counter;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Labels MFFC of the node with the current trav ID.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Res_WinVisitMffc( Res_Win_t * p )
+{
+ int Count1, Count2;
+ // dereference the node (mark with the current trav ID)
+ Count1 = Res_NodeDeref_rec( p->pNode );
+ // reference it back
+ Count2 = Res_NodeRef_rec( p->pNode );
+ assert( Count1 == Count2 );
+ return Count1;
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+