abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cuddEssent.c
Go to the documentation of this file.
1 /**CFile***********************************************************************
2 
3  FileName [cuddEssent.c]
4 
5  PackageName [cudd]
6 
7  Synopsis [Functions for the detection of essential variables.]
8 
9  Description [External procedures included in this file:
10  <ul>
11  <li> Cudd_FindEssential()
12  <li> Cudd_bddIsVarEssential()
13  <li> Cudd_FindTwoLiteralClauses()
14  <li> Cudd_ReadIthClause()
15  <li> Cudd_PrintTwoLiteralClauses()
16  <li> Cudd_tlcInfoFree()
17  </ul>
18  Static procedures included in this module:
19  <ul>
20  <li> ddFindEssentialRecur()
21  <li> ddFindTwoLiteralClausesRecur()
22  <li> computeClauses()
23  <li> computeClausesWithUniverse()
24  <li> emptyClauseSet()
25  <li> sentinelp()
26  <li> equalp()
27  <li> beforep()
28  <li> oneliteralp()
29  <li> impliedp()
30  <li> bitVectorAlloc()
31  <li> bitVectorClear()
32  <li> bitVectorFree()
33  <li> bitVectorRead()
34  <li> bitVectorSet()
35  <li> tlcInfoAlloc()
36  </ul>]
37 
38  Author [Fabio Somenzi]
39 
40  Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
41 
42  All rights reserved.
43 
44  Redistribution and use in source and binary forms, with or without
45  modification, are permitted provided that the following conditions
46  are met:
47 
48  Redistributions of source code must retain the above copyright
49  notice, this list of conditions and the following disclaimer.
50 
51  Redistributions in binary form must reproduce the above copyright
52  notice, this list of conditions and the following disclaimer in the
53  documentation and/or other materials provided with the distribution.
54 
55  Neither the name of the University of Colorado nor the names of its
56  contributors may be used to endorse or promote products derived from
57  this software without specific prior written permission.
58 
59  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
60  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
61  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
62  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
63  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
64  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
65  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
66  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
67  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
69  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
70  POSSIBILITY OF SUCH DAMAGE.]
71 
72 ******************************************************************************/
73 
74 #include "misc/util/util_hack.h"
75 #include "cuddInt.h"
76 
78 
79 
80 
81 /*---------------------------------------------------------------------------*/
82 /* Constant declarations */
83 /*---------------------------------------------------------------------------*/
84 
85 /* These definitions are for the bit vectors. */
86 #if SIZEOF_LONG == 8
87 #define BPL 64
88 #define LOGBPL 6
89 #else
90 #define BPL 32
91 #define LOGBPL 5
92 #endif
93 
94 /*---------------------------------------------------------------------------*/
95 /* Stucture declarations */
96 /*---------------------------------------------------------------------------*/
97 
98 /* This structure holds the set of clauses for a node. Each clause consists
99 ** of two literals. For one-literal clauses, the second lietral is FALSE.
100 ** Each literal is composed of a variable and a phase. A variable is a node
101 ** index, and requires sizeof(DdHalfWord) bytes. The constant literals use
102 ** CUDD_MAXINDEX as variable indicator. Each phase is a bit: 0 for positive
103 ** phase, and 1 for negative phase.
104 ** Variables and phases are stored separately for the sake of compactness.
105 ** The variables are stored in an array of DdHalfWord's terminated by a
106 ** sentinel (a pair of zeroes). The phases are stored in a bit vector.
107 ** The cnt field holds, at the end, the number of clauses.
108 ** The clauses of the set are kept sorted. For each clause, the first literal
109 ** is the one of least index. So, the clause with literals +2 and -4 is stored
110 ** as (+2,-4). A one-literal clause with literal +3 is stored as
111 ** (+3,-CUDD_MAXINDEX). Clauses are sorted in decreasing order as follows:
112 ** (+5,-7)
113 ** (+5,+6)
114 ** (-5,+7)
115 ** (-4,FALSE)
116 ** (-4,+8)
117 ** ...
118 ** That is, one first looks at the variable of the first literal, then at the
119 ** phase of the first litral, then at the variable of the second literal,
120 ** and finally at the phase of the second literal.
121 */
122 struct DdTlcInfo {
124  long *phases;
126 };
127 
128 /* This structure is for temporary representation of sets of clauses. It is
129 ** meant to be used in link lists, when the number of clauses is not yet
130 ** known. The encoding of a clause is the same as in DdTlcInfo, though
131 ** the phase information is not stored in a bit array. */
132 struct TlClause {
134  short p1, p2;
135  struct TlClause *next;
136 };
137 
138 /*---------------------------------------------------------------------------*/
139 /* Type declarations */
140 /*---------------------------------------------------------------------------*/
141 
142 typedef long BitVector;
143 typedef struct TlClause TlClause;
144 
145 /*---------------------------------------------------------------------------*/
146 /* Variable declarations */
147 /*---------------------------------------------------------------------------*/
148 
149 #ifndef lint
150 static char rcsid[] DD_UNUSED = "$Id: cuddEssent.c,v 1.24 2009/02/21 18:24:10 fabio Exp $";
151 #endif
152 
153 static BitVector *Tolv;
154 static BitVector *Tolp;
155 static BitVector *Eolv;
156 static BitVector *Eolp;
157 
158 /*---------------------------------------------------------------------------*/
159 /* Macro declarations */
160 /*---------------------------------------------------------------------------*/
161 
162 /**AutomaticStart*************************************************************/
163 
164 /*---------------------------------------------------------------------------*/
165 /* Static function prototypes */
166 /*---------------------------------------------------------------------------*/
167 
168 static DdNode * ddFindEssentialRecur (DdManager *dd, DdNode *f);
170 static DdTlcInfo * computeClauses (DdTlcInfo *Tres, DdTlcInfo *Eres, DdHalfWord label, int size);
171 static DdTlcInfo * computeClausesWithUniverse (DdTlcInfo *Cres, DdHalfWord label, short phase);
172 static DdTlcInfo * emptyClauseSet (void);
173 static int sentinelp (DdHalfWord var1, DdHalfWord var2);
174 static int equalp (DdHalfWord var1a, short phase1a, DdHalfWord var1b, short phase1b, DdHalfWord var2a, short phase2a, DdHalfWord var2b, short phase2b);
175 static int beforep (DdHalfWord var1a, short phase1a, DdHalfWord var1b, short phase1b, DdHalfWord var2a, short phase2a, DdHalfWord var2b, short phase2b);
176 static int oneliteralp (DdHalfWord var);
177 static int impliedp (DdHalfWord var1, short phase1, DdHalfWord var2, short phase2, BitVector *olv, BitVector *olp);
178 static BitVector * bitVectorAlloc (int size);
179 DD_INLINE static void bitVectorClear (BitVector *vector, int size);
180 static void bitVectorFree (BitVector *vector);
181 DD_INLINE static short bitVectorRead (BitVector *vector, int i);
182 DD_INLINE static void bitVectorSet (BitVector * vector, int i, short val);
183 static DdTlcInfo * tlcInfoAlloc (void);
184 
185 /**AutomaticEnd***************************************************************/
186 
187 
188 /*---------------------------------------------------------------------------*/
189 /* Definition of exported functions */
190 /*---------------------------------------------------------------------------*/
191 
192 
193 /**Function********************************************************************
194 
195  Synopsis [Finds the essential variables of a DD.]
196 
197  Description [Returns the cube of the essential variables. A positive
198  literal means that the variable must be set to 1 for the function to be
199  1. A negative literal means that the variable must be set to 0 for the
200  function to be 1. Returns a pointer to the cube BDD if successful;
201  NULL otherwise.]
202 
203  SideEffects [None]
204 
205  SeeAlso [Cudd_bddIsVarEssential]
206 
207 ******************************************************************************/
208 DdNode *
210  DdManager * dd,
211  DdNode * f)
212 {
213  DdNode *res;
214 
215  do {
216  dd->reordered = 0;
217  res = ddFindEssentialRecur(dd,f);
218  } while (dd->reordered == 1);
219  return(res);
220 
221 } /* end of Cudd_FindEssential */
222 
223 
224 /**Function********************************************************************
225 
226  Synopsis [Determines whether a given variable is essential with a
227  given phase in a BDD.]
228 
229  Description [Determines whether a given variable is essential with a
230  given phase in a BDD. Uses Cudd_bddIteConstant. Returns 1 if phase == 1
231  and f-->x_id, or if phase == 0 and f-->x_id'.]
232 
233  SideEffects [None]
234 
235  SeeAlso [Cudd_FindEssential]
236 
237 ******************************************************************************/
238 int
240  DdManager * manager,
241  DdNode * f,
242  int id,
243  int phase)
244 {
245  DdNode *var;
246  int res;
247 
248  var = Cudd_bddIthVar(manager, id);
249 
250  var = Cudd_NotCond(var,phase == 0);
251 
252  res = Cudd_bddLeq(manager, f, var);
253 
254  return(res);
255 
256 } /* end of Cudd_bddIsVarEssential */
257 
258 
259 /**Function********************************************************************
260 
261  Synopsis [Finds the two literal clauses of a DD.]
262 
263  Description [Returns the one- and two-literal clauses of a DD.
264  Returns a pointer to the structure holding the clauses if
265  successful; NULL otherwise. For a constant DD, the empty set of clauses
266  is returned. This is obviously correct for a non-zero constant. For the
267  constant zero, it is based on the assumption that only those clauses
268  containing variables in the support of the function are considered. Since
269  the support of a constant function is empty, no clauses are returned.]
270 
271  SideEffects [None]
272 
273  SeeAlso [Cudd_FindEssential]
274 
275 ******************************************************************************/
276 DdTlcInfo *
278  DdManager * dd,
279  DdNode * f)
280 {
281  DdTlcInfo *res;
282  st__table *table;
283  st__generator *gen;
284  DdTlcInfo *tlc;
285  DdNode *node;
286  int size = dd->size;
287 
288  if (Cudd_IsConstant(f)) {
289  res = emptyClauseSet();
290  return(res);
291  }
293  if (table == NULL) return(NULL);
294  Tolv = bitVectorAlloc(size);
295  if (Tolv == NULL) {
296  st__free_table(table);
297  return(NULL);
298  }
299  Tolp = bitVectorAlloc(size);
300  if (Tolp == NULL) {
301  st__free_table(table);
303  return(NULL);
304  }
305  Eolv = bitVectorAlloc(size);
306  if (Eolv == NULL) {
307  st__free_table(table);
310  return(NULL);
311  }
312  Eolp = bitVectorAlloc(size);
313  if (Eolp == NULL) {
314  st__free_table(table);
318  return(NULL);
319  }
320 
321  res = ddFindTwoLiteralClausesRecur(dd,f,table);
322  /* Dispose of table contents and free table. */
323  st__foreach_item(table, gen, (const char **)&node, (char **)&tlc) {
324  if (node != f) {
325  Cudd_tlcInfoFree(tlc);
326  }
327  }
328  st__free_table(table);
333 
334  if (res != NULL) {
335  int i;
336  for (i = 0; !sentinelp(res->vars[i], res->vars[i+1]); i += 2);
337  res->cnt = i >> 1;
338  }
339 
340  return(res);
341 
342 } /* end of Cudd_FindTwoLiteralClauses */
343 
344 
345 /**Function********************************************************************
346 
347  Synopsis [Accesses the i-th clause of a DD.]
348 
349  Description [Accesses the i-th clause of a DD given the clause set which
350  must be already computed. Returns 1 if successful; 0 if i is out of range,
351  or in case of error.]
352 
353  SideEffects [the four components of a clause are returned as side effects.]
354 
355  SeeAlso [Cudd_FindTwoLiteralClauses]
356 
357 ******************************************************************************/
358 int
360  DdTlcInfo * tlc,
361  int i,
362  DdHalfWord *var1,
363  DdHalfWord *var2,
364  int *phase1,
365  int *phase2)
366 {
367  if (tlc == NULL) return(0);
368  if (tlc->vars == NULL || tlc->phases == NULL) return(0);
369  if (i < 0 || (unsigned) i >= tlc->cnt) return(0);
370  *var1 = tlc->vars[2*i];
371  *var2 = tlc->vars[2*i+1];
372  *phase1 = (int) bitVectorRead(tlc->phases, 2*i);
373  *phase2 = (int) bitVectorRead(tlc->phases, 2*i+1);
374  return(1);
375 
376 } /* end of Cudd_ReadIthClause */
377 
378 
379 /**Function********************************************************************
380 
381  Synopsis [Prints the two literal clauses of a DD.]
382 
383  Description [Prints the one- and two-literal clauses. Returns 1 if
384  successful; 0 otherwise. The argument "names" can be NULL, in which case
385  the variable indices are printed.]
386 
387  SideEffects [None]
388 
389  SeeAlso [Cudd_FindTwoLiteralClauses]
390 
391 ******************************************************************************/
392 int
394  DdManager * dd,
395  DdNode * f,
396  char **names,
397  FILE *fp)
398 {
399  DdHalfWord *vars;
400  BitVector *phases;
401  int i;
403  FILE *ifp = fp == NULL ? dd->out : fp;
404 
405  if (res == NULL) return(0);
406  vars = res->vars;
407  phases = res->phases;
408  for (i = 0; !sentinelp(vars[i], vars[i+1]); i += 2) {
409  if (names != NULL) {
410  if (vars[i+1] == CUDD_MAXINDEX) {
411  (void) fprintf(ifp, "%s%s\n",
412  bitVectorRead(phases, i) ? "~" : " ",
413  names[vars[i]]);
414  } else {
415  (void) fprintf(ifp, "%s%s | %s%s\n",
416  bitVectorRead(phases, i) ? "~" : " ",
417  names[vars[i]],
418  bitVectorRead(phases, i+1) ? "~" : " ",
419  names[vars[i+1]]);
420  }
421  } else {
422  if (vars[i+1] == CUDD_MAXINDEX) {
423  (void) fprintf(ifp, "%s%d\n",
424  bitVectorRead(phases, i) ? "~" : " ",
425  (int) vars[i]);
426  } else {
427  (void) fprintf(ifp, "%s%d | %s%d\n",
428  bitVectorRead(phases, i) ? "~" : " ",
429  (int) vars[i],
430  bitVectorRead(phases, i+1) ? "~" : " ",
431  (int) vars[i+1]);
432  }
433  }
434  }
435  Cudd_tlcInfoFree(res);
436 
437  return(1);
438 
439 } /* end of Cudd_PrintTwoLiteralClauses */
440 
441 
442 /**Function********************************************************************
443 
444  Synopsis [Frees a DdTlcInfo Structure.]
445 
446  Description [Frees a DdTlcInfo Structure as well as the memory pointed
447  by it.]
448 
449  SideEffects [None]
450 
451  SeeAlso []
452 
453 ******************************************************************************/
454 void
456  DdTlcInfo * t)
457 {
458  if (t->vars != NULL) ABC_FREE(t->vars);
459  if (t->phases != NULL) ABC_FREE(t->phases);
460  ABC_FREE(t);
461 
462 } /* end of Cudd_tlcInfoFree */
463 
464 
465 /*---------------------------------------------------------------------------*/
466 /* Definition of internal functions */
467 /*---------------------------------------------------------------------------*/
468 
469 
470 /*---------------------------------------------------------------------------*/
471 /* Definition of static functions */
472 /*---------------------------------------------------------------------------*/
473 
474 
475 /**Function********************************************************************
476 
477  Synopsis [Implements the recursive step of Cudd_FindEssential.]
478 
479  Description [Implements the recursive step of Cudd_FindEssential.
480  Returns a pointer to the cube BDD if successful; NULL otherwise.]
481 
482  SideEffects [None]
483 
484 ******************************************************************************/
485 static DdNode *
487  DdManager * dd,
488  DdNode * f)
489 {
490  DdNode *T, *E, *F;
491  DdNode *essT, *essE, *res;
492  int index;
493  DdNode *one, *lzero, *azero;
494 
495  one = DD_ONE(dd);
496  F = Cudd_Regular(f);
497  /* If f is constant the set of essential variables is empty. */
498  if (cuddIsConstant(F)) return(one);
499 
501  if (res != NULL) {
502  return(res);
503  }
504 
505  lzero = Cudd_Not(one);
506  azero = DD_ZERO(dd);
507  /* Find cofactors: here f is non-constant. */
508  T = cuddT(F);
509  E = cuddE(F);
510  if (Cudd_IsComplement(f)) {
511  T = Cudd_Not(T); E = Cudd_Not(E);
512  }
513 
514  index = F->index;
515  if (Cudd_IsConstant(T) && T != lzero && T != azero) {
516  /* if E is zero, index is essential, otherwise there are no
517  ** essentials, because index is not essential and no other variable
518  ** can be, since setting index = 1 makes the function constant and
519  ** different from 0.
520  */
521  if (E == lzero || E == azero) {
522  res = dd->vars[index];
523  } else {
524  res = one;
525  }
526  } else if (T == lzero || T == azero) {
527  if (Cudd_IsConstant(E)) { /* E cannot be zero here */
528  res = Cudd_Not(dd->vars[index]);
529  } else { /* E == non-constant */
530  /* find essentials in the else branch */
531  essE = ddFindEssentialRecur(dd,E);
532  if (essE == NULL) {
533  return(NULL);
534  }
535  cuddRef(essE);
536 
537  /* add index to the set with negative phase */
538  res = cuddUniqueInter(dd,index,one,Cudd_Not(essE));
539  if (res == NULL) {
540  Cudd_RecursiveDeref(dd,essE);
541  return(NULL);
542  }
543  res = Cudd_Not(res);
544  cuddDeref(essE);
545  }
546  } else { /* T == non-const */
547  if (E == lzero || E == azero) {
548  /* find essentials in the then branch */
549  essT = ddFindEssentialRecur(dd,T);
550  if (essT == NULL) {
551  return(NULL);
552  }
553  cuddRef(essT);
554 
555  /* add index to the set with positive phase */
556  /* use And because essT may be complemented */
557  res = cuddBddAndRecur(dd,dd->vars[index],essT);
558  if (res == NULL) {
559  Cudd_RecursiveDeref(dd,essT);
560  return(NULL);
561  }
562  cuddDeref(essT);
563  } else if (!Cudd_IsConstant(E)) {
564  /* if E is a non-zero constant there are no essentials
565  ** because T is non-constant.
566  */
567  essT = ddFindEssentialRecur(dd,T);
568  if (essT == NULL) {
569  return(NULL);
570  }
571  if (essT == one) {
572  res = one;
573  } else {
574  cuddRef(essT);
575  essE = ddFindEssentialRecur(dd,E);
576  if (essE == NULL) {
577  Cudd_RecursiveDeref(dd,essT);
578  return(NULL);
579  }
580  cuddRef(essE);
581 
582  /* res = intersection(essT, essE) */
583  res = cuddBddLiteralSetIntersectionRecur(dd,essT,essE);
584  if (res == NULL) {
585  Cudd_RecursiveDeref(dd,essT);
586  Cudd_RecursiveDeref(dd,essE);
587  return(NULL);
588  }
589  cuddRef(res);
590  Cudd_RecursiveDeref(dd,essT);
591  Cudd_RecursiveDeref(dd,essE);
592  cuddDeref(res);
593  }
594  } else { /* E is a non-zero constant */
595  res = one;
596  }
597  }
598 
600  return(res);
601 
602 } /* end of ddFindEssentialRecur */
603 
604 
605 /**Function********************************************************************
606 
607  Synopsis [Implements the recursive step of Cudd_FindTwoLiteralClauses.]
608 
609  Description [Implements the recursive step of
610  Cudd_FindTwoLiteralClauses. The DD node is assumed to be not
611  constant. Returns a pointer to a set of clauses if successful; NULL
612  otherwise.]
613 
614  SideEffects [None]
615 
616  SeeAlso [Cudd_FindTwoLiteralClauses]
617 
618 ******************************************************************************/
619 static DdTlcInfo *
621  DdManager * dd,
622  DdNode * f,
623  st__table *table)
624 {
625  DdNode *T, *E, *F;
626  DdNode *one, *lzero, *azero;
627  DdTlcInfo *res, *Tres, *Eres;
628  DdHalfWord index;
629 
630  F = Cudd_Regular(f);
631 
632  assert(!cuddIsConstant(F));
633 
634  /* Check computed table. Separate entries are necessary for
635  ** a node and its complement. We should update the counter here. */
636  if ( st__lookup(table, (const char *)f, (char **)&res)) {
637  return(res);
638  }
639 
640  /* Easy access to the constants for BDDs and ADDs. */
641  one = DD_ONE(dd);
642  lzero = Cudd_Not(one);
643  azero = DD_ZERO(dd);
644 
645  /* Find cofactors and variable labeling the top node. */
646  T = cuddT(F); E = cuddE(F);
647  if (Cudd_IsComplement(f)) {
648  T = Cudd_Not(T); E = Cudd_Not(E);
649  }
650  index = F->index;
651 
652  if (Cudd_IsConstant(T) && T != lzero && T != azero) {
653  /* T is a non-zero constant. If E is zero, then this node's index
654  ** is a one-literal clause. Otherwise, if E is a non-zero
655  ** constant, there are no clauses for this node. Finally,
656  ** if E is not constant, we recursively compute its clauses, and then
657  ** merge using the empty set for T. */
658  if (E == lzero || E == azero) {
659  /* Create the clause (index + 0). */
660  res = tlcInfoAlloc();
661  if (res == NULL) return(NULL);
662  res->vars = ABC_ALLOC(DdHalfWord,4);
663  if (res->vars == NULL) {
664  ABC_FREE(res);
665  return(NULL);
666  }
667  res->phases = bitVectorAlloc(2);
668  if (res->phases == NULL) {
669  ABC_FREE(res->vars);
670  ABC_FREE(res);
671  return(NULL);
672  }
673  res->vars[0] = index;
674  res->vars[1] = CUDD_MAXINDEX;
675  res->vars[2] = 0;
676  res->vars[3] = 0;
677  bitVectorSet(res->phases, 0, 0); /* positive phase */
678  bitVectorSet(res->phases, 1, 1); /* negative phase */
679  } else if (Cudd_IsConstant(E)) {
680  /* If E is a non-zero constant, no clauses. */
681  res = emptyClauseSet();
682  } else {
683  /* E is non-constant */
684  Tres = emptyClauseSet();
685  if (Tres == NULL) return(NULL);
686  Eres = ddFindTwoLiteralClausesRecur(dd, E, table);
687  if (Eres == NULL) {
688  Cudd_tlcInfoFree(Tres);
689  return(NULL);
690  }
691  res = computeClauses(Tres, Eres, index, dd->size);
692  Cudd_tlcInfoFree(Tres);
693  }
694  } else if (T == lzero || T == azero) {
695  /* T is zero. If E is a non-zero constant, then the
696  ** complement of this node's index is a one-literal clause.
697  ** Otherwise, if E is not constant, we recursively compute its
698  ** clauses, and then merge using the universal set for T. */
699  if (Cudd_IsConstant(E)) { /* E cannot be zero here */
700  /* Create the clause (!index + 0). */
701  res = tlcInfoAlloc();
702  if (res == NULL) return(NULL);
703  res->vars = ABC_ALLOC(DdHalfWord,4);
704  if (res->vars == NULL) {
705  ABC_FREE(res);
706  return(NULL);
707  }
708  res->phases = bitVectorAlloc(2);
709  if (res->phases == NULL) {
710  ABC_FREE(res->vars);
711  ABC_FREE(res);
712  return(NULL);
713  }
714  res->vars[0] = index;
715  res->vars[1] = CUDD_MAXINDEX;
716  res->vars[2] = 0;
717  res->vars[3] = 0;
718  bitVectorSet(res->phases, 0, 1); /* negative phase */
719  bitVectorSet(res->phases, 1, 1); /* negative phase */
720  } else { /* E == non-constant */
721  Eres = ddFindTwoLiteralClausesRecur(dd, E, table);
722  if (Eres == NULL) return(NULL);
723  res = computeClausesWithUniverse(Eres, index, 1);
724  }
725  } else { /* T == non-const */
726  Tres = ddFindTwoLiteralClausesRecur(dd, T, table);
727  if (Tres == NULL) return(NULL);
728  if (Cudd_IsConstant(E)) {
729  if (E == lzero || E == azero) {
730  res = computeClausesWithUniverse(Tres, index, 0);
731  } else {
732  Eres = emptyClauseSet();
733  if (Eres == NULL) return(NULL);
734  res = computeClauses(Tres, Eres, index, dd->size);
735  Cudd_tlcInfoFree(Eres);
736  }
737  } else {
738  Eres = ddFindTwoLiteralClausesRecur(dd, E, table);
739  if (Eres == NULL) return(NULL);
740  res = computeClauses(Tres, Eres, index, dd->size);
741  }
742  }
743 
744  /* Cache results. */
745  if ( st__add_direct(table, (char *)f, (char *)res) == st__OUT_OF_MEM) {
746  ABC_FREE(res);
747  return(NULL);
748  }
749  return(res);
750 
751 } /* end of ddFindTwoLiteralClausesRecur */
752 
753 
754 /**Function********************************************************************
755 
756  Synopsis [Computes the two-literal clauses for a node.]
757 
758  Description [Computes the two-literal clauses for a node given the
759  clauses for its children and the label of the node. Returns a
760  pointer to a TclInfo structure if successful; NULL otherwise.]
761 
762  SideEffects [None]
763 
764  SeeAlso [computeClausesWithUniverse]
765 
766 ******************************************************************************/
767 static DdTlcInfo *
769  DdTlcInfo *Tres /* list of clauses for T child */,
770  DdTlcInfo *Eres /* list of clauses for E child */,
771  DdHalfWord label /* variable labeling the current node */,
772  int size /* number of variables in the manager */)
773 {
774  DdHalfWord *Tcv = Tres->vars; /* variables of clauses for the T child */
775  BitVector *Tcp = Tres->phases; /* phases of clauses for the T child */
776  DdHalfWord *Ecv = Eres->vars; /* variables of clauses for the E child */
777  BitVector *Ecp = Eres->phases; /* phases of clauses for the E child */
778  DdHalfWord *Vcv = NULL; /* pointer to variables of the clauses for v */
779  BitVector *Vcp = NULL; /* pointer to phases of the clauses for v */
780  DdTlcInfo *res = NULL; /* the set of clauses to be returned */
781  int pt = 0; /* index in the list of clauses of T */
782  int pe = 0; /* index in the list of clauses of E */
783  int cv = 0; /* counter of the clauses for this node */
784  TlClause *iclauses = NULL; /* list of inherited clauses */
785  TlClause *tclauses = NULL; /* list of 1-literal clauses of T */
786  TlClause *eclauses = NULL; /* list of 1-literal clauses of E */
787  TlClause *nclauses = NULL; /* list of new (non-inherited) clauses */
788  TlClause *lnclause = NULL; /* pointer to last new clause */
789  TlClause *newclause; /* temporary pointer to new clauses */
790 
791  /* Initialize sets of one-literal clauses. The one-literal clauses
792  ** are stored redundantly. These sets allow constant-time lookup, which
793  ** we need when we check for implication of a two-literal clause by a
794  ** one-literal clause. The linked lists allow fast sequential
795  ** processing. */
796  bitVectorClear(Tolv, size);
797  bitVectorClear(Tolp, size);
798  bitVectorClear(Eolv, size);
799  bitVectorClear(Eolp, size);
800 
801  /* Initialize result structure. */
802  res = tlcInfoAlloc();
803  if (res == NULL) goto cleanup;
804 
805  /* Scan the two input list. Extract inherited two-literal clauses
806  ** and set aside one-literal clauses from each list. The incoming lists
807  ** are sorted in the order defined by beforep. The three linked list
808  ** produced by this loop are sorted in the reverse order because we
809  ** always append to the front of the lists.
810  ** The inherited clauses are those clauses (both one- and two-literal)
811  ** that are common to both children; and the two-literal clauses of
812  ** one child that are implied by a one-literal clause of the other
813  ** child. */
814  while (!sentinelp(Tcv[pt], Tcv[pt+1]) || !sentinelp(Ecv[pe], Ecv[pe+1])) {
815  if (equalp(Tcv[pt], bitVectorRead(Tcp, pt),
816  Tcv[pt+1], bitVectorRead(Tcp, pt+1),
817  Ecv[pe], bitVectorRead(Ecp, pe),
818  Ecv[pe+1], bitVectorRead(Ecp, pe+1))) {
819  /* Add clause to inherited list. */
820  newclause = ABC_ALLOC(TlClause,1);
821  if (newclause == NULL) goto cleanup;
822  newclause->v1 = Tcv[pt];
823  newclause->v2 = Tcv[pt+1];
824  newclause->p1 = bitVectorRead(Tcp, pt);
825  newclause->p2 = bitVectorRead(Tcp, pt+1);
826  newclause->next = iclauses;
827  iclauses = newclause;
828  pt += 2; pe += 2; cv++;
829  } else if (beforep(Tcv[pt], bitVectorRead(Tcp, pt),
830  Tcv[pt+1], bitVectorRead(Tcp, pt+1),
831  Ecv[pe], bitVectorRead(Ecp, pe),
832  Ecv[pe+1], bitVectorRead(Ecp, pe+1))) {
833  if (oneliteralp(Tcv[pt+1])) {
834  /* Add this one-literal clause to the T set. */
835  newclause = ABC_ALLOC(TlClause,1);
836  if (newclause == NULL) goto cleanup;
837  newclause->v1 = Tcv[pt];
838  newclause->v2 = CUDD_MAXINDEX;
839  newclause->p1 = bitVectorRead(Tcp, pt);
840  newclause->p2 = 1;
841  newclause->next = tclauses;
842  tclauses = newclause;
843  bitVectorSet(Tolv, Tcv[pt], 1);
844  bitVectorSet(Tolp, Tcv[pt], bitVectorRead(Tcp, pt));
845  } else {
846  if (impliedp(Tcv[pt], bitVectorRead(Tcp, pt),
847  Tcv[pt+1], bitVectorRead(Tcp, pt+1),
848  Eolv, Eolp)) {
849  /* Add clause to inherited list. */
850  newclause = ABC_ALLOC(TlClause,1);
851  if (newclause == NULL) goto cleanup;
852  newclause->v1 = Tcv[pt];
853  newclause->v2 = Tcv[pt+1];
854  newclause->p1 = bitVectorRead(Tcp, pt);
855  newclause->p2 = bitVectorRead(Tcp, pt+1);
856  newclause->next = iclauses;
857  iclauses = newclause;
858  cv++;
859  }
860  }
861  pt += 2;
862  } else { /* !beforep() */
863  if (oneliteralp(Ecv[pe+1])) {
864  /* Add this one-literal clause to the E set. */
865  newclause = ABC_ALLOC(TlClause,1);
866  if (newclause == NULL) goto cleanup;
867  newclause->v1 = Ecv[pe];
868  newclause->v2 = CUDD_MAXINDEX;
869  newclause->p1 = bitVectorRead(Ecp, pe);
870  newclause->p2 = 1;
871  newclause->next = eclauses;
872  eclauses = newclause;
873  bitVectorSet(Eolv, Ecv[pe], 1);
874  bitVectorSet(Eolp, Ecv[pe], bitVectorRead(Ecp, pe));
875  } else {
876  if (impliedp(Ecv[pe], bitVectorRead(Ecp, pe),
877  Ecv[pe+1], bitVectorRead(Ecp, pe+1),
878  Tolv, Tolp)) {
879  /* Add clause to inherited list. */
880  newclause = ABC_ALLOC(TlClause,1);
881  if (newclause == NULL) goto cleanup;
882  newclause->v1 = Ecv[pe];
883  newclause->v2 = Ecv[pe+1];
884  newclause->p1 = bitVectorRead(Ecp, pe);
885  newclause->p2 = bitVectorRead(Ecp, pe+1);
886  newclause->next = iclauses;
887  iclauses = newclause;
888  cv++;
889  }
890  }
891  pe += 2;
892  }
893  }
894 
895  /* Add one-literal clauses for the label variable to the front of
896  ** the two lists. */
897  newclause = ABC_ALLOC(TlClause,1);
898  if (newclause == NULL) goto cleanup;
899  newclause->v1 = label;
900  newclause->v2 = CUDD_MAXINDEX;
901  newclause->p1 = 0;
902  newclause->p2 = 1;
903  newclause->next = tclauses;
904  tclauses = newclause;
905  newclause = ABC_ALLOC(TlClause,1);
906  if (newclause == NULL) goto cleanup;
907  newclause->v1 = label;
908  newclause->v2 = CUDD_MAXINDEX;
909  newclause->p1 = 1;
910  newclause->p2 = 1;
911  newclause->next = eclauses;
912  eclauses = newclause;
913 
914  /* Produce the non-inherited clauses. We preserve the "reverse"
915  ** order of the two input lists by appending to the end of the
916  ** list. In this way, iclauses and nclauses are consistent. */
917  while (tclauses != NULL && eclauses != NULL) {
918  if (beforep(eclauses->v1, eclauses->p1, eclauses->v2, eclauses->p2,
919  tclauses->v1, tclauses->p1, tclauses->v2, tclauses->p2)) {
920  TlClause *nextclause = tclauses->next;
921  TlClause *otherclauses = eclauses;
922  while (otherclauses != NULL) {
923  if (tclauses->v1 != otherclauses->v1) {
924  newclause = ABC_ALLOC(TlClause,1);
925  if (newclause == NULL) goto cleanup;
926  newclause->v1 = tclauses->v1;
927  newclause->v2 = otherclauses->v1;
928  newclause->p1 = tclauses->p1;
929  newclause->p2 = otherclauses->p1;
930  newclause->next = NULL;
931  if (nclauses == NULL) {
932  nclauses = newclause;
933  lnclause = newclause;
934  } else {
935  lnclause->next = newclause;
936  lnclause = newclause;
937  }
938  cv++;
939  }
940  otherclauses = otherclauses->next;
941  }
942  ABC_FREE(tclauses);
943  tclauses = nextclause;
944  } else {
945  TlClause *nextclause = eclauses->next;
946  TlClause *otherclauses = tclauses;
947  while (otherclauses != NULL) {
948  if (eclauses->v1 != otherclauses->v1) {
949  newclause = ABC_ALLOC(TlClause,1);
950  if (newclause == NULL) goto cleanup;
951  newclause->v1 = eclauses->v1;
952  newclause->v2 = otherclauses->v1;
953  newclause->p1 = eclauses->p1;
954  newclause->p2 = otherclauses->p1;
955  newclause->next = NULL;
956  if (nclauses == NULL) {
957  nclauses = newclause;
958  lnclause = newclause;
959  } else {
960  lnclause->next = newclause;
961  lnclause = newclause;
962  }
963  cv++;
964  }
965  otherclauses = otherclauses->next;
966  }
967  ABC_FREE(eclauses);
968  eclauses = nextclause;
969  }
970  }
971  while (tclauses != NULL) {
972  TlClause *nextclause = tclauses->next;
973  ABC_FREE(tclauses);
974  tclauses = nextclause;
975  }
976  while (eclauses != NULL) {
977  TlClause *nextclause = eclauses->next;
978  ABC_FREE(eclauses);
979  eclauses = nextclause;
980  }
981 
982  /* Merge inherited and non-inherited clauses. Now that we know the
983  ** total number, we allocate the arrays, and we fill them bottom-up
984  ** to restore the proper ordering. */
985  Vcv = ABC_ALLOC(DdHalfWord, 2*(cv+1));
986  if (Vcv == NULL) goto cleanup;
987  if (cv > 0) {
988  Vcp = bitVectorAlloc(2*cv);
989  if (Vcp == NULL) goto cleanup;
990  } else {
991  Vcp = NULL;
992  }
993  res->vars = Vcv;
994  res->phases = Vcp;
995  /* Add sentinel. */
996  Vcv[2*cv] = 0;
997  Vcv[2*cv+1] = 0;
998  while (iclauses != NULL || nclauses != NULL) {
999  TlClause *nextclause;
1000  cv--;
1001  if (nclauses == NULL || (iclauses != NULL &&
1002  beforep(nclauses->v1, nclauses->p1, nclauses->v2, nclauses->p2,
1003  iclauses->v1, iclauses->p1, iclauses->v2, iclauses->p2))) {
1004  Vcv[2*cv] = iclauses->v1;
1005  Vcv[2*cv+1] = iclauses->v2;
1006  bitVectorSet(Vcp, 2*cv, iclauses->p1);
1007  bitVectorSet(Vcp, 2*cv+1, iclauses->p2);
1008  nextclause = iclauses->next;
1009  ABC_FREE(iclauses);
1010  iclauses = nextclause;
1011  } else {
1012  Vcv[2*cv] = nclauses->v1;
1013  Vcv[2*cv+1] = nclauses->v2;
1014  bitVectorSet(Vcp, 2*cv, nclauses->p1);
1015  bitVectorSet(Vcp, 2*cv+1, nclauses->p2);
1016  nextclause = nclauses->next;
1017  ABC_FREE(nclauses);
1018  nclauses = nextclause;
1019  }
1020  }
1021  assert(cv == 0);
1022 
1023  return(res);
1024 
1025  cleanup:
1026  if (res != NULL) Cudd_tlcInfoFree(res);
1027  while (iclauses != NULL) {
1028  TlClause *nextclause = iclauses->next;
1029  ABC_FREE(iclauses);
1030  iclauses = nextclause;
1031  }
1032  while (nclauses != NULL) {
1033  TlClause *nextclause = nclauses->next;
1034  ABC_FREE(nclauses);
1035  nclauses = nextclause;
1036  }
1037  while (tclauses != NULL) {
1038  TlClause *nextclause = tclauses->next;
1039  ABC_FREE(tclauses);
1040  tclauses = nextclause;
1041  }
1042  while (eclauses != NULL) {
1043  TlClause *nextclause = eclauses->next;
1044  ABC_FREE(eclauses);
1045  eclauses = nextclause;
1046  }
1047 
1048  return(NULL);
1049 
1050 } /* end of computeClauses */
1051 
1052 
1053 /**Function********************************************************************
1054 
1055  Synopsis [Computes the two-literal clauses for a node.]
1056 
1057  Description [Computes the two-literal clauses for a node with a zero
1058  child, given the clauses for its other child and the label of the
1059  node. Returns a pointer to a TclInfo structure if successful; NULL
1060  otherwise.]
1061 
1062  SideEffects [None]
1063 
1064  SeeAlso [computeClauses]
1065 
1066 ******************************************************************************/
1067 static DdTlcInfo *
1069  DdTlcInfo *Cres /* list of clauses for child */,
1070  DdHalfWord label /* variable labeling the current node */,
1071  short phase /* 0 if E child is zero; 1 if T child is zero */)
1072 {
1073  DdHalfWord *Ccv = Cres->vars; /* variables of clauses for child */
1074  BitVector *Ccp = Cres->phases; /* phases of clauses for child */
1075  DdHalfWord *Vcv = NULL; /* pointer to the variables of the clauses for v */
1076  BitVector *Vcp = NULL; /* pointer to the phases of the clauses for v */
1077  DdTlcInfo *res = NULL; /* the set of clauses to be returned */
1078  int i;
1079 
1080  /* Initialize result. */
1081  res = tlcInfoAlloc();
1082  if (res == NULL) goto cleanup;
1083  /* Count entries for new list and allocate accordingly. */
1084  for (i = 0; !sentinelp(Ccv[i], Ccv[i+1]); i += 2);
1085  /* At this point, i is twice the number of clauses in the child's
1086  ** list. We need four more entries for this node: 2 for the one-literal
1087  ** clause for the label, and 2 for the sentinel. */
1088  Vcv = ABC_ALLOC(DdHalfWord,i+4);
1089  if (Vcv == NULL) goto cleanup;
1090  Vcp = bitVectorAlloc(i+4);
1091  if (Vcp == NULL) goto cleanup;
1092  res->vars = Vcv;
1093  res->phases = Vcp;
1094  /* Copy old list into new. */
1095  for (i = 0; !sentinelp(Ccv[i], Ccv[i+1]); i += 2) {
1096  Vcv[i] = Ccv[i];
1097  Vcv[i+1] = Ccv[i+1];
1098  bitVectorSet(Vcp, i, bitVectorRead(Ccp, i));
1099  bitVectorSet(Vcp, i+1, bitVectorRead(Ccp, i+1));
1100  }
1101  /* Add clause corresponding to label. */
1102  Vcv[i] = label;
1103  bitVectorSet(Vcp, i, phase);
1104  i++;
1105  Vcv[i] = CUDD_MAXINDEX;
1106  bitVectorSet(Vcp, i, 1);
1107  i++;
1108  /* Add sentinel. */
1109  Vcv[i] = 0;
1110  Vcv[i+1] = 0;
1111  bitVectorSet(Vcp, i, 0);
1112  bitVectorSet(Vcp, i+1, 0);
1113 
1114  return(res);
1115 
1116  cleanup:
1117  /* Vcp is guaranteed to be NULL here. Hence, we do not try to free it. */
1118  if (Vcv != NULL) ABC_FREE(Vcv);
1119  if (res != NULL) Cudd_tlcInfoFree(res);
1120 
1121  return(NULL);
1122 
1123 } /* end of computeClausesWithUniverse */
1124 
1125 
1126 /**Function********************************************************************
1127 
1128  Synopsis [Returns an enpty set of clauses.]
1129 
1130  Description [Returns a pointer to an empty set of clauses if
1131  successful; NULL otherwise. No bit vector for the phases is
1132  allocated.]
1133 
1134  SideEffects [None]
1135 
1136  SeeAlso []
1137 
1138 ******************************************************************************/
1139 static DdTlcInfo *
1141 {
1142  DdTlcInfo *eset;
1143 
1144  eset = ABC_ALLOC(DdTlcInfo,1);
1145  if (eset == NULL) return(NULL);
1146  eset->vars = ABC_ALLOC(DdHalfWord,2);
1147  if (eset->vars == NULL) {
1148  ABC_FREE(eset);
1149  return(NULL);
1150  }
1151  /* Sentinel */
1152  eset->vars[0] = 0;
1153  eset->vars[1] = 0;
1154  eset->phases = NULL; /* does not matter */
1155  eset->cnt = 0;
1156  return(eset);
1157 
1158 } /* end of emptyClauseSet */
1159 
1160 
1161 /**Function********************************************************************
1162 
1163  Synopsis [Returns true iff the argument is the sentinel clause.]
1164 
1165  Description [Returns true iff the argument is the sentinel clause.
1166  A sentinel clause has both variables equal to 0.]
1167 
1168  SideEffects [None]
1169 
1170  SeeAlso []
1171 
1172 ******************************************************************************/
1173 static int
1175  DdHalfWord var1,
1176  DdHalfWord var2)
1177 {
1178  return(var1 == 0 && var2 == 0);
1179 
1180 } /* end of sentinelp */
1181 
1182 
1183 /**Function********************************************************************
1184 
1185  Synopsis [Returns true iff the two arguments are identical clauses.]
1186 
1187  Description [Returns true iff the two arguments are identical
1188  clauses. Since literals are sorted, we only need to compare
1189  literals in the same position.]
1190 
1191  SideEffects [None]
1192 
1193  SeeAlso [beforep]
1194 
1195 ******************************************************************************/
1196 static int
1198  DdHalfWord var1a,
1199  short phase1a,
1200  DdHalfWord var1b,
1201  short phase1b,
1202  DdHalfWord var2a,
1203  short phase2a,
1204  DdHalfWord var2b,
1205  short phase2b)
1206 {
1207  return(var1a == var2a && phase1a == phase2a &&
1208  var1b == var2b && phase1b == phase2b);
1209 
1210 } /* end of equalp */
1211 
1212 
1213 /**Function********************************************************************
1214 
1215  Synopsis [Returns true iff the first argument precedes the second in
1216  the clause order.]
1217 
1218  Description [Returns true iff the first argument precedes the second
1219  in the clause order. A clause precedes another if its first lieral
1220  precedes the first literal of the other, or if the first literals
1221  are the same, and its second literal precedes the second literal of
1222  the other clause. A literal precedes another if it has a higher
1223  index, of if it has the same index, but it has lower phase. Phase 0
1224  is the positive phase, and it is lower than Phase 1 (negative
1225  phase).]
1226 
1227  SideEffects [None]
1228 
1229  SeeAlso [equalp]
1230 
1231 ******************************************************************************/
1232 static int
1234  DdHalfWord var1a,
1235  short phase1a,
1236  DdHalfWord var1b,
1237  short phase1b,
1238  DdHalfWord var2a,
1239  short phase2a,
1240  DdHalfWord var2b,
1241  short phase2b)
1242 {
1243  return(var1a > var2a || (var1a == var2a &&
1244  (phase1a < phase2a || (phase1a == phase2a &&
1245  (var1b > var2b || (var1b == var2b && phase1b < phase2b))))));
1246 
1247 } /* end of beforep */
1248 
1249 
1250 /**Function********************************************************************
1251 
1252  Synopsis [Returns true iff the argument is a one-literal clause.]
1253 
1254  Description [Returns true iff the argument is a one-literal clause.
1255  A one-litaral clause has the constant FALSE as second literal.
1256  Since the constant TRUE is never used, it is sufficient to test for
1257  a constant.]
1258 
1259  SideEffects [None]
1260 
1261  SeeAlso []
1262 
1263 ******************************************************************************/
1264 static int
1266  DdHalfWord var)
1267 {
1268  return(var == CUDD_MAXINDEX);
1269 
1270 } /* end of oneliteralp */
1271 
1272 
1273 /**Function********************************************************************
1274 
1275  Synopsis [Returns true iff either literal of a clause is in a set of
1276  literals.]
1277 
1278  Description [Returns true iff either literal of a clause is in a set
1279  of literals. The first four arguments specify the clause. The
1280  remaining two arguments specify the literal set.]
1281 
1282  SideEffects [None]
1283 
1284  SeeAlso []
1285 
1286 ******************************************************************************/
1287 static int
1289  DdHalfWord var1,
1290  short phase1,
1291  DdHalfWord var2,
1292  short phase2,
1293  BitVector *olv,
1294  BitVector *olp)
1295 {
1296  return((bitVectorRead(olv, var1) &&
1297  bitVectorRead(olp, var1) == phase1) ||
1298  (bitVectorRead(olv, var2) &&
1299  bitVectorRead(olp, var2) == phase2));
1300 
1301 } /* end of impliedp */
1302 
1303 
1304 /**Function********************************************************************
1305 
1306  Synopsis [Allocates a bit vector.]
1307 
1308  Description [Allocates a bit vector. The parameter size gives the
1309  number of bits. This procedure allocates enough long's to hold the
1310  specified number of bits. Returns a pointer to the allocated vector
1311  if successful; NULL otherwise.]
1312 
1313  SideEffects [None]
1314 
1315  SeeAlso [bitVectorClear bitVectorFree]
1316 
1317 ******************************************************************************/
1318 static BitVector *
1320  int size)
1321 {
1322  int allocSize;
1323  BitVector *vector;
1324 
1325  /* Find out how many long's we need.
1326  ** There are sizeof(long) * 8 bits in a long.
1327  ** The ceiling of the ratio of two integers m and n is given
1328  ** by ((n-1)/m)+1. Putting all this together, we get... */
1329  allocSize = ((size - 1) / (sizeof(BitVector) * 8)) + 1;
1330  vector = ABC_ALLOC(BitVector, allocSize);
1331  if (vector == NULL) return(NULL);
1332  /* Clear the whole array. */
1333  (void) memset(vector, 0, allocSize * sizeof(BitVector));
1334  return(vector);
1335 
1336 } /* end of bitVectorAlloc */
1337 
1338 
1339 /**Function********************************************************************
1340 
1341  Synopsis [Clears a bit vector.]
1342 
1343  Description [Clears a bit vector. The parameter size gives the
1344  number of bits.]
1345 
1346  SideEffects [None]
1347 
1348  SeeAlso [bitVectorAlloc]
1349 
1350 ******************************************************************************/
1351 DD_INLINE
1352 static void
1354  BitVector *vector,
1355  int size)
1356 {
1357  int allocSize;
1358 
1359  /* Find out how many long's we need.
1360  ** There are sizeof(long) * 8 bits in a long.
1361  ** The ceiling of the ratio of two integers m and n is given
1362  ** by ((n-1)/m)+1. Putting all this together, we get... */
1363  allocSize = ((size - 1) / (sizeof(BitVector) * 8)) + 1;
1364  /* Clear the whole array. */
1365  (void) memset(vector, 0, allocSize * sizeof(BitVector));
1366  return;
1367 
1368 } /* end of bitVectorClear */
1369 
1370 
1371 /**Function********************************************************************
1372 
1373  Synopsis [Frees a bit vector.]
1374 
1375  Description [Frees a bit vector.]
1376 
1377  SideEffects [None]
1378 
1379  SeeAlso [bitVectorAlloc]
1380 
1381 ******************************************************************************/
1382 static void
1384  BitVector *vector)
1385 {
1386  ABC_FREE(vector);
1387 
1388 } /* end of bitVectorFree */
1389 
1390 
1391 /**Function********************************************************************
1392 
1393  Synopsis [Returns the i-th entry of a bit vector.]
1394 
1395  Description [Returns the i-th entry of a bit vector.]
1396 
1397  SideEffects [None]
1398 
1399  SeeAlso [bitVectorSet]
1400 
1401 ******************************************************************************/
1402 DD_INLINE
1403 static short
1405  BitVector *vector,
1406  int i)
1407 {
1408  int word, bit;
1409  short result;
1410 
1411  if (vector == NULL) return((short) 0);
1412 
1413  word = i >> LOGBPL;
1414  bit = i & (BPL - 1);
1415  result = (short) ((vector[word] >> bit) & 1L);
1416  return(result);
1417 
1418 } /* end of bitVectorRead */
1419 
1420 
1421 /**Function********************************************************************
1422 
1423  Synopsis [Sets the i-th entry of a bit vector to a value.]
1424 
1425  Description [Sets the i-th entry of a bit vector to a value.]
1426 
1427  SideEffects [None]
1428 
1429  SeeAlso [bitVectorRead]
1430 
1431 ******************************************************************************/
1432 DD_INLINE
1433 static void
1435  BitVector * vector,
1436  int i,
1437  short val)
1438 {
1439  int word, bit;
1440 
1441  word = i >> LOGBPL;
1442  bit = i & (BPL - 1);
1443  vector[word] &= ~(1L << bit);
1444  vector[word] |= (((long) val) << bit);
1445 
1446 } /* end of bitVectorSet */
1447 
1448 
1449 /**Function********************************************************************
1450 
1451  Synopsis [Allocates a DdTlcInfo Structure.]
1452 
1453  Description [Returns a pointer to a DdTlcInfo Structure if successful;
1454  NULL otherwise.]
1455 
1456  SideEffects [None]
1457 
1458  SeeAlso [Cudd_tlcInfoFree]
1459 
1460 ******************************************************************************/
1461 static DdTlcInfo *
1463 {
1464  DdTlcInfo *res = ABC_ALLOC(DdTlcInfo,1);
1465  if (res == NULL) return(NULL);
1466  res->vars = NULL;
1467  res->phases = NULL;
1468  res->cnt = 0;
1469  return(res);
1470 
1471 } /* end of tlcInfoAlloc */
1472 
1473 
1475 
static DdTlcInfo * computeClausesWithUniverse(DdTlcInfo *Cres, DdHalfWord label, short phase)
Definition: cuddEssent.c:1068
char * memset()
short p2
Definition: cuddEssent.c:134
void st__free_table(st__table *table)
Definition: st.c:81
#define cuddRef(n)
Definition: cuddInt.h:584
static const int var1
Definition: satSolver.c:77
unsigned short DdHalfWord
Definition: cudd.h:262
#define cuddDeref(n)
Definition: cuddInt.h:604
int Cudd_bddIsVarEssential(DdManager *manager, DdNode *f, int id, int phase)
Definition: cuddEssent.c:239
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
#define LOGBPL
Definition: cuddEssent.c:91
DdHalfWord v2
Definition: cuddEssent.c:133
int size
Definition: cuddInt.h:361
int var(Lit p)
Definition: SolverTypes.h:62
#define Cudd_IsConstant(node)
Definition: cudd.h:352
static DD_INLINE void bitVectorSet(BitVector *vector, int i, short val)
Definition: cuddEssent.c:1434
#define Cudd_Regular(node)
Definition: cudd.h:397
static char rcsid[] DD_UNUSED
Definition: cuddEssent.c:150
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
DdHalfWord v1
Definition: cuddEssent.c:133
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
DdHalfWord * vars
Definition: cuddEssent.c:123
static DdTlcInfo * tlcInfoAlloc(void)
Definition: cuddEssent.c:1462
static int impliedp(DdHalfWord var1, short phase1, DdHalfWord var2, short phase2, BitVector *olv, BitVector *olp)
Definition: cuddEssent.c:1288
DdTlcInfo * Cudd_FindTwoLiteralClauses(DdManager *dd, DdNode *f)
Definition: cuddEssent.c:277
short p1
Definition: cuddEssent.c:134
#define DD_INLINE
Definition: cuddInt.h:90
int Cudd_ReadIthClause(DdTlcInfo *tlc, int i, DdHalfWord *var1, DdHalfWord *var2, int *phase1, int *phase2)
Definition: cuddEssent.c:359
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
int reordered
Definition: cuddInt.h:409
static BitVector * Eolv
Definition: cuddEssent.c:155
static DdNode * ddFindEssentialRecur(DdManager *dd, DdNode *f)
Definition: cuddEssent.c:486
long * phases
Definition: cuddEssent.c:124
#define Cudd_IsComplement(node)
Definition: cudd.h:425
DdNode * cuddBddLiteralSetIntersectionRecur(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddLiteral.c:153
DdNode * cuddCacheLookup1(DdManager *table, DD_CTFP1 op, DdNode *f)
Definition: cuddCache.c:556
static BitVector * Tolp
Definition: cuddEssent.c:154
static DdNode * one
Definition: cuddDecomp.c:112
FILE * out
Definition: cuddInt.h:441
Definition: st.h:52
static DdTlcInfo * emptyClauseSet(void)
Definition: cuddEssent.c:1140
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static BitVector * Tolv
Definition: cuddEssent.c:153
#define cuddIsConstant(node)
Definition: cuddInt.h:620
static int beforep(DdHalfWord var1a, short phase1a, DdHalfWord var1b, short phase1b, DdHalfWord var2a, short phase2a, DdHalfWord var2b, short phase2b)
Definition: cuddEssent.c:1233
static int size
Definition: cuddSign.c:86
static DdTlcInfo * ddFindTwoLiteralClausesRecur(DdManager *dd, DdNode *f, st__table *table)
Definition: cuddEssent.c:620
#define BPL
Definition: cuddEssent.c:90
#define cuddT(node)
Definition: cuddInt.h:636
#define st__OUT_OF_MEM
Definition: st.h:113
void Cudd_tlcInfoFree(DdTlcInfo *t)
Definition: cuddEssent.c:455
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static pcube phase
Definition: cvrm.c:405
int Cudd_bddLeq(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:536
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
static void bitVectorFree(BitVector *vector)
Definition: cuddEssent.c:1383
DdHalfWord index
Definition: cudd.h:279
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdNode ** vars
Definition: cuddInt.h:390
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
Definition: cuddAPI.c:416
DdHalfWord cnt
Definition: cuddEssent.c:125
struct TlClause * next
Definition: cuddEssent.c:135
static int sentinelp(DdHalfWord var1, DdHalfWord var2)
Definition: cuddEssent.c:1174
static DD_INLINE void bitVectorClear(BitVector *vector, int size)
Definition: cuddEssent.c:1353
#define CUDD_MAXINDEX
Definition: cudd.h:112
#define cuddE(node)
Definition: cuddInt.h:652
int st__add_direct(st__table *table, char *key, char *value)
Definition: st.c:205
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
#define st__foreach_item(table, gen, key, value)
Definition: st.h:107
long BitVector
Definition: cuddEssent.c:142
#define assert(ex)
Definition: util_old.h:213
static int result
Definition: cuddGenetic.c:125
static BitVector * Eolp
Definition: cuddEssent.c:156
DdNode * Cudd_FindEssential(DdManager *dd, DdNode *f)
Definition: cuddEssent.c:209
static int equalp(DdHalfWord var1a, short phase1a, DdHalfWord var1b, short phase1b, DdHalfWord var2a, short phase2a, DdHalfWord var2b, short phase2b)
Definition: cuddEssent.c:1197
#define DD_ONE(dd)
Definition: cuddInt.h:911
static DD_INLINE short bitVectorRead(BitVector *vector, int i)
Definition: cuddEssent.c:1404
DdNode * cuddBddAndRecur(DdManager *manager, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:886
static DdTlcInfo * computeClauses(DdTlcInfo *Tres, DdTlcInfo *Eres, DdHalfWord label, int size)
Definition: cuddEssent.c:768
static BitVector * bitVectorAlloc(int size)
Definition: cuddEssent.c:1319
int st__ptrhash(const char *, int)
Definition: st.c:468
DdNode * cuddUniqueInter(DdManager *unique, int index, DdNode *T, DdNode *E)
Definition: cuddTable.c:1128
int Cudd_PrintTwoLiteralClauses(DdManager *dd, DdNode *f, char **names, FILE *fp)
Definition: cuddEssent.c:393
void cuddCacheInsert1(DdManager *table, DD_CTFP1 op, DdNode *f, DdNode *data)
Definition: cuddCache.c:323
static int oneliteralp(DdHalfWord var)
Definition: cuddEssent.c:1265
#define DD_ZERO(dd)
Definition: cuddInt.h:927