ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
proplit.h
Go to the documentation of this file.
1static inline void kissat_watch_large_delayed (kissat *solver,
2 watches *all_watches,
3 unsigneds *delayed) {
4 KISSAT_assert (all_watches == solver->watches);
5 KISSAT_assert (delayed == &solver->delayed);
6 const unsigned *const end_delayed = END_STACK (*delayed);
7 unsigned const *d = BEGIN_STACK (*delayed);
8 while (d != end_delayed) {
9 const unsigned lit = *d++;
10 KISSAT_assert (d != end_delayed);
11 const watch watch = {.raw = *d++};
14 watches *const lit_watches = all_watches + lit;
15 KISSAT_assert (d != end_delayed);
16 const reference ref = *d++;
17 const unsigned blocking = watch.blocking.lit;
18 LOGREF3 (ref, "watching %s blocking %s in", LOGLIT (lit),
19 LOGLIT (blocking));
20 kissat_push_blocking_watch (solver, lit_watches, blocking, ref);
21 }
22 CLEAR_STACK (*delayed);
23}
24
25static inline void
26kissat_delay_watching_large (kissat *solver, unsigneds *const delayed,
27 unsigned lit, unsigned other, reference ref) {
28 const watch watch = kissat_blocking_watch (other);
29 PUSH_STACK (*delayed, lit);
30 PUSH_STACK (*delayed, watch.raw);
31 PUSH_STACK (*delayed, ref);
32}
33
34static inline clause *PROPAGATE_LITERAL (kissat *solver,
35#if defined(PROBING_PROPAGATION)
36 const clause *const ignore,
37#endif
38 const unsigned lit) {
39 KISSAT_assert (solver->watching);
40 LOG (PROPAGATION_TYPE " propagating %s", LOGLIT (lit));
41 KISSAT_assert (VALUE (lit) > 0);
42 KISSAT_assert (EMPTY_STACK (solver->delayed));
43
44 watches *const all_watches = solver->watches;
45 ward *const arena = BEGIN_STACK (solver->arena);
46 assigned *const assigned = solver->assigned;
47 value *const values = solver->values;
48
49 const unsigned not_lit = NOT (lit);
50
51 KISSAT_assert (not_lit < LITS);
52 watches *watches = all_watches + not_lit;
53
54 watch *const begin_watches = BEGIN_WATCHES (*watches);
55 const watch *const end_watches = END_WATCHES (*watches);
56
57 watch *q = begin_watches;
58 const watch *p = q;
59
60 unsigneds *const delayed = &solver->delayed;
61 KISSAT_assert (EMPTY_STACK (*delayed));
62
63 const size_t size_watches = SIZE_WATCHES (*watches);
64 uint64_t ticks = 1 + kissat_cache_lines (size_watches, sizeof (watch));
65 const unsigned idx = IDX (lit);
66 struct assigned *const a = assigned + idx;
67 const bool probing = solver->probing;
68 const unsigned level = a->level;
69 clause *res = 0;
70
71 while (p != end_watches) {
72 const watch head = *q++ = *p++;
73 const unsigned blocking = head.blocking.lit;
75 const value blocking_value = values[blocking];
76 const bool binary = head.type.binary;
77 watch tail;
78 if (!binary)
79 tail = *q++ = *p++;
80 if (blocking_value > 0)
81 continue;
82 if (binary) {
83 if (blocking_value < 0) {
84 res = kissat_binary_conflict (solver, not_lit, blocking);
85#ifndef CONTINUE_PROPAGATING_AFTER_CONFLICT
86 break;
87#endif
88 } else {
89 KISSAT_assert (!blocking_value);
90 kissat_fast_binary_assign (solver, probing, level, values, assigned,
91 blocking, not_lit);
92 ticks++;
93 }
94 } else {
95 const reference ref = tail.raw;
96 KISSAT_assert (ref < SIZE_STACK (solver->arena));
97 clause *const c = (clause *) (arena + ref);
98 ticks++;
99 if (c->garbage) {
100 q -= 2;
101 continue;
102 }
103 unsigned *const lits = BEGIN_LITS (c);
104 const unsigned other = lits[0] ^ lits[1] ^ not_lit;
105 KISSAT_assert (lits[0] != lits[1]);
107 KISSAT_assert (not_lit != other);
108 KISSAT_assert (lit != other);
109 const value other_value = values[other];
110 if (other_value > 0) {
111 q[-2].blocking.lit = other;
112 continue;
113 }
114 const unsigned *const end_lits = lits + c->size;
115 unsigned *const searched = lits + c->searched;
116 KISSAT_assert (c->lits + 2 <= searched);
117 KISSAT_assert (searched < end_lits);
118 unsigned *r, replacement = INVALID_LIT;
119 value replacement_value = -1;
120 for (r = searched; r != end_lits; r++) {
121 replacement = *r;
123 replacement_value = values[replacement];
124 if (replacement_value >= 0)
125 break;
126 }
127 if (replacement_value < 0) {
128 for (r = lits + 2; r != searched; r++) {
129 replacement = *r;
131 replacement_value = values[replacement];
132 if (replacement_value >= 0)
133 break;
134 }
135 }
136
137 if (replacement_value >= 0) {
138 c->searched = r - lits;
139 KISSAT_assert (replacement != INVALID_LIT);
140 LOGREF3 (ref, "unwatching %s in", LOGLIT (not_lit));
141 q -= 2;
142 lits[0] = other;
143 lits[1] = replacement;
144 KISSAT_assert (lits[0] != lits[1]);
145 *r = not_lit;
146 kissat_delay_watching_large (solver, delayed, replacement, other,
147 ref);
148 ticks++;
149 } else if (other_value) {
150 KISSAT_assert (replacement_value < 0);
151 KISSAT_assert (blocking_value < 0);
152 KISSAT_assert (other_value < 0);
153#if defined(PROBING_PROPAGATION)
154 if (c == ignore) {
155 LOGREF (ref, "conflicting but ignored");
156 continue;
157 }
158#endif
159 LOGREF (ref, "conflicting");
160 res = c;
161#ifndef CONTINUE_PROPAGATING_AFTER_CONFLICT
162 break;
163#endif
164 } else {
165 KISSAT_assert (replacement_value < 0);
166#if defined(PROBING_PROPAGATION)
167 if (c == ignore) {
168 LOGREF (ref, "forcing %s but ignored", LOGLIT (other));
169 continue;
170 }
171#endif
172 kissat_fast_assign_reference (solver, values, assigned, other, ref,
173 c);
174 ticks++;
175 }
176 }
177 }
178 solver->ticks += ticks;
179
180 while (p != end_watches)
181 *q++ = *p++;
183
184 kissat_watch_large_delayed (solver, all_watches, delayed);
185
186 return res;
187}
188
189static inline void kissat_update_conflicts_and_trail (kissat *solver,
190 clause *conflict,
191 bool flush) {
192 if (conflict) {
193#ifndef PROBING_PROPAGATION
194 INC (conflicts);
195#endif
196 if (!solver->level) {
197 LOG (PROPAGATION_TYPE " propagation on root-level failed");
198 solver->inconsistent = true;
201 }
202 } else if (flush && !solver->level && solver->unflushed)
204}
ABC_NAMESPACE_HEADER_START typedef word ward
Definition arena.h:12
#define BEGIN_STACK(S)
Definition stack.h:46
#define SIZE_STACK(S)
Definition stack.h:19
#define EMPTY_STACK(S)
Definition stack.h:18
#define CLEAR_STACK(S)
Definition stack.h:50
#define PUSH_STACK(S, E)
Definition stack.h:39
#define END_STACK(S)
Definition stack.h:48
#define INVALID_LIT
#define INC(NAME)
#define LOG(...)
ABC_NAMESPACE_IMPL_START typedef signed char value
#define CHECK_AND_ADD_EMPTY(...)
Definition check.h:146
Cube * p
Definition exorList.c:222
#define LITS
Definition internal.h:251
#define BEGIN_LITS(C)
Definition clause.h:44
#define KISSAT_assert(ignore)
Definition global.h:13
#define solver
Definition kitten.c:211
#define LOGREF(...)
Definition logging.h:433
#define LOGREF3(...)
Definition logging.h:439
#define LOGLIT(...)
Definition logging.hpp:99
unsigned short ref
Definition giaNewBdd.h:38
#define ADD_EMPTY_TO_PROOF(...)
Definition proof.h:135
#define PROPAGATION_TYPE
Definition propbeyond.c:9
#define PROPAGATE_LITERAL
Definition propbeyond.c:7
#define PROBING_PROPAGATION
Definition proprobe.c:9
ABC_NAMESPACE_HEADER_START typedef unsigned reference
Definition reference.h:9
int lit
Definition satVec.h:130
#define VALID_INTERNAL_LITERAL(LIT)
Definition literal.h:23
#define IDX(LIT)
Definition literal.h:28
#define NOT(LIT)
Definition literal.h:33
bool binary
Definition assign.h:23
unsigned level
Definition assign.h:19
unsigned lits[3]
Definition clause.h:39
unsigned searched
Definition clause.h:36
unsigned size
Definition clause.h:37
bool garbage
Definition clause.h:25
ABC_NAMESPACE_IMPL_START void kissat_flush_trail(kissat *solver)
Definition trail.c:8
Definition watch.h:41
unsigned raw
Definition watch.h:46
blocking_watch blocking
Definition watch.h:44
watch_type type
Definition watch.h:42
#define VALUE(LIT)
Definition value.h:10
#define SIZE_WATCHES(W)
Definition watch.h:104
#define BEGIN_WATCHES(WS)
Definition watch.h:115
#define END_WATCHES(WS)
Definition watch.h:118
#define SET_END_OF_WATCHES(WS, P)
Definition watch.h:128
vector watches
Definition watch.h:49