ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cnfMap.c
Go to the documentation of this file.
1
20
21#include "cnf.h"
22
24
25
29
33
45void Cnf_CutAssignAreaFlow( Cnf_Man_t * p, Dar_Cut_t * pCut, int * pAreaFlows )
46{
47 Aig_Obj_t * pLeaf;
48 int i;
49 pCut->Value = 0;
50// pCut->uSign = 100 * Cnf_CutSopCost( p, pCut );
51 pCut->uSign = 10 * Cnf_CutSopCost( p, pCut );
52 Dar_CutForEachLeaf( p->pManAig, pCut, pLeaf, i )
53 {
54 pCut->Value += pLeaf->nRefs;
55 if ( !Aig_ObjIsNode(pLeaf) )
56 continue;
57 assert( pLeaf->nRefs > 0 );
58 pCut->uSign += pAreaFlows[pLeaf->Id] / (pLeaf->nRefs? pLeaf->nRefs : 1);
59 }
60}
61
73int Cnf_CutSuperAreaFlow( Vec_Ptr_t * vSuper, int * pAreaFlows )
74{
75 Aig_Obj_t * pLeaf;
76 int i, nAreaFlow;
77 nAreaFlow = 100 * (Vec_PtrSize(vSuper) + 1);
78 Vec_PtrForEachEntry( Aig_Obj_t *, vSuper, pLeaf, i )
79 {
80 pLeaf = Aig_Regular(pLeaf);
81 if ( !Aig_ObjIsNode(pLeaf) )
82 continue;
83 assert( pLeaf->nRefs > 0 );
84 nAreaFlow += pAreaFlows[pLeaf->Id] / (pLeaf->nRefs? pLeaf->nRefs : 1);
85 }
86 return nAreaFlow;
87}
88
101{
102 Vec_Ptr_t * vSuper;
103 Aig_Obj_t * pObj;
104 Dar_Cut_t * pCut, * pCutBest;
105 int i, k, AreaFlow, * pAreaFlows;
106 // allocate area flows
107 pAreaFlows = ABC_ALLOC( int, Aig_ManObjNumMax(p->pManAig) );
108 memset( pAreaFlows, 0, sizeof(int) * Aig_ManObjNumMax(p->pManAig) );
109 // visit the nodes in the topological order and update their best cuts
110 vSuper = Vec_PtrAlloc( 100 );
111 Aig_ManForEachNode( p->pManAig, pObj, i )
112 {
113 // go through the cuts
114 pCutBest = NULL;
115 Dar_ObjForEachCut( pObj, pCut, k )
116 {
117 pCut->fBest = 0;
118 if ( k == 0 )
119 continue;
120 Cnf_CutAssignAreaFlow( p, pCut, pAreaFlows );
121 if ( pCutBest == NULL || pCutBest->uSign > pCut->uSign ||
122 (pCutBest->uSign == pCut->uSign && pCutBest->Value < pCut->Value) )
123 pCutBest = pCut;
124 }
125 // check the big cut
126// Aig_ObjCollectSuper( pObj, vSuper );
127 // get the area flow of this cut
128// AreaFlow = Cnf_CutSuperAreaFlow( vSuper, pAreaFlows );
129 AreaFlow = ABC_INFINITY;
130 if ( AreaFlow >= (int)pCutBest->uSign )
131 {
132 pAreaFlows[pObj->Id] = pCutBest->uSign;
133 pCutBest->fBest = 1;
134 }
135 else
136 {
137 pAreaFlows[pObj->Id] = AreaFlow;
138 pObj->fMarkB = 1; // mark the special node
139 }
140 }
141 Vec_PtrFree( vSuper );
142 ABC_FREE( pAreaFlows );
143
144/*
145 // compute the area of mapping
146 AreaFlow = 0;
147 Aig_ManForEachCo( p->pManAig, pObj, i )
148 AreaFlow += Dar_ObjBestCut(Aig_ObjFanin0(pObj))->uSign / 100 / Aig_ObjFanin0(pObj)->nRefs;
149 printf( "Area of the network = %d.\n", AreaFlow );
150*/
151}
152
153
154
155#if 0
156
168void Aig_CutDeref( Aig_Man_t * p, Dar_Cut_t * pCut )
169{
170 Aig_Obj_t * pLeaf;
171 int i;
172 Dar_CutForEachLeaf( p, pCut, pLeaf, i )
173 {
174 assert( pLeaf->nRefs > 0 );
175 if ( --pLeaf->nRefs > 0 || !Aig_ObjIsAnd(pLeaf) )
176 continue;
177 Aig_CutDeref( p, Aig_ObjBestCut(pLeaf) );
178 }
179}
180
192int Aig_CutRef( Aig_Man_t * p, Dar_Cut_t * pCut )
193{
194 Aig_Obj_t * pLeaf;
195 int i, Area = pCut->Value;
196 Dar_CutForEachLeaf( p, pCut, pLeaf, i )
197 {
198 assert( pLeaf->nRefs >= 0 );
199 if ( pLeaf->nRefs++ > 0 || !Aig_ObjIsAnd(pLeaf) )
200 continue;
201 Area += Aig_CutRef( p, Aig_ObjBestCut(pLeaf) );
202 }
203 return Area;
204}
205
217int Cnf_CutArea( Aig_Man_t * p, Dar_Cut_t * pCut )
218{
219 int Area;
220 Area = Aig_CutRef( p, pCut );
221 Aig_CutDeref( p, pCut );
222 return Area;
223}
224
236static inline int Cnf_CutCompare( Dar_Cut_t * pC0, Dar_Cut_t * pC1 )
237{
238 if ( pC0->Area < pC1->Area - 0.0001 )
239 return -1;
240 if ( pC0->Area > pC1->Area + 0.0001 ) // smaller area flow is better
241 return 1;
242// if ( pC0->NoRefs < pC1->NoRefs )
243// return -1;
244// if ( pC0->NoRefs > pC1->NoRefs ) // fewer non-referenced fanins is better
245// return 1;
246// if ( pC0->FanRefs / pC0->nLeaves > pC1->FanRefs / pC1->nLeaves )
247// return -1;
248// if ( pC0->FanRefs / pC0->nLeaves < pC1->FanRefs / pC1->nLeaves )
249// return 1; // larger average fanin ref-counter is better
250// return 0;
251 return 1;
252}
253
265Dar_Cut_t * Cnf_ObjFindBestCut( Aig_Obj_t * pObj )
266{
267 Dar_Cut_t * pCut, * pCutBest;
268 int i;
269 pCutBest = NULL;
270 Dar_ObjForEachCut( pObj, pCut, i )
271 if ( pCutBest == NULL || Cnf_CutCompare(pCutBest, pCut) == 1 )
272 pCutBest = pCut;
273 return pCutBest;
274}
275
287void Cnf_CutAssignArea( Cnf_Man_t * p, Dar_Cut_t * pCut )
288{
289 Aig_Obj_t * pLeaf;
290 int i;
291 pCut->Area = (float)pCut->Cost;
292 pCut->NoRefs = 0;
293 pCut->FanRefs = 0;
294 Dar_CutForEachLeaf( p->pManAig, pCut, pLeaf, i )
295 {
296 if ( !Aig_ObjIsNode(pLeaf) )
297 continue;
298 if ( pLeaf->nRefs == 0 )
299 {
300 pCut->Area += Aig_ObjBestCut(pLeaf)->Cost;
301 pCut->NoRefs++;
302 }
303 else
304 {
305 if ( pCut->FanRefs + pLeaf->nRefs > 15 )
306 pCut->FanRefs = 15;
307 else
308 pCut->FanRefs += pLeaf->nRefs;
309 }
310 }
311}
312
325{
326 Aig_Obj_t * pObj;
327 Dar_Cut_t * pCut, * pCutBest;
328 int i, k;
329 // visit the nodes in the topological order and update their best cuts
330 Aig_ManForEachNode( p->pManAig, pObj, i )
331 {
332 // find the old best cut
333 pCutBest = Aig_ObjBestCut(pObj);
334 Dar_ObjClearBestCut(pCutBest);
335 // if the node is used, dereference its cut
336 if ( pObj->nRefs )
337 Aig_CutDeref( p->pManAig, pCutBest );
338
339 // evaluate the cuts of this node
340 Dar_ObjForEachCut( pObj, pCut, k )
341// Cnf_CutAssignAreaFlow( p, pCut );
342 pCut->Area = (float)Cnf_CutArea( p->pManAig, pCut );
343
344 // find the new best cut
345 pCutBest = Cnf_ObjFindBestCut(pObj);
346 Dar_ObjSetBestCut( pCutBest );
347 // if the node is used, reference its cut
348 if ( pObj->nRefs )
349 Aig_CutRef( p->pManAig, pCutBest );
350 }
351 return 1;
352}
353
354#endif
355
359
360
362
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
#define Aig_ManForEachNode(p, pObj, i)
Definition aig.h:413
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
ABC_NAMESPACE_IMPL_START void Cnf_CutAssignAreaFlow(Cnf_Man_t *p, Dar_Cut_t *pCut, int *pAreaFlows)
DECLARATIONS ///.
Definition cnfMap.c:45
int Cnf_CutSuperAreaFlow(Vec_Ptr_t *vSuper, int *pAreaFlows)
Definition cnfMap.c:73
void Cnf_DeriveMapping(Cnf_Man_t *p)
Definition cnfMap.c:100
int Cnf_ManMapForCnf(Cnf_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
Definition cnf.h:51
struct Dar_Cut_t_ Dar_Cut_t
Definition darInt.h:52
#define Dar_CutForEachLeaf(p, pCut, pLeaf, i)
Definition darInt.h:124
#define Dar_ObjForEachCut(pObj, pCut, i)
Definition darInt.h:121
Cube * p
Definition exorList.c:222
int Id
Definition aig.h:85
unsigned int nRefs
Definition aig.h:81
unsigned int fMarkB
Definition aig.h:80
unsigned fBest
Definition darInt.h:60
unsigned Value
Definition darInt.h:59
unsigned uSign
Definition darInt.h:57
#define assert(ex)
Definition util_old.h:213
char * memset()
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