ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
aigWin.c
Go to the documentation of this file.
1
20
21#include "aig.h"
22
24
25
29
33
46static 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
80int 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
145void 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
186
187
189
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManFindCut(Aig_Obj_t *pRoot, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited, int nSizeLimit, int nFanoutLimit)
Definition aigWin.c:145
int Aig_ManFindCut_int(Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited, int nSizeLimit, int nFanoutLimit)
Definition aigWin.c:80
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
unsigned int nRefs
Definition aig.h:81
unsigned int fMarkA
Definition aig.h:79
unsigned Level
Definition aig.h:82
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55