ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
watch.c
Go to the documentation of this file.
1#define INLINE_SORT
2
3#include "inline.h"
4#include "sort.c"
5
7
9 unsigned lit) {
10 watch *const begin = BEGIN_WATCHES (*watches);
11 watch *const end = END_WATCHES (*watches);
12 watch *q = begin;
13 watch const *p = q;
14#ifndef KISSAT_NDEBUG
15 bool found = false;
16#endif
17 while (p != end) {
18 const watch watch = *q++ = *p++;
19 if (!watch.type.binary) {
20 *q++ = *p++;
21 continue;
22 }
23 const unsigned other = watch.binary.lit;
24 if (other != lit)
25 continue;
26#ifndef KISSAT_NDEBUG
27 KISSAT_assert (!found);
28 found = true;
29#endif
30 q--;
31 }
32 KISSAT_assert (found);
33#ifdef KISSAT_COMPACT
34 watches->size -= 1;
35#else
36 KISSAT_assert (begin + 1 <= end);
37 watches->end -= 1;
38#endif
39 const watch empty = {.raw = INVALID_VECTOR_ELEMENT};
40 end[-1] = empty;
41 KISSAT_assert (solver->vectors.usable < MAX_SECTOR - 1);
42 solver->vectors.usable += 1;
44}
45
47 reference ref) {
48 KISSAT_assert (solver->watching);
49 watch *const begin = BEGIN_WATCHES (*watches);
50 watch *const end = END_WATCHES (*watches);
51 watch *q = begin;
52 watch const *p = q;
53#ifndef KISSAT_NDEBUG
54 bool found = false;
55#endif
56 while (p != end) {
57 const watch head = *q++ = *p++;
58 if (head.type.binary)
59 continue;
60 const watch tail = *q++ = *p++;
61 if (tail.raw != ref)
62 continue;
63#ifndef KISSAT_NDEBUG
64 KISSAT_assert (!found);
65 found = true;
66#endif
67 q -= 2;
68 }
69 KISSAT_assert (found);
70#ifdef KISSAT_COMPACT
71 watches->size -= 2;
72#else
73 KISSAT_assert (begin + 2 <= end);
74 watches->end -= 2;
75#endif
76 const watch empty = {.raw = INVALID_VECTOR_ELEMENT};
77 end[-2] = end[-1] = empty;
78 KISSAT_assert (solver->vectors.usable < MAX_SECTOR - 2);
79 solver->vectors.usable += 2;
81}
82
84 watch src, watch dst) {
85 KISSAT_assert (!solver->watching);
86 watch *const begin = BEGIN_WATCHES (*watches);
87 const watch *const end = END_WATCHES (*watches);
88#ifndef KISSAT_NDEBUG
89 bool found = false;
90#endif
91 for (watch *p = begin; p != end; p++) {
92 const watch head = *p;
93 if (head.raw != src.raw)
94 continue;
95#ifndef KISSAT_NDEBUG
96 found = true;
97#endif
98 *p = dst;
99 break;
100 }
101 KISSAT_assert (found);
102}
103
105 KISSAT_assert (!solver->watching);
106 LOG ("flush all connected binaries and clauses");
107 watches *all_watches = solver->watches;
108 for (all_literals (lit))
109 RELEASE_WATCHES (all_watches[lit]);
110}
111
113 KISSAT_assert (solver->watching);
114 LOG ("flush large clause watches");
115 watches *all_watches = solver->watches;
116 signed char *marks = solver->marks;
117 for (all_literals (lit)) {
118 watches *lit_watches = all_watches + lit;
119 watch *begin = BEGIN_WATCHES (*lit_watches), *q = begin;
120 const watch *const end = END_WATCHES (*lit_watches), *p = q;
121 while (p != end) {
122 const watch watch = *q++ = *p++;
123 if (!watch.type.binary)
124 p++, q--;
125 else {
126 const unsigned other = watch.binary.lit;
127 if (marks[other]) {
128 if (lit < other) {
129 LOGBINARY (lit, other, "flushing duplicated");
131 }
132 q--;
133 } else
134 marks[other] = 1;
135 }
136 }
137 SET_END_OF_WATCHES (*lit_watches, q);
138 for (p = begin; p != q; p++) {
139 KISSAT_assert (p->type.binary);
140 marks[p->binary.lit] = 0;
141 }
142 }
143}
144
146 LOG ("watching all large clauses");
147 KISSAT_assert (solver->watching);
148
149 const value *const values = solver->values;
150 const assigned *const assigned = solver->assigned;
151 watches *watches = solver->watches;
152 ward *const arena = BEGIN_STACK (solver->arena);
153
154 for (all_clauses (c)) {
155 if (c->garbage)
156 continue;
157
158 unsigned *lits = c->lits;
159 kissat_sort_literals (solver, values, assigned, c->size, lits);
160 c->searched = 2;
161
162 const reference ref = (ward *) c - arena;
163 const unsigned l0 = lits[0];
164 const unsigned l1 = lits[1];
165
166 kissat_push_blocking_watch (solver, watches + l0, l1, ref);
167 kissat_push_blocking_watch (solver, watches + l1, l0, ref);
168 }
169}
170
172 KISSAT_assert (!solver->watching);
173 LOG ("connecting all large irredundant clauses");
174
175 clause *last_irredundant = kissat_last_irredundant_clause (solver);
176
177 const value *const values = solver->values;
178 watches *all_watches = solver->watches;
179 ward *const arena = BEGIN_STACK (solver->arena);
180
181 for (all_clauses (c)) {
182 if (last_irredundant && c > last_irredundant)
183 break;
184 if (c->redundant)
185 continue;
186 if (c->garbage)
187 continue;
188 bool satisfied = false;
189 KISSAT_assert (!solver->level);
190 for (all_literals_in_clause (lit, c)) {
191 const value value = values[lit];
192 if (value <= 0)
193 continue;
194 satisfied = true;
195 break;
196 }
197 if (satisfied) {
199 continue;
200 }
201 const reference ref = (ward *) c - arena;
202 kissat_inlined_connect_clause (solver, all_watches, c, ref);
203 }
204}
205
207 KISSAT_assert (!solver->watching);
208 LOG ("flushing large connected clause references");
209 size_t flushed = 0;
210 for (all_literals (lit)) {
212 watch *begin = BEGIN_WATCHES (*watches), *q = begin;
213 const watch *const end_watches = END_WATCHES (*watches), *p = q;
214 while (p != end_watches) {
215 const watch head = *p++;
216 if (head.type.binary)
217 *q++ = head;
218 else
219 flushed++;
220 }
222 }
223 LOG ("flushed %zu large clause references", flushed);
224 (void) flushed;
225}
226
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_HEADER_START typedef word ward
Definition arena.h:12
#define BEGIN_STACK(S)
Definition stack.h:46
#define LOG(...)
ABC_NAMESPACE_IMPL_START typedef signed char value
void kissat_mark_clause_as_garbage(kissat *solver, clause *c)
Definition clause.c:164
void kissat_delete_binary(kissat *solver, unsigned a, unsigned b)
Definition clause.c:181
Cube * p
Definition exorList.c:222
#define all_literals(LIT)
Definition internal.h:274
#define all_clauses(C)
Definition internal.h:279
void kissat_sort_literals(struct kissat *, unsigned size, unsigned *lits)
Definition sort.c:85
#define all_literals_in_clause(LIT, C)
Definition clause.h:47
#define KISSAT_assert(ignore)
Definition global.h:13
#define solver
Definition kitten.c:211
#define LOGBINARY(...)
Definition logging.h:442
ABC_NAMESPACE_HEADER_START typedef unsigned reference
Definition reference.h:9
int lit
Definition satVec.h:130
Definition watch.h:41
unsigned raw
Definition watch.h:46
watch_type type
Definition watch.h:42
binary_watch binary
Definition watch.h:43
#define INVALID_VECTOR_ELEMENT
Definition vector.h:20
#define kissat_check_vectors(...)
Definition vector.h:47
#define MAX_SECTOR
Definition vector.h:22
void kissat_connect_irredundant_large_clauses(kissat *solver)
Definition watch.c:171
void kissat_watch_large_clauses(kissat *solver)
Definition watch.c:145
ABC_NAMESPACE_IMPL_START void kissat_remove_binary_watch(kissat *solver, watches *watches, unsigned lit)
Definition watch.c:8
void kissat_flush_large_watches(kissat *solver)
Definition watch.c:112
void kissat_remove_blocking_watch(kissat *solver, watches *watches, reference ref)
Definition watch.c:46
void kissat_flush_all_connected(kissat *solver)
Definition watch.c:104
void kissat_flush_large_connected(kissat *solver)
Definition watch.c:206
void kissat_substitute_large_watch(kissat *solver, watches *watches, watch src, watch dst)
Definition watch.c:83
#define BEGIN_WATCHES(WS)
Definition watch.h:115
#define END_WATCHES(WS)
Definition watch.h:118
#define RELEASE_WATCHES(WS)
Definition watch.h:126
#define SET_END_OF_WATCHES(WS, P)
Definition watch.h:128
vector watches
Definition watch.h:49
#define WATCHES(LIT)
Definition watch.h:137