18static void flush_watched_clauses_by_literal (
kissat *
solver,
unsigned lit,
28 const value lit_fixed =
29 (lit_value && !lit_assigned->
level) ? lit_value : 0;
30 const unsigned mlit = kissat_map_literal (
solver,
lit,
true);
36 while (
p != end_of_watches) {
40 const unsigned other_idx =
IDX (other);
41 const value other_value = values[other];
42 const value other_fixed =
43 (other_value && !all_assigned[other_idx].
level) ? other_value : 0;
44 const unsigned mother = kissat_map_literal (
solver, other, compact);
45 if (lit_fixed > 0 || other_fixed > 0 || mother ==
INVALID_LIT) {
79 const size_t size_lit_watches =
SIZE_WATCHES (*lit_watches);
80 LOG (
"keeping %zu watches[%u]", size_lit_watches,
lit);
89#if defined(LOGGING) || !defined(KISSAT_NDEBUG)
90 const size_t size_mlit_watches =
SIZE_WATCHES (*mlit_watches);
94 else if (mlit <
lit) {
97 *mlit_watches = *lit_watches;
98 LOG (
"copied watches[%u] = watches[%u] (size %zu)", mlit,
lit,
100 memset (lit_watches, 0,
sizeof *lit_watches);
105static void flush_all_watched_clauses (
kissat *
solver,
bool compact,
110 const unsigned lit =
LIT (idx);
111 flush_watched_clauses_by_literal (
solver,
lit, compact, start);
112 const unsigned not_lit =
NOT (
lit);
113 flush_watched_clauses_by_literal (
solver, not_lit, compact, start);
118 unsigned forced,
clause *dst) {
122 const unsigned forced_idx =
IDX (forced);
125 if (a->
reason != dst_ref) {
126 LOG (
"reason reference %u of %s updated to %u", a->
reason,
127 LOGLIT (forced), dst_ref);
133static unsigned get_forced (
const value *values,
clause *dst) {
147static void get_forced_and_update_large_reason (
kissat *
solver,
149 const value *
const values,
151 const unsigned forced = get_forced (values, dst);
156 clause *first_reducible) {
157 if (first_reducible >= end) {
158 LOG (
"first reducible after end of arena");
160 }
else if (first_reducible) {
161 LOGCLS (first_reducible,
"updating first reducible clause to");
163 kissat_reference_clause (
solver, first_reducible);
165 LOG (
"first reducible clause becomes invalid");
171 clause *last_irredundant) {
172 if (!last_irredundant) {
173 LOG (
"no more large irredundant clauses left");
175 }
else if (end <= last_irredundant) {
176 LOG (
"last irredundant clause after end of arena");
179 LOGCLS (last_irredundant,
"updating last irredundant clause to");
191 if (ref >=
solver->first_reducible) {
192 LOG (
"no need to update larger first reducible");
206 if (ref <= solver->last_irredundant) {
207 LOG (
"no need to update smaller last irredundant");
215static void move_redundant_clauses_to_the_end (
kissat *
solver,
225 size_t bytes_redundant = (
char *) end - (
char *) begin;
227 "moving redundant clauses of %s to the end",
231 clause *
p = begin, *q = begin, *r = redundant;
236 clause *last_irredundant = kissat_last_irredundant_clause (
solver);
240 size_t bytes = kissat_bytes_of_clause (
p->size);
243 r = (
clause *) (bytes + (
char *) r);
248 last_irredundant = q;
251 q = (
clause *) (bytes + (
char *) q);
253 p = (
clause *) (bytes + (
char *)
p);
256 clause *first_reducible = 0;
258 size_t bytes = kissat_bytes_of_clause (r->size);
264 if (!first_reducible)
266 r = (
clause *) (bytes + (
char *) r);
267 q = (
clause *) (bytes + (
char *) q);
269 KISSAT_assert ((
char *) r <= (
char *) redundant + bytes_redundant);
274 update_first_reducible (
solver, q, first_reducible);
275 update_last_irredundant (
solver, q, last_irredundant);
285#ifdef CHECKING_OR_PROVING
286 const bool checking_or_proving = kissat_checking_or_proving (
solver);
295 size_t flushed_garbage_clauses = 0;
296 size_t flushed_satisfied_clauses = 0;
303 clause *first, *src, *dst;
305 first = kissat_dereference_clause (
solver, start);
310 clause *first_redundant = 0;
311 clause *first_reducible = 0;
315 last_irredundant = kissat_last_irredundant_clause (
solver);
317 last_irredundant = 0;
319 size_t redundant_bytes = 0;
321 for (
clause *next; src != end; src = next) {
325 flushed_garbage_clauses++;
327 if (last_irredundant == src) {
329 last_irredundant = 0;
331 last_irredundant = first;
338 next = kissat_next_clause (src);
339#if !defined(KISSAT_NDEBUG) || defined(CHECKING_OR_PROVING)
340 const unsigned old_size = src->
size;
343 *(
unsigned *) dst = *(
unsigned *) src;
345 unsigned *q = dst->
lits;
351 unsigned non_false = 0;
353 bool satisfied =
false;
356#ifdef CHECKING_OR_PROVING
357 if (checking_or_proving)
364 const unsigned idx =
IDX (
lit);
367 if (tmp < 0 && !
level)
369 else if (tmp > 0 && !
level) {
375 const unsigned mlit = kissat_map_literal (
solver,
lit, compact);
390#ifdef CHECKING_OR_PROVING
391 if (checking_or_proving)
399 DEC (clauses_redundant);
401 DEC (clauses_irredundant);
403 flushed_satisfied_clauses++;
405#ifdef CHECKING_OR_PROVING
406 if (checking_or_proving) {
413 if (last_irredundant == src) {
415 last_irredundant = 0;
417 last_irredundant = first;
422 const unsigned new_size = q - dst->
lits;
443 kissat_watch_binary (
solver, mfirst, msecond);
450 const unsigned forced_idx =
IDX (forced);
455 "reason clause[%u] of %s updated to binary reason",
462 if (!redundant && last_irredundant == src) {
464 last_irredundant = 0;
466 last_irredundant = first;
471 dst->
size = new_size;
479 clause *next_dst = kissat_next_clause (dst);
482 if (!first_reducible)
483 first_reducible = dst;
485 redundant_bytes += (
char *) next_dst - (
char *) dst;
487 if (!first_redundant)
488 first_redundant = dst;
490 last_irredundant = dst;
495#ifdef CHECKING_OR_PROVING
496 if (!checking_or_proving)
499 if (new_size != old_size) {
514 update_first_reducible (
solver, dst, first_reducible);
515 update_last_irredundant (
solver, dst, last_irredundant);
519 LOGCLS (first_redundant,
"determined first redundant clause as");
521#if !defined(KISSAT_QUIET) || defined(METRICS)
527 "flushed %zu falsified literals in large clauses",
529 size_t flushed_clauses =
530 flushed_satisfied_clauses + flushed_garbage_clauses;
531 if (flushed_satisfied_clauses)
533 solver,
"collect",
GET (garbage_collections),
534 "flushed %zu satisfied large clauses %.0f%%",
535 flushed_satisfied_clauses,
536 kissat_percent (flushed_satisfied_clauses, flushed_clauses));
537 if (flushed_garbage_clauses)
539 solver,
"collect",
GET (garbage_collections),
540 "flushed %zu large garbage clauses %.0f%%", flushed_garbage_clauses,
541 kissat_percent (flushed_garbage_clauses, flushed_clauses));
545 ADD (flushed, flushed);
547 ADD (allocated_collected, bytes);
552 if (first_redundant && last_irredundant &&
553 first_redundant < last_irredundant) {
555 size_t move_bytes = (
char *) dst - (
char *) first_redundant;
556 LOG (
"redundant bytes %s (%.0f%%) out of %s moving bytes",
558 kissat_percent (redundant_bytes, move_bytes),
562 res = kissat_reference_clause (
solver, first_redundant);
570 if (
solver->statistics_.arena_garbage)
594 for (
clause *next; c != end; c = next) {
595 next = kissat_next_clause (c);
597 unsigned *lits = c->
lits;
602 const unsigned l0 = lits[0];
603 const unsigned l1 = lits[1];
613 INC (garbage_collections);
616 unsigned vars, mfixed;
623 flush_all_watched_clauses (
solver, compact, start);
624 reference move = sparse_sweep_garbage_clauses (
solver, compact, start);
628 move_redundant_clauses_to_the_end (
solver, move);
629 rewatch_clauses (
solver, start);
640 bool compact = (inactive > limit);
641 LOG (
"%u inactive variables %.0f%% <= limit %u %.0f%%", inactive,
642 kissat_percent (inactive,
solver->vars), limit,
643 kissat_percent (limit,
solver->vars));
652 if (
solver->statistics_.units) {
659static void dense_sweep_garbage_clauses (
kissat *
solver) {
663 LOG (
"dense garbage collection");
666 size_t flushed_garbage_clauses = 0;
668 clause *first_reducible = 0;
669 clause *last_irredundant = 0;
677 for (
clause *next; src != end; src = next) {
681 flushed_garbage_clauses++;
687 next = kissat_next_clause (src);
689 *(
unsigned *) dst = *(
unsigned *) src;
696 last_irredundant = dst;
697 else if (!first_reducible)
698 first_reducible = dst;
699 dst = kissat_next_clause (dst);
702 update_first_reducible (
solver, dst, first_reducible);
703 update_last_irredundant (
solver, dst, last_irredundant);
706#if !defined(KISSAT_QUIET) || defined(METRICS)
710 "flushed %zu large garbage clauses",
711 flushed_garbage_clauses);
715 ADD (allocated_collected, bytes);
722 if (
solver->statistics_.arena_garbage)
734 INC (garbage_collections);
735 INC (dense_garbage_collections);
737 dense_sweep_garbage_clauses (
solver);
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void * kissat_malloc(kissat *solver, size_t bytes)
void kissat_free(kissat *solver, void *ptr, size_t bytes)
void kissat_shrink_arena(kissat *solver)
ABC_NAMESPACE_HEADER_START typedef word ward
#define SET_END_OF_STACK(S, P)
ABC_NAMESPACE_IMPL_START typedef signed char value
#define CHECK_AND_ADD_STACK(...)
#define REMOVE_CHECKER_STACK(...)
clause * kissat_delete_clause(kissat *solver, clause *c)
void kissat_delete_binary(kissat *solver, unsigned a, unsigned b)
void kissat_update_last_irredundant(kissat *solver, clause *irredundant)
void kissat_update_first_reducible(kissat *solver, clause *reducible)
void kissat_dense_collect(kissat *solver)
bool kissat_compacting(kissat *solver)
void kissat_initial_sparse_collect(kissat *solver)
void kissat_sparse_collect(kissat *solver, bool compact, reference start)
unsigned kissat_compact_literals(kissat *solver, unsigned *mfixed_ptr)
void kissat_finalize_compacting(kissat *solver, unsigned vars, unsigned mfixed)
ABC_NAMESPACE_IMPL_START void kissat_reset_last_learned(kissat *solver)
#define all_variables(IDX)
#define SIZE_OF_CLAUSE_HEADER
void kissat_sort_literals(struct kissat *, unsigned size, unsigned *lits)
#define all_literals_in_clause(LIT, C)
#define KISSAT_assert(ignore)
#define kissat_very_verbose(...)
#define kissat_phase(...)
#define ADD_STACK_TO_PROOF(...)
#define DELETE_STACK_FROM_PROOF(...)
ABC_NAMESPACE_HEADER_START typedef unsigned reference
#define kissat_check_statistics(...)
void kissat_mark_reason_clauses(kissat *solver, reference start)
#define BEGIN_WATCHES(WS)
#define SET_END_OF_WATCHES(WS, P)