00001
00019 #include "mapperInt.h"
00020
00024
00025 static void Map_TruthsCut( Map_Man_t * pMan, Map_Cut_t * pCut );
00026 extern void Map_TruthsCutOne( Map_Man_t * p, Map_Cut_t * pCut, unsigned uTruth[] );
00027 static void Map_CutsCollect_rec( Map_Cut_t * pCut, Map_NodeVec_t * vVisited );
00028
00032
00044 void Map_MappingTruths( Map_Man_t * pMan )
00045 {
00046 ProgressBar * pProgress;
00047 Map_Node_t * pNode;
00048 Map_Cut_t * pCut;
00049 int nNodes, i;
00050
00051 nNodes = pMan->vAnds->nSize;
00052 pProgress = Extra_ProgressBarStart( stdout, nNodes );
00053 for ( i = 0; i < nNodes; i++ )
00054 {
00055 pNode = pMan->vAnds->pArray[i];
00056 if ( !Map_NodeIsAnd( pNode ) )
00057 continue;
00058 assert( pNode->pCuts );
00059 assert( pNode->pCuts->nLeaves == 1 );
00060
00061
00062 pNode->pCuts->M[0].uPhase = 0;
00063 pNode->pCuts->M[0].pSupers = pMan->pSuperLib->pSuperInv;
00064 pNode->pCuts->M[0].uPhaseBest = 0;
00065 pNode->pCuts->M[0].pSuperBest = pMan->pSuperLib->pSuperInv;
00066
00067 pNode->pCuts->M[1].uPhase = 0;
00068 pNode->pCuts->M[1].pSupers = pMan->pSuperLib->pSuperInv;
00069 pNode->pCuts->M[1].uPhaseBest = 1;
00070 pNode->pCuts->M[1].pSuperBest = pMan->pSuperLib->pSuperInv;
00071
00072
00073 for ( pCut = pNode->pCuts->pNext; pCut; pCut = pCut->pNext )
00074 Map_TruthsCut( pMan, pCut );
00075 Extra_ProgressBarUpdate( pProgress, i, "Tables ..." );
00076 }
00077 Extra_ProgressBarStop( pProgress );
00078 }
00079
00091 void Map_TruthsCut( Map_Man_t * p, Map_Cut_t * pCut )
00092 {
00093
00094 unsigned uTruth[2], uCanon[2];
00095 unsigned char uPhases[16];
00096 unsigned * uCanon2;
00097 char * pPhases2;
00098 int fUseFast = 1;
00099 int fUseSlow = 0;
00100 int fUseRec = 0;
00101
00102 extern int Map_CanonCompute( int nVarsMax, int nVarsReal, unsigned * pt, unsigned ** pptRes, char ** ppfRes );
00103
00104
00105 if ( pCut->nLeaves == 1 )
00106 return;
00107
00108
00109
00110
00111
00112
00113
00114
00115 Map_TruthsCutOne( p, pCut, uTruth );
00116
00117
00118
00119 if ( fUseFast )
00120 Map_CanonComputeFast( p, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
00121 else if ( fUseSlow )
00122 Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
00123 else if ( fUseRec )
00124 {
00125
00126 Extra_TruthCanonFastN( p->nVarsMax, pCut->nLeaves, uTruth, &uCanon2, &pPhases2 );
00127
00128
00129
00130
00131
00132
00133
00134 uCanon[0] = uCanon2[0];
00135 uCanon[1] = (p->nVarsMax == 6)? uCanon2[1] : uCanon2[0];
00136 uPhases[0] = pPhases2[0];
00137 }
00138 else
00139 Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
00140 pCut->M[1].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
00141 pCut->M[1].uPhase = uPhases[0];
00142 p->nCanons++;
00143
00144
00145
00146
00147 uTruth[0] = ~uTruth[0];
00148 uTruth[1] = ~uTruth[1];
00149 if ( fUseFast )
00150 Map_CanonComputeFast( p, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
00151 else if ( fUseSlow )
00152 Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
00153 else if ( fUseRec )
00154 {
00155
00156 Extra_TruthCanonFastN( p->nVarsMax, pCut->nLeaves, uTruth, &uCanon2, &pPhases2 );
00157
00158
00159
00160
00161
00162
00163
00164 uCanon[0] = uCanon2[0];
00165 uCanon[1] = (p->nVarsMax == 6)? uCanon2[1] : uCanon2[0];
00166 uPhases[0] = pPhases2[0];
00167 }
00168 else
00169 Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
00170 pCut->M[0].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
00171 pCut->M[0].uPhase = uPhases[0];
00172 p->nCanons++;
00173
00174
00175
00176
00177
00178
00179 uTruth[0] = ~uTruth[0];
00180 uTruth[1] = ~uTruth[1];
00181 }
00182
00194 void Map_TruthsCutOne( Map_Man_t * p, Map_Cut_t * pCut, unsigned uTruth[] )
00195 {
00196 unsigned uTruth1[2], uTruth2[2];
00197 Map_Cut_t * pTemp;
00198 int i;
00199
00200 for ( i = 0; i < pCut->nLeaves; i++ )
00201 {
00202 pTemp = pCut->ppLeaves[i]->pCuts;
00203 pTemp->fMark = 1;
00204 pTemp->M[0].uPhaseBest = p->uTruths[i][0];
00205 pTemp->M[1].uPhaseBest = p->uTruths[i][1];
00206 }
00207 assert( pCut->fMark == 0 );
00208
00209
00210 p->vVisited->nSize = 0;
00211 Map_CutsCollect_rec( pCut, p->vVisited );
00212 assert( p->vVisited->nSize > 0 );
00213 pCut->nVolume = p->vVisited->nSize;
00214
00215
00216 for ( i = 0; i < pCut->nLeaves; i++ )
00217 {
00218 pTemp = pCut->ppLeaves[i]->pCuts;
00219 pTemp->fMark = 0;
00220 }
00221 for ( i = 0; i < p->vVisited->nSize; i++ )
00222 {
00223
00224 pTemp = (Map_Cut_t *)p->vVisited->pArray[i];
00225 pTemp->fMark = 0;
00226
00227 if ( Map_CutIsComplement(pTemp->pOne) )
00228 {
00229 uTruth1[0] = ~Map_CutRegular(pTemp->pOne)->M[0].uPhaseBest;
00230 uTruth1[1] = ~Map_CutRegular(pTemp->pOne)->M[1].uPhaseBest;
00231 }
00232 else
00233 {
00234 uTruth1[0] = Map_CutRegular(pTemp->pOne)->M[0].uPhaseBest;
00235 uTruth1[1] = Map_CutRegular(pTemp->pOne)->M[1].uPhaseBest;
00236 }
00237
00238 if ( Map_CutIsComplement(pTemp->pTwo) )
00239 {
00240 uTruth2[0] = ~Map_CutRegular(pTemp->pTwo)->M[0].uPhaseBest;
00241 uTruth2[1] = ~Map_CutRegular(pTemp->pTwo)->M[1].uPhaseBest;
00242 }
00243 else
00244 {
00245 uTruth2[0] = Map_CutRegular(pTemp->pTwo)->M[0].uPhaseBest;
00246 uTruth2[1] = Map_CutRegular(pTemp->pTwo)->M[1].uPhaseBest;
00247 }
00248
00249 if ( !pTemp->Phase )
00250 {
00251 pTemp->M[0].uPhaseBest = uTruth1[0] & uTruth2[0];
00252 pTemp->M[1].uPhaseBest = uTruth1[1] & uTruth2[1];
00253 }
00254 else
00255 {
00256 pTemp->M[0].uPhaseBest = ~(uTruth1[0] & uTruth2[0]);
00257 pTemp->M[1].uPhaseBest = ~(uTruth1[1] & uTruth2[1]);
00258 }
00259 }
00260 uTruth[0] = pTemp->M[0].uPhaseBest;
00261 uTruth[1] = pTemp->M[1].uPhaseBest;
00262 }
00263
00275 void Map_CutsCollect_rec( Map_Cut_t * pCut, Map_NodeVec_t * vVisited )
00276 {
00277 if ( pCut->fMark )
00278 return;
00279 Map_CutsCollect_rec( Map_CutRegular(pCut->pOne), vVisited );
00280 Map_CutsCollect_rec( Map_CutRegular(pCut->pTwo), vVisited );
00281 assert( pCut->fMark == 0 );
00282 pCut->fMark = 1;
00283 Map_NodeVecPush( vVisited, (Map_Node_t *)pCut );
00284 }
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00309
00310