00001
00028 #include "util_hack.h"
00029 #include "cuddInt.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifndef lint
00049 static char rcsid[] DD_UNUSED = "$Id: cuddLiteral.c,v 1.1.1.1 2003/02/24 22:23:52 wjiang Exp $";
00050 #endif
00051
00052
00053
00054
00055
00058
00059
00060
00061
00062
00066
00067
00068
00069
00070
00086 DdNode *
00087 Cudd_bddLiteralSetIntersection(
00088 DdManager * dd,
00089 DdNode * f,
00090 DdNode * g)
00091 {
00092 DdNode *res;
00093
00094 do {
00095 dd->reordered = 0;
00096 res = cuddBddLiteralSetIntersectionRecur(dd,f,g);
00097 } while (dd->reordered == 1);
00098 return(res);
00099
00100 }
00101
00102
00103
00104
00105
00106
00107
00121 DdNode *
00122 cuddBddLiteralSetIntersectionRecur(
00123 DdManager * dd,
00124 DdNode * f,
00125 DdNode * g)
00126 {
00127 DdNode *res, *tmp;
00128 DdNode *F, *G;
00129 DdNode *fc, *gc;
00130 DdNode *one;
00131 DdNode *zero;
00132 unsigned int topf, topg, comple;
00133 int phasef, phaseg;
00134
00135 statLine(dd);
00136 if (f == g) return(f);
00137
00138 F = Cudd_Regular(f);
00139 G = Cudd_Regular(g);
00140 one = DD_ONE(dd);
00141
00142
00143
00144
00145
00146 if (F == G) return(one);
00147
00148 zero = Cudd_Not(one);
00149 topf = cuddI(dd,F->index);
00150 topg = cuddI(dd,G->index);
00151
00152
00153
00154 while (topf != topg) {
00155 if (topf < topg) {
00156 comple = f != F;
00157 f = cuddT(F);
00158 if (comple) f = Cudd_Not(f);
00159 if (f == zero) {
00160 f = cuddE(F);
00161 if (comple) f = Cudd_Not(f);
00162 }
00163 F = Cudd_Regular(f);
00164 topf = cuddI(dd,F->index);
00165 } else if (topg < topf) {
00166 comple = g != G;
00167 g = cuddT(G);
00168 if (comple) g = Cudd_Not(g);
00169 if (g == zero) {
00170 g = cuddE(G);
00171 if (comple) g = Cudd_Not(g);
00172 }
00173 G = Cudd_Regular(g);
00174 topg = cuddI(dd,G->index);
00175 }
00176 }
00177
00178
00179 if (f == one) return(one);
00180
00181 res = cuddCacheLookup2(dd,Cudd_bddLiteralSetIntersection,f,g);
00182 if (res != NULL) {
00183 return(res);
00184 }
00185
00186
00187 comple = f != F;
00188 fc = cuddT(F);
00189 phasef = 1;
00190 if (comple) fc = Cudd_Not(fc);
00191 if (fc == zero) {
00192 fc = cuddE(F);
00193 phasef = 0;
00194 if (comple) fc = Cudd_Not(fc);
00195 }
00196 comple = g != G;
00197 gc = cuddT(G);
00198 phaseg = 1;
00199 if (comple) gc = Cudd_Not(gc);
00200 if (gc == zero) {
00201 gc = cuddE(G);
00202 phaseg = 0;
00203 if (comple) gc = Cudd_Not(gc);
00204 }
00205
00206 tmp = cuddBddLiteralSetIntersectionRecur(dd,fc,gc);
00207 if (tmp == NULL) {
00208 return(NULL);
00209 }
00210
00211 if (phasef != phaseg) {
00212 res = tmp;
00213 } else {
00214 cuddRef(tmp);
00215 if (phasef == 0) {
00216 res = cuddBddAndRecur(dd,Cudd_Not(dd->vars[F->index]),tmp);
00217 } else {
00218 res = cuddBddAndRecur(dd,dd->vars[F->index],tmp);
00219 }
00220 if (res == NULL) {
00221 Cudd_RecursiveDeref(dd,tmp);
00222 return(NULL);
00223 }
00224 cuddDeref(tmp);
00225 }
00226
00227 cuddCacheInsert2(dd,Cudd_bddLiteralSetIntersection,f,g,res);
00228
00229 return(res);
00230
00231 }
00232
00233
00234
00235
00236
00237