This commit is contained in:
MyskYko 2025-03-05 04:10:49 -08:00
parent a7476c65d8
commit 664d285fcb
210 changed files with 4590 additions and 2692 deletions

View File

@ -28,7 +28,7 @@ MODULES := \
src/opt/cut src/opt/fxu src/opt/fxch src/opt/rwr src/opt/mfs src/opt/sim \ src/opt/cut src/opt/fxu src/opt/fxch src/opt/rwr src/opt/mfs src/opt/sim \
src/opt/ret src/opt/fret src/opt/res src/opt/lpk src/opt/nwk src/opt/rwt src/opt/rar \ src/opt/ret src/opt/fret src/opt/res src/opt/lpk src/opt/nwk src/opt/rwt src/opt/rar \
src/opt/cgt src/opt/csw src/opt/dar src/opt/dau src/opt/dsc src/opt/sfm src/opt/sbd \ src/opt/cgt src/opt/csw src/opt/dar src/opt/dau src/opt/dsc src/opt/sfm src/opt/sbd \
src/sat/bsat src/sat/xsat src/sat/satoko src/sat/csat src/sat/msat src/sat/psat src/sat/cnf src/sat/bmc src/sat/glucose src/sat/glucose2 \ src/sat/bsat src/sat/xsat src/sat/satoko src/sat/csat src/sat/msat src/sat/psat src/sat/cnf src/sat/bmc src/sat/glucose src/sat/glucose2 src/sat/kissat \
src/bool/bdc src/bool/deco src/bool/dec src/bool/kit src/bool/lucky \ src/bool/bdc src/bool/deco src/bool/dec src/bool/kit src/bool/lucky \
src/bool/rsb src/bool/rpo \ src/bool/rsb src/bool/rpo \
src/proof/pdr src/proof/abs src/proof/live src/proof/ssc src/proof/int \ src/proof/pdr src/proof/abs src/proof/live src/proof/ssc src/proof/int \

View File

@ -2518,6 +2518,374 @@ SOURCE=.\src\sat\glucose2\Vec.h
SOURCE=.\src\sat\glucose2\XAlloc.h SOURCE=.\src\sat\glucose2\XAlloc.h
# End Source File # End Source File
# End Group # End Group
# Begin Group "kissat"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\src\sat\kissat\allocate.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\analyze.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\ands.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\arena.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\assign.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\averages.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\backbone.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\backtrack.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\build.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\bump.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\check.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\classify.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\clause.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\collect.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\colors.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\compact.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\config.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\congruence.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\decide.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\deduce.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\definition.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\dense.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\dump.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\eliminate.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\equivalences.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\error.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\extend.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\factor.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\fastel.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\file.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\flags.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\format.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\forward.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\gates.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\heap.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\ifthenelse.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\import.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\internal.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\kimits.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\kissatSolver.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\kissatTest.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\kitten.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\kptions.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\krite.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\kucky.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\learn.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\logging.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\minimize.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\mode.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\phases.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\preprocess.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\print.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\probe.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\profile.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\promote.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\proof.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\propbeyond.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\propdense.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\propinitially.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\proprobe.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\propsearch.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\queue.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\reduce.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\reluctant.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\reorder.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\rephase.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\report.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\resize.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\resolve.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\resources.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\restart.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\search.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\shrink.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\smooth.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\sort.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\stack.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\statistics.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\strengthen.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\substitute.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\sweep.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\terminate.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\tiers.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\trail.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\transitive.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\utilities.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\vector.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\vivify.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\walk.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\warmup.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\watch.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\kissat\weaken.c
# End Source File
# End Group
# End Group # End Group
# Begin Group "opt" # Begin Group "opt"

View File

@ -56001,6 +56001,11 @@ int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv )
goto usage; goto usage;
} }
} }
extern void kissat_solver_test();
kissat_solver_test();
return 0;
if ( pAbc->pGia == NULL ) if ( pAbc->pGia == NULL )
{ {
Abc_Print( -1, "Abc_CommandAbc9Test(): There is no AIG.\n" ); Abc_Print( -1, "Abc_CommandAbc9Test(): There is no AIG.\n" );

View File

@ -12,6 +12,8 @@
#include <inttypes.h> #include <inttypes.h>
#endif #endif
ABC_NAMESPACE_IMPL_START
static void inc_bytes (kissat *solver, size_t bytes) { static void inc_bytes (kissat *solver, size_t bytes) {
#ifdef METRICS #ifdef METRICS
if (!solver) if (!solver)
@ -62,16 +64,16 @@ void kissat_free (kissat *solver, void *ptr, size_t bytes) {
dec_bytes (solver, bytes); dec_bytes (solver, bytes);
free (ptr); free (ptr);
} else } else
assert (!bytes); KISSAT_assert (!bytes);
} }
char *kissat_strdup (kissat *solver, const char *str) { char *kissat_strdup (kissat *solver, const char *str) {
char *res = kissat_malloc (solver, strlen (str) + 1); char *res = (char*)kissat_malloc (solver, strlen (str) + 1);
return strcpy (res, str); return strcpy (res, str);
} }
void kissat_freestr (struct kissat *solver, char *str) { void kissat_freestr (struct kissat *solver, char *str) {
assert (str); KISSAT_assert (str);
kissat_free (solver, str, strlen (str) + 1); kissat_free (solver, str, strlen (str) + 1);
} }
@ -149,8 +151,8 @@ void *kissat_realloc (kissat *solver, void *p, size_t old_bytes,
void *kissat_nrealloc (kissat *solver, void *p, size_t o, size_t n, void *kissat_nrealloc (kissat *solver, void *p, size_t o, size_t n,
size_t size) { size_t size) {
if (!size) { if (!size) {
assert (!p); KISSAT_assert (!p);
assert (!o); KISSAT_assert (!o);
return 0; return 0;
} }
const size_t max = MAX_SIZE_T / size; const size_t max = MAX_SIZE_T / size;
@ -159,3 +161,5 @@ void *kissat_nrealloc (kissat *solver, void *p, size_t o, size_t n,
n, size); n, size);
return kissat_realloc (solver, p, o * size, n * size); return kissat_realloc (solver, p, o * size, n * size);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,6 +3,9 @@
#include <stdlib.h> #include <stdlib.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
void *kissat_malloc (struct kissat *, size_t bytes); void *kissat_malloc (struct kissat *, size_t bytes);
@ -18,14 +21,14 @@ void kissat_dealloc (struct kissat *, void *ptr, size_t n, size_t size);
void *kissat_realloc (struct kissat *, void *, size_t old, size_t bytes); void *kissat_realloc (struct kissat *, void *, size_t old, size_t bytes);
void *kissat_nrealloc (struct kissat *, void *, size_t o, size_t n, size_t); void *kissat_nrealloc (struct kissat *, void *, size_t o, size_t n, size_t);
#define NALLOC(P, N) \ #define NALLOC(T, P, N) \
do { \ do { \
(P) = kissat_nalloc (solver, (N), sizeof *(P)); \ (P) = (T*) kissat_nalloc (solver, (N), sizeof *(P)); \
} while (0) } while (0)
#define CALLOC(P, N) \ #define CALLOC(T, P, N) \
do { \ do { \
(P) = kissat_calloc (solver, (N), sizeof *(P)); \ (P) = (T*) kissat_calloc (solver, (N), sizeof *(P)); \
} while (0) } while (0)
#define DEALLOC(P, N) \ #define DEALLOC(P, N) \
@ -33,4 +36,6 @@ void *kissat_nrealloc (struct kissat *, void *, size_t o, size_t n, size_t);
kissat_dealloc (solver, (P), (N), sizeof *(P)); \ kissat_dealloc (solver, (P), (N), sizeof *(P)); \
} while (0) } while (0)
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -13,10 +13,12 @@
#include <inttypes.h> #include <inttypes.h>
ABC_NAMESPACE_IMPL_START
static bool one_literal_on_conflict_level (kissat *solver, clause *conflict, static bool one_literal_on_conflict_level (kissat *solver, clause *conflict,
unsigned *conflict_level_ptr) { unsigned *conflict_level_ptr) {
assert (conflict); KISSAT_assert (conflict);
assert (conflict->size > 1); KISSAT_assert (conflict->size > 1);
unsigned jump_level = INVALID_LEVEL; unsigned jump_level = INVALID_LEVEL;
unsigned conflict_level = INVALID_LEVEL; unsigned conflict_level = INVALID_LEVEL;
@ -31,7 +33,7 @@ static bool one_literal_on_conflict_level (kissat *solver, clause *conflict,
for (const unsigned *p = lits; p != end_of_lits; p++) { for (const unsigned *p = lits; p != end_of_lits; p++) {
const unsigned lit = *p; const unsigned lit = *p;
assert (VALUE (lit) < 0); KISSAT_assert (VALUE (lit) < 0);
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
const unsigned lit_level = all_assigned[idx].level; const unsigned lit_level = all_assigned[idx].level;
if (conflict_level == INVALID_LEVEL || conflict_level < lit_level) { if (conflict_level == INVALID_LEVEL || conflict_level < lit_level) {
@ -48,8 +50,8 @@ static bool one_literal_on_conflict_level (kissat *solver, clause *conflict,
if (literals_on_conflict_level > 1 && conflict_level == solver->level) if (literals_on_conflict_level > 1 && conflict_level == solver->level)
break; break;
} }
assert (conflict_level != INVALID_LEVEL); KISSAT_assert (conflict_level != INVALID_LEVEL);
assert (literals_on_conflict_level); KISSAT_assert (literals_on_conflict_level);
LOG ("found %u literals on conflict level %u", literals_on_conflict_level, LOG ("found %u literals on conflict level %u", literals_on_conflict_level,
conflict_level); conflict_level);
@ -105,10 +107,10 @@ static bool one_literal_on_conflict_level (kissat *solver, clause *conflict,
if (literals_on_conflict_level > 1) if (literals_on_conflict_level > 1)
return false; return false;
assert (literals_on_conflict_level == 1); KISSAT_assert (literals_on_conflict_level == 1);
assert (forced_lit != INVALID_LIT); KISSAT_assert (forced_lit != INVALID_LIT);
assert (jump_level != INVALID_LEVEL); KISSAT_assert (jump_level != INVALID_LEVEL);
assert (jump_level < conflict_level); KISSAT_assert (jump_level < conflict_level);
LOG ("reusing conflict as driving clause of %s", LOGLIT (forced_lit)); LOG ("reusing conflict as driving clause of %s", LOGLIT (forced_lit));
@ -116,7 +118,7 @@ static bool one_literal_on_conflict_level (kissat *solver, clause *conflict,
kissat_backtrack_after_conflict (solver, new_level); kissat_backtrack_after_conflict (solver, new_level);
if (conflict_size == 2) { if (conflict_size == 2) {
assert (conflict == &solver->conflict); KISSAT_assert (conflict == &solver->conflict);
const unsigned other = lits[0] ^ lits[1] ^ forced_lit; const unsigned other = lits[0] ^ lits[1] ^ forced_lit;
kissat_assign_binary (solver, forced_lit, other); kissat_assign_binary (solver, forced_lit, other);
} else { } else {
@ -142,9 +144,9 @@ static inline void analyze_reason_side_literal (kissat *solver,
unsigned lit) { unsigned lit) {
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
const assigned *a = all_assigned + idx; const assigned *a = all_assigned + idx;
assert (a->level); KISSAT_assert (a->level);
assert (a->analyzed); KISSAT_assert (a->analyzed);
assert (a->reason != UNIT_REASON); KISSAT_assert (a->reason != UNIT_REASON);
if (a->reason == DECISION_REASON) if (a->reason == DECISION_REASON)
return; return;
if (a->binary) { if (a->binary) {
@ -152,13 +154,13 @@ static inline void analyze_reason_side_literal (kissat *solver,
mark_reason_side_literal (solver, all_assigned, other); mark_reason_side_literal (solver, all_assigned, other);
} else { } else {
const reference ref = a->reason; const reference ref = a->reason;
assert (ref < SIZE_STACK (solver->arena)); KISSAT_assert (ref < SIZE_STACK (solver->arena));
clause *c = (clause *) (arena + ref); clause *c = (clause *) (arena + ref);
const unsigned not_lit = NOT (lit); const unsigned not_lit = NOT (lit);
INC (search_ticks); INC (search_ticks);
for (all_literals_in_clause (other, c)) for (all_literals_in_clause (other, c))
if (other != not_lit) { if (other != not_lit) {
assert (other != lit); KISSAT_assert (other != lit);
mark_reason_side_literal (solver, all_assigned, other); mark_reason_side_literal (solver, all_assigned, other);
if (SIZE_STACK (solver->analyzed) > limit) if (SIZE_STACK (solver->analyzed) > limit)
break; break;
@ -183,9 +185,9 @@ static void analyze_reason_side_literals (kissat *solver) {
return; return;
} }
assigned *all_assigned = solver->assigned; assigned *all_assigned = solver->assigned;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
for (all_stack (unsigned, lit, solver->clause)) for (all_stack (unsigned, lit, solver->clause))
assert (all_assigned[IDX (lit)].analyzed); KISSAT_assert (all_assigned[IDX (lit)].analyzed);
#endif #endif
LOG ("trying to bump reason side literals too"); LOG ("trying to bump reason side literals too");
const size_t saved = SIZE_STACK (solver->analyzed); const size_t saved = SIZE_STACK (solver->analyzed);
@ -203,7 +205,7 @@ static void analyze_reason_side_literals (kissat *solver) {
const unsigned idx = POP_STACK (solver->analyzed); const unsigned idx = POP_STACK (solver->analyzed);
struct assigned *a = all_assigned + idx; struct assigned *a = all_assigned + idx;
LOG ("marking %s as not analyzed", LOGVAR (idx)); LOG ("marking %s as not analyzed", LOGVAR (idx));
assert (a->analyzed); KISSAT_assert (a->analyzed);
a->analyzed = false; a->analyzed = false;
} }
BUMP_DELAY (bumpreasons); BUMP_DELAY (bumpreasons);
@ -228,7 +230,7 @@ static void sort_levels (kissat *solver) {
static void sort_deduced_clause (kissat *solver) { static void sort_deduced_clause (kissat *solver) {
sort_levels (solver); sort_levels (solver);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
const size_t size_frames = SIZE_STACK (solver->frames); const size_t size_frames = SIZE_STACK (solver->frames);
#endif #endif
frame *frames = BEGIN_STACK (solver->frames); frame *frames = BEGIN_STACK (solver->frames);
@ -238,25 +240,25 @@ static void sort_deduced_clause (kissat *solver) {
unsigned const *p = end_levels; unsigned const *p = end_levels;
while (p != begin_levels) { while (p != begin_levels) {
const unsigned level = *--p; const unsigned level = *--p;
assert (level < size_frames); KISSAT_assert (level < size_frames);
frame *f = frames + level; frame *f = frames + level;
const unsigned used = f->used; const unsigned used = f->used;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
f->saved = used; f->saved = used;
#endif #endif
assert (used > 0); KISSAT_assert (used > 0);
assert (UINT_MAX - used >= pos); KISSAT_assert (UINT_MAX - used >= pos);
f->used = pos; f->used = pos;
pos += used; pos += used;
} }
unsigneds *clause = &solver->clause; unsigneds *clause = &solver->clause;
const size_t size_clause = SIZE_STACK (*clause); const size_t size_clause = SIZE_STACK (*clause);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
assert (pos == size_clause); KISSAT_assert (pos == size_clause);
#endif #endif
unsigned const *begin_clause = BEGIN_STACK (*clause); unsigned const *begin_clause = BEGIN_STACK (*clause);
const unsigned *const end_clause = END_STACK (*clause); const unsigned *const end_clause = END_STACK (*clause);
assert (begin_clause < end_clause); KISSAT_assert (begin_clause < end_clause);
unsigneds *shadow = &solver->shadow; unsigneds *shadow = &solver->shadow;
while (SIZE_STACK (*shadow) < size_clause) while (SIZE_STACK (*shadow) < size_clause)
@ -272,37 +274,37 @@ static void sort_deduced_clause (kissat *solver) {
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
const struct assigned *a = assigned + idx; const struct assigned *a = assigned + idx;
const unsigned level = a->level; const unsigned level = a->level;
assert (level < size_frames); KISSAT_assert (level < size_frames);
frame *f = frames + level; frame *f = frames + level;
const unsigned pos = f->used++; const unsigned pos = f->used++;
POKE_STACK (*shadow, pos, lit); POKE_STACK (*shadow, pos, lit);
} }
assert (size_clause == SIZE_STACK (*shadow)); KISSAT_assert (size_clause == SIZE_STACK (*shadow));
SWAP (unsigneds, *clause, *shadow); SWAP (unsigneds, *clause, *shadow);
pos = 1; pos = 1;
p = end_levels; p = end_levels;
while (p != begin_levels) { while (p != begin_levels) {
const unsigned level = *--p; const unsigned level = *--p;
assert (level < size_frames); KISSAT_assert (level < size_frames);
frame *f = frames + level; frame *f = frames + level;
const unsigned end = f->used; const unsigned end = f->used;
assert (pos < end); KISSAT_assert (pos < end);
f->used = end - pos; f->used = end - pos;
assert (f->used == f->saved); KISSAT_assert (f->used == f->saved);
pos = end; pos = end;
} }
CLEAR_STACK (*shadow); CLEAR_STACK (*shadow);
LOGTMP ("level sorted deduced"); LOGTMP ("level sorted deduced");
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
unsigned prev_level = solver->level; unsigned prev_level = solver->level;
for (all_stack (unsigned, lit, solver->clause)) { for (all_stack (unsigned, lit, solver->clause)) {
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
const unsigned lit_level = assigned[idx].level; const unsigned lit_level = assigned[idx].level;
assert (prev_level >= lit_level); KISSAT_assert (prev_level >= lit_level);
prev_level = lit_level; prev_level = lit_level;
} }
#endif #endif
@ -311,13 +313,13 @@ static void sort_deduced_clause (kissat *solver) {
static void reset_levels (kissat *solver) { static void reset_levels (kissat *solver) {
LOG ("reset %zu marked levels", SIZE_STACK (solver->levels)); LOG ("reset %zu marked levels", SIZE_STACK (solver->levels));
frame *frames = BEGIN_STACK (solver->frames); frame *frames = BEGIN_STACK (solver->frames);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
const size_t size_frames = SIZE_STACK (solver->frames); const size_t size_frames = SIZE_STACK (solver->frames);
#endif #endif
for (all_stack (unsigned, level, solver->levels)) { for (all_stack (unsigned, level, solver->levels)) {
assert (level < size_frames); KISSAT_assert (level < size_frames);
frame *f = frames + level; frame *f = frames + level;
assert (f->used > 0); KISSAT_assert (f->used > 0);
f->used = 0; f->used = 0;
} }
CLEAR_STACK (solver->levels); CLEAR_STACK (solver->levels);
@ -327,11 +329,11 @@ void kissat_reset_only_analyzed_literals (kissat *solver) {
LOG ("reset %zu analyzed variables", SIZE_STACK (solver->analyzed)); LOG ("reset %zu analyzed variables", SIZE_STACK (solver->analyzed));
assigned *assigned = solver->assigned; assigned *assigned = solver->assigned;
for (all_stack (unsigned, idx, solver->analyzed)) { for (all_stack (unsigned, idx, solver->analyzed)) {
assert (idx < VARS); KISSAT_assert (idx < VARS);
struct assigned *a = assigned + idx; struct assigned *a = assigned + idx;
assert (!a->poisoned); KISSAT_assert (!a->poisoned);
assert (!a->removable); KISSAT_assert (!a->removable);
assert (!a->shrinkable); KISSAT_assert (!a->shrinkable);
a->analyzed = false; a->analyzed = false;
} }
CLEAR_STACK (solver->analyzed); CLEAR_STACK (solver->analyzed);
@ -340,13 +342,13 @@ void kissat_reset_only_analyzed_literals (kissat *solver) {
static void reset_removable (kissat *solver) { static void reset_removable (kissat *solver) {
LOG ("reset %zu removable variables", SIZE_STACK (solver->removable)); LOG ("reset %zu removable variables", SIZE_STACK (solver->removable));
assigned *assigned = solver->assigned; assigned *assigned = solver->assigned;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
unsigned not_removable = 0; unsigned not_removable = 0;
#endif #endif
for (all_stack (unsigned, idx, solver->removable)) { for (all_stack (unsigned, idx, solver->removable)) {
assert (idx < VARS); KISSAT_assert (idx < VARS);
struct assigned *a = assigned + idx; struct assigned *a = assigned + idx;
assert (a->removable || !not_removable++); KISSAT_assert (a->removable || !not_removable++);
a->removable = false; a->removable = false;
} }
CLEAR_STACK (solver->removable); CLEAR_STACK (solver->removable);
@ -360,8 +362,8 @@ static void reset_analysis_but_not_analyzed_literals (kissat *solver) {
} }
static void update_trail_average (kissat *solver) { static void update_trail_average (kissat *solver) {
assert (!solver->probing); KISSAT_assert (!solver->probing);
#if defined(LOGGING) || !defined(QUIET) #if defined(LOGGING) || !defined(KISSAT_QUIET)
const unsigned size = SIZE_ARRAY (solver->trail); const unsigned size = SIZE_ARRAY (solver->trail);
const unsigned assigned = size - solver->unflushed; const unsigned assigned = size - solver->unflushed;
const unsigned active = solver->active; const unsigned active = solver->active;
@ -371,36 +373,36 @@ static void update_trail_average (kissat *solver) {
#endif #endif
LOG ("trail filled %.0f%% (size %u, unflushed %u, active %u)", filled, LOG ("trail filled %.0f%% (size %u, unflushed %u, active %u)", filled,
size, solver->unflushed, active); size, solver->unflushed, active);
#ifndef QUIET #ifndef KISSAT_QUIET
UPDATE_AVERAGE (trail, filled); UPDATE_AVERAGE (trail, filled);
#endif #endif
} }
static void update_decision_rate_average (kissat *solver) { static void update_decision_rate_average (kissat *solver) {
assert (!solver->probing); KISSAT_assert (!solver->probing);
const uint64_t current = DECISIONS; const uint64_t current = DECISIONS;
const uint64_t previous = const uint64_t previous =
solver->averages[solver->stable].saved_decisions; solver->averages[solver->stable].saved_decisions;
assert (previous <= current); KISSAT_assert (previous <= current);
const uint64_t decisions = current - previous; const uint64_t decisions = current - previous;
solver->averages[solver->stable].saved_decisions = current; solver->averages[solver->stable].saved_decisions = current;
UPDATE_AVERAGE (decision_rate, decisions); UPDATE_AVERAGE (decision_rate, decisions);
} }
static void analyze_failed_literal (kissat *solver, clause *conflict) { static void analyze_failed_literal (kissat *solver, clause *conflict) {
assert (solver->level == 1); KISSAT_assert (solver->level == 1);
const unsigned failed = FRAME (1).decision; const unsigned failed = FRAME (1).decision;
LOGCLS (conflict, "analyzing failed literal %s conflict", LOGCLS (conflict, "analyzing failed literal %s conflict",
LOGLIT (failed)); LOGLIT (failed));
unsigneds *units = &solver->clause; unsigneds *units = &solver->clause;
assert (EMPTY_STACK (*units)); KISSAT_assert (EMPTY_STACK (*units));
assert (EMPTY_STACK (solver->analyzed)); KISSAT_assert (EMPTY_STACK (solver->analyzed));
const unsigned not_failed = NOT (failed); const unsigned not_failed = NOT (failed);
assigned *all_assigned = solver->assigned; assigned *all_assigned = solver->assigned;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
const value *const values = solver->values; const value *const values = solver->values;
#endif #endif
unsigned const *t = END_ARRAY (solver->trail); unsigned const *t = END_ARRAY (solver->trail);
@ -408,18 +410,18 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) {
unsigned unit = INVALID_LIT; unsigned unit = INVALID_LIT;
for (all_literals_in_clause (lit, conflict)) { for (all_literals_in_clause (lit, conflict)) {
assert (lit != failed); KISSAT_assert (lit != failed);
if (lit == not_failed) { if (lit == not_failed) {
LOG ("negation %s of failed literal %s occurs in conflict", LOG ("negation %s of failed literal %s occurs in conflict",
LOGLIT (not_failed), LOGLIT (failed)); LOGLIT (not_failed), LOGLIT (failed));
goto DONE; goto DONE;
} }
assert (values[lit] < 0); KISSAT_assert (values[lit] < 0);
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
assigned *a = all_assigned + idx; assigned *a = all_assigned + idx;
if (!a->level) if (!a->level)
continue; continue;
assert (a->level == 1); KISSAT_assert (a->level == 1);
LOG ("analyzing conflict literal %s", LOGLIT (lit)); LOG ("analyzing conflict literal %s", LOGLIT (lit));
kissat_push_analyzed (solver, all_assigned, idx); kissat_push_analyzed (solver, all_assigned, idx);
unresolved++; unresolved++;
@ -429,9 +431,9 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) {
unsigned lit; unsigned lit;
assigned *a; assigned *a;
do { do {
assert (t > BEGIN_ARRAY (solver->trail)); KISSAT_assert (t > BEGIN_ARRAY (solver->trail));
lit = *--t; lit = *--t;
assert (values[lit] > 0); KISSAT_assert (values[lit] > 0);
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
a = all_assigned + idx; a = all_assigned + idx;
} while (!a->analyzed); } while (!a->analyzed);
@ -443,9 +445,9 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) {
if (a->binary) { if (a->binary) {
const unsigned other = a->reason; const unsigned other = a->reason;
LOGBINARY (lit, other, "resolving %s reason", LOGLIT (lit)); LOGBINARY (lit, other, "resolving %s reason", LOGLIT (lit));
assert (other != failed); KISSAT_assert (other != failed);
assert (other != unit); KISSAT_assert (other != unit);
assert (values[other] < 0); KISSAT_assert (values[other] < 0);
if (other == not_failed) { if (other == not_failed) {
LOG ("negation %s of failed literal %s in reason", LOG ("negation %s of failed literal %s in reason",
LOGLIT (not_failed), LOGLIT (failed)); LOGLIT (not_failed), LOGLIT (failed));
@ -453,21 +455,21 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) {
} }
const unsigned idx = IDX (other); const unsigned idx = IDX (other);
assigned *b = all_assigned + idx; assigned *b = all_assigned + idx;
assert (b->level == 1); KISSAT_assert (b->level == 1);
if (!b->analyzed) { if (!b->analyzed) {
LOG ("analyzing reason literal %s", LOGLIT (other)); LOG ("analyzing reason literal %s", LOGLIT (other));
kissat_push_analyzed (solver, all_assigned, idx); kissat_push_analyzed (solver, all_assigned, idx);
unresolved++; unresolved++;
} }
} else { } else {
assert (a->reason != UNIT_REASON); KISSAT_assert (a->reason != UNIT_REASON);
assert (a->reason != DECISION_REASON); KISSAT_assert (a->reason != DECISION_REASON);
const reference ref = a->reason; const reference ref = a->reason;
LOGREF (ref, "resolving %s reason", LOGLIT (lit)); LOGREF (ref, "resolving %s reason", LOGLIT (lit));
clause *reason = kissat_dereference_clause (solver, ref); clause *reason = kissat_dereference_clause (solver, ref);
for (all_literals_in_clause (other, reason)) { for (all_literals_in_clause (other, reason)) {
assert (other != NOT (lit)); KISSAT_assert (other != NOT (lit));
assert (other != failed); KISSAT_assert (other != failed);
if (other == lit) if (other == lit)
continue; continue;
if (other == unit) if (other == unit)
@ -477,12 +479,12 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) {
LOGLIT (not_failed), LOGLIT (failed)); LOGLIT (not_failed), LOGLIT (failed));
goto DONE; goto DONE;
} }
assert (values[other] < 0); KISSAT_assert (values[other] < 0);
const unsigned idx = IDX (other); const unsigned idx = IDX (other);
assigned *b = all_assigned + idx; assigned *b = all_assigned + idx;
if (!b->level) if (!b->level)
continue; continue;
assert (b->level == 1); KISSAT_assert (b->level == 1);
if (b->analyzed) if (b->analyzed)
continue; continue;
LOG ("analyzing reason literal %s", LOGLIT (other)); LOG ("analyzing reason literal %s", LOGLIT (other));
@ -490,7 +492,7 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) {
unresolved++; unresolved++;
} }
} }
assert (unresolved > 0); KISSAT_assert (unresolved > 0);
unresolved--; unresolved--;
LOG ("after resolving %s there are %u unresolved literals", LOG ("after resolving %s there are %u unresolved literals",
LOGLIT (lit), unresolved); LOGLIT (lit), unresolved);
@ -526,7 +528,7 @@ static void update_tier_limits (kissat *solver) {
int kissat_analyze (kissat *solver, clause *conflict) { int kissat_analyze (kissat *solver, clause *conflict) {
if (solver->inconsistent) { if (solver->inconsistent) {
assert (!solver->level); KISSAT_assert (!solver->level);
return 20; return 20;
} }
@ -534,7 +536,7 @@ int kissat_analyze (kissat *solver, clause *conflict) {
if (!solver->probing) { if (!solver->probing) {
update_trail_average (solver); update_trail_average (solver);
update_decision_rate_average (solver); update_decision_rate_average (solver);
#ifndef QUIET #ifndef KISSAT_QUIET
UPDATE_AVERAGE (level, solver->level); UPDATE_AVERAGE (level, solver->level);
#endif #endif
} }
@ -577,3 +579,5 @@ int kissat_analyze (kissat *solver, clause *conflict) {
STOP (analyze); STOP (analyze);
return res > 0 ? 0 : 20; return res > 0 ? 0 : 20;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,10 +3,15 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct clause; struct clause;
struct kissat; struct kissat;
int kissat_analyze (struct kissat *, struct clause *); int kissat_analyze (struct kissat *, struct clause *);
void kissat_reset_only_analyzed_literals (struct kissat *); void kissat_reset_only_analyzed_literals (struct kissat *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -3,6 +3,8 @@
#include "gates.h" #include "gates.h"
#include "inline.h" #include "inline.h"
ABC_NAMESPACE_IMPL_START
bool kissat_find_and_gate (kissat *solver, unsigned lit, bool kissat_find_and_gate (kissat *solver, unsigned lit,
unsigned negative) { unsigned negative) {
if (!GET_OPTION (ands)) if (!GET_OPTION (ands))
@ -27,9 +29,9 @@ bool kissat_find_and_gate (kissat *solver, unsigned lit,
if (watch.type.binary) if (watch.type.binary)
continue; continue;
const reference ref = watch.large.ref; const reference ref = watch.large.ref;
assert (ref < SIZE_STACK (solver->arena)); KISSAT_assert (ref < SIZE_STACK (solver->arena));
clause *c = (clause *) (arena + ref); clause *c = (clause *) (arena + ref);
assert (!c->garbage); KISSAT_assert (!c->garbage);
base = c; base = c;
for (all_literals_in_clause (other, c)) { for (all_literals_in_clause (other, c)) {
if (other == not_lit) if (other == not_lit)
@ -63,7 +65,7 @@ bool kissat_find_and_gate (kissat *solver, unsigned lit,
if (values[other]) if (values[other])
continue; continue;
const unsigned not_other = NOT (other); const unsigned not_other = NOT (other);
assert (marks[not_other]); KISSAT_assert (marks[not_other]);
marks[not_other] = 0; marks[not_other] = 0;
} }
watch tmp = kissat_binary_watch (0); watch tmp = kissat_binary_watch (0);
@ -72,7 +74,7 @@ bool kissat_find_and_gate (kissat *solver, unsigned lit,
if (!watch.type.binary) if (!watch.type.binary)
continue; continue;
const unsigned other = watch.binary.lit; const unsigned other = watch.binary.lit;
assert (!solver->values[other]); KISSAT_assert (!solver->values[other]);
if (marks[other]) { if (marks[other]) {
marks[other] = 0; marks[other] = 0;
continue; continue;
@ -86,3 +88,5 @@ bool kissat_find_and_gate (kissat *solver, unsigned lit,
INC (ands_extracted); INC (ands_extracted);
return true; return true;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,9 +3,14 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
bool kissat_find_and_gate (struct kissat *, unsigned lit, bool kissat_find_and_gate (struct kissat *, unsigned lit,
unsigned negative); unsigned negative);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,8 +1,13 @@
#ifndef _application_h_INCLUDED #ifndef _application_h_INCLUDED
#define _application_h_INCLUDED #define _application_h_INCLUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
int kissat_application (struct kissat *, int argc, char **argv); int kissat_application (struct kissat *, int argc, char **argv);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -3,9 +3,11 @@
#include "logging.h" #include "logging.h"
#include "print.h" #include "print.h"
ABC_NAMESPACE_IMPL_START
static void report_resized (kissat *solver, const char *mode, static void report_resized (kissat *solver, const char *mode,
arena before) { arena before) {
#ifndef QUIET #ifndef KISSAT_QUIET
ward *const old_begin = BEGIN_STACK (before); ward *const old_begin = BEGIN_STACK (before);
ward *const new_begin = BEGIN_STACK (solver->arena); ward *const new_begin = BEGIN_STACK (solver->arena);
const bool moved = (new_begin != old_begin); const bool moved = (new_begin != old_begin);
@ -23,25 +25,25 @@ static void report_resized (kissat *solver, const char *mode,
} }
reference kissat_allocate_clause (kissat *solver, size_t size) { reference kissat_allocate_clause (kissat *solver, size_t size) {
assert (size <= UINT_MAX); KISSAT_assert (size <= UINT_MAX);
const size_t res = SIZE_STACK (solver->arena); const size_t res = SIZE_STACK (solver->arena);
assert (res <= MAX_REF); KISSAT_assert (res <= MAX_REF);
const size_t bytes = kissat_bytes_of_clause (size); const size_t bytes = kissat_bytes_of_clause (size);
assert (kissat_aligned_word (bytes)); KISSAT_assert (kissat_aligned_word (bytes));
const size_t needed = bytes / sizeof (ward); const size_t needed = bytes / sizeof (ward);
assert (needed <= UINT_MAX); KISSAT_assert (needed <= UINT_MAX);
size_t capacity = CAPACITY_STACK (solver->arena); size_t capacity = CAPACITY_STACK (solver->arena);
assert (kissat_is_power_of_two (MAX_ARENA)); KISSAT_assert (kissat_is_power_of_two (MAX_ARENA));
assert (capacity <= MAX_ARENA); KISSAT_assert (capacity <= MAX_ARENA);
size_t available = capacity - res; size_t available = capacity - res;
if (needed > available) { if (needed > available) {
const arena before = solver->arena; const arena before = solver->arena;
do { do {
assert (kissat_is_zero_or_power_of_two (capacity)); KISSAT_assert (kissat_is_zero_or_power_of_two (capacity));
if (capacity == MAX_ARENA) if (capacity == MAX_ARENA)
kissat_fatal ("maximum arena capacity " kissat_fatal ("maximum arena capacity "
"of 2^%u %zu-byte-words %s exhausted" "of 2^%u %zu-byte-words %s exhausted"
#ifdef COMPACT #ifdef KISSAT_COMPACT
" (consider a configuration without '--compact')" " (consider a configuration without '--compact')"
#endif #endif
, ,
@ -55,7 +57,7 @@ reference kissat_allocate_clause (kissat *solver, size_t size) {
INC (arena_resized); INC (arena_resized);
INC (arena_enlarged); INC (arena_enlarged);
report_resized (solver, "enlarged", before); report_resized (solver, "enlarged", before);
assert (capacity <= MAX_ARENA); KISSAT_assert (capacity <= MAX_ARENA);
} }
solver->arena.end += needed; solver->arena.end += needed;
LOG ("allocated clause[%zu] of size %zu bytes %s", res, size, LOG ("allocated clause[%zu] of size %zu bytes %s", res, size,
@ -67,7 +69,7 @@ void kissat_shrink_arena (kissat *solver) {
const arena before = solver->arena; const arena before = solver->arena;
const size_t capacity = CAPACITY_STACK (before); const size_t capacity = CAPACITY_STACK (before);
const size_t size = SIZE_STACK (before); const size_t size = SIZE_STACK (before);
#ifndef QUIET #ifndef KISSAT_QUIET
const size_t capacity_bytes = capacity * sizeof (ward); const size_t capacity_bytes = capacity * sizeof (ward);
kissat_phase (solver, "arena", GET (arena_resized), kissat_phase (solver, "arena", GET (arena_resized),
"capacity of %s %d-byte-words %s", FORMAT_COUNT (capacity), "capacity of %s %d-byte-words %s", FORMAT_COUNT (capacity),
@ -89,7 +91,7 @@ void kissat_shrink_arena (kissat *solver) {
report_resized (solver, "shrunken", before); report_resized (solver, "shrunken", before);
} }
#if !defined(NDEBUG) || defined(LOGGING) #if !defined(KISSAT_NDEBUG) || defined(LOGGING)
bool kissat_clause_in_arena (const kissat *solver, const clause *c) { bool kissat_clause_in_arena (const kissat *solver, const clause *c) {
if (!kissat_aligned_pointer (c)) if (!kissat_aligned_pointer (c))
@ -106,3 +108,5 @@ bool kissat_clause_in_arena (const kissat *solver, const clause *c) {
} }
#endif #endif
ABC_NAMESPACE_IMPL_END

View File

@ -5,7 +5,10 @@
#include "stack.h" #include "stack.h"
#include "utilities.h" #include "utilities.h"
#ifdef COMPACT #include "global.h"
ABC_NAMESPACE_HEADER_START
#ifdef KISSAT_COMPACT
typedef word ward; typedef word ward;
#else #else
typedef w2rd ward; typedef w2rd ward;
@ -29,18 +32,20 @@ struct kissat;
reference kissat_allocate_clause (struct kissat *, size_t size); reference kissat_allocate_clause (struct kissat *, size_t size);
void kissat_shrink_arena (struct kissat *); void kissat_shrink_arena (struct kissat *);
#if !defined(NDEBUG) || defined(LOGGING) #if !defined(KISSAT_NDEBUG) || defined(LOGGING)
bool kissat_clause_in_arena (const struct kissat *, const struct clause *); bool kissat_clause_in_arena (const struct kissat *, const struct clause *);
#endif #endif
static inline word kissat_align_ward (word w) { static inline word kissat_align_ward (word w) {
#ifdef COMPACT #ifdef KISSAT_COMPACT
return kissat_align_word (w); return kissat_align_word (w);
#else #else
return kissat_align_w2rd (w); return kissat_align_w2rd (w);
#endif #endif
} }
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -4,6 +4,9 @@
#include "allocate.h" #include "allocate.h"
#include "stack.h" #include "stack.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
#define ARRAY(TYPE) \ #define ARRAY(TYPE) \
struct { \ struct { \
TYPE *begin; \ TYPE *begin; \
@ -25,11 +28,11 @@
*(A).end++ = (E); \ *(A).end++ = (E); \
} while (0) } while (0)
#define REALLOCATE_ARRAY(A, O, N) \ #define REALLOCATE_ARRAY(T, A, O, N) \
do { \ do { \
const size_t SIZE = SIZE_ARRAY (A); \ const size_t SIZE = SIZE_ARRAY (A); \
(A).begin = \ (A).begin = \
kissat_nrealloc (solver, (A).begin, (O), (N), sizeof *(A).begin); \ (T*) kissat_nrealloc (solver, (A).begin, (O), (N), sizeof *(A).begin); \
(A).end = (A).begin + SIZE; \ (A).end = (A).begin + SIZE; \
} while (0) } while (0)
@ -55,4 +58,6 @@ typedef ARRAY (unsigned) unsigned_array;
// clang-format on // clang-format on
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -5,6 +5,8 @@
#include <limits.h> #include <limits.h>
ABC_NAMESPACE_IMPL_START
void kissat_assign_unit (kissat *solver, unsigned lit, const char *reason) { void kissat_assign_unit (kissat *solver, unsigned lit, const char *reason) {
kissat_assign (solver, solver->probing, 0, false, lit, UNIT_REASON); kissat_assign (solver, solver->probing, 0, false, lit, UNIT_REASON);
LOGUNARY (lit, "assign %s %s", LOGLIT (lit), reason); LOGUNARY (lit, "assign %s %s", LOGLIT (lit), reason);
@ -30,7 +32,7 @@ void kissat_assign_decision (kissat *solver, unsigned lit) {
} }
void kissat_assign_binary (kissat *solver, unsigned lit, unsigned other) { void kissat_assign_binary (kissat *solver, unsigned lit, unsigned other) {
assert (VALUE (other) < 0); KISSAT_assert (VALUE (other) < 0);
assigned *assigned = solver->assigned; assigned *assigned = solver->assigned;
const unsigned other_idx = IDX (other); const unsigned other_idx = IDX (other);
struct assigned *a = assigned + other_idx; struct assigned *a = assigned + other_idx;
@ -46,14 +48,16 @@ void kissat_assign_binary (kissat *solver, unsigned lit, unsigned other) {
void kissat_assign_reference (kissat *solver, unsigned lit, reference ref, void kissat_assign_reference (kissat *solver, unsigned lit, reference ref,
clause *reason) { clause *reason) {
assert (reason == kissat_dereference_clause (solver, ref)); KISSAT_assert (reason == kissat_dereference_clause (solver, ref));
assigned *assigned = solver->assigned; assigned *assigned = solver->assigned;
value *values = solver->values; value *values = solver->values;
const unsigned level = const unsigned level =
kissat_assignment_level (solver, values, assigned, lit, reason); kissat_assignment_level (solver, values, assigned, lit, reason);
assert (level <= solver->level); KISSAT_assert (level <= solver->level);
assert (ref != DECISION_REASON); KISSAT_assert (ref != DECISION_REASON);
assert (ref != UNIT_REASON); KISSAT_assert (ref != UNIT_REASON);
kissat_assign (solver, solver->probing, level, false, lit, ref); kissat_assign (solver, solver->probing, level, false, lit, ref);
LOGREF (ref, "assign %s reason", LOGLIT (lit)); LOGREF (ref, "assign %s reason", LOGLIT (lit));
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,6 +3,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
#define DECISION_REASON UINT_MAX #define DECISION_REASON UINT_MAX
#define UNIT_REASON (DECISION_REASON - 1) #define UNIT_REASON (DECISION_REASON - 1)
@ -26,7 +29,7 @@ struct assigned {
}; };
#define ASSIGNED(LIT) \ #define ASSIGNED(LIT) \
(assert (VALID_INTERNAL_LITERAL (LIT)), solver->assigned + IDX (LIT)) (KISSAT_assert (VALID_INTERNAL_LITERAL (LIT)), solver->assigned + IDX (LIT))
#define LEVEL(LIT) (ASSIGNED (LIT)->level) #define LEVEL(LIT) (ASSIGNED (LIT)->level)
#define TRAIL(LIT) (ASSIGNED (LIT)->trail) #define TRAIL(LIT) (ASSIGNED (LIT)->trail)
@ -34,8 +37,12 @@ struct assigned {
#ifndef FAST_ASSIGN #ifndef FAST_ASSIGN
ABC_NAMESPACE_HEADER_END
#include "reference.h" #include "reference.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
struct clause; struct clause;
@ -52,4 +59,6 @@ void kissat_assign_reference (struct kissat *, unsigned lit, reference,
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,10 +1,19 @@
#ifndef _attribute_h_INCLUDED #ifndef _attribute_h_INCLUDED
#define _attribute_h_INCLUDED #define _attribute_h_INCLUDED
#define ATTRIBUTE_FORMAT(FORMAT_POSITION, VARIADIC_ARGUMENT_POSITION) \ #include "global.h"
__attribute__ (( \ ABC_NAMESPACE_HEADER_START
format (printf, FORMAT_POSITION, VARIADIC_ARGUMENT_POSITION)))
#define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) /* #define ATTRIBUTE_FORMAT(FORMAT_POSITION, VARIADIC_ARGUMENT_POSITION) \ */
/* __attribute__ (( \ */
/* format (printf, FORMAT_POSITION, VARIADIC_ARGUMENT_POSITION))) */
#define ATTRIBUTE_FORMAT(FORMAT_POSITION, VARIADIC_ARGUMENT_POSITION)
/* #define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) */
#define ATTRIBUTE_ALWAYS_INLINE
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,11 +1,13 @@
#include "internal.h" #include "internal.h"
ABC_NAMESPACE_IMPL_START
void kissat_init_averages (kissat *solver, averages *averages) { void kissat_init_averages (kissat *solver, averages *averages) {
if (averages->initialized) if (averages->initialized)
return; return;
#define INIT_EMA(EMA, WINDOW) \ #define INIT_EMA(EMA, WINDOW) \
kissat_init_smooth (solver, &averages->EMA, WINDOW, #EMA) kissat_init_smooth (solver, &averages->EMA, WINDOW, #EMA)
#ifndef QUIET #ifndef KISSAT_QUIET
INIT_EMA (level, GET_OPTION (emaslow)); INIT_EMA (level, GET_OPTION (emaslow));
INIT_EMA (size, GET_OPTION (emaslow)); INIT_EMA (size, GET_OPTION (emaslow));
INIT_EMA (trail, GET_OPTION (emaslow)); INIT_EMA (trail, GET_OPTION (emaslow));
@ -15,3 +17,5 @@ void kissat_init_averages (kissat *solver, averages *averages) {
INIT_EMA (decision_rate, GET_OPTION (emaslow)); INIT_EMA (decision_rate, GET_OPTION (emaslow));
averages->initialized = true; averages->initialized = true;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -5,12 +5,15 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
typedef struct averages averages; typedef struct averages averages;
struct averages { struct averages {
bool initialized; bool initialized;
smooth fast_glue, slow_glue; smooth fast_glue, slow_glue;
#ifndef QUIET #ifndef KISSAT_QUIET
smooth level, size, trail; smooth level, size, trail;
#endif #endif
smooth decision_rate; smooth decision_rate;
@ -30,4 +33,6 @@ void kissat_init_averages (struct kissat *, averages *);
#define UPDATE_AVERAGE(NAME, VALUE) \ #define UPDATE_AVERAGE(NAME, VALUE) \
kissat_update_smooth (solver, &EMA (NAME), VALUE) kissat_update_smooth (solver, &EMA (NAME), VALUE)
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -13,6 +13,8 @@
#include "trail.h" #include "trail.h"
#include "utilities.h" #include "utilities.h"
ABC_NAMESPACE_IMPL_START
static void schedule_backbone_candidates (kissat *solver, static void schedule_backbone_candidates (kissat *solver,
unsigneds *candidates) { unsigneds *candidates) {
flags *flags = solver->flags; flags *flags = solver->flags;
@ -34,7 +36,7 @@ static void schedule_backbone_candidates (kissat *solver,
} else } else
not_rescheduled++; not_rescheduled++;
} }
#ifndef QUIET #ifndef KISSAT_QUIET
const size_t rescheduled = SIZE_STACK (*candidates); const size_t rescheduled = SIZE_STACK (*candidates);
const unsigned active_literals = 2u * solver->active; const unsigned active_literals = 2u * solver->active;
kissat_very_verbose ( kissat_very_verbose (
@ -58,7 +60,7 @@ static void schedule_backbone_candidates (kissat *solver,
} }
} }
} }
#ifndef QUIET #ifndef KISSAT_QUIET
const size_t total = SIZE_STACK (*candidates); const size_t total = SIZE_STACK (*candidates);
kissat_very_verbose (solver, kissat_very_verbose (solver,
"scheduled %zu backbone candidate literals %.0f%%" "scheduled %zu backbone candidate literals %.0f%%"
@ -83,21 +85,21 @@ static void keep_backbone_candidates (kissat *solver,
else else
prioritized += f->backbone0; prioritized += f->backbone0;
} }
assert (prioritized <= remain); KISSAT_assert (prioritized <= remain);
if (!remain) { if (!remain) {
kissat_very_verbose (solver, "no backbone candidates remain"); kissat_very_verbose (solver, "no backbone candidates remain");
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
for (all_variables (idx)) { for (all_variables (idx)) {
const struct flags *f = flags + idx; const struct flags *f = flags + idx;
if (!f->active) if (!f->active)
continue; continue;
assert (!f->backbone0); KISSAT_assert (!f->backbone0);
assert (!f->backbone1); KISSAT_assert (!f->backbone1);
} }
#endif #endif
return; return;
} }
#ifndef QUIET #ifndef KISSAT_QUIET
const size_t active_literals = 2u * solver->active; const size_t active_literals = 2u * solver->active;
#endif #endif
if (prioritized == remain) if (prioritized == remain)
@ -112,10 +114,10 @@ static void keep_backbone_candidates (kissat *solver,
if (!f->active) if (!f->active)
continue; continue;
if (NEGATED (lit)) { if (NEGATED (lit)) {
assert (!f->backbone1); KISSAT_assert (!f->backbone1);
f->backbone1 = true; f->backbone1 = true;
} else { } else {
assert (!f->backbone0); KISSAT_assert (!f->backbone0);
f->backbone0 = true; f->backbone0 = true;
} }
} }
@ -137,8 +139,8 @@ static inline void backbone_assign (kissat *solver, unsigned_array *trail,
value *values, assigned *assigned, value *values, assigned *assigned,
unsigned lit, unsigned reason) { unsigned lit, unsigned reason) {
const unsigned not_lit = NOT (lit); const unsigned not_lit = NOT (lit);
assert (!values[lit]); KISSAT_assert (!values[lit]);
assert (!values[not_lit]); KISSAT_assert (!values[not_lit]);
values[lit] = 1; values[lit] = 1;
values[not_lit] = -1; values[not_lit] = -1;
PUSH_ARRAY (*trail, lit); PUSH_ARRAY (*trail, lit);
@ -154,13 +156,13 @@ backbone_propagate_literal (kissat *solver, const bool stop_early,
unsigned_array *trail, value *values, unsigned_array *trail, value *values,
assigned *assigned, unsigned lit) { assigned *assigned, unsigned lit) {
LOG ("backbone propagating %s", LOGLIT (lit)); LOG ("backbone propagating %s", LOGLIT (lit));
assert (VALID_INTERNAL_LITERAL (lit)); KISSAT_assert (VALID_INTERNAL_LITERAL (lit));
assert (values[lit] > 0); KISSAT_assert (values[lit] > 0);
const unsigned not_lit = NOT (lit); const unsigned not_lit = NOT (lit);
assert (values[not_lit] < 0); KISSAT_assert (values[not_lit] < 0);
assert (not_lit < LITS); KISSAT_assert (not_lit < LITS);
const watches *const watches = all_watches + not_lit; const watches *const watches = all_watches + not_lit;
const watch *const begin_watches = BEGIN_CONST_WATCHES (*watches); const watch *const begin_watches = BEGIN_CONST_WATCHES (*watches);
@ -171,22 +173,22 @@ backbone_propagate_literal (kissat *solver, const bool stop_early,
const watch watch = *p++; const watch watch = *p++;
if (watch.type.binary) { if (watch.type.binary) {
const unsigned other = watch.binary.lit; const unsigned other = watch.binary.lit;
assert (VALID_INTERNAL_LITERAL (other)); KISSAT_assert (VALID_INTERNAL_LITERAL (other));
const value value = values[other]; const value value = values[other];
if (value > 0) if (value > 0)
continue; continue;
if (value < 0) if (value < 0)
return kissat_binary_conflict (solver, not_lit, other); return kissat_binary_conflict (solver, not_lit, other);
assert (!value); KISSAT_assert (!value);
backbone_assign (solver, trail, values, assigned, other, lit); backbone_assign (solver, trail, values, assigned, other, lit);
LOG ("backbone assign %s reason binary clause %s %s", LOGLIT (other), LOG ("backbone assign %s reason binary clause %s %s", LOGLIT (other),
LOGLIT (other), LOGLIT (not_lit)); LOGLIT (other), LOGLIT (not_lit));
} else { } else {
if (stop_early) { if (stop_early) {
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
for (const union watch *q = p + 1; q != end_watches; q++) { for (const union watch *q = p + 1; q != end_watches; q++) {
const union watch watch = *q++; const union watch watch = *q++;
assert (!watch.type.binary); KISSAT_assert (!watch.type.binary);
} }
#endif #endif
break; break;
@ -219,7 +221,7 @@ static inline clause *backbone_propagate (kissat *solver,
conflict = backbone_propagate_literal ( conflict = backbone_propagate_literal (
solver, stop_early, watches, trail, values, assigned, *propagate++); solver, stop_early, watches, trail, values, assigned, *propagate++);
assert (solver->propagate <= propagate); KISSAT_assert (solver->propagate <= propagate);
const unsigned propagated = propagate - solver->propagate; const unsigned propagated = propagate - solver->propagate;
solver->propagate = propagate; solver->propagate = propagate;
@ -240,17 +242,17 @@ static inline void backbone_backtrack (kissat *solver,
unsigned_array *trail, value *values, unsigned_array *trail, value *values,
unsigned *saved, unsigned *saved,
unsigned decision_level) { unsigned decision_level) {
assert (decision_level <= solver->level); KISSAT_assert (decision_level <= solver->level);
unsigned *end_trail = END_ARRAY (*trail); unsigned *end_trail = END_ARRAY (*trail);
assert (saved != end_trail); KISSAT_assert (saved != end_trail);
LOG ("backbone backtracking to trail level %zu and decision level %u", LOG ("backbone backtracking to trail level %zu and decision level %u",
(size_t) (saved - BEGIN_ARRAY (*trail)), decision_level); (size_t) (saved - BEGIN_ARRAY (*trail)), decision_level);
while (saved != end_trail) { while (saved != end_trail) {
const unsigned lit = *--end_trail; const unsigned lit = *--end_trail;
const unsigned not_lit = NOT (lit); const unsigned not_lit = NOT (lit);
LOG ("backbone unassign %s", LOGLIT (lit)); LOG ("backbone unassign %s", LOGLIT (lit));
assert (values[lit] > 0); KISSAT_assert (values[lit] > 0);
assert (values[not_lit] < 0); KISSAT_assert (values[not_lit] < 0);
values[lit] = values[not_lit] = 0; values[lit] = values[not_lit] = 0;
} }
SET_END_OF_ARRAY (solver->trail, saved); SET_END_OF_ARRAY (solver->trail, saved);
@ -259,9 +261,9 @@ static inline void backbone_backtrack (kissat *solver,
} }
static unsigned backbone_analyze (kissat *solver, clause *conflict) { static unsigned backbone_analyze (kissat *solver, clause *conflict) {
assert (conflict); KISSAT_assert (conflict);
LOGCLS (conflict, "backbone analyzing"); LOGCLS (conflict, "backbone analyzing");
assert (conflict->size == 2); KISSAT_assert (conflict->size == 2);
assigned *const assigned = solver->assigned; assigned *const assigned = solver->assigned;
@ -271,7 +273,7 @@ static unsigned backbone_analyze (kissat *solver, clause *conflict) {
const unsigned *t = END_ARRAY (solver->trail); const unsigned *t = END_ARRAY (solver->trail);
for (;;) { for (;;) {
assert (t > BEGIN_ARRAY (solver->trail)); KISSAT_assert (t > BEGIN_ARRAY (solver->trail));
unsigned lit = *--t; unsigned lit = *--t;
@ -282,8 +284,8 @@ static unsigned backbone_analyze (kissat *solver, clause *conflict) {
LOG ("backbone analyzing %s", LOGLIT (lit)); LOG ("backbone analyzing %s", LOGLIT (lit));
const unsigned reason = a->reason; const unsigned reason = a->reason;
assert (reason != UNIT_REASON); KISSAT_assert (reason != UNIT_REASON);
assert (reason != DECISION_REASON); KISSAT_assert (reason != DECISION_REASON);
const unsigned reason_idx = IDX (reason); const unsigned reason_idx = IDX (reason);
const struct assigned *b = assigned + reason_idx; const struct assigned *b = assigned + reason_idx;
if (!b->analyzed) { if (!b->analyzed) {
@ -298,7 +300,7 @@ static unsigned backbone_analyze (kissat *solver, clause *conflict) {
} }
} }
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
static void static void
check_large_clauses_watched_after_binary_clauses (kissat *solver) { check_large_clauses_watched_after_binary_clauses (kissat *solver) {
@ -306,7 +308,7 @@ check_large_clauses_watched_after_binary_clauses (kissat *solver) {
bool large = false; bool large = false;
for (all_binary_blocking_watches (watch, WATCHES (lit))) for (all_binary_blocking_watches (watch, WATCHES (lit)))
if (watch.type.binary) if (watch.type.binary)
assert (!large); KISSAT_assert (!large);
else else
large = true; large = true;
} }
@ -315,7 +317,7 @@ check_large_clauses_watched_after_binary_clauses (kissat *solver) {
#endif #endif
static unsigned compute_backbone (kissat *solver) { static unsigned compute_backbone (kissat *solver) {
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
if (solver->large_clauses_watched_after_binary_clauses) if (solver->large_clauses_watched_after_binary_clauses)
check_large_clauses_watched_after_binary_clauses (solver); check_large_clauses_watched_after_binary_clauses (solver);
#endif #endif
@ -325,26 +327,26 @@ static unsigned compute_backbone (kissat *solver) {
INIT_STACK (candidates); INIT_STACK (candidates);
INIT_STACK (units); INIT_STACK (units);
schedule_backbone_candidates (solver, &candidates); schedule_backbone_candidates (solver, &candidates);
#ifndef QUIET #ifndef KISSAT_QUIET
const size_t scheduled = SIZE_STACK (candidates); const size_t scheduled = SIZE_STACK (candidates);
#endif #endif
#if defined(METRICS) && (!defined(QUIET) || !defined(NDEBUG)) #if defined(METRICS) && (!defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG))
const uint64_t implied_before = solver->statistics.backbone_implied; const uint64_t implied_before = solver->statistics_.backbone_implied;
#endif #endif
unsigned_array *trail = &solver->trail; unsigned_array *trail = &solver->trail;
value *values = solver->values; value *values = solver->values;
flags *flags = solver->flags; flags *flags = solver->flags;
assigned *assigned = solver->assigned; assigned *assigned = solver->assigned;
assert (kissat_propagated (solver)); KISSAT_assert (kissat_propagated (solver));
assert (kissat_trail_flushed (solver)); KISSAT_assert (kissat_trail_flushed (solver));
unsigned inconsistent = INVALID_LIT; unsigned inconsistent = INVALID_LIT;
SET_EFFORT_LIMIT (ticks_limit, backbone, backbone_ticks); SET_EFFORT_LIMIT (ticks_limit, backbone, backbone_ticks);
size_t round_limit = GET_OPTION (backbonerounds); size_t round_limit = GET_OPTION (backbonerounds);
assert (solver->statistics.backbone_computations); KISSAT_assert (solver->statistics_.backbone_computations);
round_limit *= solver->statistics.backbone_computations; round_limit *= solver->statistics_.backbone_computations;
const size_t max_rounds = GET_OPTION (backbonemaxrounds); const size_t max_rounds = GET_OPTION (backbonemaxrounds);
if (round_limit > max_rounds) if (round_limit > max_rounds)
round_limit = max_rounds; round_limit = max_rounds;
@ -356,7 +358,7 @@ static unsigned compute_backbone (kissat *solver) {
kissat_very_verbose (solver, "backbone round limit %zu hit", round); kissat_very_verbose (solver, "backbone round limit %zu hit", round);
break; break;
} }
const uint64_t ticks = solver->statistics.backbone_ticks; const uint64_t ticks = solver->statistics_.backbone_ticks;
if (ticks > ticks_limit) { if (ticks > ticks_limit) {
kissat_very_verbose (solver, kissat_very_verbose (solver,
"backbone ticks limit %" PRIu64 " hit " "backbone ticks limit %" PRIu64 " hit "
@ -365,17 +367,17 @@ static unsigned compute_backbone (kissat *solver) {
break; break;
} }
size_t previous = failed; size_t previous = failed;
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
if (TERMINATED (backbone_terminated_1)) if (TERMINATED (backbone_terminated_1))
break; break;
round++; round++;
INC (backbone_rounds); INC (backbone_rounds);
LOG ("starting backbone round %zu", round); LOG ("starting backbone round %zu", round);
unsigned *const begin_candidates = BEGIN_STACK (candidates); unsigned *const begin_candidates = BEGIN_STACK (candidates);
assert (!solver->level); KISSAT_assert (!solver->level);
#if !defined(QUIET) && defined(METRICS) #if !defined(KISSAT_QUIET) && defined(METRICS)
size_t decisions = 0; size_t decisions = 0;
uint64_t propagated = solver->statistics.backbone_propagations; uint64_t propagated = solver->statistics_.backbone_propagations;
#endif #endif
unsigned active_before = solver->active; unsigned active_before = solver->active;
{ {
@ -383,7 +385,7 @@ static unsigned compute_backbone (kissat *solver) {
const unsigned *p = begin_candidates; const unsigned *p = begin_candidates;
const unsigned *const end_candidates = END_STACK (candidates); const unsigned *const end_candidates = END_STACK (candidates);
while (p != end_candidates) { while (p != end_candidates) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
const unsigned probe = *q++ = *p++; const unsigned probe = *q++ = *p++;
const value value = values[probe]; const value value = values[probe];
if (value > 0) { if (value > 0) {
@ -409,14 +411,14 @@ static unsigned compute_backbone (kissat *solver) {
} }
continue; continue;
} }
if (solver->statistics.backbone_ticks > ticks_limit) if (solver->statistics_.backbone_ticks > ticks_limit)
break; break;
if (TERMINATED (backbone_terminated_2)) if (TERMINATED (backbone_terminated_2))
break; break;
const unsigned level = solver->level; const unsigned level = solver->level;
unsigned *const saved = END_ARRAY (*trail); unsigned *const saved = END_ARRAY (*trail);
assert (level != UINT_MAX); KISSAT_assert (level != UINT_MAX);
#if !defined(QUIET) && defined(METRICS) #if !defined(KISSAT_QUIET) && defined(METRICS)
decisions++; decisions++;
#endif #endif
solver->level = level + 1; solver->level = level + 1;
@ -444,7 +446,7 @@ static unsigned compute_backbone (kissat *solver) {
backbone_assign (solver, trail, values, assigned, not_uip, backbone_assign (solver, trail, values, assigned, not_uip,
UNIT_REASON); UNIT_REASON);
LOG ("backbone forced assign %s", LOGLIT (not_uip)); LOG ("backbone forced assign %s", LOGLIT (not_uip));
assert (failed == SIZE_STACK (units)); KISSAT_assert (failed == SIZE_STACK (units));
conflict = backbone_propagate (solver, trail, values, assigned); conflict = backbone_propagate (solver, trail, values, assigned);
if (conflict) { if (conflict) {
@ -455,7 +457,7 @@ static unsigned compute_backbone (kissat *solver) {
LOG ("propagating backbone forced %s successful", LOGLIT (not_uip)); LOG ("propagating backbone forced %s successful", LOGLIT (not_uip));
} }
#ifndef QUIET #ifndef KISSAT_QUIET
size_t remain = end_candidates - p; size_t remain = end_candidates - p;
if (remain) if (remain)
kissat_extremely_verbose (solver, kissat_extremely_verbose (solver,
@ -497,7 +499,7 @@ static unsigned compute_backbone (kissat *solver) {
LOG ("keeping falsified probe %s", LOGLIT (probe)); LOG ("keeping falsified probe %s", LOGLIT (probe));
continue; continue;
} }
assert (!value); KISSAT_assert (!value);
LOG ("keeping unassigned probe %s", LOGLIT (probe)); LOG ("keeping unassigned probe %s", LOGLIT (probe));
} }
LOG ("flushed %zu probe candidates", LOG ("flushed %zu probe candidates",
@ -515,13 +517,13 @@ static unsigned compute_backbone (kissat *solver) {
if (kissat_probing_propagate (solver, 0, true)) if (kissat_probing_propagate (solver, 0, true))
break; break;
} }
assert (solver->active <= active_before); KISSAT_assert (solver->active <= active_before);
unsigned implied = active_before - solver->active; unsigned implied = active_before - solver->active;
assert (failed <= failed); KISSAT_assert (failed <= failed);
ADD (backbone_implied, implied); ADD (backbone_implied, implied);
#ifndef QUIET #ifndef KISSAT_QUIET
#ifdef METRICS #ifdef METRICS
propagated = solver->statistics.backbone_propagations - propagated; propagated = solver->statistics_.backbone_propagations - propagated;
kissat_very_verbose (solver, kissat_very_verbose (solver,
"backbone round %zu with %zu decisions " "backbone round %zu with %zu decisions "
"(%.2f propagations per decision)", "(%.2f propagations per decision)",
@ -545,7 +547,7 @@ static unsigned compute_backbone (kissat *solver) {
LOG ("assuming forced unit %s", LOGLIT (inconsistent)); LOG ("assuming forced unit %s", LOGLIT (inconsistent));
kissat_learned_unit (solver, inconsistent); kissat_learned_unit (solver, inconsistent);
(void) kissat_probing_propagate (solver, 0, true); (void) kissat_probing_propagate (solver, 0, true);
assert (solver->inconsistent); KISSAT_assert (solver->inconsistent);
} }
RELEASE_STACK (units); RELEASE_STACK (units);
if (solver->inconsistent) if (solver->inconsistent)
@ -553,12 +555,12 @@ static unsigned compute_backbone (kissat *solver) {
"inconsistent binary clauses"); "inconsistent binary clauses");
else { else {
keep_backbone_candidates (solver, &candidates); keep_backbone_candidates (solver, &candidates);
#if defined(METRICS) && (!defined(QUIET) || !defined(NDEBUG)) #if defined(METRICS) && (!defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG))
assert (implied_before <= solver->statistics.backbone_implied); KISSAT_assert (implied_before <= solver->statistics_.backbone_implied);
#endif #endif
#if defined(METRICS) && !defined(QUIET) #if defined(METRICS) && !defined(KISSAT_QUIET)
const uint64_t total_implied = const uint64_t total_implied =
solver->statistics.backbone_implied - implied_before; solver->statistics_.backbone_implied - implied_before;
kissat_phase (solver, "backbone", GET (backbone_computations), kissat_phase (solver, "backbone", GET (backbone_computations),
"found %zu backbone literals %" PRIu64 "found %zu backbone literals %" PRIu64
" implied in %zu rounds", " implied in %zu rounds",
@ -576,23 +578,25 @@ void kissat_binary_clauses_backbone (kissat *solver) {
return; return;
if (TERMINATED (backbone_terminated_3)) if (TERMINATED (backbone_terminated_3))
return; return;
assert (solver->watching); KISSAT_assert (solver->watching);
assert (solver->probing); KISSAT_assert (solver->probing);
assert (!solver->level); KISSAT_assert (!solver->level);
START (backbone); START (backbone);
INC (backbone_computations); INC (backbone_computations);
#if !defined(NDEBUG) || defined(METRICS) #if !defined(KISSAT_NDEBUG) || defined(METRICS)
assert (!solver->backbone_computing); KISSAT_assert (!solver->backbone_computing);
solver->backbone_computing = true; solver->backbone_computing = true;
#endif #endif
#ifndef QUIET #ifndef KISSAT_QUIET
const unsigned failed = const unsigned failed =
#endif #endif
compute_backbone (solver); compute_backbone (solver);
REPORT (!failed, 'b'); REPORT (!failed, 'b');
#if !defined(NDEBUG) || defined(METRICS) #if !defined(KISSAT_NDEBUG) || defined(METRICS)
assert (solver->backbone_computing); KISSAT_assert (solver->backbone_computing);
solver->backbone_computing = false; solver->backbone_computing = false;
#endif #endif
STOP (backbone); STOP (backbone);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,7 +3,12 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
void kissat_binary_clauses_backbone (struct kissat *); void kissat_binary_clauses_backbone (struct kissat *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -8,19 +8,21 @@
#include "propsearch.h" #include "propsearch.h"
#include "trail.h" #include "trail.h"
ABC_NAMESPACE_IMPL_START
static inline void unassign (kissat *solver, value *values, unsigned lit) { static inline void unassign (kissat *solver, value *values, unsigned lit) {
LOG ("unassign %s", LOGLIT (lit)); LOG ("unassign %s", LOGLIT (lit));
assert (values[lit] > 0); KISSAT_assert (values[lit] > 0);
const unsigned not_lit = NOT (lit); const unsigned not_lit = NOT (lit);
values[lit] = values[not_lit] = 0; values[lit] = values[not_lit] = 0;
assert (solver->unassigned < VARS); KISSAT_assert (solver->unassigned < VARS);
solver->unassigned++; solver->unassigned++;
} }
static inline void add_unassigned_variable_back_to_queue (kissat *solver, static inline void add_unassigned_variable_back_to_queue (kissat *solver,
links *links, links *links,
unsigned lit) { unsigned lit) {
assert (!solver->stable); KISSAT_assert (!solver->stable);
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
if (links[idx].stamp > solver->queue.search.stamp) if (links[idx].stamp > solver->queue.search.stamp)
kissat_update_queue (solver, links, idx); kissat_update_queue (solver, links, idx);
@ -29,7 +31,7 @@ static inline void add_unassigned_variable_back_to_queue (kissat *solver,
static inline void add_unassigned_variable_back_to_heap (kissat *solver, static inline void add_unassigned_variable_back_to_heap (kissat *solver,
heap *scores, heap *scores,
unsigned lit) { unsigned lit) {
assert (solver->stable); KISSAT_assert (solver->stable);
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
if (!kissat_heap_contains (scores, idx)) if (!kissat_heap_contains (scores, idx))
kissat_push_heap (solver, scores, idx); kissat_push_heap (solver, scores, idx);
@ -71,7 +73,7 @@ static void kissat_update_target_and_best_phases (kissat *solver) {
void kissat_backtrack_without_updating_phases (kissat *solver, void kissat_backtrack_without_updating_phases (kissat *solver,
unsigned new_level) { unsigned new_level) {
assert (solver->level >= new_level); KISSAT_assert (solver->level >= new_level);
if (solver->level == new_level) if (solver->level == new_level)
return; return;
@ -94,12 +96,12 @@ void kissat_backtrack_without_updating_phases (kissat *solver,
for (const unsigned *p = q; p != old_end; p++) { for (const unsigned *p = q; p != old_end; p++) {
const unsigned lit = *p; const unsigned lit = *p;
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
assert (idx < VARS); KISSAT_assert (idx < VARS);
struct assigned *a = assigned + idx; struct assigned *a = assigned + idx;
const unsigned level = a->level; const unsigned level = a->level;
if (level <= new_level) { if (level <= new_level) {
const unsigned new_trail = q - trail; const unsigned new_trail = q - trail;
assert (new_trail <= a->trail); KISSAT_assert (new_trail <= a->trail);
a->trail = new_trail; a->trail = new_trail;
*q++ = lit; *q++ = lit;
LOG ("reassign %s", LOGLIT (lit)); LOG ("reassign %s", LOGLIT (lit));
@ -115,12 +117,12 @@ void kissat_backtrack_without_updating_phases (kissat *solver,
for (const unsigned *p = q; p != old_end; p++) { for (const unsigned *p = q; p != old_end; p++) {
const unsigned lit = *p; const unsigned lit = *p;
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
assert (idx < VARS); KISSAT_assert (idx < VARS);
struct assigned *a = assigned + idx; struct assigned *a = assigned + idx;
const unsigned level = a->level; const unsigned level = a->level;
if (level <= new_level) { if (level <= new_level) {
const unsigned new_trail = q - trail; const unsigned new_trail = q - trail;
assert (new_trail <= a->trail); KISSAT_assert (new_trail <= a->trail);
a->trail = new_trail; a->trail = new_trail;
*q++ = lit; *q++ = lit;
LOG ("reassign %s", LOGLIT (lit)); LOG ("reassign %s", LOGLIT (lit));
@ -139,12 +141,12 @@ void kissat_backtrack_without_updating_phases (kissat *solver,
LOG ("reassigned %u literals", reassigned); LOG ("reassigned %u literals", reassigned);
(void) unassigned, (void) reassigned; (void) unassigned, (void) reassigned;
assert (new_end <= END_ARRAY (solver->trail)); KISSAT_assert (new_end <= END_ARRAY (solver->trail));
LOG ("propagation will resume at trail position %zu", LOG ("propagation will resume at trail position %zu",
(size_t) (new_end - trail)); (size_t) (new_end - trail));
solver->propagate = new_end; solver->propagate = new_end;
assert (!solver->extended); KISSAT_assert (!solver->extended);
} }
void kissat_backtrack_in_consistent_state (kissat *solver, void kissat_backtrack_in_consistent_state (kissat *solver,
@ -162,16 +164,18 @@ void kissat_backtrack_after_conflict (kissat *solver, unsigned new_level) {
void kissat_backtrack_propagate_and_flush_trail (kissat *solver) { void kissat_backtrack_propagate_and_flush_trail (kissat *solver) {
if (solver->level) { if (solver->level) {
assert (solver->watching); KISSAT_assert (solver->watching);
kissat_backtrack_in_consistent_state (solver, 0); kissat_backtrack_in_consistent_state (solver, 0);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
clause *conflict = clause *conflict =
#endif #endif
solver->probing ? kissat_probing_propagate (solver, 0, true) solver->probing ? kissat_probing_propagate (solver, 0, true)
: kissat_search_propagate (solver); : kissat_search_propagate (solver);
assert (!conflict); KISSAT_assert (!conflict);
} }
assert (kissat_propagated (solver)); KISSAT_assert (kissat_propagated (solver));
assert (kissat_trail_flushed (solver)); KISSAT_assert (kissat_trail_flushed (solver));
} }
ABC_NAMESPACE_IMPL_END

View File

@ -1,6 +1,9 @@
#ifndef _backtrack_h_INCLUDED #ifndef _backtrack_h_INCLUDED
#define _backtrack_h_INCLUDED #define _backtrack_h_INCLUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
void kissat_backtrack_without_updating_phases (struct kissat *, unsigned); void kissat_backtrack_without_updating_phases (struct kissat *, unsigned);
@ -8,4 +11,6 @@ void kissat_backtrack_in_consistent_state (struct kissat *, unsigned);
void kissat_backtrack_after_conflict (struct kissat *, unsigned); void kissat_backtrack_after_conflict (struct kissat *, unsigned);
void kissat_backtrack_propagate_and_flush_trail (struct kissat *); void kissat_backtrack_propagate_and_flush_trail (struct kissat *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -5,6 +5,8 @@
#include <stdio.h> #include <stdio.h>
ABC_NAMESPACE_IMPL_START
const char *kissat_signature (void) { return "kissat-" VERSION; } const char *kissat_signature (void) { return "kissat-" VERSION; }
const char *kissat_id (void) { return ID; } const char *kissat_id (void) { return ID; }
@ -79,3 +81,5 @@ void kissat_banner (const char *prefix, const char *name) {
kissat_build (prefix); kissat_build (prefix);
} }
ABC_NAMESPACE_IMPL_END

10
src/sat/kissat/build.h Normal file
View File

@ -0,0 +1,10 @@
#include "global.h"
ABC_NAMESPACE_HEADER_START
#define VERSION ""
#define COMPILER ""
#define ID ""
#define BUILD ""
#define DIR ""
ABC_NAMESPACE_HEADER_END

View File

@ -9,6 +9,8 @@
#include "rank.h" #include "rank.h"
#include "sort.h" #include "sort.h"
ABC_NAMESPACE_IMPL_START
#define RANK(A) ((A).rank) #define RANK(A) ((A).rank)
#define SMALLER(A, B) (RANK (A) < RANK (B)) #define SMALLER(A, B) (RANK (A) < RANK (B))
@ -32,7 +34,7 @@ void kissat_rescale_scores (kissat *solver) {
kissat_phase (solver, "rescale", GET (rescaled), kissat_phase (solver, "rescale", GET (rescaled),
"maximum score %g increment %g", max_score, solver->scinc); "maximum score %g increment %g", max_score, solver->scinc);
const double rescale = MAX (max_score, solver->scinc); const double rescale = MAX (max_score, solver->scinc);
assert (rescale > 0); KISSAT_assert (rescale > 0);
const double factor = 1.0 / rescale; const double factor = 1.0 / rescale;
kissat_rescale_heap (solver, scores, factor); kissat_rescale_heap (solver, scores, factor);
solver->scinc *= factor; solver->scinc *= factor;
@ -43,7 +45,7 @@ void kissat_rescale_scores (kissat *solver) {
void kissat_bump_score_increment (kissat *solver) { void kissat_bump_score_increment (kissat *solver) {
const double old_scinc = solver->scinc; const double old_scinc = solver->scinc;
const double decay = GET_OPTION (decay) * 1e-3; const double decay = GET_OPTION (decay) * 1e-3;
assert (0 <= decay), assert (decay <= 0.5); KISSAT_assert (0 <= decay), KISSAT_assert (decay <= 0.5);
const double factor = 1.0 / (1.0 - decay); const double factor = 1.0 / (1.0 - decay);
const double new_scinc = old_scinc * factor; const double new_scinc = old_scinc * factor;
LOG ("new score increment %g = %g * %g", new_scinc, factor, old_scinc); LOG ("new score increment %g = %g * %g", new_scinc, factor, old_scinc);
@ -79,7 +81,7 @@ static void bump_analyzed_variable_scores (kissat *solver) {
} }
static void move_analyzed_variables_to_front_of_queue (kissat *solver) { static void move_analyzed_variables_to_front_of_queue (kissat *solver) {
assert (EMPTY_STACK (solver->ranks)); KISSAT_assert (EMPTY_STACK (solver->ranks));
const links *const links = solver->links; const links *const links = solver->links;
for (all_stack (unsigned, idx, solver->analyzed)) { for (all_stack (unsigned, idx, solver->analyzed)) {
// clang-format off // clang-format off
@ -112,9 +114,11 @@ void kissat_bump_analyzed (kissat *solver) {
} }
void kissat_update_scores (kissat *solver) { void kissat_update_scores (kissat *solver) {
assert (solver->stable); KISSAT_assert (solver->stable);
heap *scores = SCORES; heap *scores = SCORES;
for (all_variables (idx)) for (all_variables (idx))
if (ACTIVE (idx) && !kissat_heap_contains (scores, idx)) if (ACTIVE (idx) && !kissat_heap_contains (scores, idx))
kissat_push_heap (solver, scores, idx); kissat_push_heap (solver, scores, idx);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,6 +3,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
void kissat_bump_analyzed (struct kissat *); void kissat_bump_analyzed (struct kissat *);
@ -13,4 +16,6 @@ void kissat_bump_score_increment (struct kissat *);
#define MAX_SCORE 1e150 #define MAX_SCORE 1e150
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,4 +1,6 @@
#ifndef NDEBUG #include "global.h"
#ifndef KISSAT_NDEBUG
#include "check.h" #include "check.h"
#include "error.h" #include "error.h"
@ -187,7 +189,7 @@ void kissat_release_checker (kissat *solver) {
kissat_free (solver, checker, sizeof (struct checker)); kissat_free (solver, checker, sizeof (struct checker));
} }
#ifndef QUIET #ifndef KISSAT_QUIET
#include <inttypes.h> #include <inttypes.h>
@ -234,18 +236,18 @@ void kissat_print_checker_statistics (kissat *solver, bool verbose) {
static unsigned reduce_hash (unsigned hash, unsigned mod) { static unsigned reduce_hash (unsigned hash, unsigned mod) {
if (mod < 2) if (mod < 2)
return 0; return 0;
assert (mod); KISSAT_assert (mod);
unsigned res = hash; unsigned res = hash;
for (unsigned shift = 16, mask = 0xffff; res >= mod; for (unsigned shift = 16, mask = 0xffff; res >= mod;
mask >>= (shift >>= 1)) mask >>= (shift >>= 1))
res = (res >> shift) & mask; res = (res >> shift) & mask;
assert (res < mod); KISSAT_assert (res < mod);
return res; return res;
} }
static void resize_hash (kissat *solver, checker *checker) { static void resize_hash (kissat *solver, checker *checker) {
const unsigned old_hashed = checker->hashed; const unsigned old_hashed = checker->hashed;
assert (old_hashed < MAX_SIZE); KISSAT_assert (old_hashed < MAX_SIZE);
const unsigned new_hashed = old_hashed ? 2 * old_hashed : 1; const unsigned new_hashed = old_hashed ? 2 * old_hashed : 1;
bucket **table = kissat_calloc (solver, new_hashed, sizeof (bucket *)); bucket **table = kissat_calloc (solver, new_hashed, sizeof (bucket *));
bucket **old_table = checker->table; bucket **old_table = checker->table;
@ -264,7 +266,7 @@ static void resize_hash (kissat *solver, checker *checker) {
static bucket *new_line (kissat *solver, checker *checker, unsigned size, static bucket *new_line (kissat *solver, checker *checker, unsigned size,
unsigned hash) { unsigned hash) {
bucket *res = kissat_malloc (solver, bytes_line (size)); bucket *res = (bucket*)kissat_malloc (solver, bytes_line (size));
res->next = 0; res->next = 0;
res->size = size; res->size = size;
res->hash = hash; res->hash = hash;
@ -291,18 +293,18 @@ static void checker_assign (kissat *solver, checker *checker, unsigned lit,
#else #else
(void) bucket; (void) bucket;
#endif #endif
assert (VALID_CHECKER_LIT (lit)); KISSAT_assert (VALID_CHECKER_LIT (lit));
const unsigned not_lit = lit ^ 1; const unsigned not_lit = lit ^ 1;
signed char *values = checker->values; signed char *values = checker->values;
assert (!values[lit]); KISSAT_assert (!values[lit]);
assert (!values[not_lit]); KISSAT_assert (!values[not_lit]);
values[lit] = 1; values[lit] = 1;
values[not_lit] = -1; values[not_lit] = -1;
PUSH_STACK (checker->trail, lit); PUSH_STACK (checker->trail, lit);
} }
static buckets *checker_watches (checker *checker, unsigned lit) { static buckets *checker_watches (checker *checker, unsigned lit) {
assert (VALID_CHECKER_LIT (lit)); KISSAT_assert (VALID_CHECKER_LIT (lit));
return checker->watches + lit; return checker->watches + lit;
} }
@ -325,7 +327,7 @@ static void unwatch_checker_literal (kissat *solver, checker *checker,
static void unwatch_line (kissat *solver, checker *checker, static void unwatch_line (kissat *solver, checker *checker,
bucket *bucket) { bucket *bucket) {
assert (bucket->size > 1); KISSAT_assert (bucket->size > 1);
const unsigned *const lits = bucket->lits; const unsigned *const lits = bucket->lits;
unwatch_checker_literal (solver, checker, bucket, lits[0]); unwatch_checker_literal (solver, checker, bucket, lits[0]);
unwatch_checker_literal (solver, checker, bucket, lits[1]); unwatch_checker_literal (solver, checker, bucket, lits[1]);
@ -474,7 +476,7 @@ static void use_line (kissat *solver, checker *checker) {
static void insert_imported (kissat *solver, checker *checker, static void insert_imported (kissat *solver, checker *checker,
unsigned hash) { unsigned hash) {
size_t size = SIZE_STACK (checker->imported); size_t size = SIZE_STACK (checker->imported);
assert (size <= UINT_MAX); KISSAT_assert (size <= UINT_MAX);
if (checker->buckets == checker->hashed) if (checker->buckets == checker->hashed)
resize_hash (solver, checker); resize_hash (solver, checker);
bucket *bucket = new_line (solver, checker, size, hash); bucket *bucket = new_line (solver, checker, size, hash);
@ -485,8 +487,8 @@ static void insert_imported (kissat *solver, checker *checker,
LOGLINE3 ("inserted checker"); LOGLINE3 ("inserted checker");
const unsigned *const lits = BEGIN_STACK (checker->imported); const unsigned *const lits = BEGIN_STACK (checker->imported);
const signed char *values = checker->values; const signed char *values = checker->values;
assert (!values[lits[0]]); KISSAT_assert (!values[lits[0]]);
assert (!values[lits[1]]); KISSAT_assert (!values[lits[1]]);
watch_checker_literal (solver, checker, bucket, lits[0]); watch_checker_literal (solver, checker, bucket, lits[0]);
watch_checker_literal (solver, checker, bucket, lits[1]); watch_checker_literal (solver, checker, bucket, lits[1]);
checker->buckets++; checker->buckets++;
@ -525,11 +527,11 @@ static void resize_checker (kissat *solver, checker *checker,
const unsigned vars = checker->vars; const unsigned vars = checker->vars;
const unsigned size = checker->size; const unsigned size = checker->size;
if (new_vars > size) { if (new_vars > size) {
assert (new_vars <= MAX_SIZE); KISSAT_assert (new_vars <= MAX_SIZE);
unsigned new_size = size ? 2 * size : 1; unsigned new_size = size ? 2 * size : 1;
while (new_size < new_vars) while (new_size < new_vars)
new_size *= 2; new_size *= 2;
assert (new_size <= MAX_SIZE); KISSAT_assert (new_size <= MAX_SIZE);
LOG3 ("resizing checker form %u to %u", size, new_size); LOG3 ("resizing checker form %u to %u", size, new_size);
const unsigned size2 = 2 * size; const unsigned size2 = 2 * size;
const unsigned new_size2 = 2 * new_size; const unsigned new_size2 = 2 * new_size;
@ -555,7 +557,7 @@ static void resize_checker (kissat *solver, checker *checker,
const unsigned vars2 = 2 * vars; const unsigned vars2 = 2 * vars;
const unsigned new_vars2 = 2 * new_vars; const unsigned new_vars2 = 2 * new_vars;
const unsigned delta2 = 2 * delta; const unsigned delta2 = 2 * delta;
assert (delta2 == new_vars2 - vars2); KISSAT_assert (delta2 == new_vars2 - vars2);
memset (checker->watches + vars2, 0, delta2 * sizeof *checker->watches); memset (checker->watches + vars2, 0, delta2 * sizeof *checker->watches);
memset (checker->marks + vars2, 0, delta2); memset (checker->marks + vars2, 0, delta2);
memset (checker->used + vars2, 0, delta2); memset (checker->used + vars2, 0, delta2);
@ -566,11 +568,11 @@ static void resize_checker (kissat *solver, checker *checker,
static inline unsigned static inline unsigned
import_external_checker (kissat *solver, checker *checker, int elit) { import_external_checker (kissat *solver, checker *checker, int elit) {
assert (elit); KISSAT_assert (elit);
const unsigned var = ABS (elit) - 1; const unsigned var = ABS (elit) - 1;
if (var >= checker->vars) if (var >= checker->vars)
resize_checker (solver, checker, var + 1); resize_checker (solver, checker, var + 1);
assert (var < checker->vars); KISSAT_assert (var < checker->vars);
return 2 * var + (elit < 0); return 2 * var + (elit < 0);
} }
@ -581,7 +583,7 @@ import_internal_checker (kissat *solver, checker *checker, unsigned ilit) {
} }
static inline int export_checker (checker *checker, unsigned ilit) { static inline int export_checker (checker *checker, unsigned ilit) {
assert (ilit <= 2 * checker->vars); KISSAT_assert (ilit <= 2 * checker->vars);
return (1 + (ilit >> 1)) * ((ilit & 1) ? -1 : 1); return (1 + (ilit >> 1)) * ((ilit & 1) ? -1 : 1);
} }
@ -619,7 +621,7 @@ static void remove_line (kissat *solver, checker *checker, size_t size) {
unwatch_line (solver, checker, bucket); unwatch_line (solver, checker, bucket);
LOGLINE3 ("removed checker"); LOGLINE3 ("removed checker");
kissat_free (solver, bucket, bytes_line (size)); kissat_free (solver, bucket, bytes_line (size));
assert (checker->buckets > 0); KISSAT_assert (checker->buckets > 0);
checker->buckets--; checker->buckets--;
checker->removed++; checker->removed++;
} }
@ -639,7 +641,7 @@ static void import_external_literals (kissat *solver, checker *checker,
static void import_internal_literals (kissat *solver, checker *checker, static void import_internal_literals (kissat *solver, checker *checker,
size_t size, const unsigned *ilits) { size_t size, const unsigned *ilits) {
assert (size <= UINT_MAX); KISSAT_assert (size <= UINT_MAX);
CLEAR_STACK (checker->imported); CLEAR_STACK (checker->imported);
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
const unsigned ilit = ilits[i]; const unsigned ilit = ilits[i];
@ -680,8 +682,8 @@ static bool checker_propagate (kissat *solver, checker *checker) {
const unsigned lit = PEEK_STACK (checker->trail, propagated); const unsigned lit = PEEK_STACK (checker->trail, propagated);
const unsigned not_lit = lit ^ 1; const unsigned not_lit = lit ^ 1;
LOG3 ("checker propagate %u", lit); LOG3 ("checker propagate %u", lit);
assert (values[lit] > 0); KISSAT_assert (values[lit] > 0);
assert (values[not_lit] < 0); KISSAT_assert (values[not_lit] < 0);
propagated++; propagated++;
buckets *buckets = checker_watches (checker, not_lit); buckets *buckets = checker_watches (checker, not_lit);
bucket **begin_of_lines = BEGIN_STACK (*buckets), **q = begin_of_lines; bucket **begin_of_lines = BEGIN_STACK (*buckets), **q = begin_of_lines;
@ -774,10 +776,10 @@ static void checker_backtrack (checker *checker, unsigned saved) {
signed char *values = checker->values; signed char *values = checker->values;
while (p != begin) { while (p != begin) {
const unsigned lit = *--p; const unsigned lit = *--p;
assert (VALID_CHECKER_LIT (lit)); KISSAT_assert (VALID_CHECKER_LIT (lit));
const unsigned not_lit = lit ^ 1; const unsigned not_lit = lit ^ 1;
assert (values[lit] > 0); KISSAT_assert (values[lit] > 0);
assert (values[not_lit] < 0); KISSAT_assert (values[not_lit] < 0);
values[lit] = values[not_lit] = 0; values[lit] = values[not_lit] = 0;
} }
checker->propagated = saved; checker->propagated = saved;
@ -787,7 +789,7 @@ static void checker_backtrack (checker *checker, unsigned saved) {
static bool checker_blocked_literal (kissat *solver, checker *checker, static bool checker_blocked_literal (kissat *solver, checker *checker,
unsigned lit) { unsigned lit) {
signed char *values = checker->values; signed char *values = checker->values;
assert (values[lit] < 0); KISSAT_assert (values[lit] < 0);
const unsigned not_lit = lit ^ 1; const unsigned not_lit = lit ^ 1;
if (checker->large[not_lit]) if (checker->large[not_lit])
return false; return false;
@ -840,7 +842,7 @@ static void check_line (kissat *solver, checker *checker) {
bool satisfied = false, pure = false; bool satisfied = false, pure = false;
unsigned decisions = 0, prev = INVALID_LIT; unsigned decisions = 0, prev = INVALID_LIT;
for (all_stack (unsigned, lit, checker->imported)) { for (all_stack (unsigned, lit, checker->imported)) {
assert (prev != lit); KISSAT_assert (prev != lit);
prev = lit; prev = lit;
signed char lit_value = values[lit]; signed char lit_value = values[lit];
if (lit_value < 0) if (lit_value < 0)
@ -896,7 +898,7 @@ void kissat_add_unchecked_internal (kissat *solver, size_t size,
LOGUNSIGNEDS3 (size, lits, "adding unchecked internal checker"); LOGUNSIGNEDS3 (size, lits, "adding unchecked internal checker");
checker *checker = solver->checker; checker *checker = solver->checker;
checker->unchecked++; checker->unchecked++;
assert (size <= UINT_MAX); KISSAT_assert (size <= UINT_MAX);
import_internal_literals (solver, checker, size, lits); import_internal_literals (solver, checker, size, lits);
insert_imported_if_not_simplified (solver, checker); insert_imported_if_not_simplified (solver, checker);
} }
@ -904,8 +906,8 @@ void kissat_add_unchecked_internal (kissat *solver, size_t size,
void kissat_check_and_add_binary (kissat *solver, unsigned a, unsigned b) { void kissat_check_and_add_binary (kissat *solver, unsigned a, unsigned b) {
LOGBINARY3 (a, b, "checking and adding internal checker"); LOGBINARY3 (a, b, "checking and adding internal checker");
checker *checker = solver->checker; checker *checker = solver->checker;
assert (VALID_INTERNAL_LITERAL (a)); KISSAT_assert (VALID_INTERNAL_LITERAL (a));
assert (VALID_INTERNAL_LITERAL (b)); KISSAT_assert (VALID_INTERNAL_LITERAL (b));
import_binary (solver, checker, a, b); import_binary (solver, checker, a, b);
check_line (solver, checker); check_line (solver, checker);
insert_imported_if_not_simplified (solver, checker); insert_imported_if_not_simplified (solver, checker);
@ -939,7 +941,7 @@ void kissat_check_and_add_internal (kissat *solver, size_t size,
void kissat_check_and_add_unit (kissat *solver, unsigned a) { void kissat_check_and_add_unit (kissat *solver, unsigned a) {
LOG3 ("checking and adding internal checker internal unit %u", a); LOG3 ("checking and adding internal checker internal unit %u", a);
checker *checker = solver->checker; checker *checker = solver->checker;
assert (VALID_INTERNAL_LITERAL (a)); KISSAT_assert (VALID_INTERNAL_LITERAL (a));
import_internal_unit (solver, checker, a); import_internal_unit (solver, checker, a);
check_line (solver, checker); check_line (solver, checker);
insert_imported_if_not_simplified (solver, checker); insert_imported_if_not_simplified (solver, checker);
@ -969,8 +971,8 @@ void kissat_check_shrink_clause (kissat *solver, clause *c, unsigned remove,
void kissat_remove_checker_binary (kissat *solver, unsigned a, unsigned b) { void kissat_remove_checker_binary (kissat *solver, unsigned a, unsigned b) {
LOGBINARY3 (a, b, "removing internal checker"); LOGBINARY3 (a, b, "removing internal checker");
checker *checker = solver->checker; checker *checker = solver->checker;
assert (VALID_INTERNAL_LITERAL (a)); KISSAT_assert (VALID_INTERNAL_LITERAL (a));
assert (VALID_INTERNAL_LITERAL (b)); KISSAT_assert (VALID_INTERNAL_LITERAL (b));
import_binary (solver, checker, a, b); import_binary (solver, checker, a, b);
remove_line_if_not_redundant (solver, checker); remove_line_if_not_redundant (solver, checker);
} }

View File

@ -1,11 +1,14 @@
#ifndef _check_h_INCLUDED #ifndef _check_h_INCLUDED
#define _check_h_INCLUDED #define _check_h_INCLUDED
#ifndef NDEBUG
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
#ifndef KISSAT_NDEBUG
struct kissat; struct kissat;
void kissat_check_satisfying_assignment (struct kissat *); void kissat_check_satisfying_assignment (struct kissat *);
@ -17,7 +20,7 @@ struct clause;
void kissat_init_checker (struct kissat *); void kissat_init_checker (struct kissat *);
void kissat_release_checker (struct kissat *); void kissat_release_checker (struct kissat *);
#ifndef QUIET #ifndef KISSAT_QUIET
void kissat_print_checker_statistics (struct kissat *, bool verbose); void kissat_print_checker_statistics (struct kissat *, bool verbose);
#endif #endif
@ -172,4 +175,7 @@ void kissat_remove_checker_internal (struct kissat *, size_t,
} while (0) } while (0)
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -2,8 +2,10 @@
#include "internal.h" #include "internal.h"
#include "print.h" #include "print.h"
ABC_NAMESPACE_IMPL_START
void kissat_classify (struct kissat *solver) { void kissat_classify (struct kissat *solver) {
statistics *s = &solver->statistics; statistics *s = &solver->statistics_;
uint64_t clauses = s->clauses_binary + s->clauses_irredundant; uint64_t clauses = s->clauses_binary + s->clauses_irredundant;
unsigned small_clauses_limit = GET_OPTION (smallclauses); unsigned small_clauses_limit = GET_OPTION (smallclauses);
if (clauses <= small_clauses_limit) { if (clauses <= small_clauses_limit) {
@ -26,3 +28,5 @@ void kissat_classify (struct kissat *solver) {
solver, "formula classified to have a %s binary clauses fraction", solver, "formula classified to have a %s binary clauses fraction",
solver->classification.bigbig ? "large" : "small"); solver->classification.bigbig ? "large" : "small");
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,6 +3,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
struct classification { struct classification {
@ -14,4 +17,6 @@ typedef struct classification classification;
void kissat_classify (struct kissat *); void kissat_classify (struct kissat *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -4,6 +4,8 @@
#include <string.h> #include <string.h>
ABC_NAMESPACE_IMPL_START
static void inc_clause (kissat *solver, bool original, bool redundant, static void inc_clause (kissat *solver, bool original, bool redundant,
bool binary) { bool binary) {
if (binary) if (binary)
@ -28,8 +30,8 @@ static void dec_clause (kissat *solver, bool redundant, bool binary) {
static void init_clause (clause *res, bool redundant, unsigned glue, static void init_clause (clause *res, bool redundant, unsigned glue,
unsigned size) { unsigned size) {
assert (size <= UINT_MAX); KISSAT_assert (size <= UINT_MAX);
assert (redundant || !glue); KISSAT_assert (redundant || !glue);
glue = MIN (MAX_GLUE, glue); glue = MIN (MAX_GLUE, glue);
@ -64,8 +66,8 @@ void kissat_connect_clause (kissat *solver, clause *c) {
static reference new_binary_clause (kissat *solver, bool original, static reference new_binary_clause (kissat *solver, bool original,
bool watch, unsigned first, bool watch, unsigned first,
unsigned second) { unsigned second) {
assert (first != second); KISSAT_assert (first != second);
assert (first != NOT (second)); KISSAT_assert (first != NOT (second));
if (watch) if (watch)
kissat_watch_binary (solver, first, second); kissat_watch_binary (solver, first, second);
kissat_mark_added_literal (solver, first); kissat_mark_added_literal (solver, first);
@ -81,7 +83,7 @@ static reference new_binary_clause (kissat *solver, bool original,
static reference new_large_clause (kissat *solver, bool original, static reference new_large_clause (kissat *solver, bool original,
bool redundant, unsigned glue, bool redundant, unsigned glue,
unsigned size, unsigned *lits) { unsigned size, unsigned *lits) {
assert (size > 2); KISSAT_assert (size > 2);
reference res = kissat_allocate_clause (solver, size); reference res = kissat_allocate_clause (solver, size);
clause *c = kissat_unchecked_dereference_clause (solver, res); clause *c = kissat_unchecked_dereference_clause (solver, res);
init_clause (c, redundant, glue, size); init_clause (c, redundant, glue, size);
@ -148,19 +150,19 @@ reference kissat_new_redundant_clause (kissat *solver, unsigned glue) {
} }
static void mark_clause_as_garbage (kissat *solver, clause *c) { static void mark_clause_as_garbage (kissat *solver, clause *c) {
assert (!c->garbage); KISSAT_assert (!c->garbage);
LOGCLS (c, "garbage"); LOGCLS (c, "garbage");
if (!c->redundant) if (!c->redundant)
kissat_mark_removed_literals (solver, c->size, c->lits); kissat_mark_removed_literals (solver, c->size, c->lits);
REMOVE_CHECKER_CLAUSE (c); REMOVE_CHECKER_CLAUSE (c);
DELETE_CLAUSE_FROM_PROOF (c); DELETE_CLAUSE_FROM_PROOF (c);
assert (c->size > 2); KISSAT_assert (c->size > 2);
dec_clause (solver, c->redundant, false); dec_clause (solver, c->redundant, false);
c->garbage = true; c->garbage = true;
} }
void kissat_mark_clause_as_garbage (kissat *solver, clause *c) { void kissat_mark_clause_as_garbage (kissat *solver, clause *c) {
assert (!c->garbage); KISSAT_assert (!c->garbage);
mark_clause_as_garbage (solver, c); mark_clause_as_garbage (solver, c);
size_t bytes = kissat_actual_bytes_of_clause (c); size_t bytes = kissat_actual_bytes_of_clause (c);
ADD (arena_garbage, bytes); ADD (arena_garbage, bytes);
@ -168,8 +170,8 @@ void kissat_mark_clause_as_garbage (kissat *solver, clause *c) {
clause *kissat_delete_clause (kissat *solver, clause *c) { clause *kissat_delete_clause (kissat *solver, clause *c) {
LOGCLS (c, "delete"); LOGCLS (c, "delete");
assert (c->size > 2); KISSAT_assert (c->size > 2);
assert (c->garbage); KISSAT_assert (c->garbage);
size_t bytes = kissat_actual_bytes_of_clause (c); size_t bytes = kissat_actual_bytes_of_clause (c);
SUB (arena_garbage, bytes); SUB (arena_garbage, bytes);
INC (clauses_deleted); INC (clauses_deleted);
@ -185,3 +187,5 @@ void kissat_delete_binary (kissat *solver, unsigned a, unsigned b) {
dec_clause (solver, false, true); dec_clause (solver, false, true);
INC (clauses_deleted); INC (clauses_deleted);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -8,6 +8,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
typedef struct clause clause; typedef struct clause clause;
#define LD_MAX_GLUE 19 #define LD_MAX_GLUE 19
@ -87,4 +90,6 @@ void kissat_delete_binary (struct kissat *, unsigned, unsigned);
void kissat_mark_clause_as_garbage (struct kissat *, clause *); void kissat_mark_clause_as_garbage (struct kissat *, clause *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -13,10 +13,12 @@
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
ABC_NAMESPACE_IMPL_START
static void flush_watched_clauses_by_literal (kissat *solver, unsigned lit, static void flush_watched_clauses_by_literal (kissat *solver, unsigned lit,
bool compact, bool compact,
reference start) { reference start) {
assert (start != INVALID_REF); KISSAT_assert (start != INVALID_REF);
const value *const values = solver->values; const value *const values = solver->values;
const assigned *const all_assigned = solver->assigned; const assigned *const all_assigned = solver->assigned;
@ -44,8 +46,8 @@ static void flush_watched_clauses_by_literal (kissat *solver, unsigned lit,
if (lit < other) if (lit < other)
kissat_delete_binary (solver, lit, other); kissat_delete_binary (solver, lit, other);
} else { } else {
assert (!lit_fixed); KISSAT_assert (!lit_fixed);
assert (!other_fixed); KISSAT_assert (!other_fixed);
{ {
head.binary.lit = mother; head.binary.lit = mother;
@ -59,7 +61,7 @@ static void flush_watched_clauses_by_literal (kissat *solver, unsigned lit,
} }
} }
} else { } else {
assert (solver->watching); KISSAT_assert (solver->watching);
const watch tail = *p++; const watch tail = *p++;
if (!lit_fixed) { if (!lit_fixed) {
const reference ref = tail.large.ref; const reference ref = tail.large.ref;
@ -71,7 +73,7 @@ static void flush_watched_clauses_by_literal (kissat *solver, unsigned lit,
} }
} }
assert (!lit_fixed || q == begin); KISSAT_assert (!lit_fixed || q == begin);
SET_END_OF_WATCHES (*lit_watches, q); SET_END_OF_WATCHES (*lit_watches, q);
#ifdef LOGGING #ifdef LOGGING
const size_t size_lit_watches = SIZE_WATCHES (*lit_watches); const size_t size_lit_watches = SIZE_WATCHES (*lit_watches);
@ -84,25 +86,25 @@ static void flush_watched_clauses_by_literal (kissat *solver, unsigned lit,
return; return;
watches *mlit_watches = &WATCHES (mlit); watches *mlit_watches = &WATCHES (mlit);
#if defined(LOGGING) || !defined(NDEBUG) #if defined(LOGGING) || !defined(KISSAT_NDEBUG)
const size_t size_mlit_watches = SIZE_WATCHES (*mlit_watches); const size_t size_mlit_watches = SIZE_WATCHES (*mlit_watches);
#endif #endif
if (lit_fixed) if (lit_fixed)
assert (!size_mlit_watches); KISSAT_assert (!size_mlit_watches);
else if (mlit < lit) { else if (mlit < lit) {
assert (mlit != INVALID_LIT); KISSAT_assert (mlit != INVALID_LIT);
assert (mlit < lit); KISSAT_assert (mlit < lit);
*mlit_watches = *lit_watches; *mlit_watches = *lit_watches;
LOG ("copied watches[%u] = watches[%u] (size %zu)", mlit, lit, LOG ("copied watches[%u] = watches[%u] (size %zu)", mlit, lit,
size_mlit_watches); size_mlit_watches);
memset (lit_watches, 0, sizeof *lit_watches); memset (lit_watches, 0, sizeof *lit_watches);
} else } else
assert (mlit == lit); KISSAT_assert (mlit == lit);
} }
static void flush_all_watched_clauses (kissat *solver, bool compact, static void flush_all_watched_clauses (kissat *solver, bool compact,
reference start) { reference start) {
assert (solver->watching); KISSAT_assert (solver->watching);
LOG ("starting to flush watches at clause[%" REFERENCE_FORMAT "]", start); LOG ("starting to flush watches at clause[%" REFERENCE_FORMAT "]", start);
for (all_variables (idx)) { for (all_variables (idx)) {
const unsigned lit = LIT (idx); const unsigned lit = LIT (idx);
@ -114,12 +116,12 @@ static void flush_all_watched_clauses (kissat *solver, bool compact,
static void update_large_reason (kissat *solver, assigned *assigned, static void update_large_reason (kissat *solver, assigned *assigned,
unsigned forced, clause *dst) { unsigned forced, clause *dst) {
assert (dst->reason); KISSAT_assert (dst->reason);
assert (forced != INVALID_LIT); KISSAT_assert (forced != INVALID_LIT);
reference dst_ref = kissat_reference_clause (solver, dst); reference dst_ref = kissat_reference_clause (solver, dst);
const unsigned forced_idx = IDX (forced); const unsigned forced_idx = IDX (forced);
struct assigned *a = assigned + forced_idx; struct assigned *a = assigned + forced_idx;
assert (!a->binary); KISSAT_assert (!a->binary);
if (a->reason != dst_ref) { if (a->reason != dst_ref) {
LOG ("reason reference %u of %s updated to %u", a->reason, LOG ("reason reference %u of %s updated to %u", a->reason,
LOGLIT (forced), dst_ref); LOGLIT (forced), dst_ref);
@ -129,7 +131,7 @@ static void update_large_reason (kissat *solver, assigned *assigned,
} }
static unsigned get_forced (const value *values, clause *dst) { static unsigned get_forced (const value *values, clause *dst) {
assert (dst->reason); KISSAT_assert (dst->reason);
unsigned forced = INVALID_LIT; unsigned forced = INVALID_LIT;
for (all_literals_in_clause (lit, dst)) { for (all_literals_in_clause (lit, dst)) {
const value value = values[lit]; const value value = values[lit];
@ -138,7 +140,7 @@ static unsigned get_forced (const value *values, clause *dst) {
forced = lit; forced = lit;
break; break;
} }
assert (forced != INVALID_LIT); KISSAT_assert (forced != INVALID_LIT);
return forced; return forced;
} }
@ -181,9 +183,9 @@ static void update_last_irredundant (kissat *solver, const clause *end,
} }
void kissat_update_first_reducible (kissat *solver, clause *reducible) { void kissat_update_first_reducible (kissat *solver, clause *reducible) {
assert (reducible); KISSAT_assert (reducible);
assert (!reducible->garbage); KISSAT_assert (!reducible->garbage);
assert (reducible->redundant); KISSAT_assert (reducible->redundant);
if (solver->first_reducible != INVALID_REF) { if (solver->first_reducible != INVALID_REF) {
reference ref = kissat_reference_clause (solver, reducible); reference ref = kissat_reference_clause (solver, reducible);
if (ref >= solver->first_reducible) { if (ref >= solver->first_reducible) {
@ -196,9 +198,9 @@ void kissat_update_first_reducible (kissat *solver, clause *reducible) {
} }
void kissat_update_last_irredundant (kissat *solver, clause *irredundant) { void kissat_update_last_irredundant (kissat *solver, clause *irredundant) {
assert (irredundant); KISSAT_assert (irredundant);
assert (!irredundant->garbage); KISSAT_assert (!irredundant->garbage);
assert (!irredundant->redundant); KISSAT_assert (!irredundant->redundant);
if (solver->last_irredundant != INVALID_REF) { if (solver->last_irredundant != INVALID_REF) {
reference ref = kissat_reference_clause (solver, irredundant); reference ref = kissat_reference_clause (solver, irredundant);
if (ref <= solver->last_irredundant) { if (ref <= solver->last_irredundant) {
@ -213,10 +215,10 @@ void kissat_update_last_irredundant (kissat *solver, clause *irredundant) {
static void move_redundant_clauses_to_the_end (kissat *solver, static void move_redundant_clauses_to_the_end (kissat *solver,
reference ref) { reference ref) {
INC (moved); INC (moved);
assert (ref != INVALID_REF); KISSAT_assert (ref != INVALID_REF);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
const size_t size = SIZE_STACK (solver->arena); const size_t size = SIZE_STACK (solver->arena);
assert ((size_t) ref <= size); KISSAT_assert ((size_t) ref <= size);
#endif #endif
clause *begin = (clause *) (BEGIN_STACK (solver->arena) + ref); clause *begin = (clause *) (BEGIN_STACK (solver->arena) + ref);
clause *end = (clause *) END_STACK (solver->arena); clause *end = (clause *) END_STACK (solver->arena);
@ -234,7 +236,7 @@ static void move_redundant_clauses_to_the_end (kissat *solver,
clause *last_irredundant = kissat_last_irredundant_clause (solver); clause *last_irredundant = kissat_last_irredundant_clause (solver);
while (p != end) { while (p != end) {
assert (!p->shrunken); KISSAT_assert (!p->shrunken);
size_t bytes = kissat_bytes_of_clause (p->size); size_t bytes = kissat_bytes_of_clause (p->size);
if (p->redundant) { if (p->redundant) {
memcpy (r, p, bytes); memcpy (r, p, bytes);
@ -258,16 +260,16 @@ static void move_redundant_clauses_to_the_end (kissat *solver,
LOGCLS (q, "new DST"); LOGCLS (q, "new DST");
if (q->reason) if (q->reason)
get_forced_and_update_large_reason (solver, assigned, values, q); get_forced_and_update_large_reason (solver, assigned, values, q);
assert (q->redundant); KISSAT_assert (q->redundant);
if (!first_reducible) if (!first_reducible)
first_reducible = q; first_reducible = q;
r = (clause *) (bytes + (char *) r); r = (clause *) (bytes + (char *) r);
q = (clause *) (bytes + (char *) q); q = (clause *) (bytes + (char *) q);
} }
assert ((char *) r <= (char *) redundant + bytes_redundant); KISSAT_assert ((char *) r <= (char *) redundant + bytes_redundant);
kissat_free (solver, redundant, bytes_redundant); kissat_free (solver, redundant, bytes_redundant);
assert (!first_reducible || first_reducible < q); KISSAT_assert (!first_reducible || first_reducible < q);
update_first_reducible (solver, q, first_reducible); update_first_reducible (solver, q, first_reducible);
update_last_irredundant (solver, q, last_irredundant); update_last_irredundant (solver, q, last_irredundant);
@ -276,20 +278,20 @@ static void move_redundant_clauses_to_the_end (kissat *solver,
static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact, static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
reference start) { reference start) {
assert (solver->watching); KISSAT_assert (solver->watching);
LOG ("sparse garbage collection starting at clause[%" REFERENCE_FORMAT LOG ("sparse garbage collection starting at clause[%" REFERENCE_FORMAT
"]", "]",
start); start);
#ifdef CHECKING_OR_PROVING #ifdef CHECKING_OR_PROVING
const bool checking_or_proving = kissat_checking_or_proving (solver); const bool checking_or_proving = kissat_checking_or_proving (solver);
#endif #endif
assert (EMPTY_STACK (solver->added)); KISSAT_assert (EMPTY_STACK (solver->added));
assert (EMPTY_STACK (solver->removed)); KISSAT_assert (EMPTY_STACK (solver->removed));
const value *const values = solver->values; const value *const values = solver->values;
assigned *assigned = solver->assigned; assigned *assigned = solver->assigned;
#ifndef QUIET #ifndef KISSAT_QUIET
size_t flushed_garbage_clauses = 0; size_t flushed_garbage_clauses = 0;
size_t flushed_satisfied_clauses = 0; size_t flushed_satisfied_clauses = 0;
#endif #endif
@ -319,7 +321,7 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
for (clause *next; src != end; src = next) { for (clause *next; src != end; src = next) {
if (src->garbage) { if (src->garbage) {
next = kissat_delete_clause (solver, src); next = kissat_delete_clause (solver, src);
#ifndef QUIET #ifndef KISSAT_QUIET
flushed_garbage_clauses++; flushed_garbage_clauses++;
#endif #endif
if (last_irredundant == src) { if (last_irredundant == src) {
@ -331,13 +333,13 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
continue; continue;
} }
assert (src->size > 1); KISSAT_assert (src->size > 1);
LOGCLS (src, "SRC"); LOGCLS (src, "SRC");
next = kissat_next_clause (src); next = kissat_next_clause (src);
#if !defined(NDEBUG) || defined(CHECKING_OR_PROVING) #if !defined(KISSAT_NDEBUG) || defined(CHECKING_OR_PROVING)
const unsigned old_size = src->size; const unsigned old_size = src->size;
#endif #endif
assert (SIZE_OF_CLAUSE_HEADER == sizeof (unsigned)); KISSAT_assert (SIZE_OF_CLAUSE_HEADER == sizeof (unsigned));
*(unsigned *) dst = *(unsigned *) src; *(unsigned *) dst = *(unsigned *) src;
unsigned *q = dst->lits; unsigned *q = dst->lits;
@ -365,15 +367,15 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
if (tmp < 0 && !level) if (tmp < 0 && !level)
flushed++; flushed++;
else if (tmp > 0 && !level) { else if (tmp > 0 && !level) {
assert (!satisfied); KISSAT_assert (!satisfied);
assert (!dst->reason); KISSAT_assert (!dst->reason);
LOG ("SRC satisfied by %s", LOGLIT (lit)); LOG ("SRC satisfied by %s", LOGLIT (lit));
satisfied = true; satisfied = true;
} else { } else {
const unsigned mlit = kissat_map_literal (solver, lit, compact); const unsigned mlit = kissat_map_literal (solver, lit, compact);
if (tmp > 0) { if (tmp > 0) {
assert (level); KISSAT_assert (level);
forced = non_false++ ? INVALID_LIT : lit; forced = non_false++ ? INVALID_LIT : lit;
} else if (tmp < 0) } else if (tmp < 0)
other = lit; other = lit;
@ -397,7 +399,7 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
DEC (clauses_redundant); DEC (clauses_redundant);
else else
DEC (clauses_irredundant); DEC (clauses_irredundant);
#ifndef QUIET #ifndef KISSAT_QUIET
flushed_satisfied_clauses++; flushed_satisfied_clauses++;
#endif #endif
#ifdef CHECKING_OR_PROVING #ifdef CHECKING_OR_PROVING
@ -418,36 +420,36 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
} }
const unsigned new_size = q - dst->lits; const unsigned new_size = q - dst->lits;
assert (new_size <= old_size); KISSAT_assert (new_size <= old_size);
assert (1 < new_size); KISSAT_assert (1 < new_size);
if (new_size == 2) { if (new_size == 2) {
assert (mfirst != INVALID_LIT); KISSAT_assert (mfirst != INVALID_LIT);
assert (msecond != INVALID_LIT); KISSAT_assert (msecond != INVALID_LIT);
statistics *statistics = &solver->statistics; statistics *statistics = &solver->statistics_;
assert (statistics->clauses_binary < UINT64_MAX); KISSAT_assert (statistics->clauses_binary < UINT64_MAX);
statistics->clauses_binary++; statistics->clauses_binary++;
bool redundant = dst->redundant; bool redundant = dst->redundant;
if (redundant) { if (redundant) {
assert (statistics->clauses_redundant > 0); KISSAT_assert (statistics->clauses_redundant > 0);
statistics->clauses_redundant--; statistics->clauses_redundant--;
redundant = false; redundant = false;
} else { } else {
assert (statistics->clauses_irredundant > 0); KISSAT_assert (statistics->clauses_irredundant > 0);
statistics->clauses_irredundant--; statistics->clauses_irredundant--;
} }
LOGBINARY (mfirst, msecond, "DST"); LOGBINARY (mfirst, msecond, "DST");
kissat_watch_binary (solver, mfirst, msecond); kissat_watch_binary (solver, mfirst, msecond);
if (dst->reason) { if (dst->reason) {
assert (non_false == 1); KISSAT_assert (non_false == 1);
assert (other != INVALID_LIT); KISSAT_assert (other != INVALID_LIT);
assert (forced != INVALID_LIT); KISSAT_assert (forced != INVALID_LIT);
const unsigned forced_idx = IDX (forced); const unsigned forced_idx = IDX (forced);
struct assigned *a = assigned + forced_idx; struct assigned *a = assigned + forced_idx;
assert (!a->binary); KISSAT_assert (!a->binary);
LOGBINARY (mfirst, msecond, LOGBINARY (mfirst, msecond,
"reason clause[%u] of %s updated to binary reason", "reason clause[%u] of %s updated to binary reason",
@ -464,7 +466,7 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
last_irredundant = first; last_irredundant = first;
} }
} else { } else {
assert (2 < new_size); KISSAT_assert (2 < new_size);
dst->size = new_size; dst->size = new_size;
dst->shrunken = false; dst->shrunken = false;
@ -495,8 +497,8 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
continue; continue;
if (new_size != old_size) { if (new_size != old_size) {
assert (1 < new_size); KISSAT_assert (1 < new_size);
assert (new_size < old_size); KISSAT_assert (new_size < old_size);
CHECK_AND_ADD_STACK (solver->added); CHECK_AND_ADD_STACK (solver->added);
ADD_STACK_TO_PROOF (solver->added); ADD_STACK_TO_PROOF (solver->added);
@ -516,10 +518,10 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
if (first_redundant) if (first_redundant)
LOGCLS (first_redundant, "determined first redundant clause as"); LOGCLS (first_redundant, "determined first redundant clause as");
#if !defined(QUIET) || defined(METRICS) #if !defined(KISSAT_QUIET) || defined(METRICS)
size_t bytes = (char *) END_STACK (solver->arena) - (char *) dst; size_t bytes = (char *) END_STACK (solver->arena) - (char *) dst;
#endif #endif
#ifndef QUIET #ifndef KISSAT_QUIET
if (flushed) if (flushed)
kissat_phase (solver, "collect", GET (garbage_collections), kissat_phase (solver, "collect", GET (garbage_collections),
"flushed %zu falsified literals in large clauses", "flushed %zu falsified literals in large clauses",
@ -556,18 +558,18 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
kissat_percent (redundant_bytes, move_bytes), kissat_percent (redundant_bytes, move_bytes),
FORMAT_BYTES (move_bytes)); FORMAT_BYTES (move_bytes));
#endif #endif
assert (first_redundant < dst); KISSAT_assert (first_redundant < dst);
res = kissat_reference_clause (solver, first_redundant); res = kissat_reference_clause (solver, first_redundant);
assert (res != INVALID_REF); KISSAT_assert (res != INVALID_REF);
} }
SET_END_OF_STACK (solver->arena, (ward *) dst); SET_END_OF_STACK (solver->arena, (ward *) dst);
kissat_shrink_arena (solver); kissat_shrink_arena (solver);
#ifdef METRICS #ifdef METRICS
if (solver->statistics.arena_garbage) if (solver->statistics_.arena_garbage)
kissat_very_verbose (solver, "still %s garbage left in arena", kissat_very_verbose (solver, "still %s garbage left in arena",
FORMAT_BYTES (solver->statistics.arena_garbage)); FORMAT_BYTES (solver->statistics_.arena_garbage));
else else
kissat_very_verbose (solver, "all garbage clauses in arena collected"); kissat_very_verbose (solver, "all garbage clauses in arena collected");
#endif #endif
@ -578,7 +580,7 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact,
static void rewatch_clauses (kissat *solver, reference start) { static void rewatch_clauses (kissat *solver, reference start) {
LOG ("rewatching clause[%" REFERENCE_FORMAT "] and following clauses", LOG ("rewatching clause[%" REFERENCE_FORMAT "] and following clauses",
start); start);
assert (solver->watching); KISSAT_assert (solver->watching);
const value *const values = solver->values; const value *const values = solver->values;
const assigned *const assigned = solver->assigned; const assigned *const assigned = solver->assigned;
@ -587,7 +589,7 @@ static void rewatch_clauses (kissat *solver, reference start) {
clause *end = (clause *) END_STACK (solver->arena); clause *end = (clause *) END_STACK (solver->arena);
clause *c = (clause *) (BEGIN_STACK (solver->arena) + start); clause *c = (clause *) (BEGIN_STACK (solver->arena) + start);
assert (c <= end); KISSAT_assert (c <= end);
for (clause *next; c != end; c = next) { for (clause *next; c != end; c = next) {
next = kissat_next_clause (c); next = kissat_next_clause (c);
@ -606,7 +608,7 @@ static void rewatch_clauses (kissat *solver, reference start) {
} }
void kissat_sparse_collect (kissat *solver, bool compact, reference start) { void kissat_sparse_collect (kissat *solver, bool compact, reference start) {
assert (solver->watching); KISSAT_assert (solver->watching);
START (collect); START (collect);
INC (garbage_collections); INC (garbage_collections);
INC (sparse_gcs); INC (sparse_gcs);
@ -643,11 +645,11 @@ bool kissat_compacting (kissat *solver) {
} }
void kissat_initial_sparse_collect (kissat *solver) { void kissat_initial_sparse_collect (kissat *solver) {
assert (!solver->level); KISSAT_assert (!solver->level);
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
assert (solver->watching); KISSAT_assert (solver->watching);
assert (kissat_trail_flushed (solver)); KISSAT_assert (kissat_trail_flushed (solver));
if (solver->statistics.units) { if (solver->statistics_.units) {
bool compact = GET_OPTION (compact); bool compact = GET_OPTION (compact);
kissat_sparse_collect (solver, compact, 0); kissat_sparse_collect (solver, compact, 0);
} }
@ -655,12 +657,12 @@ void kissat_initial_sparse_collect (kissat *solver) {
} }
static void dense_sweep_garbage_clauses (kissat *solver) { static void dense_sweep_garbage_clauses (kissat *solver) {
assert (!solver->level); KISSAT_assert (!solver->level);
assert (!solver->watching); KISSAT_assert (!solver->watching);
LOG ("dense garbage collection"); LOG ("dense garbage collection");
#ifndef QUIET #ifndef KISSAT_QUIET
size_t flushed_garbage_clauses = 0; size_t flushed_garbage_clauses = 0;
#endif #endif
clause *first_reducible = 0; clause *first_reducible = 0;
@ -675,15 +677,15 @@ static void dense_sweep_garbage_clauses (kissat *solver) {
for (clause *next; src != end; src = next) { for (clause *next; src != end; src = next) {
if (src->garbage) { if (src->garbage) {
next = kissat_delete_clause (solver, src); next = kissat_delete_clause (solver, src);
#ifndef QUIET #ifndef KISSAT_QUIET
flushed_garbage_clauses++; flushed_garbage_clauses++;
#endif #endif
continue; continue;
} }
assert (src->size > 1); KISSAT_assert (src->size > 1);
LOGCLS (src, "SRC"); LOGCLS (src, "SRC");
next = kissat_next_clause (src); next = kissat_next_clause (src);
assert (SIZE_OF_CLAUSE_HEADER == sizeof (unsigned)); KISSAT_assert (SIZE_OF_CLAUSE_HEADER == sizeof (unsigned));
*(unsigned *) dst = *(unsigned *) src; *(unsigned *) dst = *(unsigned *) src;
dst->searched = src->searched; dst->searched = src->searched;
dst->size = src->size; dst->size = src->size;
@ -701,7 +703,7 @@ static void dense_sweep_garbage_clauses (kissat *solver) {
update_last_irredundant (solver, dst, last_irredundant); update_last_irredundant (solver, dst, last_irredundant);
kissat_reset_last_learned (solver); kissat_reset_last_learned (solver);
#if !defined(QUIET) || defined(METRICS) #if !defined(KISSAT_QUIET) || defined(METRICS)
size_t bytes = (char *) END_STACK (solver->arena) - (char *) dst; size_t bytes = (char *) END_STACK (solver->arena) - (char *) dst;
#endif #endif
kissat_phase (solver, "collect", GET (garbage_collections), kissat_phase (solver, "collect", GET (garbage_collections),
@ -717,17 +719,17 @@ static void dense_sweep_garbage_clauses (kissat *solver) {
kissat_shrink_arena (solver); kissat_shrink_arena (solver);
#ifdef METRICS #ifdef METRICS
if (solver->statistics.arena_garbage) if (solver->statistics_.arena_garbage)
kissat_very_verbose (solver, "still %s garbage left in arena", kissat_very_verbose (solver, "still %s garbage left in arena",
FORMAT_BYTES (solver->statistics.arena_garbage)); FORMAT_BYTES (solver->statistics_.arena_garbage));
else else
kissat_very_verbose (solver, "all garbage clauses in arena collected"); kissat_very_verbose (solver, "all garbage clauses in arena collected");
#endif #endif
} }
void kissat_dense_collect (kissat *solver) { void kissat_dense_collect (kissat *solver) {
assert (!solver->watching); KISSAT_assert (!solver->watching);
assert (!solver->level); KISSAT_assert (!solver->level);
START (collect); START (collect);
INC (garbage_collections); INC (garbage_collections);
INC (dense_garbage_collections); INC (dense_garbage_collections);
@ -736,3 +738,5 @@ void kissat_dense_collect (kissat *solver) {
REPORT (1, 'C'); REPORT (1, 'C');
STOP (collect); STOP (collect);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,6 +3,9 @@
#include "internal.h" #include "internal.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
bool kissat_compacting (kissat *); bool kissat_compacting (kissat *);
void kissat_dense_collect (kissat *); void kissat_dense_collect (kissat *);
void kissat_sparse_collect (kissat *, bool compact, reference start); void kissat_sparse_collect (kissat *, bool compact, reference start);
@ -30,4 +33,6 @@ static inline void kissat_defrag_watches_if_needed (kissat *solver) {
void kissat_update_last_irredundant (kissat *, clause *last_irredundant); void kissat_update_last_irredundant (kissat *, clause *last_irredundant);
void kissat_update_first_reducible (kissat *, clause *first_reducible); void kissat_update_first_reducible (kissat *, clause *first_reducible);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,12 +1,18 @@
#include "colors.h" #include "colors.h"
#ifdef WIN32
#define isatty _isatty
#else
#include <unistd.h> #include <unistd.h>
#endif
ABC_NAMESPACE_IMPL_START
int kissat_is_terminal[3] = {0, -1, -1}; int kissat_is_terminal[3] = {0, -1, -1};
int kissat_initialize_terminal (int fd) { int kissat_initialize_terminal (int fd) {
assert (fd == 1 || fd == 2); KISSAT_assert (fd == 1 || fd == 2);
assert (kissat_is_terminal[fd] < 0); KISSAT_assert (kissat_is_terminal[fd] < 0);
return kissat_is_terminal[fd] = isatty (fd); return kissat_is_terminal[fd] = isatty (fd);
} }
@ -17,3 +23,5 @@ void kissat_force_colors (void) {
void kissat_force_no_colors (void) { void kissat_force_no_colors (void) {
kissat_is_terminal[1] = kissat_is_terminal[2] = 0; kissat_is_terminal[1] = kissat_is_terminal[2] = 0;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -7,6 +7,9 @@
#include "keatures.h" #include "keatures.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
#define BLUE "\033[34m" #define BLUE "\033[34m"
#define BOLD "\033[1m" #define BOLD "\033[1m"
#define CYAN "\033[36m" #define CYAN "\033[36m"
@ -21,17 +24,17 @@
#define DARK_GRAY "\033[0;37m" #define DARK_GRAY "\033[0;37m"
#ifdef KISSAT_HAS_FILENO #ifdef KISSAT_HAS_FILENO
#define assert_if_has_fileno assert #define KISSAT_assert_if_has_fileno KISSAT_assert
#else #else
#define assert_if_has_fileno(...) \ #define KISSAT_assert_if_has_fileno(...) \
do { \ do { \
} while (0) } while (0)
#endif #endif
#define TERMINAL(F, I) \ #define TERMINAL(F, I) \
assert_if_has_fileno (fileno (F) == \ KISSAT_assert_if_has_fileno (fileno (F) == \
I); /* 'fileno' only in POSIX not C99 */ \ I); /* 'fileno' only in POSIX not C99 */ \
assert ((I == 1 && F == stdout) || (I == 2 && F == stderr)); \ KISSAT_assert ((I == 1 && F == stdout) || (I == 2 && F == stderr)); \
bool connected_to_terminal = kissat_connected_to_terminal (I); \ bool connected_to_terminal = kissat_connected_to_terminal (I); \
FILE *terminal_file = F FILE *terminal_file = F
@ -49,11 +52,11 @@ void kissat_force_colors (void);
void kissat_force_no_colors (void); void kissat_force_no_colors (void);
static inline bool kissat_connected_to_terminal (int fd) { static inline bool kissat_connected_to_terminal (int fd) {
assert (fd == 1 || fd == 2); KISSAT_assert (fd == 1 || fd == 2);
int res = kissat_is_terminal[fd]; int res = kissat_is_terminal[fd];
if (res < 0) if (res < 0)
res = kissat_initialize_terminal (fd); res = kissat_initialize_terminal (fd);
assert (res == 0 || res == 1); KISSAT_assert (res == 0 || res == 1);
return res; return res;
} }
@ -65,4 +68,6 @@ static inline const char *kissat_normal_color_code (int fd) {
return kissat_connected_to_terminal (fd) ? NORMAL : ""; return kissat_connected_to_terminal (fd) ? NORMAL : "";
} }
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -6,11 +6,13 @@
#include <string.h> #include <string.h>
ABC_NAMESPACE_IMPL_START
static void reimport_literal (kissat *solver, unsigned eidx, static void reimport_literal (kissat *solver, unsigned eidx,
unsigned mlit) { unsigned mlit) {
import *import = &PEEK_STACK (solver->import, eidx); import *import = &PEEK_STACK (solver->import, eidx);
assert (import->imported); KISSAT_assert (import->imported);
assert (!import->eliminated); KISSAT_assert (!import->eliminated);
LOG ("reimporting external variable %u as internal literal %u (was %u)", LOG ("reimporting external variable %u as internal literal %u (was %u)",
eidx, mlit, import->lit); eidx, mlit, import->lit);
import->lit = mlit; import->lit = mlit;
@ -18,9 +20,9 @@ static void reimport_literal (kissat *solver, unsigned eidx,
unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) { unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) {
INC (compacted); INC (compacted);
#if !defined(QUIET) || !defined(NDEBUG) #if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)
const unsigned active = solver->active; const unsigned active = solver->active;
#ifndef QUIET #ifndef KISSAT_QUIET
const unsigned inactive = solver->vars - active; const unsigned inactive = solver->vars - active;
kissat_phase (solver, "compact", GET (compacted), kissat_phase (solver, "compact", GET (compacted),
"compacting garbage collection " "compacting garbage collection "
@ -29,7 +31,7 @@ unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) {
#endif #endif
#endif #endif
#ifdef LOGGING #ifdef LOGGING
assert (!solver->compacting); KISSAT_assert (!solver->compacting);
solver->compacting = true; solver->compacting = true;
#endif #endif
unsigned mfixed = INVALID_LIT; unsigned mfixed = INVALID_LIT;
@ -42,7 +44,7 @@ unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) {
unsigned mlit; unsigned mlit;
if (flags->fixed) { if (flags->fixed) {
const value value = kissat_fixed (solver, ilit); const value value = kissat_fixed (solver, ilit);
assert (value); KISSAT_assert (value);
if (mfixed == INVALID_LIT) { if (mfixed == INVALID_LIT) {
mlit = mfixed = LIT (vars); mlit = mfixed = LIT (vars);
LOG2 ("first fixed %u mapped to %u assigned to %d", ilit, mfixed, LOG2 ("first fixed %u mapped to %u assigned to %d", ilit, mfixed,
@ -59,29 +61,29 @@ unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) {
LOG2 ("positively fixed %u mapped to %u", ilit, mlit); LOG2 ("positively fixed %u mapped to %u", ilit, mlit);
} }
} else if (flags->active) { } else if (flags->active) {
assert (flags->active); KISSAT_assert (flags->active);
mlit = LIT (vars); mlit = LIT (vars);
LOG2 ("remapping %u to %u", ilit, mlit); LOG2 ("remapping %u to %u", ilit, mlit);
vars++; vars++;
} else { } else {
const int elit = PEEK_STACK (solver->export, iidx); const int elit = PEEK_STACK (solver->export_, iidx);
if (elit) { if (elit) {
const unsigned eidx = ABS (elit); const unsigned eidx = ABS (elit);
import *import = &PEEK_STACK (solver->import, eidx); import *import = &PEEK_STACK (solver->import, eidx);
assert (import->imported); KISSAT_assert (import->imported);
assert (!import->eliminated); KISSAT_assert (!import->eliminated);
import->imported = false; import->imported = false;
LOG2 ("external variable %d not imported anymore", eidx); LOG2 ("external variable %d not imported anymore", eidx);
POKE_STACK (solver->export, iidx, 0); POKE_STACK (solver->export_, iidx, 0);
} else } else
LOG2 ("skipping inactive %u", ilit); LOG2 ("skipping inactive %u", ilit);
continue; continue;
} }
assert (mlit <= ilit); KISSAT_assert (mlit <= ilit);
assert (mlit != NOT (ilit)); KISSAT_assert (mlit != NOT (ilit));
if (mlit == ilit) if (mlit == ilit)
continue; continue;
const int elit = PEEK_STACK (solver->export, iidx); const int elit = PEEK_STACK (solver->export_, iidx);
const unsigned eidx = ABS (elit); const unsigned eidx = ABS (elit);
if (elit < 0) if (elit < 0)
mlit = NOT (mlit); mlit = NOT (mlit);
@ -90,17 +92,17 @@ unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) {
*mfixed_ptr = mfixed; *mfixed_ptr = mfixed;
LOG ("compacting to %u variables %.2f%% from %u", vars, LOG ("compacting to %u variables %.2f%% from %u", vars,
kissat_percent (vars, solver->vars), solver->vars); kissat_percent (vars, solver->vars), solver->vars);
assert (vars == active || vars == active + 1); KISSAT_assert (vars == active || vars == active + 1);
return vars; return vars;
} }
static void compact_literal (kissat *solver, unsigned dst_lit, static void compact_literal (kissat *solver, unsigned dst_lit,
unsigned src_lit) { unsigned src_lit) {
assert (dst_lit < src_lit); KISSAT_assert (dst_lit < src_lit);
assert (dst_lit != NOT (src_lit)); KISSAT_assert (dst_lit != NOT (src_lit));
const unsigned dst_idx = IDX (dst_lit); const unsigned dst_idx = IDX (dst_lit);
const unsigned src_idx = IDX (src_lit); const unsigned src_idx = IDX (src_lit);
assert (dst_idx != src_idx); KISSAT_assert (dst_idx != src_idx);
LOG ("mapping old internal literal %u to %u", src_lit, dst_lit); LOG ("mapping old internal literal %u to %u", src_lit, dst_lit);
solver->assigned[dst_idx] = solver->assigned[src_idx]; solver->assigned[dst_idx] = solver->assigned[src_idx];
solver->flags[dst_idx] = solver->flags[src_idx]; solver->flags[dst_idx] = solver->flags[src_idx];
@ -116,19 +118,19 @@ static void compact_literal (kissat *solver, unsigned dst_lit,
} }
static unsigned map_idx (kissat *solver, unsigned iidx) { static unsigned map_idx (kissat *solver, unsigned iidx) {
int elit = PEEK_STACK (solver->export, iidx); int elit = PEEK_STACK (solver->export_, iidx);
if (!elit) if (!elit)
return INVALID_IDX; return INVALID_IDX;
assert (elit); KISSAT_assert (elit);
const unsigned eidx = ABS (elit); const unsigned eidx = ABS (elit);
assert (eidx); KISSAT_assert (eidx);
import *import = &PEEK_STACK (solver->import, eidx); import *import = &PEEK_STACK (solver->import, eidx);
assert (import->imported); KISSAT_assert (import->imported);
if (import->eliminated) if (import->eliminated)
return INVALID_IDX; return INVALID_IDX;
const unsigned mlit = import->lit; const unsigned mlit = import->lit;
const unsigned midx = IDX (mlit); const unsigned midx = IDX (mlit);
assert (midx <= iidx); KISSAT_assert (midx <= iidx);
return midx; return midx;
} }
@ -139,7 +141,7 @@ static void compact_queue (kissat *solver) {
solver->queue.stamp = 0; solver->queue.stamp = 0;
for (unsigned idx; !DISCONNECTED (idx = *p); p = &l->next) { for (unsigned idx; !DISCONNECTED (idx = *p); p = &l->next) {
const unsigned midx = map_idx (solver, idx); const unsigned midx = map_idx (solver, idx);
assert (midx != INVALID_IDX); KISSAT_assert (midx != INVALID_IDX);
l = links + idx; l = links + idx;
l->prev = prev; l->prev = prev;
l->stamp = ++solver->queue.stamp; l->stamp = ++solver->queue.stamp;
@ -211,16 +213,16 @@ static void compact_trail (kissat *solver) {
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
const unsigned ilit = PEEK_ARRAY (solver->trail, i); const unsigned ilit = PEEK_ARRAY (solver->trail, i);
const unsigned mlit = kissat_map_literal (solver, ilit, true); const unsigned mlit = kissat_map_literal (solver, ilit, true);
assert (mlit != INVALID_LIT); KISSAT_assert (mlit != INVALID_LIT);
POKE_ARRAY (solver->trail, i, mlit); POKE_ARRAY (solver->trail, i, mlit);
const unsigned idx = IDX (ilit); const unsigned idx = IDX (ilit);
assigned *a = solver->assigned + idx; assigned *a = solver->assigned + idx;
if (!a->binary) if (!a->binary)
continue; continue;
const unsigned other = a->reason; const unsigned other = a->reason;
assert (VALID_INTERNAL_LITERAL (other)); KISSAT_assert (VALID_INTERNAL_LITERAL (other));
const unsigned mother = kissat_map_literal (solver, other, true); const unsigned mother = kissat_map_literal (solver, other, true);
assert (mother != INVALID_LIT); KISSAT_assert (mother != INVALID_LIT);
a->reason = mother; a->reason = mother;
} }
} }
@ -232,55 +234,55 @@ static void compact_frames (kissat *solver) {
frame *frame = &FRAME (level); frame *frame = &FRAME (level);
const unsigned ilit = frame->decision; const unsigned ilit = frame->decision;
const unsigned mlit = kissat_map_literal (solver, ilit, true); const unsigned mlit = kissat_map_literal (solver, ilit, true);
assert (mlit != INVALID_LIT); KISSAT_assert (mlit != INVALID_LIT);
frame->decision = mlit; frame->decision = mlit;
} }
} }
static void compact_export (kissat *solver, unsigned vars) { static void compact_export (kissat *solver, unsigned vars) {
LOG ("compacting export"); LOG ("compacting export");
const size_t size = SIZE_STACK (solver->export); const size_t size = SIZE_STACK (solver->export_);
assert (size <= UINT_MAX); KISSAT_assert (size <= UINT_MAX);
assert (size == solver->vars); KISSAT_assert (size == solver->vars);
for (unsigned iidx = 0; iidx < size; iidx++) { for (unsigned iidx = 0; iidx < size; iidx++) {
const unsigned elit = PEEK_STACK (solver->export, iidx); const unsigned elit = PEEK_STACK (solver->export_, iidx);
if (!elit) if (!elit)
continue; continue;
const unsigned midx = map_idx (solver, iidx); const unsigned midx = map_idx (solver, iidx);
if (midx == INVALID_IDX) if (midx == INVALID_IDX)
continue; continue;
POKE_STACK (solver->export, midx, elit); POKE_STACK (solver->export_, midx, elit);
} }
RESIZE_STACK (solver->export, vars); RESIZE_STACK (solver->export_, vars);
SHRINK_STACK (solver->export); SHRINK_STACK (solver->export_);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
assert (SIZE_STACK (solver->export) == vars); KISSAT_assert (SIZE_STACK (solver->export_) == vars);
for (unsigned iidx = 0; iidx < vars; iidx++) { for (unsigned iidx = 0; iidx < vars; iidx++) {
const int elit = PEEK_STACK (solver->export, iidx); const int elit = PEEK_STACK (solver->export_, iidx);
assert (VALID_EXTERNAL_LITERAL (elit)); KISSAT_assert (VALID_EXTERNAL_LITERAL (elit));
const unsigned eidx = ABS (elit); const unsigned eidx = ABS (elit);
const import *const import = &PEEK_STACK (solver->import, eidx); const import *const import = &PEEK_STACK (solver->import, eidx);
assert (import->imported); KISSAT_assert (import->imported);
if (import->eliminated) if (import->eliminated)
continue; continue;
unsigned mlit = import->lit; unsigned mlit = import->lit;
if (elit < 0) if (elit < 0)
mlit = NOT (mlit); mlit = NOT (mlit);
const unsigned ilit = LIT (iidx); const unsigned ilit = LIT (iidx);
assert (mlit == ilit); KISSAT_assert (mlit == ilit);
} }
#endif #endif
} }
static void compact_units (kissat *solver, unsigned mfixed) { static void compact_units (kissat *solver, unsigned mfixed) {
LOG ("compacting units (first fixed %u)", mfixed); LOG ("compacting units (first fixed %u)", mfixed);
assert (kissat_fixed (solver, mfixed) > 0); KISSAT_assert (kissat_fixed (solver, mfixed) > 0);
for (all_stack (int, elit, solver->units)) { for (all_stack (int, elit, solver->units)) {
const unsigned eidx = ABS (elit); const unsigned eidx = ABS (elit);
const unsigned mlit = elit < 0 ? NOT (mfixed) : mfixed; const unsigned mlit = elit < 0 ? NOT (mfixed) : mfixed;
const import *const import = &PEEK_STACK (solver->import, eidx); const import *const import = &PEEK_STACK (solver->import, eidx);
assert (import->imported); KISSAT_assert (import->imported);
assert (!import->eliminated); KISSAT_assert (!import->eliminated);
const unsigned ilit = import->lit; const unsigned ilit = import->lit;
if (mlit != ilit) if (mlit != ilit)
reimport_literal (solver, eidx, mlit); reimport_literal (solver, eidx, mlit);
@ -320,9 +322,9 @@ static void compact_best_and_target_values (kissat *solver, unsigned vars) {
void kissat_finalize_compacting (kissat *solver, unsigned vars, void kissat_finalize_compacting (kissat *solver, unsigned vars,
unsigned mfixed) { unsigned mfixed) {
LOG ("finalizing compacting"); LOG ("finalizing compacting");
assert (vars <= solver->vars); KISSAT_assert (vars <= solver->vars);
#ifdef LOGGING #ifdef LOGGING
assert (solver->compacting); KISSAT_assert (solver->compacting);
#endif #endif
if (vars == solver->vars) { if (vars == solver->vars) {
#ifdef LOGGING #ifdef LOGGING
@ -341,7 +343,7 @@ void kissat_finalize_compacting (kissat *solver, unsigned vars,
if (flags->fixed && first) if (flags->fixed && first)
first = false; first = false;
else if (!flags->active) else if (!flags->active)
POKE_STACK (solver->export, iidx, 0); POKE_STACK (solver->export_, iidx, 0);
} }
compact_trail (solver); compact_trail (solver);
@ -374,3 +376,5 @@ void kissat_finalize_compacting (kissat *solver, unsigned vars,
#endif #endif
kissat_decrease_size (solver); kissat_decrease_size (solver);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -1,9 +1,14 @@
#ifndef _compact_h_INCLUDED #ifndef _compact_h_INCLUDED
#define _compact_h_INCLUDED #define _compact_h_INCLUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
unsigned kissat_compact_literals (struct kissat *, unsigned *mfixed_ptr); unsigned kissat_compact_literals (struct kissat *, unsigned *mfixed_ptr);
void kissat_finalize_compacting (struct kissat *, unsigned vars, void kissat_finalize_compacting (struct kissat *, unsigned vars,
unsigned mfixed); unsigned mfixed);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,4 +1,6 @@
#ifndef NOPTIONS #include "global.h"
#ifndef KISSAT_NOPTIONS
#include "config.h" #include "config.h"
#include "kissat.h" #include "kissat.h"

View File

@ -1,8 +1,14 @@
#ifndef NOPTIONS
#ifndef _config_h_INCLUDED #ifndef _config_h_INCLUDED
#define _config_h_INCLUDED #define _config_h_INCLUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
#ifndef KISSAT_NOPTIONS
void kissat_configuration_usage (void); void kissat_configuration_usage (void);
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,12 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
bool kissat_congruence (struct kissat *); bool kissat_congruence (struct kissat *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -4,6 +4,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
#define COVER(COND) \ #define COVER(COND) \
((COND) ? \ ((COND) ? \
\ \
@ -25,4 +28,6 @@
} while (0) } while (0)
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -6,15 +6,17 @@
#include <inttypes.h> #include <inttypes.h>
ABC_NAMESPACE_IMPL_START
static unsigned last_enqueued_unassigned_variable (kissat *solver) { static unsigned last_enqueued_unassigned_variable (kissat *solver) {
assert (solver->unassigned); KISSAT_assert (solver->unassigned);
const links *const links = solver->links; const links *const links = solver->links;
const value *const values = solver->values; const value *const values = solver->values;
unsigned res = solver->queue.search.idx; unsigned res = solver->queue.search.idx;
if (values[LIT (res)]) { if (values[LIT (res)]) {
do { do {
res = links[res].prev; res = links[res].prev;
assert (!DISCONNECTED (res)); KISSAT_assert (!DISCONNECTED (res));
} while (values[LIT (res)]); } while (values[LIT (res)]);
kissat_update_queue (solver, links, res); kissat_update_queue (solver, links, res);
} }
@ -24,7 +26,7 @@ static unsigned last_enqueued_unassigned_variable (kissat *solver) {
#endif #endif
#ifdef CHECK_QUEUE #ifdef CHECK_QUEUE
for (unsigned i = links[res].next; !DISCONNECTED (i); i = links[i].next) for (unsigned i = links[res].next; !DISCONNECTED (i); i = links[i].next)
assert (VALUE (LIT (i))); KISSAT_assert (VALUE (LIT (i)));
#endif #endif
return res; return res;
} }
@ -48,7 +50,7 @@ static unsigned largest_score_unassigned_variable (kissat *solver) {
if (VALUE (LIT (idx))) if (VALUE (LIT (idx)))
continue; continue;
const double idx_score = kissat_get_heap_score (scores, idx); const double idx_score = kissat_get_heap_score (scores, idx);
assert (score >= idx_score); KISSAT_assert (score >= idx_score);
} }
#endif #endif
return res; return res;
@ -71,7 +73,7 @@ void kissat_start_random_sequence (kissat *solver) {
FORMAT_COUNT (CONFLICTS)); FORMAT_COUNT (CONFLICTS));
else { else {
INC (random_sequences); INC (random_sequences);
const uint64_t count = solver->statistics.random_sequences; const uint64_t count = solver->statistics_.random_sequences;
const unsigned length = GET_OPTION (randeclength) * LOGN (count); const unsigned length = GET_OPTION (randeclength) * LOGN (count);
kissat_very_verbose (solver, kissat_very_verbose (solver,
"starting random decision sequence " "starting random decision sequence "
@ -100,7 +102,7 @@ static unsigned next_random_decision (kissat *solver) {
return INVALID_IDX; return INVALID_IDX;
if (!solver->randec) { if (!solver->randec) {
assert (solver->level); KISSAT_assert (solver->level);
if (solver->level > 1) if (solver->level > 1)
return INVALID_IDX; return INVALID_IDX;
@ -176,7 +178,7 @@ int kissat_decide_phase (kissat *solver, unsigned idx) {
value res = 0; value res = 0;
if (!solver->stable) { if (!solver->stable) {
switch ((solver->statistics.switched >> 1) & 7) { switch ((solver->statistics_.switched >> 1) & 7) {
case 1: case 1:
res = INITIAL_PHASE; res = INITIAL_PHASE;
break; break;
@ -201,14 +203,14 @@ int kissat_decide_phase (kissat *solver, unsigned idx) {
LOG ("%s uses initial decision phase %d", LOGVAR (idx), (int) res); LOG ("%s uses initial decision phase %d", LOGVAR (idx), (int) res);
INC (initial_decisions); INC (initial_decisions);
} }
assert (res); KISSAT_assert (res);
return res < 0 ? -1 : 1; return res < 0 ? -1 : 1;
} }
void kissat_decide (kissat *solver) { void kissat_decide (kissat *solver) {
START (decide); START (decide);
assert (solver->unassigned); KISSAT_assert (solver->unassigned);
if (solver->warming) if (solver->warming)
INC (warming_decisions); INC (warming_decisions);
else { else {
@ -219,26 +221,28 @@ void kissat_decide (kissat *solver) {
INC (focused_decisions); INC (focused_decisions);
} }
solver->level++; solver->level++;
assert (solver->level != INVALID_LEVEL); KISSAT_assert (solver->level != INVALID_LEVEL);
const unsigned idx = kissat_next_decision_variable (solver); const unsigned idx = kissat_next_decision_variable (solver);
const value value = kissat_decide_phase (solver, idx); const value value = kissat_decide_phase (solver, idx);
unsigned lit = LIT (idx); unsigned lit = LIT (idx);
if (value < 0) if (value < 0)
lit = NOT (lit); lit = NOT (lit);
kissat_push_frame (solver, lit); kissat_push_frame (solver, lit);
assert (solver->level < SIZE_STACK (solver->frames)); KISSAT_assert (solver->level < SIZE_STACK (solver->frames));
LOG ("decide literal %s", LOGLIT (lit)); LOG ("decide literal %s", LOGLIT (lit));
kissat_assign_decision (solver, lit); kissat_assign_decision (solver, lit);
STOP (decide); STOP (decide);
} }
void kissat_internal_assume (kissat *solver, unsigned lit) { void kissat_internal_assume (kissat *solver, unsigned lit) {
assert (solver->unassigned); KISSAT_assert (solver->unassigned);
assert (!VALUE (lit)); KISSAT_assert (!VALUE (lit));
solver->level++; solver->level++;
assert (solver->level != INVALID_LEVEL); KISSAT_assert (solver->level != INVALID_LEVEL);
kissat_push_frame (solver, lit); kissat_push_frame (solver, lit);
assert (solver->level < SIZE_STACK (solver->frames)); KISSAT_assert (solver->level < SIZE_STACK (solver->frames));
LOG ("assuming literal %s", LOGLIT (lit)); LOG ("assuming literal %s", LOGLIT (lit));
kissat_assign_decision (solver, lit); kissat_assign_decision (solver, lit);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -1,6 +1,9 @@
#ifndef _decide_h_INCLUDED #ifndef _decide_h_INCLUDED
#define _decide_h_INCLUDED #define _decide_h_INCLUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
void kissat_decide (struct kissat *); void kissat_decide (struct kissat *);
@ -11,4 +14,6 @@ int kissat_decide_phase (struct kissat *, unsigned idx);
#define INITIAL_PHASE (GET_OPTION (phase) ? 1 : -1) #define INITIAL_PHASE (GET_OPTION (phase) ? 1 : -1)
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -3,8 +3,10 @@
#include "promote.h" #include "promote.h"
#include "strengthen.h" #include "strengthen.h"
ABC_NAMESPACE_IMPL_START
static inline void recompute_and_promote (kissat *solver, clause *c) { static inline void recompute_and_promote (kissat *solver, clause *c) {
assert (c->redundant); KISSAT_assert (c->redundant);
const unsigned old_glue = c->glue; const unsigned old_glue = c->glue;
const unsigned new_glue = kissat_recompute_glue (solver, c, old_glue); const unsigned new_glue = kissat_recompute_glue (solver, c, old_glue);
if (new_glue < old_glue) if (new_glue < old_glue)
@ -19,7 +21,7 @@ static inline void mark_clause_as_used (kissat *solver, clause *c) {
LOGCLS (c, "using"); LOGCLS (c, "using");
recompute_and_promote (solver, c); recompute_and_promote (solver, c);
unsigned glue = MIN (c->glue, MAX_GLUE_USED); unsigned glue = MIN (c->glue, MAX_GLUE_USED);
solver->statistics.used[solver->stable].glue[glue]++; solver->statistics_.used[solver->stable].glue[glue]++;
if (solver->stable) if (solver->stable)
INC (clauses_used_stable); INC (clauses_used_stable);
else else
@ -27,7 +29,7 @@ static inline void mark_clause_as_used (kissat *solver, clause *c) {
} }
bool kissat_recompute_and_promote (kissat *solver, clause *c) { bool kissat_recompute_and_promote (kissat *solver, clause *c) {
assert (c->redundant); KISSAT_assert (c->redundant);
const unsigned old_glue = c->glue; const unsigned old_glue = c->glue;
const unsigned new_glue = kissat_recompute_glue (solver, c, old_glue); const unsigned new_glue = kissat_recompute_glue (solver, c, old_glue);
if (new_glue >= old_glue) if (new_glue >= old_glue)
@ -38,7 +40,7 @@ bool kissat_recompute_and_promote (kissat *solver, clause *c) {
static inline bool analyze_literal (kissat *solver, assigned *all_assigned, static inline bool analyze_literal (kissat *solver, assigned *all_assigned,
frame *frames, unsigned lit) { frame *frames, unsigned lit) {
assert (VALUE (lit) < 0); KISSAT_assert (VALUE (lit) < 0);
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
assigned *a = all_assigned + idx; assigned *a = all_assigned + idx;
const unsigned level = a->level; const unsigned level = a->level;
@ -49,14 +51,14 @@ static inline bool analyze_literal (kissat *solver, assigned *all_assigned,
return false; return false;
LOG ("analyzing literal %s", LOGLIT (lit)); LOG ("analyzing literal %s", LOGLIT (lit));
kissat_push_analyzed (solver, all_assigned, idx); kissat_push_analyzed (solver, all_assigned, idx);
assert (level <= solver->level); KISSAT_assert (level <= solver->level);
#if defined(LOGGING) || !defined(NDEBUG) #if defined(LOGGING) || !defined(KISSAT_NDEBUG)
PUSH_STACK (solver->resolvent, lit); PUSH_STACK (solver->resolvent, lit);
#endif #endif
solver->resolvent_size++; solver->resolvent_size++;
if (level == solver->level) if (level == solver->level)
return true; return true;
assert (a->analyzed); KISSAT_assert (a->analyzed);
PUSH_STACK (solver->clause, lit); PUSH_STACK (solver->clause, lit);
LOG ("learned literal %s", LOGLIT (lit)); LOG ("learned literal %s", LOGLIT (lit));
frame *f = frames + level; frame *f = frames + level;
@ -69,10 +71,10 @@ static inline bool analyze_literal (kissat *solver, assigned *all_assigned,
clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) { clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) {
START (deduce); START (deduce);
assert (EMPTY_STACK (solver->analyzed)); KISSAT_assert (EMPTY_STACK (solver->analyzed));
assert (EMPTY_STACK (solver->levels)); KISSAT_assert (EMPTY_STACK (solver->levels));
assert (EMPTY_STACK (solver->clause)); KISSAT_assert (EMPTY_STACK (solver->clause));
#if defined(LOGGING) || !defined(NDEBUG) #if defined(LOGGING) || !defined(KISSAT_NDEBUG)
CLEAR_STACK (solver->resolvent); CLEAR_STACK (solver->resolvent);
#endif #endif
if (conflict->size > 2) if (conflict->size > 2)
@ -84,16 +86,16 @@ clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) {
assigned *all_assigned = solver->assigned; assigned *all_assigned = solver->assigned;
frame *frames = BEGIN_STACK (solver->frames); frame *frames = BEGIN_STACK (solver->frames);
for (all_literals_in_clause (lit, conflict)) { for (all_literals_in_clause (lit, conflict)) {
assert (VALUE (lit) < 0); KISSAT_assert (VALUE (lit) < 0);
if (LEVEL (lit)) if (LEVEL (lit))
conflict_size++; conflict_size++;
if (analyze_literal (solver, all_assigned, frames, lit)) if (analyze_literal (solver, all_assigned, frames, lit))
unresolved_on_current_level++; unresolved_on_current_level++;
} }
assert (unresolved_on_current_level > 1); KISSAT_assert (unresolved_on_current_level > 1);
LOG ("starting with %u unresolved literals on current decision level", LOG ("starting with %u unresolved literals on current decision level",
unresolved_on_current_level); unresolved_on_current_level);
assert (solver->antecedent_size == solver->resolvent_size); KISSAT_assert (solver->antecedent_size == solver->resolvent_size);
LOGRES2 ("initial"); LOGRES2 ("initial");
const bool otfs = GET_OPTION (otfs); const bool otfs = GET_OPTION (otfs);
unsigned const *t = END_ARRAY (solver->trail); unsigned const *t = END_ARRAY (solver->trail);
@ -102,14 +104,14 @@ clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) {
assigned *a = 0; assigned *a = 0;
for (;;) { for (;;) {
do { do {
assert (t > BEGIN_ARRAY (solver->trail)); KISSAT_assert (t > BEGIN_ARRAY (solver->trail));
uip = *--t; uip = *--t;
a = ASSIGNED (uip); a = ASSIGNED (uip);
} while (!a->analyzed || a->level != solver->level); } while (!a->analyzed || a->level != solver->level);
if (unresolved_on_current_level == 1) if (unresolved_on_current_level == 1)
break; break;
assert (a->reason != DECISION_REASON); KISSAT_assert (a->reason != DECISION_REASON);
assert (a->level == solver->level); KISSAT_assert (a->level == solver->level);
solver->antecedent_size = 1; solver->antecedent_size = 1;
resolved++; resolved++;
if (a->binary) { if (a->binary) {
@ -127,38 +129,38 @@ clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) {
unresolved_on_current_level++; unresolved_on_current_level++;
mark_clause_as_used (solver, reason); mark_clause_as_used (solver, reason);
} }
assert (unresolved_on_current_level > 0); KISSAT_assert (unresolved_on_current_level > 0);
unresolved_on_current_level--; unresolved_on_current_level--;
LOG ("after resolving %s there are %u literals left " LOG ("after resolving %s there are %u literals left "
"on current decision level", "on current decision level",
LOGLIT (uip), unresolved_on_current_level); LOGLIT (uip), unresolved_on_current_level);
assert (solver->resolvent_size > 0); KISSAT_assert (solver->resolvent_size > 0);
solver->resolvent_size--; solver->resolvent_size--;
#if defined(LOGGING) || !defined(NDEBUG) #if defined(LOGGING) || !defined(KISSAT_NDEBUG)
LOG2 ("actual antecedent size %u", solver->antecedent_size); LOG2 ("actual antecedent size %u", solver->antecedent_size);
REMOVE_STACK (unsigned, solver->resolvent, NOT (uip)); REMOVE_STACK (unsigned, solver->resolvent, NOT (uip));
assert (SIZE_STACK (solver->resolvent) == solver->resolvent_size); KISSAT_assert (SIZE_STACK (solver->resolvent) == solver->resolvent_size);
LOGRES2 ("new"); LOGRES2 ("new");
#endif #endif
if (otfs && solver->antecedent_size > 2 && if (otfs && solver->antecedent_size > 2 &&
solver->resolvent_size < solver->antecedent_size) { solver->resolvent_size < solver->antecedent_size) {
assert (!a->binary); KISSAT_assert (!a->binary);
assert (solver->antecedent_size && solver->resolvent_size + 1); KISSAT_assert (solver->antecedent_size && solver->resolvent_size + 1);
clause *reason = kissat_dereference_clause (solver, a->reason); clause *reason = kissat_dereference_clause (solver, a->reason);
assert (!reason->garbage); KISSAT_assert (!reason->garbage);
clause *res = kissat_on_the_fly_strengthen (solver, reason, uip); clause *res = kissat_on_the_fly_strengthen (solver, reason, uip);
if (resolved == 1 && solver->resolvent_size < conflict_size) { if (resolved == 1 && solver->resolvent_size < conflict_size) {
assert (!conflict->garbage); KISSAT_assert (!conflict->garbage);
assert (conflict_size > 2); KISSAT_assert (conflict_size > 2);
kissat_on_the_fly_subsume (solver, res, conflict); kissat_on_the_fly_subsume (solver, res, conflict);
} }
STOP (deduce); STOP (deduce);
return res; return res;
} }
} }
assert (uip != INVALID_LIT); KISSAT_assert (uip != INVALID_LIT);
LOG ("first unique implication point %s (1st UIP)", LOGLIT (uip)); LOG ("first unique implication point %s (1st UIP)", LOGLIT (uip));
assert (PEEK_STACK (solver->clause, 0) == INVALID_LIT); KISSAT_assert (PEEK_STACK (solver->clause, 0) == INVALID_LIT);
POKE_STACK (solver->clause, 0, NOT (uip)); POKE_STACK (solver->clause, 0, NOT (uip));
LOGTMP ("deduced not yet minimized 1st UIP"); LOGTMP ("deduced not yet minimized 1st UIP");
if (!solver->probing) if (!solver->probing)
@ -166,3 +168,5 @@ clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) {
STOP (deduce); STOP (deduce);
return 0; return 0;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,6 +3,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct clause; struct clause;
struct kissat; struct kissat;
@ -11,4 +14,6 @@ struct clause *kissat_deduce_first_uip_clause (struct kissat *,
bool kissat_recompute_and_promote (struct kissat *, struct clause *); bool kissat_recompute_and_promote (struct kissat *, struct clause *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -5,6 +5,8 @@
#include "kitten.h" #include "kitten.h"
#include "print.h" #include "print.h"
ABC_NAMESPACE_IMPL_START
typedef struct definition_extractor definition_extractor; typedef struct definition_extractor definition_extractor;
struct definition_extractor { struct definition_extractor {
@ -14,13 +16,13 @@ struct definition_extractor {
}; };
static void traverse_definition_core (void *state, unsigned id) { static void traverse_definition_core (void *state, unsigned id) {
definition_extractor *extractor = state; definition_extractor *extractor = (definition_extractor*)state;
kissat *solver = extractor->solver; kissat *solver = extractor->solver;
watch watch; watch watch;
watches *watches0 = extractor->watches[0]; watches *watches0 = extractor->watches[0];
watches *watches1 = extractor->watches[1]; watches *watches1 = extractor->watches[1];
const size_t size_watches0 = SIZE_WATCHES (*watches0); const size_t size_watches0 = SIZE_WATCHES (*watches0);
assert (size_watches0 <= UINT_MAX); KISSAT_assert (size_watches0 <= UINT_MAX);
unsigned sign; unsigned sign;
if (id < size_watches0) { if (id < size_watches0) {
watch = BEGIN_WATCHES (*watches0)[id]; watch = BEGIN_WATCHES (*watches0)[id];
@ -28,10 +30,10 @@ static void traverse_definition_core (void *state, unsigned id) {
sign = 0; sign = 0;
} else { } else {
unsigned tmp = id - size_watches0; unsigned tmp = id - size_watches0;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
const size_t size_watches1 = SIZE_WATCHES (*watches1); const size_t size_watches1 = SIZE_WATCHES (*watches1);
assert (size_watches1 <= UINT_MAX); KISSAT_assert (size_watches1 <= UINT_MAX);
assert (tmp < size_watches1); KISSAT_assert (tmp < size_watches1);
#endif #endif
watch = BEGIN_WATCHES (*watches1)[tmp]; watch = BEGIN_WATCHES (*watches1)[tmp];
LOGWATCH (NOT (extractor->lit), watch, "gate[1]"); LOGWATCH (NOT (extractor->lit), watch, "gate[1]");
@ -40,7 +42,7 @@ static void traverse_definition_core (void *state, unsigned id) {
PUSH_STACK (solver->gates[sign], watch); PUSH_STACK (solver->gates[sign], watch);
} }
#if !defined(NDEBUG) || !defined(NPROOFS) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS)
typedef struct lemma_extractor lemma_extractor; typedef struct lemma_extractor lemma_extractor;
@ -59,7 +61,7 @@ static void traverse_one_sided_core_lemma (void *state, bool learned,
kissat *solver = extractor->solver; kissat *solver = extractor->solver;
const unsigned unit = extractor->unit; const unsigned unit = extractor->unit;
unsigneds *added = &solver->added; unsigneds *added = &solver->added;
assert (extractor->lemmas || EMPTY_STACK (*added)); KISSAT_assert (extractor->lemmas || EMPTY_STACK (*added));
if (size) { if (size) {
PUSH_STACK (*added, size + 1); PUSH_STACK (*added, size + 1);
const size_t offset = SIZE_STACK (*added); const size_t offset = SIZE_STACK (*added);
@ -68,7 +70,7 @@ static void traverse_one_sided_core_lemma (void *state, bool learned,
for (const unsigned *p = lits; p != end; p++) for (const unsigned *p = lits; p != end; p++)
PUSH_STACK (*added, *p); PUSH_STACK (*added, *p);
unsigned *extended = &PEEK_STACK (*added, offset); unsigned *extended = &PEEK_STACK (*added, offset);
assert (offset + size + 1 == SIZE_STACK (*added)); KISSAT_assert (offset + size + 1 == SIZE_STACK (*added));
CHECK_AND_ADD_LITS (size + 1, extended); CHECK_AND_ADD_LITS (size + 1, extended);
ADD_LITS_TO_PROOF (size + 1, extended); ADD_LITS_TO_PROOF (size + 1, extended);
} else { } else {
@ -77,7 +79,7 @@ static void traverse_one_sided_core_lemma (void *state, bool learned,
unsigned *begin = BEGIN_STACK (*added); unsigned *begin = BEGIN_STACK (*added);
for (unsigned *p = begin, size; p != end; p += size) { for (unsigned *p = begin, size; p != end; p += size) {
size = *p++; size = *p++;
assert (p + size <= end); KISSAT_assert (p + size <= end);
REMOVE_CHECKER_LITS (size, p); REMOVE_CHECKER_LITS (size, p);
DELETE_LITS_FROM_PROOF (size, p); DELETE_LITS_FROM_PROOF (size, p);
} }
@ -93,7 +95,7 @@ bool kissat_find_definition (kissat *solver, unsigned lit) {
return false; return false;
START (definition); START (definition);
struct kitten *kitten = solver->kitten; struct kitten *kitten = solver->kitten;
assert (kitten); KISSAT_assert (kitten);
kitten_clear (kitten); kitten_clear (kitten);
const unsigned not_lit = NOT (lit); const unsigned not_lit = NOT (lit);
definition_extractor extractor; definition_extractor extractor;
@ -103,7 +105,7 @@ bool kissat_find_definition (kissat *solver, unsigned lit) {
extractor.watches[1] = &WATCHES (not_lit); extractor.watches[1] = &WATCHES (not_lit);
kitten_track_antecedents (kitten); kitten_track_antecedents (kitten);
unsigned exported = 0; unsigned exported = 0;
#if !defined(QUIET) || !defined(NDEBUG) #if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)
size_t occs[2] = {0, 0}; size_t occs[2] = {0, 0};
#endif #endif
for (unsigned sign = 0; sign < 2; sign++) { for (unsigned sign = 0; sign < 2; sign++) {
@ -119,7 +121,7 @@ bool kissat_find_definition (kissat *solver, unsigned lit) {
kitten_clause_with_id_and_exception (kitten, exported, c->size, kitten_clause_with_id_and_exception (kitten, exported, c->size,
c->lits, except); c->lits, except);
} }
#if !defined(QUIET) || !defined(NDEBUG) #if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)
occs[sign]++; occs[sign]++;
#endif #endif
exported++; exported++;
@ -143,19 +145,19 @@ bool kissat_find_definition (kissat *solver, unsigned lit) {
kitten_shuffle_clauses (kitten); kitten_shuffle_clauses (kitten);
kitten_set_ticks_limit (kitten, 10 * limit); kitten_set_ticks_limit (kitten, 10 * limit);
int tmp = kitten_solve (kitten); int tmp = kitten_solve (kitten);
assert (!tmp || tmp == 20); KISSAT_assert (!tmp || tmp == 20);
if (!tmp) { if (!tmp) {
LOG ("aborting core extraction"); LOG ("aborting core extraction");
goto ABORT; goto ABORT;
} }
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
unsigned previous = reduced; unsigned previous = reduced;
#endif #endif
reduced = kitten_compute_clausal_core (kitten, &learned); reduced = kitten_compute_clausal_core (kitten, &learned);
LOG ("%s sub-solver core of size %u original clauses out of %u", LOG ("%s sub-solver core of size %u original clauses out of %u",
FORMAT_ORDINAL (i), reduced, exported); FORMAT_ORDINAL (i), reduced, exported);
assert (reduced <= previous); KISSAT_assert (reduced <= previous);
#if defined(QUIET) && defined(NDEBUG) #if defined(KISSAT_QUIET) && defined(KISSAT_NDEBUG)
(void) reduced; (void) reduced;
#endif #endif
} }
@ -164,8 +166,8 @@ bool kissat_find_definition (kissat *solver, unsigned lit) {
size_t size[2]; size_t size[2];
size[0] = SIZE_STACK (solver->gates[0]); size[0] = SIZE_STACK (solver->gates[0]);
size[1] = SIZE_STACK (solver->gates[1]); size[1] = SIZE_STACK (solver->gates[1]);
#if !defined(QUIET) || !defined(NDEBUG) #if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)
assert (reduced == size[0] + size[1]); KISSAT_assert (reduced == size[0] + size[1]);
#ifdef METRICS #ifdef METRICS
kissat_extremely_verbose ( kissat_extremely_verbose (
solver, solver,
@ -188,7 +190,7 @@ bool kissat_find_definition (kissat *solver, unsigned lit) {
unsigned unit = INVALID_LIT; unsigned unit = INVALID_LIT;
if (!size[0]) { if (!size[0]) {
unit = not_lit; unit = not_lit;
assert (size[1]); KISSAT_assert (size[1]);
} else if (!size[1]) } else if (!size[1])
unit = lit; unit = lit;
@ -198,12 +200,12 @@ bool kissat_find_definition (kissat *solver, unsigned lit) {
kissat_extremely_verbose (solver, "one sided core " kissat_extremely_verbose (solver, "one sided core "
"definition extraction yields " "definition extraction yields "
"failed literal"); "failed literal");
#if !defined(NDEBUG) || !defined(NPROOFS) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS)
if (false if (false
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
|| GET_OPTION (check) > 1 || GET_OPTION (check) > 1
#endif #endif
#ifndef NPROOFS #ifndef KISSAT_NPROOFS
|| solver->proof || solver->proof
#endif #endif
) { ) {
@ -228,3 +230,5 @@ bool kissat_find_definition (kissat *solver, unsigned lit) {
STOP (definition); STOP (definition);
return res; return res;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,8 +3,13 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
bool kissat_find_definition (struct kissat *, unsigned lit); bool kissat_find_definition (struct kissat *, unsigned lit);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -10,9 +10,11 @@
#include <string.h> #include <string.h>
ABC_NAMESPACE_IMPL_START
static void flush_large_watches (kissat *solver, litpairs *irredundant) { static void flush_large_watches (kissat *solver, litpairs *irredundant) {
assert (!solver->level); KISSAT_assert (!solver->level);
assert (solver->watching); KISSAT_assert (solver->watching);
#ifndef LOGGING #ifndef LOGGING
LOG ("flushing large watches"); LOG ("flushing large watches");
if (irredundant) if (irredundant)
@ -22,9 +24,9 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) {
#endif #endif
const value *const values = solver->values; const value *const values = solver->values;
mark *const marks = solver->marks; mark *const marks = solver->marks;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
for (all_literals (lit)) for (all_literals (lit))
assert (!marks[lit]); KISSAT_assert (!marks[lit]);
#endif #endif
size_t flushed = 0, collected = 0; size_t flushed = 0, collected = 0;
#ifdef LOGGING #ifdef LOGGING
@ -37,7 +39,7 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) {
watches *watches = all_watches + lit; watches *watches = all_watches + lit;
watch *begin = BEGIN_WATCHES (*watches), *q = begin; watch *begin = BEGIN_WATCHES (*watches), *q = begin;
const watch *const end_watches = END_WATCHES (*watches), *p = q; const watch *const end_watches = END_WATCHES (*watches), *p = q;
assert (EMPTY_STACK (*marked)); KISSAT_assert (EMPTY_STACK (*marked));
while (p != end_watches) { while (p != end_watches) {
const watch watch = *p++; const watch watch = *p++;
if (watch.type.binary) { if (watch.type.binary) {
@ -65,7 +67,7 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) {
*q++ = watch; *q++ = watch;
} }
} else { } else {
assert (lit_value > 0 || other_value > 0); KISSAT_assert (lit_value > 0 || other_value > 0);
if (lit < other) { if (lit < other) {
kissat_delete_binary (solver, lit, other); kissat_delete_binary (solver, lit, other);
collected++; collected++;
@ -84,7 +86,7 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) {
marks[other] = 0; marks[other] = 0;
CLEAR_ARRAY (*marked); CLEAR_ARRAY (*marked);
} }
assert (EMPTY_STACK (*marked)); KISSAT_assert (EMPTY_STACK (*marked));
LOG ("flushed %zu large watches", flushed); LOG ("flushed %zu large watches", flushed);
LOG ("removed %zu duplicated binary clauses", deduplicated); LOG ("removed %zu duplicated binary clauses", deduplicated);
LOG ("collected %zu satisfied binary clauses", collected); LOG ("collected %zu satisfied binary clauses", collected);
@ -97,9 +99,9 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) {
} }
void kissat_enter_dense_mode (kissat *solver, litpairs *irredundant) { void kissat_enter_dense_mode (kissat *solver, litpairs *irredundant) {
assert (!solver->level); KISSAT_assert (!solver->level);
assert (solver->watching); KISSAT_assert (solver->watching);
assert (kissat_propagated (solver)); KISSAT_assert (kissat_propagated (solver));
LOG ("entering dense mode with full occurrence lists"); LOG ("entering dense mode with full occurrence lists");
if (irredundant) if (irredundant)
flush_large_watches (solver, irredundant); flush_large_watches (solver, irredundant);
@ -111,7 +113,7 @@ void kissat_enter_dense_mode (kissat *solver, litpairs *irredundant) {
static void resume_watching_irredundant_binaries (kissat *solver, static void resume_watching_irredundant_binaries (kissat *solver,
litpairs *binaries) { litpairs *binaries) {
assert (binaries); KISSAT_assert (binaries);
#ifdef LOGGING #ifdef LOGGING
size_t resumed_watching = 0; size_t resumed_watching = 0;
#endif #endif
@ -120,8 +122,8 @@ static void resume_watching_irredundant_binaries (kissat *solver,
const unsigned first = litpair.lits[0]; const unsigned first = litpair.lits[0];
const unsigned second = litpair.lits[1]; const unsigned second = litpair.lits[1];
assert (!ELIMINATED (IDX (first))); KISSAT_assert (!ELIMINATED (IDX (first)));
assert (!ELIMINATED (IDX (second))); KISSAT_assert (!ELIMINATED (IDX (second)));
watches *first_watches = all_watches + first; watches *first_watches = all_watches + first;
watch first_watch = kissat_binary_watch (second); watch first_watch = kissat_binary_watch (second);
@ -172,7 +174,7 @@ resume_watching_large_clauses_after_elimination (kissat *solver) {
continue; continue;
} }
assert (c->size > 2); KISSAT_assert (c->size > 2);
unsigned *lits = c->lits; unsigned *lits = c->lits;
kissat_sort_literals (solver, values, assigned, c->size, lits); kissat_sort_literals (solver, values, assigned, c->size, lits);
@ -198,8 +200,8 @@ resume_watching_large_clauses_after_elimination (kissat *solver) {
void kissat_resume_sparse_mode (kissat *solver, bool flush_eliminated, void kissat_resume_sparse_mode (kissat *solver, bool flush_eliminated,
litpairs *irredundant) { litpairs *irredundant) {
assert (!solver->level); KISSAT_assert (!solver->level);
assert (!solver->watching); KISSAT_assert (!solver->watching);
if (solver->inconsistent) if (solver->inconsistent)
return; return;
LOG ("resuming sparse mode watching clauses"); LOG ("resuming sparse mode watching clauses");
@ -224,12 +226,14 @@ void kissat_resume_sparse_mode (kissat *solver, bool flush_eliminated,
else else
conflict = kissat_search_propagate (solver); conflict = kissat_search_propagate (solver);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
if (conflict) if (conflict)
assert (solver->inconsistent); KISSAT_assert (solver->inconsistent);
else else
assert (kissat_trail_flushed (solver)); KISSAT_assert (kissat_trail_flushed (solver));
#else #else
(void) conflict; (void) conflict;
#endif #endif
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,10 +3,15 @@
#include "watch.h" #include "watch.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
void kissat_enter_dense_mode (struct kissat *, void kissat_enter_dense_mode (struct kissat *,
litpairs *saved_irredundant_binary_clauses); litpairs *saved_irredundant_binary_clauses);
void kissat_resume_sparse_mode (struct kissat *, bool flush_eliminated, void kissat_resume_sparse_mode (struct kissat *, bool flush_eliminated,
litpairs *); litpairs *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,4 +1,6 @@
#ifndef NDEBUG #include "global.h"
#ifndef KISSAT_NDEBUG
#include "inline.h" #include "inline.h"
@ -64,14 +66,14 @@ static void dump_trail (kissat *solver) {
const unsigned lit = PEEK_ARRAY (solver->trail, i); const unsigned lit = PEEK_ARRAY (solver->trail, i);
dump_literal (solver, lit); dump_literal (solver, lit);
const unsigned lit_level = LEVEL (lit); const unsigned lit_level = LEVEL (lit);
assert (lit_level <= level); KISSAT_assert (lit_level <= level);
if (lit_level < level) if (lit_level < level)
printf (" out-of-order"); printf (" out-of-order");
assigned *a = ASSIGNED (lit); assigned *a = ASSIGNED (lit);
if (!lit_level) { if (!lit_level) {
printf (" UNIT\n"); printf (" UNIT\n");
assert (!a->binary); KISSAT_assert (!a->binary);
assert (a->reason == UNIT_REASON); KISSAT_assert (a->reason == UNIT_REASON);
} else { } else {
fputc (' ', stdout); fputc (' ', stdout);
if (a->binary) { if (a->binary) {
@ -80,7 +82,7 @@ static void dump_trail (kissat *solver) {
} else if (a->reason == DECISION_REASON) } else if (a->reason == DECISION_REASON)
printf ("DECISION\n"); printf ("DECISION\n");
else { else {
assert (a->reason != UNIT_REASON); KISSAT_assert (a->reason != UNIT_REASON);
const reference ref = a->reason; const reference ref = a->reason;
dump_ref (solver, ref); dump_ref (solver, ref);
} }
@ -129,18 +131,18 @@ static void dump_scores (kissat *solver) {
} }
static void dump_export (kissat *solver) { static void dump_export (kissat *solver) {
const unsigned size = SIZE_STACK (solver->export); const unsigned size = SIZE_STACK (solver->export_);
for (unsigned idx = 0; idx < size; idx++) for (unsigned idx = 0; idx < size; idx++)
printf ("export[%u] = %u\n", LIT (idx), printf ("export[%u] = %u\n", LIT (idx),
PEEK_STACK (solver->export, idx)); PEEK_STACK (solver->export_, idx));
} }
void dump_map (kissat *solver) { void dump_map (kissat *solver) {
const unsigned size = SIZE_STACK (solver->export); const unsigned size = SIZE_STACK (solver->export_);
unsigned first = INVALID_LIT; unsigned first = INVALID_LIT;
for (unsigned idx = 0; idx < size; idx++) { for (unsigned idx = 0; idx < size; idx++) {
const unsigned ilit = LIT (idx); const unsigned ilit = LIT (idx);
const int elit = PEEK_STACK (solver->export, idx); const int elit = PEEK_STACK (solver->export_, idx);
printf ("map[%u] -> %d", ilit, elit); printf ("map[%u] -> %d", ilit, elit);
if (elit) { if (elit) {
const unsigned eidx = ABS (elit); const unsigned eidx = ABS (elit);
@ -195,7 +197,7 @@ static void dump_extend (kissat *solver) {
const extension *const begin = BEGIN_STACK (solver->extend); const extension *const begin = BEGIN_STACK (solver->extend);
const extension *const end = END_STACK (solver->extend); const extension *const end = END_STACK (solver->extend);
for (const extension *p = begin, *q; p != end; p = q) { for (const extension *p = begin, *q; p != end; p = q) {
assert (p->blocking); KISSAT_assert (p->blocking);
printf ("extend[%zu] %d", (size_t) (p - begin), p->lit); printf ("extend[%zu] %d", (size_t) (p - begin), p->lit);
if (!p[1].blocking) if (!p[1].blocking)
fputs (" :", stdout); fputs (" :", stdout);

View File

@ -18,10 +18,12 @@
#include <inttypes.h> #include <inttypes.h>
#include <math.h> #include <math.h>
ABC_NAMESPACE_IMPL_START
bool kissat_eliminating (kissat *solver) { bool kissat_eliminating (kissat *solver) {
if (!solver->enabled.eliminate) if (!solver->enabled.eliminate)
return false; return false;
statistics *statistics = &solver->statistics; statistics *statistics = &solver->statistics_;
if (!statistics->clauses_irredundant) if (!statistics->clauses_irredundant)
return false; return false;
const uint64_t conflicts = statistics->conflicts; const uint64_t conflicts = statistics->conflicts;
@ -51,9 +53,9 @@ static inline double variable_score (kissat *solver, unsigned idx) {
double prod = pos * neg; double prod = pos * neg;
double sum = pos + neg; double sum = pos + neg;
double occlim2 = occlim * (double) occlim; double occlim2 = occlim * (double) occlim;
assert (prod <= occlim2); KISSAT_assert (prod <= occlim2);
double score = prod - sum; double score = prod - sum;
assert (score <= occlim2); KISSAT_assert (score <= occlim2);
double relevancy; double relevancy;
if (solver->stable) if (solver->stable)
relevancy = kissat_get_heap_score (&solver->scores, idx); relevancy = kissat_get_heap_score (&solver->scores, idx);
@ -70,8 +72,8 @@ static inline double variable_score (kissat *solver, unsigned idx) {
static inline void update_variable_score (kissat *solver, heap *schedule, static inline void update_variable_score (kissat *solver, heap *schedule,
unsigned idx) { unsigned idx) {
assert (schedule->size); KISSAT_assert (schedule->size);
assert (schedule == &solver->schedule); KISSAT_assert (schedule == &solver->schedule);
double new_score = variable_score (solver, idx); double new_score = variable_score (solver, idx);
LOG ("new score %g for variable %s", new_score, LOGVAR (idx)); LOG ("new score %g for variable %s", new_score, LOGVAR (idx));
kissat_update_heap (solver, schedule, idx, -new_score); kissat_update_heap (solver, schedule, idx, -new_score);
@ -83,7 +85,7 @@ void kissat_update_variable_score (kissat *solver, unsigned idx) {
static inline void update_after_adding_stack (kissat *solver, static inline void update_after_adding_stack (kissat *solver,
unsigneds *stack) { unsigneds *stack) {
assert (!solver->probing); KISSAT_assert (!solver->probing);
heap *schedule = &solver->schedule; heap *schedule = &solver->schedule;
if (!schedule->size) if (!schedule->size)
return; return;
@ -96,11 +98,11 @@ static inline void update_after_removing_variable (kissat *solver,
heap *schedule = &solver->schedule; heap *schedule = &solver->schedule;
if (!schedule->size) if (!schedule->size)
return; return;
assert (!solver->probing); KISSAT_assert (!solver->probing);
flags *f = solver->flags + idx; flags *f = solver->flags + idx;
if (f->fixed) if (f->fixed)
return; return;
assert (!f->eliminated); KISSAT_assert (!f->eliminated);
update_variable_score (solver, schedule, idx); update_variable_score (solver, schedule, idx);
if (!kissat_heap_contains (schedule, idx)) if (!kissat_heap_contains (schedule, idx))
kissat_push_heap (solver, schedule, idx); kissat_push_heap (solver, schedule, idx);
@ -110,7 +112,7 @@ static inline void update_after_removing_clause (kissat *solver, clause *c,
unsigned except) { unsigned except) {
if (!solver->schedule.size) if (!solver->schedule.size)
return; return;
assert (c->garbage); KISSAT_assert (c->garbage);
for (all_literals_in_clause (lit, c)) for (all_literals_in_clause (lit, c))
if (lit != except) if (lit != except)
update_after_removing_variable (solver, IDX (lit)); update_after_removing_variable (solver, IDX (lit));
@ -130,7 +132,7 @@ void kissat_eliminate_clause (kissat *solver, clause *c, unsigned lit) {
static unsigned schedule_variables (kissat *solver) { static unsigned schedule_variables (kissat *solver) {
LOG ("initializing variable schedule"); LOG ("initializing variable schedule");
assert (!solver->schedule.size); KISSAT_assert (!solver->schedule.size);
kissat_resize_heap (solver, &solver->schedule, solver->vars); kissat_resize_heap (solver, &solver->schedule, solver->vars);
@ -147,8 +149,8 @@ static unsigned schedule_variables (kissat *solver) {
scheduled++; scheduled++;
update_after_removing_variable (solver, idx); update_after_removing_variable (solver, idx);
} }
assert (scheduled == kissat_size_heap (&solver->schedule)); KISSAT_assert (scheduled == kissat_size_heap (&solver->schedule));
#ifndef QUIET #ifndef KISSAT_QUIET
size_t active = solver->active; size_t active = solver->active;
kissat_phase (solver, "eliminate", GET (eliminations), kissat_phase (solver, "eliminate", GET (eliminations),
"scheduled %zu variables %.0f%%", scheduled, "scheduled %zu variables %.0f%%", scheduled,
@ -160,7 +162,7 @@ static unsigned schedule_variables (kissat *solver) {
void kissat_flush_units_while_connected (kissat *solver) { void kissat_flush_units_while_connected (kissat *solver) {
const unsigned *propagate = solver->propagate; const unsigned *propagate = solver->propagate;
const unsigned *end_trail = END_ARRAY (solver->trail); const unsigned *end_trail = END_ARRAY (solver->trail);
assert (propagate <= end_trail); KISSAT_assert (propagate <= end_trail);
const size_t units = end_trail - propagate; const size_t units = end_trail - propagate;
if (!units) if (!units)
return; return;
@ -191,11 +193,11 @@ void kissat_flush_units_while_connected (kissat *solver) {
clause *c = kissat_dereference_clause (solver, ref); clause *c = kissat_dereference_clause (solver, ref);
if (!c->garbage) if (!c->garbage)
kissat_eliminate_clause (solver, c, unit); kissat_eliminate_clause (solver, c, unit);
assert (c->garbage); KISSAT_assert (c->garbage);
q--; q--;
} }
} }
assert (q <= end); KISSAT_assert (q <= end);
size_t flushed = end - q; size_t flushed = end - q;
if (!flushed) if (!flushed)
continue; continue;
@ -206,7 +208,7 @@ void kissat_flush_units_while_connected (kissat *solver) {
static void connect_resolvents (kissat *solver) { static void connect_resolvents (kissat *solver) {
const value *const values = solver->values; const value *const values = solver->values;
assert (EMPTY_STACK (solver->clause)); KISSAT_assert (EMPTY_STACK (solver->clause));
bool satisfied = false; bool satisfied = false;
#ifdef LOGGING #ifdef LOGGING
uint64_t added = 0; uint64_t added = 0;
@ -219,7 +221,7 @@ static void connect_resolvents (kissat *solver) {
LOGTMP ("temporary resolvent"); LOGTMP ("temporary resolvent");
const size_t size = SIZE_STACK (solver->clause); const size_t size = SIZE_STACK (solver->clause);
if (!size) { if (!size) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
LOG ("resolved empty clause"); LOG ("resolved empty clause");
CHECK_AND_ADD_EMPTY (); CHECK_AND_ADD_EMPTY ();
ADD_EMPTY_TO_PROOF (); ADD_EMPTY_TO_PROOF ();
@ -230,7 +232,7 @@ static void connect_resolvents (kissat *solver) {
LOG ("resolved unit clause %s", LOGLIT (unit)); LOG ("resolved unit clause %s", LOGLIT (unit));
kissat_learned_unit (solver, unit); kissat_learned_unit (solver, unit);
} else { } else {
assert (size > 1); KISSAT_assert (size > 1);
(void) kissat_new_irredundant_clause (solver); (void) kissat_new_irredundant_clause (solver);
update_after_adding_stack (solver, &solver->clause); update_after_adding_stack (solver, &solver->clause);
#ifdef LOGGING #ifdef LOGGING
@ -258,7 +260,7 @@ static void weaken_clauses (kissat *solver, unsigned lit) {
const unsigned not_lit = NOT (lit); const unsigned not_lit = NOT (lit);
const value *const values = solver->values; const value *const values = solver->values;
assert (!values[lit]); KISSAT_assert (!values[lit]);
watches *pos_watches = &WATCHES (lit); watches *pos_watches = &WATCHES (lit);
@ -340,7 +342,7 @@ static void set_next_elimination_bound (kissat *solver, bool complete) {
const unsigned max_bound = GET_OPTION (eliminatebound); const unsigned max_bound = GET_OPTION (eliminatebound);
const unsigned current_bound = const unsigned current_bound =
solver->bounds.eliminate.additional_clauses; solver->bounds.eliminate.additional_clauses;
assert (current_bound <= max_bound); KISSAT_assert (current_bound <= max_bound);
if (complete) { if (complete) {
if (current_bound == max_bound) { if (current_bound == max_bound) {
@ -348,11 +350,11 @@ static void set_next_elimination_bound (kissat *solver, bool complete) {
"completed maximum elimination bound %u", "completed maximum elimination bound %u",
current_bound); current_bound);
limits *limits = &solver->limits; limits *limits = &solver->limits;
statistics *statistics = &solver->statistics; statistics *statistics = &solver->statistics_;
limits->eliminate.variables.eliminate = limits->eliminate.variables.eliminate =
statistics->variables_eliminate; statistics->variables_eliminate;
limits->eliminate.variables.subsume = statistics->variables_subsume; limits->eliminate.variables.subsume = statistics->variables_subsume;
#ifndef QUIET #ifndef KISSAT_QUIET
bool first = !solver->bounds.eliminate.max_bound_completed++; bool first = !solver->bounds.eliminate.max_bound_completed++;
REPORT (!first, first ? '!' : ':'); REPORT (!first, first ? '!' : ':');
#endif #endif
@ -389,8 +391,8 @@ static bool eliminate_variable (kissat *solver, unsigned idx) {
(void) variable_score (solver, idx); (void) variable_score (solver, idx);
#endif #endif
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
assert (can_eliminate_variable (solver, idx)); KISSAT_assert (can_eliminate_variable (solver, idx));
LOG ("marking %s as not removed", LOGVAR (idx)); LOG ("marking %s as not removed", LOGVAR (idx));
FLAGS (idx)->eliminate = false; FLAGS (idx)->eliminate = false;
@ -406,7 +408,7 @@ static bool eliminate_variable (kissat *solver, unsigned idx) {
if (solver->gate_eliminated) { if (solver->gate_eliminated) {
INC (gates_eliminated); INC (gates_eliminated);
#ifdef METRICS #ifdef METRICS
assert (*solver->gate_eliminated < UINT64_MAX); KISSAT_assert (*solver->gate_eliminated < UINT64_MAX);
*solver->gate_eliminated += 1; *solver->gate_eliminated += 1;
#endif #endif
} }
@ -417,8 +419,8 @@ static void eliminate_variables (kissat *solver) {
kissat_very_verbose (solver, kissat_very_verbose (solver,
"trying to eliminate variables with bound %u", "trying to eliminate variables with bound %u",
solver->bounds.eliminate.additional_clauses); solver->bounds.eliminate.additional_clauses);
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
#ifndef QUIET #ifndef KISSAT_QUIET
unsigned before = solver->active; unsigned before = solver->active;
unsigned eliminated = 0; unsigned eliminated = 0;
uint64_t tried = 0; uint64_t tried = 0;
@ -452,7 +454,7 @@ static void eliminate_variables (kissat *solver) {
complete = true; complete = true;
} }
#ifndef QUIET #ifndef KISSAT_QUIET
const unsigned last_round_scheduled = const unsigned last_round_scheduled =
#endif #endif
schedule_variables (solver); schedule_variables (solver);
@ -474,7 +476,7 @@ static void eliminate_variables (kissat *solver) {
unsigned idx = kissat_pop_max_heap (solver, &solver->schedule); unsigned idx = kissat_pop_max_heap (solver, &solver->schedule);
if (!can_eliminate_variable (solver, idx)) if (!can_eliminate_variable (solver, idx))
continue; continue;
statistics *s = &solver->statistics; statistics *s = &solver->statistics_;
if (s->eliminate_resolutions > resolution_limit) { if (s->eliminate_resolutions > resolution_limit) {
kissat_extremely_verbose ( kissat_extremely_verbose (
solver, solver,
@ -484,7 +486,7 @@ static void eliminate_variables (kissat *solver) {
complete = false; complete = false;
break; break;
} }
#ifndef QUIET #ifndef KISSAT_QUIET
tried++; tried++;
#endif #endif
if (eliminate_variable (solver, idx)) if (eliminate_variable (solver, idx))
@ -496,7 +498,7 @@ static void eliminate_variables (kissat *solver) {
if (last_round_eliminated) { if (last_round_eliminated) {
complete = false; complete = false;
#ifndef QUIET #ifndef KISSAT_QUIET
eliminated += last_round_eliminated; eliminated += last_round_eliminated;
#endif #endif
} }
@ -520,7 +522,7 @@ static void eliminate_variables (kissat *solver) {
break; break;
if (round == GET_OPTION (eliminaterounds)) if (round == GET_OPTION (eliminaterounds))
break; break;
if (solver->statistics.eliminate_resolutions > resolution_limit) if (solver->statistics_.eliminate_resolutions > resolution_limit)
break; break;
if (TERMINATED (eliminate_terminated_2)) if (TERMINATED (eliminate_terminated_2))
break; break;
@ -528,7 +530,7 @@ static void eliminate_variables (kissat *solver) {
const unsigned remain = kissat_size_heap (&solver->schedule); const unsigned remain = kissat_size_heap (&solver->schedule);
kissat_release_heap (solver, &solver->schedule); kissat_release_heap (solver, &solver->schedule);
#ifndef QUIET #ifndef KISSAT_QUIET
kissat_very_verbose (solver, kissat_very_verbose (solver,
"eliminated %u variables %.0f%% of %" PRIu64 " tried" "eliminated %u variables %.0f%% of %" PRIu64 " tried"
" (%u remain %.0f%%)", " (%u remain %.0f%%)",
@ -545,13 +547,13 @@ static void eliminate_variables (kissat *solver) {
set_next_elimination_bound (solver, complete); set_next_elimination_bound (solver, complete);
if (!complete) { if (!complete) {
const flags *end = solver->flags + VARS; const flags *end = solver->flags + VARS;
#ifndef QUIET #ifndef KISSAT_QUIET
unsigned dropped = 0; unsigned dropped = 0;
#endif #endif
for (struct flags *f = solver->flags; f != end; f++) for (struct flags *f = solver->flags; f != end; f++)
if (f->eliminate) { if (f->eliminate) {
f->eliminate = false; f->eliminate = false;
#ifndef QUIET #ifndef KISSAT_QUIET
dropped++; dropped++;
#endif #endif
} }
@ -565,7 +567,7 @@ static void eliminate_variables (kissat *solver) {
static void init_map_and_kitten (kissat *solver) { static void init_map_and_kitten (kissat *solver) {
if (!GET_OPTION (definitions)) if (!GET_OPTION (definitions))
return; return;
assert (!solver->kitten); KISSAT_assert (!solver->kitten);
solver->kitten = kitten_embedded (solver); solver->kitten = kitten_embedded (solver);
} }
@ -578,7 +580,7 @@ static void reset_map_and_kitten (kissat *solver) {
static void eliminate (kissat *solver) { static void eliminate (kissat *solver) {
kissat_backtrack_propagate_and_flush_trail (solver); kissat_backtrack_propagate_and_flush_trail (solver);
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
STOP_SEARCH_AND_START_SIMPLIFIER (eliminate); STOP_SEARCH_AND_START_SIMPLIFIER (eliminate);
kissat_phase (solver, "eliminate", GET (eliminations), kissat_phase (solver, "eliminate", GET (eliminations),
"elimination limit of %" PRIu64 " conflicts hit", "elimination limit of %" PRIu64 " conflicts hit",
@ -593,11 +595,13 @@ static void eliminate (kissat *solver) {
} }
int kissat_eliminate (kissat *solver) { int kissat_eliminate (kissat *solver) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
INC (eliminations); INC (eliminations);
eliminate (solver); eliminate (solver);
kissat_classify (solver); kissat_classify (solver);
UPDATE_CONFLICT_LIMIT (eliminate, eliminations, NLOG2N, true); UPDATE_CONFLICT_LIMIT (eliminate, eliminations, NLOG2N, true);
solver->last.ticks.eliminate = solver->statistics.search_ticks; solver->last.ticks.eliminate = solver->statistics_.search_ticks;
return solver->inconsistent ? 20 : 0; return solver->inconsistent ? 20 : 0;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,6 +3,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
struct clause; struct clause;
struct heap; struct heap;
@ -16,4 +19,6 @@ void kissat_eliminate_binary (struct kissat *, unsigned, unsigned);
void kissat_eliminate_clause (struct kissat *, struct clause *, unsigned); void kissat_eliminate_clause (struct kissat *, struct clause *, unsigned);
void kissat_update_variable_score (struct kissat *, unsigned idx); void kissat_update_variable_score (struct kissat *, unsigned idx);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -2,6 +2,8 @@
#include "inlinevector.h" #include "inlinevector.h"
#include "logging.h" #include "logging.h"
ABC_NAMESPACE_IMPL_START
bool kissat_find_equivalence_gate (kissat *solver, unsigned lit) { bool kissat_find_equivalence_gate (kissat *solver, unsigned lit) {
if (!GET_OPTION (equivalences)) if (!GET_OPTION (equivalences))
return false; return false;
@ -35,3 +37,5 @@ bool kissat_find_equivalence_gate (kissat *solver, unsigned lit) {
INC (equivalences_extracted); INC (equivalences_extracted);
return true; return true;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,8 +3,13 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
bool kissat_find_equivalence_gate (struct kissat *, unsigned lit); bool kissat_find_equivalence_gate (struct kissat *, unsigned lit);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -5,6 +5,8 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
ABC_NAMESPACE_IMPL_START
static void (*kissat_abort_function) (void); static void (*kissat_abort_function) (void);
void kissat_call_function_instead_of_abort (void (*f) (void)) { void kissat_call_function_instead_of_abort (void (*f) (void)) {
@ -60,3 +62,5 @@ void kissat_fatal (const char *fmt, ...) {
va_end (ap); va_end (ap);
kissat_abort (); kissat_abort ();
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,6 +3,9 @@
#include "attribute.h" #include "attribute.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
// clang-format off // clang-format off
void kissat_error (const char *fmt, ...) ATTRIBUTE_FORMAT (1, 2); void kissat_error (const char *fmt, ...) ATTRIBUTE_FORMAT (1, 2);
@ -15,4 +18,6 @@ void kissat_abort (void);
// clang-format on // clang-format on
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,6 +1,8 @@
#include "colors.h" #include "colors.h"
#include "inline.h" #include "inline.h"
ABC_NAMESPACE_IMPL_START
static void undo_eliminated_assignment (kissat *solver) { static void undo_eliminated_assignment (kissat *solver) {
size_t size_etrail = SIZE_STACK (solver->etrail); size_t size_etrail = SIZE_STACK (solver->etrail);
#ifdef LOGGING #ifdef LOGGING
@ -18,32 +20,32 @@ static void undo_eliminated_assignment (kissat *solver) {
while (!EMPTY_STACK (solver->etrail)) { while (!EMPTY_STACK (solver->etrail)) {
const unsigned pos = POP_STACK (solver->etrail); const unsigned pos = POP_STACK (solver->etrail);
assert (pos < SIZE_STACK (solver->eliminated)); KISSAT_assert (pos < SIZE_STACK (solver->eliminated));
assert (values[pos]); KISSAT_assert (values[pos]);
LOG2 ("unassigned eliminated[%u] external variable", pos); LOG2 ("unassigned eliminated[%u] external variable", pos);
values[pos] = 0; values[pos] = 0;
} }
} }
static void extend_assign (kissat *solver, value *values, int lit) { static void extend_assign (kissat *solver, value *values, int lit) {
assert (lit); KISSAT_assert (lit);
assert (lit != INT_MIN); KISSAT_assert (lit != INT_MIN);
const unsigned idx = ABS (lit); const unsigned idx = ABS (lit);
import *import = &PEEK_STACK (solver->import, idx); import *import = &PEEK_STACK (solver->import, idx);
assert (import->eliminated); KISSAT_assert (import->eliminated);
assert (import->imported); KISSAT_assert (import->imported);
const unsigned pos = import->lit; const unsigned pos = import->lit;
assert (pos < SIZE_STACK (solver->eliminated)); KISSAT_assert (pos < SIZE_STACK (solver->eliminated));
const value value = lit < 0 ? -1 : 1; const value value = lit < 0 ? -1 : 1;
values[pos] = value; values[pos] = value;
assert (kissat_value (solver, lit) == lit); KISSAT_assert (kissat_value (solver, lit) == lit);
LOG ("assigned eliminated[%u] external literal %d", pos, value * idx); LOG ("assigned eliminated[%u] external literal %d", pos, value * idx);
PUSH_STACK (solver->etrail, pos); PUSH_STACK (solver->etrail, pos);
} }
void kissat_extend (kissat *solver) { void kissat_extend (kissat *solver) {
assert (!EMPTY_STACK (solver->extend)); KISSAT_assert (!EMPTY_STACK (solver->extend));
assert (!solver->extended); KISSAT_assert (!solver->extended);
START (extend); START (extend);
solver->extended = true; solver->extended = true;
@ -79,7 +81,7 @@ void kissat_extend (kissat *solver) {
#endif #endif
do { do {
size++; size++;
assert (begin < p); KISSAT_assert (begin < p);
const extension ext = *--p; const extension ext = *--p;
const int elit = ext.lit; const int elit = ext.lit;
if (ext.blocking) if (ext.blocking)
@ -88,15 +90,15 @@ void kissat_extend (kissat *solver) {
if (satisfied) if (satisfied)
continue; continue;
assert (elit != INT_MIN); KISSAT_assert (elit != INT_MIN);
const unsigned eidx = ABS (elit); const unsigned eidx = ABS (elit);
assert (eidx < SIZE_STACK (solver->import)); KISSAT_assert (eidx < SIZE_STACK (solver->import));
const import *const import = imports + eidx; const import *const import = imports + eidx;
assert (import->imported); KISSAT_assert (import->imported);
if (import->eliminated) { if (import->eliminated) {
const unsigned tmp = import->lit; const unsigned tmp = import->lit;
assert (tmp < SIZE_STACK (solver->eliminated)); KISSAT_assert (tmp < SIZE_STACK (solver->eliminated));
value value = evalues[tmp]; value value = evalues[tmp];
if (elit < 0) if (elit < 0)
@ -120,7 +122,7 @@ void kissat_extend (kissat *solver) {
} else { } else {
const unsigned ilit = import->lit; const unsigned ilit = import->lit;
value value = ivalues[ilit]; value value = ivalues[ilit];
assert (value); KISSAT_assert (value);
if (elit < 0) if (elit < 0)
value = -value; value = -value;
@ -151,10 +153,10 @@ void kissat_extend (kissat *solver) {
#ifdef LOGGING #ifdef LOGGING
const unsigned blocking_idx = ABS (blocking); const unsigned blocking_idx = ABS (blocking);
assert (blocking_idx < SIZE_STACK (solver->import)); KISSAT_assert (blocking_idx < SIZE_STACK (solver->import));
assert (imports[blocking_idx].eliminated); KISSAT_assert (imports[blocking_idx].eliminated);
const unsigned blocking_pos = imports[blocking_idx].lit; const unsigned blocking_pos = imports[blocking_idx].lit;
assert (blocking_pos < SIZE_STACK (solver->eliminated)); KISSAT_assert (blocking_pos < SIZE_STACK (solver->eliminated));
const value blocking_value = evalues[blocking_pos]; const value blocking_value = evalues[blocking_pos];
LOGEXT2 (size, p, LOGEXT2 (size, p,
"%s blocking external literal %d " "%s blocking external literal %d "
@ -179,3 +181,5 @@ void kissat_extend (kissat *solver) {
STOP (extend); STOP (extend);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -4,6 +4,9 @@
#include "stack.h" #include "stack.h"
#include "utilities.h" #include "utilities.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
typedef struct extension extension; typedef struct extension extension;
struct extension { struct extension {
@ -16,7 +19,7 @@ typedef STACK (extension) extensions;
// clang-format on // clang-format on
static inline extension kissat_extension (bool blocking, int lit) { static inline extension kissat_extension (bool blocking, int lit) {
assert (ABS (lit) < (1 << 30)); KISSAT_assert (ABS (lit) < (1 << 30));
extension res; extension res;
res.blocking = blocking; res.blocking = blocking;
res.lit = lit; res.lit = lit;
@ -27,4 +30,6 @@ struct kissat;
void kissat_extend (struct kissat *solver); void kissat_extend (struct kissat *solver);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -19,6 +19,8 @@
#include <string.h> #include <string.h>
ABC_NAMESPACE_IMPL_START
#define FACTOR 1 #define FACTOR 1
#define QUOTIENT 2 #define QUOTIENT 2
#define NOUNTED 4 #define NOUNTED 4
@ -73,19 +75,19 @@ static void init_factoring (kissat *solver, factoring *factoring,
factoring->hops = GET_OPTION (factorhops); factoring->hops = GET_OPTION (factorhops);
const unsigned hops = factoring->hops; const unsigned hops = factoring->hops;
if (hops) { if (hops) {
CALLOC (factoring->scores, hops); CALLOC (scores, factoring->scores, hops);
for (unsigned i = 0; i != hops; i++) { for (unsigned i = 0; i != hops; i++) {
scores *scores = factoring->scores + i; scores *scores = factoring->scores + i;
NALLOC (scores->score, VARS); NALLOC (double, scores->score, VARS);
double *score = scores->score; double *score = scores->score;
for (all_variables (idx)) for (all_variables (idx))
score[idx] = -1; score[idx] = -1;
} }
} }
CALLOC (factoring->count, factoring->allocated); CALLOC (unsigned, factoring->count, factoring->allocated);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
for (all_literals (lit)) for (all_literals (lit))
assert (!solver->marks[lit]); KISSAT_assert (!solver->marks[lit]);
#endif #endif
} }
@ -95,7 +97,7 @@ static void release_quotients (factoring *factoring) {
for (quotient *q = factoring->quotients.first, *next; q; q = next) { for (quotient *q = factoring->quotients.first, *next; q; q = next) {
next = q->next; next = q->next;
unsigned factor = q->factor; unsigned factor = q->factor;
assert (marks[factor] == FACTOR); KISSAT_assert (marks[factor] == FACTOR);
marks[factor] = 0; marks[factor] = 0;
RELEASE_STACK (q->clauses); RELEASE_STACK (q->clauses);
RELEASE_STACK (q->matches); RELEASE_STACK (q->matches);
@ -118,10 +120,10 @@ static void release_quotients (factoring *factoring) {
static void release_factoring (factoring *factoring) { static void release_factoring (factoring *factoring) {
kissat *const solver = factoring->solver; kissat *const solver = factoring->solver;
assert (EMPTY_STACK (solver->analyzed)); KISSAT_assert (EMPTY_STACK (solver->analyzed));
assert (EMPTY_STACK (factoring->counted)); KISSAT_assert (EMPTY_STACK (factoring->counted));
assert (EMPTY_STACK (factoring->nounted)); KISSAT_assert (EMPTY_STACK (factoring->nounted));
assert (EMPTY_STACK (factoring->qlauses)); KISSAT_assert (EMPTY_STACK (factoring->qlauses));
DEALLOC (factoring->count, factoring->allocated); DEALLOC (factoring->count, factoring->allocated);
RELEASE_STACK (factoring->counted); RELEASE_STACK (factoring->counted);
RELEASE_STACK (factoring->nounted); RELEASE_STACK (factoring->nounted);
@ -129,7 +131,7 @@ static void release_factoring (factoring *factoring) {
RELEASE_STACK (factoring->qlauses); RELEASE_STACK (factoring->qlauses);
release_quotients (factoring); release_quotients (factoring);
kissat_release_heap (solver, &factoring->schedule); kissat_release_heap (solver, &factoring->schedule);
assert (!(factoring->allocated & 1)); KISSAT_assert (!(factoring->allocated & 1));
const size_t allocated_score = factoring->allocated / 2; const size_t allocated_score = factoring->allocated / 2;
const unsigned hops = factoring->hops; const unsigned hops = factoring->hops;
if (hops) { if (hops) {
@ -141,9 +143,9 @@ static void release_factoring (factoring *factoring) {
} }
DEALLOC (factoring->scores, hops); DEALLOC (factoring->scores, hops);
} }
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
for (all_literals (lit)) for (all_literals (lit))
assert (!solver->marks[lit]); KISSAT_assert (!solver->marks[lit]);
#endif #endif
} }
@ -174,7 +176,7 @@ static void schedule_factorization (factoring *factoring) {
update_candidate (factoring, not_lit); update_candidate (factoring, not_lit);
} }
} }
#ifndef QUIET #ifndef KISSAT_QUIET
heap *cands = &factoring->schedule; heap *cands = &factoring->schedule;
size_t size_cands = kissat_size_heap (cands); size_t size_cands = kissat_size_heap (cands);
kissat_very_verbose ( kissat_very_verbose (
@ -186,19 +188,19 @@ static void schedule_factorization (factoring *factoring) {
static quotient *new_quotient (factoring *factoring, unsigned factor) { static quotient *new_quotient (factoring *factoring, unsigned factor) {
kissat *const solver = factoring->solver; kissat *const solver = factoring->solver;
mark *marks = solver->marks; mark *marks = solver->marks;
assert (!marks[factor]); KISSAT_assert (!marks[factor]);
marks[factor] = FACTOR; marks[factor] = FACTOR;
quotient *res = kissat_malloc (solver, sizeof *res); quotient *res = (quotient*)kissat_malloc (solver, sizeof *res);
memset (res, 0, sizeof *res); memset (res, 0, sizeof *res);
res->factor = factor; res->factor = factor;
quotient *last = factoring->quotients.last; quotient *last = factoring->quotients.last;
if (last) { if (last) {
assert (factoring->quotients.first); KISSAT_assert (factoring->quotients.first);
assert (!last->next); KISSAT_assert (!last->next);
last->next = res; last->next = res;
res->id = last->id + 1; res->id = last->id + 1;
} else { } else {
assert (!factoring->quotients.first); KISSAT_assert (!factoring->quotients.first);
factoring->quotients.first = res; factoring->quotients.first = res;
} }
factoring->quotients.last = res; factoring->quotients.last = res;
@ -211,24 +213,24 @@ static size_t first_factor (factoring *factoring, unsigned factor) {
kissat *const solver = factoring->solver; kissat *const solver = factoring->solver;
watches *all_watches = solver->watches; watches *all_watches = solver->watches;
watches *factor_watches = all_watches + factor; watches *factor_watches = all_watches + factor;
assert (!factoring->quotients.first); KISSAT_assert (!factoring->quotients.first);
quotient *quotient = new_quotient (factoring, factor); quotient *quotient = new_quotient (factoring, factor);
statches *clauses = &quotient->clauses; statches *clauses = &quotient->clauses;
uint64_t ticks = 0; uint64_t ticks = 0;
for (all_binary_large_watches (watch, *factor_watches)) { for (all_binary_large_watches (watch, *factor_watches)) {
PUSH_STACK (*clauses, watch); PUSH_STACK (*clauses, watch);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
if (watch.type.binary) if (watch.type.binary)
continue; continue;
const reference ref = watch.large.ref; const reference ref = watch.large.ref;
clause *const c = kissat_dereference_clause (solver, ref); clause *const c = kissat_dereference_clause (solver, ref);
assert (!c->quotient); KISSAT_assert (!c->quotient);
#endif #endif
ticks++; ticks++;
} }
size_t res = SIZE_STACK (*clauses); size_t res = SIZE_STACK (*clauses);
LOG ("quotient[0] factor %s size %zu", LOGLIT (factor), res); LOG ("quotient[0] factor %s size %zu", LOGLIT (factor), res);
assert (res > 1); KISSAT_assert (res > 1);
ADD (factor_ticks, ticks); ADD (factor_ticks, ticks);
return res; return res;
} }
@ -236,7 +238,7 @@ static size_t first_factor (factoring *factoring, unsigned factor) {
static void clear_nounted (kissat *solver, unsigneds *nounted) { static void clear_nounted (kissat *solver, unsigneds *nounted) {
mark *marks = solver->marks; mark *marks = solver->marks;
for (all_stack (unsigned, lit, *nounted)) { for (all_stack (unsigned, lit, *nounted)) {
assert (marks[lit] & NOUNTED); KISSAT_assert (marks[lit] & NOUNTED);
marks[lit] &= ~NOUNTED; marks[lit] &= ~NOUNTED;
} }
CLEAR_STACK (*nounted); CLEAR_STACK (*nounted);
@ -246,7 +248,7 @@ static void clear_qlauses (kissat *solver, references *qlauses) {
ward *const arena = BEGIN_STACK (solver->arena); ward *const arena = BEGIN_STACK (solver->arena);
for (all_stack (reference, ref, *qlauses)) { for (all_stack (reference, ref, *qlauses)) {
clause *const c = (clause *) (arena + ref); clause *const c = (clause *) (arena + ref);
assert (c->quotient); KISSAT_assert (c->quotient);
c->quotient = false; c->quotient = false;
} }
CLEAR_STACK (*qlauses); CLEAR_STACK (*qlauses);
@ -286,7 +288,7 @@ static double distinct_paths (factoring *factoring, unsigned src_lit,
} }
ADD (factor_ticks, ticks); ADD (factor_ticks, ticks);
} }
assert (res >= 0); KISSAT_assert (res >= 0);
score[src_idx] = res; score[src_idx] = res;
unsigneds *scored = &scores->scored; unsigneds *scored = &scores->scored;
PUSH_STACK (*scored, src_idx); PUSH_STACK (*scored, src_idx);
@ -297,9 +299,9 @@ static double distinct_paths (factoring *factoring, unsigned src_lit,
static double structural_score (factoring *factoring, unsigned lit) { static double structural_score (factoring *factoring, unsigned lit) {
const quotient *first_quotient = factoring->quotients.first; const quotient *first_quotient = factoring->quotients.first;
assert (first_quotient); KISSAT_assert (first_quotient);
const unsigned first_factor = first_quotient->factor; const unsigned first_factor = first_quotient->factor;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
kissat *const solver = factoring->solver; kissat *const solver = factoring->solver;
#endif #endif
const unsigned first_factor_idx = IDX (first_factor); const unsigned first_factor_idx = IDX (first_factor);
@ -324,15 +326,15 @@ static double tied_next_factor_score (factoring *factoring, unsigned lit) {
static unsigned next_factor (factoring *factoring, static unsigned next_factor (factoring *factoring,
unsigned *next_count_ptr) { unsigned *next_count_ptr) {
quotient *last_quotient = factoring->quotients.last; quotient *last_quotient = factoring->quotients.last;
assert (last_quotient); KISSAT_assert (last_quotient);
statches *last_clauses = &last_quotient->clauses; statches *last_clauses = &last_quotient->clauses;
kissat *const solver = factoring->solver; kissat *const solver = factoring->solver;
watches *all_watches = solver->watches; watches *all_watches = solver->watches;
unsigned *count = factoring->count; unsigned *count = factoring->count;
unsigneds *counted = &factoring->counted; unsigneds *counted = &factoring->counted;
references *qlauses = &factoring->qlauses; references *qlauses = &factoring->qlauses;
assert (EMPTY_STACK (*counted)); KISSAT_assert (EMPTY_STACK (*counted));
assert (EMPTY_STACK (*qlauses)); KISSAT_assert (EMPTY_STACK (*qlauses));
ward *const arena = BEGIN_STACK (solver->arena); ward *const arena = BEGIN_STACK (solver->arena);
mark *marks = solver->marks; mark *marks = solver->marks;
const unsigned initial = factoring->initial; const unsigned initial = factoring->initial;
@ -362,7 +364,7 @@ static unsigned next_factor (factoring *factoring,
} else { } else {
const reference c_ref = quotient_watch.large.ref; const reference c_ref = quotient_watch.large.ref;
clause *const c = (clause *) (arena + c_ref); clause *const c = (clause *) (arena + c_ref);
assert (!c->quotient); KISSAT_assert (!c->quotient);
unsigned min_lit = INVALID_LIT, factors = 0; unsigned min_lit = INVALID_LIT, factors = 0;
size_t min_size = 0; size_t min_size = 0;
ticks++; ticks++;
@ -371,7 +373,7 @@ static unsigned next_factor (factoring *factoring,
if (factors++) if (factors++)
break; break;
} else { } else {
assert (!(marks[other] & QUOTIENT)); KISSAT_assert (!(marks[other] & QUOTIENT));
marks[other] |= QUOTIENT; marks[other] |= QUOTIENT;
watches *other_watches = all_watches + other; watches *other_watches = all_watches + other;
const size_t other_size = SIZE_WATCHES (*other_watches); const size_t other_size = SIZE_WATCHES (*other_watches);
@ -381,13 +383,13 @@ static unsigned next_factor (factoring *factoring,
min_size = other_size; min_size = other_size;
} }
} }
assert (factors); KISSAT_assert (factors);
if (factors == 1) { if (factors == 1) {
assert (min_lit != INVALID_LIT); KISSAT_assert (min_lit != INVALID_LIT);
watches *min_watches = all_watches + min_lit; watches *min_watches = all_watches + min_lit;
unsigned c_size = c->size; unsigned c_size = c->size;
unsigneds *nounted = &factoring->nounted; unsigneds *nounted = &factoring->nounted;
assert (EMPTY_STACK (*nounted)); KISSAT_assert (EMPTY_STACK (*nounted));
ticks += 1 + kissat_cache_lines (SIZE_WATCHES (*min_watches), ticks += 1 + kissat_cache_lines (SIZE_WATCHES (*min_watches),
sizeof (watch)); sizeof (watch));
for (all_binary_large_watches (min_watch, *min_watches)) { for (all_binary_large_watches (min_watch, *min_watches)) {
@ -403,25 +405,35 @@ static unsigned next_factor (factoring *factoring,
if (d->size != c_size) if (d->size != c_size)
continue; continue;
unsigned next = INVALID_LIT; unsigned next = INVALID_LIT;
int continue_with_next_min_watch = 0;
for (all_literals_in_clause (other, d)) { for (all_literals_in_clause (other, d)) {
const mark mark = marks[other]; const mark mark = marks[other];
if (mark & QUOTIENT) if (mark & QUOTIENT)
continue; continue;
if (mark & FACTOR) if (mark & FACTOR) {
goto CONTINUE_WITH_NEXT_MIN_WATCH; continue_with_next_min_watch = 1;
if (mark & NOUNTED) break;
goto CONTINUE_WITH_NEXT_MIN_WATCH; }
if (next != INVALID_LIT) if (mark & NOUNTED) {
goto CONTINUE_WITH_NEXT_MIN_WATCH; continue_with_next_min_watch = 1;
break;
}
if (next != INVALID_LIT) {
continue_with_next_min_watch = 1;
break;
}
next = other; next = other;
} }
assert (next != INVALID_LIT); if(continue_with_next_min_watch) {
continue;
}
KISSAT_assert (next != INVALID_LIT);
if (next > initial) if (next > initial)
continue; continue;
const unsigned next_idx = IDX (next); const unsigned next_idx = IDX (next);
if (!ACTIVE (next_idx)) if (!ACTIVE (next_idx))
continue; continue;
assert (!(marks[next] & (FACTOR | NOUNTED))); KISSAT_assert (!(marks[next] & (FACTOR | NOUNTED)));
marks[next] |= NOUNTED; marks[next] |= NOUNTED;
PUSH_STACK (*nounted, next); PUSH_STACK (*nounted, next);
d->quotient = true; d->quotient = true;
@ -429,7 +441,6 @@ static unsigned next_factor (factoring *factoring,
if (!count[next]) if (!count[next])
PUSH_STACK (*counted, next); PUSH_STACK (*counted, next);
count[next]++; count[next]++;
CONTINUE_WITH_NEXT_MIN_WATCH:;
} }
clear_nounted (solver, nounted); clear_nounted (solver, nounted);
} }
@ -438,22 +449,22 @@ static unsigned next_factor (factoring *factoring,
} }
ADD (factor_ticks, ticks); ADD (factor_ticks, ticks);
ticks = 0; ticks = 0;
if (solver->statistics.factor_ticks > factoring->limit) if (solver->statistics_.factor_ticks > factoring->limit)
break; break;
} }
clear_qlauses (solver, qlauses); clear_qlauses (solver, qlauses);
unsigned next_count = 0, next = INVALID_LIT; unsigned next_count = 0, next = INVALID_LIT;
if (solver->statistics.factor_ticks <= factoring->limit) { if (solver->statistics_.factor_ticks <= factoring->limit) {
unsigned ties = 0; unsigned ties = 0;
for (all_stack (unsigned, lit, *counted)) { for (all_stack (unsigned, lit, *counted)) {
const unsigned lit_count = count[lit]; const unsigned lit_count = count[lit];
if (lit_count < next_count) if (lit_count < next_count)
continue; continue;
if (lit_count == next_count) { if (lit_count == next_count) {
assert (lit_count); KISSAT_assert (lit_count);
ties++; ties++;
} else { } else {
assert (lit_count > next_count); KISSAT_assert (lit_count > next_count);
next_count = lit_count; next_count = lit_count;
next = lit; next = lit;
ties = 1; ties = 1;
@ -471,7 +482,7 @@ static unsigned next_factor (factoring *factoring,
if (lit_count != next_count) if (lit_count != next_count)
continue; continue;
double lit_score = tied_next_factor_score (factoring, lit); double lit_score = tied_next_factor_score (factoring, lit);
assert (lit_score >= 0); KISSAT_assert (lit_score >= 0);
LOG ("score %g of next factor candidate %s", lit_score, LOG ("score %g of next factor candidate %s", lit_score,
LOGLIT (lit)); LOGLIT (lit));
if (lit_score <= next_score) if (lit_score <= next_score)
@ -479,11 +490,11 @@ static unsigned next_factor (factoring *factoring,
next_score = lit_score; next_score = lit_score;
next = lit; next = lit;
} }
assert (next_score >= 0); KISSAT_assert (next_score >= 0);
assert (next != INVALID_LIT); KISSAT_assert (next != INVALID_LIT);
LOG ("best score %g of next factor %s", next_score, LOGLIT (next)); LOG ("best score %g of next factor %s", next_score, LOGLIT (next));
} else { } else {
assert (ties == 1); KISSAT_assert (ties == 1);
LOG ("single next factor %s with count %u", LOGLIT (next), LOG ("single next factor %s with count %u", LOGLIT (next),
next_count); next_count);
} }
@ -491,7 +502,7 @@ static unsigned next_factor (factoring *factoring,
for (all_stack (unsigned, lit, *counted)) for (all_stack (unsigned, lit, *counted))
count[lit] = 0; count[lit] = 0;
CLEAR_STACK (*counted); CLEAR_STACK (*counted);
assert (next == INVALID_LIT || next_count > 1); KISSAT_assert (next == INVALID_LIT || next_count > 1);
*next_count_ptr = next_count; *next_count_ptr = next_count;
return next; return next;
} }
@ -506,12 +517,12 @@ static void factorize_next (factoring *factoring, unsigned next,
ward *const arena = BEGIN_STACK (solver->arena); ward *const arena = BEGIN_STACK (solver->arena);
mark *marks = solver->marks; mark *marks = solver->marks;
assert (last_quotient); KISSAT_assert (last_quotient);
statches *last_clauses = &last_quotient->clauses; statches *last_clauses = &last_quotient->clauses;
statches *next_clauses = &next_quotient->clauses; statches *next_clauses = &next_quotient->clauses;
sizes *matches = &next_quotient->matches; sizes *matches = &next_quotient->matches;
references *qlauses = &factoring->qlauses; references *qlauses = &factoring->qlauses;
assert (EMPTY_STACK (*qlauses)); KISSAT_assert (EMPTY_STACK (*qlauses));
uint64_t ticks = uint64_t ticks =
1 + kissat_cache_lines (SIZE_STACK (*last_clauses), sizeof (watch)); 1 + kissat_cache_lines (SIZE_STACK (*last_clauses), sizeof (watch));
@ -535,7 +546,7 @@ static void factorize_next (factoring *factoring, unsigned next,
} else { } else {
const reference c_ref = last_watch.large.ref; const reference c_ref = last_watch.large.ref;
clause *const c = (clause *) (arena + c_ref); clause *const c = (clause *) (arena + c_ref);
assert (!c->quotient); KISSAT_assert (!c->quotient);
unsigned min_lit = INVALID_LIT, factors = 0; unsigned min_lit = INVALID_LIT, factors = 0;
size_t min_size = 0; size_t min_size = 0;
ticks++; ticks++;
@ -544,7 +555,7 @@ static void factorize_next (factoring *factoring, unsigned next,
if (factors++) if (factors++)
break; break;
} else { } else {
assert (!(marks[other] & QUOTIENT)); KISSAT_assert (!(marks[other] & QUOTIENT));
marks[other] |= QUOTIENT; marks[other] |= QUOTIENT;
watches *other_watches = all_watches + other; watches *other_watches = all_watches + other;
const size_t other_size = SIZE_WATCHES (*other_watches); const size_t other_size = SIZE_WATCHES (*other_watches);
@ -554,9 +565,9 @@ static void factorize_next (factoring *factoring, unsigned next,
min_size = other_size; min_size = other_size;
} }
} }
assert (factors); KISSAT_assert (factors);
if (factors == 1) { if (factors == 1) {
assert (min_lit != INVALID_LIT); KISSAT_assert (min_lit != INVALID_LIT);
watches *min_watches = all_watches + min_lit; watches *min_watches = all_watches + min_lit;
unsigned c_size = c->size; unsigned c_size = c->size;
ticks += 1 + kissat_cache_lines (SIZE_WATCHES (*min_watches), ticks += 1 + kissat_cache_lines (SIZE_WATCHES (*min_watches),
@ -599,7 +610,7 @@ static void factorize_next (factoring *factoring, unsigned next,
clear_qlauses (solver, qlauses); clear_qlauses (solver, qlauses);
ADD (factor_ticks, ticks); ADD (factor_ticks, ticks);
assert (expected_next_count <= SIZE_STACK (*next_clauses)); KISSAT_assert (expected_next_count <= SIZE_STACK (*next_clauses));
(void) expected_next_count; (void) expected_next_count;
} }
@ -643,9 +654,9 @@ static quotient *best_quotient (factoring *factoring,
static void resize_factoring (factoring *factoring, unsigned lit) { static void resize_factoring (factoring *factoring, unsigned lit) {
kissat *const solver = factoring->solver; kissat *const solver = factoring->solver;
assert (lit > NOT (lit)); KISSAT_assert (lit > NOT (lit));
const size_t old_size = factoring->size; const size_t old_size = factoring->size;
assert (lit > old_size); KISSAT_assert (lit > old_size);
const size_t old_allocated = factoring->allocated; const size_t old_allocated = factoring->allocated;
size_t new_size = lit + 1; size_t new_size = lit + 1;
if (new_size > old_allocated) { if (new_size > old_allocated) {
@ -653,20 +664,20 @@ static void resize_factoring (factoring *factoring, unsigned lit) {
while (new_size > new_allocated) while (new_size > new_allocated)
new_allocated *= 2; new_allocated *= 2;
unsigned *count = factoring->count; unsigned *count = factoring->count;
count = kissat_nrealloc (solver, count, old_allocated, new_allocated, count = (unsigned*)kissat_nrealloc (solver, count, old_allocated, new_allocated,
sizeof *count); sizeof *count);
const size_t delta_allocated = new_allocated - old_allocated; const size_t delta_allocated = new_allocated - old_allocated;
const size_t delta_bytes = delta_allocated * sizeof *count; const size_t delta_bytes = delta_allocated * sizeof *count;
memset (count + old_size, 0, delta_bytes); memset (count + old_size, 0, delta_bytes);
factoring->count = count; factoring->count = count;
assert (!(old_allocated & 1)); KISSAT_assert (!(old_allocated & 1));
assert (!(new_allocated & 1)); KISSAT_assert (!(new_allocated & 1));
const size_t old_allocated_score = old_allocated / 2; const size_t old_allocated_score = old_allocated / 2;
const size_t new_allocated_score = new_allocated / 2; const size_t new_allocated_score = new_allocated / 2;
for (unsigned i = 0; i != factoring->hops; i++) { for (unsigned i = 0; i != factoring->hops; i++) {
scores *scores = factoring->scores + i; scores *scores = factoring->scores + i;
double *score = scores->score; double *score = scores->score;
score = kissat_nrealloc (solver, score, old_allocated_score, score = (double*)kissat_nrealloc (solver, score, old_allocated_score,
new_allocated_score, sizeof *score); new_allocated_score, sizeof *score);
for (size_t i = old_allocated_score; i != new_allocated_score; i++) for (size_t i = old_allocated_score; i != new_allocated_score; i++)
score[i] = -1; score[i] = -1;
@ -682,12 +693,12 @@ static void flush_unmatched_clauses (kissat *solver, quotient *q) {
sizes *q_matches = &q->matches, *prev_matches = &prev->matches; sizes *q_matches = &q->matches, *prev_matches = &prev->matches;
statches *q_clauses = &q->clauses, *prev_clauses = &prev->clauses; statches *q_clauses = &q->clauses, *prev_clauses = &prev->clauses;
const size_t n = SIZE_STACK (*q_clauses); const size_t n = SIZE_STACK (*q_clauses);
assert (n == SIZE_STACK (*q_matches)); KISSAT_assert (n == SIZE_STACK (*q_matches));
bool prev_is_first = !prev->id; bool prev_is_first = !prev->id;
size_t i = 0; size_t i = 0;
while (i != n) { while (i != n) {
size_t j = PEEK_STACK (*q_matches, i); size_t j = PEEK_STACK (*q_matches, i);
assert (i <= j); KISSAT_assert (i <= j);
if (!prev_is_first) { if (!prev_is_first) {
size_t matches = PEEK_STACK (*prev_matches, j); size_t matches = PEEK_STACK (*prev_matches, j);
POKE_STACK (*prev_matches, i, matches); POKE_STACK (*prev_matches, i, matches);
@ -728,22 +739,22 @@ static void add_factored_quotient (factoring *factoring, quotient *q,
const reference c_ref = watch.large.ref; const reference c_ref = watch.large.ref;
clause *const c = kissat_dereference_clause (solver, c_ref); clause *const c = kissat_dereference_clause (solver, c_ref);
unsigneds *clause = &solver->clause; unsigneds *clause = &solver->clause;
assert (EMPTY_STACK (*clause)); KISSAT_assert (EMPTY_STACK (*clause));
const unsigned factor = q->factor; const unsigned factor = q->factor;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
bool found = false; bool found = false;
#endif #endif
PUSH_STACK (*clause, not_fresh); PUSH_STACK (*clause, not_fresh);
for (all_literals_in_clause (other, c)) { for (all_literals_in_clause (other, c)) {
if (other == factor) { if (other == factor) {
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
found = true; found = true;
#endif #endif
continue; continue;
} }
PUSH_STACK (*clause, other); PUSH_STACK (*clause, other);
} }
assert (found); KISSAT_assert (found);
ADD (literals_factored, c->size); ADD (literals_factored, c->size);
kissat_new_irredundant_clause (solver); kissat_new_irredundant_clause (solver);
CLEAR_STACK (*clause); CLEAR_STACK (*clause);
@ -756,10 +767,10 @@ static void eagerly_remove_watch (kissat *solver, watches *watches,
watch needle) { watch needle) {
watch *p = BEGIN_WATCHES (*watches); watch *p = BEGIN_WATCHES (*watches);
watch *end = END_WATCHES (*watches); watch *end = END_WATCHES (*watches);
assert (p != end); KISSAT_assert (p != end);
watch *last = end - 1; watch *last = end - 1;
while (p->raw != needle.raw) while (p->raw != needle.raw)
p++, assert (p != end); p++, KISSAT_assert (p != end);
if (p != last) if (p != last)
memmove (p, p + 1, (last - p) * sizeof *p); memmove (p, p + 1, (last - p) * sizeof *p);
SET_END_OF_WATCHES (*watches, last); SET_END_OF_WATCHES (*watches, last);
@ -833,7 +844,7 @@ static bool apply_factoring (factoring *factoring, quotient *q) {
delete_unfactored (factoring, p); delete_unfactored (factoring, p);
for (quotient *p = q; p; p = p->prev) for (quotient *p = q; p; p = p->prev)
update_factored (factoring, p); update_factored (factoring, p);
assert (fresh < not_fresh); KISSAT_assert (fresh < not_fresh);
resize_factoring (factoring, not_fresh); resize_factoring (factoring, not_fresh);
return true; return true;
} }
@ -871,16 +882,16 @@ adjust_scores_and_phases_of_fresh_varaibles (factoring *factoring) {
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
struct links *l = links + idx; struct links *l = links + idx;
if (DISCONNECTED (queue->first)) { if (DISCONNECTED (queue->first)) {
assert (DISCONNECTED (queue->last)); KISSAT_assert (DISCONNECTED (queue->last));
queue->last = idx; queue->last = idx;
} else { } else {
struct links *first = links + queue->first; struct links *first = links + queue->first;
assert (DISCONNECTED (first->prev)); KISSAT_assert (DISCONNECTED (first->prev));
first->prev = idx; first->prev = idx;
} }
l->next = queue->first; l->next = queue->first;
queue->first = idx; queue->first = idx;
assert (DISCONNECTED (l->prev)); KISSAT_assert (DISCONNECTED (l->prev));
l->stamp = ++queue->stamp; l->stamp = ++queue->stamp;
} }
while (!DISCONNECTED (rest)) { while (!DISCONNECTED (rest)) {
@ -898,10 +909,10 @@ static bool run_factorization (kissat *solver, uint64_t limit) {
init_factoring (solver, &factoring, limit); init_factoring (solver, &factoring, limit);
schedule_factorization (&factoring); schedule_factorization (&factoring);
bool done = false; bool done = false;
#ifndef QUIET #ifndef KISSAT_QUIET
unsigned factored = 0; unsigned factored = 0;
#endif #endif
uint64_t *ticks = &solver->statistics.factor_ticks; uint64_t *ticks = &solver->statistics_.factor_ticks;
kissat_extremely_verbose ( kissat_extremely_verbose (
solver, "factorization limit of %" PRIu64 " ticks", limit - *ticks); solver, "factorization limit of %" PRIu64 " ticks", limit - *ticks);
while (!done && !kissat_empty_heap (&factoring.schedule)) { while (!done && !kissat_empty_heap (&factoring.schedule)) {
@ -928,7 +939,7 @@ static bool run_factorization (kissat *solver, uint64_t limit) {
const unsigned next = next_factor (&factoring, &next_count); const unsigned next = next_factor (&factoring, &next_count);
if (next == INVALID_LIT) if (next == INVALID_LIT)
break; break;
assert (next_count > 1); KISSAT_assert (next_count > 1);
if (next_count < 2) if (next_count < 2)
break; break;
factorize_next (&factoring, next, next_count); factorize_next (&factoring, next, next_count);
@ -937,7 +948,7 @@ static bool run_factorization (kissat *solver, uint64_t limit) {
quotient *q = best_quotient (&factoring, &reduction); quotient *q = best_quotient (&factoring, &reduction);
if (q && reduction > factoring.bound) { if (q && reduction > factoring.bound) {
if (apply_factoring (&factoring, q)) { if (apply_factoring (&factoring, q)) {
#ifndef QUIET #ifndef KISSAT_QUIET
factored++; factored++;
#endif #endif
} else } else
@ -965,12 +976,12 @@ static void connect_clauses_to_factor (kissat *solver) {
ward *const arena = BEGIN_STACK (solver->arena); ward *const arena = BEGIN_STACK (solver->arena);
watches *all_watches = solver->watches; watches *all_watches = solver->watches;
unsigned *bincount, *largecount; unsigned *bincount, *largecount;
CALLOC (bincount, LITS); CALLOC (unsigned, bincount, LITS);
for (all_literals (lit)) { for (all_literals (lit)) {
if (!ACTIVE (IDX (lit))) if (!ACTIVE (IDX (lit)))
continue; continue;
for (all_binary_large_watches (watch, WATCHES (lit))) { for (all_binary_large_watches (watch, WATCHES (lit))) {
assert (watch.type.binary); KISSAT_assert (watch.type.binary);
const unsigned other = watch.type.lit; const unsigned other = watch.type.lit;
if (lit > other) if (lit > other)
continue; continue;
@ -978,7 +989,7 @@ static void connect_clauses_to_factor (kissat *solver) {
bincount[other]++; bincount[other]++;
} }
} }
CALLOC (largecount, LITS); CALLOC (unsigned, largecount, LITS);
size_t initial_candidates = 0; size_t initial_candidates = 0;
for (all_clauses (c)) { for (all_clauses (c)) {
if (c->garbage) if (c->garbage)
@ -1001,7 +1012,7 @@ static void connect_clauses_to_factor (kissat *solver) {
for (unsigned round = 1; round <= rounds; round++) { for (unsigned round = 1; round <= rounds; round++) {
size_t new_candidates = 0; size_t new_candidates = 0;
unsigned *newlargecount; unsigned *newlargecount;
CALLOC (newlargecount, LITS); CALLOC (unsigned, newlargecount, LITS);
for (all_clauses (c)) { for (all_clauses (c)) {
if (c->garbage) if (c->garbage)
continue; continue;
@ -1035,7 +1046,7 @@ static void connect_clauses_to_factor (kissat *solver) {
"round %u", "round %u",
candidates, kissat_percent (candidates, initial_candidates), round); candidates, kissat_percent (candidates, initial_candidates), round);
} }
#ifndef QUIET #ifndef KISSAT_QUIET
size_t connected = 0; size_t connected = 0;
#endif #endif
for (all_clauses (c)) { for (all_clauses (c)) {
@ -1047,15 +1058,20 @@ static void connect_clauses_to_factor (kissat *solver) {
continue; continue;
if (c->size > size_limit) if (c->size > size_limit)
continue; continue;
int continue_with_next_clause2 = 0;
for (all_literals_in_clause (lit, c)) for (all_literals_in_clause (lit, c))
if (bincount[lit] + largecount[lit] < 2) if (bincount[lit] + largecount[lit] < 2) {
goto CONTINUE_WITH_NEXT_CLAUSE2; continue_with_next_clause2 = 1;
break;
}
if(continue_with_next_clause2) {
continue;
}
const reference ref = (ward *) c - arena; const reference ref = (ward *) c - arena;
kissat_inlined_connect_clause (solver, all_watches, c, ref); kissat_inlined_connect_clause (solver, all_watches, c, ref);
#ifndef QUIET #ifndef KISSAT_QUIET
connected++; connected++;
#endif #endif
CONTINUE_WITH_NEXT_CLAUSE2:;
} }
DEALLOC (largecount, LITS); DEALLOC (largecount, LITS);
DEALLOC (bincount, LITS); DEALLOC (bincount, LITS);
@ -1065,12 +1081,12 @@ static void connect_clauses_to_factor (kissat *solver) {
} }
void kissat_factor (kissat *solver) { void kissat_factor (kissat *solver) {
assert (!solver->level); KISSAT_assert (!solver->level);
if (solver->inconsistent) if (solver->inconsistent)
return; return;
if (!GET_OPTION (factor)) if (!GET_OPTION (factor))
return; return;
statistics *s = &solver->statistics; statistics *s = &solver->statistics_;
if (solver->limits.factor.marked >= s->literals_factor) { if (solver->limits.factor.marked >= s->literals_factor) {
kissat_extremely_verbose ( kissat_extremely_verbose (
solver, solver,
@ -1095,7 +1111,7 @@ void kissat_factor (kissat *solver) {
limit *= 1e6; limit *= 1e6;
limit += s->factor_ticks; limit += s->factor_ticks;
} }
#ifndef QUIET #ifndef KISSAT_QUIET
struct { struct {
int64_t variables, binary, clauses, ticks; int64_t variables, binary, clauses, ticks;
} before, after, delta; } before, after, delta;
@ -1108,7 +1124,7 @@ void kissat_factor (kissat *solver) {
connect_clauses_to_factor (solver); connect_clauses_to_factor (solver);
bool completed = run_factorization (solver, limit); bool completed = run_factorization (solver, limit);
kissat_resume_sparse_mode (solver, false, 0); kissat_resume_sparse_mode (solver, false, 0);
#ifndef QUIET #ifndef KISSAT_QUIET
after.variables = s->variables_extension + s->variables_original; after.variables = s->variables_extension + s->variables_original;
after.binary = BINARY_CLAUSES; after.binary = BINARY_CLAUSES;
after.clauses = IRREDUNDANT_CLAUSES; after.clauses = IRREDUNDANT_CLAUSES;
@ -1134,3 +1150,5 @@ void kissat_factor (kissat *solver) {
solver->limits.factor.marked = s->literals_factor; solver->limits.factor.marked = s->literals_factor;
STOP (factor); STOP (factor);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,7 +3,12 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
void kissat_factor (struct kissat *); void kissat_factor (struct kissat *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -6,6 +6,9 @@
#include "inline.h" #include "inline.h"
#include "inlineassign.h" #include "inlineassign.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
static inline void kissat_fast_binary_assign ( static inline void kissat_fast_binary_assign (
kissat *solver, const bool probing, const unsigned level, value *values, kissat *solver, const bool probing, const unsigned level, value *values,
assigned *assigned, unsigned lit, unsigned other) { assigned *assigned, unsigned lit, unsigned other) {
@ -27,15 +30,17 @@ static inline void
kissat_fast_assign_reference (kissat *solver, value *values, kissat_fast_assign_reference (kissat *solver, value *values,
assigned *assigned, unsigned lit, assigned *assigned, unsigned lit,
reference ref, clause *reason) { reference ref, clause *reason) {
assert (reason == kissat_dereference_clause (solver, ref)); KISSAT_assert (reason == kissat_dereference_clause (solver, ref));
const unsigned level = const unsigned level =
kissat_assignment_level (solver, values, assigned, lit, reason); kissat_assignment_level (solver, values, assigned, lit, reason);
assert (level <= solver->level); KISSAT_assert (level <= solver->level);
assert (ref != DECISION_REASON); KISSAT_assert (ref != DECISION_REASON);
assert (ref != UNIT_REASON); KISSAT_assert (ref != UNIT_REASON);
kissat_fast_assign (solver, solver->probing, level, values, assigned, kissat_fast_assign (solver, solver->probing, level, values, assigned,
false, lit, ref); false, lit, ref);
LOGREF (ref, "assign %s reason", LOGLIT (lit)); LOGREF (ref, "assign %s reason", LOGLIT (lit));
} }
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -9,9 +9,11 @@
#include "terminate.h" #include "terminate.h"
#include "weaken.h" #include "weaken.h"
ABC_NAMESPACE_IMPL_START
static bool fast_forward_subsumed (kissat *solver, clause *c) { static bool fast_forward_subsumed (kissat *solver, clause *c) {
assert (!c->garbage); KISSAT_assert (!c->garbage);
assert (!c->redundant); KISSAT_assert (!c->redundant);
unsigned max_occurring = INVALID_LIT; unsigned max_occurring = INVALID_LIT;
size_t max_occurrence = 0; size_t max_occurrence = 0;
watches *all_watches = solver->watches; watches *all_watches = solver->watches;
@ -58,7 +60,7 @@ static bool fast_forward_subsumed (kissat *solver, clause *c) {
continue; continue;
if (d->size > c->size) if (d->size > c->size)
continue; continue;
assert (!d->redundant); KISSAT_assert (!d->redundant);
subsumed = true; subsumed = true;
for (all_literals_in_clause (other2, d)) { for (all_literals_in_clause (other2, d)) {
if (values[other2] < 0) if (values[other2] < 0)
@ -147,8 +149,8 @@ static size_t flush_occurrences (kissat *solver, unsigned lit) {
static void do_fast_resolve_binary_binary (kissat *solver, unsigned pivot, static void do_fast_resolve_binary_binary (kissat *solver, unsigned pivot,
unsigned clit, unsigned dlit) { unsigned clit, unsigned dlit) {
assert (!FLAGS (IDX (clit))->eliminated); KISSAT_assert (!FLAGS (IDX (clit))->eliminated);
assert (!FLAGS (IDX (dlit))->eliminated); KISSAT_assert (!FLAGS (IDX (dlit))->eliminated);
if (clit == NOT (dlit)) { if (clit == NOT (dlit)) {
LOG ("resolvent tautological"); LOG ("resolvent tautological");
return; return;
@ -165,7 +167,7 @@ static void do_fast_resolve_binary_binary (kissat *solver, unsigned pivot,
return; return;
} }
if (cval < 0 && dval < 0) { if (cval < 0 && dval < 0) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
solver->inconsistent = true; solver->inconsistent = true;
LOG ("resolved empty clause"); LOG ("resolved empty clause");
CHECK_AND_ADD_EMPTY (); CHECK_AND_ADD_EMPTY ();
@ -190,10 +192,10 @@ static void do_fast_resolve_binary_binary (kissat *solver, unsigned pivot,
kissat_learned_unit (solver, clit); kissat_learned_unit (solver, clit);
return; return;
} }
assert (!cval); KISSAT_assert (!cval);
assert (!dval); KISSAT_assert (!dval);
unsigneds *clause = &solver->clause; unsigneds *clause = &solver->clause;
assert (EMPTY_STACK (*clause)); KISSAT_assert (EMPTY_STACK (*clause));
PUSH_STACK (*clause, clit); PUSH_STACK (*clause, clit);
PUSH_STACK (*clause, dlit); PUSH_STACK (*clause, dlit);
LOGTMP ("%s resolvent", LOGVAR (pivot)); LOGTMP ("%s resolvent", LOGVAR (pivot));
@ -206,10 +208,10 @@ static void do_fast_resolve_binary_binary (kissat *solver, unsigned pivot,
static void do_fast_resolve_binary_large (kissat *solver, unsigned pivot, static void do_fast_resolve_binary_large (kissat *solver, unsigned pivot,
unsigned lit, clause *c) { unsigned lit, clause *c) {
assert (!FLAGS (IDX (lit))->eliminated); KISSAT_assert (!FLAGS (IDX (lit))->eliminated);
if (c->garbage) if (c->garbage)
return; return;
assert (!c->redundant); KISSAT_assert (!c->redundant);
value *values = solver->values; value *values = solver->values;
value lit_val = values[lit]; value lit_val = values[lit];
if (lit_val > 0) { if (lit_val > 0) {
@ -217,7 +219,7 @@ static void do_fast_resolve_binary_large (kissat *solver, unsigned pivot,
return; return;
} }
unsigneds *clause = &solver->clause; unsigneds *clause = &solver->clause;
assert (EMPTY_STACK (*clause)); KISSAT_assert (EMPTY_STACK (*clause));
if (!lit_val) if (!lit_val)
PUSH_STACK (*clause, lit); PUSH_STACK (*clause, lit);
bool satisfied = false, tautological = false; bool satisfied = false, tautological = false;
@ -250,7 +252,7 @@ static void do_fast_resolve_binary_large (kissat *solver, unsigned pivot,
} }
size_t size = SIZE_STACK (*clause); size_t size = SIZE_STACK (*clause);
if (!size) { if (!size) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
solver->inconsistent = true; solver->inconsistent = true;
LOG ("resolved empty clause"); LOG ("resolved empty clause");
CHECK_AND_ADD_EMPTY (); CHECK_AND_ADD_EMPTY ();
@ -276,12 +278,12 @@ static void do_fast_resolve_large_large (kissat *solver, unsigned pivot,
return; return;
if (d->garbage) if (d->garbage)
return; return;
assert (!c->redundant); KISSAT_assert (!c->redundant);
assert (!d->redundant); KISSAT_assert (!d->redundant);
value *values = solver->values; value *values = solver->values;
mark *marks = solver->marks; mark *marks = solver->marks;
unsigneds *clause = &solver->clause; unsigneds *clause = &solver->clause;
assert (EMPTY_STACK (*clause)); KISSAT_assert (EMPTY_STACK (*clause));
bool satisfied = false, tautological = false; bool satisfied = false, tautological = false;
for (all_literals_in_clause (other, c)) { for (all_literals_in_clause (other, c)) {
const unsigned idx_other = IDX (other); const unsigned idx_other = IDX (other);
@ -337,7 +339,7 @@ static void do_fast_resolve_large_large (kissat *solver, unsigned pivot,
} }
size_t size = SIZE_STACK (*clause); size_t size = SIZE_STACK (*clause);
if (!size) { if (!size) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
solver->inconsistent = true; solver->inconsistent = true;
LOG ("resolved empty clause"); LOG ("resolved empty clause");
CHECK_AND_ADD_EMPTY (); CHECK_AND_ADD_EMPTY ();
@ -363,7 +365,7 @@ static void do_fast_resolve_large_large (kissat *solver, unsigned pivot,
static void do_fast_resolve (kissat *solver, unsigned pivot, watch cwatch, static void do_fast_resolve (kissat *solver, unsigned pivot, watch cwatch,
watch dwatch) { watch dwatch) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
LOGWATCH (LIT (pivot), cwatch, "1st fast %s elimination antecedent", LOGWATCH (LIT (pivot), cwatch, "1st fast %s elimination antecedent",
LOGVAR (pivot)); LOGVAR (pivot));
LOGWATCH (NOT (LIT (pivot)), dwatch, "1st fast %s elimination antecedent", LOGWATCH (NOT (LIT (pivot)), dwatch, "1st fast %s elimination antecedent",
@ -383,7 +385,7 @@ static void do_fast_resolve (kissat *solver, unsigned pivot, watch cwatch,
else if (!cbin && dbin) else if (!cbin && dbin)
do_fast_resolve_binary_large (solver, pivot, dlit, c); do_fast_resolve_binary_large (solver, pivot, dlit, c);
else { else {
assert (!cbin), assert (!dbin); KISSAT_assert (!cbin), KISSAT_assert (!dbin);
do_fast_resolve_large_large (solver, pivot, c, d); do_fast_resolve_large_large (solver, pivot, c, d);
} }
} }
@ -449,7 +451,7 @@ static void do_fast_eliminate (kissat *solver, unsigned pivot) {
p = begin_lit_watches + i; p = begin_lit_watches + i;
q = begin_not_lit_watches + j; q = begin_not_lit_watches + j;
} }
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
INC (eliminated); INC (eliminated);
INC (fast_eliminated); INC (fast_eliminated);
kissat_mark_eliminated_variable (solver, pivot); kissat_mark_eliminated_variable (solver, pivot);
@ -459,8 +461,8 @@ static void do_fast_eliminate (kissat *solver, unsigned pivot) {
static bool can_fast_resolve_binary_binary (kissat *solver, unsigned clit, static bool can_fast_resolve_binary_binary (kissat *solver, unsigned clit,
unsigned dlit) { unsigned dlit) {
assert (!FLAGS (IDX (clit))->eliminated); KISSAT_assert (!FLAGS (IDX (clit))->eliminated);
assert (!FLAGS (IDX (dlit))->eliminated); KISSAT_assert (!FLAGS (IDX (dlit))->eliminated);
if (clit == NOT (dlit)) if (clit == NOT (dlit))
return false; return false;
value *values = solver->values; value *values = solver->values;
@ -471,7 +473,7 @@ static bool can_fast_resolve_binary_binary (kissat *solver, unsigned clit,
if (dval > 0) if (dval > 0)
return false; return false;
if (cval < 0 && dval < 0) { if (cval < 0 && dval < 0) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
solver->inconsistent = true; solver->inconsistent = true;
LOG ("resolved empty clause"); LOG ("resolved empty clause");
CHECK_AND_ADD_EMPTY (); CHECK_AND_ADD_EMPTY ();
@ -496,17 +498,17 @@ static bool can_fast_resolve_binary_binary (kissat *solver, unsigned clit,
kissat_learned_unit (solver, clit); kissat_learned_unit (solver, clit);
return false; return false;
} }
assert (!cval); KISSAT_assert (!cval);
assert (!dval); KISSAT_assert (!dval);
return true; return true;
} }
static bool can_fast_resolve_binary_large (kissat *solver, unsigned pivot, static bool can_fast_resolve_binary_large (kissat *solver, unsigned pivot,
unsigned lit, clause *c) { unsigned lit, clause *c) {
assert (!FLAGS (IDX (lit))->eliminated); KISSAT_assert (!FLAGS (IDX (lit))->eliminated);
if (c->garbage) if (c->garbage)
return false; return false;
assert (!c->redundant); KISSAT_assert (!c->redundant);
value *values = solver->values; value *values = solver->values;
value lit_val = values[lit]; value lit_val = values[lit];
if (lit_val > 0) if (lit_val > 0)
@ -527,7 +529,7 @@ static bool can_fast_resolve_binary_large (kissat *solver, unsigned pivot,
} }
if (found_lit) { if (found_lit) {
unsigneds *clause = &solver->clause; unsigneds *clause = &solver->clause;
assert (EMPTY_STACK (*clause)); KISSAT_assert (EMPTY_STACK (*clause));
for (all_literals_in_clause (other, c)) { for (all_literals_in_clause (other, c)) {
const unsigned idx = IDX (other); const unsigned idx = IDX (other);
if (idx == pivot) if (idx == pivot)
@ -535,7 +537,7 @@ static bool can_fast_resolve_binary_large (kissat *solver, unsigned pivot,
value value = values[other]; value value = values[other];
if (value < 0) if (value < 0)
continue; continue;
assert (!value); KISSAT_assert (!value);
PUSH_STACK (*clause, other); PUSH_STACK (*clause, other);
} }
LOGTMP ("self-subsuming resolvent"); LOGTMP ("self-subsuming resolvent");
@ -544,7 +546,7 @@ static bool can_fast_resolve_binary_large (kissat *solver, unsigned pivot,
const size_t size = SIZE_STACK (*clause); const size_t size = SIZE_STACK (*clause);
const reference ref = kissat_reference_clause (solver, c); const reference ref = kissat_reference_clause (solver, c);
if (!size) { if (!size) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
solver->inconsistent = true; solver->inconsistent = true;
LOG ("resolved empty clause"); LOG ("resolved empty clause");
CHECK_AND_ADD_EMPTY (); CHECK_AND_ADD_EMPTY ();
@ -571,13 +573,13 @@ static bool can_fast_resolve_large_large (kissat *solver, unsigned pivot,
return false; return false;
if (d->garbage) if (d->garbage)
return false; return false;
assert (!c->redundant); KISSAT_assert (!c->redundant);
assert (!d->redundant); KISSAT_assert (!d->redundant);
value *values = solver->values; value *values = solver->values;
mark *marks = solver->marks; mark *marks = solver->marks;
bool satisfied = false; bool satisfied = false;
unsigneds *clause = &solver->clause; unsigneds *clause = &solver->clause;
assert (EMPTY_STACK (*clause)); KISSAT_assert (EMPTY_STACK (*clause));
for (all_literals_in_clause (other, c)) { for (all_literals_in_clause (other, c)) {
const unsigned idx_other = IDX (other); const unsigned idx_other = IDX (other);
if (idx_other == pivot) if (idx_other == pivot)
@ -591,7 +593,7 @@ static bool can_fast_resolve_large_large (kissat *solver, unsigned pivot,
kissat_mark_clause_as_garbage (solver, c); kissat_mark_clause_as_garbage (solver, c);
break; break;
} }
assert (!marks[other]); KISSAT_assert (!marks[other]);
marks[other] = 1; marks[other] = 1;
PUSH_STACK (*clause, other); PUSH_STACK (*clause, other);
} }
@ -628,7 +630,7 @@ static bool can_fast_resolve_large_large (kissat *solver, unsigned pivot,
if (!satisfied && !tautological) { if (!satisfied && !tautological) {
const size_t size = SIZE_STACK (*clause); const size_t size = SIZE_STACK (*clause);
if (!size) { if (!size) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
solver->inconsistent = true; solver->inconsistent = true;
LOG ("resolved empty clause"); LOG ("resolved empty clause");
CHECK_AND_ADD_EMPTY (); CHECK_AND_ADD_EMPTY ();
@ -698,7 +700,7 @@ static bool can_fast_resolve_large_large (kissat *solver, unsigned pivot,
static bool can_fast_resolve (kissat *solver, unsigned pivot, watch cwatch, static bool can_fast_resolve (kissat *solver, unsigned pivot, watch cwatch,
watch dwatch) { watch dwatch) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
const unsigned clit = cwatch.binary.lit; const unsigned clit = cwatch.binary.lit;
const unsigned dlit = dwatch.binary.lit; const unsigned dlit = dwatch.binary.lit;
const reference cref = cwatch.large.ref; const reference cref = cwatch.large.ref;
@ -713,7 +715,7 @@ static bool can_fast_resolve (kissat *solver, unsigned pivot, watch cwatch,
return can_fast_resolve_binary_large (solver, pivot, clit, d); return can_fast_resolve_binary_large (solver, pivot, clit, d);
if (!cbin && dbin) if (!cbin && dbin)
return can_fast_resolve_binary_large (solver, pivot, dlit, c); return can_fast_resolve_binary_large (solver, pivot, dlit, c);
assert (!cbin), assert (!dbin); KISSAT_assert (!cbin), KISSAT_assert (!dbin);
return can_fast_resolve_large_large (solver, pivot, c, d); return can_fast_resolve_large_large (solver, pivot, c, d);
} }
@ -752,7 +754,7 @@ static bool resolvents_limited (kissat *solver, unsigned pivot,
} }
static bool try_to_fast_eliminate (kissat *solver, unsigned pivot) { static bool try_to_fast_eliminate (kissat *solver, unsigned pivot) {
assert (!solver->inconsistent); KISSAT_assert (!solver->inconsistent);
if (!ACTIVE (pivot)) if (!ACTIVE (pivot))
return false; return false;
const unsigned lit = LIT (pivot); const unsigned lit = LIT (pivot);
@ -824,16 +826,16 @@ void kissat_fast_variable_elimination (kissat *solver) {
return; return;
if (!GET_OPTION (fastel)) if (!GET_OPTION (fastel))
return; return;
#ifndef QUIET #ifndef KISSAT_QUIET
const unsigned variables_before = solver->active; const unsigned variables_before = solver->active;
#endif #endif
assert (!solver->level); KISSAT_assert (!solver->level);
START (fastel); START (fastel);
kissat_enter_dense_mode (solver, 0); kissat_enter_dense_mode (solver, 0);
kissat_connect_irredundant_large_clauses (solver); kissat_connect_irredundant_large_clauses (solver);
const unsigned fastelrounds = GET_OPTION (fastelrounds); const unsigned fastelrounds = GET_OPTION (fastelrounds);
const size_t fasteloccs = GET_OPTION (fasteloccs); const size_t fasteloccs = GET_OPTION (fasteloccs);
#ifndef QUIET #ifndef KISSAT_QUIET
unsigned eliminated = 0; unsigned eliminated = 0;
#endif #endif
unsigned round = 0; unsigned round = 0;
@ -846,7 +848,7 @@ void kissat_fast_variable_elimination (kissat *solver) {
kissat_extremely_verbose ( kissat_extremely_verbose (
solver, "gathering candidates for fast elimination round %u", solver, "gathering candidates for fast elimination round %u",
round); round);
assert (EMPTY_STACK (candidates)); KISSAT_assert (EMPTY_STACK (candidates));
flags *all_flags = solver->flags; flags *all_flags = solver->flags;
for (all_variables (pivot)) { for (all_variables (pivot)) {
flags *pivot_flags = all_flags + pivot; flags *pivot_flags = all_flags + pivot;
@ -868,7 +870,7 @@ void kissat_fast_variable_elimination (kissat *solver) {
candidate candidate = {pivot, score}; candidate candidate = {pivot, score};
PUSH_STACK (candidates, candidate); PUSH_STACK (candidates, candidate);
} }
#ifndef QUIET #ifndef KISSAT_QUIET
const size_t size_candidates = SIZE_STACK (candidates); const size_t size_candidates = SIZE_STACK (candidates);
const size_t active_variables = solver->active; const size_t active_variables = solver->active;
kissat_extremely_verbose ( kissat_extremely_verbose (
@ -903,7 +905,7 @@ void kissat_fast_variable_elimination (kissat *solver) {
} }
} }
CLEAR_STACK (candidates); CLEAR_STACK (candidates);
#ifndef QUIET #ifndef KISSAT_QUIET
eliminated += eliminated_this_round; eliminated += eliminated_this_round;
kissat_very_verbose ( kissat_very_verbose (
solver, "fast eliminated %u of %zu candidates %.0f%% in round %u", solver, "fast eliminated %u of %zu candidates %.0f%% in round %u",
@ -918,7 +920,7 @@ void kissat_fast_variable_elimination (kissat *solver) {
FLAGS (idx)->eliminate = true; FLAGS (idx)->eliminate = true;
flush_eliminated_binary_clauses (solver); flush_eliminated_binary_clauses (solver);
kissat_resume_sparse_mode (solver, true, 0); kissat_resume_sparse_mode (solver, true, 0);
#ifndef QUIET #ifndef KISSAT_QUIET
const unsigned original_variables = solver->statistics.variables_original; const unsigned original_variables = solver->statistics.variables_original;
const unsigned variables_after = solver->active; const unsigned variables_after = solver->active;
kissat_verbose ( kissat_verbose (
@ -932,3 +934,5 @@ void kissat_fast_variable_elimination (kissat *solver) {
STOP (fastel); STOP (fastel);
REPORT (!eliminated, 'e'); REPORT (!eliminated, 'e');
} }
ABC_NAMESPACE_IMPL_END

View File

@ -1,6 +1,11 @@
#ifndef _fastel_h_INCLUDED #ifndef _fastel_h_INCLUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
void kissat_fast_variable_elimination (struct kissat *); void kissat_fast_variable_elimination (struct kissat *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -5,6 +5,9 @@
#include <string.h> #include <string.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
#define FIFO(TYPE) \ #define FIFO(TYPE) \
struct { \ struct { \
TYPE *begin; \ TYPE *begin; \
@ -29,7 +32,7 @@
#define MOVABLE_FIFO(F) (BEGIN_FIFO (F) == LIMIT_FIFO (F)) #define MOVABLE_FIFO(F) (BEGIN_FIFO (F) == LIMIT_FIFO (F))
#define CAPACITY_FIFO(F) (ALLOCATED_FIFO (F) - START_FIFO (F)) #define CAPACITY_FIFO(F) (ALLOCATED_FIFO (F) - START_FIFO (F))
#define ENLARGE_FIFO(F) \ #define ENLARGE_FIFO(T, F) \
do { \ do { \
size_t OLD_BEGIN_OFFSET = BEGIN_FIFO (F) - START_FIFO (F); \ size_t OLD_BEGIN_OFFSET = BEGIN_FIFO (F) - START_FIFO (F); \
size_t OLD_END_OFFSET = END_FIFO (F) - START_FIFO (F); \ size_t OLD_END_OFFSET = END_FIFO (F) - START_FIFO (F); \
@ -38,12 +41,12 @@
size_t OLD_BYTES = OLD_CAPACITY * sizeof *BEGIN_FIFO (F); \ size_t OLD_BYTES = OLD_CAPACITY * sizeof *BEGIN_FIFO (F); \
size_t NEW_BYTES = NEW_CAPACITY * sizeof *BEGIN_FIFO (F); \ size_t NEW_BYTES = NEW_CAPACITY * sizeof *BEGIN_FIFO (F); \
START_FIFO (F) = \ START_FIFO (F) = \
kissat_realloc (solver, START_FIFO (F), OLD_BYTES, NEW_BYTES); \ (T*) kissat_realloc (solver, START_FIFO (F), OLD_BYTES, NEW_BYTES); \
ALLOCATED_FIFO (F) = START_FIFO (F) + NEW_CAPACITY; \ ALLOCATED_FIFO (F) = START_FIFO (F) + NEW_CAPACITY; \
LIMIT_FIFO (F) = START_FIFO (F) + NEW_CAPACITY / 2; \ LIMIT_FIFO (F) = START_FIFO (F) + NEW_CAPACITY / 2; \
BEGIN_FIFO (F) = START_FIFO (F) + OLD_BEGIN_OFFSET; \ BEGIN_FIFO (F) = START_FIFO (F) + OLD_BEGIN_OFFSET; \
END_FIFO (F) = START_FIFO (F) + OLD_END_OFFSET; \ END_FIFO (F) = START_FIFO (F) + OLD_END_OFFSET; \
assert (BEGIN_FIFO (F) < LIMIT_FIFO (F)); \ KISSAT_assert (BEGIN_FIFO (F) < LIMIT_FIFO (F)); \
} while (0) } while (0)
#define MOVE_FIFO(F) \ #define MOVE_FIFO(F) \
@ -55,22 +58,22 @@
END_FIFO (F) = BEGIN_FIFO (F) + SIZE; \ END_FIFO (F) = BEGIN_FIFO (F) + SIZE; \
} while (0) } while (0)
#define ENQUEUE_FIFO(F, E) \ #define ENQUEUE_FIFO(T, F, E) \
do { \ do { \
if (FULL_FIFO (F)) \ if (FULL_FIFO (F)) \
ENLARGE_FIFO (F); \ ENLARGE_FIFO (T, F); \
*END_FIFO (F)++ = (E); \ *END_FIFO (F)++ = (E); \
} while (0) } while (0)
#define DEQUEUE_FIFO(F, E) \ #define DEQUEUE_FIFO(F, E) \
do { \ do { \
assert (!EMPTY_FIFO (F)); \ KISSAT_assert (!EMPTY_FIFO (F)); \
(E) = *BEGIN_FIFO (F)++; \ (E) = *BEGIN_FIFO (F)++; \
if (MOVABLE_FIFO (F)) \ if (MOVABLE_FIFO (F)) \
MOVE_FIFO (F); \ MOVE_FIFO (F); \
} while (0) } while (0)
#define POP_FIFO(F) (assert (!EMPTY_FIFO (F)), *--END_FIFO (F)) #define POP_FIFO(F) (KISSAT_assert (!EMPTY_FIFO (F)), *--END_FIFO (F))
#define RELEASE_FIFO(F) \ #define RELEASE_FIFO(F) \
do { \ do { \
@ -94,4 +97,6 @@ typedef struct unsigned_fifo unsigned_fifo;
#define all_fifo all_stack #define all_fifo all_stack
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -7,7 +7,17 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef WIN32
#define unlink _unlink
#define access _access
#define R_OK 4
#define W_OK 2
#else
#include <unistd.h> #include <unistd.h>
#endif
ABC_NAMESPACE_IMPL_START
bool kissat_file_exists (const char *path) { bool kissat_file_exists (const char *path) {
if (!path) if (!path)
@ -57,7 +67,7 @@ bool kissat_file_writable (const char *path) {
res = 5; res = 5;
else { else {
const size_t len = p - path; const size_t len = p - path;
char *dirname = malloc (len + 1); char *dirname = (char*)malloc (len + 1);
if (dirname) { if (dirname) {
strncpy (dirname, path, len); strncpy (dirname, path, len);
dirname[len] = 0; dirname[len] = 0;
@ -98,7 +108,7 @@ bool kissat_find_executable (const char *name) {
if (!environment) if (!environment)
return false; return false;
const size_t dirs_len = strlen (environment); const size_t dirs_len = strlen (environment);
char *dirs = malloc (dirs_len + 1); char *dirs = (char*)malloc (dirs_len + 1);
if (!dirs) if (!dirs)
return false; return false;
strcpy (dirs, environment); strcpy (dirs, environment);
@ -106,16 +116,16 @@ bool kissat_find_executable (const char *name) {
const char *end = dirs + dirs_len + 1; const char *end = dirs + dirs_len + 1;
for (char *dir = dirs, *q; !res && dir != end; dir = q) { for (char *dir = dirs, *q; !res && dir != end; dir = q) {
for (q = dir; *q && *q != ':'; q++) for (q = dir; *q && *q != ':'; q++)
assert (q + 1 < end); KISSAT_assert (q + 1 < end);
*q++ = 0; *q++ = 0;
const size_t path_len = (q - dir) + name_len; const size_t path_len = (q - dir) + name_len;
char *path = malloc (path_len + 1); char *path = (char*)malloc (path_len + 1);
if (!path) { if (!path) {
free (dirs); free (dirs);
return false; return false;
} }
sprintf (path, "%s/%s", dir, name); sprintf (path, "%s/%s", dir, name);
assert (strlen (path) == path_len); KISSAT_assert (strlen (path) == path_len);
res = kissat_file_readable (path); res = kissat_file_readable (path);
free (path); free (path);
} }
@ -131,7 +141,7 @@ static int xzsig[] = {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00, 0x00, EOF};
static int Zsig[] = {0x1F, 0x9D, 0x90, EOF}; static int Zsig[] = {0x1F, 0x9D, 0x90, EOF};
static bool match_signature (const char *path, const int *sig) { static bool match_signature (const char *path, const int *sig) {
assert (path); KISSAT_assert (path);
FILE *tmp = fopen (path, "r"); FILE *tmp = fopen (path, "r");
if (!tmp) if (!tmp)
return false; return false;
@ -149,7 +159,7 @@ static FILE *open_pipe (const char *fmt, const char *path,
size_t name_len = 0; size_t name_len = 0;
while (fmt[name_len] && fmt[name_len] != ' ') while (fmt[name_len] && fmt[name_len] != ' ')
name_len++; name_len++;
char *name = malloc (name_len + 1); char *name = (char*)malloc (name_len + 1);
if (!name) if (!name)
return 0; return 0;
strncpy (name, fmt, name_len); strncpy (name, fmt, name_len);
@ -158,7 +168,7 @@ static FILE *open_pipe (const char *fmt, const char *path,
free (name); free (name);
if (!found) if (!found)
return 0; return 0;
char *cmd = malloc (strlen (fmt) + strlen (path)); char *cmd = (char*)malloc (strlen (fmt) + strlen (path));
if (!cmd) if (!cmd)
return 0; return 0;
sprintf (cmd, fmt, path); sprintf (cmd, fmt, path);
@ -296,15 +306,17 @@ bool kissat_open_to_write_file (file *file, const char *path) {
} }
void kissat_close_file (file *file) { void kissat_close_file (file *file) {
assert (file); KISSAT_assert (file);
assert (file->file); KISSAT_assert (file->file);
#ifdef KISSAT_HAS_COMPRESSION #ifdef KISSAT_HAS_COMPRESSION
if (file->close && file->compressed) if (file->close && file->compressed)
pclose (file->file); pclose (file->file);
#else #else
assert (!file->compressed); KISSAT_assert (!file->compressed);
#endif #endif
if (file->close && !file->compressed) if (file->close && !file->compressed)
fclose (file->file); fclose (file->file);
file->file = 0; file->file = 0;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -9,6 +9,9 @@
#include "attribute.h" #include "attribute.h"
#include "keatures.h" #include "keatures.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
bool kissat_file_exists (const char *path); bool kissat_file_exists (const char *path);
bool kissat_file_readable (const char *path); bool kissat_file_readable (const char *path);
bool kissat_file_writable (const char *path); bool kissat_file_writable (const char *path);
@ -57,9 +60,9 @@ static inline void kissat_flush (file *) ATTRIBUTE_ALWAYS_INLINE;
// clang-format on // clang-format on
static inline size_t kissat_read (file *file, void *ptr, size_t bytes) { static inline size_t kissat_read (file *file, void *ptr, size_t bytes) {
assert (file); KISSAT_assert (file);
assert (file->file); KISSAT_assert (file->file);
assert (file->reading); KISSAT_assert (file->reading);
#ifdef KISSAT_HAS_UNLOCKEDIO #ifdef KISSAT_HAS_UNLOCKEDIO
size_t res = fread_unlocked (ptr, 1, bytes, file->file); size_t res = fread_unlocked (ptr, 1, bytes, file->file);
#else #else
@ -70,9 +73,9 @@ static inline size_t kissat_read (file *file, void *ptr, size_t bytes) {
} }
static inline size_t kissat_write (file *file, void *ptr, size_t bytes) { static inline size_t kissat_write (file *file, void *ptr, size_t bytes) {
assert (file); KISSAT_assert (file);
assert (file->file); KISSAT_assert (file->file);
assert (!file->reading); KISSAT_assert (!file->reading);
#ifdef KISSAT_HAS_UNLOCKEDIO #ifdef KISSAT_HAS_UNLOCKEDIO
size_t res = fwrite_unlocked (ptr, 1, bytes, file->file); size_t res = fwrite_unlocked (ptr, 1, bytes, file->file);
#else #else
@ -83,9 +86,9 @@ static inline size_t kissat_write (file *file, void *ptr, size_t bytes) {
} }
static inline int kissat_getc (file *file) { static inline int kissat_getc (file *file) {
assert (file); KISSAT_assert (file);
assert (file->file); KISSAT_assert (file->file);
assert (file->reading); KISSAT_assert (file->reading);
#ifdef KISSAT_HAS_UNLOCKEDIO #ifdef KISSAT_HAS_UNLOCKEDIO
int res = getc_unlocked (file->file); int res = getc_unlocked (file->file);
#else #else
@ -97,9 +100,9 @@ static inline int kissat_getc (file *file) {
} }
static inline int kissat_putc (file *file, int ch) { static inline int kissat_putc (file *file, int ch) {
assert (file); KISSAT_assert (file);
assert (file->file); KISSAT_assert (file->file);
assert (!file->reading); KISSAT_assert (!file->reading);
#ifdef KISSAT_HAS_UNLOCKEDIO #ifdef KISSAT_HAS_UNLOCKEDIO
int res = putc_unlocked (ch, file->file); int res = putc_unlocked (ch, file->file);
#else #else
@ -111,9 +114,9 @@ static inline int kissat_putc (file *file, int ch) {
} }
static inline void kissat_flush (file *file) { static inline void kissat_flush (file *file) {
assert (file); KISSAT_assert (file);
assert (file->file); KISSAT_assert (file->file);
assert (!file->reading); KISSAT_assert (!file->reading);
#ifdef KISSAT_HAS_UNLOCKEDIO #ifdef KISSAT_HAS_UNLOCKEDIO
fflush_unlocked (file->file); fflush_unlocked (file->file);
#else #else
@ -121,4 +124,6 @@ static inline void kissat_flush (file *file) {
#endif #endif
} }
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -2,6 +2,8 @@
#include "inlineheap.h" #include "inlineheap.h"
#include "inlinequeue.h" #include "inlinequeue.h"
ABC_NAMESPACE_IMPL_START
static inline void activate_literal (kissat *solver, unsigned lit) { static inline void activate_literal (kissat *solver, unsigned lit) {
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
flags *f = FLAGS (idx); flags *f = FLAGS (idx);
@ -10,37 +12,37 @@ static inline void activate_literal (kissat *solver, unsigned lit) {
lit = STRIP (lit); lit = STRIP (lit);
LOG ("activating %s", LOGVAR (idx)); LOG ("activating %s", LOGVAR (idx));
f->active = true; f->active = true;
assert (!f->fixed); KISSAT_assert (!f->fixed);
assert (!f->eliminated); KISSAT_assert (!f->eliminated);
solver->active++; solver->active++;
INC (variables_activated); INC (variables_activated);
kissat_enqueue (solver, idx); kissat_enqueue (solver, idx);
const double score = 1.0 - 1.0 / solver->statistics.variables_activated; const double score = 1.0 - 1.0 / solver->statistics_.variables_activated;
kissat_update_heap (solver, &solver->scores, idx, score); kissat_update_heap (solver, &solver->scores, idx, score);
if (solver->stable) { if (solver->stable) {
const unsigned lit = LIT (idx); const unsigned lit = LIT (idx);
if (!VALUE (lit)) if (!VALUE (lit))
kissat_push_heap (solver, &solver->scores, idx); kissat_push_heap (solver, &solver->scores, idx);
} }
assert (solver->unassigned < UINT_MAX); KISSAT_assert (solver->unassigned < UINT_MAX);
solver->unassigned++; solver->unassigned++;
kissat_mark_removed_literal (solver, lit); kissat_mark_removed_literal (solver, lit);
kissat_mark_added_literal (solver, lit); kissat_mark_added_literal (solver, lit);
assert (!VALUE (lit)); KISSAT_assert (!VALUE (lit));
assert (!VALUE (NOT (lit))); KISSAT_assert (!VALUE (NOT (lit)));
assert (!SAVED (idx)); KISSAT_assert (!SAVED (idx));
assert (!TARGET (idx)); KISSAT_assert (!TARGET (idx));
assert (!BEST (idx)); KISSAT_assert (!BEST (idx));
} }
static inline void deactivate_variable (kissat *solver, flags *f, static inline void deactivate_variable (kissat *solver, flags *f,
unsigned idx) { unsigned idx) {
assert (solver->flags + idx == f); KISSAT_assert (solver->flags + idx == f);
LOG ("deactivating %s", LOGVAR (idx)); LOG ("deactivating %s", LOGVAR (idx));
assert (f->active); KISSAT_assert (f->active);
assert (f->eliminated || f->fixed); KISSAT_assert (f->eliminated || f->fixed);
f->active = false; f->active = false;
assert (solver->active > 0); KISSAT_assert (solver->active > 0);
solver->active--; solver->active--;
kissat_dequeue (solver, idx); kissat_dequeue (solver, idx);
if (kissat_heap_contains (SCORES, idx)) if (kissat_heap_contains (SCORES, idx))
@ -58,47 +60,47 @@ void kissat_activate_literals (kissat *solver, unsigned size,
} }
void kissat_mark_fixed_literal (kissat *solver, unsigned lit) { void kissat_mark_fixed_literal (kissat *solver, unsigned lit) {
assert (VALUE (lit) > 0); KISSAT_assert (VALUE (lit) > 0);
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
LOG ("marking internal %s as fixed", LOGVAR (idx)); LOG ("marking internal %s as fixed", LOGVAR (idx));
flags *f = FLAGS (idx); flags *f = FLAGS (idx);
assert (f->active); KISSAT_assert (f->active);
assert (!f->eliminated); KISSAT_assert (!f->eliminated);
assert (!f->fixed); KISSAT_assert (!f->fixed);
f->fixed = true; f->fixed = true;
deactivate_variable (solver, f, idx); deactivate_variable (solver, f, idx);
INC (units); INC (units);
int elit = kissat_export_literal (solver, lit); int elit = kissat_export_literal (solver, lit);
assert (elit); KISSAT_assert (elit);
PUSH_STACK (solver->units, elit); PUSH_STACK (solver->units, elit);
LOG ("pushed external unit literal %d (internal %u)", elit, lit); LOG ("pushed external unit literal %d (internal %u)", elit, lit);
} }
void kissat_mark_eliminated_variable (kissat *solver, unsigned idx) { void kissat_mark_eliminated_variable (kissat *solver, unsigned idx) {
const unsigned lit = LIT (idx); const unsigned lit = LIT (idx);
assert (!VALUE (lit)); KISSAT_assert (!VALUE (lit));
LOG ("marking internal %s as eliminated", LOGVAR (idx)); LOG ("marking internal %s as eliminated", LOGVAR (idx));
flags *f = FLAGS (idx); flags *f = FLAGS (idx);
assert (f->active); KISSAT_assert (f->active);
assert (!f->eliminated); KISSAT_assert (!f->eliminated);
assert (!f->fixed); KISSAT_assert (!f->fixed);
f->eliminated = true; f->eliminated = true;
deactivate_variable (solver, f, idx); deactivate_variable (solver, f, idx);
int elit = kissat_export_literal (solver, lit); int elit = kissat_export_literal (solver, lit);
assert (elit); KISSAT_assert (elit);
assert (elit != INT_MIN); KISSAT_assert (elit != INT_MIN);
unsigned eidx = ABS (elit); unsigned eidx = ABS (elit);
import *import = &PEEK_STACK (solver->import, eidx); import *import = &PEEK_STACK (solver->import, eidx);
assert (!import->eliminated); KISSAT_assert (!import->eliminated);
assert (import->imported); KISSAT_assert (import->imported);
assert (STRIP (import->lit) == STRIP (lit)); KISSAT_assert (STRIP (import->lit) == STRIP (lit));
size_t pos = SIZE_STACK (solver->eliminated); size_t pos = SIZE_STACK (solver->eliminated);
assert (pos < (1u << 30)); KISSAT_assert (pos < (1u << 30));
import->lit = pos; import->lit = pos;
import->eliminated = true; import->eliminated = true;
PUSH_STACK (solver->eliminated, (value) 0); PUSH_STACK (solver->eliminated, (value) 0);
LOG ("marked external variable %u as eliminated", eidx); LOG ("marked external variable %u as eliminated", eidx);
assert (solver->unassigned > 0); KISSAT_assert (solver->unassigned > 0);
solver->unassigned--; solver->unassigned--;
} }
@ -113,3 +115,5 @@ void kissat_mark_added_literals (kissat *solver, unsigned size,
for (unsigned i = 0; i < size; i++) for (unsigned i = 0; i < size; i++)
kissat_mark_added_literal (solver, lits[i]); kissat_mark_added_literal (solver, lits[i]);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,6 +3,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
typedef struct flags flags; typedef struct flags flags;
struct flags { struct flags {
@ -18,7 +21,7 @@ struct flags {
bool transitive : 1; bool transitive : 1;
}; };
#define FLAGS(IDX) (assert ((IDX) < VARS), (solver->flags + (IDX))) #define FLAGS(IDX) (KISSAT_assert ((IDX) < VARS), (solver->flags + (IDX)))
#define ACTIVE(IDX) (FLAGS (IDX)->active) #define ACTIVE(IDX) (FLAGS (IDX)->active)
#define ELIMINATED(IDX) (FLAGS (IDX)->eliminated) #define ELIMINATED(IDX) (FLAGS (IDX)->eliminated)
@ -34,4 +37,6 @@ void kissat_mark_fixed_literal (struct kissat *, unsigned lit);
void kissat_mark_added_literals (struct kissat *, unsigned, unsigned *); void kissat_mark_added_literals (struct kissat *, unsigned, unsigned *);
void kissat_mark_removed_literals (struct kissat *, unsigned, unsigned *); void kissat_mark_removed_literals (struct kissat *, unsigned, unsigned *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -7,8 +7,10 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
char *kissat_next_format_string (format *format) { ABC_NAMESPACE_IMPL_START
assert (format->pos < NUM_FORMAT_STRINGS);
char *kissat_next_format_string (kormat *format) {
KISSAT_assert (format->pos < NUM_FORMAT_STRINGS);
char *res = format->str[format->pos++]; char *res = format->str[format->pos++];
if (format->pos == NUM_FORMAT_STRINGS) if (format->pos == NUM_FORMAT_STRINGS)
format->pos = 0; format->pos = 0;
@ -19,7 +21,7 @@ static void format_count (char *res, uint64_t w) {
if (w >= 128 && kissat_is_power_of_two (w)) { if (w >= 128 && kissat_is_power_of_two (w)) {
unsigned l; unsigned l;
for (l = 0; ((uint64_t) 1 << l) != w; l++) for (l = 0; ((uint64_t) 1 << l) != w; l++)
assert (l + 1 < 8 * sizeof (word)); KISSAT_assert (l + 1 < 8 * sizeof (word));
sprintf (res, "2^%u", l); sprintf (res, "2^%u", l);
} else if (w >= 1000 && !(w % 1000)) { } else if (w >= 1000 && !(w % 1000)) {
unsigned l; unsigned l;
@ -30,13 +32,13 @@ static void format_count (char *res, uint64_t w) {
sprintf (res, "%" PRIu64, w); sprintf (res, "%" PRIu64, w);
} }
const char *kissat_format_count (format *format, uint64_t w) { const char *kissat_format_count (kormat *format, uint64_t w) {
char *res = kissat_next_format_string (format); char *res = kissat_next_format_string (format);
format_count (res, w); format_count (res, w);
return res; return res;
} }
const char *kissat_format_value (format *format, bool boolean, int value) { const char *kissat_format_value (kormat *format, bool boolean, int value) {
if (boolean && value) if (boolean && value)
return "true"; return "true";
if (boolean && !value) if (boolean && !value)
@ -54,7 +56,7 @@ const char *kissat_format_value (format *format, bool boolean, int value) {
return res; return res;
} }
const char *kissat_format_bytes (format *format, uint64_t bytes) { const char *kissat_format_bytes (kormat *format, uint64_t bytes) {
char *res = kissat_next_format_string (format); char *res = kissat_next_format_string (format);
if (bytes < (1u << 10)) if (bytes < (1u << 10))
sprintf (res, "%" PRIu64 " bytes", bytes); sprintf (res, "%" PRIu64 " bytes", bytes);
@ -70,7 +72,7 @@ const char *kissat_format_bytes (format *format, uint64_t bytes) {
return res; return res;
} }
const char *kissat_format_time (format *format, double seconds) { const char *kissat_format_time (kormat *format, double seconds) {
if (!seconds) if (!seconds)
return "0s"; return "0s";
char *res = kissat_next_format_string (format); char *res = kissat_next_format_string (format);
@ -106,10 +108,10 @@ const char *kissat_format_time (format *format, double seconds) {
return res; return res;
} }
const char *kissat_format_signs (format *format, unsigned size, const char *kissat_format_signs (kormat *format, unsigned size,
word signs) { word signs) {
char *res = kissat_next_format_string (format); char *res = kissat_next_format_string (format);
assert (size + 1 < FORMAT_STRING_SIZE); KISSAT_assert (size + 1 < FORMAT_STRING_SIZE);
char *p = res; char *p = res;
word bit = 1; word bit = 1;
for (unsigned i = 0; i < size; i++, bit <<= 1) for (unsigned i = 0; i < size; i++, bit <<= 1)
@ -118,7 +120,7 @@ const char *kissat_format_signs (format *format, unsigned size,
return res; return res;
} }
const char *kissat_format_ordinal (format *format, uint64_t ordinal) { const char *kissat_format_ordinal (kormat *format, uint64_t ordinal) {
char const *suffix; char const *suffix;
unsigned mod100 = ordinal % 100; unsigned mod100 = ordinal % 100;
if (10 <= mod100 && mod100 <= 19) if (10 <= mod100 && mod100 <= 19)
@ -143,3 +145,5 @@ const char *kissat_format_ordinal (format *format, uint64_t ordinal) {
sprintf (res, "%" PRIu64 "%s", ordinal, suffix); sprintf (res, "%" PRIu64 "%s", ordinal, suffix);
return res; return res;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -6,24 +6,27 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
#define NUM_FORMAT_STRINGS 16 #define NUM_FORMAT_STRINGS 16
#define FORMAT_STRING_SIZE 128 #define FORMAT_STRING_SIZE 128
typedef struct format format; typedef struct kormat kormat;
struct format { struct kormat {
unsigned pos; unsigned pos;
char str[NUM_FORMAT_STRINGS][FORMAT_STRING_SIZE]; char str[NUM_FORMAT_STRINGS][FORMAT_STRING_SIZE];
}; };
char *kissat_next_format_string (format *); char *kissat_next_format_string (kormat *);
char const *kissat_format_bytes (format *, uint64_t bytes); char const *kissat_format_bytes (kormat *, uint64_t bytes);
char const *kissat_format_count (format *, uint64_t); char const *kissat_format_count (kormat *, uint64_t);
char const *kissat_format_ordinal (format *, uint64_t); char const *kissat_format_ordinal (kormat *, uint64_t);
char const *kissat_format_signs (format *, unsigned size, word); char const *kissat_format_signs (kormat *, unsigned size, word);
char const *kissat_format_time (format *, double seconds); char const *kissat_format_time (kormat *, double seconds);
char const *kissat_format_value (format *, bool boolean, int value); char const *kissat_format_value (kormat *, bool boolean, int value);
#define FORMAT_BYTES(BYTES) kissat_format_bytes (&solver->format, BYTES) #define FORMAT_BYTES(BYTES) kissat_format_bytes (&solver->format, BYTES)
@ -39,4 +42,6 @@ char const *kissat_format_value (format *, bool boolean, int value);
#define FORMAT_VALUE(BOOLEAN, VALUE) \ #define FORMAT_VALUE(BOOLEAN, VALUE) \
kissat_format_value (&solver->format, BOOLEAN, VALUE) kissat_format_value (&solver->format, BOOLEAN, VALUE)
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -10,6 +10,8 @@
#include <inttypes.h> #include <inttypes.h>
ABC_NAMESPACE_IMPL_START
static size_t remove_duplicated_binaries_with_literal (kissat *solver, static size_t remove_duplicated_binaries_with_literal (kissat *solver,
unsigned lit) { unsigned lit) {
watches *watches = &WATCHES (lit); watches *watches = &WATCHES (lit);
@ -21,7 +23,7 @@ static size_t remove_duplicated_binaries_with_literal (kissat *solver,
while (p != end) { while (p != end) {
const watch watch = *q++ = *p++; const watch watch = *q++ = *p++;
assert (watch.type.binary); KISSAT_assert (watch.type.binary);
const unsigned other = watch.binary.lit; const unsigned other = watch.binary.lit;
struct flags *f = flags + IDX (other); struct flags *f = flags + IDX (other);
if (!f->active) if (!f->active)
@ -67,10 +69,10 @@ static size_t remove_duplicated_binaries_with_literal (kissat *solver,
static void remove_all_duplicated_binary_clauses (kissat *solver) { static void remove_all_duplicated_binary_clauses (kissat *solver) {
LOG ("removing all duplicated irredundant binary clauses"); LOG ("removing all duplicated irredundant binary clauses");
#if !defined(QUIET) || !defined(NDEBUG) #if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)
size_t removed = 0; size_t removed = 0;
#endif #endif
assert (EMPTY_STACK (solver->delayed)); KISSAT_assert (EMPTY_STACK (solver->delayed));
const flags *const all_flags = solver->flags; const flags *const all_flags = solver->flags;
@ -82,16 +84,16 @@ static void remove_all_duplicated_binary_clauses (kissat *solver) {
continue; continue;
const unsigned int lit = LIT (idx); const unsigned int lit = LIT (idx);
const unsigned int not_lit = NOT (lit); const unsigned int not_lit = NOT (lit);
#if !defined(QUIET) || !defined(NDEBUG) #if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)
removed += removed +=
#endif #endif
remove_duplicated_binaries_with_literal (solver, lit); remove_duplicated_binaries_with_literal (solver, lit);
#if !defined(QUIET) || !defined(NDEBUG) #if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)
removed += removed +=
#endif #endif
remove_duplicated_binaries_with_literal (solver, not_lit); remove_duplicated_binaries_with_literal (solver, not_lit);
} }
assert (!(removed & 1)); KISSAT_assert (!(removed & 1));
size_t units = SIZE_STACK (solver->delayed); size_t units = SIZE_STACK (solver->delayed);
if (units) { if (units) {
@ -141,7 +143,7 @@ static void find_forward_subsumption_candidates (kissat *solver,
continue; continue;
if (c->size > clslim) if (c->size > clslim)
continue; continue;
assert (c->size > 2); KISSAT_assert (c->size > 2);
unsigned subsume = 0; unsigned subsume = 0;
for (all_literals_in_clause (lit, c)) { for (all_literals_in_clause (lit, c)) {
const unsigned idx = IDX (lit); const unsigned idx = IDX (lit);
@ -151,7 +153,7 @@ static void find_forward_subsumption_candidates (kissat *solver,
if (values[lit] > 0) { if (values[lit] > 0) {
LOGCLS (c, "satisfied by %s", LOGLIT (lit)); LOGCLS (c, "satisfied by %s", LOGLIT (lit));
kissat_mark_clause_as_garbage (solver, c); kissat_mark_clause_as_garbage (solver, c);
assert (c->garbage); KISSAT_assert (c->garbage);
break; break;
} }
} }
@ -166,7 +168,7 @@ static void find_forward_subsumption_candidates (kissat *solver,
static inline unsigned static inline unsigned
get_size_of_reference (kissat *solver, ward *const arena, reference ref) { get_size_of_reference (kissat *solver, ward *const arena, reference ref) {
assert (ref < SIZE_STACK (solver->arena)); KISSAT_assert (ref < SIZE_STACK (solver->arena));
const clause *const c = (clause *) (arena + ref); const clause *const c = (clause *) (arena + ref);
(void) solver; (void) solver;
return c->size; return c->size;
@ -223,14 +225,14 @@ static inline bool forward_literal (kissat *solver, unsigned lit,
const unsigned not_other = NOT (other); const unsigned not_other = NOT (other);
if (marks[not_other]) { if (marks[not_other]) {
LOGBINARY (lit, other, "forward %s strengthener", LOGLIT (other)); LOGBINARY (lit, other, "forward %s strengthener", LOGLIT (other));
assert (!subsume); KISSAT_assert (!subsume);
*remove = not_other; *remove = not_other;
break; break;
} }
} }
} else { } else {
const reference ref = watch.large.ref; const reference ref = watch.large.ref;
assert (ref < SIZE_STACK (solver->arena)); KISSAT_assert (ref < SIZE_STACK (solver->arena));
clause *d = (clause *) (arena + ref); clause *d = (clause *) (arena + ref);
steps++; steps++;
@ -253,34 +255,34 @@ static inline bool forward_literal (kissat *solver, unsigned lit,
if (value > 0) { if (value > 0) {
LOGCLS (d, "satisfied by %s", LOGLIT (other)); LOGCLS (d, "satisfied by %s", LOGLIT (other));
kissat_mark_clause_as_garbage (solver, d); kissat_mark_clause_as_garbage (solver, d);
assert (d->garbage); KISSAT_assert (d->garbage);
candidate = INVALID_LIT; candidate = INVALID_LIT;
subsume = false; subsume = false;
break; break;
} }
if (!subsume) { if (!subsume) {
assert (candidate != INVALID_LIT); KISSAT_assert (candidate != INVALID_LIT);
candidate = INVALID_LIT; candidate = INVALID_LIT;
break; break;
} }
subsume = false; subsume = false;
const unsigned not_other = NOT (other); const unsigned not_other = NOT (other);
if (!marks[not_other]) { if (!marks[not_other]) {
assert (candidate == INVALID_LIT); KISSAT_assert (candidate == INVALID_LIT);
break; break;
} }
candidate = not_other; candidate = not_other;
} }
if (d->garbage) { if (d->garbage) {
assert (!subsume); KISSAT_assert (!subsume);
q--; q--;
break; break;
} }
if (subsume) { if (subsume) {
LOGCLS (d, "forward subsuming"); LOGCLS (d, "forward subsuming");
assert (subsume); KISSAT_assert (subsume);
break; break;
} }
@ -316,7 +318,7 @@ static inline bool forward_marked_clause (kissat *solver, clause *c,
if (!flags[idx].active) if (!flags[idx].active)
continue; continue;
assert (!VALUE (lit)); KISSAT_assert (!VALUE (lit));
if (forward_literal (solver, lit, true, remove, limit)) if (forward_literal (solver, lit, true, remove, limit))
return true; return true;
@ -330,7 +332,7 @@ static inline bool forward_marked_clause (kissat *solver, clause *c,
static bool forward_subsumed_clause (kissat *solver, clause *c, static bool forward_subsumed_clause (kissat *solver, clause *c,
bool *strengthened, bool *strengthened,
unsigneds *new_binaries) { unsigneds *new_binaries) {
assert (!c->garbage); KISSAT_assert (!c->garbage);
LOGCLS2 (c, "trying to forward subsume"); LOGCLS2 (c, "trying to forward subsume");
value *marks = solver->marks; value *marks = solver->marks;
@ -344,7 +346,7 @@ static bool forward_subsumed_clause (kissat *solver, clause *c,
if (value > 0) { if (value > 0) {
LOGCLS (c, "satisfied by %s", LOGLIT (lit)); LOGCLS (c, "satisfied by %s", LOGLIT (lit));
kissat_mark_clause_as_garbage (solver, c); kissat_mark_clause_as_garbage (solver, c);
assert (c->garbage); KISSAT_assert (c->garbage);
break; break;
} }
marks[lit] = 1; marks[lit] = 1;
@ -370,7 +372,7 @@ static bool forward_subsumed_clause (kissat *solver, clause *c,
} }
if (non_false == 1) { if (non_false == 1) {
assert (VALID_INTERNAL_LITERAL (unit)); KISSAT_assert (VALID_INTERNAL_LITERAL (unit));
LOG ("new remaining non-false literal unit clause %s", LOGLIT (unit)); LOG ("new remaining non-false literal unit clause %s", LOGLIT (unit));
kissat_learned_unit (solver, unit); kissat_learned_unit (solver, unit);
kissat_mark_clause_as_garbage (solver, c); kissat_mark_clause_as_garbage (solver, c);
@ -396,7 +398,7 @@ static bool forward_subsumed_clause (kissat *solver, clause *c,
LOGCLS (c, "forward strengthening by removing %s in", LOGLIT (remove)); LOGCLS (c, "forward strengthening by removing %s in", LOGLIT (remove));
if (non_false == 2) { if (non_false == 2) {
unit ^= remove; unit ^= remove;
assert (VALID_INTERNAL_LITERAL (unit)); KISSAT_assert (VALID_INTERNAL_LITERAL (unit));
LOG ("forward strengthened unit clause %s", LOGLIT (unit)); LOG ("forward strengthened unit clause %s", LOGLIT (unit));
kissat_learned_unit (solver, unit); kissat_learned_unit (solver, unit);
kissat_mark_clause_as_garbage (solver, c); kissat_mark_clause_as_garbage (solver, c);
@ -416,12 +418,12 @@ static bool forward_subsumed_clause (kissat *solver, clause *c,
const value value = values[lit]; const value value = values[lit];
if (value < 0) if (value < 0)
continue; continue;
assert (!value); KISSAT_assert (!value);
lits[new_size++] = lit; lits[new_size++] = lit;
kissat_mark_added_literal (solver, lit); kissat_mark_added_literal (solver, lit);
} }
assert (new_size == non_false - 1); KISSAT_assert (new_size == non_false - 1);
assert (new_size > 2); KISSAT_assert (new_size > 2);
if (!c->shrunken) { if (!c->shrunken) {
c->shrunken = true; c->shrunken = true;
lits[c->size - 1] = INVALID_LIT; lits[c->size - 1] = INVALID_LIT;
@ -431,9 +433,9 @@ static bool forward_subsumed_clause (kissat *solver, clause *c,
c->subsume = true; c->subsume = true;
LOGCLS (c, "forward strengthened"); LOGCLS (c, "forward strengthened");
} else { } else {
assert (non_false == 3); KISSAT_assert (non_false == 3);
LOGCLS (c, "garbage"); LOGCLS (c, "garbage");
assert (!c->garbage); KISSAT_assert (!c->garbage);
const size_t bytes = kissat_actual_bytes_of_clause (c); const size_t bytes = kissat_actual_bytes_of_clause (c);
ADD (arena_garbage, bytes); ADD (arena_garbage, bytes);
c->garbage = true; c->garbage = true;
@ -444,25 +446,25 @@ static bool forward_subsumed_clause (kissat *solver, clause *c,
const value value = values[lit]; const value value = values[lit];
if (value < 0) if (value < 0)
continue; continue;
assert (!value); KISSAT_assert (!value);
if (first == INVALID_LIT) if (first == INVALID_LIT)
first = lit; first = lit;
else { else {
assert (second == INVALID_LIT); KISSAT_assert (second == INVALID_LIT);
second = lit; second = lit;
} }
kissat_mark_added_literal (solver, lit); kissat_mark_added_literal (solver, lit);
} }
assert (first != INVALID_LIT); KISSAT_assert (first != INVALID_LIT);
assert (second != INVALID_LIT); KISSAT_assert (second != INVALID_LIT);
LOGBINARY (first, second, "forward strengthened"); LOGBINARY (first, second, "forward strengthened");
kissat_watch_other (solver, first, second); kissat_watch_other (solver, first, second);
kissat_watch_other (solver, second, first); kissat_watch_other (solver, second, first);
assert (new_binaries); KISSAT_assert (new_binaries);
assert (solver->statistics.clauses_irredundant); KISSAT_assert (solver->statistics_.clauses_irredundant);
solver->statistics.clauses_irredundant--; solver->statistics_.clauses_irredundant--;
assert (solver->statistics.clauses_binary < UINT64_MAX); KISSAT_assert (solver->statistics_.clauses_binary < UINT64_MAX);
solver->statistics.clauses_binary++; solver->statistics_.clauses_binary++;
PUSH_STACK (*new_binaries, first); PUSH_STACK (*new_binaries, first);
PUSH_STACK (*new_binaries, second); PUSH_STACK (*new_binaries, second);
} }
@ -473,7 +475,7 @@ static bool forward_subsumed_clause (kissat *solver, clause *c,
} }
static void connect_subsuming (kissat *solver, unsigned occlim, clause *c) { static void connect_subsuming (kissat *solver, unsigned occlim, clause *c) {
assert (!c->garbage); KISSAT_assert (!c->garbage);
unsigned min_lit = INVALID_LIT; unsigned min_lit = INVALID_LIT;
size_t min_occs = MAX_SIZE_T; size_t min_occs = MAX_SIZE_T;
@ -513,19 +515,19 @@ static bool forward_subsume_all_clauses (kissat *solver) {
INIT_STACK (candidates); INIT_STACK (candidates);
find_forward_subsumption_candidates (solver, &candidates); find_forward_subsumption_candidates (solver, &candidates);
#ifndef QUIET #ifndef KISSAT_QUIET
size_t scheduled = SIZE_STACK (candidates); size_t scheduled = SIZE_STACK (candidates);
kissat_phase ( kissat_phase (
solver, "forward", GET (forward_subsumptions), solver, "forward", GET (forward_subsumptions),
"scheduled %zu irredundant clauses %.0f%%", scheduled, "scheduled %zu irredundant clauses %.0f%%", scheduled,
kissat_percent (scheduled, solver->statistics.clauses_irredundant)); kissat_percent (scheduled, solver->statistics_.clauses_irredundant));
#endif #endif
sort_forward_subsumption_candidates (solver, &candidates); sort_forward_subsumption_candidates (solver, &candidates);
const reference *const end_of_candidates = END_STACK (candidates); const reference *const end_of_candidates = END_STACK (candidates);
reference *p = BEGIN_STACK (candidates); reference *p = BEGIN_STACK (candidates);
#ifndef QUIET #ifndef KISSAT_QUIET
size_t subsumed = 0; size_t subsumed = 0;
size_t strengthened = 0; size_t strengthened = 0;
size_t checked = 0; size_t checked = 0;
@ -541,25 +543,25 @@ static bool forward_subsume_all_clauses (kissat *solver) {
ward *arena = BEGIN_STACK (solver->arena); ward *arena = BEGIN_STACK (solver->arena);
while (p != end_of_candidates) { while (p != end_of_candidates) {
if (solver->statistics.forward_steps > steps_limit) if (solver->statistics_.forward_steps > steps_limit)
break; break;
if (TERMINATED (forward_terminated_1)) if (TERMINATED (forward_terminated_1))
break; break;
reference ref = *p++; reference ref = *p++;
clause *c = (clause *) (arena + ref); clause *c = (clause *) (arena + ref);
assert (kissat_clause_in_arena (solver, c)); KISSAT_assert (kissat_clause_in_arena (solver, c));
assert (!c->garbage); KISSAT_assert (!c->garbage);
#ifndef QUIET #ifndef KISSAT_QUIET
checked++; checked++;
#endif #endif
bool not_subsumed_but_strengthened = false; bool not_subsumed_but_strengthened = false;
if (forward_subsumed_clause ( if (forward_subsumed_clause (
solver, c, &not_subsumed_but_strengthened, &new_binaries)) { solver, c, &not_subsumed_but_strengthened, &new_binaries)) {
#ifndef QUIET #ifndef KISSAT_QUIET
subsumed++; subsumed++;
#endif #endif
} else if (not_subsumed_but_strengthened) { } else if (not_subsumed_but_strengthened) {
#ifndef QUIET #ifndef KISSAT_QUIET
strengthened++; strengthened++;
#endif #endif
} }
@ -569,7 +571,7 @@ static bool forward_subsume_all_clauses (kissat *solver) {
connect_subsuming (solver, occlim, c); connect_subsuming (solver, occlim, c);
} }
} }
#ifndef QUIET #ifndef KISSAT_QUIET
if (subsumed) if (subsumed)
kissat_phase (solver, "forward", GET (forward_subsumptions), kissat_phase (solver, "forward", GET (forward_subsumptions),
"subsumed %zu clauses %.2f%% of %zu checked %.0f%%", "subsumed %zu clauses %.2f%% of %zu checked %.0f%%",
@ -593,19 +595,19 @@ static bool forward_subsume_all_clauses (kissat *solver) {
ward *arena = BEGIN_STACK (solver->arena); ward *arena = BEGIN_STACK (solver->arena);
unsigned reactivated = 0; unsigned reactivated = 0;
#ifndef QUIET #ifndef KISSAT_QUIET
size_t remain = 0; size_t remain = 0;
#endif #endif
for (reference *q = BEGIN_STACK (candidates); q != end_of_candidates; for (reference *q = BEGIN_STACK (candidates); q != end_of_candidates;
q++) { q++) {
const reference ref = *q; const reference ref = *q;
clause *c = (clause *) (arena + ref); clause *c = (clause *) (arena + ref);
assert (kissat_clause_in_arena (solver, c)); KISSAT_assert (kissat_clause_in_arena (solver, c));
if (c->garbage) if (c->garbage)
continue; continue;
if (q < p && !c->subsume) if (q < p && !c->subsume)
continue; continue;
#ifndef QUIET #ifndef KISSAT_QUIET
remain++; remain++;
#endif #endif
for (all_literals_in_clause (lit, c)) { for (all_literals_in_clause (lit, c)) {
@ -618,7 +620,7 @@ static bool forward_subsume_all_clauses (kissat *solver) {
"in remaining or strengthened", "in remaining or strengthened",
LOGVAR (idx)); LOGVAR (idx));
f->subsume = true; f->subsume = true;
assert (reactivated < UINT_MAX); KISSAT_assert (reactivated < UINT_MAX);
reactivated++; reactivated++;
} }
} }
@ -638,7 +640,7 @@ static bool forward_subsume_all_clauses (kissat *solver) {
"in strengthened binary clause", "in strengthened binary clause",
LOGVAR (idx)); LOGVAR (idx));
f->subsume = true; f->subsume = true;
assert (reactivated < UINT_MAX); KISSAT_assert (reactivated < UINT_MAX);
reactivated++; reactivated++;
} }
} }
@ -649,7 +651,7 @@ static bool forward_subsume_all_clauses (kissat *solver) {
"in next forward subsumption", "in next forward subsumption",
reactivated, reactivated,
kissat_percent (reactivated, solver->active)); kissat_percent (reactivated, solver->active));
#ifndef QUIET #ifndef KISSAT_QUIET
if (remain) if (remain)
kissat_phase (solver, "forward", GET (forward_subsumptions), kissat_phase (solver, "forward", GET (forward_subsumptions),
"%zu unchecked clauses remain %.0f%%", remain, "%zu unchecked clauses remain %.0f%%", remain,
@ -668,7 +670,7 @@ static bool forward_subsume_all_clauses (kissat *solver) {
completed = false; completed = false;
else else
completed = true; completed = true;
#ifndef QUIET #ifndef KISSAT_QUIET
kissat_very_verbose (solver, "forward subsumption considered %scomplete", kissat_very_verbose (solver, "forward subsumption considered %scomplete",
completed ? "" : "in"); completed ? "" : "in");
#endif #endif
@ -678,9 +680,9 @@ static bool forward_subsume_all_clauses (kissat *solver) {
bool kissat_forward_subsume_during_elimination (kissat *solver) { bool kissat_forward_subsume_during_elimination (kissat *solver) {
START (subsume); START (subsume);
START (forward); START (forward);
assert (GET_OPTION (forward)); KISSAT_assert (GET_OPTION (forward));
INC (forward_subsumptions); INC (forward_subsumptions);
assert (!solver->watching); KISSAT_assert (!solver->watching);
remove_all_duplicated_binary_clauses (solver); remove_all_duplicated_binary_clauses (solver);
bool complete = true; bool complete = true;
if (!solver->inconsistent) if (!solver->inconsistent)
@ -689,3 +691,5 @@ bool kissat_forward_subsume_during_elimination (kissat *solver) {
STOP (subsume); STOP (subsume);
return complete; return complete;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,8 +3,13 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
bool kissat_forward_subsume_during_elimination (struct kissat *); bool kissat_forward_subsume_during_elimination (struct kissat *);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -6,6 +6,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
typedef struct frame frame; typedef struct frame frame;
typedef struct slice slice; typedef struct slice slice;
@ -14,7 +17,7 @@ struct frame {
unsigned decision; unsigned decision;
unsigned trail; unsigned trail;
unsigned used; unsigned used;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
unsigned saved; unsigned saved;
#endif #endif
}; };
@ -29,4 +32,6 @@ struct kissat;
#define FRAME(LEVEL) (PEEK_STACK (solver->frames, (LEVEL))) #define FRAME(LEVEL) (PEEK_STACK (solver->frames, (LEVEL)))
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -6,6 +6,8 @@
#include "ifthenelse.h" #include "ifthenelse.h"
#include "inline.h" #include "inline.h"
ABC_NAMESPACE_IMPL_START
size_t kissat_mark_binaries (kissat *solver, unsigned lit) { size_t kissat_mark_binaries (kissat *solver, unsigned lit) {
value *marks = solver->marks; value *marks = solver->marks;
size_t res = 0; size_t res = 0;
@ -14,7 +16,7 @@ size_t kissat_mark_binaries (kissat *solver, unsigned lit) {
if (!watch.type.binary) if (!watch.type.binary)
continue; continue;
const unsigned other = watch.binary.lit; const unsigned other = watch.binary.lit;
assert (!solver->values[other]); KISSAT_assert (!solver->values[other]);
if (marks[other]) if (marks[other])
continue; continue;
marks[other] = 1; marks[other] = 1;
@ -60,14 +62,14 @@ bool kissat_find_gates (kissat *solver, unsigned lit) {
static void get_antecedents (kissat *solver, unsigned lit, static void get_antecedents (kissat *solver, unsigned lit,
unsigned negative) { unsigned negative) {
assert (!solver->watching); KISSAT_assert (!solver->watching);
assert (!negative || negative == 1); KISSAT_assert (!negative || negative == 1);
statches *gates = solver->gates + negative; statches *gates = solver->gates + negative;
watches *watches = &WATCHES (lit); watches *watches = &WATCHES (lit);
statches *antecedents = solver->antecedents + negative; statches *antecedents = solver->antecedents + negative;
assert (EMPTY_STACK (*antecedents)); KISSAT_assert (EMPTY_STACK (*antecedents));
const watch *const begin_gates = BEGIN_STACK (*gates); const watch *const begin_gates = BEGIN_STACK (*gates);
const watch *const end_gates = END_STACK (*gates); const watch *const end_gates = END_STACK (*gates);
@ -85,7 +87,7 @@ static void get_antecedents (kissat *solver, unsigned lit,
PUSH_STACK (*antecedents, watch); PUSH_STACK (*antecedents, watch);
} }
assert (g == end_gates); KISSAT_assert (g == end_gates);
#ifdef LOGGING #ifdef LOGGING
size_t size_gates = SIZE_STACK (*gates); size_t size_gates = SIZE_STACK (*gates);
size_t size_antecedents = SIZE_STACK (*antecedents); size_t size_antecedents = SIZE_STACK (*antecedents);
@ -102,3 +104,5 @@ void kissat_get_antecedents (kissat *solver, unsigned lit) {
get_antecedents (solver, lit, 0); get_antecedents (solver, lit, 0);
get_antecedents (solver, NOT (lit), 1); get_antecedents (solver, NOT (lit), 1);
} }
ABC_NAMESPACE_IMPL_END

View File

@ -4,6 +4,9 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
struct clause; struct clause;
@ -19,4 +22,6 @@ void kissat_unmark_binaries (struct kissat *, unsigned lit);
#define GATE_ELIMINATED(NAME) (&solver->statistics.NAME##_eliminated) #define GATE_ELIMINATED(NAME) (&solver->statistics.NAME##_eliminated)
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif #endif

14
src/sat/kissat/global.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef ABC_SAT_KISSAT_GLOBAL_H_
#define ABC_SAT_KISSAT_GLOBAL_H_
#define KISSAT_COMPACT
#define KISSAT_NDEBUG
#define KISSAT_NOPTIONS
#define KISSAT_NPROOFS
#define KISSAT_QUIET
#define KISSAT_assert(ignore) ((void)0)
#include "misc/util/abc_global.h"
#endif

View File

@ -3,6 +3,9 @@
#include <signal.h> #include <signal.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
void kissat_init_signal_handler (void (*handler) (int)); void kissat_init_signal_handler (void (*handler) (int));
void kissat_reset_signal_handler (void); void kissat_reset_signal_handler (void);
@ -40,4 +43,6 @@ kissat_signal_name (int sig)
// clang-format on // clang-format on
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -5,6 +5,8 @@
#include <string.h> #include <string.h>
ABC_NAMESPACE_IMPL_START
void kissat_release_heap (kissat *solver, heap *heap) { void kissat_release_heap (kissat *solver, heap *heap) {
RELEASE_STACK (heap->stack); RELEASE_STACK (heap->stack);
DEALLOC (heap->pos, heap->size); DEALLOC (heap->pos, heap->size);
@ -12,7 +14,7 @@ void kissat_release_heap (kissat *solver, heap *heap) {
memset (heap, 0, sizeof *heap); memset (heap, 0, sizeof *heap);
} }
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
void kissat_check_heap (heap *heap) { void kissat_check_heap (heap *heap) {
const unsigned *const stack = BEGIN_STACK (heap->stack); const unsigned *const stack = BEGIN_STACK (heap->stack);
@ -22,18 +24,18 @@ void kissat_check_heap (heap *heap) {
for (unsigned i = 0; i < end; i++) { for (unsigned i = 0; i < end; i++) {
const unsigned idx = stack[i]; const unsigned idx = stack[i];
const unsigned idx_pos = pos[idx]; const unsigned idx_pos = pos[idx];
assert (idx_pos == i); KISSAT_assert (idx_pos == i);
unsigned child_pos = HEAP_CHILD (idx_pos); unsigned child_pos = HEAP_CHILD (idx_pos);
unsigned parent_pos = HEAP_PARENT (child_pos); unsigned parent_pos = HEAP_PARENT (child_pos);
assert (parent_pos == idx_pos); KISSAT_assert (parent_pos == idx_pos);
if (child_pos < end) { if (child_pos < end) {
unsigned child = stack[child_pos]; unsigned child = stack[child_pos];
assert (score[idx] >= score[child]); KISSAT_assert (score[idx] >= score[child]);
if (++child_pos < end) { if (++child_pos < end) {
parent_pos = HEAP_PARENT (child_pos); parent_pos = HEAP_PARENT (child_pos);
assert (parent_pos == idx_pos); KISSAT_assert (parent_pos == idx_pos);
child = stack[child_pos]; child = stack[child_pos];
assert (score[idx] >= score[child]); KISSAT_assert (score[idx] >= score[child]);
} }
} }
} }
@ -48,15 +50,15 @@ void kissat_resize_heap (kissat *solver, heap *heap, unsigned new_size) {
LOG ("resizing %s heap from %u to %u", LOG ("resizing %s heap from %u to %u",
(heap->tainted ? "tainted" : "untainted"), old_size, new_size); (heap->tainted ? "tainted" : "untainted"), old_size, new_size);
heap->pos = kissat_nrealloc (solver, heap->pos, old_size, new_size, heap->pos = (unsigned*)kissat_nrealloc (solver, heap->pos, old_size, new_size,
sizeof (unsigned)); sizeof (unsigned));
if (heap->tainted) { if (heap->tainted) {
heap->score = kissat_nrealloc (solver, heap->score, old_size, new_size, heap->score = (double*)kissat_nrealloc (solver, heap->score, old_size, new_size,
sizeof (double)); sizeof (double));
} else { } else {
if (old_size) if (old_size)
DEALLOC (heap->score, old_size); DEALLOC (heap->score, old_size);
heap->score = kissat_calloc (solver, new_size, sizeof (double)); heap->score = (double*)kissat_calloc (solver, new_size, sizeof (double));
} }
heap->size = new_size; heap->size = new_size;
#ifdef CHECK_HEAP #ifdef CHECK_HEAP
@ -69,7 +71,7 @@ void kissat_rescale_heap (kissat *solver, heap *heap, double factor) {
double *score = heap->score; double *score = heap->score;
for (unsigned i = 0; i < heap->vars; i++) for (unsigned i = 0; i < heap->vars; i++)
score[i] *= factor; score[i] *= factor;
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
kissat_check_heap (heap); kissat_check_heap (heap);
#endif #endif
#ifndef LOGGING #ifndef LOGGING
@ -79,8 +81,8 @@ void kissat_rescale_heap (kissat *solver, heap *heap, double factor) {
void kissat_enlarge_heap (kissat *solver, heap *heap, unsigned new_vars) { void kissat_enlarge_heap (kissat *solver, heap *heap, unsigned new_vars) {
const unsigned old_vars = heap->vars; const unsigned old_vars = heap->vars;
assert (old_vars < new_vars); KISSAT_assert (old_vars < new_vars);
assert (new_vars <= heap->size); KISSAT_assert (new_vars <= heap->size);
const size_t delta = new_vars - heap->vars; const size_t delta = new_vars - heap->vars;
memset (heap->pos + old_vars, 0xff, delta * sizeof (unsigned)); memset (heap->pos + old_vars, 0xff, delta * sizeof (unsigned));
heap->vars = new_vars; heap->vars = new_vars;
@ -92,7 +94,7 @@ void kissat_enlarge_heap (kissat *solver, heap *heap, unsigned new_vars) {
#endif #endif
} }
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
static void dump_heap (heap *heap) { static void dump_heap (heap *heap) {
for (unsigned i = 0; i < SIZE_STACK (heap->stack); i++) for (unsigned i = 0; i < SIZE_STACK (heap->stack); i++)
@ -106,3 +108,5 @@ static void dump_heap (heap *heap) {
void kissat_dump_heap (heap *heap) { dump_heap (heap); } void kissat_dump_heap (heap *heap) { dump_heap (heap); }
#endif #endif
ABC_NAMESPACE_IMPL_END

View File

@ -8,6 +8,9 @@
#include <limits.h> #include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
#define DISCONTAIN UINT_MAX #define DISCONTAIN UINT_MAX
#define DISCONTAINED(IDX) ((int) (IDX) < 0) #define DISCONTAINED(IDX) ((int) (IDX) < 0)
@ -50,7 +53,7 @@ static inline size_t kissat_size_heap (heap *heap) {
} }
static inline unsigned kissat_max_heap (heap *heap) { static inline unsigned kissat_max_heap (heap *heap) {
assert (!kissat_empty_heap (heap)); KISSAT_assert (!kissat_empty_heap (heap));
return PEEK_STACK (heap->stack, 0); return PEEK_STACK (heap->stack, 0);
} }
@ -61,7 +64,7 @@ void kissat_enlarge_heap (struct kissat *, heap *, unsigned new_vars);
static inline double kissat_max_score_on_heap (heap *heap) { static inline double kissat_max_score_on_heap (heap *heap) {
if (!heap->tainted) if (!heap->tainted)
return 0; return 0;
assert (heap->vars); KISSAT_assert (heap->vars);
const double *const score = heap->score; const double *const score = heap->score;
const double *const end = score + heap->vars; const double *const end = score + heap->vars;
double res = score[0]; double res = score[0];
@ -70,11 +73,11 @@ static inline double kissat_max_score_on_heap (heap *heap) {
return res; return res;
} }
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
void kissat_dump_heap (heap *); void kissat_dump_heap (heap *);
#endif #endif
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
void kissat_check_heap (heap *); void kissat_check_heap (heap *);
#else #else
#define kissat_check_heap(...) \ #define kissat_check_heap(...) \
@ -82,4 +85,6 @@ void kissat_check_heap (heap *);
} while (0) } while (0)
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -3,6 +3,8 @@
#include "gates.h" #include "gates.h"
#include "inline.h" #include "inline.h"
ABC_NAMESPACE_IMPL_START
static bool get_ternary_clause (kissat *solver, reference ref, unsigned *p, static bool get_ternary_clause (kissat *solver, reference ref, unsigned *p,
unsigned *q, unsigned *r) { unsigned *q, unsigned *r) {
clause *clause = kissat_dereference_clause (solver, ref); clause *clause = kissat_dereference_clause (solver, ref);
@ -30,9 +32,9 @@ static bool get_ternary_clause (kissat *solver, reference ref, unsigned *p,
} }
if (found != 3) if (found != 3)
return false; return false;
assert (a != INVALID_LIT); KISSAT_assert (a != INVALID_LIT);
assert (b != INVALID_LIT); KISSAT_assert (b != INVALID_LIT);
assert (c != INVALID_LIT); KISSAT_assert (c != INVALID_LIT);
*p = a; *p = a;
*q = b; *q = b;
*r = c; *r = c;
@ -121,7 +123,7 @@ bool kissat_find_if_then_else_gate (kissat *solver, unsigned lit,
SWAP (unsigned, a1, b1); SWAP (unsigned, a1, b1);
if (c1 == lit) if (c1 == lit)
SWAP (unsigned, a1, c1); SWAP (unsigned, a1, c1);
assert (a1 == lit); KISSAT_assert (a1 == lit);
for (const watch *p2 = p1 + 1; steps < limit && p2 != end; p2++) { for (const watch *p2 = p1 + 1; steps < limit && p2 != end; p2++) {
watch w2 = *p2; watch w2 = *p2;
if (w2.type.binary) if (w2.type.binary)
@ -133,7 +135,7 @@ bool kissat_find_if_then_else_gate (kissat *solver, unsigned lit,
SWAP (unsigned, a2, b2); SWAP (unsigned, a2, b2);
if (c2 == lit) if (c2 == lit)
SWAP (unsigned, a2, c2); SWAP (unsigned, a2, c2);
assert (a2 == lit); KISSAT_assert (a2 == lit);
if (STRIP (b1) == STRIP (c2)) if (STRIP (b1) == STRIP (c2))
SWAP (unsigned, b2, c2); SWAP (unsigned, b2, c2);
if (STRIP (c1) == STRIP (c2)) if (STRIP (c1) == STRIP (c2))
@ -172,3 +174,5 @@ bool kissat_find_if_then_else_gate (kissat *solver, unsigned lit,
} }
return false; return false;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -3,9 +3,14 @@
#include <stdbool.h> #include <stdbool.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
bool kissat_find_if_then_else_gate (struct kissat *, unsigned lit, bool kissat_find_if_then_else_gate (struct kissat *, unsigned lit,
unsigned negative); unsigned negative);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -2,6 +2,8 @@
#include "logging.h" #include "logging.h"
#include "resize.h" #include "resize.h"
ABC_NAMESPACE_IMPL_START
static void adjust_imports_for_external_literal (kissat *solver, static void adjust_imports_for_external_literal (kissat *solver,
unsigned eidx) { unsigned eidx) {
while (eidx >= SIZE_STACK (solver->import)) { while (eidx >= SIZE_STACK (solver->import)) {
@ -27,13 +29,13 @@ static void adjust_exports_for_external_literal (kissat *solver,
INC (variables_extension); INC (variables_extension);
else else
INC (variables_original); INC (variables_original);
assert (!import->eliminated); KISSAT_assert (!import->eliminated);
import->lit = ilit; import->lit = ilit;
LOG ("importing %s external variable %u as internal literal %u", LOG ("importing %s external variable %u as internal literal %u",
extension ? "extension" : "original", eidx, ilit); extension ? "extension" : "original", eidx, ilit);
while (iidx >= SIZE_STACK (solver->export)) while (iidx >= SIZE_STACK (solver->export_))
PUSH_STACK (solver->export, 0); PUSH_STACK (solver->export_, 0);
POKE_STACK (solver->export, iidx, (int) eidx); POKE_STACK (solver->export_, iidx, (int) eidx);
LOG ("exporting internal variable %u as external literal %u", iidx, eidx); LOG ("exporting internal variable %u as external literal %u", iidx, eidx);
} }
@ -47,20 +49,20 @@ static inline unsigned import_literal (kissat *solver, int elit,
unsigned ilit; unsigned ilit;
if (!import->imported) if (!import->imported)
adjust_exports_for_external_literal (solver, eidx, extension); adjust_exports_for_external_literal (solver, eidx, extension);
assert (import->imported); KISSAT_assert (import->imported);
ilit = import->lit; ilit = import->lit;
if (elit < 0) if (elit < 0)
ilit = NOT (ilit); ilit = NOT (ilit);
assert (VALID_INTERNAL_LITERAL (ilit)); KISSAT_assert (VALID_INTERNAL_LITERAL (ilit));
return ilit; return ilit;
} }
unsigned kissat_import_literal (kissat *solver, int elit) { unsigned kissat_import_literal (kissat *solver, int elit) {
assert (VALID_EXTERNAL_LITERAL (elit)); KISSAT_assert (VALID_EXTERNAL_LITERAL (elit));
if (GET_OPTION (tumble)) if (GET_OPTION (tumble))
return import_literal (solver, elit, false); return import_literal (solver, elit, false);
const unsigned eidx = ABS (elit); const unsigned eidx = ABS (elit);
assert (SIZE_STACK (solver->import) <= UINT_MAX); KISSAT_assert (SIZE_STACK (solver->import) <= UINT_MAX);
unsigned other = SIZE_STACK (solver->import); unsigned other = SIZE_STACK (solver->import);
if (eidx < other) if (eidx < other)
return import_literal (solver, elit, false); return import_literal (solver, elit, false);
@ -69,7 +71,7 @@ unsigned kissat_import_literal (kissat *solver, int elit) {
unsigned ilit = 0; unsigned ilit = 0;
do { do {
assert (VALID_EXTERNAL_LITERAL ((int) other)); KISSAT_assert (VALID_EXTERNAL_LITERAL ((int) other));
ilit = import_literal (solver, other, false); ilit = import_literal (solver, other, false);
} while (other++ < eidx); } while (other++ < eidx);
@ -81,20 +83,22 @@ unsigned kissat_import_literal (kissat *solver, int elit) {
unsigned kissat_fresh_literal (kissat *solver) { unsigned kissat_fresh_literal (kissat *solver) {
size_t imported = SIZE_STACK (solver->import); size_t imported = SIZE_STACK (solver->import);
assert (imported <= EXTERNAL_MAX_VAR); KISSAT_assert (imported <= EXTERNAL_MAX_VAR);
if (imported == EXTERNAL_MAX_VAR) { if (imported == EXTERNAL_MAX_VAR) {
LOG ("can not get another external variable"); LOG ("can not get another external variable");
return INVALID_LIT; return INVALID_LIT;
} }
assert (imported <= (unsigned) INT_MAX); KISSAT_assert (imported <= (unsigned) INT_MAX);
int eidx = (int) imported; int eidx = (int) imported;
unsigned res = import_literal (solver, eidx, true); unsigned res = import_literal (solver, eidx, true);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
struct import *import = &PEEK_STACK (solver->import, imported); struct import *import = &PEEK_STACK (solver->import, imported);
assert (import->imported); KISSAT_assert (import->imported);
assert (import->extension); KISSAT_assert (import->extension);
#endif #endif
INC (fresh); INC (fresh);
kissat_activate_literal (solver, res); kissat_activate_literal (solver, res);
return res; return res;
} }
ABC_NAMESPACE_IMPL_END

View File

@ -1,9 +1,14 @@
#ifndef _import_h_INLCUDED #ifndef _import_h_INLCUDED
#define _import_h_INLCUDED #define _import_h_INLCUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
struct kissat; struct kissat;
unsigned kissat_import_literal (struct kissat *solver, int lit); unsigned kissat_import_literal (struct kissat *solver, int lit);
unsigned kissat_fresh_literal (struct kissat *solver); unsigned kissat_fresh_literal (struct kissat *solver);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -4,6 +4,9 @@
#include "inlinevector.h" #include "inlinevector.h"
#include "logging.h" #include "logging.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
#ifdef METRICS #ifdef METRICS
static inline size_t kissat_allocated (kissat *solver) { static inline size_t kissat_allocated (kissat *solver) {
@ -13,8 +16,8 @@ static inline size_t kissat_allocated (kissat *solver) {
#endif #endif
static inline bool kissat_propagated (kissat *solver) { static inline bool kissat_propagated (kissat *solver) {
assert (BEGIN_ARRAY (solver->trail) <= solver->propagate); KISSAT_assert (BEGIN_ARRAY (solver->trail) <= solver->propagate);
assert (solver->propagate <= END_ARRAY (solver->trail)); KISSAT_assert (solver->propagate <= END_ARRAY (solver->trail));
return solver->propagate == END_ARRAY (solver->trail); return solver->propagate == END_ARRAY (solver->trail);
} }
@ -27,7 +30,7 @@ static inline void kissat_reset_propagate (kissat *solver) {
} }
static inline value kissat_fixed (kissat *solver, unsigned lit) { static inline value kissat_fixed (kissat *solver, unsigned lit) {
assert (lit < LITS); KISSAT_assert (lit < LITS);
const value res = solver->values[lit]; const value res = solver->values[lit];
if (!res) if (!res)
return 0; return 0;
@ -83,7 +86,7 @@ static inline void kissat_push_blocking_watch (kissat *solver,
watches *watches, watches *watches,
unsigned blocking, unsigned blocking,
reference ref) { reference ref) {
assert (solver->watching); KISSAT_assert (solver->watching);
const watch head = kissat_blocking_watch (blocking); const watch head = kissat_blocking_watch (blocking);
PUSH_WATCHES (*watches, head); PUSH_WATCHES (*watches, head);
const watch tail = kissat_large_watch (ref); const watch tail = kissat_large_watch (ref);
@ -107,7 +110,7 @@ static inline void kissat_watch_binary (kissat *solver, unsigned a,
static inline void kissat_watch_blocking (kissat *solver, unsigned lit, static inline void kissat_watch_blocking (kissat *solver, unsigned lit,
unsigned blocking, unsigned blocking,
reference ref) { reference ref) {
assert (solver->watching); KISSAT_assert (solver->watching);
LOGREF3 (ref, "watching %s blocking %s in", LOGLIT (lit), LOGREF3 (ref, "watching %s blocking %s in", LOGLIT (lit),
LOGLIT (blocking)); LOGLIT (blocking));
watches *watches = &WATCHES (lit); watches *watches = &WATCHES (lit);
@ -116,7 +119,7 @@ static inline void kissat_watch_blocking (kissat *solver, unsigned lit,
static inline void kissat_unwatch_blocking (kissat *solver, unsigned lit, static inline void kissat_unwatch_blocking (kissat *solver, unsigned lit,
reference ref) { reference ref) {
assert (solver->watching); KISSAT_assert (solver->watching);
LOGREF3 (ref, "unwatching %s in", LOGLIT (lit)); LOGREF3 (ref, "unwatching %s in", LOGLIT (lit));
watches *watches = &WATCHES (lit); watches *watches = &WATCHES (lit);
kissat_remove_blocking_watch (solver, watches, ref); kissat_remove_blocking_watch (solver, watches, ref);
@ -124,7 +127,7 @@ static inline void kissat_unwatch_blocking (kissat *solver, unsigned lit,
static inline void kissat_disconnect_binary (kissat *solver, unsigned lit, static inline void kissat_disconnect_binary (kissat *solver, unsigned lit,
unsigned other) { unsigned other) {
assert (!solver->watching); KISSAT_assert (!solver->watching);
watches *watches = &WATCHES (lit); watches *watches = &WATCHES (lit);
const watch watch = kissat_binary_watch (other); const watch watch = kissat_binary_watch (other);
REMOVE_WATCHES (*watches, watch); REMOVE_WATCHES (*watches, watch);
@ -132,7 +135,7 @@ static inline void kissat_disconnect_binary (kissat *solver, unsigned lit,
static inline void static inline void
kissat_disconnect_reference (kissat *solver, unsigned lit, reference ref) { kissat_disconnect_reference (kissat *solver, unsigned lit, reference ref) {
assert (!solver->watching); KISSAT_assert (!solver->watching);
LOGREF3 (ref, "disconnecting %s in", LOGLIT (lit)); LOGREF3 (ref, "disconnecting %s in", LOGLIT (lit));
const watch watch = kissat_large_watch (ref); const watch watch = kissat_large_watch (ref);
watches *watches = &WATCHES (lit); watches *watches = &WATCHES (lit);
@ -141,14 +144,14 @@ kissat_disconnect_reference (kissat *solver, unsigned lit, reference ref) {
static inline void kissat_watch_reference (kissat *solver, unsigned a, static inline void kissat_watch_reference (kissat *solver, unsigned a,
unsigned b, reference ref) { unsigned b, reference ref) {
assert (solver->watching); KISSAT_assert (solver->watching);
kissat_watch_blocking (solver, a, b, ref); kissat_watch_blocking (solver, a, b, ref);
kissat_watch_blocking (solver, b, a, ref); kissat_watch_blocking (solver, b, a, ref);
} }
static inline void kissat_connect_literal (kissat *solver, unsigned lit, static inline void kissat_connect_literal (kissat *solver, unsigned lit,
reference ref) { reference ref) {
assert (!solver->watching); KISSAT_assert (!solver->watching);
LOGREF3 (ref, "connecting %s in", LOGLIT (lit)); LOGREF3 (ref, "connecting %s in", LOGLIT (lit));
watches *watches = &WATCHES (lit); watches *watches = &WATCHES (lit);
kissat_push_large_watch (solver, watches, ref); kissat_push_large_watch (solver, watches, ref);
@ -162,13 +165,13 @@ static inline clause *kissat_unchecked_dereference_clause (kissat *solver,
static inline clause *kissat_dereference_clause (kissat *solver, static inline clause *kissat_dereference_clause (kissat *solver,
reference ref) { reference ref) {
clause *res = kissat_unchecked_dereference_clause (solver, ref); clause *res = kissat_unchecked_dereference_clause (solver, ref);
assert (kissat_clause_in_arena (solver, res)); KISSAT_assert (kissat_clause_in_arena (solver, res));
return res; return res;
} }
static inline reference kissat_reference_clause (kissat *solver, static inline reference kissat_reference_clause (kissat *solver,
const clause *c) { const clause *c) {
assert (kissat_clause_in_arena (solver, c)); KISSAT_assert (kissat_clause_in_arena (solver, c));
return (ward *) c - BEGIN_STACK (solver->arena); return (ward *) c - BEGIN_STACK (solver->arena);
} }
@ -176,33 +179,33 @@ static inline void kissat_inlined_connect_clause (kissat *solver,
watches *all_watches, watches *all_watches,
clause *c, clause *c,
reference ref) { reference ref) {
assert (!solver->watching); KISSAT_assert (!solver->watching);
assert (ref == kissat_reference_clause (solver, c)); KISSAT_assert (ref == kissat_reference_clause (solver, c));
assert (c == kissat_dereference_clause (solver, ref)); KISSAT_assert (c == kissat_dereference_clause (solver, ref));
for (all_literals_in_clause (lit, c)) { for (all_literals_in_clause (lit, c)) {
assert (!solver->watching); KISSAT_assert (!solver->watching);
LOGREF3 (ref, "connecting %s in", LOGLIT (lit)); LOGREF3 (ref, "connecting %s in", LOGLIT (lit));
assert (lit < LITS); KISSAT_assert (lit < LITS);
watches *lit_watches = all_watches + lit; watches *lit_watches = all_watches + lit;
kissat_push_large_watch (solver, lit_watches, ref); kissat_push_large_watch (solver, lit_watches, ref);
} }
} }
static inline void kissat_watch_clause (kissat *solver, clause *c) { static inline void kissat_watch_clause (kissat *solver, clause *c) {
assert (c->searched < c->size); KISSAT_assert (c->searched < c->size);
const reference ref = kissat_reference_clause (solver, c); const reference ref = kissat_reference_clause (solver, c);
kissat_watch_reference (solver, c->lits[0], c->lits[1], ref); kissat_watch_reference (solver, c->lits[0], c->lits[1], ref);
} }
static inline int kissat_export_literal (kissat *solver, unsigned ilit) { static inline int kissat_export_literal (kissat *solver, unsigned ilit) {
const unsigned iidx = IDX (ilit); const unsigned iidx = IDX (ilit);
assert (iidx < (unsigned) INT_MAX); KISSAT_assert (iidx < (unsigned) INT_MAX);
int elit = PEEK_STACK (solver->export, iidx); int elit = PEEK_STACK (solver->export_, iidx);
if (!elit) if (!elit)
return 0; return 0;
if (NEGATED (ilit)) if (NEGATED (ilit))
elit = -elit; elit = -elit;
assert (VALID_EXTERNAL_LITERAL (elit)); KISSAT_assert (VALID_EXTERNAL_LITERAL (elit));
return elit; return elit;
} }
@ -242,9 +245,9 @@ static inline clause *kissat_binary_conflict (kissat *solver, unsigned a,
static inline void kissat_push_analyzed (kissat *solver, assigned *assigned, static inline void kissat_push_analyzed (kissat *solver, assigned *assigned,
unsigned idx) { unsigned idx) {
assert (idx < VARS); KISSAT_assert (idx < VARS);
struct assigned *a = assigned + idx; struct assigned *a = assigned + idx;
assert (!a->analyzed); KISSAT_assert (!a->analyzed);
a->analyzed = true; a->analyzed = true;
PUSH_STACK (solver->analyzed, idx); PUSH_STACK (solver->analyzed, idx);
LOG2 ("%s analyzed", LOGVAR (idx)); LOG2 ("%s analyzed", LOGVAR (idx));
@ -256,9 +259,9 @@ static inline bool kissat_analyzed (kissat *solver) {
static inline void static inline void
kissat_push_removable (kissat *solver, assigned *assigned, unsigned idx) { kissat_push_removable (kissat *solver, assigned *assigned, unsigned idx) {
assert (idx < VARS); KISSAT_assert (idx < VARS);
struct assigned *a = assigned + idx; struct assigned *a = assigned + idx;
assert (!a->removable); KISSAT_assert (!a->removable);
a->removable = true; a->removable = true;
PUSH_STACK (solver->removable, idx); PUSH_STACK (solver->removable, idx);
LOG2 ("%s removable", LOGVAR (idx)); LOG2 ("%s removable", LOGVAR (idx));
@ -266,9 +269,9 @@ kissat_push_removable (kissat *solver, assigned *assigned, unsigned idx) {
static inline void kissat_push_poisoned (kissat *solver, assigned *assigned, static inline void kissat_push_poisoned (kissat *solver, assigned *assigned,
unsigned idx) { unsigned idx) {
assert (idx < VARS); KISSAT_assert (idx < VARS);
struct assigned *a = assigned + idx; struct assigned *a = assigned + idx;
assert (!a->poisoned); KISSAT_assert (!a->poisoned);
a->poisoned = true; a->poisoned = true;
PUSH_STACK (solver->poisoned, idx); PUSH_STACK (solver->poisoned, idx);
LOG2 ("%s poisoned", LOGVAR (idx)); LOG2 ("%s poisoned", LOGVAR (idx));
@ -276,17 +279,17 @@ static inline void kissat_push_poisoned (kissat *solver, assigned *assigned,
static inline void static inline void
kissat_push_shrinkable (kissat *solver, assigned *assigned, unsigned idx) { kissat_push_shrinkable (kissat *solver, assigned *assigned, unsigned idx) {
assert (idx < VARS); KISSAT_assert (idx < VARS);
struct assigned *a = assigned + idx; struct assigned *a = assigned + idx;
assert (!a->shrinkable); KISSAT_assert (!a->shrinkable);
a->shrinkable = true; a->shrinkable = true;
PUSH_STACK (solver->shrinkable, idx); PUSH_STACK (solver->shrinkable, idx);
LOG2 ("%s shrinkable", LOGVAR (idx)); LOG2 ("%s shrinkable", LOGVAR (idx));
} }
static inline int kissat_checking (kissat *solver) { static inline int kissat_checking (kissat *solver) {
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
#ifdef NOPTIONS #ifdef KISSAT_NOPTIONS
(void) solver; (void) solver;
#endif #endif
return GET_OPTION (check); return GET_OPTION (check);
@ -298,7 +301,7 @@ static inline int kissat_checking (kissat *solver) {
static inline bool kissat_logging (kissat *solver) { static inline bool kissat_logging (kissat *solver) {
#ifdef LOGGING #ifdef LOGGING
#ifdef NOPTIONS #ifdef KISSAT_NOPTIONS
(void) solver; (void) solver;
#endif #endif
return GET_OPTION (log) > 0; return GET_OPTION (log) > 0;
@ -309,7 +312,7 @@ static inline bool kissat_logging (kissat *solver) {
} }
static inline bool kissat_proving (kissat *solver) { static inline bool kissat_proving (kissat *solver) {
#ifdef NPROOFS #ifdef KISSAT_NPROOFS
(void) solver; (void) solver;
return false; return false;
#else #else
@ -321,8 +324,10 @@ static inline bool kissat_checking_or_proving (kissat *solver) {
return kissat_checking (solver) || kissat_proving (solver); return kissat_checking (solver) || kissat_proving (solver);
} }
#if !defined(NDEBUG) || !defined(NPROOFS) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS)
#define CHECKING_OR_PROVING #define CHECKING_OR_PROVING
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,6 +1,9 @@
#ifndef _inlineassign_h_INLCUDED #ifndef _inlineassign_h_INLCUDED
#define _inlineassign_h_INLCUDED #define _inlineassign_h_INLCUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
#ifdef FAST_ASSIGN #ifdef FAST_ASSIGN
#define kissat_assign kissat_fast_assign #define kissat_assign kissat_fast_assign
#endif #endif
@ -17,24 +20,26 @@ static inline void kissat_assign (kissat *solver, const bool probing,
watches watches = WATCHES (not_lit); watches watches = WATCHES (not_lit);
if (!kissat_empty_vector (&watches)) { if (!kissat_empty_vector (&watches)) {
watch *w = BEGIN_WATCHES (watches); watch *w = BEGIN_WATCHES (watches);
#ifndef WIN32
__builtin_prefetch (w, 0, 1); __builtin_prefetch (w, 0, 1);
#endif
} }
#ifndef FAST_ASSIGN #ifndef FAST_ASSIGN
value *values = solver->values; value *values = solver->values;
#endif #endif
assert (!values[lit]); KISSAT_assert (!values[lit]);
assert (!values[not_lit]); KISSAT_assert (!values[not_lit]);
values[lit] = 1; values[lit] = 1;
values[not_lit] = -1; values[not_lit] = -1;
assert (solver->unassigned > 0); KISSAT_assert (solver->unassigned > 0);
solver->unassigned--; solver->unassigned--;
if (!level) { if (!level) {
kissat_mark_fixed_literal (solver, lit); kissat_mark_fixed_literal (solver, lit);
assert (solver->unflushed < UINT_MAX); KISSAT_assert (solver->unflushed < UINT_MAX);
solver->unflushed++; solver->unflushed++;
if (reason != UNIT_REASON) { if (reason != UNIT_REASON) {
CHECK_AND_ADD_UNIT (lit); CHECK_AND_ADD_UNIT (lit);
@ -84,17 +89,19 @@ kissat_assignment_level (kissat *solver, value *values, assigned *assigned,
for (all_literals_in_clause (other, reason)) { for (all_literals_in_clause (other, reason)) {
if (other == lit) if (other == lit)
continue; continue;
assert (values[other] < 0), (void) values; KISSAT_assert (values[other] < 0), (void) values;
const unsigned other_idx = IDX (other); const unsigned other_idx = IDX (other);
struct assigned *a = assigned + other_idx; struct assigned *a = assigned + other_idx;
const unsigned level = a->level; const unsigned level = a->level;
if (res < level) if (res < level)
res = level; res = level;
} }
#ifdef NDEBUG #ifdef KISSAT_NDEBUG
(void) solver; (void) solver;
#endif #endif
return res; return res;
} }
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -4,8 +4,11 @@
#include "allocate.h" #include "allocate.h"
#include "internal.h" #include "internal.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
static inline void kissat_push_frame (kissat *solver, unsigned decision) { static inline void kissat_push_frame (kissat *solver, unsigned decision) {
assert (!solver->level || decision != UINT_MAX); KISSAT_assert (!solver->level || decision != UINT_MAX);
const size_t trail = SIZE_ARRAY (solver->trail); const size_t trail = SIZE_ARRAY (solver->trail);
frame frame; frame frame;
frame.decision = decision; frame.decision = decision;
@ -15,4 +18,6 @@ static inline void kissat_push_frame (kissat *solver, unsigned decision) {
PUSH_STACK (solver->frames, frame); PUSH_STACK (solver->frames, frame);
} }
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -5,9 +5,12 @@
#include "internal.h" #include "internal.h"
#include "logging.h" #include "logging.h"
#define HEAP_CHILD(POS) (assert ((POS) < (1u << 31)), (2 * (POS) + 1)) #include "global.h"
ABC_NAMESPACE_HEADER_START
#define HEAP_PARENT(POS) (assert ((POS) > 0), (((POS) - 1) / 2)) #define HEAP_CHILD(POS) (KISSAT_assert ((POS) < (1u << 31)), (2 * (POS) + 1))
#define HEAP_PARENT(POS) (KISSAT_assert ((POS) > 0), (((POS) - 1) / 2))
static inline void kissat_bubble_up (kissat *solver, heap *heap, static inline void kissat_bubble_up (kissat *solver, heap *heap,
unsigned idx) { unsigned idx) {
@ -75,7 +78,7 @@ static inline void kissat_bubble_down (kissat *solver, heap *heap,
#define HEAP_IMPORT(IDX) \ #define HEAP_IMPORT(IDX) \
do { \ do { \
assert ((IDX) < UINT_MAX - 1); \ KISSAT_assert ((IDX) < UINT_MAX - 1); \
if (heap->vars <= (IDX)) \ if (heap->vars <= (IDX)) \
kissat_enlarge_heap (solver, heap, (IDX) + 1); \ kissat_enlarge_heap (solver, heap, (IDX) + 1); \
} while (0) } while (0)
@ -85,7 +88,7 @@ static inline void kissat_bubble_down (kissat *solver, heap *heap,
static inline void kissat_push_heap (kissat *solver, heap *heap, static inline void kissat_push_heap (kissat *solver, heap *heap,
unsigned idx) { unsigned idx) {
LOG ("push heap %u", idx); LOG ("push heap %u", idx);
assert (!kissat_heap_contains (heap, idx)); KISSAT_assert (!kissat_heap_contains (heap, idx));
HEAP_IMPORT (idx); HEAP_IMPORT (idx);
heap->pos[idx] = SIZE_STACK (heap->stack); heap->pos[idx] = SIZE_STACK (heap->stack);
PUSH_STACK (heap->stack, idx); PUSH_STACK (heap->stack, idx);
@ -95,7 +98,7 @@ static inline void kissat_push_heap (kissat *solver, heap *heap,
static inline void kissat_pop_heap (kissat *solver, heap *heap, static inline void kissat_pop_heap (kissat *solver, heap *heap,
unsigned idx) { unsigned idx) {
LOG ("pop heap %u", idx); LOG ("pop heap %u", idx);
assert (kissat_heap_contains (heap, idx)); KISSAT_assert (kissat_heap_contains (heap, idx));
const unsigned last = POP_STACK (heap->stack); const unsigned last = POP_STACK (heap->stack);
heap->pos[last] = DISCONTAIN; heap->pos[last] = DISCONTAIN;
if (last == idx) if (last == idx)
@ -112,11 +115,11 @@ static inline void kissat_pop_heap (kissat *solver, heap *heap,
} }
static inline unsigned kissat_pop_max_heap (kissat *solver, heap *heap) { static inline unsigned kissat_pop_max_heap (kissat *solver, heap *heap) {
assert (!EMPTY_STACK (heap->stack)); KISSAT_assert (!EMPTY_STACK (heap->stack));
unsigneds *stack = &heap->stack; unsigneds *stack = &heap->stack;
unsigned *const begin = BEGIN_STACK (*stack); unsigned *const begin = BEGIN_STACK (*stack);
const unsigned idx = *begin; const unsigned idx = *begin;
assert (!heap->pos[idx]); KISSAT_assert (!heap->pos[idx]);
LOG ("pop max heap %u", idx); LOG ("pop max heap %u", idx);
const unsigned last = POP_STACK (*stack); const unsigned last = POP_STACK (*stack);
unsigned *const pos = heap->pos; unsigned *const pos = heap->pos;
@ -144,7 +147,7 @@ static inline void kissat_adjust_heap (kissat *solver, heap *heap,
size_t new_size = old_size ? 2 * old_size : 1; size_t new_size = old_size ? 2 * old_size : 1;
while (idx >= new_size) while (idx >= new_size)
new_size *= 2; new_size *= 2;
assert (new_size < DISCONTAIN); KISSAT_assert (new_size < DISCONTAIN);
kissat_resize_heap (solver, heap, new_size); kissat_resize_heap (solver, heap, new_size);
} }
kissat_enlarge_heap (solver, heap, idx + 1); kissat_enlarge_heap (solver, heap, idx + 1);
@ -173,4 +176,6 @@ static inline void kissat_update_heap (kissat *solver, heap *heap,
#endif #endif
} }
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -4,9 +4,12 @@
#include "internal.h" #include "internal.h"
#include "logging.h" #include "logging.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
static inline void kissat_update_queue (kissat *solver, const links *links, static inline void kissat_update_queue (kissat *solver, const links *links,
unsigned idx) { unsigned idx) {
assert (!DISCONNECTED (idx)); KISSAT_assert (!DISCONNECTED (idx));
const unsigned stamp = links[idx].stamp; const unsigned stamp = links[idx].stamp;
LOG ("queue updated to %s stamped %u", LOGVAR (idx), stamp); LOG ("queue updated to %s stamped %u", LOGVAR (idx), stamp);
solver->queue.search.idx = idx; solver->queue.search.idx = idx;
@ -16,20 +19,20 @@ static inline void kissat_update_queue (kissat *solver, const links *links,
static inline void kissat_enqueue_links (kissat *solver, unsigned i, static inline void kissat_enqueue_links (kissat *solver, unsigned i,
links *links, queue *queue) { links *links, queue *queue) {
struct links *p = links + i; struct links *p = links + i;
assert (DISCONNECTED (p->prev)); KISSAT_assert (DISCONNECTED (p->prev));
assert (DISCONNECTED (p->next)); KISSAT_assert (DISCONNECTED (p->next));
const unsigned j = p->prev = queue->last; const unsigned j = p->prev = queue->last;
queue->last = i; queue->last = i;
if (DISCONNECTED (j)) if (DISCONNECTED (j))
queue->first = i; queue->first = i;
else { else {
struct links *l = links + j; struct links *l = links + j;
assert (DISCONNECTED (l->next)); KISSAT_assert (DISCONNECTED (l->next));
l->next = i; l->next = i;
} }
if (queue->stamp == UINT_MAX) { if (queue->stamp == UINT_MAX) {
kissat_reassign_queue_stamps (solver); kissat_reassign_queue_stamps (solver);
assert (p->stamp == queue->stamp); KISSAT_assert (p->stamp == queue->stamp);
} else } else
p->stamp = ++queue->stamp; p->stamp = ++queue->stamp;
} }
@ -40,25 +43,25 @@ static inline void kissat_dequeue_links (unsigned i, links *links,
const unsigned j = l->prev, k = l->next; const unsigned j = l->prev, k = l->next;
l->prev = l->next = DISCONNECT; l->prev = l->next = DISCONNECT;
if (DISCONNECTED (j)) { if (DISCONNECTED (j)) {
assert (queue->first == i); KISSAT_assert (queue->first == i);
queue->first = k; queue->first = k;
} else { } else {
struct links *p = links + j; struct links *p = links + j;
assert (p->next == i); KISSAT_assert (p->next == i);
p->next = k; p->next = k;
} }
if (DISCONNECTED (k)) { if (DISCONNECTED (k)) {
assert (queue->last == i); KISSAT_assert (queue->last == i);
queue->last = j; queue->last = j;
} else { } else {
struct links *n = links + k; struct links *n = links + k;
assert (n->prev == i); KISSAT_assert (n->prev == i);
n->prev = j; n->prev = j;
} }
} }
static inline void kissat_enqueue (kissat *solver, unsigned idx) { static inline void kissat_enqueue (kissat *solver, unsigned idx) {
assert (idx < solver->vars); KISSAT_assert (idx < solver->vars);
links *links = solver->links, *l = links + idx; links *links = solver->links, *l = links + idx;
l->prev = l->next = DISCONNECT; l->prev = l->next = DISCONNECT;
kissat_enqueue_links (solver, idx, links, &solver->queue); kissat_enqueue_links (solver, idx, links, &solver->queue);
@ -69,7 +72,7 @@ static inline void kissat_enqueue (kissat *solver, unsigned idx) {
} }
static inline void kissat_dequeue (kissat *solver, unsigned idx) { static inline void kissat_dequeue (kissat *solver, unsigned idx) {
assert (idx < solver->vars); KISSAT_assert (idx < solver->vars);
LOG ("dequeued %s", LOGVAR (idx)); LOG ("dequeued %s", LOGVAR (idx));
links *links = solver->links; links *links = solver->links;
if (solver->queue.search.idx == idx) { if (solver->queue.search.idx == idx) {
@ -91,10 +94,10 @@ static inline void kissat_move_to_front (kissat *solver, unsigned idx) {
queue *queue = &solver->queue; queue *queue = &solver->queue;
links *links = solver->links; links *links = solver->links;
if (idx == queue->last) { if (idx == queue->last) {
assert (DISCONNECTED (links[idx].next)); KISSAT_assert (DISCONNECTED (links[idx].next));
return; return;
} }
assert (idx < solver->vars); KISSAT_assert (idx < solver->vars);
const value tmp = VALUE (LIT (idx)); const value tmp = VALUE (LIT (idx));
if (tmp && queue->search.idx == idx) { if (tmp && queue->search.idx == idx) {
unsigned prev = links[idx].prev; unsigned prev = links[idx].prev;
@ -102,7 +105,7 @@ static inline void kissat_move_to_front (kissat *solver, unsigned idx) {
kissat_update_queue (solver, links, prev); kissat_update_queue (solver, links, prev);
else { else {
unsigned next = links[idx].next; unsigned next = links[idx].next;
assert (!DISCONNECTED (next)); KISSAT_assert (!DISCONNECTED (next));
kissat_update_queue (solver, links, next); kissat_update_queue (solver, links, next);
} }
} }
@ -114,4 +117,6 @@ static inline void kissat_move_to_front (kissat *solver, unsigned idx) {
kissat_check_queue (solver); kissat_check_queue (solver);
} }
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -3,9 +3,12 @@
#include "internal.h" #include "internal.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
static inline unsigned *kissat_begin_vector (kissat *solver, static inline unsigned *kissat_begin_vector (kissat *solver,
vector *vector) { vector *vector) {
#ifdef COMPACT #ifdef KISSAT_COMPACT
return BEGIN_STACK (solver->vectors.stack) + vector->offset; return BEGIN_STACK (solver->vectors.stack) + vector->offset;
#else #else
(void) solver; (void) solver;
@ -14,7 +17,7 @@ static inline unsigned *kissat_begin_vector (kissat *solver,
} }
static inline unsigned *kissat_end_vector (kissat *solver, vector *vector) { static inline unsigned *kissat_end_vector (kissat *solver, vector *vector) {
#ifdef COMPACT #ifdef KISSAT_COMPACT
return kissat_begin_vector (solver, vector) + vector->size; return kissat_begin_vector (solver, vector) + vector->size;
#else #else
(void) solver; (void) solver;
@ -24,7 +27,7 @@ static inline unsigned *kissat_end_vector (kissat *solver, vector *vector) {
static inline const unsigned * static inline const unsigned *
kissat_begin_const_vector (kissat *solver, const vector *vector) { kissat_begin_const_vector (kissat *solver, const vector *vector) {
#ifdef COMPACT #ifdef KISSAT_COMPACT
return BEGIN_STACK (solver->vectors.stack) + vector->offset; return BEGIN_STACK (solver->vectors.stack) + vector->offset;
#else #else
(void) solver; (void) solver;
@ -34,7 +37,7 @@ kissat_begin_const_vector (kissat *solver, const vector *vector) {
static inline const unsigned * static inline const unsigned *
kissat_end_const_vector (kissat *solver, const vector *vector) { kissat_end_const_vector (kissat *solver, const vector *vector) {
#ifdef COMPACT #ifdef KISSAT_COMPACT
return kissat_begin_const_vector (solver, vector) + vector->size; return kissat_begin_const_vector (solver, vector) + vector->size;
#else #else
(void) solver; (void) solver;
@ -45,7 +48,7 @@ kissat_end_const_vector (kissat *solver, const vector *vector) {
#if defined(LOGGING) || defined(TEST_VECTOR) #if defined(LOGGING) || defined(TEST_VECTOR)
static inline size_t kissat_offset_vector (kissat *solver, vector *vector) { static inline size_t kissat_offset_vector (kissat *solver, vector *vector) {
#ifdef COMPACT #ifdef KISSAT_COMPACT
(void) solver; (void) solver;
return vector->offset; return vector->offset;
#else #else
@ -58,7 +61,7 @@ static inline size_t kissat_offset_vector (kissat *solver, vector *vector) {
#endif #endif
static inline size_t kissat_size_vector (const vector *vector) { static inline size_t kissat_size_vector (const vector *vector) {
#ifdef COMPACT #ifdef KISSAT_COMPACT
return vector->size; return vector->size;
#else #else
return vector->end - vector->begin; return vector->end - vector->begin;
@ -66,7 +69,7 @@ static inline size_t kissat_size_vector (const vector *vector) {
} }
static inline bool kissat_empty_vector (vector *vector) { static inline bool kissat_empty_vector (vector *vector) {
#ifdef COMPACT #ifdef KISSAT_COMPACT
return !vector->size; return !vector->size;
#else #else
return vector->end == vector->begin; return vector->end == vector->begin;
@ -74,20 +77,20 @@ static inline bool kissat_empty_vector (vector *vector) {
} }
static inline void kissat_inc_usable (kissat *solver) { static inline void kissat_inc_usable (kissat *solver) {
assert (MAX_SECTOR > solver->vectors.usable); KISSAT_assert (MAX_SECTOR > solver->vectors.usable);
solver->vectors.usable++; solver->vectors.usable++;
} }
static inline void kissat_add_usable (kissat *solver, size_t inc) { static inline void kissat_add_usable (kissat *solver, size_t inc) {
assert (MAX_SECTOR - inc >= solver->vectors.usable); KISSAT_assert (MAX_SECTOR - inc >= solver->vectors.usable);
solver->vectors.usable += inc; solver->vectors.usable += inc;
} }
static inline unsigned *kissat_last_vector_pointer (kissat *solver, static inline unsigned *kissat_last_vector_pointer (kissat *solver,
vector *vector) { vector *vector) {
assert (!kissat_empty_vector (vector)); KISSAT_assert (!kissat_empty_vector (vector));
#ifdef COMPACT #ifdef KISSAT_COMPACT
assert (vector->size); KISSAT_assert (vector->size);
unsigned *begin = kissat_begin_vector (solver, vector); unsigned *begin = kissat_begin_vector (solver, vector);
return begin + vector->size - 1; return begin + vector->size - 1;
#else #else
@ -99,8 +102,8 @@ static inline unsigned *kissat_last_vector_pointer (kissat *solver,
#ifdef TEST_VECTOR #ifdef TEST_VECTOR
static inline void kissat_pop_vector (kissat *solver, vector *vector) { static inline void kissat_pop_vector (kissat *solver, vector *vector) {
assert (!kissat_empty_vector (vector)); KISSAT_assert (!kissat_empty_vector (vector));
#ifdef COMPACT #ifdef KISSAT_COMPACT
unsigned *p = kissat_last_vector_pointer (solver, vector); unsigned *p = kissat_last_vector_pointer (solver, vector);
vector->size--; vector->size--;
*p = INVALID_VECTOR_ELEMENT; *p = INVALID_VECTOR_ELEMENT;
@ -118,16 +121,16 @@ static inline void kissat_release_vector (kissat *solver, vector *vector) {
} }
static inline void kissat_dec_usable (kissat *solver) { static inline void kissat_dec_usable (kissat *solver) {
assert (solver->vectors.usable > 0); KISSAT_assert (solver->vectors.usable > 0);
solver->vectors.usable--; solver->vectors.usable--;
} }
static inline void kissat_push_vectors (kissat *solver, vector *vector, static inline void kissat_push_vectors (kissat *solver, vector *vector,
unsigned e) { unsigned e) {
unsigneds *stack = &solver->vectors.stack; unsigneds *stack = &solver->vectors.stack;
assert (e != INVALID_VECTOR_ELEMENT); KISSAT_assert (e != INVALID_VECTOR_ELEMENT);
if ( if (
#ifdef COMPACT #ifdef KISSAT_COMPACT
!vector->size && !vector->offset !vector->size && !vector->offset
#else #else
!vector->begin !vector->begin
@ -137,21 +140,21 @@ static inline void kissat_push_vectors (kissat *solver, vector *vector,
PUSH_STACK (*stack, 0); PUSH_STACK (*stack, 0);
if (FULL_STACK (*stack)) { if (FULL_STACK (*stack)) {
unsigned *end = kissat_enlarge_vector (solver, vector); unsigned *end = kissat_enlarge_vector (solver, vector);
assert (*end == INVALID_VECTOR_ELEMENT); KISSAT_assert (*end == INVALID_VECTOR_ELEMENT);
*end = e; *end = e;
kissat_dec_usable (solver); kissat_dec_usable (solver);
} else { } else {
#ifdef COMPACT #ifdef KISSAT_COMPACT
assert ((uint64_t) SIZE_STACK (*stack) < MAX_VECTORS); KISSAT_assert ((uint64_t) SIZE_STACK (*stack) < MAX_VECTORS);
vector->offset = SIZE_STACK (*stack); vector->offset = SIZE_STACK (*stack);
assert (vector->offset); KISSAT_assert (vector->offset);
*stack->end++ = e; *stack->end++ = e;
#else #else
assert (stack->end < stack->allocated); KISSAT_assert (stack->end < stack->allocated);
*(vector->begin = stack->end++) = e; *(vector->begin = stack->end++) = e;
#endif #endif
} }
#if !defined(COMPACT) #if !defined(KISSAT_COMPACT)
vector->end = vector->begin; vector->end = vector->begin;
#endif #endif
} else { } else {
@ -159,7 +162,7 @@ static inline void kissat_push_vectors (kissat *solver, vector *vector,
if (end == END_STACK (*stack)) { if (end == END_STACK (*stack)) {
if (FULL_STACK (*stack)) { if (FULL_STACK (*stack)) {
end = kissat_enlarge_vector (solver, vector); end = kissat_enlarge_vector (solver, vector);
assert (*end == INVALID_VECTOR_ELEMENT); KISSAT_assert (*end == INVALID_VECTOR_ELEMENT);
*end = e; *end = e;
kissat_dec_usable (solver); kissat_dec_usable (solver);
} else } else
@ -167,12 +170,12 @@ static inline void kissat_push_vectors (kissat *solver, vector *vector,
} else { } else {
if (*end != INVALID_VECTOR_ELEMENT) if (*end != INVALID_VECTOR_ELEMENT)
end = kissat_enlarge_vector (solver, vector); end = kissat_enlarge_vector (solver, vector);
assert (*end == INVALID_VECTOR_ELEMENT); KISSAT_assert (*end == INVALID_VECTOR_ELEMENT);
*end = e; *end = e;
kissat_dec_usable (solver); kissat_dec_usable (solver);
} }
} }
#ifndef COMPACT #ifndef KISSAT_COMPACT
vector->end++; vector->end++;
#else #else
vector->size++; vector->size++;
@ -190,4 +193,6 @@ static inline void kissat_push_vectors (kissat *solver, vector *vector,
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -17,24 +17,26 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
ABC_NAMESPACE_IMPL_START
void kissat_reset_last_learned (kissat *solver) { void kissat_reset_last_learned (kissat *solver) {
for (really_all_last_learned (p)) for (really_all_last_learned (p))
*p = INVALID_REF; *p = INVALID_REF;
} }
kissat *kissat_init (void) { kissat *kissat_init (void) {
kissat *solver = kissat_calloc (0, 1, sizeof *solver); kissat *solver = (kissat*)kissat_calloc (0, 1, sizeof *solver);
#ifndef NOPTIONS #ifndef KISSAT_NOPTIONS
kissat_init_options (&solver->options); kissat_init_options (&solver->options);
#else #else
kissat_init_options (); kissat_init_options ();
#endif #endif
#ifndef QUIET #ifndef KISSAT_QUIET
kissat_init_profiles (&solver->profiles); kissat_init_profiles (&solver->profiles);
#endif #endif
START (total); START (total);
kissat_init_queue (solver); kissat_init_queue (solver);
assert (INTERNAL_MAX_LIT < UINT_MAX); KISSAT_assert (INTERNAL_MAX_LIT < UINT_MAX);
kissat_push_frame (solver, UINT_MAX); kissat_push_frame (solver, UINT_MAX);
solver->watching = true; solver->watching = true;
solver->conflict.size = 2; solver->conflict.size = 2;
@ -42,7 +44,7 @@ kissat *kissat_init (void) {
solver->first_reducible = INVALID_REF; solver->first_reducible = INVALID_REF;
solver->last_irredundant = INVALID_REF; solver->last_irredundant = INVALID_REF;
kissat_reset_last_learned (solver); kissat_reset_last_learned (solver);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
kissat_init_checker (solver); kissat_init_checker (solver);
#endif #endif
solver->prefix = kissat_strdup (solver, "c "); solver->prefix = kissat_strdup (solver, "c ");
@ -83,7 +85,7 @@ void kissat_release (kissat *solver) {
kissat_release_vectors (solver); kissat_release_vectors (solver);
kissat_release_phases (solver); kissat_release_phases (solver);
RELEASE_STACK (solver->export); RELEASE_STACK (solver->export_);
RELEASE_STACK (solver->import); RELEASE_STACK (solver->import);
DEALLOC_VARIABLE_INDEXED (assigned); DEALLOC_VARIABLE_INDEXED (assigned);
@ -104,7 +106,7 @@ void kissat_release (kissat *solver) {
RELEASE_STACK (solver->clause); RELEASE_STACK (solver->clause);
RELEASE_STACK (solver->shadow); RELEASE_STACK (solver->shadow);
#if defined(LOGGING) || !defined(NDEBUG) #if defined(LOGGING) || !defined(KISSAT_NDEBUG)
RELEASE_STACK (solver->resolvent); RELEASE_STACK (solver->resolvent);
#endif #endif
@ -136,26 +138,26 @@ void kissat_release (kissat *solver) {
RELEASE_STACK (solver->gates[1]); RELEASE_STACK (solver->gates[1]);
RELEASE_STACK (solver->resolvents); RELEASE_STACK (solver->resolvents);
#if !defined(NDEBUG) || !defined(NPROOFS) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS)
RELEASE_STACK (solver->added); RELEASE_STACK (solver->added);
RELEASE_STACK (solver->removed); RELEASE_STACK (solver->removed);
#endif #endif
#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) || defined(LOGGING)
RELEASE_STACK (solver->original); RELEASE_STACK (solver->original);
#endif #endif
#ifndef QUIET #ifndef KISSAT_QUIET
RELEASE_STACK (solver->profiles.stack); RELEASE_STACK (solver->profiles.stack);
#endif #endif
kissat_freestr (solver, solver->prefix); kissat_freestr (solver, solver->prefix);
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
kissat_release_checker (solver); kissat_release_checker (solver);
#endif #endif
#if !defined(NDEBUG) && defined(METRICS) #if !defined(KISSAT_NDEBUG) && defined(METRICS)
uint64_t leaked = solver->statistics.allocated_current; uint64_t leaked = solver->statistics_.allocated_current;
if (leaked) if (leaked)
if (!getenv ("LEAK")) if (!getenv ("LEAK"))
kissat_fatal ("internally leaking %" PRIu64 " bytes", leaked); kissat_fatal ("internally leaking %" PRIu64 " bytes", leaked);
@ -182,7 +184,7 @@ void kissat_reserve (kissat *solver, int max_var) {
int kissat_get_option (kissat *solver, const char *name) { int kissat_get_option (kissat *solver, const char *name) {
kissat_require_initialized (solver); kissat_require_initialized (solver);
kissat_require (name, "name zero pointer"); kissat_require (name, "name zero pointer");
#ifndef NOPTIONS #ifndef KISSAT_NOPTIONS
return kissat_options_get (&solver->options, name); return kissat_options_get (&solver->options, name);
#else #else
(void) solver; (void) solver;
@ -191,10 +193,10 @@ int kissat_get_option (kissat *solver, const char *name) {
} }
int kissat_set_option (kissat *solver, const char *name, int new_value) { int kissat_set_option (kissat *solver, const char *name, int new_value) {
#ifndef NOPTIONS #ifndef KISSAT_NOPTIONS
kissat_require_initialized (solver); kissat_require_initialized (solver);
kissat_require (name, "name zero pointer"); kissat_require (name, "name zero pointer");
#ifndef NOPTIONS #ifndef KISSAT_NOPTIONS
return kissat_options_set (&solver->options, name, new_value); return kissat_options_set (&solver->options, name, new_value);
#else #else
return kissat_options_set (name, new_value); return kissat_options_set (name, new_value);
@ -209,9 +211,9 @@ void kissat_set_decision_limit (kissat *solver, unsigned limit) {
kissat_require_initialized (solver); kissat_require_initialized (solver);
limits *limits = &solver->limits; limits *limits = &solver->limits;
limited *limited = &solver->limited; limited *limited = &solver->limited;
statistics *statistics = &solver->statistics; statistics *statistics = &solver->statistics_;
limited->decisions = true; limited->decisions = true;
assert (UINT64_MAX - limit >= statistics->decisions); KISSAT_assert (UINT64_MAX - limit >= statistics->decisions);
limits->decisions = statistics->decisions + limit; limits->decisions = statistics->decisions + limit;
LOG ("set decision limit to %" PRIu64 " after %u decisions", LOG ("set decision limit to %" PRIu64 " after %u decisions",
limits->decisions, limit); limits->decisions, limit);
@ -221,16 +223,16 @@ void kissat_set_conflict_limit (kissat *solver, unsigned limit) {
kissat_require_initialized (solver); kissat_require_initialized (solver);
limits *limits = &solver->limits; limits *limits = &solver->limits;
limited *limited = &solver->limited; limited *limited = &solver->limited;
statistics *statistics = &solver->statistics; statistics *statistics = &solver->statistics_;
limited->conflicts = true; limited->conflicts = true;
assert (UINT64_MAX - limit >= statistics->conflicts); KISSAT_assert (UINT64_MAX - limit >= statistics->conflicts);
limits->conflicts = statistics->conflicts + limit; limits->conflicts = statistics->conflicts + limit;
LOG ("set conflict limit to %" PRIu64 " after %u conflicts", LOG ("set conflict limit to %" PRIu64 " after %u conflicts",
limits->conflicts, limit); limits->conflicts, limit);
} }
void kissat_print_statistics (kissat *solver) { void kissat_print_statistics (kissat *solver) {
#ifndef QUIET #ifndef KISSAT_QUIET
kissat_require_initialized (solver); kissat_require_initialized (solver);
const int verbosity = kissat_verbosity (solver); const int verbosity = kissat_verbosity (solver);
if (verbosity < 0) if (verbosity < 0)
@ -243,13 +245,13 @@ void kissat_print_statistics (kissat *solver) {
kissat_section (solver, "statistics"); kissat_section (solver, "statistics");
const bool verbose = (complete || verbosity > 0); const bool verbose = (complete || verbosity > 0);
kissat_statistics_print (solver, verbose); kissat_statistics_print (solver, verbose);
#ifndef NPROOFS #ifndef KISSAT_NPROOFS
if (solver->proof) { if (solver->proof) {
kissat_section (solver, "proof"); kissat_section (solver, "proof");
kissat_print_proof_statistics (solver, verbose); kissat_print_proof_statistics (solver, verbose);
} }
#endif #endif
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
if (GET_OPTION (check) > 1) { if (GET_OPTION (check) > 1) {
kissat_section (solver, "checker"); kissat_section (solver, "checker");
kissat_print_checker_statistics (solver, verbose); kissat_print_checker_statistics (solver, verbose);
@ -266,14 +268,14 @@ void kissat_print_statistics (kissat *solver) {
void kissat_add (kissat *solver, int elit) { void kissat_add (kissat *solver, int elit) {
kissat_require_initialized (solver); kissat_require_initialized (solver);
kissat_require (!GET (searches), "incremental solving not supported"); kissat_require (!GET (searches), "incremental solving not supported");
#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) || defined(LOGGING)
const int checking = kissat_checking (solver); const int checking = kissat_checking (solver);
const bool logging = kissat_logging (solver); const bool logging = kissat_logging (solver);
const bool proving = kissat_proving (solver); const bool proving = kissat_proving (solver);
#endif #endif
if (elit) { if (elit) {
kissat_require_valid_external_internal (elit); kissat_require_valid_external_internal (elit);
#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) || defined(LOGGING)
if (checking || logging || proving) if (checking || logging || proving)
PUSH_STACK (solver->original, elit); PUSH_STACK (solver->original, elit);
#endif #endif
@ -297,18 +299,18 @@ void kissat_add (kissat *solver, int elit) {
} else { } else {
MARK (ilit) = 1; MARK (ilit) = 1;
MARK (NOT (ilit)) = -1; MARK (NOT (ilit)) = -1;
assert (SIZE_STACK (solver->clause) < UINT_MAX); KISSAT_assert (SIZE_STACK (solver->clause) < UINT_MAX);
PUSH_STACK (solver->clause, ilit); PUSH_STACK (solver->clause, ilit);
} }
} else if (mark < 0) { } else if (mark < 0) {
assert (mark < 0); KISSAT_assert (mark < 0);
if (!solver->clause_trivial) { if (!solver->clause_trivial) {
LOG ("adding dual literal %u(%d) and %u(%d)", NOT (ilit), -elit, LOG ("adding dual literal %u(%d) and %u(%d)", NOT (ilit), -elit,
ilit, elit); ilit, elit);
solver->clause_trivial = true; solver->clause_trivial = true;
} }
} else { } else {
assert (mark > 0); KISSAT_assert (mark > 0);
LOG ("adding duplicated literal %u(%d)", ilit, elit); LOG ("adding duplicated literal %u(%d)", ilit, elit);
if (!solver->clause_shrink) { if (!solver->clause_shrink) {
solver->clause_shrink = true; solver->clause_shrink = true;
@ -316,16 +318,16 @@ void kissat_add (kissat *solver, int elit) {
} }
} }
} else { } else {
#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) || defined(LOGGING)
const size_t offset = solver->offset_of_last_original_clause; const size_t offset = solver->offset_of_last_original_clause;
size_t esize = SIZE_STACK (solver->original) - offset; size_t esize = SIZE_STACK (solver->original) - offset;
int *elits = BEGIN_STACK (solver->original) + offset; int *elits = BEGIN_STACK (solver->original) + offset;
assert (esize <= UINT_MAX); KISSAT_assert (esize <= UINT_MAX);
#endif #endif
ADD_UNCHECKED_EXTERNAL (esize, elits); ADD_UNCHECKED_EXTERNAL (esize, elits);
const size_t isize = SIZE_STACK (solver->clause); const size_t isize = SIZE_STACK (solver->clause);
unsigned *ilits = BEGIN_STACK (solver->clause); unsigned *ilits = BEGIN_STACK (solver->clause);
assert (isize < (unsigned) INT_MAX); KISSAT_assert (isize < (unsigned) INT_MAX);
if (solver->inconsistent) if (solver->inconsistent)
LOG ("inconsistent thus skipping original clause"); LOG ("inconsistent thus skipping original clause");
@ -380,38 +382,38 @@ void kissat_add (kissat *solver, int elit) {
assign = true; assign = true;
} else if (u < 0 && k == l) { } else if (u < 0 && k == l) {
LOG ("both watches falsified at level @%u", k); LOG ("both watches falsified at level @%u", k);
assert (v < 0); KISSAT_assert (v < 0);
assert (k > 0); KISSAT_assert (k > 0);
kissat_backtrack_without_updating_phases (solver, k - 1); kissat_backtrack_without_updating_phases (solver, k - 1);
} else if (u < 0) { } else if (u < 0) {
LOG ("watches falsified at levels @%u and @%u", k, l); LOG ("watches falsified at levels @%u and @%u", k, l);
assert (v < 0); KISSAT_assert (v < 0);
assert (k > l); KISSAT_assert (k > l);
assert (l > 0); KISSAT_assert (l > 0);
assign = true; assign = true;
} else if (u > 0 && v < 0) { } else if (u > 0 && v < 0) {
LOG ("first watch satisfied at level @%u " LOG ("first watch satisfied at level @%u "
"second falsified at level @%u", "second falsified at level @%u",
k, l); k, l);
assert (k <= l); KISSAT_assert (k <= l);
} else if (!u && v > 0) { } else if (!u && v > 0) {
LOG ("first watch unassigned " LOG ("first watch unassigned "
"second falsified at level @%u", "second falsified at level @%u",
l); l);
assign = true; assign = true;
} else { } else {
assert (!u); KISSAT_assert (!u);
assert (!v); KISSAT_assert (!v);
} }
if (assign) { if (assign) {
assert (solver->level > 0); KISSAT_assert (solver->level > 0);
if (isize == 2) { if (isize == 2) {
assert (res == INVALID_REF); KISSAT_assert (res == INVALID_REF);
kissat_assign_binary (solver, a, b); kissat_assign_binary (solver, a, b);
} else { } else {
assert (res != INVALID_REF); KISSAT_assert (res != INVALID_REF);
clause *c = kissat_dereference_clause (solver, res); clause *c = kissat_dereference_clause (solver, res);
kissat_assign_reference (solver, a, res, c); kissat_assign_reference (solver, a, res, c);
} }
@ -419,13 +421,13 @@ void kissat_add (kissat *solver, int elit) {
} }
} }
#if !defined(NDEBUG) || !defined(NPROOFS) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS)
if (solver->clause_satisfied || solver->clause_trivial) { if (solver->clause_satisfied || solver->clause_trivial) {
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
if (checking > 1) if (checking > 1)
kissat_remove_checker_external (solver, esize, elits); kissat_remove_checker_external (solver, esize, elits);
#endif #endif
#ifndef NPROOFS #ifndef KISSAT_NPROOFS
if (proving) { if (proving) {
if (esize == 1) if (esize == 1)
LOG ("skipping deleting unit from proof"); LOG ("skipping deleting unit from proof");
@ -434,13 +436,13 @@ void kissat_add (kissat *solver, int elit) {
} }
#endif #endif
} else if (!solver->inconsistent && solver->clause_shrink) { } else if (!solver->inconsistent && solver->clause_shrink) {
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
if (checking > 1) { if (checking > 1) {
kissat_check_and_add_internal (solver, isize, ilits); kissat_check_and_add_internal (solver, isize, ilits);
kissat_remove_checker_external (solver, esize, elits); kissat_remove_checker_external (solver, esize, elits);
} }
#endif #endif
#ifndef NPROOFS #ifndef KISSAT_NPROOFS
if (proving) { if (proving) {
kissat_add_lits_to_proof (solver, isize, ilits); kissat_add_lits_to_proof (solver, isize, ilits);
kissat_delete_external_from_proof (solver, esize, elits); kissat_delete_external_from_proof (solver, esize, elits);
@ -449,7 +451,7 @@ void kissat_add (kissat *solver, int elit) {
} }
#endif #endif
#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) || defined(LOGGING)
if (checking) { if (checking) {
LOGINTS (esize, elits, "saved original"); LOGINTS (esize, elits, "saved original");
PUSH_STACK (solver->original, 0); PUSH_STACK (solver->original, 0);
@ -483,7 +485,7 @@ int kissat_solve (kissat *solver) {
void kissat_terminate (kissat *solver) { void kissat_terminate (kissat *solver) {
kissat_require_initialized (solver); kissat_require_initialized (solver);
solver->termination.flagged = ~(unsigned) 0; solver->termination.flagged = ~(unsigned) 0;
assert (solver->termination.flagged); KISSAT_assert (solver->termination.flagged);
} }
void kissat_set_terminate (kissat *solver, void *state, void kissat_set_terminate (kissat *solver, void *state,
@ -518,3 +520,9 @@ int kissat_value (kissat *solver, int elit) {
tmp = -tmp; tmp = -tmp;
return tmp < 0 ? -elit : elit; return tmp < 0 ? -elit : elit;
} }
int kissat_is_inconsistent(kissat *solver) {
return solver->inconsistent;
}
ABC_NAMESPACE_IMPL_END

View File

@ -33,6 +33,9 @@
#include "vector.h" #include "vector.h"
#include "watch.h" #include "watch.h"
#include "global.h"
ABC_NAMESPACE_HEADER_START
typedef struct datarank datarank; typedef struct datarank datarank;
struct datarank { struct datarank {
@ -74,7 +77,7 @@ typedef STACK (watch *) patches;
struct kitten; struct kitten;
struct kissat { struct kissat {
#if !defined(NDEBUG) || defined(METRICS) #if !defined(KISSAT_NDEBUG) || defined(METRICS)
bool backbone_computing; bool backbone_computing;
#endif #endif
#ifdef LOGGING #ifdef LOGGING
@ -85,11 +88,11 @@ struct kissat {
bool iterating; bool iterating;
bool preprocessing; bool preprocessing;
bool probing; bool probing;
#ifndef QUIET #ifndef KISSAT_QUIET
bool sectioned; bool sectioned;
#endif #endif
bool stable; bool stable;
#if !defined(NDEBUG) || defined(METRICS) #if !defined(KISSAT_NDEBUG) || defined(METRICS)
bool transitive_reducing; bool transitive_reducing;
bool vivifying; bool vivifying;
#endif #endif
@ -105,7 +108,7 @@ struct kissat {
unsigned active; unsigned active;
unsigned randec; unsigned randec;
ints export; ints export_;
ints units; ints units;
imports import; imports import;
extensions extend; extensions extend;
@ -144,7 +147,7 @@ struct kissat {
unsigneds delayed; unsigneds delayed;
#if defined(LOGGING) || !defined(NDEBUG) #if defined(LOGGING) || !defined(KISSAT_NDEBUG)
unsigneds resolvent; unsigneds resolvent;
#endif #endif
unsigned resolvent_size; unsigned resolvent_size;
@ -197,7 +200,7 @@ struct kissat {
uint64_t ticks; uint64_t ticks;
format format; kormat format;
char *prefix; char *prefix;
statches antecedents[2]; statches antecedents[2];
@ -215,33 +218,33 @@ struct kissat {
bool sweep_incomplete; bool sweep_incomplete;
unsigneds sweep_schedule; unsigneds sweep_schedule;
#if !defined(NDEBUG) || !defined(NPROOFS) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS)
unsigneds added; unsigneds added;
unsigneds removed; unsigneds removed;
#endif #endif
#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING) #if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) || defined(LOGGING)
ints original; ints original;
size_t offset_of_last_original_clause; size_t offset_of_last_original_clause;
#endif #endif
#ifndef QUIET #ifndef KISSAT_QUIET
profiles profiles; profiles profiles;
#endif #endif
#ifndef NOPTIONS #ifndef KISSAT_NOPTIONS
options options; options options;
#endif #endif
#ifndef NDEBUG #ifndef KISSAT_NDEBUG
checker *checker; checker *checker;
#endif #endif
#ifndef NPROOFS #ifndef KISSAT_NPROOFS
proof *proof; proof *proof;
#endif #endif
statistics statistics; statistics statistics_;
}; };
#define VARS (solver->vars) #define VARS (solver->vars)
@ -259,7 +262,7 @@ struct kissat {
#define SCORES (&solver->scores) #define SCORES (&solver->scores)
static inline unsigned kissat_assigned (kissat *solver) { static inline unsigned kissat_assigned (kissat *solver) {
assert (VARS >= solver->unassigned); KISSAT_assert (VARS >= solver->unassigned);
return VARS - solver->unassigned; return VARS - solver->unassigned;
} }
@ -292,4 +295,6 @@ static inline unsigned kissat_assigned (kissat *solver) {
void kissat_reset_last_learned (kissat *solver); void kissat_reset_last_learned (kissat *solver);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,6 +1,9 @@
#ifndef _keatures_h_INCLUDED #ifndef _keatures_h_INCLUDED
#define _keatures_h_INCLUDED #define _keatures_h_INCLUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define KISSAT_IS_BIG_ENDIAN #define KISSAT_IS_BIG_ENDIAN
#endif #endif
@ -15,4 +18,6 @@
#define KISSAT_HAS_UNLOCKEDIO #define KISSAT_HAS_UNLOCKEDIO
#endif #endif
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -10,29 +10,31 @@
#include <inttypes.h> #include <inttypes.h>
#include <math.h> #include <math.h>
ABC_NAMESPACE_IMPL_START
double kissat_logn (uint64_t count) { double kissat_logn (uint64_t count) {
assert (count > 0); KISSAT_assert (count > 0);
const double res = log10 (count + 9); const double res = log10 (count + 9);
assert (res >= 1); KISSAT_assert (res >= 1);
return res; return res;
} }
double kissat_sqrt (uint64_t count) { double kissat_sqrt (uint64_t count) {
assert (count > 0); KISSAT_assert (count > 0);
const double res = sqrt (count); const double res = sqrt (count);
assert (res >= 1); KISSAT_assert (res >= 1);
return res; return res;
} }
double kissat_nlogpown (uint64_t count, unsigned exponent) { double kissat_nlogpown (uint64_t count, unsigned exponent) {
assert (count > 0); KISSAT_assert (count > 0);
const double tmp = log10 (count + 9); const double tmp = log10 (count + 9);
double factor = 1; double factor = 1;
while (exponent--) while (exponent--)
factor *= tmp; factor *= tmp;
assert (factor >= 1); KISSAT_assert (factor >= 1);
const double res = count * factor; const double res = count * factor;
assert (res >= 1); KISSAT_assert (res >= 1);
return res; return res;
} }
@ -41,10 +43,10 @@ uint64_t kissat_scale_delta (kissat *solver, const char *pretty,
const uint64_t C = BINIRR_CLAUSES; const uint64_t C = BINIRR_CLAUSES;
double f = kissat_logn (C + 1) - 5; double f = kissat_logn (C + 1) - 5;
const double ff = f * f; const double ff = f * f;
assert (ff >= 0); KISSAT_assert (ff >= 0);
const double fff = 4.5 * ff + 25; const double fff = 4.5 * ff + 25;
uint64_t scaled = fff * delta; uint64_t scaled = fff * delta;
assert (delta <= scaled); KISSAT_assert (delta <= scaled);
// clang-format off // clang-format off
kissat_very_verbose (solver, kissat_very_verbose (solver,
"scaled %s delta %" PRIu64 "scaled %s delta %" PRIu64
@ -97,7 +99,7 @@ static void init_enabled (kissat *solver) {
} while (0) } while (0)
void kissat_init_limits (kissat *solver) { void kissat_init_limits (kissat *solver) {
assert (solver->statistics.searches == 1); KISSAT_assert (solver->statistics.searches == 1);
init_enabled (solver); init_enabled (solver);
@ -131,7 +133,7 @@ void kissat_init_limits (kissat *solver) {
INIT_CONFLICT_LIMIT (probe, true); INIT_CONFLICT_LIMIT (probe, true);
} }
#ifndef QUIET #ifndef KISSAT_QUIET
static const char *delay_description (kissat *solver, delay *delay) { static const char *delay_description (kissat *solver, delay *delay) {
delays *delays = &solver->delays; delays *delays = &solver->delays;
@ -142,7 +144,7 @@ static const char *delay_description (kissat *solver, delay *delay) {
else if (delay == &delays->sweep) else if (delay == &delays->sweep)
return "sweeping"; return "sweeping";
else { else {
assert (delay == &delays->vivifyirr); KISSAT_assert (delay == &delays->vivifyirr);
return "vivifying irredundant clauses"; return "vivifying irredundant clauses";
} }
} }
@ -160,7 +162,7 @@ void kissat_reduce_delay (kissat *solver, delay *delay) {
solver, "%s delay interval decreased to %u", solver, "%s delay interval decreased to %u",
delay_description (solver, delay), delay->current); delay_description (solver, delay), delay->current);
delay->count = delay->current; delay->count = delay->current;
#ifdef QUIET #ifdef KISSAT_QUIET
(void) solver; (void) solver;
#endif #endif
} }
@ -171,7 +173,7 @@ void kissat_bump_delay (kissat *solver, delay *delay) {
solver, "%s delay interval increased to %u", solver, "%s delay interval increased to %u",
delay_description (solver, delay), delay->current); delay_description (solver, delay), delay->current);
delay->count = delay->current; delay->count = delay->current;
#ifdef QUIET #ifdef KISSAT_QUIET
(void) solver; (void) solver;
#endif #endif
} }
@ -188,7 +190,9 @@ bool kissat_delaying (kissat *solver, delay *delay) {
delay_description (solver, delay)); delay_description (solver, delay));
return false; return false;
} }
#ifdef QUIET #ifdef KISSAT_QUIET
(void) solver; (void) solver;
#endif #endif
} }
ABC_NAMESPACE_IMPL_END

View File

@ -4,6 +4,9 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "global.h"
ABC_NAMESPACE_HEADER_START
typedef struct bounds bounds; typedef struct bounds bounds;
typedef struct changes changes; typedef struct changes changes;
typedef struct delays delays; typedef struct delays delays;
@ -114,12 +117,12 @@ double kissat_logn (uint64_t);
do { \ do { \
if (solver->inconsistent) \ if (solver->inconsistent) \
break; \ break; \
const struct statistics *statistics = &solver->statistics; \ const struct statistics *statistics = &solver->statistics_; \
assert (statistics->COUNT > 0); \ KISSAT_assert (statistics->COUNT > 0); \
struct limits *limits = &solver->limits; \ struct limits *limits = &solver->limits; \
uint64_t DELTA = GET_OPTION (NAME##int); \ uint64_t DELTA = GET_OPTION (NAME##int); \
const double SCALING = SCALE_COUNT_FUNCTION (statistics->COUNT); \ const double SCALING = SCALE_COUNT_FUNCTION (statistics->COUNT); \
assert (SCALING >= 1); \ KISSAT_assert (SCALING >= 1); \
DELTA *= SCALING; \ DELTA *= SCALING; \
const uint64_t SCALED = \ const uint64_t SCALED = \
!(SCALE_DELTA) ? DELTA \ !(SCALE_DELTA) ? DELTA \
@ -135,8 +138,8 @@ double kissat_logn (uint64_t);
#define SET_EFFORT_LIMIT(LIMIT, NAME, START) \ #define SET_EFFORT_LIMIT(LIMIT, NAME, START) \
uint64_t LIMIT; \ uint64_t LIMIT; \
do { \ do { \
const uint64_t OLD_LIMIT = solver->statistics.START; \ const uint64_t OLD_LIMIT = solver->statistics_.START; \
const uint64_t TICKS = solver->statistics.search_ticks; \ const uint64_t TICKS = solver->statistics_.search_ticks; \
const uint64_t LAST = solver->probing ? solver->last.ticks.probe \ const uint64_t LAST = solver->probing ? solver->last.ticks.probe \
: solver->last.ticks.eliminate; \ : solver->last.ticks.eliminate; \
uint64_t REFERENCE = TICKS - LAST; \ uint64_t REFERENCE = TICKS - LAST; \
@ -182,4 +185,6 @@ void kissat_reduce_delay (struct kissat *, delay *);
#define REDUCE_DELAY(NAME) \ #define REDUCE_DELAY(NAME) \
kissat_reduce_delay (solver, &solver->delays.NAME) kissat_reduce_delay (solver, &solver->delays.NAME)
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -1,6 +1,9 @@
#ifndef _kissat_h_INCLUDED #ifndef _kissat_h_INCLUDED
#define _kissat_h_INCLUDED #define _kissat_h_INCLUDED
#include "global.h"
ABC_NAMESPACE_HEADER_START
typedef struct kissat kissat; typedef struct kissat kissat;
// Default (partial) IPASIR interface. // Default (partial) IPASIR interface.
@ -41,4 +44,9 @@ void kissat_set_decision_limit (kissat *solver, unsigned);
void kissat_print_statistics (kissat *solver); void kissat_print_statistics (kissat *solver);
// Extra API functions.
int kissat_is_inconsistent(kissat *solver);
ABC_NAMESPACE_HEADER_END
#endif #endif

View File

@ -0,0 +1,198 @@
/**CFile****************************************************************
FileName [kissatSolver.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName []
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: kissatSolver.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "kissat.h"
#include "kissatSolver.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [allocate solver]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
kissat_solver* kissat_solver_new(void) {
kissat_solver* s = (kissat_solver*)malloc(sizeof(kissat_solver));
s->p = (void*)kissat_init();
s->nVars = 0;
return s;
}
/**Function*************************************************************
Synopsis [delete solver]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void kissat_solver_delete(kissat_solver* s) {
kissat_release((kissat*)s->p);
free(s);
}
/**Function*************************************************************
Synopsis [add clause]
Description [kissat takes x and -x as a literal for a variable x > 0,
where 0 is an indicator of the end of a clause.
since variables start from 0 in abc, a variable v is
translated into v + 1 in kissat.]
SideEffects []
SeeAlso []
***********************************************************************/
int kissat_solver_addclause(kissat_solver* s, int* begin, int* end) {
for(;begin != end; begin++) {
if(*begin & 1) {
kissat_add((kissat*)s->p, -(1 + ((*begin) >> 1)));
} else {
kissat_add((kissat*)s->p, 1 + ((*begin) >> 1) );
}
}
kissat_add((kissat*)s->p, 0);
return !kissat_is_inconsistent((kissat*)s->p);
}
/**Function*************************************************************
Synopsis [solve with resource limits]
Description [assumptions and inspection limits are not supported.]
SideEffects []
SeeAlso []
***********************************************************************/
int kissat_solver_solve(kissat_solver* s, int* begin, int* end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal) {
// assumptions are not supported
assert(begin == end);
// inspection limits are not supported
assert(nInsLimit == 0);
assert(nInsLimitGlobal == 0);
// set conflict limits
if(nConfLimit)
kissat_set_conflict_limit((kissat*)s->p, nConfLimit);
if(nConfLimitGlobal && (nConfLimit == 0 || nConfLimit > nConfLimitGlobal))
kissat_set_conflict_limit((kissat*)s->p, nConfLimitGlobal);
// solve
int res = kissat_solve((kissat*)s->p);
// translate this kissat return value into a corresponding ABC status value
switch(res) {
case 0: // UNDETERMINED
return 0;
case 10: // SATISFIABLE
return 1;
case 20: // UNSATISFIABLE
return -1;
default:
assert(0);
}
return 0;
}
/**Function*************************************************************
Synopsis [get number of variables]
Description [emulated using "nVars".]
SideEffects []
SeeAlso []
***********************************************************************/
int kissat_solver_nvars(kissat_solver* s) {
return s->nVars;
}
/**Function*************************************************************
Synopsis [add new variable]
Description [emulated using "nVars".]
SideEffects []
SeeAlso []
***********************************************************************/
int kissat_solver_addvar(kissat_solver* s) {
return s->nVars++;
}
/**Function*************************************************************
Synopsis [set number of variables]
Description [not only emulate with "nVars" but also reserve memory.]
SideEffects []
SeeAlso []
***********************************************************************/
void kissat_solver_setnvars(kissat_solver* s,int n) {
s->nVars = n;
kissat_reserve((kissat*)s->p, n);
}
/**Function*************************************************************
Synopsis [get value of variable]
Description [kissat returns x (true) or -x (false) for a variable x.
note a variable v was translated into v + 1 in kissat.]
SideEffects []
SeeAlso []
***********************************************************************/
int kissat_solver_get_var_value(kissat_solver* s, int v) {
return kissat_value((kissat*)s->p, v + 1) > 0;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

View File

@ -0,0 +1,71 @@
/**CFile****************************************************************
FileName [kissatSolver.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName []
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: kissatSolver.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#ifndef ABC_SAT_KISSAT_SOLVER_H_
#define ABC_SAT_KISSAT_SOLVER_H_
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "aig/gia/gia.h"
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// BASIC TYPES ///
////////////////////////////////////////////////////////////////////////
typedef struct kissat_solver_ kissat_solver;
struct kissat_solver_
{
void* p;
int nVars;
};
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
extern kissat_solver* kissat_solver_new(void);
extern void kissat_solver_delete(kissat_solver* s);
extern int kissat_solver_addclause(kissat_solver* s, int* begin, int* end);
extern int kissat_solver_solve(kissat_solver* s, int* begin, int* end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal);
extern int kissat_solver_nvars(kissat_solver* s);
extern int kissat_solver_addvar(kissat_solver* s);
extern void kissat_solver_setnvars(kissat_solver* s,int n);
extern int kissat_solver_get_var_value(kissat_solver* s, int v);
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

133
src/sat/kissat/kissatTest.c Normal file
View File

@ -0,0 +1,133 @@
/**CFile****************************************************************
FileName [kissatTest.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName []
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: kissatTest.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "kissatSolver.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
void kissat_solver_test() {
int RetValue;
int Lits[3];
// test 1
{
kissat_solver *pSat = kissat_solver_new();
int a = kissat_solver_addvar(pSat);
int b = kissat_solver_addvar(pSat);
int c = kissat_solver_addvar(pSat);
assert(kissat_solver_nvars(pSat) == 3);
Lits[0] = Abc_Var2Lit(a, 0);
Lits[1] = Abc_Var2Lit(b, 0);
Lits[2] = Abc_Var2Lit(c, 0);
printf("adding (a, b, c)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 3);
assert(RetValue);
Lits[0] = Abc_Var2Lit(a, 0);
Lits[1] = Abc_Var2Lit(b, 1);
printf("adding (a, !b)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 2);
assert(RetValue);
Lits[0] = Abc_Var2Lit(a, 1);
printf("adding (!a)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 1);
assert(RetValue);
RetValue = kissat_solver_solve(pSat, NULL, NULL, 0, 0, 0, 0);
printf("solved: %d\n", RetValue);
assert(RetValue == 1);
int a_val = kissat_solver_get_var_value(pSat, a);
int b_val = kissat_solver_get_var_value(pSat, b);
int c_val = kissat_solver_get_var_value(pSat, c);
printf("a = %d, b = %d, c = %d\n", a_val, b_val, c_val);
assert(a_val == 0);
assert(b_val == 0);
assert(c_val == 1);
kissat_solver_delete(pSat);
printf("test 1 passed\n");
}
// test 2
{
kissat_solver *pSat = kissat_solver_new();
kissat_solver_setnvars(pSat, 2);
assert(kissat_solver_nvars(pSat) == 2);
Lits[0] = Abc_Var2Lit(0, 0);
Lits[1] = Abc_Var2Lit(1, 0);
printf("adding (x0, x1)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 2);
assert(RetValue);
Lits[0] = Abc_Var2Lit(0, 0);
Lits[1] = Abc_Var2Lit(1, 1);
printf("adding (x0, !x1)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 2);
assert(RetValue);
Lits[0] = Abc_Var2Lit(0, 1);
Lits[1] = Abc_Var2Lit(1, 1);
printf("adding (!x0, !x1)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 2);
assert(RetValue);
RetValue = kissat_solver_solve(pSat, NULL, NULL, 0, 0, 0, 0);
printf("solved: %d\n", RetValue);
assert(RetValue == 1);
printf("x0 = %d, x1 = %d\n", kissat_solver_get_var_value(pSat, 0), kissat_solver_get_var_value(pSat, 1));
assert(kissat_solver_get_var_value(pSat, 0) == 1);
assert(kissat_solver_get_var_value(pSat, 1) == 0);
kissat_solver_delete(pSat);
printf("test 2 passed\n");
}
// test 3
{
kissat_solver *pSat = kissat_solver_new();
kissat_solver_setnvars(pSat, 3);
assert(kissat_solver_nvars(pSat) == 3);
Lits[0] = Abc_Var2Lit(0, 1);
Lits[1] = Abc_Var2Lit(1, 0);
Lits[2] = Abc_Var2Lit(2, 1);
printf("adding (!x0, x1, !x2)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 3);
assert(RetValue);
Lits[0] = Abc_Var2Lit(0, 0);
printf("adding (x0)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 1);
assert(RetValue);
Lits[0] = Abc_Var2Lit(1, 1);
printf("adding (!x1)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 1);
assert(RetValue);
Lits[0] = Abc_Var2Lit(2, 0);
printf("adding (x2)\n");
RetValue = kissat_solver_addclause(pSat, Lits, Lits + 1);
RetValue = kissat_solver_solve(pSat, NULL, NULL, 0, 0, 0, 0);
printf("solved: %d\n", RetValue);
assert(RetValue == -1);
kissat_solver_delete(pSat);
printf("test 3 passed\n");
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END

Some files were not shown because too many files have changed in this diff Show More