1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
|
/**CFile***********************************************************************
FileName [cuddGenCof.c]
PackageName [cudd]
Synopsis [Generalized cofactors for BDDs and ADDs.]
Description [External procedures included in this module:
<ul>
<li> Cudd_bddConstrain()
<li> Cudd_bddRestrict()
<li> Cudd_bddNPAnd()
<li> Cudd_addConstrain()
<li> Cudd_bddConstrainDecomp()
<li> Cudd_addRestrict()
<li> Cudd_bddCharToVect()
<li> Cudd_bddLICompaction()
<li> Cudd_bddSqueeze()
<li> Cudd_SubsetCompress()
<li> Cudd_SupersetCompress()
</ul>
Internal procedures included in this module:
<ul>
<li> cuddBddConstrainRecur()
<li> cuddBddRestrictRecur()
<li> cuddBddNPAndRecur()
<li> cuddAddConstrainRecur()
<li> cuddAddRestrictRecur()
<li> cuddBddLICompaction()
</ul>
Static procedures included in this module:
<ul>
<li> cuddBddConstrainDecomp()
<li> cuddBddCharToVect()
<li> cuddBddLICMarkEdges()
<li> cuddBddLICBuildResult()
<li> cuddBddSqueeze()
</ul>
]
Author [Fabio Somenzi]
Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of the University of Colorado nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.]
******************************************************************************/
#include "util_hack.h"
#include "cuddInt.h"
ABC_NAMESPACE_IMPL_START
/*---------------------------------------------------------------------------*/
/* Constant declarations */
/*---------------------------------------------------------------------------*/
/* Codes for edge markings in Cudd_bddLICompaction. The codes are defined
** so that they can be bitwise ORed to implement the code priority scheme.
*/
#define DD_LIC_DC 0
#define DD_LIC_1 1
#define DD_LIC_0 2
#define DD_LIC_NL 3
/*---------------------------------------------------------------------------*/
/* Stucture declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Type declarations */
/*---------------------------------------------------------------------------*/
/* Key for the cache used in the edge marking phase. */
typedef struct MarkCacheKey {
DdNode *f;
DdNode *c;
} MarkCacheKey;
/*---------------------------------------------------------------------------*/
/* Variable declarations */
/*---------------------------------------------------------------------------*/
#ifndef lint
static char rcsid[] DD_UNUSED = "$Id: cuddGenCof.c,v 1.38 2005/05/14 17:27:11 fabio Exp $";
#endif
/*---------------------------------------------------------------------------*/
/* Macro declarations */
/*---------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/**AutomaticStart*************************************************************/
/*---------------------------------------------------------------------------*/
/* Static function prototypes */
/*---------------------------------------------------------------------------*/
static int cuddBddConstrainDecomp (DdManager *dd, DdNode *f, DdNode **decomp);
static DdNode * cuddBddCharToVect (DdManager *dd, DdNode *f, DdNode *x);
static int cuddBddLICMarkEdges (DdManager *dd, DdNode *f, DdNode *c, st_table *table, st_table *cache);
static DdNode * cuddBddLICBuildResult (DdManager *dd, DdNode *f, st_table *cache, st_table *table);
static int MarkCacheHash (const char *ptr, int modulus);
static int MarkCacheCompare (const char *ptr1, const char *ptr2);
static enum st_retval MarkCacheCleanUp (char *key, char *value, char *arg);
static DdNode * cuddBddSqueeze (DdManager *dd, DdNode *l, DdNode *u);
/**AutomaticEnd***************************************************************/
#ifdef __cplusplus
}
#endif
/*---------------------------------------------------------------------------*/
/* Definition of exported functions */
/*---------------------------------------------------------------------------*/
/**Function********************************************************************
Synopsis [Computes f constrain c.]
Description [Computes f constrain c (f @ c).
Uses a canonical form: (f' @ c) = ( f @ c)'. (Note: this is not true
for c.) List of special cases:
<ul>
<li> f @ 0 = 0
<li> f @ 1 = f
<li> 0 @ c = 0
<li> 1 @ c = 1
<li> f @ f = 1
<li> f @ f'= 0
</ul>
Returns a pointer to the result if successful; NULL otherwise. Note that if
F=(f1,...,fn) and reordering takes place while computing F @ c, then the
image restriction property (Img(F,c) = Img(F @ c)) is lost.]
SideEffects [None]
SeeAlso [Cudd_bddRestrict Cudd_addConstrain]
******************************************************************************/
DdNode *
Cudd_bddConstrain(
DdManager * dd,
DdNode * f,
DdNode * c)
{
DdNode *res;
do {
dd->reordered = 0;
res = cuddBddConstrainRecur(dd,f,c);
} while (dd->reordered == 1);
return(res);
} /* end of Cudd_bddConstrain */
/**Function********************************************************************
Synopsis [BDD restrict according to Coudert and Madre's algorithm
(ICCAD90).]
Description [BDD restrict according to Coudert and Madre's algorithm
(ICCAD90). Returns the restricted BDD if successful; otherwise NULL.
If application of restrict results in a BDD larger than the input
BDD, the input BDD is returned.]
SideEffects [None]
SeeAlso [Cudd_bddConstrain Cudd_addRestrict]
******************************************************************************/
DdNode *
Cudd_bddRestrict(
DdManager * dd,
DdNode * f,
DdNode * c)
{
DdNode *suppF, *suppC, *commonSupport;
DdNode *cplus, *res;
int retval;
int sizeF, sizeRes;
/* Check terminal cases here to avoid computing supports in trivial cases.
** This also allows us notto check later for the case c == 0, in which
** there is no common support. */
if (c == Cudd_Not(DD_ONE(dd))) return(Cudd_Not(DD_ONE(dd)));
if (Cudd_IsConstant(f)) return(f);
if (f == c) return(DD_ONE(dd));
if (f == Cudd_Not(c)) return(Cudd_Not(DD_ONE(dd)));
/* Check if supports intersect. */
retval = Cudd_ClassifySupport(dd,f,c,&commonSupport,&suppF,&suppC);
if (retval == 0) {
return(NULL);
}
cuddRef(commonSupport); cuddRef(suppF); cuddRef(suppC);
Cudd_IterDerefBdd(dd,suppF);
if (commonSupport == DD_ONE(dd)) {
Cudd_IterDerefBdd(dd,commonSupport);
Cudd_IterDerefBdd(dd,suppC);
return(f);
}
Cudd_IterDerefBdd(dd,commonSupport);
/* Abstract from c the variables that do not appear in f. */
cplus = Cudd_bddExistAbstract(dd, c, suppC);
if (cplus == NULL) {
Cudd_IterDerefBdd(dd,suppC);
return(NULL);
}
cuddRef(cplus);
Cudd_IterDerefBdd(dd,suppC);
do {
dd->reordered = 0;
res = cuddBddRestrictRecur(dd, f, cplus);
} while (dd->reordered == 1);
if (res == NULL) {
Cudd_IterDerefBdd(dd,cplus);
return(NULL);
}
cuddRef(res);
Cudd_IterDerefBdd(dd,cplus);
/* Make restric safe by returning the smaller of the input and the
** result. */
sizeF = Cudd_DagSize(f);
sizeRes = Cudd_DagSize(res);
if (sizeF <= sizeRes) {
Cudd_IterDerefBdd(dd, res);
return(f);
} else {
cuddDeref(res);
return(res);
}
} /* end of Cudd_bddRestrict */
/**Function********************************************************************
Synopsis [Computes f non-polluting-and g.]
Description [Computes f non-polluting-and g. The non-polluting AND
of f and g is a hybrid of AND and Restrict. From Restrict, this
operation takes the idea of existentially quantifying the top
variable of the second operand if it does not appear in the first.
Therefore, the variables that appear in the result also appear in f.
For the rest, the function behaves like AND. Since the two operands
play different roles, non-polluting AND is not commutative.
Returns a pointer to the result if successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddConstrain Cudd_bddRestrict]
******************************************************************************/
DdNode *
Cudd_bddNPAnd(
DdManager * dd,
DdNode * f,
DdNode * g)
{
DdNode *res;
do {
dd->reordered = 0;
res = cuddBddNPAndRecur(dd,f,g);
} while (dd->reordered == 1);
return(res);
} /* end of Cudd_bddNPAnd */
/**Function********************************************************************
Synopsis [Computes f constrain c for ADDs.]
Description [Computes f constrain c (f @ c), for f an ADD and c a 0-1
ADD. List of special cases:
<ul>
<li> F @ 0 = 0
<li> F @ 1 = F
<li> 0 @ c = 0
<li> 1 @ c = 1
<li> F @ F = 1
</ul>
Returns a pointer to the result if successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddConstrain]
******************************************************************************/
DdNode *
Cudd_addConstrain(
DdManager * dd,
DdNode * f,
DdNode * c)
{
DdNode *res;
do {
dd->reordered = 0;
res = cuddAddConstrainRecur(dd,f,c);
} while (dd->reordered == 1);
return(res);
} /* end of Cudd_addConstrain */
/**Function********************************************************************
Synopsis [BDD conjunctive decomposition as in McMillan's CAV96 paper.]
Description [BDD conjunctive decomposition as in McMillan's CAV96
paper. The decomposition is canonical only for a given variable
order. If canonicity is required, variable ordering must be disabled
after the decomposition has been computed. Returns an array with one
entry for each BDD variable in the manager if successful; otherwise
NULL. The components of the solution have their reference counts
already incremented (unlike the results of most other functions in
the package.]
SideEffects [None]
SeeAlso [Cudd_bddConstrain Cudd_bddExistAbstract]
******************************************************************************/
DdNode **
Cudd_bddConstrainDecomp(
DdManager * dd,
DdNode * f)
{
DdNode **decomp;
int res;
int i;
/* Create an initialize decomposition array. */
decomp = ABC_ALLOC(DdNode *,dd->size);
if (decomp == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
return(NULL);
}
for (i = 0; i < dd->size; i++) {
decomp[i] = NULL;
}
do {
dd->reordered = 0;
/* Clean up the decomposition array in case reordering took place. */
for (i = 0; i < dd->size; i++) {
if (decomp[i] != NULL) {
Cudd_IterDerefBdd(dd, decomp[i]);
decomp[i] = NULL;
}
}
res = cuddBddConstrainDecomp(dd,f,decomp);
} while (dd->reordered == 1);
if (res == 0) {
ABC_FREE(decomp);
return(NULL);
}
/* Missing components are constant ones. */
for (i = 0; i < dd->size; i++) {
if (decomp[i] == NULL) {
decomp[i] = DD_ONE(dd);
cuddRef(decomp[i]);
}
}
return(decomp);
} /* end of Cudd_bddConstrainDecomp */
/**Function********************************************************************
Synopsis [ADD restrict according to Coudert and Madre's algorithm
(ICCAD90).]
Description [ADD restrict according to Coudert and Madre's algorithm
(ICCAD90). Returns the restricted ADD if successful; otherwise NULL.
If application of restrict results in an ADD larger than the input
ADD, the input ADD is returned.]
SideEffects [None]
SeeAlso [Cudd_addConstrain Cudd_bddRestrict]
******************************************************************************/
DdNode *
Cudd_addRestrict(
DdManager * dd,
DdNode * f,
DdNode * c)
{
DdNode *supp_f, *supp_c;
DdNode *res, *commonSupport;
int intersection;
int sizeF, sizeRes;
/* Check if supports intersect. */
supp_f = Cudd_Support(dd, f);
if (supp_f == NULL) {
return(NULL);
}
cuddRef(supp_f);
supp_c = Cudd_Support(dd, c);
if (supp_c == NULL) {
Cudd_RecursiveDeref(dd,supp_f);
return(NULL);
}
cuddRef(supp_c);
commonSupport = Cudd_bddLiteralSetIntersection(dd, supp_f, supp_c);
if (commonSupport == NULL) {
Cudd_RecursiveDeref(dd,supp_f);
Cudd_RecursiveDeref(dd,supp_c);
return(NULL);
}
cuddRef(commonSupport);
Cudd_RecursiveDeref(dd,supp_f);
Cudd_RecursiveDeref(dd,supp_c);
intersection = commonSupport != DD_ONE(dd);
Cudd_RecursiveDeref(dd,commonSupport);
if (intersection) {
do {
dd->reordered = 0;
res = cuddAddRestrictRecur(dd, f, c);
} while (dd->reordered == 1);
sizeF = Cudd_DagSize(f);
sizeRes = Cudd_DagSize(res);
if (sizeF <= sizeRes) {
cuddRef(res);
Cudd_RecursiveDeref(dd, res);
return(f);
} else {
return(res);
}
} else {
return(f);
}
} /* end of Cudd_addRestrict */
/**Function********************************************************************
Synopsis [Computes a vector whose image equals a non-zero function.]
Description [Computes a vector of BDDs whose image equals a non-zero
function.
The result depends on the variable order. The i-th component of the vector
depends only on the first i variables in the order. Each BDD in the vector
is not larger than the BDD of the given characteristic function. This
function is based on the description of char-to-vect in "Verification of
Sequential Machines Using Boolean Functional Vectors" by O. Coudert, C.
Berthet and J. C. Madre.
Returns a pointer to an array containing the result if successful; NULL
otherwise. The size of the array equals the number of variables in the
manager. The components of the solution have their reference counts
already incremented (unlike the results of most other functions in
the package).]
SideEffects [None]
SeeAlso [Cudd_bddConstrain]
******************************************************************************/
DdNode **
Cudd_bddCharToVect(
DdManager * dd,
DdNode * f)
{
int i, j;
DdNode **vect;
DdNode *res = NULL;
if (f == Cudd_Not(DD_ONE(dd))) return(NULL);
vect = ABC_ALLOC(DdNode *, dd->size);
if (vect == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
return(NULL);
}
do {
dd->reordered = 0;
for (i = 0; i < dd->size; i++) {
res = cuddBddCharToVect(dd,f,dd->vars[dd->invperm[i]]);
if (res == NULL) {
/* Clean up the vector array in case reordering took place. */
for (j = 0; j < i; j++) {
Cudd_IterDerefBdd(dd, vect[dd->invperm[j]]);
}
break;
}
cuddRef(res);
vect[dd->invperm[i]] = res;
}
} while (dd->reordered == 1);
if (res == NULL) {
ABC_FREE(vect);
return(NULL);
}
return(vect);
} /* end of Cudd_bddCharToVect */
/**Function********************************************************************
Synopsis [Performs safe minimization of a BDD.]
Description [Performs safe minimization of a BDD. Given the BDD
<code>f</code> of a function to be minimized and a BDD
<code>c</code> representing the care set, Cudd_bddLICompaction
produces the BDD of a function that agrees with <code>f</code>
wherever <code>c</code> is 1. Safe minimization means that the size
of the result is guaranteed not to exceed the size of
<code>f</code>. This function is based on the DAC97 paper by Hong et
al.. Returns a pointer to the result if successful; NULL
otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddRestrict]
******************************************************************************/
DdNode *
Cudd_bddLICompaction(
DdManager * dd /* manager */,
DdNode * f /* function to be minimized */,
DdNode * c /* constraint (care set) */)
{
DdNode *res;
do {
dd->reordered = 0;
res = cuddBddLICompaction(dd,f,c);
} while (dd->reordered == 1);
return(res);
} /* end of Cudd_bddLICompaction */
/**Function********************************************************************
Synopsis [Finds a small BDD in a function interval.]
Description [Finds a small BDD in a function interval. Given BDDs
<code>l</code> and <code>u</code>, representing the lower bound and
upper bound of a function interval, Cudd_bddSqueeze produces the BDD
of a function within the interval with a small BDD. Returns a
pointer to the result if successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddRestrict Cudd_bddLICompaction]
******************************************************************************/
DdNode *
Cudd_bddSqueeze(
DdManager * dd /* manager */,
DdNode * l /* lower bound */,
DdNode * u /* upper bound */)
{
DdNode *res;
int sizeRes, sizeL, sizeU;
do {
dd->reordered = 0;
res = cuddBddSqueeze(dd,l,u);
} while (dd->reordered == 1);
if (res == NULL) return(NULL);
/* We now compare the result with the bounds and return the smallest.
** We first compare to u, so that in case l == 0 and u == 1, we return
** 0 as in other minimization algorithms. */
sizeRes = Cudd_DagSize(res);
sizeU = Cudd_DagSize(u);
if (sizeU <= sizeRes) {
cuddRef(res);
Cudd_IterDerefBdd(dd,res);
res = u;
sizeRes = sizeU;
}
sizeL = Cudd_DagSize(l);
if (sizeL <= sizeRes) {
cuddRef(res);
Cudd_IterDerefBdd(dd,res);
res = l;
sizeRes = sizeL;
}
return(res);
} /* end of Cudd_bddSqueeze */
/**Function********************************************************************
Synopsis [Finds a small BDD that agrees with <code>f</code> over
<code>c</code>.]
Description [Finds a small BDD that agrees with <code>f</code> over
<code>c</code>. Returns a pointer to the result if successful; NULL
otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddRestrict Cudd_bddLICompaction Cudd_bddSqueeze]
******************************************************************************/
DdNode *
Cudd_bddMinimize(
DdManager * dd,
DdNode * f,
DdNode * c)
{
DdNode *cplus, *res;
if (c == Cudd_Not(DD_ONE(dd))) return(c);
if (Cudd_IsConstant(f)) return(f);
if (f == c) return(DD_ONE(dd));
if (f == Cudd_Not(c)) return(Cudd_Not(DD_ONE(dd)));
cplus = Cudd_RemapOverApprox(dd,c,0,0,1.0);
if (cplus == NULL) return(NULL);
cuddRef(cplus);
res = Cudd_bddLICompaction(dd,f,cplus);
if (res == NULL) {
Cudd_IterDerefBdd(dd,cplus);
return(NULL);
}
cuddRef(res);
Cudd_IterDerefBdd(dd,cplus);
cuddDeref(res);
return(res);
} /* end of Cudd_bddMinimize */
/**Function********************************************************************
Synopsis [Find a dense subset of BDD <code>f</code>.]
Description [Finds a dense subset of BDD <code>f</code>. Density is
the ratio of number of minterms to number of nodes. Uses several
techniques in series. It is more expensive than other subsetting
procedures, but often produces better results. See
Cudd_SubsetShortPaths for a description of the threshold and nvars
parameters. Returns a pointer to the result if successful; NULL
otherwise.]
SideEffects [None]
SeeAlso [Cudd_SubsetRemap Cudd_SubsetShortPaths Cudd_SubsetHeavyBranch
Cudd_bddSqueeze]
******************************************************************************/
DdNode *
Cudd_SubsetCompress(
DdManager * dd /* manager */,
DdNode * f /* BDD whose subset is sought */,
int nvars /* number of variables in the support of f */,
int threshold /* maximum number of nodes in the subset */)
{
DdNode *res, *tmp1, *tmp2;
tmp1 = Cudd_SubsetShortPaths(dd, f, nvars, threshold, 0);
if (tmp1 == NULL) return(NULL);
cuddRef(tmp1);
tmp2 = Cudd_RemapUnderApprox(dd,tmp1,nvars,0,1.0);
if (tmp2 == NULL) {
Cudd_IterDerefBdd(dd,tmp1);
return(NULL);
}
cuddRef(tmp2);
Cudd_IterDerefBdd(dd,tmp1);
res = Cudd_bddSqueeze(dd,tmp2,f);
if (res == NULL) {
Cudd_IterDerefBdd(dd,tmp2);
return(NULL);
}
cuddRef(res);
Cudd_IterDerefBdd(dd,tmp2);
cuddDeref(res);
return(res);
} /* end of Cudd_SubsetCompress */
/**Function********************************************************************
Synopsis [Find a dense superset of BDD <code>f</code>.]
Description [Finds a dense superset of BDD <code>f</code>. Density is
the ratio of number of minterms to number of nodes. Uses several
techniques in series. It is more expensive than other supersetting
procedures, but often produces better results. See
Cudd_SupersetShortPaths for a description of the threshold and nvars
parameters. Returns a pointer to the result if successful; NULL
otherwise.]
SideEffects [None]
SeeAlso [Cudd_SubsetCompress Cudd_SupersetRemap Cudd_SupersetShortPaths
Cudd_SupersetHeavyBranch Cudd_bddSqueeze]
******************************************************************************/
DdNode *
Cudd_SupersetCompress(
DdManager * dd /* manager */,
DdNode * f /* BDD whose superset is sought */,
int nvars /* number of variables in the support of f */,
int threshold /* maximum number of nodes in the superset */)
{
DdNode *subset;
subset = Cudd_SubsetCompress(dd, Cudd_Not(f),nvars,threshold);
return(Cudd_NotCond(subset, (subset != NULL)));
} /* end of Cudd_SupersetCompress */
/*---------------------------------------------------------------------------*/
/* Definition of internal functions */
/*---------------------------------------------------------------------------*/
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_bddConstrain.]
Description [Performs the recursive step of Cudd_bddConstrain.
Returns a pointer to the result if successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddConstrain]
******************************************************************************/
DdNode *
cuddBddConstrainRecur(
DdManager * dd,
DdNode * f,
DdNode * c)
{
DdNode *Fv, *Fnv, *Cv, *Cnv, *t, *e, *r;
DdNode *one, *zero;
unsigned int topf, topc;
int index;
int comple = 0;
statLine(dd);
one = DD_ONE(dd);
zero = Cudd_Not(one);
/* Trivial cases. */
if (c == one) return(f);
if (c == zero) return(zero);
if (Cudd_IsConstant(f)) return(f);
if (f == c) return(one);
if (f == Cudd_Not(c)) return(zero);
/* Make canonical to increase the utilization of the cache. */
if (Cudd_IsComplement(f)) {
f = Cudd_Not(f);
comple = 1;
}
/* Now f is a regular pointer to a non-constant node; c is also
** non-constant, but may be complemented.
*/
/* Check the cache. */
r = cuddCacheLookup2(dd, Cudd_bddConstrain, f, c);
if (r != NULL) {
return(Cudd_NotCond(r,comple));
}
/* Recursive step. */
topf = dd->perm[f->index];
topc = dd->perm[Cudd_Regular(c)->index];
if (topf <= topc) {
index = f->index;
Fv = cuddT(f); Fnv = cuddE(f);
} else {
index = Cudd_Regular(c)->index;
Fv = Fnv = f;
}
if (topc <= topf) {
Cv = cuddT(Cudd_Regular(c)); Cnv = cuddE(Cudd_Regular(c));
if (Cudd_IsComplement(c)) {
Cv = Cudd_Not(Cv);
Cnv = Cudd_Not(Cnv);
}
} else {
Cv = Cnv = c;
}
if (!Cudd_IsConstant(Cv)) {
t = cuddBddConstrainRecur(dd, Fv, Cv);
if (t == NULL)
return(NULL);
} else if (Cv == one) {
t = Fv;
} else { /* Cv == zero: return Fnv @ Cnv */
if (Cnv == one) {
r = Fnv;
} else {
r = cuddBddConstrainRecur(dd, Fnv, Cnv);
if (r == NULL)
return(NULL);
}
return(Cudd_NotCond(r,comple));
}
cuddRef(t);
if (!Cudd_IsConstant(Cnv)) {
e = cuddBddConstrainRecur(dd, Fnv, Cnv);
if (e == NULL) {
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
} else if (Cnv == one) {
e = Fnv;
} else { /* Cnv == zero: return Fv @ Cv previously computed */
cuddDeref(t);
return(Cudd_NotCond(t,comple));
}
cuddRef(e);
if (Cudd_IsComplement(t)) {
t = Cudd_Not(t);
e = Cudd_Not(e);
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
r = Cudd_Not(r);
} else {
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
}
cuddDeref(t);
cuddDeref(e);
cuddCacheInsert2(dd, Cudd_bddConstrain, f, c, r);
return(Cudd_NotCond(r,comple));
} /* end of cuddBddConstrainRecur */
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_bddRestrict.]
Description [Performs the recursive step of Cudd_bddRestrict.
Returns the restricted BDD if successful; otherwise NULL.]
SideEffects [None]
SeeAlso [Cudd_bddRestrict]
******************************************************************************/
DdNode *
cuddBddRestrictRecur(
DdManager * dd,
DdNode * f,
DdNode * c)
{
DdNode *Fv, *Fnv, *Cv, *Cnv, *t, *e, *r, *one, *zero;
unsigned int topf, topc;
int index;
int comple = 0;
statLine(dd);
one = DD_ONE(dd);
zero = Cudd_Not(one);
/* Trivial cases */
if (c == one) return(f);
if (c == zero) return(zero);
if (Cudd_IsConstant(f)) return(f);
if (f == c) return(one);
if (f == Cudd_Not(c)) return(zero);
/* Make canonical to increase the utilization of the cache. */
if (Cudd_IsComplement(f)) {
f = Cudd_Not(f);
comple = 1;
}
/* Now f is a regular pointer to a non-constant node; c is also
** non-constant, but may be complemented.
*/
/* Check the cache. */
r = cuddCacheLookup2(dd, Cudd_bddRestrict, f, c);
if (r != NULL) {
return(Cudd_NotCond(r,comple));
}
topf = dd->perm[f->index];
topc = dd->perm[Cudd_Regular(c)->index];
if (topc < topf) { /* abstract top variable from c */
DdNode *d, *s1, *s2;
/* Find complements of cofactors of c. */
if (Cudd_IsComplement(c)) {
s1 = cuddT(Cudd_Regular(c));
s2 = cuddE(Cudd_Regular(c));
} else {
s1 = Cudd_Not(cuddT(c));
s2 = Cudd_Not(cuddE(c));
}
/* Take the OR by applying DeMorgan. */
d = cuddBddAndRecur(dd, s1, s2);
if (d == NULL) return(NULL);
d = Cudd_Not(d);
cuddRef(d);
r = cuddBddRestrictRecur(dd, f, d);
if (r == NULL) {
Cudd_IterDerefBdd(dd, d);
return(NULL);
}
cuddRef(r);
Cudd_IterDerefBdd(dd, d);
cuddCacheInsert2(dd, Cudd_bddRestrict, f, c, r);
cuddDeref(r);
return(Cudd_NotCond(r,comple));
}
/* Recursive step. Here topf <= topc. */
index = f->index;
Fv = cuddT(f); Fnv = cuddE(f);
if (topc == topf) {
Cv = cuddT(Cudd_Regular(c)); Cnv = cuddE(Cudd_Regular(c));
if (Cudd_IsComplement(c)) {
Cv = Cudd_Not(Cv);
Cnv = Cudd_Not(Cnv);
}
} else {
Cv = Cnv = c;
}
if (!Cudd_IsConstant(Cv)) {
t = cuddBddRestrictRecur(dd, Fv, Cv);
if (t == NULL) return(NULL);
} else if (Cv == one) {
t = Fv;
} else { /* Cv == zero: return(Fnv @ Cnv) */
if (Cnv == one) {
r = Fnv;
} else {
r = cuddBddRestrictRecur(dd, Fnv, Cnv);
if (r == NULL) return(NULL);
}
return(Cudd_NotCond(r,comple));
}
cuddRef(t);
if (!Cudd_IsConstant(Cnv)) {
e = cuddBddRestrictRecur(dd, Fnv, Cnv);
if (e == NULL) {
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
} else if (Cnv == one) {
e = Fnv;
} else { /* Cnv == zero: return (Fv @ Cv) previously computed */
cuddDeref(t);
return(Cudd_NotCond(t,comple));
}
cuddRef(e);
if (Cudd_IsComplement(t)) {
t = Cudd_Not(t);
e = Cudd_Not(e);
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
r = Cudd_Not(r);
} else {
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
}
cuddDeref(t);
cuddDeref(e);
cuddCacheInsert2(dd, Cudd_bddRestrict, f, c, r);
return(Cudd_NotCond(r,comple));
} /* end of cuddBddRestrictRecur */
/**Function********************************************************************
Synopsis [Implements the recursive step of Cudd_bddAnd.]
Description [Implements the recursive step of Cudd_bddNPAnd.
Returns a pointer to the result is successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddNPAnd]
******************************************************************************/
DdNode *
cuddBddNPAndRecur(
DdManager * manager,
DdNode * f,
DdNode * g)
{
DdNode *F, *ft, *fe, *G, *gt, *ge;
DdNode *one, *r, *t, *e;
unsigned int topf, topg, index;
statLine(manager);
one = DD_ONE(manager);
/* Terminal cases. */
F = Cudd_Regular(f);
G = Cudd_Regular(g);
if (F == G) {
if (f == g) return(one);
else return(Cudd_Not(one));
}
if (G == one) {
if (g == one) return(f);
else return(g);
}
if (F == one) {
return(f);
}
/* At this point f and g are not constant. */
/* Check cache. */
if (F->ref != 1 || G->ref != 1) {
r = cuddCacheLookup2(manager, Cudd_bddNPAnd, f, g);
if (r != NULL) return(r);
}
/* Here we can skip the use of cuddI, because the operands are known
** to be non-constant.
*/
topf = manager->perm[F->index];
topg = manager->perm[G->index];
if (topg < topf) { /* abstract top variable from g */
DdNode *d;
/* Find complements of cofactors of g. */
if (Cudd_IsComplement(g)) {
gt = cuddT(G);
ge = cuddE(G);
} else {
gt = Cudd_Not(cuddT(g));
ge = Cudd_Not(cuddE(g));
}
/* Take the OR by applying DeMorgan. */
d = cuddBddAndRecur(manager, gt, ge);
if (d == NULL) return(NULL);
d = Cudd_Not(d);
cuddRef(d);
r = cuddBddNPAndRecur(manager, f, d);
if (r == NULL) {
Cudd_IterDerefBdd(manager, d);
return(NULL);
}
cuddRef(r);
Cudd_IterDerefBdd(manager, d);
cuddCacheInsert2(manager, Cudd_bddNPAnd, f, g, r);
cuddDeref(r);
return(r);
}
/* Compute cofactors. */
index = F->index;
ft = cuddT(F);
fe = cuddE(F);
if (Cudd_IsComplement(f)) {
ft = Cudd_Not(ft);
fe = Cudd_Not(fe);
}
if (topg == topf) {
gt = cuddT(G);
ge = cuddE(G);
if (Cudd_IsComplement(g)) {
gt = Cudd_Not(gt);
ge = Cudd_Not(ge);
}
} else {
gt = ge = g;
}
t = cuddBddAndRecur(manager, ft, gt);
if (t == NULL) return(NULL);
cuddRef(t);
e = cuddBddAndRecur(manager, fe, ge);
if (e == NULL) {
Cudd_IterDerefBdd(manager, t);
return(NULL);
}
cuddRef(e);
if (t == e) {
r = t;
} else {
if (Cudd_IsComplement(t)) {
r = cuddUniqueInter(manager,(int)index,Cudd_Not(t),Cudd_Not(e));
if (r == NULL) {
Cudd_IterDerefBdd(manager, t);
Cudd_IterDerefBdd(manager, e);
return(NULL);
}
r = Cudd_Not(r);
} else {
r = cuddUniqueInter(manager,(int)index,t,e);
if (r == NULL) {
Cudd_IterDerefBdd(manager, t);
Cudd_IterDerefBdd(manager, e);
return(NULL);
}
}
}
cuddDeref(e);
cuddDeref(t);
if (F->ref != 1 || G->ref != 1)
cuddCacheInsert2(manager, Cudd_bddNPAnd, f, g, r);
return(r);
} /* end of cuddBddNPAndRecur */
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_addConstrain.]
Description [Performs the recursive step of Cudd_addConstrain.
Returns a pointer to the result if successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_addConstrain]
******************************************************************************/
DdNode *
cuddAddConstrainRecur(
DdManager * dd,
DdNode * f,
DdNode * c)
{
DdNode *Fv, *Fnv, *Cv, *Cnv, *t, *e, *r;
DdNode *one, *zero;
unsigned int topf, topc;
int index;
statLine(dd);
one = DD_ONE(dd);
zero = DD_ZERO(dd);
/* Trivial cases. */
if (c == one) return(f);
if (c == zero) return(zero);
if (Cudd_IsConstant(f)) return(f);
if (f == c) return(one);
/* Now f and c are non-constant. */
/* Check the cache. */
r = cuddCacheLookup2(dd, Cudd_addConstrain, f, c);
if (r != NULL) {
return(r);
}
/* Recursive step. */
topf = dd->perm[f->index];
topc = dd->perm[c->index];
if (topf <= topc) {
index = f->index;
Fv = cuddT(f); Fnv = cuddE(f);
} else {
index = c->index;
Fv = Fnv = f;
}
if (topc <= topf) {
Cv = cuddT(c); Cnv = cuddE(c);
} else {
Cv = Cnv = c;
}
if (!Cudd_IsConstant(Cv)) {
t = cuddAddConstrainRecur(dd, Fv, Cv);
if (t == NULL)
return(NULL);
} else if (Cv == one) {
t = Fv;
} else { /* Cv == zero: return Fnv @ Cnv */
if (Cnv == one) {
r = Fnv;
} else {
r = cuddAddConstrainRecur(dd, Fnv, Cnv);
if (r == NULL)
return(NULL);
}
return(r);
}
cuddRef(t);
if (!Cudd_IsConstant(Cnv)) {
e = cuddAddConstrainRecur(dd, Fnv, Cnv);
if (e == NULL) {
Cudd_RecursiveDeref(dd, t);
return(NULL);
}
} else if (Cnv == one) {
e = Fnv;
} else { /* Cnv == zero: return Fv @ Cv previously computed */
cuddDeref(t);
return(t);
}
cuddRef(e);
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_RecursiveDeref(dd, e);
Cudd_RecursiveDeref(dd, t);
return(NULL);
}
cuddDeref(t);
cuddDeref(e);
cuddCacheInsert2(dd, Cudd_addConstrain, f, c, r);
return(r);
} /* end of cuddAddConstrainRecur */
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_addRestrict.]
Description [Performs the recursive step of Cudd_addRestrict.
Returns the restricted ADD if successful; otherwise NULL.]
SideEffects [None]
SeeAlso [Cudd_addRestrict]
******************************************************************************/
DdNode *
cuddAddRestrictRecur(
DdManager * dd,
DdNode * f,
DdNode * c)
{
DdNode *Fv, *Fnv, *Cv, *Cnv, *t, *e, *r, *one, *zero;
unsigned int topf, topc;
int index;
statLine(dd);
one = DD_ONE(dd);
zero = DD_ZERO(dd);
/* Trivial cases */
if (c == one) return(f);
if (c == zero) return(zero);
if (Cudd_IsConstant(f)) return(f);
if (f == c) return(one);
/* Now f and c are non-constant. */
/* Check the cache. */
r = cuddCacheLookup2(dd, Cudd_addRestrict, f, c);
if (r != NULL) {
return(r);
}
topf = dd->perm[f->index];
topc = dd->perm[c->index];
if (topc < topf) { /* abstract top variable from c */
DdNode *d, *s1, *s2;
/* Find cofactors of c. */
s1 = cuddT(c);
s2 = cuddE(c);
/* Take the OR by applying DeMorgan. */
d = cuddAddApplyRecur(dd, Cudd_addOr, s1, s2);
if (d == NULL) return(NULL);
cuddRef(d);
r = cuddAddRestrictRecur(dd, f, d);
if (r == NULL) {
Cudd_RecursiveDeref(dd, d);
return(NULL);
}
cuddRef(r);
Cudd_RecursiveDeref(dd, d);
cuddCacheInsert2(dd, Cudd_addRestrict, f, c, r);
cuddDeref(r);
return(r);
}
/* Recursive step. Here topf <= topc. */
index = f->index;
Fv = cuddT(f); Fnv = cuddE(f);
if (topc == topf) {
Cv = cuddT(c); Cnv = cuddE(c);
} else {
Cv = Cnv = c;
}
if (!Cudd_IsConstant(Cv)) {
t = cuddAddRestrictRecur(dd, Fv, Cv);
if (t == NULL) return(NULL);
} else if (Cv == one) {
t = Fv;
} else { /* Cv == zero: return(Fnv @ Cnv) */
if (Cnv == one) {
r = Fnv;
} else {
r = cuddAddRestrictRecur(dd, Fnv, Cnv);
if (r == NULL) return(NULL);
}
return(r);
}
cuddRef(t);
if (!Cudd_IsConstant(Cnv)) {
e = cuddAddRestrictRecur(dd, Fnv, Cnv);
if (e == NULL) {
Cudd_RecursiveDeref(dd, t);
return(NULL);
}
} else if (Cnv == one) {
e = Fnv;
} else { /* Cnv == zero: return (Fv @ Cv) previously computed */
cuddDeref(t);
return(t);
}
cuddRef(e);
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_RecursiveDeref(dd, e);
Cudd_RecursiveDeref(dd, t);
return(NULL);
}
cuddDeref(t);
cuddDeref(e);
cuddCacheInsert2(dd, Cudd_addRestrict, f, c, r);
return(r);
} /* end of cuddAddRestrictRecur */
/**Function********************************************************************
Synopsis [Performs safe minimization of a BDD.]
Description [Performs safe minimization of a BDD. Given the BDD
<code>f</code> of a function to be minimized and a BDD
<code>c</code> representing the care set, Cudd_bddLICompaction
produces the BDD of a function that agrees with <code>f</code>
wherever <code>c</code> is 1. Safe minimization means that the size
of the result is guaranteed not to exceed the size of
<code>f</code>. This function is based on the DAC97 paper by Hong et
al.. Returns a pointer to the result if successful; NULL
otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddLICompaction]
******************************************************************************/
DdNode *
cuddBddLICompaction(
DdManager * dd /* manager */,
DdNode * f /* function to be minimized */,
DdNode * c /* constraint (care set) */)
{
st_table *marktable, *markcache, *buildcache;
DdNode *res, *zero;
zero = Cudd_Not(DD_ONE(dd));
if (c == zero) return(zero);
/* We need to use local caches for both steps of this operation.
** The results of the edge marking step are only valid as long as the
** edge markings themselves are available. However, the edge markings
** are lost at the end of one invocation of Cudd_bddLICompaction.
** Hence, the cache entries for the edge marking step must be
** invalidated at the end of this function.
** For the result of the building step we argue as follows. The result
** for a node and a given constrain depends on the BDD in which the node
** appears. Hence, the same node and constrain may give different results
** in successive invocations.
*/
marktable = st_init_table(st_ptrcmp,st_ptrhash);
if (marktable == NULL) {
return(NULL);
}
markcache = st_init_table(MarkCacheCompare,MarkCacheHash);
if (markcache == NULL) {
st_free_table(marktable);
return(NULL);
}
if (cuddBddLICMarkEdges(dd,f,c,marktable,markcache) == CUDD_OUT_OF_MEM) {
st_foreach(markcache, MarkCacheCleanUp, NULL);
st_free_table(marktable);
st_free_table(markcache);
return(NULL);
}
st_foreach(markcache, MarkCacheCleanUp, NULL);
st_free_table(markcache);
buildcache = st_init_table(st_ptrcmp,st_ptrhash);
if (buildcache == NULL) {
st_free_table(marktable);
return(NULL);
}
res = cuddBddLICBuildResult(dd,f,buildcache,marktable);
st_free_table(buildcache);
st_free_table(marktable);
return(res);
} /* end of cuddBddLICompaction */
/*---------------------------------------------------------------------------*/
/* Definition of static functions */
/*---------------------------------------------------------------------------*/
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_bddConstrainDecomp.]
Description [Performs the recursive step of Cudd_bddConstrainDecomp.
Returns f super (i) if successful; otherwise NULL.]
SideEffects [None]
SeeAlso [Cudd_bddConstrainDecomp]
******************************************************************************/
static int
cuddBddConstrainDecomp(
DdManager * dd,
DdNode * f,
DdNode ** decomp)
{
DdNode *F, *fv, *fvn;
DdNode *fAbs;
DdNode *result;
int ok;
if (Cudd_IsConstant(f)) return(1);
/* Compute complements of cofactors. */
F = Cudd_Regular(f);
fv = cuddT(F);
fvn = cuddE(F);
if (F == f) {
fv = Cudd_Not(fv);
fvn = Cudd_Not(fvn);
}
/* Compute abstraction of top variable. */
fAbs = cuddBddAndRecur(dd, fv, fvn);
if (fAbs == NULL) {
return(0);
}
cuddRef(fAbs);
fAbs = Cudd_Not(fAbs);
/* Recursively find the next abstraction and the components of the
** decomposition. */
ok = cuddBddConstrainDecomp(dd, fAbs, decomp);
if (ok == 0) {
Cudd_IterDerefBdd(dd,fAbs);
return(0);
}
/* Compute the component of the decomposition corresponding to the
** top variable and store it in the decomposition array. */
result = cuddBddConstrainRecur(dd, f, fAbs);
if (result == NULL) {
Cudd_IterDerefBdd(dd,fAbs);
return(0);
}
cuddRef(result);
decomp[F->index] = result;
Cudd_IterDerefBdd(dd, fAbs);
return(1);
} /* end of cuddBddConstrainDecomp */
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_bddCharToVect.]
Description [Performs the recursive step of Cudd_bddCharToVect.
This function maintains the invariant that f is non-zero.
Returns the i-th component of the vector if successful; otherwise NULL.]
SideEffects [None]
SeeAlso [Cudd_bddCharToVect]
******************************************************************************/
static DdNode *
cuddBddCharToVect(
DdManager * dd,
DdNode * f,
DdNode * x)
{
unsigned int topf;
unsigned int level;
int comple;
DdNode *one, *zero, *res, *F, *fT, *fE, *T, *E;
statLine(dd);
/* Check the cache. */
res = cuddCacheLookup2(dd, cuddBddCharToVect, f, x);
if (res != NULL) {
return(res);
}
F = Cudd_Regular(f);
topf = cuddI(dd,F->index);
level = dd->perm[x->index];
if (topf > level) return(x);
one = DD_ONE(dd);
zero = Cudd_Not(one);
comple = F != f;
fT = Cudd_NotCond(cuddT(F),comple);
fE = Cudd_NotCond(cuddE(F),comple);
if (topf == level) {
if (fT == zero) return(zero);
if (fE == zero) return(one);
return(x);
}
/* Here topf < level. */
if (fT == zero) return(cuddBddCharToVect(dd, fE, x));
if (fE == zero) return(cuddBddCharToVect(dd, fT, x));
T = cuddBddCharToVect(dd, fT, x);
if (T == NULL) {
return(NULL);
}
cuddRef(T);
E = cuddBddCharToVect(dd, fE, x);
if (E == NULL) {
Cudd_IterDerefBdd(dd,T);
return(NULL);
}
cuddRef(E);
res = cuddBddIteRecur(dd, dd->vars[F->index], T, E);
if (res == NULL) {
Cudd_IterDerefBdd(dd,T);
Cudd_IterDerefBdd(dd,E);
return(NULL);
}
cuddDeref(T);
cuddDeref(E);
cuddCacheInsert2(dd, cuddBddCharToVect, f, x, res);
return(res);
} /* end of cuddBddCharToVect */
/**Function********************************************************************
Synopsis [Performs the edge marking step of Cudd_bddLICompaction.]
Description [Performs the edge marking step of Cudd_bddLICompaction.
Returns the LUB of the markings of the two outgoing edges of <code>f</code>
if successful; otherwise CUDD_OUT_OF_MEM.]
SideEffects [None]
SeeAlso [Cudd_bddLICompaction cuddBddLICBuildResult]
******************************************************************************/
static int
cuddBddLICMarkEdges(
DdManager * dd,
DdNode * f,
DdNode * c,
st_table * table,
st_table * cache)
{
DdNode *Fv, *Fnv, *Cv, *Cnv;
DdNode *one, *zero;
unsigned int topf, topc;
int comple;
int resT, resE, res, retval;
char **slot;
MarkCacheKey *key;
one = DD_ONE(dd);
zero = Cudd_Not(one);
/* Terminal cases. */
if (c == zero) return(DD_LIC_DC);
if (f == one) return(DD_LIC_1);
if (f == zero) return(DD_LIC_0);
/* Make canonical to increase the utilization of the cache. */
comple = Cudd_IsComplement(f);
f = Cudd_Regular(f);
/* Now f is a regular pointer to a non-constant node; c may be
** constant, or it may be complemented.
*/
/* Check the cache. */
key = ABC_ALLOC(MarkCacheKey, 1);
if (key == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
return(CUDD_OUT_OF_MEM);
}
key->f = f; key->c = c;
if (st_lookup_int(cache, (char *)key, &res)) {
ABC_FREE(key);
if (comple) {
if (res == DD_LIC_0) res = DD_LIC_1;
else if (res == DD_LIC_1) res = DD_LIC_0;
}
return(res);
}
/* Recursive step. */
topf = dd->perm[f->index];
topc = cuddI(dd,Cudd_Regular(c)->index);
if (topf <= topc) {
Fv = cuddT(f); Fnv = cuddE(f);
} else {
Fv = Fnv = f;
}
if (topc <= topf) {
/* We know that c is not constant because f is not. */
Cv = cuddT(Cudd_Regular(c)); Cnv = cuddE(Cudd_Regular(c));
if (Cudd_IsComplement(c)) {
Cv = Cudd_Not(Cv);
Cnv = Cudd_Not(Cnv);
}
} else {
Cv = Cnv = c;
}
resT = cuddBddLICMarkEdges(dd, Fv, Cv, table, cache);
if (resT == CUDD_OUT_OF_MEM) {
ABC_FREE(key);
return(CUDD_OUT_OF_MEM);
}
resE = cuddBddLICMarkEdges(dd, Fnv, Cnv, table, cache);
if (resE == CUDD_OUT_OF_MEM) {
ABC_FREE(key);
return(CUDD_OUT_OF_MEM);
}
/* Update edge markings. */
if (topf <= topc) {
retval = st_find_or_add(table, (char *)f, (char ***)&slot);
if (retval == 0) {
*slot = (char *) (ptrint)((resT << 2) | resE);
} else if (retval == 1) {
*slot = (char *) (ptrint)((int)((ptrint) *slot) | (resT << 2) | resE);
} else {
ABC_FREE(key);
return(CUDD_OUT_OF_MEM);
}
}
/* Cache result. */
res = resT | resE;
if (st_insert(cache, (char *)key, (char *)(ptrint)res) == ST_OUT_OF_MEM) {
ABC_FREE(key);
return(CUDD_OUT_OF_MEM);
}
/* Take into account possible complementation. */
if (comple) {
if (res == DD_LIC_0) res = DD_LIC_1;
else if (res == DD_LIC_1) res = DD_LIC_0;
}
return(res);
} /* end of cuddBddLICMarkEdges */
/**Function********************************************************************
Synopsis [Builds the result of Cudd_bddLICompaction.]
Description [Builds the results of Cudd_bddLICompaction.
Returns a pointer to the minimized BDD if successful; otherwise NULL.]
SideEffects [None]
SeeAlso [Cudd_bddLICompaction cuddBddLICMarkEdges]
******************************************************************************/
static DdNode *
cuddBddLICBuildResult(
DdManager * dd,
DdNode * f,
st_table * cache,
st_table * table)
{
DdNode *Fv, *Fnv, *r, *t, *e;
DdNode *one, *zero;
int index;
int comple;
int markT, markE, markings;
one = DD_ONE(dd);
zero = Cudd_Not(one);
if (Cudd_IsConstant(f)) return(f);
/* Make canonical to increase the utilization of the cache. */
comple = Cudd_IsComplement(f);
f = Cudd_Regular(f);
/* Check the cache. */
if (st_lookup(cache, (const char *)f, (char **)&r)) {
return(Cudd_NotCond(r,comple));
}
/* Retrieve the edge markings. */
if (st_lookup_int(table, (char *)f, &markings) == 0)
return(NULL);
markT = markings >> 2;
markE = markings & 3;
index = f->index;
Fv = cuddT(f); Fnv = cuddE(f);
if (markT == DD_LIC_NL) {
t = cuddBddLICBuildResult(dd,Fv,cache,table);
if (t == NULL) {
return(NULL);
}
} else if (markT == DD_LIC_1) {
t = one;
} else {
t = zero;
}
cuddRef(t);
if (markE == DD_LIC_NL) {
e = cuddBddLICBuildResult(dd,Fnv,cache,table);
if (e == NULL) {
Cudd_IterDerefBdd(dd,t);
return(NULL);
}
} else if (markE == DD_LIC_1) {
e = one;
} else {
e = zero;
}
cuddRef(e);
if (markT == DD_LIC_DC && markE != DD_LIC_DC) {
r = e;
} else if (markT != DD_LIC_DC && markE == DD_LIC_DC) {
r = t;
} else {
if (Cudd_IsComplement(t)) {
t = Cudd_Not(t);
e = Cudd_Not(e);
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
r = Cudd_Not(r);
} else {
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
}
}
cuddDeref(t);
cuddDeref(e);
if (st_insert(cache, (char *)f, (char *)r) == ST_OUT_OF_MEM) {
cuddRef(r);
Cudd_IterDerefBdd(dd,r);
return(NULL);
}
return(Cudd_NotCond(r,comple));
} /* end of cuddBddLICBuildResult */
/**Function********************************************************************
Synopsis [Hash function for the computed table of cuddBddLICMarkEdges.]
Description [Hash function for the computed table of
cuddBddLICMarkEdges. Returns the bucket number.]
SideEffects [None]
SeeAlso [Cudd_bddLICompaction]
******************************************************************************/
static int
MarkCacheHash(
const char * ptr,
int modulus)
{
int val = 0;
MarkCacheKey *entry;
entry = (MarkCacheKey *) ptr;
val = (int) (ptrint) entry->f;
val = val * 997 + (int) (ptrint) entry->c;
return ((val < 0) ? -val : val) % modulus;
} /* end of MarkCacheHash */
/**Function********************************************************************
Synopsis [Comparison function for the computed table of
cuddBddLICMarkEdges.]
Description [Comparison function for the computed table of
cuddBddLICMarkEdges. Returns 0 if the two nodes of the key are equal; 1
otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddLICompaction]
******************************************************************************/
static int
MarkCacheCompare(
const char * ptr1,
const char * ptr2)
{
MarkCacheKey *entry1, *entry2;
entry1 = (MarkCacheKey *) ptr1;
entry2 = (MarkCacheKey *) ptr2;
return((entry1->f != entry2->f) || (entry1->c != entry2->c));
} /* end of MarkCacheCompare */
/**Function********************************************************************
Synopsis [Frees memory associated with computed table of
cuddBddLICMarkEdges.]
Description [Frees memory associated with computed table of
cuddBddLICMarkEdges. Returns ST_CONTINUE.]
SideEffects [None]
SeeAlso [Cudd_bddLICompaction]
******************************************************************************/
static enum st_retval
MarkCacheCleanUp(
char * key,
char * value,
char * arg)
{
MarkCacheKey *entry;
entry = (MarkCacheKey *) key;
ABC_FREE(entry);
return ST_CONTINUE;
} /* end of MarkCacheCleanUp */
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_bddSqueeze.]
Description [Performs the recursive step of Cudd_bddSqueeze. This
procedure exploits the fact that if we complement and swap the
bounds of the interval we obtain a valid solution by taking the
complement of the solution to the original problem. Therefore, we
can enforce the condition that the upper bound is always regular.
Returns a pointer to the result if successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_bddSqueeze]
******************************************************************************/
static DdNode *
cuddBddSqueeze(
DdManager * dd,
DdNode * l,
DdNode * u)
{
DdNode *one, *zero, *r, *lt, *le, *ut, *ue, *t, *e;
#if 0
DdNode *ar;
#endif
int comple = 0;
unsigned int topu, topl;
int index;
statLine(dd);
if (l == u) {
return(l);
}
one = DD_ONE(dd);
zero = Cudd_Not(one);
/* The only case when l == zero && u == one is at the top level,
** where returning either one or zero is OK. In all other cases
** the procedure will detect such a case and will perform
** remapping. Therefore the order in which we test l and u at this
** point is immaterial. */
if (l == zero) return(l);
if (u == one) return(u);
/* Make canonical to increase the utilization of the cache. */
if (Cudd_IsComplement(u)) {
DdNode *temp;
temp = Cudd_Not(l);
l = Cudd_Not(u);
u = temp;
comple = 1;
}
/* At this point u is regular and non-constant; l is non-constant, but
** may be complemented. */
/* Here we could check the relative sizes. */
/* Check the cache. */
r = cuddCacheLookup2(dd, Cudd_bddSqueeze, l, u);
if (r != NULL) {
return(Cudd_NotCond(r,comple));
}
/* Recursive step. */
topu = dd->perm[u->index];
topl = dd->perm[Cudd_Regular(l)->index];
if (topu <= topl) {
index = u->index;
ut = cuddT(u); ue = cuddE(u);
} else {
index = Cudd_Regular(l)->index;
ut = ue = u;
}
if (topl <= topu) {
lt = cuddT(Cudd_Regular(l)); le = cuddE(Cudd_Regular(l));
if (Cudd_IsComplement(l)) {
lt = Cudd_Not(lt);
le = Cudd_Not(le);
}
} else {
lt = le = l;
}
/* If one interval is contained in the other, use the smaller
** interval. This corresponds to one-sided matching. */
if ((lt == zero || Cudd_bddLeq(dd,lt,le)) &&
(ut == one || Cudd_bddLeq(dd,ue,ut))) { /* remap */
r = cuddBddSqueeze(dd, le, ue);
if (r == NULL)
return(NULL);
return(Cudd_NotCond(r,comple));
} else if ((le == zero || Cudd_bddLeq(dd,le,lt)) &&
(ue == one || Cudd_bddLeq(dd,ut,ue))) { /* remap */
r = cuddBddSqueeze(dd, lt, ut);
if (r == NULL)
return(NULL);
return(Cudd_NotCond(r,comple));
} else if ((le == zero || Cudd_bddLeq(dd,le,Cudd_Not(ut))) &&
(ue == one || Cudd_bddLeq(dd,Cudd_Not(lt),ue))) { /* c-remap */
t = cuddBddSqueeze(dd, lt, ut);
cuddRef(t);
if (Cudd_IsComplement(t)) {
r = cuddUniqueInter(dd, index, Cudd_Not(t), t);
if (r == NULL) {
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
r = Cudd_Not(r);
} else {
r = cuddUniqueInter(dd, index, t, Cudd_Not(t));
if (r == NULL) {
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
}
cuddDeref(t);
if (r == NULL)
return(NULL);
cuddCacheInsert2(dd, Cudd_bddSqueeze, l, u, r);
return(Cudd_NotCond(r,comple));
} else if ((lt == zero || Cudd_bddLeq(dd,lt,Cudd_Not(ue))) &&
(ut == one || Cudd_bddLeq(dd,Cudd_Not(le),ut))) { /* c-remap */
e = cuddBddSqueeze(dd, le, ue);
cuddRef(e);
if (Cudd_IsComplement(e)) {
r = cuddUniqueInter(dd, index, Cudd_Not(e), e);
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
return(NULL);
}
} else {
r = cuddUniqueInter(dd, index, e, Cudd_Not(e));
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
return(NULL);
}
r = Cudd_Not(r);
}
cuddDeref(e);
if (r == NULL)
return(NULL);
cuddCacheInsert2(dd, Cudd_bddSqueeze, l, u, r);
return(Cudd_NotCond(r,comple));
}
#if 0
/* If the two intervals intersect, take a solution from
** the intersection of the intervals. This guarantees that the
** splitting variable will not appear in the result.
** This approach corresponds to two-sided matching, and is very
** expensive. */
if (Cudd_bddLeq(dd,lt,ue) && Cudd_bddLeq(dd,le,ut)) {
DdNode *au, *al;
au = cuddBddAndRecur(dd,ut,ue);
if (au == NULL)
return(NULL);
cuddRef(au);
al = cuddBddAndRecur(dd,Cudd_Not(lt),Cudd_Not(le));
if (al == NULL) {
Cudd_IterDerefBdd(dd,au);
return(NULL);
}
cuddRef(al);
al = Cudd_Not(al);
ar = cuddBddSqueeze(dd, al, au);
if (ar == NULL) {
Cudd_IterDerefBdd(dd,au);
Cudd_IterDerefBdd(dd,al);
return(NULL);
}
cuddRef(ar);
Cudd_IterDerefBdd(dd,au);
Cudd_IterDerefBdd(dd,al);
} else {
ar = NULL;
}
#endif
t = cuddBddSqueeze(dd, lt, ut);
if (t == NULL) {
return(NULL);
}
cuddRef(t);
e = cuddBddSqueeze(dd, le, ue);
if (e == NULL) {
Cudd_IterDerefBdd(dd,t);
return(NULL);
}
cuddRef(e);
if (Cudd_IsComplement(t)) {
t = Cudd_Not(t);
e = Cudd_Not(e);
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
r = Cudd_Not(r);
} else {
r = (t == e) ? t : cuddUniqueInter(dd, index, t, e);
if (r == NULL) {
Cudd_IterDerefBdd(dd, e);
Cudd_IterDerefBdd(dd, t);
return(NULL);
}
}
cuddDeref(t);
cuddDeref(e);
#if 0
/* Check whether there is a result obtained by abstraction and whether
** it is better than the one obtained by recursion. */
cuddRef(r);
if (ar != NULL) {
if (Cudd_DagSize(ar) <= Cudd_DagSize(r)) {
Cudd_IterDerefBdd(dd, r);
r = ar;
} else {
Cudd_IterDerefBdd(dd, ar);
}
}
cuddDeref(r);
#endif
cuddCacheInsert2(dd, Cudd_bddSqueeze, l, u, r);
return(Cudd_NotCond(r,comple));
} /* end of cuddBddSqueeze */
ABC_NAMESPACE_IMPL_END
|