00001
00021 #include "lpkInt.h"
00022
00026
00030
00042 Lpk_Res_t * Lpk_MuxAnalize( Lpk_Man_t * pMan, Lpk_Fun_t * p )
00043 {
00044 static Lpk_Res_t Res, * pRes = &Res;
00045 int nSuppSize0, nSuppSize1, nSuppSizeS, nSuppSizeL;
00046 int Var, Area, Polarity, Delay, Delay0, Delay1, DelayA, DelayB;
00047 memset( pRes, 0, sizeof(Lpk_Res_t) );
00048 assert( p->uSupp == Kit_BitMask(p->nVars) );
00049 assert( p->fSupports );
00050
00051 pRes->Variable = -1;
00052 Lpk_SuppForEachVar( p->uSupp, Var )
00053 {
00054 nSuppSize0 = Kit_WordCountOnes(p->puSupps[2*Var+0]);
00055 nSuppSize1 = Kit_WordCountOnes(p->puSupps[2*Var+1]);
00056 assert( nSuppSize0 < (int)p->nVars );
00057 assert( nSuppSize1 < (int)p->nVars );
00058 if ( nSuppSize0 < 1 || nSuppSize1 < 1 )
00059 continue;
00060
00061 if ( nSuppSize0 <= (int)p->nLutK - 2 && nSuppSize1 <= (int)p->nLutK - 2 )
00062 {
00063
00064 DelayA = Lpk_SuppDelay( p->puSupps[2*Var+0] | (1<<Var), p->pDelays );
00065 DelayB = Lpk_SuppDelay( p->puSupps[2*Var+1] , p->pDelays );
00066 Delay0 = ABC_MAX( DelayA, DelayB + 1 );
00067
00068 DelayA = Lpk_SuppDelay( p->puSupps[2*Var+1] | (1<<Var), p->pDelays );
00069 DelayB = Lpk_SuppDelay( p->puSupps[2*Var+0] , p->pDelays );
00070 Delay1 = ABC_MAX( DelayA, DelayB + 1 );
00071
00072 Delay = ABC_MIN( Delay0, Delay1 );
00073 Area = 2;
00074 Polarity = (int)(Delay == Delay1);
00075 }
00076 else if ( nSuppSize0 <= (int)p->nLutK - 2 )
00077 {
00078 DelayA = Lpk_SuppDelay( p->puSupps[2*Var+0] | (1<<Var), p->pDelays );
00079 DelayB = Lpk_SuppDelay( p->puSupps[2*Var+1] , p->pDelays );
00080 Delay = ABC_MAX( DelayA, DelayB + 1 );
00081 Area = 1 + Lpk_LutNumLuts( nSuppSize1, p->nLutK );
00082 Polarity = 0;
00083 }
00084 else if ( nSuppSize1 <= (int)p->nLutK - 2 )
00085 {
00086 DelayA = Lpk_SuppDelay( p->puSupps[2*Var+1] | (1<<Var), p->pDelays );
00087 DelayB = Lpk_SuppDelay( p->puSupps[2*Var+0] , p->pDelays );
00088 Delay = ABC_MAX( DelayA, DelayB + 1 );
00089 Area = 1 + Lpk_LutNumLuts( nSuppSize0, p->nLutK );
00090 Polarity = 1;
00091 }
00092 else if ( nSuppSize0 <= (int)p->nLutK )
00093 {
00094 DelayA = Lpk_SuppDelay( p->puSupps[2*Var+1] | (1<<Var), p->pDelays );
00095 DelayB = Lpk_SuppDelay( p->puSupps[2*Var+0] , p->pDelays );
00096 Delay = ABC_MAX( DelayA, DelayB + 1 );
00097 Area = 1 + Lpk_LutNumLuts( nSuppSize1+2, p->nLutK );
00098 Polarity = 1;
00099 }
00100 else if ( nSuppSize1 <= (int)p->nLutK )
00101 {
00102 DelayA = Lpk_SuppDelay( p->puSupps[2*Var+0] | (1<<Var), p->pDelays );
00103 DelayB = Lpk_SuppDelay( p->puSupps[2*Var+1] , p->pDelays );
00104 Delay = ABC_MAX( DelayA, DelayB + 1 );
00105 Area = 1 + Lpk_LutNumLuts( nSuppSize0+2, p->nLutK );
00106 Polarity = 0;
00107 }
00108 else
00109 {
00110
00111 DelayA = Lpk_SuppDelay( p->puSupps[2*Var+0] | (1<<Var), p->pDelays );
00112 DelayB = Lpk_SuppDelay( p->puSupps[2*Var+1] , p->pDelays );
00113 Delay0 = ABC_MAX( DelayA, DelayB + 1 );
00114
00115 DelayA = Lpk_SuppDelay( p->puSupps[2*Var+1] | (1<<Var), p->pDelays );
00116 DelayB = Lpk_SuppDelay( p->puSupps[2*Var+0] , p->pDelays );
00117 Delay1 = ABC_MAX( DelayA, DelayB + 1 );
00118
00119 Delay = ABC_MIN( Delay0, Delay1 );
00120 if ( Delay == Delay0 )
00121 Area = Lpk_LutNumLuts( nSuppSize0+2, p->nLutK ) + Lpk_LutNumLuts( nSuppSize1, p->nLutK );
00122 else
00123 Area = Lpk_LutNumLuts( nSuppSize1+2, p->nLutK ) + Lpk_LutNumLuts( nSuppSize0, p->nLutK );
00124 Polarity = (int)(Delay == Delay1);
00125 }
00126
00127 if ( Delay > (int)p->nDelayLim )
00128 continue;
00129 if ( Area > (int)p->nAreaLim )
00130 continue;
00131 nSuppSizeS = ABC_MIN( nSuppSize0 + 2 *!Polarity, nSuppSize1 + 2 * Polarity );
00132 nSuppSizeL = ABC_MAX( nSuppSize0 + 2 *!Polarity, nSuppSize1 + 2 * Polarity );
00133 if ( nSuppSizeL > (int)p->nVars )
00134 continue;
00135 if ( pRes->Variable == -1 || pRes->AreaEst > Area ||
00136 (pRes->AreaEst == Area && pRes->nSuppSizeS + pRes->nSuppSizeL > nSuppSizeS + nSuppSizeL) ||
00137 (pRes->AreaEst == Area && pRes->nSuppSizeS + pRes->nSuppSizeL == nSuppSizeS + nSuppSizeL && pRes->DelayEst > Delay) )
00138 {
00139 pRes->Variable = Var;
00140 pRes->Polarity = Polarity;
00141 pRes->AreaEst = Area;
00142 pRes->DelayEst = Delay;
00143 pRes->nSuppSizeS = nSuppSizeS;
00144 pRes->nSuppSizeL = nSuppSizeL;
00145 }
00146 }
00147 return pRes->Variable == -1 ? NULL : pRes;
00148 }
00149
00161 Lpk_Fun_t * Lpk_MuxSplit( Lpk_Man_t * pMan, Lpk_Fun_t * p, int Var, int Pol )
00162 {
00163 Lpk_Fun_t * pNew;
00164 unsigned * pTruth = Lpk_FunTruth( p, 0 );
00165 unsigned * pTruth0 = Lpk_FunTruth( p, 1 );
00166 unsigned * pTruth1 = Lpk_FunTruth( p, 2 );
00167
00168 int iVarVac;
00169 assert( Var >= 0 && Var < (int)p->nVars );
00170 assert( p->nAreaLim >= 2 );
00171 assert( p->uSupp == Kit_BitMask(p->nVars) );
00172 Kit_TruthCofactor0New( pTruth0, pTruth, p->nVars, Var );
00173 Kit_TruthCofactor1New( pTruth1, pTruth, p->nVars, Var );
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 pNew = Lpk_FunDup( p, Pol ? pTruth0 : pTruth1 );
00184
00185 p->uSupp = Kit_TruthSupport( Pol ? pTruth1 : pTruth0, p->nVars );
00186 p->uSupp |= (1 << Var);
00187
00188 iVarVac = Kit_WordFindFirstBit( ~p->uSupp );
00189 assert( iVarVac < (int)p->nVars );
00190 p->uSupp |= (1 << iVarVac);
00191 Kit_TruthIthVar( pTruth, p->nVars, iVarVac );
00192 if ( Pol )
00193 Kit_TruthMuxVar( pTruth, pTruth, pTruth1, p->nVars, Var );
00194 else
00195 Kit_TruthMuxVar( pTruth, pTruth0, pTruth, p->nVars, Var );
00196 assert( p->uSupp == Kit_TruthSupport(pTruth, p->nVars) );
00197
00198 p->pFanins[iVarVac] = pNew->Id;
00199 p->pDelays[iVarVac] = p->nDelayLim - 1;
00200
00201 p->fSupports = 0;
00202 Lpk_FunSuppMinimize( p );
00203 Lpk_FunSuppMinimize( pNew );
00204
00205 pNew->nDelayLim = p->nDelayLim - 1;
00206 if ( pNew->nVars <= pNew->nLutK )
00207 {
00208 pNew->nAreaLim = 1;
00209 p->nAreaLim = p->nAreaLim - 1;
00210 }
00211 else if ( p->nVars <= p->nLutK )
00212 {
00213 pNew->nAreaLim = p->nAreaLim - 1;
00214 p->nAreaLim = 1;
00215 }
00216 else if ( p->nVars < pNew->nVars )
00217 {
00218 pNew->nAreaLim = p->nAreaLim / 2 + p->nAreaLim % 2;
00219 p->nAreaLim = p->nAreaLim / 2 - p->nAreaLim % 2;
00220 }
00221 else
00222 {
00223 pNew->nAreaLim = p->nAreaLim / 2 - p->nAreaLim % 2;
00224 p->nAreaLim = p->nAreaLim / 2 + p->nAreaLim % 2;
00225 }
00226 pNew->fMark = 1;
00227 return pNew;
00228 }
00229
00230
00234
00235