00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "espresso.h"
00015
00016 long start_time;
00017
00018
00019
00020 pcover cv_sharp(A, B)
00021 pcover A, B;
00022 {
00023 pcube last, p;
00024 pcover T;
00025
00026 T = new_cover(0);
00027 foreach_set(A, last, p)
00028 T = sf_union(T, cb_sharp(p, B));
00029 return T;
00030 }
00031
00032
00033
00034 pcover cb_sharp(c, T)
00035 pcube c;
00036 pcover T;
00037 {
00038 if (T->count == 0) {
00039 T = sf_addset(new_cover(1), c);
00040 } else {
00041 start_time = ptime();
00042 T = cb_recur_sharp(c, T, 0, T->count-1, 0);
00043 }
00044 return T;
00045 }
00046
00047
00048
00049 pcover cb_recur_sharp(c, T, first, last, level)
00050 pcube c;
00051 pcover T;
00052 int first, last, level;
00053 {
00054 pcover temp, left, right;
00055 int middle;
00056
00057 if (first == last) {
00058 temp = sharp(c, GETSET(T, first));
00059 } else {
00060 middle = (first + last) / 2;
00061 left = cb_recur_sharp(c, T, first, middle, level+1);
00062 right = cb_recur_sharp(c, T, middle+1, last, level+1);
00063 temp = cv_intersect(left, right);
00064 if ((debug & SHARP) && level < 4) {
00065 printf("# SHARP[%d]: %4d = %4d x %4d, time = %s\n",
00066 level, temp->count, left->count, right->count,
00067 print_time(ptime() - start_time));
00068 (void) fflush(stdout);
00069 }
00070 free_cover(left);
00071 free_cover(right);
00072 }
00073 return temp;
00074 }
00075
00076
00077
00078 pcover sharp(a, b)
00079 pcube a, b;
00080 {
00081 register int var;
00082 register pcube d=cube.temp[0], temp=cube.temp[1], temp1=cube.temp[2];
00083 pcover r = new_cover(cube.num_vars);
00084
00085 if (cdist0(a, b)) {
00086 set_diff(d, a, b);
00087 for(var = 0; var < cube.num_vars; var++) {
00088 if (! setp_empty(set_and(temp, d, cube.var_mask[var]))) {
00089 set_diff(temp1, a, cube.var_mask[var]);
00090 set_or(GETSET(r, r->count++), temp, temp1);
00091 }
00092 }
00093 } else {
00094 r = sf_addset(r, a);
00095 }
00096 return r;
00097 }
00098
00099 pcover make_disjoint(A)
00100 pcover A;
00101 {
00102 pcover R, new;
00103 register pset last, p;
00104
00105 R = new_cover(0);
00106 foreach_set(A, last, p) {
00107 new = cb_dsharp(p, R);
00108 R = sf_append(R, new);
00109 }
00110 return R;
00111 }
00112
00113
00114
00115 pcover cv_dsharp(A, B)
00116 pcover A, B;
00117 {
00118 register pcube last, p;
00119 pcover T;
00120
00121 T = new_cover(0);
00122 foreach_set(A, last, p) {
00123 T = sf_union(T, cb_dsharp(p, B));
00124 }
00125 return T;
00126 }
00127
00128
00129
00130 pcover cb1_dsharp(T, c)
00131 pcover T;
00132 pcube c;
00133 {
00134 pcube last, p;
00135 pcover R;
00136
00137 R = new_cover(T->count);
00138 foreach_set(T, last, p) {
00139 R = sf_union(R, dsharp(p, c));
00140 }
00141 return R;
00142 }
00143
00144
00145
00146 pcover cb_dsharp(c, T)
00147 pcube c;
00148 pcover T;
00149 {
00150 pcube last, p;
00151 pcover Y, Y1;
00152
00153 if (T->count == 0) {
00154 Y = sf_addset(new_cover(1), c);
00155 } else {
00156 Y = new_cover(T->count);
00157 set_copy(GETSET(Y,Y->count++), c);
00158 foreach_set(T, last, p) {
00159 Y1 = cb1_dsharp(Y, p);
00160 free_cover(Y);
00161 Y = Y1;
00162 }
00163 }
00164 return Y;
00165 }
00166
00167
00168
00169 pcover dsharp(a, b)
00170 pcube a, b;
00171 {
00172 register pcube mask, diff, and, temp, temp1 = cube.temp[0];
00173 int var;
00174 pcover r;
00175
00176 r = new_cover(cube.num_vars);
00177
00178 if (cdist0(a, b)) {
00179 diff = set_diff(new_cube(), a, b);
00180 and = set_and(new_cube(), a, b);
00181 mask = new_cube();
00182 for(var = 0; var < cube.num_vars; var++) {
00183
00184 if (! setp_disjoint(diff, cube.var_mask[var])) {
00185
00186
00187 temp = GETSET(r, r->count++);
00188 (void) set_and(temp, diff, cube.var_mask[var]);
00189
00190
00191 INLINEset_and(temp1, and, mask);
00192 INLINEset_or(temp, temp, temp1);
00193
00194
00195 set_or(mask, mask, cube.var_mask[var]);
00196 INLINEset_diff(temp1, a, mask);
00197 INLINEset_or(temp, temp, temp1);
00198 }
00199 }
00200 free_cube(diff);
00201 free_cube(and);
00202 free_cube(mask);
00203 } else {
00204 r = sf_addset(r, a);
00205 }
00206 return r;
00207 }
00208
00209
00210
00211 #define MAGIC 500
00212
00213 pcover cv_intersect(A, B)
00214 pcover A, B;
00215 {
00216 register pcube pi, pj, lasti, lastj, pt;
00217 pcover T, Tsave = NULL;
00218
00219
00220 T = new_cover(MAGIC);
00221 pt = T->data;
00222
00223
00224 foreach_set(A, lasti, pi) {
00225 foreach_set(B, lastj, pj) {
00226 if (cdist0(pi, pj)) {
00227 (void) set_and(pt, pi, pj);
00228 if (++T->count >= T->capacity) {
00229 if (Tsave == NULL)
00230 Tsave = sf_contain(T);
00231 else
00232 Tsave = sf_union(Tsave, sf_contain(T));
00233 T = new_cover(MAGIC);
00234 pt = T->data;
00235 } else
00236 pt += T->wsize;
00237 }
00238 }
00239 }
00240
00241
00242 if (Tsave == NULL)
00243 Tsave = sf_contain(T);
00244 else
00245 Tsave = sf_union(Tsave, sf_contain(T));
00246 return Tsave;
00247 }