00001
00019 #include "dsdInt.h"
00020
00024
00025 typedef struct Dsd_Cache_t_ Dds_Cache_t;
00026 typedef struct Dsd_Entry_t_ Dsd_Entry_t;
00027
00028 struct Dsd_Cache_t_
00029 {
00030 Dsd_Entry_t * pTable;
00031 int nTableSize;
00032 int nSuccess;
00033 int nFailure;
00034 };
00035
00036 struct Dsd_Entry_t_
00037 {
00038 DdNode * bX[5];
00039 };
00040
00041 static Dds_Cache_t * pCache;
00042
00043 static int Dsd_CheckRootFunctionIdentity_rec( DdManager * dd, DdNode * bF1, DdNode * bF2, DdNode * bC1, DdNode * bC2 );
00044
00048
00060 void Dsd_CheckCacheAllocate( int nEntries )
00061 {
00062 int nRequested;
00063
00064 pCache = ALLOC( Dds_Cache_t, 1 );
00065 memset( pCache, 0, sizeof(Dds_Cache_t) );
00066
00067
00068 nRequested = Cudd_Prime( nEntries );
00069 if ( pCache->nTableSize != nRequested )
00070 {
00071
00072 if ( pCache->nTableSize )
00073 Dsd_CheckCacheDeallocate();
00074
00075 pCache->nTableSize = nRequested;
00076 pCache->pTable = ALLOC( Dsd_Entry_t, nRequested );
00077 }
00078
00079 Dsd_CheckCacheClear();
00080
00081 }
00082
00094 void Dsd_CheckCacheDeallocate()
00095 {
00096 free( pCache->pTable );
00097 free( pCache );
00098 }
00099
00111 void Dsd_CheckCacheClear()
00112 {
00113 int i;
00114 for ( i = 0; i < pCache->nTableSize; i++ )
00115 pCache->pTable[0].bX[0] = NULL;
00116 }
00117
00118
00130 int Dsd_CheckRootFunctionIdentity( DdManager * dd, DdNode * bF1, DdNode * bF2, DdNode * bC1, DdNode * bC2 )
00131 {
00132 int RetValue;
00133
00134
00135 RetValue = Dsd_CheckRootFunctionIdentity_rec(dd, bF1, bF2, bC1, bC2);
00136
00137 return RetValue;
00138 }
00139
00151 int Dsd_CheckRootFunctionIdentity_rec( DdManager * dd, DdNode * bF1, DdNode * bF2, DdNode * bC1, DdNode * bC2 )
00152 {
00153 unsigned HKey;
00154
00155
00156
00157 assert( bC1 != b0 );
00158 assert( bC2 != b0 );
00159
00160
00161 if ( bC1 == b1 && bC2 == b1 ) return (int)( bF1 == bF2 );
00162
00163 if ( bF1 == b0 )
00164 return Cudd_bddLeq( dd, bC2, Cudd_Not(bF2) );
00165
00166 if ( bF1 == b1 )
00167 return Cudd_bddLeq( dd, bC2, bF2 );
00168
00169 if ( bF2 == b0 )
00170 return Cudd_bddLeq( dd, bC1, Cudd_Not(bF1) );
00171
00172 if ( bF2 == b1 )
00173 return Cudd_bddLeq( dd, bC1, bF1 );
00174
00175
00176
00177
00178
00179 HKey = hashKey4( bF1, bF2, bC1, bC2, pCache->nTableSize );
00180 if ( pCache->pTable[HKey].bX[0] == bF1 &&
00181 pCache->pTable[HKey].bX[1] == bF2 &&
00182 pCache->pTable[HKey].bX[2] == bC1 &&
00183 pCache->pTable[HKey].bX[3] == bC2 )
00184 {
00185 pCache->nSuccess++;
00186 return (int)pCache->pTable[HKey].bX[4];
00187 }
00188 else
00189 {
00190
00191
00192 int RetValue;
00193 DdNode * bA[4] = { bF1, bF2, bC1, bC2 };
00194 DdNode * bAR[4] = { Cudd_Regular(bF1), Cudd_Regular(bF2), Cudd_Regular(bC1), Cudd_Regular(bC2) };
00195 int CurLevel[4] = { cuddI(dd,bAR[0]->index), cuddI(dd,bAR[1]->index), cuddI(dd,bAR[2]->index), cuddI(dd,bAR[3]->index) };
00196 int TopLevel = CUDD_CONST_INDEX;
00197 int i;
00198 DdNode * bE[4], * bT[4];
00199 DdNode * bF1next, * bF2next, * bC1next, * bC2next;
00200
00201 pCache->nFailure++;
00202
00203
00204 for ( i = 0; i < 4; i++ )
00205 if ( TopLevel > CurLevel[i] )
00206 TopLevel = CurLevel[i];
00207
00208
00209 for ( i = 0; i < 4; i++ )
00210 if ( TopLevel == CurLevel[i] )
00211 {
00212 if ( bA[i] != bAR[i] )
00213 {
00214 bE[i] = Cudd_Not(cuddE(bAR[i]));
00215 bT[i] = Cudd_Not(cuddT(bAR[i]));
00216 }
00217 else
00218 {
00219 bE[i] = cuddE(bAR[i]);
00220 bT[i] = cuddT(bAR[i]);
00221 }
00222 }
00223 else
00224 bE[i] = bT[i] = bA[i];
00225
00226
00227
00228
00229
00230
00231
00232 if ( TopLevel == CurLevel[2] && TopLevel == CurLevel[3] )
00233 {
00234 if ( bE[2] != b0 )
00235 {
00236 bF1next = bE[0];
00237 bC1next = bE[2];
00238 }
00239 else
00240 {
00241 bF1next = bT[0];
00242 bC1next = bT[2];
00243 }
00244 if ( bE[3] != b0 )
00245 {
00246 bF2next = bE[1];
00247 bC2next = bE[3];
00248 }
00249 else
00250 {
00251 bF2next = bT[1];
00252 bC2next = bT[3];
00253 }
00254 RetValue = Dsd_CheckRootFunctionIdentity_rec( dd, bF1next, bF2next, bC1next, bC2next );
00255 }
00256
00257
00258 else if ( TopLevel == CurLevel[2] && TopLevel != CurLevel[3] )
00259 {
00260 if ( bE[2] != b0 )
00261 {
00262 bF1next = bE[0];
00263 bC1next = bE[2];
00264 }
00265 else
00266 {
00267 bF1next = bT[0];
00268 bC1next = bT[2];
00269 }
00270
00271 RetValue = Dsd_CheckRootFunctionIdentity_rec( dd, bF1next, bE[1], bC1next, bE[3] );
00272 if ( RetValue == 1 )
00273 RetValue = Dsd_CheckRootFunctionIdentity_rec( dd, bF1next, bT[1], bC1next, bT[3] );
00274 }
00275 else if ( TopLevel != CurLevel[2] && TopLevel == CurLevel[3] )
00276 {
00277 if ( bE[3] != b0 )
00278 {
00279 bF2next = bE[1];
00280 bC2next = bE[3];
00281 }
00282 else
00283 {
00284 bF2next = bT[1];
00285 bC2next = bT[3];
00286 }
00287
00288 RetValue = Dsd_CheckRootFunctionIdentity_rec( dd, bE[0], bF2next, bE[2], bC2next );
00289 if ( RetValue == 1 )
00290 RetValue = Dsd_CheckRootFunctionIdentity_rec( dd, bT[0], bF2next, bT[2], bC2next );
00291 }
00292
00293
00294 else
00295 {
00296
00297 RetValue = Dsd_CheckRootFunctionIdentity_rec( dd, bE[0], bE[1], bE[2], bE[3] );
00298 if ( RetValue == 1 )
00299 RetValue = Dsd_CheckRootFunctionIdentity_rec( dd, bT[0], bT[1], bT[2], bT[3] );
00300 }
00301
00302
00303 for ( i = 0; i < 4; i++ )
00304 pCache->pTable[HKey].bX[i] = bA[i];
00305 pCache->pTable[HKey].bX[4] = (DdNode*)RetValue;
00306
00307 return RetValue;
00308 }
00309 }
00310
00314