00001
00029 #include "util_hack.h"
00030 #include "cuddInt.h"
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef lint
00053 static char rcsid[] DD_UNUSED = "$Id: cuddAddNeg.c,v 1.1.1.1 2003/02/24 22:23:50 wjiang Exp $";
00054 #endif
00055
00056
00057
00058
00059
00060
00061
00064
00065
00066
00067
00068
00072
00073
00074
00075
00088 DdNode *
00089 Cudd_addNegate(
00090 DdManager * dd,
00091 DdNode * f)
00092 {
00093 DdNode *res;
00094
00095 do {
00096 res = cuddAddNegateRecur(dd,f);
00097 } while (dd->reordered == 1);
00098 return(res);
00099
00100 }
00101
00102
00116 DdNode *
00117 Cudd_addRoundOff(
00118 DdManager * dd,
00119 DdNode * f,
00120 int N)
00121 {
00122 DdNode *res;
00123 double trunc = pow(10.0,(double)N);
00124
00125 do {
00126 res = cuddAddRoundOffRecur(dd,f,trunc);
00127 } while (dd->reordered == 1);
00128 return(res);
00129
00130 }
00131
00132
00133
00134
00135
00136
00137
00148 DdNode *
00149 cuddAddNegateRecur(
00150 DdManager * dd,
00151 DdNode * f)
00152 {
00153 DdNode *res,
00154 *fv, *fvn,
00155 *T, *E;
00156
00157 statLine(dd);
00158
00159 if (cuddIsConstant(f)) {
00160 res = cuddUniqueConst(dd,-cuddV(f));
00161 return(res);
00162 }
00163
00164
00165 res = cuddCacheLookup1(dd,Cudd_addNegate,f);
00166 if (res != NULL) return(res);
00167
00168
00169 fv = cuddT(f);
00170 fvn = cuddE(f);
00171 T = cuddAddNegateRecur(dd,fv);
00172 if (T == NULL) return(NULL);
00173 cuddRef(T);
00174
00175 E = cuddAddNegateRecur(dd,fvn);
00176 if (E == NULL) {
00177 Cudd_RecursiveDeref(dd,T);
00178 return(NULL);
00179 }
00180 cuddRef(E);
00181 res = (T == E) ? T : cuddUniqueInter(dd,(int)f->index,T,E);
00182 if (res == NULL) {
00183 Cudd_RecursiveDeref(dd, T);
00184 Cudd_RecursiveDeref(dd, E);
00185 return(NULL);
00186 }
00187 cuddDeref(T);
00188 cuddDeref(E);
00189
00190
00191 cuddCacheInsert1(dd,Cudd_addNegate,f,res);
00192
00193 return(res);
00194
00195 }
00196
00197
00208 DdNode *
00209 cuddAddRoundOffRecur(
00210 DdManager * dd,
00211 DdNode * f,
00212 double trunc)
00213 {
00214
00215 DdNode *res, *fv, *fvn, *T, *E;
00216 double n;
00217 DdNode *(*cacheOp)(DdManager *, DdNode *);
00218
00219 statLine(dd);
00220 if (cuddIsConstant(f)) {
00221 n = ceil(cuddV(f)*trunc)/trunc;
00222 res = cuddUniqueConst(dd,n);
00223 return(res);
00224 }
00225 cacheOp = (DdNode *(*)(DdManager *, DdNode *)) Cudd_addRoundOff;
00226 res = cuddCacheLookup1(dd,cacheOp,f);
00227 if (res != NULL) {
00228 return(res);
00229 }
00230
00231 fv = cuddT(f);
00232 fvn = cuddE(f);
00233 T = cuddAddRoundOffRecur(dd,fv,trunc);
00234 if (T == NULL) {
00235 return(NULL);
00236 }
00237 cuddRef(T);
00238 E = cuddAddRoundOffRecur(dd,fvn,trunc);
00239 if (E == NULL) {
00240 Cudd_RecursiveDeref(dd,T);
00241 return(NULL);
00242 }
00243 cuddRef(E);
00244 res = (T == E) ? T : cuddUniqueInter(dd,(int)f->index,T,E);
00245 if (res == NULL) {
00246 Cudd_RecursiveDeref(dd,T);
00247 Cudd_RecursiveDeref(dd,E);
00248 return(NULL);
00249 }
00250 cuddDeref(T);
00251 cuddDeref(E);
00252
00253
00254 cuddCacheInsert1(dd,cacheOp,f,res);
00255 return(res);
00256
00257 }
00258
00259
00260
00261
00262