109 static char rcsid[]
DD_UNUSED =
"$Id: cuddDecomp.c,v 1.44 2004/08/13 18:04:47 fabio Exp $";
120 #define FactorsNotStored(factors) ((int)((long)(factors) & 01))
122 #define FactorsComplement(factors) ((Conjuncts *)((long)(factors) | 01))
124 #define FactorsUncomplement(factors) ((Conjuncts *)((long)(factors) ^ 01))
180 DdNode *superset1, *superset2, *glocal, *hlocal;
185 if (superset1 == NULL)
return(0);
188 if (superset2 == NULL) {
197 if (hlocal == NULL) {
206 if (glocal == NULL) {
214 if (glocal !=
DD_ONE(dd)) {
215 if (hlocal !=
DD_ONE(dd)) {
217 if (*conjuncts == NULL) {
223 (*conjuncts)[0] = glocal;
224 (*conjuncts)[1] = hlocal;
229 if (*conjuncts == NULL) {
234 (*conjuncts)[0] = glocal;
240 if (*conjuncts == NULL) {
245 (*conjuncts)[0] = hlocal;
281 for (i = 0; i <
result; i++) {
282 (*disjuncts)[i] =
Cudd_Not((*disjuncts)[i]);
318 DdNode *superset1, *superset2, *old[2], *res[2];
319 int sizeOld, sizeNew;
332 if (superset1 == NULL) {
339 if (superset2 == NULL) {
348 if (res[0] == NULL) {
356 if (res[0] == old[0]) {
363 if (res[1] == NULL) {
371 if (sizeNew <= sizeOld) {
388 if (superset1 == NULL) {
397 if (old[0] !=
DD_ONE(dd)) {
398 if (old[1] !=
DD_ONE(dd)) {
400 if (*conjuncts == NULL) {
406 (*conjuncts)[0] = old[0];
407 (*conjuncts)[1] = old[1];
412 if (*conjuncts == NULL) {
417 (*conjuncts)[0] = old[0];
423 if (*conjuncts == NULL) {
428 (*conjuncts)[0] = old[1];
464 for (i = 0; i <
result; i++) {
465 (*disjuncts)[i] =
Cudd_Not((*disjuncts)[i]);
519 if (*conjuncts == NULL) {
525 (*conjuncts)[0] = glocal;
526 (*conjuncts)[1] = hlocal;
531 if (*conjuncts == NULL) {
536 (*conjuncts)[0] = glocal;
542 if (*conjuncts == NULL) {
547 (*conjuncts)[0] = hlocal;
583 for (i = 0; i <
result; i++) {
584 (*disjuncts)[i] =
Cudd_Not((*disjuncts)[i]);
622 DdNode *support, *scan, *
var, *glocal, *hlocal;
626 if (support == NULL)
return(0);
629 if (*conjuncts == NULL) {
646 int est = (est1 > est0) ? est1 : est0;
660 if (glocal == NULL) {
665 if (hlocal == NULL) {
671 if (glocal !=
DD_ONE(dd)) {
672 if (hlocal !=
DD_ONE(dd)) {
674 if (*conjuncts == NULL) {
680 (*conjuncts)[0] = glocal;
681 (*conjuncts)[1] = hlocal;
686 if (*conjuncts == NULL) {
691 (*conjuncts)[0] = glocal;
697 if (*conjuncts == NULL) {
702 (*conjuncts)[0] = hlocal;
741 for (i = 0; i <
result; i++) {
742 (*disjuncts)[i] =
Cudd_Not((*disjuncts)[i]);
777 int distance, distanceNv, distanceNnv;
778 NodeStat *nodeStat, *nodeStatNv, *nodeStatNnv;
788 if (
st__lookup(distanceTable, (
const char *)N, (
char **)&nodeStat)) {
800 if (nodeStatNv == NULL)
return(NULL);
804 if (nodeStatNnv == NULL)
return(NULL);
805 distanceNnv = nodeStatNnv->
distance;
809 distance = (distanceNv > distanceNnv) ? (distanceNv+1) : (distanceNnv + 1);
812 if (nodeStat == NULL) {
818 if (
st__insert(distanceTable, (
char *)N, (
char *)nodeStat) ==
848 double min, minNv, minNnv;
862 if (
st__lookup(mintermTable, (
const char *)node, (
char **)&dummy)) {
874 if (minNv == -1.0)
return(-1.0);
876 if (minNnv == -1.0)
return(-1.0);
877 min = minNv / 2.0 + minNnv / 2.0;
882 if (dummy == NULL)
return(-1.0);
885 (void) fprintf(fp,
"st table insert failed\n");
949 int valueG, valueH, gPresent, hPresent;
951 valueG = valueH = gPresent = hPresent = 0;
956 if (!gPresent && !hPresent)
return(
NONE);
959 if (valueG & 1)
return(
G_ST);
960 if (valueG & 2)
return(
G_CR);
963 if (valueH & 1)
return(
H_CR);
964 if (valueH & 2)
return(
H_ST);
967 if ((valueG & 1) && (valueH & 2))
return(
PAIR_ST);
968 if ((valueG & 2) && (valueH & 1))
return(
PAIR_CR);
1013 if (factors == NULL)
return(NULL);
1014 if ((pairValue ==
BOTH_H) || (pairValue ==
H_ST)) {
1029 }
else if ((pairValue ==
BOTH_G) || (pairValue ==
G_ST)) {
1044 }
else if (pairValue ==
H_CR) {
1054 }
else if (pairValue ==
G_CR) {
1064 }
else if (pairValue ==
PAIR_CR) {
1068 }
else if (pairValue ==
PAIR_ST) {
1113 if (factors == NULL)
return(NULL);
1118 }
else if (g2 == one) {
1127 }
else if (g1 == one) {
1134 if (oneRef >= twoRef) {
1146 if (factors->
g != one) {
1168 if (factors->
h != one) {
1191 if (
st__insert(cacheTable, (
char *)node, (
char *)factors) ==
1227 int pairValue1, pairValue2;
1238 if ((pairValue1 ==
NONE) && (pairValue2 ==
NONE)) {
1243 if (factors == NULL) {
1252 }
else if (pairValue2 ==
PAIR_ST) {
1255 }
else if (pairValue1 ==
PAIR_CR) {
1258 }
else if (pairValue2 ==
PAIR_CR) {
1261 }
else if (pairValue1 ==
G_ST) {
1274 }
else if (pairValue1 ==
BOTH_G) {
1287 }
else if (pairValue1 ==
H_ST) {
1300 }
else if (pairValue1 ==
BOTH_H) {
1313 }
else if (pairValue2 ==
G_ST) {
1326 }
else if (pairValue2 ==
BOTH_G) {
1339 }
else if (pairValue2 ==
H_ST) {
1352 }
else if (pairValue2 ==
BOTH_H) {
1365 }
else if (pairValue1 ==
G_CR) {
1378 }
else if (pairValue1 ==
H_CR) {
1391 }
else if (pairValue2 ==
G_CR) {
1404 }
else if (pairValue2 ==
H_CR) {
1420 if (
st__insert(cacheTable, (
char *)node, (
char *)factors) ==
1456 DdNode *g, *h, *g1, *g2, *h1, *h2, *x, *N, *G, *H, *Gv, *Gnv;
1465 x = dd->
vars[topid];
1470 if (factorsNv->
g == one) {
1473 if (factors == NULL) {
1480 factors->
h = factorsNv->
h;
1504 if (factorsNv->
h == one) {
1507 if (factors == NULL) {
1513 factors->
g = factorsNv->
g;
1542 if ((Gv == zero) || (Gnv == zero)) {
1560 if (factors == NULL) {
1574 if ((Hv == zero) || (Hnv == zero)) {
1592 if (factors == NULL) {
1622 factors =
CheckInTables(node, g1, h1, g2, h2, ghTable, cacheTable, &outOfMem);
1631 if (factors != NULL) {
1632 if ((factors->
g == g1) || (factors->
g == h1)) {
1643 factors =
PickOnePair(node,g1, h1, g2, h2, ghTable, cacheTable);
1644 if (factors == NULL) {
1652 if ((factors->
g == g1) || (factors->
g == h1)) {
1695 int topid, distance;
1696 Conjuncts *factorsNv = NULL, *factorsNnv = NULL, *factors;
1698 DdNode *N, *Nv, *Nnv, *temp, *g1, *g2, *h1, *h2, *topv;
1699 double minNv = 0.0, minNnv = 0.0;
1700 double *doubleDummy;
1703 int freeNv = 0, freeNnv = 0, freeTemp;
1710 if (factors == NULL) {
1720 if (
st__lookup(cacheTable, (
const char *)node, (
char **)&dummy)) {
1727 if (!
st__lookup(distanceTable, (
const char *)N, (
char **)&nodeStat)) {
1728 (void) fprintf(dd->
err,
"Not in table, Something wrong\n");
1735 if (((nodeStat->
localRef > maxLocalRef*2/3) &&
1736 (distance < approxDistance*2/3)) ||
1737 (distance <= approxDistance/4)) {
1739 if (factors == NULL) {
1756 }
else if (value == 1) {
1797 if (!
st__lookup(mintermTable, (
const char *)Nv, (
char **)&doubleDummy)) {
1798 (void) fprintf(dd->
err,
"Not in table: Something wrong\n");
1802 minNv = *doubleDummy;
1806 if (!
st__lookup(mintermTable, (
const char *)Nnv, (
char **)&doubleDummy)) {
1807 (void) fprintf(dd->
err,
"Not in table: Something wrong\n");
1811 minNnv = *doubleDummy;
1814 if (minNv < minNnv) {
1824 cacheTable, approxDistance, maxLocalRef,
1825 ghTable, mintermTable);
1826 if (factorsNv == NULL)
return(NULL);
1835 factors =
ZeroCase(dd, node, factorsNv, ghTable,
1836 cacheTable, switched);
1845 cacheTable, approxDistance, maxLocalRef,
1846 ghTable, mintermTable);
1847 if (factorsNnv == NULL) {
1861 factors =
ZeroCase(dd, node, factorsNnv, ghTable,
1862 cacheTable, switched);
1872 factors = factorsNnv;
1873 factorsNnv = factorsNv;
1874 factorsNv = factors;
1882 topv = dd->
vars[topid];
1947 factors =
CheckInTables(node, g1, h1, g2, h2, ghTable, cacheTable, &outOfMem);
1956 if (factors != NULL) {
1957 if ((factors->g == g1) || (factors->g == h1)) {
1968 factors =
PickOnePair(node,g1, h1, g2, h2, ghTable, cacheTable);
1969 if (factors == NULL) {
1977 if ((factors->g == g1) || (factors->g == h1)) {
2018 int distance, approxDistance;
2030 if (distanceTable == NULL)
goto outOfMem;
2034 if (nodeStat == NULL)
goto outOfMem;
2043 if (nodeStat == NULL)
goto outOfMem;
2049 if (distance < approxDistance) {
2055 if (stGen == NULL)
goto outOfMem;
2056 while(
st__gen(stGen, (
const char **)&key, (
char **)&value)) {
2067 if (stGen == NULL)
goto outOfMem;
2068 while(
st__gen(stGen, (
const char **)&key, (
char **)&value)) {
2070 maxLocalRef = (nodeStat->
localRef > maxLocalRef) ?
2079 if (mintermTable == NULL)
goto outOfMem;
2081 if (minterms == -1.0)
goto outOfMem;
2085 if (cacheTable == NULL)
goto outOfMem;
2087 if (ghTable == NULL)
goto outOfMem;
2091 approxDistance, maxLocalRef, ghTable, mintermTable);
2092 if (factors == NULL)
goto outOfMem;
2096 if (stGen == NULL)
goto outOfMem;
2097 while(
st__gen(stGen, (
const char **)&key, (
char **)&value)) {
2105 if (stGen == NULL)
goto outOfMem;
2106 while(
st__gen(stGen, (
const char **)&key, (
char **)&value)) {
2114 if (factors != NULL) {
2119 if (freeFactors)
ABC_FREE(factors);
2139 if (stGen == NULL)
goto outOfMem;
2140 while(
st__gen(stGen, (
const char **)&key, (
char **)&value)) {
2150 if (distanceTable != NULL) {
2152 if (stGen == NULL)
goto outOfMem;
2153 while(
st__gen(stGen, (
const char **)&key, (
char **)&value)) {
2159 if (mintermTable != NULL) {
2161 if (stGen == NULL)
goto outOfMem;
2162 while(
st__gen(stGen, (
const char **)&key, (
char **)&value)) {
2169 if (cacheTable != NULL) {
2171 if (stGen == NULL)
goto outOfMem;
2172 while(
st__gen(stGen, (
const char **)&key, (
char **)&value)) {
void st__free_table(st__table *table)
int Cudd_bddIterDisjDecomp(DdManager *dd, DdNode *f, DdNode ***disjuncts)
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
void st__free_gen(st__generator *gen)
int st__insert(st__table *table, const char *key, char *value)
DdNode * Cudd_Support(DdManager *dd, DdNode *f)
static char rcsid[] DD_UNUSED
#define Cudd_IsConstant(node)
DdNode * Cudd_RemapOverApprox(DdManager *dd, DdNode *f, int numVars, int threshold, double quality)
#define Cudd_Regular(node)
int st__ptrcmp(const char *, const char *)
#define ABC_ALLOC(type, num)
int st__lookup_int(st__table *table, char *key, int *value)
static void ConjunctsFree(DdManager *dd, Conjuncts *factors)
DdNode * Cudd_bddLICompaction(DdManager *dd, DdNode *f, DdNode *c)
int Cudd_bddGenDisjDecomp(DdManager *dd, DdNode *f, DdNode ***disjuncts)
struct Conjuncts Conjuncts
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
static Conjuncts * CheckInTables(DdNode *node, DdNode *g1, DdNode *h1, DdNode *g2, DdNode *h2, st__table *ghTable, st__table *cacheTable, int *outOfMem)
static Conjuncts * PickOnePair(DdNode *node, DdNode *g1, DdNode *h1, DdNode *g2, DdNode *h2, st__table *ghTable, st__table *cacheTable)
#define FactorsUncomplement(factors)
#define Cudd_IsComplement(node)
#define FactorsComplement(factors)
int Cudd_bddVarConjDecomp(DdManager *dd, DdNode *f, DdNode ***conjuncts)
static Conjuncts * BuildConjuncts(DdManager *dd, DdNode *node, st__table *distanceTable, st__table *cacheTable, int approxDistance, int maxLocalRef, st__table *ghTable, st__table *mintermTable)
#define ABC_NAMESPACE_IMPL_END
#define cuddIsConstant(node)
int Cudd_bddApproxConjDecomp(DdManager *dd, DdNode *f, DdNode ***conjuncts)
static Conjuncts * CheckTablesCacheAndReturn(DdNode *node, DdNode *g, DdNode *h, st__table *ghTable, st__table *cacheTable)
int Cudd_bddApproxDisjDecomp(DdManager *dd, DdNode *f, DdNode ***disjuncts)
DdNode * Cudd_bddOr(DdManager *dd, DdNode *f, DdNode *g)
st__generator * st__init_gen(st__table *table)
int Cudd_EstimateCofactor(DdManager *dd, DdNode *node, int i, int phase)
#define ABC_NAMESPACE_IMPL_START
static int PairInTables(DdNode *g, DdNode *h, st__table *ghTable)
int Cudd_bddLeq(DdManager *dd, DdNode *f, DdNode *g)
int st__lookup(st__table *table, const char *key, char **value)
int Cudd_bddVarDisjDecomp(DdManager *dd, DdNode *f, DdNode ***disjuncts)
static NodeStat * CreateBotDist(DdNode *node, st__table *distanceTable)
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
int Cudd_bddIterConjDecomp(DdManager *dd, DdNode *f, DdNode ***conjuncts)
#define Cudd_NotCond(node, c)
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
#define FactorsNotStored(factors)
int Cudd_bddGenConjDecomp(DdManager *dd, DdNode *f, DdNode ***conjuncts)
DdNode * cuddBddAndRecur(DdManager *manager, DdNode *f, DdNode *g)
int Cudd_SupportSize(DdManager *dd, DdNode *f)
static int cuddConjunctsAux(DdManager *dd, DdNode *f, DdNode **c1, DdNode **c2)
int Cudd_SharingSize(DdNode **nodeArray, int n)
int st__ptrhash(const char *, int)
int st__gen(st__generator *gen, const char **key_p, char **value_p)
DdNode * Cudd_bddSqueeze(DdManager *dd, DdNode *l, DdNode *u)
static Conjuncts * ZeroCase(DdManager *dd, DdNode *node, Conjuncts *factorsNv, st__table *ghTable, st__table *cacheTable, int switched)
static double CountMinterms(DdNode *node, double max, st__table *mintermTable, FILE *fp)
DdNode * cuddBddIteRecur(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)