00001
00019 #include "mapperInt.h"
00020
00024
00025 static float Map_SwitchCutRefDeref( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase, int fReference );
00026
00030
00042 float Map_SwitchCutGetDerefed( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase )
00043 {
00044 float aResult, aResult2;
00045
00046 aResult2 = Map_SwitchCutRefDeref( pNode, pCut, fPhase, 1 );
00047 aResult = Map_SwitchCutRefDeref( pNode, pCut, fPhase, 0 );
00048
00049 return aResult;
00050 }
00051
00063 float Map_SwitchCutRef( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase )
00064 {
00065 return Map_SwitchCutRefDeref( pNode, pCut, fPhase, 1 );
00066 }
00067
00079 float Map_SwitchCutDeref( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase )
00080 {
00081 return Map_SwitchCutRefDeref( pNode, pCut, fPhase, 0 );
00082 }
00083
00096 float Map_SwitchCutRefDeref( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase, int fReference )
00097 {
00098 Map_Node_t * pNodeChild;
00099 Map_Cut_t * pCutChild;
00100 float aSwitchActivity;
00101 int i, fPhaseChild;
00102
00103
00104 aSwitchActivity = pNode->Switching;
00105
00106 if ( pCut->nLeaves == 1 )
00107 return aSwitchActivity;
00108
00109
00110 assert( pCut->M[fPhase].pSuperBest );
00111 for ( i = 0; i < pCut->nLeaves; i++ )
00112 {
00113 pNodeChild = pCut->ppLeaves[i];
00114 fPhaseChild = Map_CutGetLeafPhase( pCut, fPhase, i );
00115
00116
00117 if ( fReference )
00118 {
00119 if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] )
00120 {
00121
00122 pNodeChild->nRefAct[2]++;
00123 if ( pNodeChild->nRefAct[fPhaseChild]++ > 0 )
00124 continue;
00125 }
00126 else
00127 {
00128
00129
00130 if ( pNodeChild->nRefAct[fPhaseChild]++ == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
00131 aSwitchActivity += pNodeChild->Switching;
00132
00133 if ( pNodeChild->nRefAct[2]++ > 0 )
00134 continue;
00135 }
00136 }
00137 else
00138 {
00139 if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] )
00140 {
00141
00142 --pNodeChild->nRefAct[2];
00143 if ( --pNodeChild->nRefAct[fPhaseChild] > 0 )
00144 continue;
00145 }
00146 else
00147 {
00148
00149
00150 if ( --pNodeChild->nRefAct[fPhaseChild] == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
00151 aSwitchActivity += pNodeChild->Switching;
00152
00153 if ( --pNodeChild->nRefAct[2] > 0 )
00154 continue;
00155 }
00156 assert( pNodeChild->nRefAct[fPhaseChild] >= 0 );
00157 }
00158
00159
00160 pCutChild = pNodeChild->pCutBest[fPhaseChild];
00161
00162 if ( pCutChild == NULL )
00163 {
00164 fPhaseChild = !fPhaseChild;
00165 pCutChild = pNodeChild->pCutBest[fPhaseChild];
00166 }
00167
00168 aSwitchActivity += Map_SwitchCutRefDeref( pNodeChild, pCutChild, fPhaseChild, fReference );
00169 }
00170 return aSwitchActivity;
00171 }
00172
00184 float Map_MappingGetSwitching( Map_Man_t * pMan, Map_NodeVec_t * vMapping )
00185 {
00186 Map_Node_t * pNode;
00187 float Switch;
00188 int i;
00189 Switch = 0.0;
00190 for ( i = 0; i < vMapping->nSize; i++ )
00191 {
00192 pNode = vMapping->pArray[i];
00193
00194 assert( pNode->pCutBest[0] != NULL || pNode->pCutBest[1] != NULL );
00195
00196 assert( pNode->nRefAct[0] > 0 || pNode->nRefAct[1] > 0 );
00197
00198 if ( Map_NodeIsAnd(pNode) )
00199 {
00200
00201 if ( pNode->pCutBest[0] && (pNode->nRefAct[0] > 0 || pNode->pCutBest[1] == NULL) )
00202 Switch += pNode->Switching;
00203
00204 if ( pNode->pCutBest[1] && (pNode->nRefAct[1] > 0 || pNode->pCutBest[0] == NULL) )
00205 Switch += pNode->Switching;
00206 }
00207
00208 if ( (pNode->pCutBest[0] == NULL && pNode->nRefAct[0] > 0) ||
00209 (pNode->pCutBest[1] == NULL && pNode->nRefAct[1] > 0) )
00210 Switch += pNode->Switching;
00211 }
00212
00213 for ( i = 0; i < pMan->nOutputs; i++ )
00214 if ( Map_NodeIsVar(pMan->pOutputs[i]) && !Map_IsComplement(pMan->pOutputs[i]) )
00215 Switch += pMan->pOutputs[i]->Switching;
00216 return Switch;
00217 }
00218
00222
00223