00001
00002
00003
00004 #include "bddint.h"
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 void
00017 mtbdd_transform_closure(cmu_bdd_manager bddm,
00018 int (*canonical_fn)(cmu_bdd_manager, INT_PTR, INT_PTR, pointer),
00019 void (*transform_fn)(cmu_bdd_manager, INT_PTR, INT_PTR, INT_PTR *, INT_PTR *, pointer),
00020 pointer transform_env)
00021 {
00022 bddm->transform_fn=transform_fn;
00023 bddm->transform_env=transform_env;
00024 bddm->canonical_fn=canonical_fn;
00025 }
00026
00027
00028
00029
00030
00031 void
00032 mtcmu_bdd_one_data(cmu_bdd_manager bddm, INT_PTR value1, INT_PTR value2)
00033 {
00034 var_table table;
00035 long hash;
00036
00037 table=bddm->unique_table.tables[BDD_CONST_INDEXINDEX];
00038 if (table->entries != 1)
00039 cmu_bdd_fatal("mtcmu_bdd_one_data: other terminal nodes already exist");
00040 hash=HASH_NODE(bddm->one->data[0], bddm->one->data[1]);
00041 BDD_REDUCE(hash, table->size);
00042 table->table[hash]=0;
00043 bddm->one->data[0]=value1;
00044 bddm->one->data[1]=value2;
00045 hash=HASH_NODE(bddm->one->data[0], bddm->one->data[1]);
00046 BDD_REDUCE(hash, table->size);
00047 table->table[hash]=bddm->one;
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057 void
00058 cmu_mtbdd_free_terminal_closure(cmu_bdd_manager bddm,
00059 void (*free_terminal_fn)(cmu_bdd_manager, INT_PTR, INT_PTR, pointer),
00060 pointer free_terminal_env)
00061 {
00062 bddm->unique_table.free_terminal_fn=free_terminal_fn;
00063 bddm->unique_table.free_terminal_env=free_terminal_env;
00064 }
00065
00066
00067
00068
00069
00070 bdd
00071 cmu_mtbdd_get_terminal(cmu_bdd_manager bddm, INT_PTR value1, INT_PTR value2)
00072 {
00073 FIREWALL(bddm);
00074 RETURN_BDD(bdd_find_terminal(bddm, value1, value2));
00075 }
00076
00077
00078
00079
00080
00081 void
00082 cmu_mtbdd_terminal_value(cmu_bdd_manager bddm, bdd f, INT_PTR *value1, INT_PTR *value2)
00083 {
00084 if (bdd_check_arguments(1, f))
00085 {
00086 BDD_SETUP(f);
00087 if (!BDD_IS_CONST(f))
00088 {
00089 cmu_bdd_warning("mtbdd_terminal_data: argument is terminal node");
00090 *value1=0;
00091 *value2=0;
00092 return;
00093 }
00094 cmu_mtbdd_terminal_value_aux(bddm, f, value1, value2);
00095 }
00096 }
00097
00098
00099 static
00100 bdd
00101 mtcmu_bdd_ite_step(cmu_bdd_manager bddm, bdd f, bdd g, bdd h)
00102 {
00103 bdd_indexindex_type top_indexindex;
00104 bdd f1, f2;
00105 bdd g1, g2;
00106 bdd h1, h2;
00107 bdd temp1, temp2;
00108 bdd result;
00109
00110 BDD_SETUP(f);
00111 BDD_SETUP(g);
00112 BDD_SETUP(h);
00113 if (BDD_IS_CONST(f))
00114 {
00115 if (f == BDD_ONE(bddm))
00116 {
00117 BDD_TEMP_INCREFS(g);
00118 return (g);
00119 }
00120 BDD_TEMP_INCREFS(h);
00121 return (h);
00122 }
00123
00124 if (g == h)
00125 {
00126 BDD_TEMP_INCREFS(g);
00127 return (g);
00128 }
00129
00130 if (!BDD_IS_OUTPOS(f))
00131 {
00132 f=BDD_NOT(f);
00133 BDD_SWAP(g, h);
00134 }
00135
00136 if (bdd_lookup_in_cache31(bddm, CACHE_TYPE_ITE, (INT_PTR)f, (INT_PTR)g, (INT_PTR)h, (INT_PTR *)&result))
00137 return (result);
00138 BDD_TOP_VAR3(top_indexindex, bddm, f, g, h);
00139 BDD_COFACTOR(top_indexindex, f, f1, f2);
00140 BDD_COFACTOR(top_indexindex, g, g1, g2);
00141 BDD_COFACTOR(top_indexindex, h, h1, h2);
00142 temp1=mtcmu_bdd_ite_step(bddm, f1, g1, h1);
00143 temp2=mtcmu_bdd_ite_step(bddm, f2, g2, h2);
00144 result=bdd_find(bddm, top_indexindex, temp1, temp2);
00145 bdd_insert_in_cache31(bddm, CACHE_TYPE_ITE, (INT_PTR)f, (INT_PTR)g, (INT_PTR)h, (INT_PTR)result);
00146 return (result);
00147 }
00148
00149
00150
00151
00152
00153 bdd
00154 mtcmu_bdd_ite(cmu_bdd_manager bddm, bdd f, bdd g, bdd h)
00155 {
00156 if (bdd_check_arguments(3, f, g, h))
00157 {
00158 FIREWALL(bddm);
00159 RETURN_BDD(mtcmu_bdd_ite_step(bddm, f, g, h));
00160 }
00161 return ((bdd)0);
00162 }
00163
00164
00165
00166
00167 bdd
00168 mtcmu_bdd_substitute(cmu_bdd_manager bddm, bdd f)
00169 {
00170 long op;
00171
00172 if (bdd_check_arguments(1, f))
00173 {
00174 FIREWALL(bddm);
00175 if (bddm->curr_assoc_id == -1)
00176 op=bddm->temp_op--;
00177 else
00178 op=OP_SUBST+bddm->curr_assoc_id;
00179 RETURN_BDD(cmu_bdd_substitute_step(bddm, f, op, mtcmu_bdd_ite_step, bddm->curr_assoc));
00180 }
00181 return ((bdd)0);
00182 }
00183
00184
00185 static
00186 bdd
00187 cmu_mtbdd_equal_step(cmu_bdd_manager bddm, bdd f, bdd g)
00188 {
00189 bdd_indexindex_type top_indexindex;
00190 bdd f1, f2;
00191 bdd g1, g2;
00192 bdd temp1, temp2;
00193 bdd result;
00194
00195 BDD_SETUP(f);
00196 BDD_SETUP(g);
00197 if (f == g)
00198 return (BDD_ONE(bddm));
00199 if (BDD_IS_CONST(f) && BDD_IS_CONST(g))
00200 return (BDD_ZERO(bddm));
00201 if (BDD_OUT_OF_ORDER(f, g))
00202 BDD_SWAP(f, g);
00203 if (bdd_lookup_in_cache2(bddm, OP_EQUAL, f, g, &result))
00204 return (result);
00205 BDD_TOP_VAR2(top_indexindex, bddm, f, g);
00206 BDD_COFACTOR(top_indexindex, f, f1, f2);
00207 BDD_COFACTOR(top_indexindex, g, g1, g2);
00208 temp1=cmu_mtbdd_equal_step(bddm, f1, g1);
00209 temp2=cmu_mtbdd_equal_step(bddm, f2, g2);
00210 result=bdd_find(bddm, top_indexindex, temp1, temp2);
00211 bdd_insert_in_cache2(bddm, OP_EQUAL, f, g, result);
00212 return (result);
00213 }
00214
00215
00216
00217
00218
00219 bdd
00220 cmu_mtbdd_equal(cmu_bdd_manager bddm, bdd f, bdd g)
00221 {
00222 if (bdd_check_arguments(2, f, g))
00223 {
00224 FIREWALL(bddm);
00225 RETURN_BDD(cmu_mtbdd_equal_step(bddm, f, g));
00226 }
00227 return ((bdd)0);
00228 }