00001
00019 #include "mapperInt.h"
00020
00024
00025 static int Map_NodeIncRefPhaseAct( Map_Node_t * pNode, int fPhase );
00026 static int Map_NodeDecRefPhaseAct( Map_Node_t * pNode, int fPhase );
00027 static float Map_CutRefDeref( Map_Cut_t * pCut, int fPhase, int fReference );
00028 static void Map_MappingSetRefs_rec( Map_Man_t * pMan, Map_Node_t * pNode, Map_Node_t ** ppStore );
00029
00033
00045 int Map_NodeReadRefPhaseAct( Map_Node_t * pNode, int fPhase )
00046 {
00047 assert( !Map_IsComplement(pNode) );
00048 if ( pNode->pCutBest[0] && pNode->pCutBest[1] )
00049 return pNode->nRefAct[fPhase];
00050 assert( pNode->pCutBest[0] || pNode->pCutBest[1] );
00051 return pNode->nRefAct[2];
00052 }
00053
00065 float Map_NodeReadRefPhaseEst( Map_Node_t * pNode, int fPhase )
00066 {
00067 assert( !Map_IsComplement(pNode) );
00068 if ( pNode->pCutBest[0] && pNode->pCutBest[1] )
00069 return pNode->nRefEst[fPhase];
00070 assert( pNode->pCutBest[0] || pNode->pCutBest[1] );
00071
00072 return pNode->nRefEst[2];
00073 }
00074
00075
00087 int Map_NodeIncRefPhaseAct( Map_Node_t * pNode, int fPhase )
00088 {
00089 assert( !Map_IsComplement(pNode) );
00090 if ( pNode->pCutBest[0] && pNode->pCutBest[1] )
00091 return pNode->nRefAct[fPhase]++;
00092 assert( pNode->pCutBest[0] || pNode->pCutBest[1] );
00093 return pNode->nRefAct[2]++;
00094 }
00095
00107 int Map_NodeDecRefPhaseAct( Map_Node_t * pNode, int fPhase )
00108 {
00109 assert( !Map_IsComplement(pNode) );
00110 if ( pNode->pCutBest[0] && pNode->pCutBest[1] )
00111 return --pNode->nRefAct[fPhase];
00112 assert( pNode->pCutBest[0] || pNode->pCutBest[1] );
00113 return --pNode->nRefAct[2];
00114 }
00115
00116
00128 void Map_MappingEstimateRefsInit( Map_Man_t * p )
00129 {
00130 Map_Node_t * pNode;
00131 int i;
00132 for ( i = 0; i < p->vAnds->nSize; i++ )
00133 {
00134 pNode = p->vAnds->pArray[i];
00135
00136 pNode->nRefEst[0] = pNode->nRefEst[1] = pNode->nRefEst[2] = ((float)pNode->nRefs);
00137 }
00138 }
00139
00153 void Map_MappingEstimateRefs( Map_Man_t * p )
00154 {
00155 Map_Node_t * pNode;
00156 int i;
00157 for ( i = 0; i < p->vAnds->nSize; i++ )
00158 {
00159 pNode = p->vAnds->pArray[i];
00160
00161
00162
00163 pNode->nRefEst[0] = (float)((3.0 * pNode->nRefEst[0] + 1.0 * pNode->nRefAct[0]) / 4.0);
00164 pNode->nRefEst[1] = (float)((3.0 * pNode->nRefEst[1] + 1.0 * pNode->nRefAct[1]) / 4.0);
00165 pNode->nRefEst[2] = (float)((3.0 * pNode->nRefEst[2] + 1.0 * pNode->nRefAct[2]) / 4.0);
00166 }
00167 }
00168
00169
00170
00171
00172
00185 float Map_CutGetAreaFlow( Map_Cut_t * pCut, int fPhase )
00186 {
00187 Map_Match_t * pM = pCut->M + fPhase;
00188 Map_Super_t * pSuper = pM->pSuperBest;
00189 unsigned uPhaseTot = pM->uPhaseBest;
00190 Map_Cut_t * pCutFanin;
00191 float aFlowRes, aFlowFanin, nRefs;
00192 int i, fPinPhasePos;
00193
00194
00195 aFlowRes = pSuper->Area;
00196
00197 for ( i = 0; i < pCut->nLeaves; i++ )
00198 {
00199
00200 fPinPhasePos = ((uPhaseTot & (1 << i)) == 0);
00201
00202 pCutFanin = pCut->ppLeaves[i]->pCutBest[fPinPhasePos];
00203
00204 if ( pCutFanin == NULL )
00205 {
00206 fPinPhasePos = !fPinPhasePos;
00207 pCutFanin = pCut->ppLeaves[i]->pCutBest[fPinPhasePos];
00208 }
00209 aFlowFanin = pCutFanin->M[fPinPhasePos].AreaFlow;
00210
00211 nRefs = Map_NodeReadRefPhaseEst( pCut->ppLeaves[i], fPinPhasePos );
00212
00213 if ( nRefs == (float)0.0 )
00214 nRefs = (float)1.0;
00215
00216 aFlowRes += aFlowFanin / nRefs;
00217 }
00218 pM->AreaFlow = aFlowRes;
00219 return aFlowRes;
00220 }
00221
00222
00223
00235 float Map_CutGetAreaRefed( Map_Cut_t * pCut, int fPhase )
00236 {
00237 float aResult, aResult2;
00238 aResult2 = Map_CutRefDeref( pCut, fPhase, 0 );
00239 aResult = Map_CutRefDeref( pCut, fPhase, 1 );
00240
00241 return aResult;
00242 }
00243
00255 float Map_CutGetAreaDerefed( Map_Cut_t * pCut, int fPhase )
00256 {
00257 float aResult, aResult2;
00258 aResult2 = Map_CutRefDeref( pCut, fPhase, 1 );
00259 aResult = Map_CutRefDeref( pCut, fPhase, 0 );
00260
00261 return aResult;
00262 }
00263
00275 float Map_CutRef( Map_Cut_t * pCut, int fPhase )
00276 {
00277 return Map_CutRefDeref( pCut, fPhase, 1 );
00278 }
00279
00291 float Map_CutDeref( Map_Cut_t * pCut, int fPhase )
00292 {
00293 return Map_CutRefDeref( pCut, fPhase, 0 );
00294 }
00295
00308 float Map_CutRefDeref( Map_Cut_t * pCut, int fPhase, int fReference )
00309 {
00310 Map_Node_t * pNodeChild;
00311 Map_Cut_t * pCutChild;
00312 float aArea;
00313 int i, fPhaseChild;
00314
00315
00316
00317 if ( pCut->nLeaves == 1 )
00318 return 0;
00319
00320 aArea = Map_CutGetRootArea( pCut, fPhase );
00321
00322 for ( i = 0; i < pCut->nLeaves; i++ )
00323 {
00324 pNodeChild = pCut->ppLeaves[i];
00325 fPhaseChild = Map_CutGetLeafPhase( pCut, fPhase, i );
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 if ( fReference )
00341 {
00342 if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] )
00343 {
00344
00345 pNodeChild->nRefAct[2]++;
00346 if ( pNodeChild->nRefAct[fPhaseChild]++ > 0 )
00347 continue;
00348 }
00349 else
00350 {
00351
00352
00353 if ( pNodeChild->nRefAct[fPhaseChild]++ == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
00354 aArea += pNodeChild->p->pSuperLib->AreaInv;
00355
00356 if ( pNodeChild->nRefAct[2]++ > 0 )
00357 continue;
00358 }
00359 }
00360 else
00361 {
00362 if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] )
00363 {
00364
00365 --pNodeChild->nRefAct[2];
00366 if ( --pNodeChild->nRefAct[fPhaseChild] > 0 )
00367 continue;
00368 }
00369 else
00370 {
00371
00372
00373 if ( --pNodeChild->nRefAct[fPhaseChild] == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
00374 aArea += pNodeChild->p->pSuperLib->AreaInv;
00375
00376 if ( --pNodeChild->nRefAct[2] > 0 )
00377 continue;
00378 }
00379 assert( pNodeChild->nRefAct[fPhaseChild] >= 0 );
00380 }
00381
00382
00383 pCutChild = pNodeChild->pCutBest[fPhaseChild];
00384
00385 if ( pCutChild == NULL )
00386 {
00387 fPhaseChild = !fPhaseChild;
00388 pCutChild = pNodeChild->pCutBest[fPhaseChild];
00389 }
00390
00391 aArea += Map_CutRefDeref( pCutChild, fPhaseChild, fReference );
00392 }
00393 return aArea;
00394 }
00395
00396
00397
00398
00412 void Map_MappingSetRefs( Map_Man_t * pMan )
00413 {
00414 Map_Node_t * pNode, ** ppStore;
00415 int i, fPhase, LevelMax;
00416
00417
00418 for ( i = 0; i < pMan->vNodesAll->nSize; i++ )
00419 {
00420 pNode = pMan->vNodesAll->pArray[i];
00421 pNode->nRefAct[0] = 0;
00422 pNode->nRefAct[1] = 0;
00423 pNode->nRefAct[2] = 0;
00424 }
00425
00426
00427 LevelMax = 0;
00428 for ( i = 0; i < pMan->nOutputs; i++ )
00429 if ( LevelMax < (int)Map_Regular(pMan->pOutputs[i])->Level )
00430 LevelMax = Map_Regular(pMan->pOutputs[i])->Level;
00431
00432
00433 ppStore = ALLOC( Map_Node_t *, LevelMax + 1 );
00434 memset( ppStore, 0, sizeof(Map_Node_t *) * (LevelMax + 1) );
00435
00436
00437 for ( i = 0; i < pMan->nOutputs; i++ )
00438 {
00439 pNode = pMan->pOutputs[i];
00440 fPhase = !Map_IsComplement(pNode);
00441 if ( !Map_NodeIsConst(pNode) )
00442 Map_MappingSetRefs_rec( pMan, pNode, ppStore );
00443 }
00444
00445
00446 pMan->vMapping->nSize = 0;
00447 for ( i = LevelMax; i >= 0; i-- )
00448 for ( pNode = ppStore[i]; pNode; pNode = (Map_Node_t *)pNode->pData0 )
00449 Map_NodeVecPush( pMan->vMapping, pNode );
00450 free( ppStore );
00451 }
00452
00464 void Map_MappingSetRefs_rec( Map_Man_t * pMan, Map_Node_t * pNode, Map_Node_t ** ppStore )
00465 {
00466 Map_Cut_t * pCut;
00467 Map_Node_t * pNodeR;
00468 unsigned uPhase;
00469 int i, fPhase, fInvPin;
00470
00471
00472 pNodeR = Map_Regular(pNode);
00473 fPhase = !Map_IsComplement(pNode);
00474
00475
00476 if ( pNodeR->nRefAct[2]++ == 0 )
00477
00478 pNodeR->pData0 = (char *)ppStore[pNodeR->Level], ppStore[pNodeR->Level] = pNodeR;
00479
00480
00481 if ( pNodeR->nRefAct[fPhase]++ )
00482 return;
00483
00484
00485 if ( Map_NodeIsVar(pNodeR) )
00486 return;
00487
00488
00489 pCut = pNodeR->pCutBest[fPhase];
00490 if ( pCut == NULL )
00491 {
00492 fPhase = !fPhase;
00493 pCut = pNodeR->pCutBest[fPhase];
00494 }
00495
00496
00497 uPhase = pCut->M[fPhase].uPhaseBest;
00498 for ( i = 0; i < pCut->nLeaves; i++ )
00499 {
00500 fInvPin = ((uPhase & (1 << i)) > 0);
00501 Map_MappingSetRefs_rec( pMan, Map_NotCond(pCut->ppLeaves[i], fInvPin), ppStore );
00502 }
00503 }
00504
00505
00517 float Map_MappingGetArea( Map_Man_t * pMan, Map_NodeVec_t * vMapping )
00518 {
00519 Map_Node_t * pNode;
00520 float Area;
00521 int i;
00522 Area = 0.0;
00523 for ( i = 0; i < vMapping->nSize; i++ )
00524 {
00525 pNode = vMapping->pArray[i];
00526
00527 assert( pNode->pCutBest[0] != NULL || pNode->pCutBest[1] != NULL );
00528
00529 assert( pNode->nRefAct[0] > 0 || pNode->nRefAct[1] > 0 );
00530
00531 if ( Map_NodeIsAnd(pNode) )
00532 {
00533
00534 if ( pNode->pCutBest[0] && (pNode->nRefAct[0] > 0 || pNode->pCutBest[1] == NULL) )
00535 Area += pNode->pCutBest[0]->M[0].pSuperBest->Area;
00536
00537 if ( pNode->pCutBest[1] && (pNode->nRefAct[1] > 0 || pNode->pCutBest[0] == NULL) )
00538 Area += pNode->pCutBest[1]->M[1].pSuperBest->Area;
00539 }
00540
00541 if ( (pNode->pCutBest[0] == NULL && pNode->nRefAct[0] > 0) ||
00542 (pNode->pCutBest[1] == NULL && pNode->nRefAct[1] > 0) )
00543 Area += pMan->pSuperLib->AreaInv;
00544 }
00545
00546 for ( i = 0; i < pMan->nOutputs; i++ )
00547 if ( Map_NodeIsVar(pMan->pOutputs[i]) && !Map_IsComplement(pMan->pOutputs[i]) )
00548 Area += pMan->pSuperLib->AreaBuf;
00549 return Area;
00550 }
00551
00552
00556
00557