00001
00021 #include "bdcInt.h"
00022
00026
00030
00042 Bdc_Man_t * Bdc_ManAlloc( Bdc_Par_t * pPars )
00043 {
00044 Bdc_Man_t * p;
00045 unsigned * pData;
00046 int i, k, nBits;
00047 p = ALLOC( Bdc_Man_t, 1 );
00048 memset( p, 0, sizeof(Bdc_Man_t) );
00049 assert( pPars->nVarsMax > 3 && pPars->nVarsMax < 16 );
00050 p->pPars = pPars;
00051 p->nWords = Kit_TruthWordNum( pPars->nVarsMax );
00052 p->nDivsLimit = 200;
00053 p->nNodesLimit = 0;
00054
00055 p->vMemory = Vec_IntStart( 1 << 16 );
00056
00057 p->nNodesAlloc = 512;
00058 p->pNodes = ALLOC( Bdc_Fun_t, p->nNodesAlloc );
00059
00060 p->nTableSize = (1 << p->pPars->nVarsMax);
00061 p->pTable = ALLOC( Bdc_Fun_t *, p->nTableSize );
00062 memset( p->pTable, 0, sizeof(Bdc_Fun_t *) * p->nTableSize );
00063 p->vSpots = Vec_IntAlloc( 256 );
00064
00065 p->vTruths = Vec_PtrAllocSimInfo( pPars->nVarsMax + 5, p->nWords );
00066
00067 nBits = (1 << pPars->nVarsMax);
00068 Kit_TruthFill( Vec_PtrEntry(p->vTruths, 0), p->nVars );
00069 for ( k = 0; k < pPars->nVarsMax; k++ )
00070 {
00071 pData = Vec_PtrEntry( p->vTruths, k+1 );
00072 Kit_TruthClear( pData, p->nVars );
00073 for ( i = 0; i < nBits; i++ )
00074 if ( i & (1 << k) )
00075 pData[i>>5] |= (1 << (i&31));
00076 }
00077 p->puTemp1 = Vec_PtrEntry( p->vTruths, pPars->nVarsMax + 1 );
00078 p->puTemp2 = Vec_PtrEntry( p->vTruths, pPars->nVarsMax + 2 );
00079 p->puTemp3 = Vec_PtrEntry( p->vTruths, pPars->nVarsMax + 3 );
00080 p->puTemp4 = Vec_PtrEntry( p->vTruths, pPars->nVarsMax + 4 );
00081
00082 p->pIsfOL = &p->IsfOL; Bdc_IsfStart( p, p->pIsfOL );
00083 p->pIsfOR = &p->IsfOR; Bdc_IsfStart( p, p->pIsfOR );
00084 p->pIsfAL = &p->IsfAL; Bdc_IsfStart( p, p->pIsfAL );
00085 p->pIsfAR = &p->IsfAR; Bdc_IsfStart( p, p->pIsfAR );
00086 return p;
00087 }
00088
00100 void Bdc_ManFree( Bdc_Man_t * p )
00101 {
00102 Vec_IntFree( p->vMemory );
00103 Vec_IntFree( p->vSpots );
00104 Vec_PtrFree( p->vTruths );
00105 free( p->pNodes );
00106 free( p->pTable );
00107 free( p );
00108 }
00109
00121 void Bdc_ManPrepare( Bdc_Man_t * p, Vec_Ptr_t * vDivs )
00122 {
00123 unsigned * puTruth;
00124 Bdc_Fun_t * pNode;
00125 int i;
00126 Bdc_TableClear( p );
00127 Vec_IntClear( p->vMemory );
00128
00129 p->nNodes = p->nNodesNew = 0;
00130 for ( i = 0; i <= p->pPars->nVarsMax; i++ )
00131 {
00132 pNode = Bdc_FunNew( p );
00133 pNode->Type = BDC_TYPE_PI;
00134 pNode->puFunc = Vec_PtrEntry( p->vTruths, i );
00135 pNode->uSupp = i? (1 << (i-1)) : 0;
00136 Bdc_TableAdd( p, pNode );
00137 }
00138
00139 Vec_PtrForEachEntry( vDivs, puTruth, i )
00140 {
00141 pNode = Bdc_FunNew( p );
00142 pNode->Type = BDC_TYPE_PI;
00143 pNode->puFunc = puTruth;
00144 pNode->uSupp = Kit_TruthSupport( puTruth, p->nVars );
00145 Bdc_TableAdd( p, pNode );
00146 if ( i == p->nDivsLimit )
00147 break;
00148 }
00149 }
00150
00162 int Bdc_ManDecompose( Bdc_Man_t * p, unsigned * puFunc, unsigned * puCare, int nVars, Vec_Ptr_t * vDivs, int nNodesMax )
00163 {
00164 Bdc_Isf_t Isf, * pIsf = &Isf;
00165
00166 p->nVars = nVars;
00167 p->nWords = Kit_TruthWordNum( nVars );
00168 Bdc_ManPrepare( p, vDivs );
00169 p->nNodesLimit = (p->nNodes + nNodesMax < p->nNodesAlloc)? p->nNodes + nNodesMax : p->nNodesAlloc;
00170
00171 Bdc_IsfStart( p, pIsf );
00172 Bdc_IsfClean( pIsf );
00173 pIsf->uSupp = Kit_TruthSupport( puFunc, p->nVars ) | Kit_TruthSupport( puCare, p->nVars );
00174 Kit_TruthAnd( pIsf->puOn, puCare, puFunc, p->nVars );
00175 Kit_TruthSharp( pIsf->puOff, puCare, puFunc, p->nVars );
00176
00177 Bdc_SuppMinimize( p, pIsf );
00178 p->pRoot = Bdc_ManDecompose_rec( p, pIsf );
00179 if ( p->pRoot == NULL )
00180 return -1;
00181 return p->nNodesNew;
00182 }
00183
00184
00188
00189