abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
aigWin.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [aigWin.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [AIG package.]
8 
9  Synopsis [Window computation.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: aigWin.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "aig.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Evaluate the cost of removing the node from the set of leaves.]
37 
38  Description [Returns the number of new leaves that will be brought in.
39  Returns large number if the node cannot be removed from the set of leaves.]
40 
41  SideEffects []
42 
43  SeeAlso []
44 
45 ***********************************************************************/
46 static inline int Aig_NodeGetLeafCostOne( Aig_Obj_t * pNode, int nFanoutLimit )
47 {
48  int Cost;
49  // make sure the node is in the construction zone
50  assert( pNode->fMarkA );
51  // cannot expand over the PI node
52  if ( Aig_ObjIsCi(pNode) )
53  return 999;
54  // get the cost of the cone
55  Cost = (!Aig_ObjFanin0(pNode)->fMarkA) + (!Aig_ObjFanin1(pNode)->fMarkA);
56  // always accept if the number of leaves does not increase
57  if ( Cost < 2 )
58  return Cost;
59  // skip nodes with many fanouts
60  if ( (int)pNode->nRefs > nFanoutLimit )
61  return 999;
62  // return the number of nodes that will be on the leaves if this node is removed
63  return Cost;
64 }
65 
66 /**Function*************************************************************
67 
68  Synopsis [Builds reconvergence-driven cut by changing one leaf at a time.]
69 
70  Description [This procedure looks at the current leaves and tries to change
71  one leaf at a time in such a way that the cut grows as little as possible.
72  In evaluating the fanins, this procedure looks only at their immediate
73  predecessors (this is why it is called a one-level construction procedure).]
74 
75  SideEffects []
76 
77  SeeAlso []
78 
79 ***********************************************************************/
80 int Aig_ManFindCut_int( Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited, int nSizeLimit, int nFanoutLimit )
81 {
82  Aig_Obj_t * pNode, * pFaninBest, * pNext;
83  int CostBest, CostCur, i;
84  // find the best fanin
85  CostBest = 100;
86  pFaninBest = NULL;
87 //printf( "Evaluating fanins of the cut:\n" );
88  Vec_PtrForEachEntry( Aig_Obj_t *, vFront, pNode, i )
89  {
90  CostCur = Aig_NodeGetLeafCostOne( pNode, nFanoutLimit );
91 //printf( " Fanin %s has cost %d.\n", Aig_ObjName(pNode), CostCur );
92  if ( CostBest > CostCur ||
93  (CostBest == CostCur && pNode->Level > pFaninBest->Level) )
94  {
95  CostBest = CostCur;
96  pFaninBest = pNode;
97  }
98  if ( CostBest == 0 )
99  break;
100  }
101  if ( pFaninBest == NULL )
102  return 0;
103  assert( CostBest < 3 );
104  if ( Vec_PtrSize(vFront) - 1 + CostBest > nSizeLimit )
105  return 0;
106  assert( Aig_ObjIsNode(pFaninBest) );
107  // remove the node from the array
108  Vec_PtrRemove( vFront, pFaninBest );
109 //printf( "Removing fanin %s.\n", Aig_ObjName(pFaninBest) );
110 
111  // add the left child to the fanins
112  pNext = Aig_ObjFanin0(pFaninBest);
113  if ( !pNext->fMarkA )
114  {
115 //printf( "Adding fanin %s.\n", Aig_ObjName(pNext) );
116  pNext->fMarkA = 1;
117  Vec_PtrPush( vFront, pNext );
118  Vec_PtrPush( vVisited, pNext );
119  }
120  // add the right child to the fanins
121  pNext = Aig_ObjFanin1(pFaninBest);
122  if ( !pNext->fMarkA )
123  {
124 //printf( "Adding fanin %s.\n", Aig_ObjName(pNext) );
125  pNext->fMarkA = 1;
126  Vec_PtrPush( vFront, pNext );
127  Vec_PtrPush( vVisited, pNext );
128  }
129  assert( Vec_PtrSize(vFront) <= nSizeLimit );
130  // keep doing this
131  return 1;
132 }
133 
134 /**Function*************************************************************
135 
136  Synopsis [Computes one sequential cut of the given size.]
137 
138  Description []
139 
140  SideEffects []
141 
142  SeeAlso []
143 
144 ***********************************************************************/
145 void Aig_ManFindCut( Aig_Obj_t * pRoot, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited, int nSizeLimit, int nFanoutLimit )
146 {
147  Aig_Obj_t * pNode;
148  int i;
149 
150  assert( !Aig_IsComplement(pRoot) );
151  assert( Aig_ObjIsNode(pRoot) );
152  assert( Aig_ObjChild0(pRoot) );
153  assert( Aig_ObjChild1(pRoot) );
154 
155  // start the cut
156  Vec_PtrClear( vFront );
157  Vec_PtrPush( vFront, Aig_ObjFanin0(pRoot) );
158  Vec_PtrPush( vFront, Aig_ObjFanin1(pRoot) );
159 
160  // start the visited nodes
161  Vec_PtrClear( vVisited );
162  Vec_PtrPush( vVisited, pRoot );
163  Vec_PtrPush( vVisited, Aig_ObjFanin0(pRoot) );
164  Vec_PtrPush( vVisited, Aig_ObjFanin1(pRoot) );
165 
166  // mark these nodes
167  assert( !pRoot->fMarkA );
168  assert( !Aig_ObjFanin0(pRoot)->fMarkA );
169  assert( !Aig_ObjFanin1(pRoot)->fMarkA );
170  pRoot->fMarkA = 1;
171  Aig_ObjFanin0(pRoot)->fMarkA = 1;
172  Aig_ObjFanin1(pRoot)->fMarkA = 1;
173 
174  // compute the cut
175  while ( Aig_ManFindCut_int( vFront, vVisited, nSizeLimit, nFanoutLimit ) );
176  assert( Vec_PtrSize(vFront) <= nSizeLimit );
177 
178  // clean the visit markings
179  Vec_PtrForEachEntry( Aig_Obj_t *, vVisited, pNode, i )
180  pNode->fMarkA = 0;
181 }
182 
183 ////////////////////////////////////////////////////////////////////////
184 /// END OF FILE ///
185 ////////////////////////////////////////////////////////////////////////
186 
187 
189 
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
unsigned Level
Definition: aig.h:82
static Aig_Obj_t * Aig_ObjChild0(Aig_Obj_t *pObj)
Definition: aig.h:310
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
unsigned int fMarkA
Definition: aig.h:79
void Aig_ManFindCut(Aig_Obj_t *pRoot, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited, int nSizeLimit, int nFanoutLimit)
Definition: aigWin.c:145
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
int Aig_ManFindCut_int(Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited, int nSizeLimit, int nFanoutLimit)
Definition: aigWin.c:80
static void Vec_PtrRemove(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:714
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static Aig_Obj_t * Aig_ObjChild1(Aig_Obj_t *pObj)
Definition: aig.h:311
Definition: aig.h:69
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
static ABC_NAMESPACE_IMPL_START int Aig_NodeGetLeafCostOne(Aig_Obj_t *pNode, int nFanoutLimit)
DECLARATIONS ///.
Definition: aigWin.c:46
unsigned int nRefs
Definition: aig.h:81