00001
00021 #include "lpkInt.h"
00022
00026
00030
00042 int Lpk_MapTreeBestCofVar( Lpk_Man_t * p, unsigned * pTruth, int nVars, unsigned * pCof0, unsigned * pCof1 )
00043 {
00044 int i, iBestVar, nSuppSizeCur0, nSuppSizeCur1, nSuppSizeCur, nSuppSizeMin;
00045
00046 iBestVar = -1;
00047 nSuppSizeMin = KIT_INFINITY;
00048 for ( i = 0; i < nVars; i++ )
00049 {
00050
00051 Kit_TruthCofactor0New( pCof0, pTruth, nVars, i );
00052 Kit_TruthCofactor1New( pCof1, pTruth, nVars, i );
00053 nSuppSizeCur0 = Kit_TruthSupportSize( pCof0, nVars );
00054 nSuppSizeCur1 = Kit_TruthSupportSize( pCof1, nVars );
00055 nSuppSizeCur = nSuppSizeCur0 + nSuppSizeCur1;
00056
00057 if ( nSuppSizeCur0 > p->pPars->nLutSize || nSuppSizeCur1 > p->pPars->nLutSize )
00058 continue;
00059
00060 if ( nSuppSizeMin > nSuppSizeCur )
00061 {
00062 nSuppSizeMin = nSuppSizeCur;
00063 iBestVar = i;
00064 }
00065 }
00066
00067 if ( iBestVar != -1 )
00068 {
00069 Kit_TruthCofactor0New( pCof0, pTruth, nVars, iBestVar );
00070 Kit_TruthCofactor1New( pCof1, pTruth, nVars, iBestVar );
00071 }
00072 return iBestVar;
00073 }
00074
00086 If_Obj_t * Lpk_MapTreeMux_rec( Lpk_Man_t * p, unsigned * pTruth, int nVars, If_Obj_t ** ppLeaves )
00087 {
00088 unsigned * pCof0 = Vec_PtrEntry( p->vTtNodes, 0 );
00089 unsigned * pCof1 = Vec_PtrEntry( p->vTtNodes, 1 );
00090 If_Obj_t * pObj0, * pObj1;
00091 Kit_DsdNtk_t * ppNtks[2];
00092 int iBestVar;
00093 assert( nVars > 3 );
00094 p->fCalledOnce = 1;
00095
00096 iBestVar = Lpk_MapTreeBestCofVar( p, pTruth, nVars, pCof0, pCof1 );
00097 if ( iBestVar == -1 )
00098 return NULL;
00099
00100 ppNtks[0] = Kit_DsdDecompose( pCof0, nVars );
00101 ppNtks[1] = Kit_DsdDecompose( pCof1, nVars );
00102 if ( p->pPars->fVeryVerbose )
00103 {
00104 printf( "Cofactoring w.r.t. var %c (%d -> %d+%d supp vars):\n",
00105 'a'+iBestVar, nVars, Kit_TruthSupportSize(pCof0, nVars), Kit_TruthSupportSize(pCof1, nVars) );
00106 Kit_DsdPrintExpanded( ppNtks[0] );
00107 Kit_DsdPrintExpanded( ppNtks[1] );
00108 }
00109
00110 pObj0 = Lpk_MapTree_rec( p, ppNtks[0], ppLeaves, ppNtks[0]->Root, NULL );
00111 pObj1 = Lpk_MapTree_rec( p, ppNtks[1], ppLeaves, ppNtks[1]->Root, NULL );
00112 Kit_DsdNtkFree( ppNtks[0] );
00113 Kit_DsdNtkFree( ppNtks[1] );
00114 return If_ManCreateMux( p->pIfMan, pObj0, pObj1, ppLeaves[iBestVar] );
00115 }
00116
00117
00118
00130 If_Obj_t * Lpk_MapSuppRedDec_rec( Lpk_Man_t * p, unsigned * pTruth, int nVars, If_Obj_t ** ppLeaves )
00131 {
00132 Kit_DsdNtk_t * pNtkDec, * pNtkComp, * ppNtks[2], * pTemp;
00133 If_Obj_t * pObjNew;
00134 unsigned * pCof0 = Vec_PtrEntry( p->vTtNodes, 0 );
00135 unsigned * pCof1 = Vec_PtrEntry( p->vTtNodes, 1 );
00136 unsigned * pDec0 = Vec_PtrEntry( p->vTtNodes, 2 );
00137 unsigned * pDec1 = Vec_PtrEntry( p->vTtNodes, 3 );
00138 unsigned * pDec = Vec_PtrEntry( p->vTtNodes, 4 );
00139 unsigned * pCo00 = Vec_PtrEntry( p->vTtNodes, 5 );
00140 unsigned * pCo01 = Vec_PtrEntry( p->vTtNodes, 6 );
00141 unsigned * pCo10 = Vec_PtrEntry( p->vTtNodes, 7 );
00142 unsigned * pCo11 = Vec_PtrEntry( p->vTtNodes, 8 );
00143 unsigned * pCo0 = Vec_PtrEntry( p->vTtNodes, 9 );
00144 unsigned * pCo1 = Vec_PtrEntry( p->vTtNodes, 10 );
00145 unsigned * pCo = Vec_PtrEntry( p->vTtNodes, 11 );
00146 int TrueMint0, TrueMint1, FalseMint0, FalseMint1;
00147 int uSubsets, uSubset0, uSubset1, iVar, iVarReused, i;
00148
00149
00150 uSubsets = Lpk_MapSuppRedDecSelect( p, pTruth, nVars, &iVar, &iVarReused );
00151 if ( uSubsets == 0 )
00152 return NULL;
00153 p->nCalledSRed++;
00154
00155
00156 Kit_TruthCofactor0New( pCof0, pTruth, nVars, iVar );
00157 Kit_TruthCofactor1New( pCof1, pTruth, nVars, iVar );
00158
00159
00160 uSubset0 = uSubsets & 0xFFFF;
00161 uSubset1 = uSubsets >> 16;
00162
00163
00164 ppNtks[0] = Kit_DsdDecompose( pCof0, nVars );
00165 ppNtks[1] = Kit_DsdDecompose( pCof1, nVars );
00166 ppNtks[0] = Kit_DsdExpand( pTemp = ppNtks[0] ); Kit_DsdNtkFree( pTemp );
00167 ppNtks[1] = Kit_DsdExpand( pTemp = ppNtks[1] ); Kit_DsdNtkFree( pTemp );
00168 Kit_DsdTruthPartial( p->pDsdMan, ppNtks[0], pDec0, uSubset0 );
00169 Kit_DsdTruthPartial( p->pDsdMan, ppNtks[1], pDec1, uSubset1 );
00170
00171
00172 Kit_DsdNtkFree( ppNtks[0] );
00173 Kit_DsdNtkFree( ppNtks[1] );
00174
00175
00176
00177 Kit_TruthMuxVar( pDec, pDec0, pDec1, nVars, iVar );
00178
00179
00180 TrueMint0 = Kit_TruthFindFirstBit( pDec0, nVars );
00181 TrueMint1 = Kit_TruthFindFirstBit( pDec1, nVars );
00182 assert( TrueMint0 >= 0 && TrueMint1 >= 0 );
00183
00184 FalseMint0 = Kit_TruthFindFirstZero( pDec0, nVars );
00185 FalseMint1 = Kit_TruthFindFirstZero( pDec1, nVars );
00186 assert( FalseMint0 >= 0 && FalseMint1 >= 0 );
00187
00188
00189 Kit_TruthCopy( pCo00, pCof0, nVars );
00190 Kit_TruthCopy( pCo01, pCof0, nVars );
00191 for ( i = 0; i < nVars; i++ )
00192 if ( uSubset0 & (1 << i) )
00193 {
00194 if ( FalseMint0 & (1 << i) )
00195 Kit_TruthCofactor1( pCo00, nVars, i );
00196 else
00197 Kit_TruthCofactor0( pCo00, nVars, i );
00198 if ( TrueMint0 & (1 << i) )
00199 Kit_TruthCofactor1( pCo01, nVars, i );
00200 else
00201 Kit_TruthCofactor0( pCo01, nVars, i );
00202 }
00203 Kit_TruthCopy( pCo10, pCof1, nVars );
00204 Kit_TruthCopy( pCo11, pCof1, nVars );
00205 for ( i = 0; i < nVars; i++ )
00206 if ( uSubset1 & (1 << i) )
00207 {
00208 if ( FalseMint1 & (1 << i) )
00209 Kit_TruthCofactor1( pCo10, nVars, i );
00210 else
00211 Kit_TruthCofactor0( pCo10, nVars, i );
00212 if ( TrueMint1 & (1 << i) )
00213 Kit_TruthCofactor1( pCo11, nVars, i );
00214 else
00215 Kit_TruthCofactor0( pCo11, nVars, i );
00216 }
00217
00218
00219 Kit_TruthMuxVar( pCo0, pCo00, pCo01, nVars, iVarReused );
00220 Kit_TruthMuxVar( pCo1, pCo10, pCo11, nVars, iVarReused );
00221
00222
00223
00224
00225 Kit_TruthMuxVar( pCo , pCo0 , pCo1 , nVars, iVar );
00226
00227
00228 pNtkDec = Kit_DsdDecompose( pDec, nVars );
00229 pNtkComp = Kit_DsdDecompose( pCo, nVars );
00230
00231
00232
00233
00234
00235 ppLeaves[iVarReused] = Lpk_MapTree_rec( p, pNtkDec, ppLeaves, pNtkDec->Root, NULL );
00236 pObjNew = Lpk_MapTree_rec( p, pNtkComp, ppLeaves, pNtkComp->Root, NULL );
00237
00238 Kit_DsdNtkFree( pNtkDec );
00239 Kit_DsdNtkFree( pNtkComp );
00240 return pObjNew;
00241 }
00242
00246
00247