00001
00021 #include "cnf.h"
00022
00026
00030
00042 void Cnf_CutAssignAreaFlow( Cnf_Man_t * p, Dar_Cut_t * pCut, int * pAreaFlows )
00043 {
00044 Aig_Obj_t * pLeaf;
00045 int i;
00046 pCut->Value = 0;
00047 pCut->uSign = 100 * Cnf_CutSopCost( p, pCut );
00048 Dar_CutForEachLeaf( p->pManAig, pCut, pLeaf, i )
00049 {
00050 pCut->Value += pLeaf->nRefs;
00051 if ( !Aig_ObjIsNode(pLeaf) )
00052 continue;
00053 assert( pLeaf->nRefs > 0 );
00054 pCut->uSign += pAreaFlows[pLeaf->Id] / (pLeaf->nRefs? pLeaf->nRefs : 1);
00055 }
00056 }
00057
00069 int Cnf_CutSuperAreaFlow( Vec_Ptr_t * vSuper, int * pAreaFlows )
00070 {
00071 Aig_Obj_t * pLeaf;
00072 int i, nAreaFlow;
00073 nAreaFlow = 100 * (Vec_PtrSize(vSuper) + 1);
00074 Vec_PtrForEachEntry( vSuper, pLeaf, i )
00075 {
00076 pLeaf = Aig_Regular(pLeaf);
00077 if ( !Aig_ObjIsNode(pLeaf) )
00078 continue;
00079 assert( pLeaf->nRefs > 0 );
00080 nAreaFlow += pAreaFlows[pLeaf->Id] / (pLeaf->nRefs? pLeaf->nRefs : 1);
00081 }
00082 return nAreaFlow;
00083 }
00084
00096 void Cnf_DeriveMapping( Cnf_Man_t * p )
00097 {
00098 Vec_Ptr_t * vSuper;
00099 Aig_Obj_t * pObj;
00100 Dar_Cut_t * pCut, * pCutBest;
00101 int i, k, AreaFlow, * pAreaFlows;
00102
00103 pAreaFlows = ALLOC( int, Aig_ManObjNumMax(p->pManAig) );
00104 memset( pAreaFlows, 0, sizeof(int) * Aig_ManObjNumMax(p->pManAig) );
00105
00106 vSuper = Vec_PtrAlloc( 100 );
00107 Aig_ManForEachNode( p->pManAig, pObj, i )
00108 {
00109
00110 pCutBest = NULL;
00111 Dar_ObjForEachCut( pObj, pCut, k )
00112 {
00113 pCut->fBest = 0;
00114 if ( k == 0 )
00115 continue;
00116 Cnf_CutAssignAreaFlow( p, pCut, pAreaFlows );
00117 if ( pCutBest == NULL || pCutBest->uSign > pCut->uSign ||
00118 (pCutBest->uSign == pCut->uSign && pCutBest->Value < pCut->Value) )
00119 pCutBest = pCut;
00120 }
00121
00122
00123
00124
00125 AreaFlow = AIG_INFINITY;
00126 if ( AreaFlow >= (int)pCutBest->uSign )
00127 {
00128 pAreaFlows[pObj->Id] = pCutBest->uSign;
00129 pCutBest->fBest = 1;
00130 }
00131 else
00132 {
00133 pAreaFlows[pObj->Id] = AreaFlow;
00134 pObj->fMarkB = 1;
00135 }
00136 }
00137 Vec_PtrFree( vSuper );
00138 free( pAreaFlows );
00139
00140
00141
00142
00143
00144
00145
00146
00147 }
00148
00149
00150
00151 #if 0
00152
00164 void Aig_CutDeref( Aig_Man_t * p, Dar_Cut_t * pCut )
00165 {
00166 Aig_Obj_t * pLeaf;
00167 int i;
00168 Dar_CutForEachLeaf( p, pCut, pLeaf, i )
00169 {
00170 assert( pLeaf->nRefs > 0 );
00171 if ( --pLeaf->nRefs > 0 || !Aig_ObjIsAnd(pLeaf) )
00172 continue;
00173 Aig_CutDeref( p, Aig_ObjBestCut(pLeaf) );
00174 }
00175 }
00176
00188 int Aig_CutRef( Aig_Man_t * p, Dar_Cut_t * pCut )
00189 {
00190 Aig_Obj_t * pLeaf;
00191 int i, Area = pCut->Value;
00192 Dar_CutForEachLeaf( p, pCut, pLeaf, i )
00193 {
00194 assert( pLeaf->nRefs >= 0 );
00195 if ( pLeaf->nRefs++ > 0 || !Aig_ObjIsAnd(pLeaf) )
00196 continue;
00197 Area += Aig_CutRef( p, Aig_ObjBestCut(pLeaf) );
00198 }
00199 return Area;
00200 }
00201
00213 int Cnf_CutArea( Aig_Man_t * p, Dar_Cut_t * pCut )
00214 {
00215 int Area;
00216 Area = Aig_CutRef( p, pCut );
00217 Aig_CutDeref( p, pCut );
00218 return Area;
00219 }
00220
00232 static inline int Cnf_CutCompare( Dar_Cut_t * pC0, Dar_Cut_t * pC1 )
00233 {
00234 if ( pC0->Area < pC1->Area - 0.0001 )
00235 return -1;
00236 if ( pC0->Area > pC1->Area + 0.0001 )
00237 return 1;
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 return 1;
00248 }
00249
00261 Dar_Cut_t * Cnf_ObjFindBestCut( Aig_Obj_t * pObj )
00262 {
00263 Dar_Cut_t * pCut, * pCutBest;
00264 int i;
00265 pCutBest = NULL;
00266 Dar_ObjForEachCut( pObj, pCut, i )
00267 if ( pCutBest == NULL || Cnf_CutCompare(pCutBest, pCut) == 1 )
00268 pCutBest = pCut;
00269 return pCutBest;
00270 }
00271
00283 void Cnf_CutAssignArea( Cnf_Man_t * p, Dar_Cut_t * pCut )
00284 {
00285 Aig_Obj_t * pLeaf;
00286 int i;
00287 pCut->Area = (float)pCut->Cost;
00288 pCut->NoRefs = 0;
00289 pCut->FanRefs = 0;
00290 Dar_CutForEachLeaf( p->pManAig, pCut, pLeaf, i )
00291 {
00292 if ( !Aig_ObjIsNode(pLeaf) )
00293 continue;
00294 if ( pLeaf->nRefs == 0 )
00295 {
00296 pCut->Area += Aig_ObjBestCut(pLeaf)->Cost;
00297 pCut->NoRefs++;
00298 }
00299 else
00300 {
00301 if ( pCut->FanRefs + pLeaf->nRefs > 15 )
00302 pCut->FanRefs = 15;
00303 else
00304 pCut->FanRefs += pLeaf->nRefs;
00305 }
00306 }
00307 }
00308
00320 int Cnf_ManMapForCnf( Cnf_Man_t * p )
00321 {
00322 Aig_Obj_t * pObj;
00323 Dar_Cut_t * pCut, * pCutBest;
00324 int i, k;
00325
00326 Aig_ManForEachNode( p->pManAig, pObj, i )
00327 {
00328
00329 pCutBest = Aig_ObjBestCut(pObj);
00330 Dar_ObjClearBestCut(pCutBest);
00331
00332 if ( pObj->nRefs )
00333 Aig_CutDeref( p->pManAig, pCutBest );
00334
00335
00336 Dar_ObjForEachCut( pObj, pCut, k )
00337
00338 pCut->Area = (float)Cnf_CutArea( p->pManAig, pCut );
00339
00340
00341 pCutBest = Cnf_ObjFindBestCut(pObj);
00342 Dar_ObjSetBestCut( pCutBest );
00343
00344 if ( pObj->nRefs )
00345 Aig_CutRef( p->pManAig, pCutBest );
00346 }
00347 return 1;
00348 }
00349
00350 #endif
00351
00355
00356