00001
00019 #include "mapperInt.h"
00020
00024
00025 #define MAP_CO_LIST_SIZE 5
00026
00027 static void Map_MappingDfs_rec( Map_Node_t * pNode, Map_NodeVec_t * vNodes, int fCollectEquiv );
00028 static int Map_MappingCountLevels_rec( Map_Node_t * pNode );
00029 static float Map_MappingSetRefsAndArea_rec( Map_Man_t * pMan, Map_Node_t * pNode );
00030 static float Map_MappingSetRefsAndSwitch_rec( Map_Man_t * pMan, Map_Node_t * pNode );
00031 static float Map_MappingSetRefsAndWire_rec( Map_Man_t * pMan, Map_Node_t * pNode );
00032 static void Map_MappingDfsCuts_rec( Map_Node_t * pNode, Map_NodeVec_t * vNodes );
00033 static float Map_MappingArea_rec( Map_Man_t * pMan, Map_Node_t * pNode, Map_NodeVec_t * vNodes );
00034 static int Map_MappingCompareOutputDelay( Map_Node_t ** ppNode1, Map_Node_t ** ppNode2 );
00035 static void Map_MappingFindLatest( Map_Man_t * p, int * pNodes, int nNodesMax );
00036 static unsigned Map_MappingExpandTruth_rec( unsigned uTruth, int nVars );
00037 static void Map_MappingGetChoiceLevels( Map_Man_t * pMan, Map_Node_t * p1, Map_Node_t * p2, int * pMin, int * pMax );
00038 static float Map_MappingGetChoiceVolumes( Map_Man_t * pMan, Map_Node_t * p1, Map_Node_t * p2 );
00039 static int Map_MappingCountUsedNodes( Map_Man_t * pMan, int fChoices );
00040 static Map_Man_t * s_pMan = NULL;
00041
00045
00046
00058 Map_NodeVec_t * Map_MappingDfs( Map_Man_t * pMan, int fCollectEquiv )
00059 {
00060 Map_NodeVec_t * vNodes;
00061 int i;
00062
00063 vNodes = Map_NodeVecAlloc( 100 );
00064 for ( i = 0; i < pMan->nOutputs; i++ )
00065 Map_MappingDfs_rec( Map_Regular(pMan->pOutputs[i]), vNodes, fCollectEquiv );
00066 for ( i = 0; i < vNodes->nSize; i++ )
00067 vNodes->pArray[i]->fMark0 = 0;
00068
00069
00070 return vNodes;
00071 }
00072
00084 Map_NodeVec_t * Map_MappingDfsNodes( Map_Man_t * pMan, Map_Node_t ** ppCuts, int nNodes, int fEquiv )
00085 {
00086 Map_NodeVec_t * vNodes;
00087 int i;
00088
00089 vNodes = Map_NodeVecAlloc( 200 );
00090 for ( i = 0; i < nNodes; i++ )
00091 Map_MappingDfs_rec( ppCuts[i], vNodes, fEquiv );
00092 for ( i = 0; i < vNodes->nSize; i++ )
00093 vNodes->pArray[i]->fMark0 = 0;
00094 return vNodes;
00095 }
00096
00108 void Map_MappingDfs_rec( Map_Node_t * pNode, Map_NodeVec_t * vNodes, int fCollectEquiv )
00109 {
00110 assert( !Map_IsComplement(pNode) );
00111 if ( pNode->fMark0 )
00112 return;
00113
00114 if ( Map_NodeIsAnd(pNode) )
00115 {
00116 Map_MappingDfs_rec( Map_Regular(pNode->p1), vNodes, fCollectEquiv );
00117 Map_MappingDfs_rec( Map_Regular(pNode->p2), vNodes, fCollectEquiv );
00118 }
00119
00120 if ( fCollectEquiv && pNode->pNextE )
00121 Map_MappingDfs_rec( pNode->pNextE, vNodes, fCollectEquiv );
00122
00123 assert( pNode->fMark0 == 0 );
00124
00125 pNode->fMark0 = 1;
00126
00127 Map_NodeVecPush( vNodes, pNode );
00128 }
00129
00130
00131
00143 void Map_MappingDfsMarked1_rec( Map_Node_t * pNode, Map_NodeVec_t * vNodes, int fFirst )
00144 {
00145 assert( !Map_IsComplement(pNode) );
00146 if ( pNode->fMark0 )
00147 return;
00148
00149 if ( Map_NodeIsAnd(pNode) )
00150 {
00151 Map_MappingDfsMarked1_rec( Map_Regular(pNode->p1), vNodes, 0 );
00152 Map_MappingDfsMarked1_rec( Map_Regular(pNode->p2), vNodes, 0 );
00153 }
00154
00155 if ( !fFirst && pNode->pNextE )
00156 Map_MappingDfsMarked1_rec( pNode->pNextE, vNodes, 0 );
00157
00158 assert( pNode->fMark0 == 0 );
00159
00160 pNode->fMark0 = 1;
00161
00162 Map_NodeVecPush( vNodes, pNode );
00163 }
00164
00176 void Map_MappingDfsMarked2_rec( Map_Node_t * pNode, Map_NodeVec_t * vNodes, Map_NodeVec_t * vBoundary, int fFirst )
00177 {
00178 assert( !Map_IsComplement(pNode) );
00179 if ( pNode->fMark1 )
00180 return;
00181 if ( pNode->fMark0 || Map_NodeIsVar(pNode) )
00182 {
00183 pNode->fMark1 = 1;
00184 Map_NodeVecPush(vBoundary, pNode);
00185 return;
00186 }
00187
00188 if ( Map_NodeIsAnd(pNode) )
00189 {
00190 Map_MappingDfsMarked2_rec( Map_Regular(pNode->p1), vNodes, vBoundary, 0 );
00191 Map_MappingDfsMarked2_rec( Map_Regular(pNode->p2), vNodes, vBoundary, 0 );
00192 }
00193
00194 if ( !fFirst && pNode->pNextE )
00195 Map_MappingDfsMarked2_rec( pNode->pNextE, vNodes, vBoundary, 0 );
00196
00197 assert( pNode->fMark1 == 0 );
00198
00199 pNode->fMark1 = 1;
00200
00201 Map_NodeVecPush( vNodes, pNode );
00202 }
00203
00204
00216 void Map_MappingDfsMarked3_rec( Map_Node_t * pNode, Map_NodeVec_t * vNodes )
00217 {
00218 assert( !Map_IsComplement(pNode) );
00219 if ( pNode->fMark0 )
00220 return;
00221
00222 if ( Map_NodeIsAnd(pNode) )
00223 {
00224 Map_MappingDfsMarked3_rec( Map_Regular(pNode->p1), vNodes );
00225 Map_MappingDfsMarked3_rec( Map_Regular(pNode->p2), vNodes );
00226 }
00227
00228 assert( pNode->fMark0 == 0 );
00229
00230 pNode->fMark0 = 1;
00231
00232 Map_NodeVecPush( vNodes, pNode );
00233 }
00234
00246 void Map_MappingDfsMarked4_rec( Map_Node_t * pNode, Map_NodeVec_t * vNodes )
00247 {
00248 assert( !Map_IsComplement(pNode) );
00249 if ( pNode->fMark1 )
00250 return;
00251
00252 if ( Map_NodeIsAnd(pNode) )
00253 {
00254 Map_MappingDfsMarked4_rec( Map_Regular(pNode->p1), vNodes );
00255 Map_MappingDfsMarked4_rec( Map_Regular(pNode->p2), vNodes );
00256 }
00257
00258 assert( pNode->fMark1 == 0 );
00259
00260 pNode->fMark1 = 1;
00261
00262 Map_NodeVecPush( vNodes, pNode );
00263 }
00264
00265
00266
00280 int Map_MappingCountLevels( Map_Man_t * pMan )
00281 {
00282 int i, LevelsMax, LevelsCur;
00283
00284 LevelsMax = -1;
00285 for ( i = 0; i < pMan->nOutputs; i++ )
00286 {
00287 LevelsCur = Map_MappingCountLevels_rec( Map_Regular(pMan->pOutputs[i]) );
00288 if ( LevelsMax < LevelsCur )
00289 LevelsMax = LevelsCur;
00290 }
00291 for ( i = 0; i < pMan->nOutputs; i++ )
00292 Map_MappingUnmark_rec( Map_Regular(pMan->pOutputs[i]) );
00293 return LevelsMax;
00294 }
00295
00307 int Map_MappingCountLevels_rec( Map_Node_t * pNode )
00308 {
00309 int Level1, Level2;
00310 assert( !Map_IsComplement(pNode) );
00311 if ( !Map_NodeIsAnd(pNode) )
00312 {
00313 pNode->Level = 0;
00314 return 0;
00315 }
00316 if ( pNode->fMark0 )
00317 return pNode->Level;
00318 pNode->fMark0 = 1;
00319
00320 Level1 = Map_MappingCountLevels_rec( Map_Regular(pNode->p1) );
00321 Level2 = Map_MappingCountLevels_rec( Map_Regular(pNode->p2) );
00322
00323 pNode->Level = 1 + ((Level1>Level2)? Level1: Level2);
00324 return pNode->Level;
00325 }
00326
00338 void Map_MappingUnmark( Map_Man_t * pMan )
00339 {
00340 int i;
00341 for ( i = 0; i < pMan->nOutputs; i++ )
00342 Map_MappingUnmark_rec( Map_Regular(pMan->pOutputs[i]) );
00343 }
00344
00356 void Map_MappingUnmark_rec( Map_Node_t * pNode )
00357 {
00358 assert( !Map_IsComplement(pNode) );
00359 if ( pNode->fMark0 == 0 )
00360 return;
00361 pNode->fMark0 = 0;
00362 if ( !Map_NodeIsAnd(pNode) )
00363 return;
00364 Map_MappingUnmark_rec( Map_Regular(pNode->p1) );
00365 Map_MappingUnmark_rec( Map_Regular(pNode->p2) );
00366
00367 if ( pNode->pNextE )
00368 Map_MappingUnmark_rec( pNode->pNextE );
00369 }
00370
00382 void Map_MappingMark_rec( Map_Node_t * pNode )
00383 {
00384 assert( !Map_IsComplement(pNode) );
00385 if ( pNode->fMark0 == 1 )
00386 return;
00387 pNode->fMark0 = 1;
00388 if ( !Map_NodeIsAnd(pNode) )
00389 return;
00390
00391 Map_MappingMark_rec( Map_Regular(pNode->p1) );
00392 Map_MappingMark_rec( Map_Regular(pNode->p2) );
00393 }
00394
00406 int Map_MappingCompareOutputDelay( Map_Node_t ** ppNode1, Map_Node_t ** ppNode2 )
00407 {
00408 Map_Node_t * pNode1 = Map_Regular(*ppNode1);
00409 Map_Node_t * pNode2 = Map_Regular(*ppNode2);
00410 int fPhase1 = !Map_IsComplement(*ppNode1);
00411 int fPhase2 = !Map_IsComplement(*ppNode2);
00412 float Arrival1 = pNode1->tArrival[fPhase1].Worst;
00413 float Arrival2 = pNode2->tArrival[fPhase2].Worst;
00414 if ( Arrival1 < Arrival2 )
00415 return -1;
00416 if ( Arrival1 > Arrival2 )
00417 return 1;
00418 return 0;
00419 }
00420
00432 void Map_MappingFindLatest( Map_Man_t * p, int * pNodes, int nNodesMax )
00433 {
00434 int nNodes, i, k, v;
00435 assert( p->nOutputs >= nNodesMax );
00436 pNodes[0] = 0;
00437 nNodes = 1;
00438 for ( i = 1; i < p->nOutputs; i++ )
00439 {
00440 for ( k = nNodes - 1; k >= 0; k-- )
00441 if ( Map_MappingCompareOutputDelay( &p->pOutputs[pNodes[k]], &p->pOutputs[i] ) >= 0 )
00442 break;
00443 if ( k == nNodesMax - 1 )
00444 continue;
00445 if ( nNodes < nNodesMax )
00446 nNodes++;
00447 for ( v = nNodes - 1; v > k+1; v-- )
00448 pNodes[v] = pNodes[v-1];
00449 pNodes[k+1] = i;
00450 }
00451 }
00452
00464 void Map_MappingPrintOutputArrivals( Map_Man_t * p )
00465 {
00466 int pSorted[MAP_CO_LIST_SIZE];
00467 Map_Time_t * pTimes;
00468 Map_Node_t * pNode;
00469 int fPhase, Limit, i;
00470 int MaxNameSize;
00471
00472
00473 Limit = (p->nOutputs > MAP_CO_LIST_SIZE)? MAP_CO_LIST_SIZE : p->nOutputs;
00474
00475
00476 Map_MappingFindLatest( p, pSorted, Limit );
00477
00478
00479 MaxNameSize = 0;
00480 for ( i = 0; i < Limit; i++ )
00481 if ( MaxNameSize < (int)strlen(p->ppOutputNames[pSorted[i]]) )
00482 MaxNameSize = strlen(p->ppOutputNames[pSorted[i]]);
00483
00484
00485 for ( i = 0; i < Limit; i++ )
00486 {
00487
00488 pNode = Map_Regular(p->pOutputs[pSorted[i]]);
00489 fPhase =!Map_IsComplement(p->pOutputs[pSorted[i]]);
00490 pTimes = pNode->tArrival + fPhase;
00491
00492 printf( "Output %-*s : ", MaxNameSize + 3, p->ppOutputNames[pSorted[i]] );
00493 printf( "Delay = (%5.2f, %5.2f) ", (double)pTimes->Rise, (double)pTimes->Fall );
00494 printf( "%s", fPhase? "POS" : "NEG" );
00495 printf( "\n" );
00496 }
00497 }
00498
00510 void Map_MappingSetupTruthTables( unsigned uTruths[][2] )
00511 {
00512 int m, v;
00513
00514 for ( m = 0; m < 32; m++ )
00515 for ( v = 0; v < 5; v++ )
00516 if ( m & (1 << v) )
00517 uTruths[v][0] |= (1 << m);
00518
00519 for ( v = 0; v < 5; v++ )
00520 uTruths[v][1] = uTruths[v][0];
00521 uTruths[5][0] = 0;
00522 uTruths[5][1] = MAP_FULL;
00523 }
00524
00536 void Map_MappingSetupTruthTablesLarge( unsigned uTruths[][32] )
00537 {
00538 int m, v;
00539
00540 for ( m = 0; m < 32; m++ )
00541 for ( v = 0; v < 10; v++ )
00542 uTruths[v][m] = 0;
00543
00544 for ( m = 0; m < 32; m++ )
00545 for ( v = 0; v < 5; v++ )
00546 if ( m & (1 << v) )
00547 {
00548 uTruths[v][0] |= (1 << m);
00549 uTruths[v+5][m] = MAP_FULL;
00550 }
00551
00552 for ( m = 0; m < 32; m++ )
00553 for ( v = 0; v < 5; v++ )
00554 uTruths[v][m] = uTruths[v][0];
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564 }
00565
00577 void Map_MappingSetupMask( unsigned uMask[], int nVarsMax )
00578 {
00579 if ( nVarsMax == 6 )
00580 uMask[0] = uMask[1] = MAP_FULL;
00581 else
00582 {
00583 uMask[0] = MAP_MASK(1 << nVarsMax);
00584 uMask[1] = 0;
00585 }
00586 }
00587
00602 int Map_ManCheckConsistency( Map_Man_t * p )
00603 {
00604 Map_Node_t * pNode;
00605 Map_NodeVec_t * pVec;
00606 int i;
00607 pVec = Map_MappingDfs( p, 0 );
00608 for ( i = 0; i < pVec->nSize; i++ )
00609 {
00610 pNode = pVec->pArray[i];
00611 if ( Map_NodeIsVar(pNode) )
00612 {
00613 if ( pNode->pRepr )
00614 printf( "Primary input %d is a secondary node.\n", pNode->Num );
00615 }
00616 else if ( Map_NodeIsConst(pNode) )
00617 {
00618 if ( pNode->pRepr )
00619 printf( "Constant 1 %d is a secondary node.\n", pNode->Num );
00620 }
00621 else
00622 {
00623 if ( pNode->pRepr )
00624 printf( "Internal node %d is a secondary node.\n", pNode->Num );
00625 if ( Map_Regular(pNode->p1)->pRepr )
00626 printf( "Internal node %d has first fanin that is a secondary node.\n", pNode->Num );
00627 if ( Map_Regular(pNode->p2)->pRepr )
00628 printf( "Internal node %d has second fanin that is a secondary node.\n", pNode->Num );
00629 }
00630 }
00631 Map_NodeVecFree( pVec );
00632 return 1;
00633 }
00634
00646 int Map_MappingNodeIsViolator( Map_Node_t * pNode, Map_Cut_t * pCut, int fPosPol )
00647 {
00648 return pNode->nRefAct[fPosPol] > (int)pCut->M[fPosPol].pSuperBest->nFanLimit;
00649 }
00650
00662 float Map_MappingGetAreaFlow( Map_Man_t * p )
00663 {
00664 Map_Node_t * pNode;
00665 Map_Cut_t * pCut;
00666 float aFlowFlowTotal = 0;
00667 int fPosPol, i;
00668 for ( i = 0; i < p->nOutputs; i++ )
00669 {
00670 pNode = Map_Regular(p->pOutputs[i]);
00671 if ( !Map_NodeIsAnd(pNode) )
00672 continue;
00673 fPosPol = !Map_IsComplement(p->pOutputs[i]);
00674 pCut = pNode->pCutBest[fPosPol];
00675 if ( pCut == NULL )
00676 {
00677 fPosPol = !fPosPol;
00678 pCut = pNode->pCutBest[fPosPol];
00679 }
00680 aFlowFlowTotal += pNode->pCutBest[fPosPol]->M[fPosPol].AreaFlow;
00681 }
00682 return aFlowFlowTotal;
00683 }
00684
00685
00697 int Map_CompareNodesByLevel( Map_Node_t ** ppS1, Map_Node_t ** ppS2 )
00698 {
00699 Map_Node_t * pN1 = Map_Regular(*ppS1);
00700 Map_Node_t * pN2 = Map_Regular(*ppS2);
00701 if ( pN1->Level > pN2->Level )
00702 return -1;
00703 if ( pN1->Level < pN2->Level )
00704 return 1;
00705 return 0;
00706 }
00707
00719 void Map_MappingSortByLevel( Map_Man_t * pMan, Map_NodeVec_t * vNodes )
00720 {
00721 qsort( (void *)vNodes->pArray, vNodes->nSize, sizeof(Map_Node_t *),
00722 (int (*)(const void *, const void *)) Map_CompareNodesByLevel );
00723
00724 }
00725
00726
00738 int Map_CompareNodesByPointer( Map_Node_t ** ppS1, Map_Node_t ** ppS2 )
00739 {
00740 if ( *ppS1 < *ppS2 )
00741 return -1;
00742 if ( *ppS1 > *ppS2 )
00743 return 1;
00744 return 0;
00745 }
00746
00758 int Map_MappingCountDoubles( Map_Man_t * pMan, Map_NodeVec_t * vNodes )
00759 {
00760 Map_Node_t * pNode;
00761 int Counter, i;
00762
00763 Counter = 0;
00764 for ( i = 0; i < vNodes->nSize; i++ )
00765 {
00766 pNode = vNodes->pArray[i];
00767 if ( !Map_NodeIsAnd(pNode) )
00768 continue;
00769 if ( (pNode->nRefAct[0] && pNode->pCutBest[0]) &&
00770 (pNode->nRefAct[1] && pNode->pCutBest[1]) )
00771 Counter++;
00772 }
00773 return Counter;
00774 }
00775
00776
00788 st_table * Map_CreateTableGate2Super( Map_Man_t * pMan )
00789 {
00790 Map_Super_t * pSuper;
00791 st_table * tTable;
00792 int i, nInputs, v;
00793 tTable = st_init_table(strcmp, st_strhash);
00794 for ( i = 0; i < pMan->pSuperLib->nSupersAll; i++ )
00795 {
00796 pSuper = pMan->pSuperLib->ppSupers[i];
00797 if ( pSuper->nGates == 1 )
00798 {
00799
00800 nInputs = Mio_GateReadInputs(pSuper->pRoot);
00801 for ( v = 0; v < nInputs; v++ )
00802 if ( pSuper->pFanins[v]->Num != nInputs - 1 - v )
00803 break;
00804 if ( v != nInputs )
00805 continue;
00806
00807 if ( st_insert( tTable, (char *)pSuper->pRoot, (char *)pSuper ) )
00808 {
00809 assert( 0 );
00810 }
00811 }
00812 }
00813 return tTable;
00814 }
00815
00827 void Map_ManCleanData( Map_Man_t * p )
00828 {
00829 int i;
00830 for ( i = 0; i < p->vNodesAll->nSize; i++ )
00831 p->vNodesAll->pArray[i]->pData0 = p->vNodesAll->pArray[i]->pData1 = 0;
00832 }
00833
00845 void Map_MappingExpandTruth( unsigned uTruth[2], int nVars )
00846 {
00847 assert( nVars < 7 );
00848 if ( nVars == 6 )
00849 return;
00850 if ( nVars < 5 )
00851 {
00852 uTruth[0] &= MAP_MASK( (1<<nVars) );
00853 uTruth[0] = Map_MappingExpandTruth_rec( uTruth[0], nVars );
00854 }
00855 uTruth[1] = uTruth[0];
00856 }
00857
00869 unsigned Map_MappingExpandTruth_rec( unsigned uTruth, int nVars )
00870 {
00871 assert( nVars < 6 );
00872 if ( nVars == 5 )
00873 return uTruth;
00874 return Map_MappingExpandTruth_rec( uTruth | (uTruth << (1 << nVars)), nVars + 1 );
00875 }
00876
00888 float Map_MappingComputeDelayWithFanouts( Map_Man_t * p )
00889 {
00890 Map_Node_t * pNode;
00891 float Result;
00892 int i;
00893 for ( i = 0; i < p->vAnds->nSize; i++ )
00894 {
00895
00896 pNode = p->vAnds->pArray[i];
00897 if ( !Map_NodeIsAnd( pNode ) )
00898 continue;
00899
00900 if ( pNode->pRepr )
00901 continue;
00902
00903 if ( pNode->nRefAct[0] > 0 )
00904 Map_TimeCutComputeArrival( pNode, pNode->pCutBest[0], 0, MAP_FLOAT_LARGE );
00905 if ( pNode->nRefAct[1] > 0 )
00906 Map_TimeCutComputeArrival( pNode, pNode->pCutBest[1], 1, MAP_FLOAT_LARGE );
00907 }
00908 Result = Map_TimeComputeArrivalMax(p);
00909 printf( "Max arrival times with fanouts = %10.2f.\n", Result );
00910 return Result;
00911 }
00912
00913
00925 int Map_MappingGetMaxLevel( Map_Man_t * pMan )
00926 {
00927 int nLevelMax, i;
00928 nLevelMax = 0;
00929 for ( i = 0; i < pMan->nOutputs; i++ )
00930 nLevelMax = ((unsigned)nLevelMax) > Map_Regular(pMan->pOutputs[i])->Level?
00931 nLevelMax : Map_Regular(pMan->pOutputs[i])->Level;
00932 return nLevelMax;
00933 }
00934
00946 int Map_MappingUpdateLevel_rec( Map_Man_t * pMan, Map_Node_t * pNode, int fMaximum )
00947 {
00948 Map_Node_t * pTemp;
00949 int Level1, Level2, LevelE;
00950 assert( !Map_IsComplement(pNode) );
00951 if ( !Map_NodeIsAnd(pNode) )
00952 return pNode->Level;
00953
00954 if ( pNode->TravId == pMan->nTravIds )
00955 return pNode->Level;
00956 pNode->TravId = pMan->nTravIds;
00957
00958 Level1 = Map_MappingUpdateLevel_rec( pMan, Map_Regular(pNode->p1), fMaximum );
00959 Level2 = Map_MappingUpdateLevel_rec( pMan, Map_Regular(pNode->p2), fMaximum );
00960 pNode->Level = 1 + MAP_MAX( Level1, Level2 );
00961 if ( pNode->pNextE )
00962 {
00963 LevelE = Map_MappingUpdateLevel_rec( pMan, pNode->pNextE, fMaximum );
00964 if ( fMaximum )
00965 {
00966 if ( pNode->Level < (unsigned)LevelE )
00967 pNode->Level = LevelE;
00968 }
00969 else
00970 {
00971 if ( pNode->Level > (unsigned)LevelE )
00972 pNode->Level = LevelE;
00973 }
00974
00975 if ( pNode->pRepr == NULL )
00976 for ( pTemp = pNode->pNextE; pTemp; pTemp = pTemp->pNextE )
00977 pTemp->Level = pNode->Level;
00978 }
00979 return pNode->Level;
00980 }
00981
00996 void Map_MappingSetChoiceLevels( Map_Man_t * pMan )
00997 {
00998 int i;
00999 pMan->nTravIds++;
01000 for ( i = 0; i < pMan->nOutputs; i++ )
01001 Map_MappingUpdateLevel_rec( pMan, Map_Regular(pMan->pOutputs[i]), 1 );
01002 }
01003
01017 void Map_MappingReportChoices( Map_Man_t * pMan )
01018 {
01019 Map_Node_t * pNode, * pTemp;
01020 int nChoiceNodes, nChoices;
01021 int i, LevelMax1, LevelMax2;
01022
01023
01024 LevelMax1 = Map_MappingGetMaxLevel( pMan );
01025 pMan->nTravIds++;
01026 for ( i = 0; i < pMan->nOutputs; i++ )
01027 Map_MappingUpdateLevel_rec( pMan, Map_Regular(pMan->pOutputs[i]), 0 );
01028 LevelMax2 = Map_MappingGetMaxLevel( pMan );
01029
01030
01031 nChoiceNodes = nChoices = 0;
01032 for ( i = 0; i < pMan->vAnds->nSize; i++ )
01033 {
01034 pNode = pMan->vAnds->pArray[i];
01035 if ( pNode->pRepr == NULL && pNode->pNextE != NULL )
01036 {
01037 nChoiceNodes++;
01038 for ( pTemp = pNode; pTemp; pTemp = pTemp->pNextE )
01039 nChoices++;
01040 }
01041 }
01042 printf( "Maximum level: Original = %d. Reduced due to choices = %d.\n", LevelMax1, LevelMax2 );
01043 printf( "Choice stats: Choice nodes = %d. Total choices = %d.\n", nChoiceNodes, nChoices );
01044 }
01045
01057 void Map_MappingGetChoiceLevels( Map_Man_t * pMan, Map_Node_t * p1, Map_Node_t * p2, int * pMin, int * pMax )
01058 {
01059 Map_NodeVec_t * vNodes;
01060 Map_NodeVec_t * vBoundary;
01061 Map_Node_t * pNode;
01062 int i, Min, Max;
01063
01064 vNodes = Map_NodeVecAlloc( 100 );
01065 vBoundary = Map_NodeVecAlloc( 100 );
01066 Map_MappingDfsMarked1_rec( p1, vNodes, 1 );
01067 Map_MappingDfsMarked2_rec( p2, vNodes, vBoundary, 1 );
01068
01069 Min = 100000;
01070 Max = -100000;
01071 for ( i = 0; i < vBoundary->nSize; i++ )
01072 {
01073 pNode = vBoundary->pArray[i];
01074 if ( Min > (int)pNode->Level )
01075 Min = pNode->Level;
01076 if ( Max < (int)pNode->Level )
01077 Max = pNode->Level;
01078 }
01079 Map_NodeVecFree( vBoundary );
01080 for ( i = 0; i < vNodes->nSize; i++ )
01081 {
01082 pNode = vNodes->pArray[i];
01083 pNode->fMark0 = pNode->fMark1 = 0;
01084 }
01085 Map_NodeVecFree( vNodes );
01086 *pMin = Min;
01087 *pMax = Max;
01088 }
01089
01090
01102 float Map_MappingGetChoiceVolumes( Map_Man_t * pMan, Map_Node_t * p1, Map_Node_t * p2 )
01103 {
01104 Map_NodeVec_t * vNodes;
01105 Map_Node_t * pNode;
01106 int i, nVolumeTotal, nVolumeUnique;
01107
01108 vNodes = Map_NodeVecAlloc( 100 );
01109 Map_MappingDfsMarked3_rec( p1, vNodes );
01110 Map_MappingDfsMarked4_rec( p2, vNodes );
01111
01112 nVolumeTotal = nVolumeUnique = 0;
01113 for ( i = 0; i < vNodes->nSize; i++ )
01114 {
01115 pNode = vNodes->pArray[i];
01116 if ( !Map_NodeIsAnd(pNode) )
01117 continue;
01118 nVolumeTotal++;
01119 if ( pNode->fMark0 ^ pNode->fMark1 )
01120 nVolumeUnique++;
01121 pNode->fMark0 = pNode->fMark1 = 0;
01122 }
01123 Map_NodeVecFree( vNodes );
01124
01125 return (float)nVolumeUnique;
01126 }
01127
01128
01140 int Map_MappingCountUsedNodes( Map_Man_t * pMan, int fChoices )
01141 {
01142 Map_NodeVec_t * vNodes;
01143 int Result;
01144 vNodes = Map_MappingDfs( pMan, fChoices );
01145 Result = vNodes->nSize;
01146 Map_NodeVecFree( vNodes );
01147 return Result;
01148 }
01149
01153
01154