[13] | 1 | /* Written by Gitanjali M. Swamy */ |
---|
| 2 | /* bddcproject.c,v 1.2 1994/06/02 02:36:30 shiple Exp */ |
---|
| 3 | /* bddcproject.c,v |
---|
| 4 | * Revision 1.2 1994/06/02 02:36:30 shiple |
---|
| 5 | * Fixed bug in RETURN_BDD use. |
---|
| 6 | * |
---|
| 7 | * Revision 1.1 1994/06/02 00:48:50 shiple |
---|
| 8 | * Initial revision |
---|
| 9 | * |
---|
| 10 | * Revision 1.5 1994/05/31 15:19:32 gms |
---|
| 11 | * May31 Tues |
---|
| 12 | * */ |
---|
| 13 | |
---|
| 14 | #ifndef lint |
---|
| 15 | static char vcid[] = "bddcproject.c,v 1.2 1994/06/02 02:36:30 shiple Exp"; |
---|
| 16 | #endif /* lint */ |
---|
| 17 | |
---|
| 18 | #include "bddint.h" /* CMU internal routines; for use in bdd_get_node() */ |
---|
| 19 | |
---|
| 20 | #define OP_CPROJ 5000001 |
---|
| 21 | |
---|
| 22 | extern bdd cmu_bdd_project(cmu_bdd_manager, bdd); |
---|
| 23 | |
---|
| 24 | /* INTERNAL ONLY */ |
---|
| 25 | |
---|
| 26 | /* |
---|
| 27 | * smooth - recursively perform the smoothing |
---|
| 28 | * |
---|
| 29 | * return the result of the reorganization |
---|
| 30 | */ |
---|
| 31 | |
---|
| 32 | static |
---|
| 33 | bdd |
---|
| 34 | cmu_bdd_smooth_g_step(cmu_bdd_manager bddm, bdd f, long op, var_assoc vars ,long id) |
---|
| 35 | { |
---|
| 36 | bdd temp1, temp2; |
---|
| 37 | bdd result; |
---|
| 38 | int quantifying; |
---|
| 39 | |
---|
| 40 | BDD_SETUP(f); |
---|
| 41 | if ((long)BDD_INDEX(bddm, f) > vars->last) |
---|
| 42 | { |
---|
| 43 | BDD_TEMP_INCREFS(f); |
---|
| 44 | return (f); |
---|
| 45 | } |
---|
| 46 | if (bdd_lookup_in_cache1(bddm, op, f, &result)) |
---|
| 47 | return (result); |
---|
| 48 | quantifying=(vars->assoc[BDD_INDEXINDEX(f)] != 0); |
---|
| 49 | |
---|
| 50 | temp1=cmu_bdd_smooth_g_step(bddm, BDD_THEN(f), op, vars,id); |
---|
| 51 | |
---|
| 52 | if ((quantifying && temp1 == BDD_ONE(bddm))&&((long)BDD_INDEX(bddm, f) > id )) |
---|
| 53 | |
---|
| 54 | result=temp1; |
---|
| 55 | else |
---|
| 56 | { |
---|
| 57 | temp2=cmu_bdd_smooth_g_step(bddm, BDD_ELSE(f), op, vars,id); |
---|
| 58 | if (quantifying) |
---|
| 59 | { |
---|
| 60 | BDD_SETUP(temp1); |
---|
| 61 | BDD_SETUP(temp2); |
---|
| 62 | bddm->op_cache.cache_level++; |
---|
| 63 | result=cmu_bdd_ite_step(bddm, temp1, BDD_ONE(bddm), temp2); |
---|
| 64 | BDD_TEMP_DECREFS(temp1); |
---|
| 65 | BDD_TEMP_DECREFS(temp2); |
---|
| 66 | bddm->op_cache.cache_level--; |
---|
| 67 | } |
---|
| 68 | else |
---|
| 69 | result=bdd_find(bddm, BDD_INDEXINDEX(f), temp1, temp2); |
---|
| 70 | } |
---|
| 71 | bdd_insert_in_cache1(bddm, op, f, result); |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | return (result); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | static |
---|
| 79 | bdd |
---|
| 80 | cmu_bdd_smooth_g(cmu_bdd_manager bddm, bdd f, long id) |
---|
| 81 | { |
---|
| 82 | long op; |
---|
| 83 | |
---|
| 84 | if (bddm->curr_assoc_id == -1) |
---|
| 85 | op=bddm->temp_op--; |
---|
| 86 | else |
---|
| 87 | op=OP_QNT+bddm->curr_assoc_id; |
---|
| 88 | RETURN_BDD(cmu_bdd_smooth_g_step(bddm, f, op, bddm->curr_assoc,id)); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | /* |
---|
| 93 | * project - recursively perform compatible projection |
---|
| 94 | * |
---|
| 95 | * return the result of the reorganization |
---|
| 96 | */ |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | static |
---|
| 101 | bdd |
---|
| 102 | cmu_bdd_project_step(cmu_bdd_manager bddm, bdd f, long op, var_assoc vars) |
---|
| 103 | |
---|
| 104 | { |
---|
| 105 | bdd temp1, temp2; |
---|
| 106 | bdd sm, pr; |
---|
| 107 | bdd result; |
---|
| 108 | int quantifying; |
---|
| 109 | |
---|
| 110 | BDD_SETUP(f); |
---|
| 111 | if ((long)BDD_INDEX(bddm, f) > vars->last) |
---|
| 112 | { |
---|
| 113 | BDD_TEMP_INCREFS(f); |
---|
| 114 | return (f); |
---|
| 115 | } |
---|
| 116 | if (bdd_lookup_in_cache1(bddm, op, f, &result)) |
---|
| 117 | return (result); |
---|
| 118 | quantifying=(vars->assoc[BDD_INDEXINDEX(f)] != 0); |
---|
| 119 | |
---|
| 120 | if (quantifying) |
---|
| 121 | { |
---|
| 122 | |
---|
| 123 | sm = cmu_bdd_smooth_g(bddm,BDD_THEN(f),(long)BDD_INDEXINDEX(f)); |
---|
| 124 | if (sm == BDD_ONE(bddm)) |
---|
| 125 | { |
---|
| 126 | pr = cmu_bdd_project_step(bddm, BDD_THEN(f), op, vars); |
---|
| 127 | { |
---|
| 128 | BDD_SETUP(pr); |
---|
| 129 | result = bdd_find(bddm, BDD_INDEXINDEX(f), pr,BDD_ZERO(bddm)); |
---|
| 130 | BDD_TEMP_DECREFS(pr); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | } |
---|
| 134 | else if (sm == BDD_ZERO(bddm)) |
---|
| 135 | { |
---|
| 136 | pr = cmu_bdd_project_step(bddm, BDD_ELSE(f), op, vars); |
---|
| 137 | { |
---|
| 138 | BDD_SETUP(pr); |
---|
| 139 | result = bdd_find(bddm, BDD_INDEXINDEX(f), BDD_ZERO(bddm), pr); |
---|
| 140 | BDD_TEMP_DECREFS(pr); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | } |
---|
| 144 | else |
---|
| 145 | { |
---|
| 146 | temp1 = cmu_bdd_project_step(bddm, BDD_THEN(f), op, vars); |
---|
| 147 | temp2 = cmu_bdd_project_step(bddm, BDD_ELSE(f),op, vars); |
---|
| 148 | { |
---|
| 149 | BDD_SETUP(temp1); |
---|
| 150 | BDD_SETUP(temp2); |
---|
| 151 | pr = cmu_bdd_ite_step(bddm, sm, BDD_ZERO(bddm), temp2); |
---|
| 152 | bddm->op_cache.cache_level++; |
---|
| 153 | result = bdd_find(bddm, BDD_INDEXINDEX(f), temp1, pr); |
---|
| 154 | BDD_TEMP_DECREFS(temp1); |
---|
| 155 | BDD_TEMP_DECREFS(temp2); |
---|
| 156 | bddm->op_cache.cache_level--; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | else |
---|
| 163 | { |
---|
| 164 | temp1=cmu_bdd_project_step(bddm, BDD_THEN(f), op, vars); |
---|
| 165 | temp2=cmu_bdd_project_step(bddm, BDD_ELSE(f), op, vars); |
---|
| 166 | result=bdd_find(bddm, BDD_INDEXINDEX(f), temp1, temp2); |
---|
| 167 | |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | bdd_insert_in_cache1(bddm, op, f, result); |
---|
| 171 | return (result); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | bdd |
---|
| 175 | cmu_bdd_project(cmu_bdd_manager bddm, bdd f) |
---|
| 176 | { |
---|
| 177 | long op; |
---|
| 178 | |
---|
| 179 | if (bdd_check_arguments(1, f)) |
---|
| 180 | { |
---|
| 181 | FIREWALL(bddm); |
---|
| 182 | if (bddm->curr_assoc_id == -1) |
---|
| 183 | op=bddm->temp_op--; |
---|
| 184 | else |
---|
| 185 | op=OP_CPROJ+bddm->curr_assoc_id; |
---|
| 186 | RETURN_BDD(cmu_bdd_project_step(bddm, f, op, bddm->curr_assoc)); |
---|
| 187 | } |
---|
| 188 | return ((bdd)0); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | |
---|