00001
00021 #include "lpkInt.h"
00022
00026
00030
00042 Lpk_Fun_t * Lpk_FunAlloc( int nVars )
00043 {
00044 Lpk_Fun_t * p;
00045 p = (Lpk_Fun_t *)malloc( sizeof(Lpk_Fun_t) + sizeof(unsigned) * Kit_TruthWordNum(nVars) * 3 );
00046 memset( p, 0, sizeof(Lpk_Fun_t) );
00047 return p;
00048 }
00049
00061 void Lpk_FunFree( Lpk_Fun_t * p )
00062 {
00063 free( p );
00064 }
00065
00077 Lpk_Fun_t * Lpk_FunCreate( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, int nLutK, int AreaLim, int DelayLim )
00078 {
00079 Lpk_Fun_t * p;
00080 Abc_Obj_t * pNode;
00081 int i;
00082 p = Lpk_FunAlloc( Vec_PtrSize(vLeaves) );
00083 p->Id = Vec_PtrSize(vLeaves);
00084 p->vNodes = vLeaves;
00085 p->nVars = Vec_PtrSize(vLeaves);
00086 p->nLutK = nLutK;
00087 p->nAreaLim = AreaLim;
00088 p->nDelayLim = DelayLim;
00089 p->uSupp = Kit_TruthSupport( pTruth, p->nVars );
00090 Kit_TruthCopy( Lpk_FunTruth(p,0), pTruth, p->nVars );
00091 Vec_PtrForEachEntry( vLeaves, pNode, i )
00092 {
00093 p->pFanins[i] = i;
00094 p->pDelays[i] = pNode->Level;
00095 }
00096 Vec_PtrPush( p->vNodes, p );
00097 return p;
00098 }
00099
00111 Lpk_Fun_t * Lpk_FunDup( Lpk_Fun_t * p, unsigned * pTruth )
00112 {
00113 Lpk_Fun_t * pNew;
00114 pNew = Lpk_FunAlloc( p->nVars );
00115 pNew->Id = Vec_PtrSize(p->vNodes);
00116 pNew->vNodes = p->vNodes;
00117 pNew->nVars = p->nVars;
00118 pNew->nLutK = p->nLutK;
00119 pNew->nAreaLim = p->nAreaLim;
00120 pNew->nDelayLim = p->nDelayLim;
00121 pNew->uSupp = Kit_TruthSupport( pTruth, p->nVars );
00122 Kit_TruthCopy( Lpk_FunTruth(pNew,0), pTruth, p->nVars );
00123 memcpy( pNew->pFanins, p->pFanins, 16 );
00124 memcpy( pNew->pDelays, p->pDelays, 16 );
00125 Vec_PtrPush( p->vNodes, pNew );
00126 return pNew;
00127 }
00128
00140 int Lpk_FunSuppMinimize( Lpk_Fun_t * p )
00141 {
00142 int i, k, nVarsNew;
00143
00144 if ( p->uSupp == Kit_BitMask(p->nVars) )
00145 return 0;
00146
00147 p->fSupports = 0;
00148
00149
00150 nVarsNew = Kit_WordCountOnes(p->uSupp);
00151 Kit_TruthShrink( Lpk_FunTruth(p, 1), Lpk_FunTruth(p, 0), nVarsNew, p->nVars, p->uSupp, 1 );
00152 k = 0;
00153 Lpk_SuppForEachVar( p->uSupp, i )
00154 {
00155 p->pFanins[k] = p->pFanins[i];
00156 p->pDelays[k] = p->pDelays[i];
00157
00158
00159
00160
00161
00162
00163
00164 k++;
00165 }
00166 assert( k == nVarsNew );
00167 p->nVars = k;
00168 p->uSupp = Kit_BitMask(p->nVars);
00169 return 1;
00170 }
00171
00183 void Lpk_FunComputeCofSupps( Lpk_Fun_t * p )
00184 {
00185 unsigned * pTruth = Lpk_FunTruth( p, 0 );
00186 unsigned * pTruth0 = Lpk_FunTruth( p, 1 );
00187 unsigned * pTruth1 = Lpk_FunTruth( p, 2 );
00188 int Var;
00189 assert( p->fSupports == 0 );
00190
00191 for ( Var = 0; Var < (int)p->nVars; Var++ )
00192 {
00193 Kit_TruthCofactor0New( pTruth0, pTruth, p->nVars, Var );
00194 Kit_TruthCofactor1New( pTruth1, pTruth, p->nVars, Var );
00195 p->puSupps[2*Var+0] = Kit_TruthSupport( pTruth0, p->nVars );
00196 p->puSupps[2*Var+1] = Kit_TruthSupport( pTruth1, p->nVars );
00197 }
00198 p->fSupports = 1;
00199 }
00200
00212 int Lpk_SuppDelay( unsigned uSupp, char * pDelays )
00213 {
00214 int Delay, Var;
00215 Delay = 0;
00216 Lpk_SuppForEachVar( uSupp, Var )
00217 Delay = ABC_MAX( Delay, pDelays[Var] );
00218 return Delay + 1;
00219 }
00220
00232 int Lpk_SuppToVars( unsigned uBoundSet, char * pVars )
00233 {
00234 int i, nVars = 0;
00235 Lpk_SuppForEachVar( uBoundSet, i )
00236 pVars[nVars++] = i;
00237 return nVars;
00238 }
00239
00243
00244