00001
00021 #include "if.h"
00022
00026
00030
00042 void If_ManCleanNodeCopy( If_Man_t * p )
00043 {
00044 If_Obj_t * pObj;
00045 int i;
00046 If_ManForEachObj( p, pObj, i )
00047 If_ObjSetCopy( pObj, NULL );
00048 }
00049
00061 void If_ManCleanCutData( If_Man_t * p )
00062 {
00063 If_Obj_t * pObj;
00064 int i;
00065 If_ManForEachObj( p, pObj, i )
00066 If_CutSetData( If_ObjCutBest(pObj), NULL );
00067 }
00068
00080 void If_ManCleanMarkV( If_Man_t * p )
00081 {
00082 If_Obj_t * pObj;
00083 int i;
00084 If_ManForEachObj( p, pObj, i )
00085 pObj->fVisit = 0;
00086 }
00087
00099 float If_ManDelayMax( If_Man_t * p, int fSeq )
00100 {
00101 If_Obj_t * pObj;
00102 float DelayBest;
00103 int i;
00104 if ( p->pPars->fLatchPaths && p->pPars->nLatches == 0 )
00105 {
00106 printf( "Delay optimization of latch path is not performed because there is no latches.\n" );
00107 p->pPars->fLatchPaths = 0;
00108 }
00109 DelayBest = -IF_FLOAT_LARGE;
00110 if ( fSeq )
00111 {
00112 assert( p->pPars->nLatches > 0 );
00113 If_ManForEachPo( p, pObj, i )
00114 if ( DelayBest < If_ObjArrTime(If_ObjFanin0(pObj)) )
00115 DelayBest = If_ObjArrTime(If_ObjFanin0(pObj));
00116 }
00117 else if ( p->pPars->fLatchPaths )
00118 {
00119 If_ManForEachLatchInput( p, pObj, i )
00120 if ( DelayBest < If_ObjArrTime(If_ObjFanin0(pObj)) )
00121 DelayBest = If_ObjArrTime(If_ObjFanin0(pObj));
00122 }
00123 else
00124 {
00125 If_ManForEachCo( p, pObj, i )
00126 if ( DelayBest < If_ObjArrTime(If_ObjFanin0(pObj)) )
00127 DelayBest = If_ObjArrTime(If_ObjFanin0(pObj));
00128 }
00129 return DelayBest;
00130 }
00131
00143 void If_ManComputeRequired( If_Man_t * p )
00144 {
00145 If_Obj_t * pObj;
00146 int i, Counter;
00147
00148
00149 p->nNets = 0;
00150 p->AreaGlo = If_ManScanMapping( p );
00151
00152
00153 if ( p->pPars->pTimesReq )
00154 {
00155 assert( !p->pPars->fAreaOnly );
00156
00157 Counter = 0;
00158 If_ManForEachCo( p, pObj, i )
00159 {
00160 if ( If_ObjArrTime(If_ObjFanin0(pObj)) > p->pPars->pTimesReq[i] + p->fEpsilon )
00161 {
00162 Counter++;
00163
00164
00165 }
00166 If_ObjFanin0(pObj)->Required = p->pPars->pTimesReq[i];
00167 }
00168 if ( Counter )
00169 printf( "Required times are violated for %d outputs.\n", Counter );
00170 }
00171 else
00172 {
00173
00174 p->RequiredGlo = If_ManDelayMax( p, 0 );
00175
00176 if ( p->pPars->DelayTarget != -1 )
00177 {
00178 if ( p->RequiredGlo > p->pPars->DelayTarget + p->fEpsilon )
00179 {
00180 if ( p->fNextRound == 0 )
00181 {
00182 p->fNextRound = 1;
00183 printf( "Cannot meet the target required times (%4.2f). Mapping continues anyway.\n", p->pPars->DelayTarget );
00184 }
00185 }
00186 else if ( p->RequiredGlo < p->pPars->DelayTarget - p->fEpsilon )
00187 {
00188 if ( p->fNextRound == 0 )
00189 {
00190 p->fNextRound = 1;
00191 printf( "Relaxing the required times from (%4.2f) to the target (%4.2f).\n", p->RequiredGlo, p->pPars->DelayTarget );
00192 }
00193 p->RequiredGlo = p->pPars->DelayTarget;
00194 }
00195 }
00196
00197 if ( p->pPars->fAreaOnly )
00198 return;
00199
00200 if ( p->pPars->fLatchPaths )
00201 {
00202 If_ManForEachLatchInput( p, pObj, i )
00203 If_ObjFanin0(pObj)->Required = p->RequiredGlo;
00204 }
00205 else
00206 {
00207 If_ManForEachCo( p, pObj, i )
00208 If_ObjFanin0(pObj)->Required = p->RequiredGlo;
00209 }
00210 }
00211
00212 Vec_PtrForEachEntry( p->vMapped, pObj, i )
00213 If_CutPropagateRequired( p, If_ObjCutBest(pObj), pObj->Required );
00214 }
00215
00227 float If_ManScanMapping_rec( If_Man_t * p, If_Obj_t * pObj, If_Obj_t ** ppStore )
00228 {
00229 If_Obj_t * pLeaf;
00230 If_Cut_t * pCutBest;
00231 float aArea;
00232 int i;
00233 if ( pObj->nRefs++ || If_ObjIsCi(pObj) || If_ObjIsConst1(pObj) )
00234 return 0.0;
00235
00236 assert( If_ObjIsAnd(pObj) );
00237 pObj->pCopy = (char *)ppStore[pObj->Level];
00238 ppStore[pObj->Level] = pObj;
00239
00240 pCutBest = If_ObjCutBest(pObj);
00241 p->nNets += pCutBest->nLeaves;
00242 aArea = If_CutLutArea( p, pCutBest );
00243 If_CutForEachLeaf( p, pCutBest, pLeaf, i )
00244 aArea += If_ManScanMapping_rec( p, pLeaf, ppStore );
00245 return aArea;
00246 }
00247
00260 float If_ManScanMapping( If_Man_t * p )
00261 {
00262 If_Obj_t * pObj, ** ppStore;
00263 float aArea;
00264 int i;
00265 assert( !p->pPars->fLiftLeaves );
00266
00267 If_ManForEachObj( p, pObj, i )
00268 {
00269 pObj->Required = IF_FLOAT_LARGE;
00270 pObj->nVisits = pObj->nVisitsCopy;
00271 pObj->nRefs = 0;
00272 }
00273
00274 ppStore = ALLOC( If_Obj_t *, p->nLevelMax + 1 );
00275 memset( ppStore, 0, sizeof(If_Obj_t *) * (p->nLevelMax + 1) );
00276
00277 aArea = 0;
00278 If_ManForEachCo( p, pObj, i )
00279 aArea += If_ManScanMapping_rec( p, If_ObjFanin0(pObj), ppStore );
00280
00281 Vec_PtrClear( p->vMapped );
00282 for ( i = p->nLevelMax; i >= 0; i-- )
00283 for ( pObj = ppStore[i]; pObj; pObj = pObj->pCopy )
00284 Vec_PtrPush( p->vMapped, pObj );
00285 free( ppStore );
00286 return aArea;
00287 }
00288
00300 float If_ManScanMappingSeq_rec( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vMapped )
00301 {
00302 If_Obj_t * pLeaf;
00303 If_Cut_t * pCutBest;
00304 float aArea;
00305 int i, Shift;
00306
00307 if ( If_ObjIsLatch(pObj) )
00308 return If_ManScanMappingSeq_rec( p, If_ObjFanin0(pObj), vMapped );
00309
00310 if ( pObj->nRefs++ || If_ObjIsPi(pObj) || If_ObjIsConst1(pObj) )
00311 return 0.0;
00312
00313 assert( If_ObjIsAnd(pObj) );
00314
00315 pCutBest = If_ObjCutBest(pObj);
00316 aArea = If_ObjIsAnd(pObj)? If_CutLutArea(p, pCutBest) : (float)0.0;
00317 If_CutForEachLeafSeq( p, pCutBest, pLeaf, Shift, i )
00318 aArea += If_ManScanMappingSeq_rec( p, pLeaf, vMapped );
00319
00320 Vec_PtrPush( vMapped, pObj );
00321 return aArea;
00322 }
00323
00336 float If_ManScanMappingSeq( If_Man_t * p )
00337 {
00338 If_Obj_t * pObj;
00339 float aArea;
00340 int i;
00341 assert( p->pPars->fLiftLeaves );
00342
00343 If_ManForEachObj( p, pObj, i )
00344 pObj->nRefs = 0;
00345
00346 aArea = 0;
00347 Vec_PtrClear( p->vMapped );
00348 If_ManForEachPo( p, pObj, i )
00349 aArea += If_ManScanMappingSeq_rec( p, If_ObjFanin0(pObj), p->vMapped );
00350 return aArea;
00351 }
00352
00365 void If_ManResetOriginalRefs( If_Man_t * p )
00366 {
00367 If_Obj_t * pObj;
00368 int i;
00369 If_ManForEachObj( p, pObj, i )
00370 pObj->nRefs = 0;
00371 If_ManForEachObj( p, pObj, i )
00372 {
00373 if ( If_ObjIsAnd(pObj) )
00374 {
00375 pObj->pFanin0->nRefs++;
00376 pObj->pFanin1->nRefs++;
00377 }
00378 else if ( If_ObjIsCo(pObj) )
00379 pObj->pFanin0->nRefs++;
00380 }
00381 }
00382
00394 int If_ManCrossCut( If_Man_t * p )
00395 {
00396 If_Obj_t * pObj, * pFanin;
00397 int i, nCutSize = 0, nCutSizeMax = 0;
00398 If_ManForEachObj( p, pObj, i )
00399 {
00400 if ( !If_ObjIsAnd(pObj) )
00401 continue;
00402
00403 if ( nCutSizeMax < ++nCutSize )
00404 nCutSizeMax = nCutSize;
00405 if ( pObj->nVisits == 0 )
00406 nCutSize--;
00407
00408 pFanin = If_ObjFanin0(pObj);
00409 if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
00410 nCutSize--;
00411 pFanin = If_ObjFanin1(pObj);
00412 if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
00413 nCutSize--;
00414
00415 if ( pObj->fRepr )
00416 for ( pFanin = pObj; pFanin; pFanin = pFanin->pEquiv )
00417 if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
00418 nCutSize--;
00419 }
00420 If_ManForEachObj( p, pObj, i )
00421 {
00422 assert( If_ObjIsCi(pObj) || pObj->fVisit == 0 );
00423 pObj->nVisits = pObj->nVisitsCopy;
00424 }
00425 assert( nCutSize == 0 );
00426
00427 return nCutSizeMax;
00428 }
00429
00441 int If_ManCountTrueArea( If_Man_t * p )
00442 {
00443 If_Obj_t * pObj;
00444 int i, Area = 0;
00445 Vec_PtrForEachEntry( p->vMapped, pObj, i )
00446 Area += 1 + (If_ObjCutBest(pObj)->nLeaves > (unsigned)p->pPars->nLutSize / 2);
00447 return Area;
00448 }
00449
00453
00454