ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ifthenelse.c File Reference
#include "ifthenelse.h"
#include "eliminate.h"
#include "gates.h"
#include "inline.h"
Include dependency graph for ifthenelse.c:

Go to the source code of this file.

Functions

bool kissat_find_if_then_else_gate (kissat *solver, unsigned lit, unsigned negative)
 

Function Documentation

◆ kissat_find_if_then_else_gate()

bool kissat_find_if_then_else_gate ( kissat * solver,
unsigned lit,
unsigned negative )

Definition at line 97 of file ifthenelse.c.

98 {
99 if (!GET_OPTION (ifthenelse))
100 return false;
102 const watch *const begin = BEGIN_WATCHES (*watches);
103 const watch *const end = END_WATCHES (*watches);
104 if (begin == end)
105 return false;
106 uint64_t large_clauses = 0;
107 for (const watch *p = begin; p != end; p++)
108 if (!p->type.binary)
109 large_clauses++;
110 const uint64_t limit = GET_OPTION (eliminateocclim);
111 if (large_clauses * large_clauses > limit)
112 return false;
113 const watch *const last = end - 1;
114 uint64_t steps = 0;
115 for (const watch *p1 = begin; steps < limit && p1 != last; p1++) {
116 watch w1 = *p1;
117 if (w1.type.binary)
118 continue;
119 unsigned a1, b1, c1;
120 if (!get_ternary_clause (solver, p1->large.ref, &a1, &b1, &c1))
121 continue;
122 if (b1 == lit)
123 SWAP (unsigned, a1, b1);
124 if (c1 == lit)
125 SWAP (unsigned, a1, c1);
126 KISSAT_assert (a1 == lit);
127 for (const watch *p2 = p1 + 1; steps < limit && p2 != end; p2++) {
128 watch w2 = *p2;
129 if (w2.type.binary)
130 continue;
131 unsigned a2, b2, c2;
132 if (!get_ternary_clause (solver, p2->large.ref, &a2, &b2, &c2))
133 continue;
134 if (b2 == lit)
135 SWAP (unsigned, a2, b2);
136 if (c2 == lit)
137 SWAP (unsigned, a2, c2);
138 KISSAT_assert (a2 == lit);
139 if (STRIP (b1) == STRIP (c2))
140 SWAP (unsigned, b2, c2);
141 if (STRIP (c1) == STRIP (c2))
142 continue;
143 const unsigned not_b2 = NOT (b2);
144 if (b1 != not_b2)
145 continue;
146 solver->resolve_gate = false;
147 const unsigned not_lit = NOT (lit);
148 const unsigned not_c1 = NOT (c1);
149 const watch *const p3 =
150 find_ternary_clause (solver, &steps, not_lit, b1, not_c1);
151 if (!p3)
152 continue;
153 const unsigned not_c2 = NOT (c2);
154 const watch *const p4 =
155 find_ternary_clause (solver, &steps, not_lit, b2, not_c2);
156 if (!p4)
157 continue;
158 watch w3 = p3 < p4 ? *p3 : *p4;
159 watch w4 = p3 < p4 ? *p4 : *p3;
160 LOGWATCH (lit, w1, "1st if-then-else");
161 LOGWATCH (lit, w2, "2nd if-then-else");
162 LOGWATCH (not_lit, w3, "3rd if-then-else");
163 LOGWATCH (not_lit, w4, "4th if-then-else");
164 LOG ("found if-then-else gate %s = (%s ? %s : %s)", LOGLIT (lit),
165 LOGLIT (NOT (b1)), LOGLIT (not_c1), LOGLIT (not_c2));
166 solver->gate_eliminated = GATE_ELIMINATED (if_then_else);
167 PUSH_STACK (solver->gates[negative], w1);
168 PUSH_STACK (solver->gates[negative], w2);
169 PUSH_STACK (solver->gates[!negative], w3);
170 PUSH_STACK (solver->gates[!negative], w4);
171 INC (if_then_else_extracted);
172 return true;
173 }
174 }
175 return false;
176}
#define b1
Definition bbrImage.c:97
#define PUSH_STACK(S, E)
Definition stack.h:39
#define INC(NAME)
#define LOG(...)
Cube * p
Definition exorList.c:222
#define a1
Definition extraBdd.h:80
#define GATE_ELIMINATED(...)
Definition gates.h:20
#define KISSAT_assert(ignore)
Definition global.h:13
#define solver
Definition kitten.c:211
#define LOGWATCH(...)
Definition logging.h:454
#define LOGLIT(...)
Definition logging.hpp:99
#define GET_OPTION(N)
Definition options.h:295
int lit
Definition satVec.h:130
#define NOT(LIT)
Definition literal.h:33
#define STRIP(LIT)
Definition literal.h:37
Definition watch.h:41
watch_type type
Definition watch.h:42
#define SWAP(TYPE, A, B)
Definition utilities.h:151
#define BEGIN_WATCHES(WS)
Definition watch.h:115
#define END_WATCHES(WS)
Definition watch.h:118
vector watches
Definition watch.h:49
#define WATCHES(LIT)
Definition watch.h:137
Here is the caller graph for this function: