From 664d285fcb18cbd7e51ece366b15ae3dc3f8154b Mon Sep 17 00:00:00 2001 From: MyskYko Date: Wed, 5 Mar 2025 04:10:49 -0800 Subject: [PATCH] patch --- Makefile | 2 +- abclib.dsp | 368 +++++++++++ src/base/abci/abc.c | 5 + src/sat/kissat/allocate.c | 14 +- src/sat/kissat/allocate.h | 13 +- src/sat/kissat/analyze.c | 144 ++--- src/sat/kissat/analyze.h | 5 + src/sat/kissat/ands.c | 12 +- src/sat/kissat/ands.h | 5 + src/sat/kissat/application.h | 5 + src/sat/kissat/arena.c | 28 +- src/sat/kissat/arena.h | 11 +- src/sat/kissat/array.h | 9 +- src/sat/kissat/assign.c | 14 +- src/sat/kissat/assign.h | 11 +- src/sat/kissat/attribute.h | 17 +- src/sat/kissat/averages.c | 6 +- src/sat/kissat/averages.h | 7 +- src/sat/kissat/backbone.c | 140 ++--- src/sat/kissat/backbone.h | 5 + src/sat/kissat/backtrack.c | 36 +- src/sat/kissat/backtrack.h | 5 + src/sat/kissat/build.c | 4 + src/sat/kissat/build.h | 10 + src/sat/kissat/bump.c | 12 +- src/sat/kissat/bump.h | 5 + src/sat/kissat/check.c | 72 +-- src/sat/kissat/check.h | 12 +- src/sat/kissat/classify.c | 6 +- src/sat/kissat/classify.h | 5 + src/sat/kissat/clause.c | 24 +- src/sat/kissat/clause.h | 5 + src/sat/kissat/collect.c | 166 ++--- src/sat/kissat/collect.h | 5 + src/sat/kissat/colors.c | 12 +- src/sat/kissat/colors.h | 17 +- src/sat/kissat/compact.c | 98 +-- src/sat/kissat/compact.h | 5 + src/sat/kissat/config.c | 4 +- src/sat/kissat/config.h | 8 +- src/sat/kissat/congruence.c | 774 ++++++++++++------------ src/sat/kissat/congruence.h | 5 + src/sat/kissat/cover.h | 5 + src/sat/kissat/decide.c | 34 +- src/sat/kissat/decide.h | 5 + src/sat/kissat/deduce.c | 60 +- src/sat/kissat/deduce.h | 5 + src/sat/kissat/definition.c | 48 +- src/sat/kissat/definition.h | 5 + src/sat/kissat/dense.c | 42 +- src/sat/kissat/dense.h | 5 + src/sat/kissat/dump.c | 22 +- src/sat/kissat/eliminate.c | 82 +-- src/sat/kissat/eliminate.h | 5 + src/sat/kissat/equivalences.c | 4 + src/sat/kissat/equivalences.h | 5 + src/sat/kissat/error.c | 4 + src/sat/kissat/error.h | 5 + src/sat/kissat/extend.c | 42 +- src/sat/kissat/extend.h | 7 +- src/sat/kissat/factor.c | 210 ++++--- src/sat/kissat/factor.h | 5 + src/sat/kissat/fastassign.h | 13 +- src/sat/kissat/fastel.c | 94 +-- src/sat/kissat/fastel.h | 5 + src/sat/kissat/fifo.h | 19 +- src/sat/kissat/file.c | 34 +- src/sat/kissat/file.h | 35 +- src/sat/kissat/flags.c | 62 +- src/sat/kissat/flags.h | 7 +- src/sat/kissat/format.c | 24 +- src/sat/kissat/format.h | 23 +- src/sat/kissat/forward.c | 114 ++-- src/sat/kissat/forward.h | 5 + src/sat/kissat/frames.h | 7 +- src/sat/kissat/gates.c | 14 +- src/sat/kissat/gates.h | 5 + src/sat/kissat/global.h | 14 + src/sat/kissat/handle.h | 5 + src/sat/kissat/heap.c | 30 +- src/sat/kissat/heap.h | 13 +- src/sat/kissat/ifthenelse.c | 14 +- src/sat/kissat/ifthenelse.h | 5 + src/sat/kissat/import.c | 32 +- src/sat/kissat/import.h | 5 + src/sat/kissat/inline.h | 73 +-- src/sat/kissat/inlineassign.h | 19 +- src/sat/kissat/inlineframes.h | 7 +- src/sat/kissat/inlineheap.h | 21 +- src/sat/kissat/inlinequeue.h | 33 +- src/sat/kissat/inlinevector.h | 57 +- src/sat/kissat/internal.c | 106 ++-- src/sat/kissat/internal.h | 33 +- src/sat/kissat/keatures.h | 5 + src/sat/kissat/kimits.c | 34 +- src/sat/kissat/kimits.h | 15 +- src/sat/kissat/kissat.h | 8 + src/sat/kissat/kissatSolver.c | 198 ++++++ src/sat/kissat/kissatSolver.h | 71 +++ src/sat/kissat/kissatTest.c | 133 ++++ src/sat/kissat/kitten.c | 350 ++++++----- src/sat/kissat/kitten.h | 5 + src/sat/kissat/{options.c => kptions.c} | 36 +- src/sat/kissat/krite.c | 6 +- src/sat/kissat/krite.h | 5 + src/sat/kissat/{lucky.c => kucky.c} | 74 +-- src/sat/kissat/learn.c | 34 +- src/sat/kissat/learn.h | 5 + src/sat/kissat/literal.h | 15 +- src/sat/kissat/logging.c | 16 +- src/sat/kissat/logging.h | 9 +- src/sat/kissat/lucky.h | 5 + src/sat/kissat/minimize.c | 48 +- src/sat/kissat/minimize.h | 5 + src/sat/kissat/mode.c | 46 +- src/sat/kissat/mode.h | 7 +- src/sat/kissat/module.make | 91 +++ src/sat/kissat/options.h | 19 +- src/sat/kissat/parse.h | 5 + src/sat/kissat/phases.c | 18 +- src/sat/kissat/phases.h | 11 +- src/sat/kissat/preprocess.c | 26 +- src/sat/kissat/preprocess.h | 5 + src/sat/kissat/print.c | 8 +- src/sat/kissat/print.h | 9 +- src/sat/kissat/probe.c | 28 +- src/sat/kissat/probe.h | 5 + src/sat/kissat/profile.c | 38 +- src/sat/kissat/profile.h | 9 +- src/sat/kissat/promote.c | 24 +- src/sat/kissat/promote.h | 13 +- src/sat/kissat/proof.c | 96 +-- src/sat/kissat/proof.h | 11 +- src/sat/kissat/propbeyond.c | 14 +- src/sat/kissat/propbeyond.h | 5 + src/sat/kissat/propdense.c | 30 +- src/sat/kissat/propdense.h | 5 + src/sat/kissat/propinitially.c | 16 +- src/sat/kissat/propinitially.h | 5 + src/sat/kissat/proplit.h | 56 +- src/sat/kissat/proprobe.c | 10 +- src/sat/kissat/proprobe.h | 5 + src/sat/kissat/propsearch.c | 12 +- src/sat/kissat/propsearch.h | 5 + src/sat/kissat/queue.c | 18 +- src/sat/kissat/queue.h | 9 +- src/sat/kissat/random.h | 13 +- src/sat/kissat/rank.h | 19 +- src/sat/kissat/reduce.c | 32 +- src/sat/kissat/reduce.h | 5 + src/sat/kissat/reference.h | 5 + src/sat/kissat/reluctant.c | 12 +- src/sat/kissat/reluctant.h | 5 + src/sat/kissat/reorder.c | 35 +- src/sat/kissat/reorder.h | 5 + src/sat/kissat/rephase.c | 16 +- src/sat/kissat/rephase.h | 5 + src/sat/kissat/report.c | 10 +- src/sat/kissat/report.h | 10 +- src/sat/kissat/require.h | 7 +- src/sat/kissat/resize.c | 28 +- src/sat/kissat/resize.h | 5 + src/sat/kissat/resolve.c | 26 +- src/sat/kissat/resolve.h | 5 + src/sat/kissat/resources.c | 20 +- src/sat/kissat/resources.h | 7 +- src/sat/kissat/restart.c | 14 +- src/sat/kissat/restart.h | 5 + src/sat/kissat/search.c | 20 +- src/sat/kissat/search.h | 5 + src/sat/kissat/shrink.c | 68 ++- src/sat/kissat/shrink.h | 5 + src/sat/kissat/smooth.c | 12 +- src/sat/kissat/smooth.h | 5 + src/sat/kissat/sort.c | 18 +- src/sat/kissat/sort.h | 19 +- src/sat/kissat/stack.c | 26 +- src/sat/kissat/stack.h | 23 +- src/sat/kissat/statistics.c | 20 +- src/sat/kissat/statistics.h | 39 +- src/sat/kissat/strengthen.c | 70 ++- src/sat/kissat/strengthen.h | 5 + src/sat/kissat/substitute.c | 82 +-- src/sat/kissat/substitute.h | 5 + src/sat/kissat/sweep.c | 264 ++++---- src/sat/kissat/sweep.h | 5 + src/sat/kissat/terminate.c | 6 +- src/sat/kissat/terminate.h | 13 +- src/sat/kissat/tiers.c | 16 +- src/sat/kissat/tiers.h | 5 + src/sat/kissat/trail.c | 38 +- src/sat/kissat/trail.h | 5 + src/sat/kissat/transitive.c | 78 +-- src/sat/kissat/transitive.h | 5 + src/sat/kissat/utilities.c | 4 + src/sat/kissat/utilities.h | 40 +- src/sat/kissat/value.h | 9 +- src/sat/kissat/vector.c | 78 +-- src/sat/kissat/vector.h | 9 +- src/sat/kissat/vivify.c | 283 ++++----- src/sat/kissat/vivify.h | 5 + src/sat/kissat/walk.c | 202 ++++--- src/sat/kissat/walk.h | 5 + src/sat/kissat/warmup.c | 22 +- src/sat/kissat/warmup.h | 5 + src/sat/kissat/watch.c | 56 +- src/sat/kissat/watch.h | 21 +- src/sat/kissat/weaken.c | 12 +- src/sat/kissat/weaken.h | 5 + src/sat/kissat/witness.h | 5 + 210 files changed, 4590 insertions(+), 2692 deletions(-) create mode 100644 src/sat/kissat/build.h create mode 100644 src/sat/kissat/global.h create mode 100644 src/sat/kissat/kissatSolver.c create mode 100644 src/sat/kissat/kissatSolver.h create mode 100644 src/sat/kissat/kissatTest.c rename src/sat/kissat/{options.c => kptions.c} (94%) rename src/sat/kissat/{lucky.c => kucky.c} (89%) create mode 100644 src/sat/kissat/module.make diff --git a/Makefile b/Makefile index 9b4838ce8..2da81734b 100644 --- a/Makefile +++ b/Makefile @@ -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/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/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/rsb src/bool/rpo \ src/proof/pdr src/proof/abs src/proof/live src/proof/ssc src/proof/int \ diff --git a/abclib.dsp b/abclib.dsp index 358a966a7..7f6af6f81 100644 --- a/abclib.dsp +++ b/abclib.dsp @@ -2518,6 +2518,374 @@ SOURCE=.\src\sat\glucose2\Vec.h SOURCE=.\src\sat\glucose2\XAlloc.h # End Source File # 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 # Begin Group "opt" diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index ac178258f..e036283f0 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -56001,6 +56001,11 @@ int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv ) goto usage; } } + + extern void kissat_solver_test(); + kissat_solver_test(); + return 0; + if ( pAbc->pGia == NULL ) { Abc_Print( -1, "Abc_CommandAbc9Test(): There is no AIG.\n" ); diff --git a/src/sat/kissat/allocate.c b/src/sat/kissat/allocate.c index 68bb68a88..61f8c202f 100644 --- a/src/sat/kissat/allocate.c +++ b/src/sat/kissat/allocate.c @@ -12,6 +12,8 @@ #include #endif +ABC_NAMESPACE_IMPL_START + static void inc_bytes (kissat *solver, size_t bytes) { #ifdef METRICS if (!solver) @@ -62,16 +64,16 @@ void kissat_free (kissat *solver, void *ptr, size_t bytes) { dec_bytes (solver, bytes); free (ptr); } else - assert (!bytes); + KISSAT_assert (!bytes); } 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); } void kissat_freestr (struct kissat *solver, char *str) { - assert (str); + KISSAT_assert (str); 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, size_t size) { if (!size) { - assert (!p); - assert (!o); + KISSAT_assert (!p); + KISSAT_assert (!o); return 0; } 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); return kissat_realloc (solver, p, o * size, n * size); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/allocate.h b/src/sat/kissat/allocate.h index db24fd5f8..bdac75bd2 100644 --- a/src/sat/kissat/allocate.h +++ b/src/sat/kissat/allocate.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; 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_nrealloc (struct kissat *, void *, size_t o, size_t n, size_t); -#define NALLOC(P, N) \ +#define NALLOC(T, P, N) \ do { \ - (P) = kissat_nalloc (solver, (N), sizeof *(P)); \ + (P) = (T*) kissat_nalloc (solver, (N), sizeof *(P)); \ } while (0) -#define CALLOC(P, N) \ +#define CALLOC(T, P, N) \ do { \ - (P) = kissat_calloc (solver, (N), sizeof *(P)); \ + (P) = (T*) kissat_calloc (solver, (N), sizeof *(P)); \ } while (0) #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)); \ } while (0) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/analyze.c b/src/sat/kissat/analyze.c index d21b0a74b..70a68ae0e 100644 --- a/src/sat/kissat/analyze.c +++ b/src/sat/kissat/analyze.c @@ -13,10 +13,12 @@ #include +ABC_NAMESPACE_IMPL_START + static bool one_literal_on_conflict_level (kissat *solver, clause *conflict, unsigned *conflict_level_ptr) { - assert (conflict); - assert (conflict->size > 1); + KISSAT_assert (conflict); + KISSAT_assert (conflict->size > 1); unsigned jump_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++) { const unsigned lit = *p; - assert (VALUE (lit) < 0); + KISSAT_assert (VALUE (lit) < 0); const unsigned idx = IDX (lit); const unsigned lit_level = all_assigned[idx].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) break; } - assert (conflict_level != INVALID_LEVEL); - assert (literals_on_conflict_level); + KISSAT_assert (conflict_level != INVALID_LEVEL); + KISSAT_assert (literals_on_conflict_level); LOG ("found %u literals on conflict level %u", literals_on_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) return false; - assert (literals_on_conflict_level == 1); - assert (forced_lit != INVALID_LIT); - assert (jump_level != INVALID_LEVEL); - assert (jump_level < conflict_level); + KISSAT_assert (literals_on_conflict_level == 1); + KISSAT_assert (forced_lit != INVALID_LIT); + KISSAT_assert (jump_level != INVALID_LEVEL); + KISSAT_assert (jump_level < conflict_level); 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); if (conflict_size == 2) { - assert (conflict == &solver->conflict); + KISSAT_assert (conflict == &solver->conflict); const unsigned other = lits[0] ^ lits[1] ^ forced_lit; kissat_assign_binary (solver, forced_lit, other); } else { @@ -142,9 +144,9 @@ static inline void analyze_reason_side_literal (kissat *solver, unsigned lit) { const unsigned idx = IDX (lit); const assigned *a = all_assigned + idx; - assert (a->level); - assert (a->analyzed); - assert (a->reason != UNIT_REASON); + KISSAT_assert (a->level); + KISSAT_assert (a->analyzed); + KISSAT_assert (a->reason != UNIT_REASON); if (a->reason == DECISION_REASON) return; if (a->binary) { @@ -152,13 +154,13 @@ static inline void analyze_reason_side_literal (kissat *solver, mark_reason_side_literal (solver, all_assigned, other); } else { const reference ref = a->reason; - assert (ref < SIZE_STACK (solver->arena)); + KISSAT_assert (ref < SIZE_STACK (solver->arena)); clause *c = (clause *) (arena + ref); const unsigned not_lit = NOT (lit); INC (search_ticks); for (all_literals_in_clause (other, c)) if (other != not_lit) { - assert (other != lit); + KISSAT_assert (other != lit); mark_reason_side_literal (solver, all_assigned, other); if (SIZE_STACK (solver->analyzed) > limit) break; @@ -183,9 +185,9 @@ static void analyze_reason_side_literals (kissat *solver) { return; } assigned *all_assigned = solver->assigned; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG for (all_stack (unsigned, lit, solver->clause)) - assert (all_assigned[IDX (lit)].analyzed); + KISSAT_assert (all_assigned[IDX (lit)].analyzed); #endif LOG ("trying to bump reason side literals too"); 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); struct assigned *a = all_assigned + idx; LOG ("marking %s as not analyzed", LOGVAR (idx)); - assert (a->analyzed); + KISSAT_assert (a->analyzed); a->analyzed = false; } BUMP_DELAY (bumpreasons); @@ -228,7 +230,7 @@ static void sort_levels (kissat *solver) { static void sort_deduced_clause (kissat *solver) { sort_levels (solver); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG const size_t size_frames = SIZE_STACK (solver->frames); #endif frame *frames = BEGIN_STACK (solver->frames); @@ -238,25 +240,25 @@ static void sort_deduced_clause (kissat *solver) { unsigned const *p = end_levels; while (p != begin_levels) { const unsigned level = *--p; - assert (level < size_frames); + KISSAT_assert (level < size_frames); frame *f = frames + level; const unsigned used = f->used; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG f->saved = used; #endif - assert (used > 0); - assert (UINT_MAX - used >= pos); + KISSAT_assert (used > 0); + KISSAT_assert (UINT_MAX - used >= pos); f->used = pos; pos += used; } unsigneds *clause = &solver->clause; const size_t size_clause = SIZE_STACK (*clause); -#ifndef NDEBUG - assert (pos == size_clause); +#ifndef KISSAT_NDEBUG + KISSAT_assert (pos == size_clause); #endif unsigned const *begin_clause = BEGIN_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; while (SIZE_STACK (*shadow) < size_clause) @@ -272,37 +274,37 @@ static void sort_deduced_clause (kissat *solver) { const unsigned idx = IDX (lit); const struct assigned *a = assigned + idx; const unsigned level = a->level; - assert (level < size_frames); + KISSAT_assert (level < size_frames); frame *f = frames + level; const unsigned pos = f->used++; POKE_STACK (*shadow, pos, lit); } - assert (size_clause == SIZE_STACK (*shadow)); + KISSAT_assert (size_clause == SIZE_STACK (*shadow)); SWAP (unsigneds, *clause, *shadow); pos = 1; p = end_levels; while (p != begin_levels) { const unsigned level = *--p; - assert (level < size_frames); + KISSAT_assert (level < size_frames); frame *f = frames + level; const unsigned end = f->used; - assert (pos < end); + KISSAT_assert (pos < end); f->used = end - pos; - assert (f->used == f->saved); + KISSAT_assert (f->used == f->saved); pos = end; } CLEAR_STACK (*shadow); LOGTMP ("level sorted deduced"); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG unsigned prev_level = solver->level; for (all_stack (unsigned, lit, solver->clause)) { const unsigned idx = IDX (lit); const unsigned lit_level = assigned[idx].level; - assert (prev_level >= lit_level); + KISSAT_assert (prev_level >= lit_level); prev_level = lit_level; } #endif @@ -311,13 +313,13 @@ static void sort_deduced_clause (kissat *solver) { static void reset_levels (kissat *solver) { LOG ("reset %zu marked levels", SIZE_STACK (solver->levels)); frame *frames = BEGIN_STACK (solver->frames); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG const size_t size_frames = SIZE_STACK (solver->frames); #endif for (all_stack (unsigned, level, solver->levels)) { - assert (level < size_frames); + KISSAT_assert (level < size_frames); frame *f = frames + level; - assert (f->used > 0); + KISSAT_assert (f->used > 0); f->used = 0; } 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)); assigned *assigned = solver->assigned; for (all_stack (unsigned, idx, solver->analyzed)) { - assert (idx < VARS); + KISSAT_assert (idx < VARS); struct assigned *a = assigned + idx; - assert (!a->poisoned); - assert (!a->removable); - assert (!a->shrinkable); + KISSAT_assert (!a->poisoned); + KISSAT_assert (!a->removable); + KISSAT_assert (!a->shrinkable); a->analyzed = false; } CLEAR_STACK (solver->analyzed); @@ -340,13 +342,13 @@ void kissat_reset_only_analyzed_literals (kissat *solver) { static void reset_removable (kissat *solver) { LOG ("reset %zu removable variables", SIZE_STACK (solver->removable)); assigned *assigned = solver->assigned; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG unsigned not_removable = 0; #endif for (all_stack (unsigned, idx, solver->removable)) { - assert (idx < VARS); + KISSAT_assert (idx < VARS); struct assigned *a = assigned + idx; - assert (a->removable || !not_removable++); + KISSAT_assert (a->removable || !not_removable++); a->removable = false; } 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) { - assert (!solver->probing); -#if defined(LOGGING) || !defined(QUIET) + KISSAT_assert (!solver->probing); +#if defined(LOGGING) || !defined(KISSAT_QUIET) const unsigned size = SIZE_ARRAY (solver->trail); const unsigned assigned = size - solver->unflushed; const unsigned active = solver->active; @@ -371,36 +373,36 @@ static void update_trail_average (kissat *solver) { #endif LOG ("trail filled %.0f%% (size %u, unflushed %u, active %u)", filled, size, solver->unflushed, active); -#ifndef QUIET +#ifndef KISSAT_QUIET UPDATE_AVERAGE (trail, filled); #endif } static void update_decision_rate_average (kissat *solver) { - assert (!solver->probing); + KISSAT_assert (!solver->probing); const uint64_t current = DECISIONS; const uint64_t previous = solver->averages[solver->stable].saved_decisions; - assert (previous <= current); + KISSAT_assert (previous <= current); const uint64_t decisions = current - previous; solver->averages[solver->stable].saved_decisions = current; UPDATE_AVERAGE (decision_rate, decisions); } static void analyze_failed_literal (kissat *solver, clause *conflict) { - assert (solver->level == 1); + KISSAT_assert (solver->level == 1); const unsigned failed = FRAME (1).decision; LOGCLS (conflict, "analyzing failed literal %s conflict", LOGLIT (failed)); unsigneds *units = &solver->clause; - assert (EMPTY_STACK (*units)); - assert (EMPTY_STACK (solver->analyzed)); + KISSAT_assert (EMPTY_STACK (*units)); + KISSAT_assert (EMPTY_STACK (solver->analyzed)); const unsigned not_failed = NOT (failed); assigned *all_assigned = solver->assigned; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG const value *const values = solver->values; #endif unsigned const *t = END_ARRAY (solver->trail); @@ -408,18 +410,18 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) { unsigned unit = INVALID_LIT; for (all_literals_in_clause (lit, conflict)) { - assert (lit != failed); + KISSAT_assert (lit != failed); if (lit == not_failed) { LOG ("negation %s of failed literal %s occurs in conflict", LOGLIT (not_failed), LOGLIT (failed)); goto DONE; } - assert (values[lit] < 0); + KISSAT_assert (values[lit] < 0); const unsigned idx = IDX (lit); assigned *a = all_assigned + idx; if (!a->level) continue; - assert (a->level == 1); + KISSAT_assert (a->level == 1); LOG ("analyzing conflict literal %s", LOGLIT (lit)); kissat_push_analyzed (solver, all_assigned, idx); unresolved++; @@ -429,9 +431,9 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) { unsigned lit; assigned *a; do { - assert (t > BEGIN_ARRAY (solver->trail)); + KISSAT_assert (t > BEGIN_ARRAY (solver->trail)); lit = *--t; - assert (values[lit] > 0); + KISSAT_assert (values[lit] > 0); const unsigned idx = IDX (lit); a = all_assigned + idx; } while (!a->analyzed); @@ -443,9 +445,9 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) { if (a->binary) { const unsigned other = a->reason; LOGBINARY (lit, other, "resolving %s reason", LOGLIT (lit)); - assert (other != failed); - assert (other != unit); - assert (values[other] < 0); + KISSAT_assert (other != failed); + KISSAT_assert (other != unit); + KISSAT_assert (values[other] < 0); if (other == not_failed) { LOG ("negation %s of failed literal %s in reason", LOGLIT (not_failed), LOGLIT (failed)); @@ -453,21 +455,21 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) { } const unsigned idx = IDX (other); assigned *b = all_assigned + idx; - assert (b->level == 1); + KISSAT_assert (b->level == 1); if (!b->analyzed) { LOG ("analyzing reason literal %s", LOGLIT (other)); kissat_push_analyzed (solver, all_assigned, idx); unresolved++; } } else { - assert (a->reason != UNIT_REASON); - assert (a->reason != DECISION_REASON); + KISSAT_assert (a->reason != UNIT_REASON); + KISSAT_assert (a->reason != DECISION_REASON); const reference ref = a->reason; LOGREF (ref, "resolving %s reason", LOGLIT (lit)); clause *reason = kissat_dereference_clause (solver, ref); for (all_literals_in_clause (other, reason)) { - assert (other != NOT (lit)); - assert (other != failed); + KISSAT_assert (other != NOT (lit)); + KISSAT_assert (other != failed); if (other == lit) continue; if (other == unit) @@ -477,12 +479,12 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) { LOGLIT (not_failed), LOGLIT (failed)); goto DONE; } - assert (values[other] < 0); + KISSAT_assert (values[other] < 0); const unsigned idx = IDX (other); assigned *b = all_assigned + idx; if (!b->level) continue; - assert (b->level == 1); + KISSAT_assert (b->level == 1); if (b->analyzed) continue; LOG ("analyzing reason literal %s", LOGLIT (other)); @@ -490,7 +492,7 @@ static void analyze_failed_literal (kissat *solver, clause *conflict) { unresolved++; } } - assert (unresolved > 0); + KISSAT_assert (unresolved > 0); unresolved--; LOG ("after resolving %s there are %u unresolved literals", LOGLIT (lit), unresolved); @@ -526,7 +528,7 @@ static void update_tier_limits (kissat *solver) { int kissat_analyze (kissat *solver, clause *conflict) { if (solver->inconsistent) { - assert (!solver->level); + KISSAT_assert (!solver->level); return 20; } @@ -534,7 +536,7 @@ int kissat_analyze (kissat *solver, clause *conflict) { if (!solver->probing) { update_trail_average (solver); update_decision_rate_average (solver); -#ifndef QUIET +#ifndef KISSAT_QUIET UPDATE_AVERAGE (level, solver->level); #endif } @@ -577,3 +579,5 @@ int kissat_analyze (kissat *solver, clause *conflict) { STOP (analyze); return res > 0 ? 0 : 20; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/analyze.h b/src/sat/kissat/analyze.h index be4393c76..ec0b2af4e 100644 --- a/src/sat/kissat/analyze.h +++ b/src/sat/kissat/analyze.h @@ -3,10 +3,15 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct clause; struct kissat; int kissat_analyze (struct kissat *, struct clause *); void kissat_reset_only_analyzed_literals (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/ands.c b/src/sat/kissat/ands.c index 51bff792a..bd53b9489 100644 --- a/src/sat/kissat/ands.c +++ b/src/sat/kissat/ands.c @@ -3,6 +3,8 @@ #include "gates.h" #include "inline.h" +ABC_NAMESPACE_IMPL_START + bool kissat_find_and_gate (kissat *solver, unsigned lit, unsigned negative) { if (!GET_OPTION (ands)) @@ -27,9 +29,9 @@ bool kissat_find_and_gate (kissat *solver, unsigned lit, if (watch.type.binary) continue; const reference ref = watch.large.ref; - assert (ref < SIZE_STACK (solver->arena)); + KISSAT_assert (ref < SIZE_STACK (solver->arena)); clause *c = (clause *) (arena + ref); - assert (!c->garbage); + KISSAT_assert (!c->garbage); base = c; for (all_literals_in_clause (other, c)) { if (other == not_lit) @@ -63,7 +65,7 @@ bool kissat_find_and_gate (kissat *solver, unsigned lit, if (values[other]) continue; const unsigned not_other = NOT (other); - assert (marks[not_other]); + KISSAT_assert (marks[not_other]); marks[not_other] = 0; } watch tmp = kissat_binary_watch (0); @@ -72,7 +74,7 @@ bool kissat_find_and_gate (kissat *solver, unsigned lit, if (!watch.type.binary) continue; const unsigned other = watch.binary.lit; - assert (!solver->values[other]); + KISSAT_assert (!solver->values[other]); if (marks[other]) { marks[other] = 0; continue; @@ -86,3 +88,5 @@ bool kissat_find_and_gate (kissat *solver, unsigned lit, INC (ands_extracted); return true; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/ands.h b/src/sat/kissat/ands.h index 606c41d6e..4780d1138 100644 --- a/src/sat/kissat/ands.h +++ b/src/sat/kissat/ands.h @@ -3,9 +3,14 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_find_and_gate (struct kissat *, unsigned lit, unsigned negative); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/application.h b/src/sat/kissat/application.h index f4a5b12f7..25c23f178 100644 --- a/src/sat/kissat/application.h +++ b/src/sat/kissat/application.h @@ -1,8 +1,13 @@ #ifndef _application_h_INCLUDED #define _application_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; int kissat_application (struct kissat *, int argc, char **argv); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/arena.c b/src/sat/kissat/arena.c index 7296d2605..2ee25018f 100644 --- a/src/sat/kissat/arena.c +++ b/src/sat/kissat/arena.c @@ -3,9 +3,11 @@ #include "logging.h" #include "print.h" +ABC_NAMESPACE_IMPL_START + static void report_resized (kissat *solver, const char *mode, arena before) { -#ifndef QUIET +#ifndef KISSAT_QUIET ward *const old_begin = BEGIN_STACK (before); ward *const new_begin = BEGIN_STACK (solver->arena); 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) { - assert (size <= UINT_MAX); + KISSAT_assert (size <= UINT_MAX); 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); - assert (kissat_aligned_word (bytes)); + KISSAT_assert (kissat_aligned_word (bytes)); const size_t needed = bytes / sizeof (ward); - assert (needed <= UINT_MAX); + KISSAT_assert (needed <= UINT_MAX); size_t capacity = CAPACITY_STACK (solver->arena); - assert (kissat_is_power_of_two (MAX_ARENA)); - assert (capacity <= MAX_ARENA); + KISSAT_assert (kissat_is_power_of_two (MAX_ARENA)); + KISSAT_assert (capacity <= MAX_ARENA); size_t available = capacity - res; if (needed > available) { const arena before = solver->arena; do { - assert (kissat_is_zero_or_power_of_two (capacity)); + KISSAT_assert (kissat_is_zero_or_power_of_two (capacity)); if (capacity == MAX_ARENA) kissat_fatal ("maximum arena capacity " "of 2^%u %zu-byte-words %s exhausted" -#ifdef COMPACT +#ifdef KISSAT_COMPACT " (consider a configuration without '--compact')" #endif , @@ -55,7 +57,7 @@ reference kissat_allocate_clause (kissat *solver, size_t size) { INC (arena_resized); INC (arena_enlarged); report_resized (solver, "enlarged", before); - assert (capacity <= MAX_ARENA); + KISSAT_assert (capacity <= MAX_ARENA); } solver->arena.end += needed; 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 size_t capacity = CAPACITY_STACK (before); const size_t size = SIZE_STACK (before); -#ifndef QUIET +#ifndef KISSAT_QUIET const size_t capacity_bytes = capacity * sizeof (ward); kissat_phase (solver, "arena", GET (arena_resized), "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); } -#if !defined(NDEBUG) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || defined(LOGGING) bool kissat_clause_in_arena (const kissat *solver, const clause *c) { if (!kissat_aligned_pointer (c)) @@ -106,3 +108,5 @@ bool kissat_clause_in_arena (const kissat *solver, const clause *c) { } #endif + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/arena.h b/src/sat/kissat/arena.h index da83c7e39..8e1750ce7 100644 --- a/src/sat/kissat/arena.h +++ b/src/sat/kissat/arena.h @@ -5,7 +5,10 @@ #include "stack.h" #include "utilities.h" -#ifdef COMPACT +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#ifdef KISSAT_COMPACT typedef word ward; #else typedef w2rd ward; @@ -29,18 +32,20 @@ struct kissat; reference kissat_allocate_clause (struct kissat *, size_t size); 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 *); #endif static inline word kissat_align_ward (word w) { -#ifdef COMPACT +#ifdef KISSAT_COMPACT return kissat_align_word (w); #else return kissat_align_w2rd (w); #endif } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/array.h b/src/sat/kissat/array.h index 3ae23f90b..a3a71d202 100644 --- a/src/sat/kissat/array.h +++ b/src/sat/kissat/array.h @@ -4,6 +4,9 @@ #include "allocate.h" #include "stack.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define ARRAY(TYPE) \ struct { \ TYPE *begin; \ @@ -25,11 +28,11 @@ *(A).end++ = (E); \ } while (0) -#define REALLOCATE_ARRAY(A, O, N) \ +#define REALLOCATE_ARRAY(T, A, O, N) \ do { \ const size_t SIZE = SIZE_ARRAY (A); \ (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; \ } while (0) @@ -55,4 +58,6 @@ typedef ARRAY (unsigned) unsigned_array; // clang-format on +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/assign.c b/src/sat/kissat/assign.c index 6a34f3529..c2fb61b4b 100644 --- a/src/sat/kissat/assign.c +++ b/src/sat/kissat/assign.c @@ -5,6 +5,8 @@ #include +ABC_NAMESPACE_IMPL_START + void kissat_assign_unit (kissat *solver, unsigned lit, const char *reason) { kissat_assign (solver, solver->probing, 0, false, lit, UNIT_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) { - assert (VALUE (other) < 0); + KISSAT_assert (VALUE (other) < 0); assigned *assigned = solver->assigned; const unsigned other_idx = IDX (other); 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, clause *reason) { - assert (reason == kissat_dereference_clause (solver, ref)); + KISSAT_assert (reason == kissat_dereference_clause (solver, ref)); assigned *assigned = solver->assigned; value *values = solver->values; const unsigned level = kissat_assignment_level (solver, values, assigned, lit, reason); - assert (level <= solver->level); - assert (ref != DECISION_REASON); - assert (ref != UNIT_REASON); + KISSAT_assert (level <= solver->level); + KISSAT_assert (ref != DECISION_REASON); + KISSAT_assert (ref != UNIT_REASON); kissat_assign (solver, solver->probing, level, false, lit, ref); LOGREF (ref, "assign %s reason", LOGLIT (lit)); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/assign.h b/src/sat/kissat/assign.h index 64ac2027d..d063d17f6 100644 --- a/src/sat/kissat/assign.h +++ b/src/sat/kissat/assign.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define DECISION_REASON UINT_MAX #define UNIT_REASON (DECISION_REASON - 1) @@ -26,7 +29,7 @@ struct assigned { }; #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 TRAIL(LIT) (ASSIGNED (LIT)->trail) @@ -34,8 +37,12 @@ struct assigned { #ifndef FAST_ASSIGN +ABC_NAMESPACE_HEADER_END + #include "reference.h" +ABC_NAMESPACE_HEADER_START + struct kissat; struct clause; @@ -52,4 +59,6 @@ void kissat_assign_reference (struct kissat *, unsigned lit, reference, #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/attribute.h b/src/sat/kissat/attribute.h index 9ec5f40ab..4e43ac83f 100644 --- a/src/sat/kissat/attribute.h +++ b/src/sat/kissat/attribute.h @@ -1,10 +1,19 @@ #ifndef _attribute_h_INCLUDED #define _attribute_h_INCLUDED -#define ATTRIBUTE_FORMAT(FORMAT_POSITION, VARIADIC_ARGUMENT_POSITION) \ - __attribute__ (( \ - format (printf, FORMAT_POSITION, VARIADIC_ARGUMENT_POSITION))) +#include "global.h" +ABC_NAMESPACE_HEADER_START -#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 diff --git a/src/sat/kissat/averages.c b/src/sat/kissat/averages.c index 03c96a73f..c59a6c2ed 100644 --- a/src/sat/kissat/averages.c +++ b/src/sat/kissat/averages.c @@ -1,11 +1,13 @@ #include "internal.h" +ABC_NAMESPACE_IMPL_START + void kissat_init_averages (kissat *solver, averages *averages) { if (averages->initialized) return; #define INIT_EMA(EMA, WINDOW) \ kissat_init_smooth (solver, &averages->EMA, WINDOW, #EMA) -#ifndef QUIET +#ifndef KISSAT_QUIET INIT_EMA (level, GET_OPTION (emaslow)); INIT_EMA (size, 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)); averages->initialized = true; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/averages.h b/src/sat/kissat/averages.h index d8cd03045..b793e0b69 100644 --- a/src/sat/kissat/averages.h +++ b/src/sat/kissat/averages.h @@ -5,12 +5,15 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct averages averages; struct averages { bool initialized; smooth fast_glue, slow_glue; -#ifndef QUIET +#ifndef KISSAT_QUIET smooth level, size, trail; #endif smooth decision_rate; @@ -30,4 +33,6 @@ void kissat_init_averages (struct kissat *, averages *); #define UPDATE_AVERAGE(NAME, VALUE) \ kissat_update_smooth (solver, &EMA (NAME), VALUE) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/backbone.c b/src/sat/kissat/backbone.c index 6a774efce..6db42d77a 100644 --- a/src/sat/kissat/backbone.c +++ b/src/sat/kissat/backbone.c @@ -13,6 +13,8 @@ #include "trail.h" #include "utilities.h" +ABC_NAMESPACE_IMPL_START + static void schedule_backbone_candidates (kissat *solver, unsigneds *candidates) { flags *flags = solver->flags; @@ -34,7 +36,7 @@ static void schedule_backbone_candidates (kissat *solver, } else not_rescheduled++; } -#ifndef QUIET +#ifndef KISSAT_QUIET const size_t rescheduled = SIZE_STACK (*candidates); const unsigned active_literals = 2u * solver->active; 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); kissat_very_verbose (solver, "scheduled %zu backbone candidate literals %.0f%%" @@ -83,21 +85,21 @@ static void keep_backbone_candidates (kissat *solver, else prioritized += f->backbone0; } - assert (prioritized <= remain); + KISSAT_assert (prioritized <= remain); if (!remain) { kissat_very_verbose (solver, "no backbone candidates remain"); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG for (all_variables (idx)) { const struct flags *f = flags + idx; if (!f->active) continue; - assert (!f->backbone0); - assert (!f->backbone1); + KISSAT_assert (!f->backbone0); + KISSAT_assert (!f->backbone1); } #endif return; } -#ifndef QUIET +#ifndef KISSAT_QUIET const size_t active_literals = 2u * solver->active; #endif if (prioritized == remain) @@ -112,10 +114,10 @@ static void keep_backbone_candidates (kissat *solver, if (!f->active) continue; if (NEGATED (lit)) { - assert (!f->backbone1); + KISSAT_assert (!f->backbone1); f->backbone1 = true; } else { - assert (!f->backbone0); + KISSAT_assert (!f->backbone0); f->backbone0 = true; } } @@ -137,8 +139,8 @@ static inline void backbone_assign (kissat *solver, unsigned_array *trail, value *values, assigned *assigned, unsigned lit, unsigned reason) { const unsigned not_lit = NOT (lit); - assert (!values[lit]); - assert (!values[not_lit]); + KISSAT_assert (!values[lit]); + KISSAT_assert (!values[not_lit]); values[lit] = 1; values[not_lit] = -1; PUSH_ARRAY (*trail, lit); @@ -154,13 +156,13 @@ backbone_propagate_literal (kissat *solver, const bool stop_early, unsigned_array *trail, value *values, assigned *assigned, unsigned lit) { LOG ("backbone propagating %s", LOGLIT (lit)); - assert (VALID_INTERNAL_LITERAL (lit)); - assert (values[lit] > 0); + KISSAT_assert (VALID_INTERNAL_LITERAL (lit)); + KISSAT_assert (values[lit] > 0); 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 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++; if (watch.type.binary) { const unsigned other = watch.binary.lit; - assert (VALID_INTERNAL_LITERAL (other)); + KISSAT_assert (VALID_INTERNAL_LITERAL (other)); const value value = values[other]; if (value > 0) continue; if (value < 0) return kissat_binary_conflict (solver, not_lit, other); - assert (!value); + KISSAT_assert (!value); backbone_assign (solver, trail, values, assigned, other, lit); LOG ("backbone assign %s reason binary clause %s %s", LOGLIT (other), LOGLIT (other), LOGLIT (not_lit)); } else { if (stop_early) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG for (const union watch *q = p + 1; q != end_watches; q++) { const union watch watch = *q++; - assert (!watch.type.binary); + KISSAT_assert (!watch.type.binary); } #endif break; @@ -219,7 +221,7 @@ static inline clause *backbone_propagate (kissat *solver, conflict = backbone_propagate_literal ( solver, stop_early, watches, trail, values, assigned, *propagate++); - assert (solver->propagate <= propagate); + KISSAT_assert (solver->propagate <= propagate); const unsigned propagated = propagate - solver->propagate; solver->propagate = propagate; @@ -240,17 +242,17 @@ static inline void backbone_backtrack (kissat *solver, unsigned_array *trail, value *values, unsigned *saved, unsigned decision_level) { - assert (decision_level <= solver->level); + KISSAT_assert (decision_level <= solver->level); 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", (size_t) (saved - BEGIN_ARRAY (*trail)), decision_level); while (saved != end_trail) { const unsigned lit = *--end_trail; const unsigned not_lit = NOT (lit); LOG ("backbone unassign %s", LOGLIT (lit)); - assert (values[lit] > 0); - assert (values[not_lit] < 0); + KISSAT_assert (values[lit] > 0); + KISSAT_assert (values[not_lit] < 0); values[lit] = values[not_lit] = 0; } 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) { - assert (conflict); + KISSAT_assert (conflict); LOGCLS (conflict, "backbone analyzing"); - assert (conflict->size == 2); + KISSAT_assert (conflict->size == 2); assigned *const assigned = solver->assigned; @@ -271,7 +273,7 @@ static unsigned backbone_analyze (kissat *solver, clause *conflict) { const unsigned *t = END_ARRAY (solver->trail); for (;;) { - assert (t > BEGIN_ARRAY (solver->trail)); + KISSAT_assert (t > BEGIN_ARRAY (solver->trail)); unsigned lit = *--t; @@ -282,8 +284,8 @@ static unsigned backbone_analyze (kissat *solver, clause *conflict) { LOG ("backbone analyzing %s", LOGLIT (lit)); const unsigned reason = a->reason; - assert (reason != UNIT_REASON); - assert (reason != DECISION_REASON); + KISSAT_assert (reason != UNIT_REASON); + KISSAT_assert (reason != DECISION_REASON); const unsigned reason_idx = IDX (reason); const struct assigned *b = assigned + reason_idx; if (!b->analyzed) { @@ -298,7 +300,7 @@ static unsigned backbone_analyze (kissat *solver, clause *conflict) { } } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG static void 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; for (all_binary_blocking_watches (watch, WATCHES (lit))) if (watch.type.binary) - assert (!large); + KISSAT_assert (!large); else large = true; } @@ -315,7 +317,7 @@ check_large_clauses_watched_after_binary_clauses (kissat *solver) { #endif static unsigned compute_backbone (kissat *solver) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG if (solver->large_clauses_watched_after_binary_clauses) check_large_clauses_watched_after_binary_clauses (solver); #endif @@ -325,26 +327,26 @@ static unsigned compute_backbone (kissat *solver) { INIT_STACK (candidates); INIT_STACK (units); schedule_backbone_candidates (solver, &candidates); -#ifndef QUIET +#ifndef KISSAT_QUIET const size_t scheduled = SIZE_STACK (candidates); #endif -#if defined(METRICS) && (!defined(QUIET) || !defined(NDEBUG)) - const uint64_t implied_before = solver->statistics.backbone_implied; +#if defined(METRICS) && (!defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)) + const uint64_t implied_before = solver->statistics_.backbone_implied; #endif unsigned_array *trail = &solver->trail; value *values = solver->values; flags *flags = solver->flags; assigned *assigned = solver->assigned; - assert (kissat_propagated (solver)); - assert (kissat_trail_flushed (solver)); + KISSAT_assert (kissat_propagated (solver)); + KISSAT_assert (kissat_trail_flushed (solver)); unsigned inconsistent = INVALID_LIT; SET_EFFORT_LIMIT (ticks_limit, backbone, backbone_ticks); size_t round_limit = GET_OPTION (backbonerounds); - assert (solver->statistics.backbone_computations); - round_limit *= solver->statistics.backbone_computations; + KISSAT_assert (solver->statistics_.backbone_computations); + round_limit *= solver->statistics_.backbone_computations; const size_t max_rounds = GET_OPTION (backbonemaxrounds); if (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); break; } - const uint64_t ticks = solver->statistics.backbone_ticks; + const uint64_t ticks = solver->statistics_.backbone_ticks; if (ticks > ticks_limit) { kissat_very_verbose (solver, "backbone ticks limit %" PRIu64 " hit " @@ -365,17 +367,17 @@ static unsigned compute_backbone (kissat *solver) { break; } size_t previous = failed; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); if (TERMINATED (backbone_terminated_1)) break; round++; INC (backbone_rounds); LOG ("starting backbone round %zu", round); unsigned *const begin_candidates = BEGIN_STACK (candidates); - assert (!solver->level); -#if !defined(QUIET) && defined(METRICS) + KISSAT_assert (!solver->level); +#if !defined(KISSAT_QUIET) && defined(METRICS) size_t decisions = 0; - uint64_t propagated = solver->statistics.backbone_propagations; + uint64_t propagated = solver->statistics_.backbone_propagations; #endif unsigned active_before = solver->active; { @@ -383,7 +385,7 @@ static unsigned compute_backbone (kissat *solver) { const unsigned *p = begin_candidates; const unsigned *const end_candidates = END_STACK (candidates); while (p != end_candidates) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); const unsigned probe = *q++ = *p++; const value value = values[probe]; if (value > 0) { @@ -409,14 +411,14 @@ static unsigned compute_backbone (kissat *solver) { } continue; } - if (solver->statistics.backbone_ticks > ticks_limit) + if (solver->statistics_.backbone_ticks > ticks_limit) break; if (TERMINATED (backbone_terminated_2)) break; const unsigned level = solver->level; unsigned *const saved = END_ARRAY (*trail); - assert (level != UINT_MAX); -#if !defined(QUIET) && defined(METRICS) + KISSAT_assert (level != UINT_MAX); +#if !defined(KISSAT_QUIET) && defined(METRICS) decisions++; #endif solver->level = level + 1; @@ -444,7 +446,7 @@ static unsigned compute_backbone (kissat *solver) { backbone_assign (solver, trail, values, assigned, not_uip, UNIT_REASON); 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); if (conflict) { @@ -455,7 +457,7 @@ static unsigned compute_backbone (kissat *solver) { LOG ("propagating backbone forced %s successful", LOGLIT (not_uip)); } -#ifndef QUIET +#ifndef KISSAT_QUIET size_t remain = end_candidates - p; if (remain) kissat_extremely_verbose (solver, @@ -497,7 +499,7 @@ static unsigned compute_backbone (kissat *solver) { LOG ("keeping falsified probe %s", LOGLIT (probe)); continue; } - assert (!value); + KISSAT_assert (!value); LOG ("keeping unassigned probe %s", LOGLIT (probe)); } LOG ("flushed %zu probe candidates", @@ -515,13 +517,13 @@ static unsigned compute_backbone (kissat *solver) { if (kissat_probing_propagate (solver, 0, true)) break; } - assert (solver->active <= active_before); + KISSAT_assert (solver->active <= active_before); unsigned implied = active_before - solver->active; - assert (failed <= failed); + KISSAT_assert (failed <= failed); ADD (backbone_implied, implied); -#ifndef QUIET +#ifndef KISSAT_QUIET #ifdef METRICS - propagated = solver->statistics.backbone_propagations - propagated; + propagated = solver->statistics_.backbone_propagations - propagated; kissat_very_verbose (solver, "backbone round %zu with %zu decisions " "(%.2f propagations per decision)", @@ -545,7 +547,7 @@ static unsigned compute_backbone (kissat *solver) { LOG ("assuming forced unit %s", LOGLIT (inconsistent)); kissat_learned_unit (solver, inconsistent); (void) kissat_probing_propagate (solver, 0, true); - assert (solver->inconsistent); + KISSAT_assert (solver->inconsistent); } RELEASE_STACK (units); if (solver->inconsistent) @@ -553,12 +555,12 @@ static unsigned compute_backbone (kissat *solver) { "inconsistent binary clauses"); else { keep_backbone_candidates (solver, &candidates); -#if defined(METRICS) && (!defined(QUIET) || !defined(NDEBUG)) - assert (implied_before <= solver->statistics.backbone_implied); +#if defined(METRICS) && (!defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)) + KISSAT_assert (implied_before <= solver->statistics_.backbone_implied); #endif -#if defined(METRICS) && !defined(QUIET) +#if defined(METRICS) && !defined(KISSAT_QUIET) const uint64_t total_implied = - solver->statistics.backbone_implied - implied_before; + solver->statistics_.backbone_implied - implied_before; kissat_phase (solver, "backbone", GET (backbone_computations), "found %zu backbone literals %" PRIu64 " implied in %zu rounds", @@ -576,23 +578,25 @@ void kissat_binary_clauses_backbone (kissat *solver) { return; if (TERMINATED (backbone_terminated_3)) return; - assert (solver->watching); - assert (solver->probing); - assert (!solver->level); + KISSAT_assert (solver->watching); + KISSAT_assert (solver->probing); + KISSAT_assert (!solver->level); START (backbone); INC (backbone_computations); -#if !defined(NDEBUG) || defined(METRICS) - assert (!solver->backbone_computing); +#if !defined(KISSAT_NDEBUG) || defined(METRICS) + KISSAT_assert (!solver->backbone_computing); solver->backbone_computing = true; #endif -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned failed = #endif compute_backbone (solver); REPORT (!failed, 'b'); -#if !defined(NDEBUG) || defined(METRICS) - assert (solver->backbone_computing); +#if !defined(KISSAT_NDEBUG) || defined(METRICS) + KISSAT_assert (solver->backbone_computing); solver->backbone_computing = false; #endif STOP (backbone); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/backbone.h b/src/sat/kissat/backbone.h index 0ddf87c99..4cb189c9d 100644 --- a/src/sat/kissat/backbone.h +++ b/src/sat/kissat/backbone.h @@ -3,7 +3,12 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_binary_clauses_backbone (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/backtrack.c b/src/sat/kissat/backtrack.c index 09ba8df70..ef33f1010 100644 --- a/src/sat/kissat/backtrack.c +++ b/src/sat/kissat/backtrack.c @@ -8,19 +8,21 @@ #include "propsearch.h" #include "trail.h" +ABC_NAMESPACE_IMPL_START + static inline void unassign (kissat *solver, value *values, unsigned lit) { LOG ("unassign %s", LOGLIT (lit)); - assert (values[lit] > 0); + KISSAT_assert (values[lit] > 0); const unsigned not_lit = NOT (lit); values[lit] = values[not_lit] = 0; - assert (solver->unassigned < VARS); + KISSAT_assert (solver->unassigned < VARS); solver->unassigned++; } static inline void add_unassigned_variable_back_to_queue (kissat *solver, links *links, unsigned lit) { - assert (!solver->stable); + KISSAT_assert (!solver->stable); const unsigned idx = IDX (lit); if (links[idx].stamp > solver->queue.search.stamp) 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, heap *scores, unsigned lit) { - assert (solver->stable); + KISSAT_assert (solver->stable); const unsigned idx = IDX (lit); if (!kissat_heap_contains (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, unsigned new_level) { - assert (solver->level >= new_level); + KISSAT_assert (solver->level >= new_level); if (solver->level == new_level) return; @@ -94,12 +96,12 @@ void kissat_backtrack_without_updating_phases (kissat *solver, for (const unsigned *p = q; p != old_end; p++) { const unsigned lit = *p; const unsigned idx = IDX (lit); - assert (idx < VARS); + KISSAT_assert (idx < VARS); struct assigned *a = assigned + idx; const unsigned level = a->level; if (level <= new_level) { const unsigned new_trail = q - trail; - assert (new_trail <= a->trail); + KISSAT_assert (new_trail <= a->trail); a->trail = new_trail; *q++ = 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++) { const unsigned lit = *p; const unsigned idx = IDX (lit); - assert (idx < VARS); + KISSAT_assert (idx < VARS); struct assigned *a = assigned + idx; const unsigned level = a->level; if (level <= new_level) { const unsigned new_trail = q - trail; - assert (new_trail <= a->trail); + KISSAT_assert (new_trail <= a->trail); a->trail = new_trail; *q++ = lit; LOG ("reassign %s", LOGLIT (lit)); @@ -139,12 +141,12 @@ void kissat_backtrack_without_updating_phases (kissat *solver, LOG ("reassigned %u literals", 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", (size_t) (new_end - trail)); solver->propagate = new_end; - assert (!solver->extended); + KISSAT_assert (!solver->extended); } 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) { if (solver->level) { - assert (solver->watching); + KISSAT_assert (solver->watching); kissat_backtrack_in_consistent_state (solver, 0); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG clause *conflict = #endif solver->probing ? kissat_probing_propagate (solver, 0, true) : kissat_search_propagate (solver); - assert (!conflict); + KISSAT_assert (!conflict); } - assert (kissat_propagated (solver)); - assert (kissat_trail_flushed (solver)); + KISSAT_assert (kissat_propagated (solver)); + KISSAT_assert (kissat_trail_flushed (solver)); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/backtrack.h b/src/sat/kissat/backtrack.h index 7a9b93bf7..0df13f8b8 100644 --- a/src/sat/kissat/backtrack.h +++ b/src/sat/kissat/backtrack.h @@ -1,6 +1,9 @@ #ifndef _backtrack_h_INCLUDED #define _backtrack_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; 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_propagate_and_flush_trail (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/build.c b/src/sat/kissat/build.c index 0426854a2..d1f21e937 100644 --- a/src/sat/kissat/build.c +++ b/src/sat/kissat/build.c @@ -5,6 +5,8 @@ #include +ABC_NAMESPACE_IMPL_START + const char *kissat_signature (void) { return "kissat-" VERSION; } const char *kissat_id (void) { return ID; } @@ -79,3 +81,5 @@ void kissat_banner (const char *prefix, const char *name) { kissat_build (prefix); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/build.h b/src/sat/kissat/build.h new file mode 100644 index 000000000..cd418ecfd --- /dev/null +++ b/src/sat/kissat/build.h @@ -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 diff --git a/src/sat/kissat/bump.c b/src/sat/kissat/bump.c index 5771db4ac..5dc365f51 100644 --- a/src/sat/kissat/bump.c +++ b/src/sat/kissat/bump.c @@ -9,6 +9,8 @@ #include "rank.h" #include "sort.h" +ABC_NAMESPACE_IMPL_START + #define RANK(A) ((A).rank) #define SMALLER(A, B) (RANK (A) < RANK (B)) @@ -32,7 +34,7 @@ void kissat_rescale_scores (kissat *solver) { kissat_phase (solver, "rescale", GET (rescaled), "maximum score %g increment %g", 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; kissat_rescale_heap (solver, scores, factor); solver->scinc *= factor; @@ -43,7 +45,7 @@ void kissat_rescale_scores (kissat *solver) { void kissat_bump_score_increment (kissat *solver) { const double old_scinc = solver->scinc; 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 new_scinc = old_scinc * factor; 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) { - assert (EMPTY_STACK (solver->ranks)); + KISSAT_assert (EMPTY_STACK (solver->ranks)); const links *const links = solver->links; for (all_stack (unsigned, idx, solver->analyzed)) { // clang-format off @@ -112,9 +114,11 @@ void kissat_bump_analyzed (kissat *solver) { } void kissat_update_scores (kissat *solver) { - assert (solver->stable); + KISSAT_assert (solver->stable); heap *scores = SCORES; for (all_variables (idx)) if (ACTIVE (idx) && !kissat_heap_contains (scores, idx)) kissat_push_heap (solver, scores, idx); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/bump.h b/src/sat/kissat/bump.h index 55d541562..036324502 100644 --- a/src/sat/kissat/bump.h +++ b/src/sat/kissat/bump.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_bump_analyzed (struct kissat *); @@ -13,4 +16,6 @@ void kissat_bump_score_increment (struct kissat *); #define MAX_SCORE 1e150 +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/check.c b/src/sat/kissat/check.c index 0245a0866..fa771f2c7 100644 --- a/src/sat/kissat/check.c +++ b/src/sat/kissat/check.c @@ -1,4 +1,6 @@ -#ifndef NDEBUG +#include "global.h" + +#ifndef KISSAT_NDEBUG #include "check.h" #include "error.h" @@ -187,7 +189,7 @@ void kissat_release_checker (kissat *solver) { kissat_free (solver, checker, sizeof (struct checker)); } -#ifndef QUIET +#ifndef KISSAT_QUIET #include @@ -234,18 +236,18 @@ void kissat_print_checker_statistics (kissat *solver, bool verbose) { static unsigned reduce_hash (unsigned hash, unsigned mod) { if (mod < 2) return 0; - assert (mod); + KISSAT_assert (mod); unsigned res = hash; for (unsigned shift = 16, mask = 0xffff; res >= mod; mask >>= (shift >>= 1)) res = (res >> shift) & mask; - assert (res < mod); + KISSAT_assert (res < mod); return res; } static void resize_hash (kissat *solver, checker *checker) { 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; bucket **table = kissat_calloc (solver, new_hashed, sizeof (bucket *)); 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, unsigned hash) { - bucket *res = kissat_malloc (solver, bytes_line (size)); + bucket *res = (bucket*)kissat_malloc (solver, bytes_line (size)); res->next = 0; res->size = size; res->hash = hash; @@ -291,18 +293,18 @@ static void checker_assign (kissat *solver, checker *checker, unsigned lit, #else (void) bucket; #endif - assert (VALID_CHECKER_LIT (lit)); + KISSAT_assert (VALID_CHECKER_LIT (lit)); const unsigned not_lit = lit ^ 1; signed char *values = checker->values; - assert (!values[lit]); - assert (!values[not_lit]); + KISSAT_assert (!values[lit]); + KISSAT_assert (!values[not_lit]); values[lit] = 1; values[not_lit] = -1; PUSH_STACK (checker->trail, lit); } static buckets *checker_watches (checker *checker, unsigned lit) { - assert (VALID_CHECKER_LIT (lit)); + KISSAT_assert (VALID_CHECKER_LIT (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, bucket *bucket) { - assert (bucket->size > 1); + KISSAT_assert (bucket->size > 1); const unsigned *const lits = bucket->lits; unwatch_checker_literal (solver, checker, bucket, lits[0]); 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, unsigned hash) { size_t size = SIZE_STACK (checker->imported); - assert (size <= UINT_MAX); + KISSAT_assert (size <= UINT_MAX); if (checker->buckets == checker->hashed) resize_hash (solver, checker); bucket *bucket = new_line (solver, checker, size, hash); @@ -485,8 +487,8 @@ static void insert_imported (kissat *solver, checker *checker, LOGLINE3 ("inserted checker"); const unsigned *const lits = BEGIN_STACK (checker->imported); const signed char *values = checker->values; - assert (!values[lits[0]]); - assert (!values[lits[1]]); + KISSAT_assert (!values[lits[0]]); + KISSAT_assert (!values[lits[1]]); watch_checker_literal (solver, checker, bucket, lits[0]); watch_checker_literal (solver, checker, bucket, lits[1]); checker->buckets++; @@ -525,11 +527,11 @@ static void resize_checker (kissat *solver, checker *checker, const unsigned vars = checker->vars; const unsigned size = checker->size; if (new_vars > size) { - assert (new_vars <= MAX_SIZE); + KISSAT_assert (new_vars <= MAX_SIZE); unsigned new_size = size ? 2 * size : 1; while (new_size < new_vars) new_size *= 2; - assert (new_size <= MAX_SIZE); + KISSAT_assert (new_size <= MAX_SIZE); LOG3 ("resizing checker form %u to %u", size, new_size); const unsigned size2 = 2 * 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 new_vars2 = 2 * new_vars; 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->marks + vars2, 0, delta2); memset (checker->used + vars2, 0, delta2); @@ -566,11 +568,11 @@ static void resize_checker (kissat *solver, checker *checker, static inline unsigned import_external_checker (kissat *solver, checker *checker, int elit) { - assert (elit); + KISSAT_assert (elit); const unsigned var = ABS (elit) - 1; if (var >= checker->vars) resize_checker (solver, checker, var + 1); - assert (var < checker->vars); + KISSAT_assert (var < checker->vars); 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) { - assert (ilit <= 2 * checker->vars); + KISSAT_assert (ilit <= 2 * checker->vars); 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); LOGLINE3 ("removed checker"); kissat_free (solver, bucket, bytes_line (size)); - assert (checker->buckets > 0); + KISSAT_assert (checker->buckets > 0); checker->buckets--; checker->removed++; } @@ -639,7 +641,7 @@ static void import_external_literals (kissat *solver, checker *checker, static void import_internal_literals (kissat *solver, checker *checker, size_t size, const unsigned *ilits) { - assert (size <= UINT_MAX); + KISSAT_assert (size <= UINT_MAX); CLEAR_STACK (checker->imported); for (size_t i = 0; i < size; 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 not_lit = lit ^ 1; LOG3 ("checker propagate %u", lit); - assert (values[lit] > 0); - assert (values[not_lit] < 0); + KISSAT_assert (values[lit] > 0); + KISSAT_assert (values[not_lit] < 0); propagated++; buckets *buckets = checker_watches (checker, not_lit); 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; while (p != begin) { const unsigned lit = *--p; - assert (VALID_CHECKER_LIT (lit)); + KISSAT_assert (VALID_CHECKER_LIT (lit)); const unsigned not_lit = lit ^ 1; - assert (values[lit] > 0); - assert (values[not_lit] < 0); + KISSAT_assert (values[lit] > 0); + KISSAT_assert (values[not_lit] < 0); values[lit] = values[not_lit] = 0; } checker->propagated = saved; @@ -787,7 +789,7 @@ static void checker_backtrack (checker *checker, unsigned saved) { static bool checker_blocked_literal (kissat *solver, checker *checker, unsigned lit) { signed char *values = checker->values; - assert (values[lit] < 0); + KISSAT_assert (values[lit] < 0); const unsigned not_lit = lit ^ 1; if (checker->large[not_lit]) return false; @@ -840,7 +842,7 @@ static void check_line (kissat *solver, checker *checker) { bool satisfied = false, pure = false; unsigned decisions = 0, prev = INVALID_LIT; for (all_stack (unsigned, lit, checker->imported)) { - assert (prev != lit); + KISSAT_assert (prev != lit); prev = lit; signed char lit_value = values[lit]; 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"); checker *checker = solver->checker; checker->unchecked++; - assert (size <= UINT_MAX); + KISSAT_assert (size <= UINT_MAX); import_internal_literals (solver, checker, size, lits); 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) { LOGBINARY3 (a, b, "checking and adding internal checker"); checker *checker = solver->checker; - assert (VALID_INTERNAL_LITERAL (a)); - assert (VALID_INTERNAL_LITERAL (b)); + KISSAT_assert (VALID_INTERNAL_LITERAL (a)); + KISSAT_assert (VALID_INTERNAL_LITERAL (b)); import_binary (solver, checker, a, b); check_line (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) { LOG3 ("checking and adding internal checker internal unit %u", a); checker *checker = solver->checker; - assert (VALID_INTERNAL_LITERAL (a)); + KISSAT_assert (VALID_INTERNAL_LITERAL (a)); import_internal_unit (solver, checker, a); check_line (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) { LOGBINARY3 (a, b, "removing internal checker"); checker *checker = solver->checker; - assert (VALID_INTERNAL_LITERAL (a)); - assert (VALID_INTERNAL_LITERAL (b)); + KISSAT_assert (VALID_INTERNAL_LITERAL (a)); + KISSAT_assert (VALID_INTERNAL_LITERAL (b)); import_binary (solver, checker, a, b); remove_line_if_not_redundant (solver, checker); } diff --git a/src/sat/kissat/check.h b/src/sat/kissat/check.h index f7eaf27a1..e6065fd1d 100644 --- a/src/sat/kissat/check.h +++ b/src/sat/kissat/check.h @@ -1,11 +1,14 @@ #ifndef _check_h_INCLUDED #define _check_h_INCLUDED -#ifndef NDEBUG - #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#ifndef KISSAT_NDEBUG + struct kissat; void kissat_check_satisfying_assignment (struct kissat *); @@ -17,7 +20,7 @@ struct clause; void kissat_init_checker (struct kissat *); void kissat_release_checker (struct kissat *); -#ifndef QUIET +#ifndef KISSAT_QUIET void kissat_print_checker_statistics (struct kissat *, bool verbose); #endif @@ -172,4 +175,7 @@ void kissat_remove_checker_internal (struct kissat *, size_t, } while (0) #endif + +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/classify.c b/src/sat/kissat/classify.c index 4514fb7bb..5b86239bf 100644 --- a/src/sat/kissat/classify.c +++ b/src/sat/kissat/classify.c @@ -2,8 +2,10 @@ #include "internal.h" #include "print.h" +ABC_NAMESPACE_IMPL_START + void kissat_classify (struct kissat *solver) { - statistics *s = &solver->statistics; + statistics *s = &solver->statistics_; uint64_t clauses = s->clauses_binary + s->clauses_irredundant; unsigned small_clauses_limit = GET_OPTION (smallclauses); 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->classification.bigbig ? "large" : "small"); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/classify.h b/src/sat/kissat/classify.h index f1f9b84d7..7590e72d0 100644 --- a/src/sat/kissat/classify.h +++ b/src/sat/kissat/classify.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; struct classification { @@ -14,4 +17,6 @@ typedef struct classification classification; void kissat_classify (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/clause.c b/src/sat/kissat/clause.c index 8d4859193..9e50462cb 100644 --- a/src/sat/kissat/clause.c +++ b/src/sat/kissat/clause.c @@ -4,6 +4,8 @@ #include +ABC_NAMESPACE_IMPL_START + static void inc_clause (kissat *solver, bool original, bool redundant, bool 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, unsigned size) { - assert (size <= UINT_MAX); - assert (redundant || !glue); + KISSAT_assert (size <= UINT_MAX); + KISSAT_assert (redundant || !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, bool watch, unsigned first, unsigned second) { - assert (first != second); - assert (first != NOT (second)); + KISSAT_assert (first != second); + KISSAT_assert (first != NOT (second)); if (watch) kissat_watch_binary (solver, first, second); 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, bool redundant, unsigned glue, unsigned size, unsigned *lits) { - assert (size > 2); + KISSAT_assert (size > 2); reference res = kissat_allocate_clause (solver, size); clause *c = kissat_unchecked_dereference_clause (solver, res); 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) { - assert (!c->garbage); + KISSAT_assert (!c->garbage); LOGCLS (c, "garbage"); if (!c->redundant) kissat_mark_removed_literals (solver, c->size, c->lits); REMOVE_CHECKER_CLAUSE (c); DELETE_CLAUSE_FROM_PROOF (c); - assert (c->size > 2); + KISSAT_assert (c->size > 2); dec_clause (solver, c->redundant, false); c->garbage = true; } void kissat_mark_clause_as_garbage (kissat *solver, clause *c) { - assert (!c->garbage); + KISSAT_assert (!c->garbage); mark_clause_as_garbage (solver, c); size_t bytes = kissat_actual_bytes_of_clause (c); 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) { LOGCLS (c, "delete"); - assert (c->size > 2); - assert (c->garbage); + KISSAT_assert (c->size > 2); + KISSAT_assert (c->garbage); size_t bytes = kissat_actual_bytes_of_clause (c); SUB (arena_garbage, bytes); INC (clauses_deleted); @@ -185,3 +187,5 @@ void kissat_delete_binary (kissat *solver, unsigned a, unsigned b) { dec_clause (solver, false, true); INC (clauses_deleted); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/clause.h b/src/sat/kissat/clause.h index d926a6cc2..52e9c6fd1 100644 --- a/src/sat/kissat/clause.h +++ b/src/sat/kissat/clause.h @@ -8,6 +8,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct clause clause; #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 *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/collect.c b/src/sat/kissat/collect.c index 77d45319e..3dfffe2db 100644 --- a/src/sat/kissat/collect.c +++ b/src/sat/kissat/collect.c @@ -13,10 +13,12 @@ #include #include +ABC_NAMESPACE_IMPL_START + static void flush_watched_clauses_by_literal (kissat *solver, unsigned lit, bool compact, reference start) { - assert (start != INVALID_REF); + KISSAT_assert (start != INVALID_REF); const value *const values = solver->values; 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) kissat_delete_binary (solver, lit, other); } else { - assert (!lit_fixed); - assert (!other_fixed); + KISSAT_assert (!lit_fixed); + KISSAT_assert (!other_fixed); { head.binary.lit = mother; @@ -59,7 +61,7 @@ static void flush_watched_clauses_by_literal (kissat *solver, unsigned lit, } } } else { - assert (solver->watching); + KISSAT_assert (solver->watching); const watch tail = *p++; if (!lit_fixed) { 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); #ifdef LOGGING 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; 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); #endif if (lit_fixed) - assert (!size_mlit_watches); + KISSAT_assert (!size_mlit_watches); else if (mlit < lit) { - assert (mlit != INVALID_LIT); - assert (mlit < lit); + KISSAT_assert (mlit != INVALID_LIT); + KISSAT_assert (mlit < lit); *mlit_watches = *lit_watches; LOG ("copied watches[%u] = watches[%u] (size %zu)", mlit, lit, size_mlit_watches); memset (lit_watches, 0, sizeof *lit_watches); } else - assert (mlit == lit); + KISSAT_assert (mlit == lit); } static void flush_all_watched_clauses (kissat *solver, bool compact, reference start) { - assert (solver->watching); + KISSAT_assert (solver->watching); LOG ("starting to flush watches at clause[%" REFERENCE_FORMAT "]", start); for (all_variables (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, unsigned forced, clause *dst) { - assert (dst->reason); - assert (forced != INVALID_LIT); + KISSAT_assert (dst->reason); + KISSAT_assert (forced != INVALID_LIT); reference dst_ref = kissat_reference_clause (solver, dst); const unsigned forced_idx = IDX (forced); struct assigned *a = assigned + forced_idx; - assert (!a->binary); + KISSAT_assert (!a->binary); if (a->reason != dst_ref) { LOG ("reason reference %u of %s updated to %u", a->reason, 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) { - assert (dst->reason); + KISSAT_assert (dst->reason); unsigned forced = INVALID_LIT; for (all_literals_in_clause (lit, dst)) { const value value = values[lit]; @@ -138,7 +140,7 @@ static unsigned get_forced (const value *values, clause *dst) { forced = lit; break; } - assert (forced != INVALID_LIT); + KISSAT_assert (forced != INVALID_LIT); 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) { - assert (reducible); - assert (!reducible->garbage); - assert (reducible->redundant); + KISSAT_assert (reducible); + KISSAT_assert (!reducible->garbage); + KISSAT_assert (reducible->redundant); if (solver->first_reducible != INVALID_REF) { reference ref = kissat_reference_clause (solver, 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) { - assert (irredundant); - assert (!irredundant->garbage); - assert (!irredundant->redundant); + KISSAT_assert (irredundant); + KISSAT_assert (!irredundant->garbage); + KISSAT_assert (!irredundant->redundant); if (solver->last_irredundant != INVALID_REF) { reference ref = kissat_reference_clause (solver, 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, reference ref) { INC (moved); - assert (ref != INVALID_REF); -#ifndef NDEBUG + KISSAT_assert (ref != INVALID_REF); +#ifndef KISSAT_NDEBUG const size_t size = SIZE_STACK (solver->arena); - assert ((size_t) ref <= size); + KISSAT_assert ((size_t) ref <= size); #endif clause *begin = (clause *) (BEGIN_STACK (solver->arena) + ref); 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); while (p != end) { - assert (!p->shrunken); + KISSAT_assert (!p->shrunken); size_t bytes = kissat_bytes_of_clause (p->size); if (p->redundant) { memcpy (r, p, bytes); @@ -258,16 +260,16 @@ static void move_redundant_clauses_to_the_end (kissat *solver, LOGCLS (q, "new DST"); if (q->reason) get_forced_and_update_large_reason (solver, assigned, values, q); - assert (q->redundant); + KISSAT_assert (q->redundant); if (!first_reducible) first_reducible = q; r = (clause *) (bytes + (char *) r); 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); - assert (!first_reducible || first_reducible < q); + KISSAT_assert (!first_reducible || first_reducible < q); update_first_reducible (solver, q, first_reducible); 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, reference start) { - assert (solver->watching); + KISSAT_assert (solver->watching); LOG ("sparse garbage collection starting at clause[%" REFERENCE_FORMAT "]", start); #ifdef CHECKING_OR_PROVING const bool checking_or_proving = kissat_checking_or_proving (solver); #endif - assert (EMPTY_STACK (solver->added)); - assert (EMPTY_STACK (solver->removed)); + KISSAT_assert (EMPTY_STACK (solver->added)); + KISSAT_assert (EMPTY_STACK (solver->removed)); const value *const values = solver->values; assigned *assigned = solver->assigned; -#ifndef QUIET +#ifndef KISSAT_QUIET size_t flushed_garbage_clauses = 0; size_t flushed_satisfied_clauses = 0; #endif @@ -319,7 +321,7 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact, for (clause *next; src != end; src = next) { if (src->garbage) { next = kissat_delete_clause (solver, src); -#ifndef QUIET +#ifndef KISSAT_QUIET flushed_garbage_clauses++; #endif if (last_irredundant == src) { @@ -331,13 +333,13 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact, continue; } - assert (src->size > 1); + KISSAT_assert (src->size > 1); LOGCLS (src, "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; #endif - assert (SIZE_OF_CLAUSE_HEADER == sizeof (unsigned)); + KISSAT_assert (SIZE_OF_CLAUSE_HEADER == sizeof (unsigned)); *(unsigned *) dst = *(unsigned *) src; unsigned *q = dst->lits; @@ -365,15 +367,15 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact, if (tmp < 0 && !level) flushed++; else if (tmp > 0 && !level) { - assert (!satisfied); - assert (!dst->reason); + KISSAT_assert (!satisfied); + KISSAT_assert (!dst->reason); LOG ("SRC satisfied by %s", LOGLIT (lit)); satisfied = true; } else { const unsigned mlit = kissat_map_literal (solver, lit, compact); if (tmp > 0) { - assert (level); + KISSAT_assert (level); forced = non_false++ ? INVALID_LIT : lit; } else if (tmp < 0) other = lit; @@ -397,7 +399,7 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact, DEC (clauses_redundant); else DEC (clauses_irredundant); -#ifndef QUIET +#ifndef KISSAT_QUIET flushed_satisfied_clauses++; #endif #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; - assert (new_size <= old_size); - assert (1 < new_size); + KISSAT_assert (new_size <= old_size); + KISSAT_assert (1 < new_size); if (new_size == 2) { - assert (mfirst != INVALID_LIT); - assert (msecond != INVALID_LIT); + KISSAT_assert (mfirst != INVALID_LIT); + KISSAT_assert (msecond != INVALID_LIT); - statistics *statistics = &solver->statistics; - assert (statistics->clauses_binary < UINT64_MAX); + statistics *statistics = &solver->statistics_; + KISSAT_assert (statistics->clauses_binary < UINT64_MAX); statistics->clauses_binary++; bool redundant = dst->redundant; if (redundant) { - assert (statistics->clauses_redundant > 0); + KISSAT_assert (statistics->clauses_redundant > 0); statistics->clauses_redundant--; redundant = false; } else { - assert (statistics->clauses_irredundant > 0); + KISSAT_assert (statistics->clauses_irredundant > 0); statistics->clauses_irredundant--; } LOGBINARY (mfirst, msecond, "DST"); kissat_watch_binary (solver, mfirst, msecond); if (dst->reason) { - assert (non_false == 1); - assert (other != INVALID_LIT); - assert (forced != INVALID_LIT); + KISSAT_assert (non_false == 1); + KISSAT_assert (other != INVALID_LIT); + KISSAT_assert (forced != INVALID_LIT); const unsigned forced_idx = IDX (forced); struct assigned *a = assigned + forced_idx; - assert (!a->binary); + KISSAT_assert (!a->binary); LOGBINARY (mfirst, msecond, "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; } } else { - assert (2 < new_size); + KISSAT_assert (2 < new_size); dst->size = new_size; dst->shrunken = false; @@ -495,8 +497,8 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact, continue; if (new_size != old_size) { - assert (1 < new_size); - assert (new_size < old_size); + KISSAT_assert (1 < new_size); + KISSAT_assert (new_size < old_size); CHECK_AND_ADD_STACK (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) 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; #endif -#ifndef QUIET +#ifndef KISSAT_QUIET if (flushed) kissat_phase (solver, "collect", GET (garbage_collections), "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), FORMAT_BYTES (move_bytes)); #endif - assert (first_redundant < dst); + KISSAT_assert (first_redundant < dst); res = kissat_reference_clause (solver, first_redundant); - assert (res != INVALID_REF); + KISSAT_assert (res != INVALID_REF); } SET_END_OF_STACK (solver->arena, (ward *) dst); kissat_shrink_arena (solver); #ifdef METRICS - if (solver->statistics.arena_garbage) + if (solver->statistics_.arena_garbage) kissat_very_verbose (solver, "still %s garbage left in arena", - FORMAT_BYTES (solver->statistics.arena_garbage)); + FORMAT_BYTES (solver->statistics_.arena_garbage)); else kissat_very_verbose (solver, "all garbage clauses in arena collected"); #endif @@ -578,7 +580,7 @@ static reference sparse_sweep_garbage_clauses (kissat *solver, bool compact, static void rewatch_clauses (kissat *solver, reference start) { LOG ("rewatching clause[%" REFERENCE_FORMAT "] and following clauses", start); - assert (solver->watching); + KISSAT_assert (solver->watching); const value *const values = solver->values; 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 *c = (clause *) (BEGIN_STACK (solver->arena) + start); - assert (c <= end); + KISSAT_assert (c <= end); for (clause *next; c != end; c = next) { 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) { - assert (solver->watching); + KISSAT_assert (solver->watching); START (collect); INC (garbage_collections); INC (sparse_gcs); @@ -643,11 +645,11 @@ bool kissat_compacting (kissat *solver) { } void kissat_initial_sparse_collect (kissat *solver) { - assert (!solver->level); - assert (!solver->inconsistent); - assert (solver->watching); - assert (kissat_trail_flushed (solver)); - if (solver->statistics.units) { + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->inconsistent); + KISSAT_assert (solver->watching); + KISSAT_assert (kissat_trail_flushed (solver)); + if (solver->statistics_.units) { bool compact = GET_OPTION (compact); 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) { - assert (!solver->level); - assert (!solver->watching); + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->watching); LOG ("dense garbage collection"); -#ifndef QUIET +#ifndef KISSAT_QUIET size_t flushed_garbage_clauses = 0; #endif clause *first_reducible = 0; @@ -675,15 +677,15 @@ static void dense_sweep_garbage_clauses (kissat *solver) { for (clause *next; src != end; src = next) { if (src->garbage) { next = kissat_delete_clause (solver, src); -#ifndef QUIET +#ifndef KISSAT_QUIET flushed_garbage_clauses++; #endif continue; } - assert (src->size > 1); + KISSAT_assert (src->size > 1); LOGCLS (src, "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; dst->searched = src->searched; dst->size = src->size; @@ -701,7 +703,7 @@ static void dense_sweep_garbage_clauses (kissat *solver) { update_last_irredundant (solver, dst, last_irredundant); 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; #endif kissat_phase (solver, "collect", GET (garbage_collections), @@ -717,17 +719,17 @@ static void dense_sweep_garbage_clauses (kissat *solver) { kissat_shrink_arena (solver); #ifdef METRICS - if (solver->statistics.arena_garbage) + if (solver->statistics_.arena_garbage) kissat_very_verbose (solver, "still %s garbage left in arena", - FORMAT_BYTES (solver->statistics.arena_garbage)); + FORMAT_BYTES (solver->statistics_.arena_garbage)); else kissat_very_verbose (solver, "all garbage clauses in arena collected"); #endif } void kissat_dense_collect (kissat *solver) { - assert (!solver->watching); - assert (!solver->level); + KISSAT_assert (!solver->watching); + KISSAT_assert (!solver->level); START (collect); INC (garbage_collections); INC (dense_garbage_collections); @@ -736,3 +738,5 @@ void kissat_dense_collect (kissat *solver) { REPORT (1, 'C'); STOP (collect); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/collect.h b/src/sat/kissat/collect.h index 6a9c8c4ef..f6222ded4 100644 --- a/src/sat/kissat/collect.h +++ b/src/sat/kissat/collect.h @@ -3,6 +3,9 @@ #include "internal.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + bool kissat_compacting (kissat *); void kissat_dense_collect (kissat *); 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_first_reducible (kissat *, clause *first_reducible); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/colors.c b/src/sat/kissat/colors.c index a3f2e6db9..f45260b29 100644 --- a/src/sat/kissat/colors.c +++ b/src/sat/kissat/colors.c @@ -1,12 +1,18 @@ #include "colors.h" +#ifdef WIN32 +#define isatty _isatty +#else #include +#endif + +ABC_NAMESPACE_IMPL_START int kissat_is_terminal[3] = {0, -1, -1}; int kissat_initialize_terminal (int fd) { - assert (fd == 1 || fd == 2); - assert (kissat_is_terminal[fd] < 0); + KISSAT_assert (fd == 1 || fd == 2); + KISSAT_assert (kissat_is_terminal[fd] < 0); return kissat_is_terminal[fd] = isatty (fd); } @@ -17,3 +23,5 @@ void kissat_force_colors (void) { void kissat_force_no_colors (void) { kissat_is_terminal[1] = kissat_is_terminal[2] = 0; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/colors.h b/src/sat/kissat/colors.h index fe981e505..0d79c79e8 100644 --- a/src/sat/kissat/colors.h +++ b/src/sat/kissat/colors.h @@ -7,6 +7,9 @@ #include "keatures.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define BLUE "\033[34m" #define BOLD "\033[1m" #define CYAN "\033[36m" @@ -21,17 +24,17 @@ #define DARK_GRAY "\033[0;37m" #ifdef KISSAT_HAS_FILENO -#define assert_if_has_fileno assert +#define KISSAT_assert_if_has_fileno KISSAT_assert #else -#define assert_if_has_fileno(...) \ +#define KISSAT_assert_if_has_fileno(...) \ do { \ } while (0) #endif #define TERMINAL(F, I) \ - assert_if_has_fileno (fileno (F) == \ + KISSAT_assert_if_has_fileno (fileno (F) == \ 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); \ FILE *terminal_file = F @@ -49,11 +52,11 @@ void kissat_force_colors (void); void kissat_force_no_colors (void); 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]; if (res < 0) res = kissat_initialize_terminal (fd); - assert (res == 0 || res == 1); + KISSAT_assert (res == 0 || res == 1); return res; } @@ -65,4 +68,6 @@ static inline const char *kissat_normal_color_code (int fd) { return kissat_connected_to_terminal (fd) ? NORMAL : ""; } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/compact.c b/src/sat/kissat/compact.c index 2d27fa9ca..cb89cb9a9 100644 --- a/src/sat/kissat/compact.c +++ b/src/sat/kissat/compact.c @@ -6,11 +6,13 @@ #include +ABC_NAMESPACE_IMPL_START + static void reimport_literal (kissat *solver, unsigned eidx, unsigned mlit) { import *import = &PEEK_STACK (solver->import, eidx); - assert (import->imported); - assert (!import->eliminated); + KISSAT_assert (import->imported); + KISSAT_assert (!import->eliminated); LOG ("reimporting external variable %u as internal literal %u (was %u)", eidx, mlit, import->lit); import->lit = mlit; @@ -18,9 +20,9 @@ static void reimport_literal (kissat *solver, unsigned eidx, unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) { INC (compacted); -#if !defined(QUIET) || !defined(NDEBUG) +#if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG) const unsigned active = solver->active; -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned inactive = solver->vars - active; kissat_phase (solver, "compact", GET (compacted), "compacting garbage collection " @@ -29,7 +31,7 @@ unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) { #endif #endif #ifdef LOGGING - assert (!solver->compacting); + KISSAT_assert (!solver->compacting); solver->compacting = true; #endif unsigned mfixed = INVALID_LIT; @@ -42,7 +44,7 @@ unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) { unsigned mlit; if (flags->fixed) { const value value = kissat_fixed (solver, ilit); - assert (value); + KISSAT_assert (value); if (mfixed == INVALID_LIT) { mlit = mfixed = LIT (vars); 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); } } else if (flags->active) { - assert (flags->active); + KISSAT_assert (flags->active); mlit = LIT (vars); LOG2 ("remapping %u to %u", ilit, mlit); vars++; } else { - const int elit = PEEK_STACK (solver->export, iidx); + const int elit = PEEK_STACK (solver->export_, iidx); if (elit) { const unsigned eidx = ABS (elit); import *import = &PEEK_STACK (solver->import, eidx); - assert (import->imported); - assert (!import->eliminated); + KISSAT_assert (import->imported); + KISSAT_assert (!import->eliminated); import->imported = false; LOG2 ("external variable %d not imported anymore", eidx); - POKE_STACK (solver->export, iidx, 0); + POKE_STACK (solver->export_, iidx, 0); } else LOG2 ("skipping inactive %u", ilit); continue; } - assert (mlit <= ilit); - assert (mlit != NOT (ilit)); + KISSAT_assert (mlit <= ilit); + KISSAT_assert (mlit != NOT (ilit)); if (mlit == ilit) continue; - const int elit = PEEK_STACK (solver->export, iidx); + const int elit = PEEK_STACK (solver->export_, iidx); const unsigned eidx = ABS (elit); if (elit < 0) mlit = NOT (mlit); @@ -90,17 +92,17 @@ unsigned kissat_compact_literals (kissat *solver, unsigned *mfixed_ptr) { *mfixed_ptr = mfixed; LOG ("compacting to %u variables %.2f%% from %u", vars, kissat_percent (vars, solver->vars), solver->vars); - assert (vars == active || vars == active + 1); + KISSAT_assert (vars == active || vars == active + 1); return vars; } static void compact_literal (kissat *solver, unsigned dst_lit, unsigned src_lit) { - assert (dst_lit < src_lit); - assert (dst_lit != NOT (src_lit)); + KISSAT_assert (dst_lit < src_lit); + KISSAT_assert (dst_lit != NOT (src_lit)); const unsigned dst_idx = IDX (dst_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); solver->assigned[dst_idx] = solver->assigned[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) { - int elit = PEEK_STACK (solver->export, iidx); + int elit = PEEK_STACK (solver->export_, iidx); if (!elit) return INVALID_IDX; - assert (elit); + KISSAT_assert (elit); const unsigned eidx = ABS (elit); - assert (eidx); + KISSAT_assert (eidx); import *import = &PEEK_STACK (solver->import, eidx); - assert (import->imported); + KISSAT_assert (import->imported); if (import->eliminated) return INVALID_IDX; const unsigned mlit = import->lit; const unsigned midx = IDX (mlit); - assert (midx <= iidx); + KISSAT_assert (midx <= iidx); return midx; } @@ -139,7 +141,7 @@ static void compact_queue (kissat *solver) { solver->queue.stamp = 0; for (unsigned idx; !DISCONNECTED (idx = *p); p = &l->next) { const unsigned midx = map_idx (solver, idx); - assert (midx != INVALID_IDX); + KISSAT_assert (midx != INVALID_IDX); l = links + idx; l->prev = prev; l->stamp = ++solver->queue.stamp; @@ -211,16 +213,16 @@ static void compact_trail (kissat *solver) { for (size_t i = 0; i < size; i++) { const unsigned ilit = PEEK_ARRAY (solver->trail, i); const unsigned mlit = kissat_map_literal (solver, ilit, true); - assert (mlit != INVALID_LIT); + KISSAT_assert (mlit != INVALID_LIT); POKE_ARRAY (solver->trail, i, mlit); const unsigned idx = IDX (ilit); assigned *a = solver->assigned + idx; if (!a->binary) continue; 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); - assert (mother != INVALID_LIT); + KISSAT_assert (mother != INVALID_LIT); a->reason = mother; } } @@ -232,55 +234,55 @@ static void compact_frames (kissat *solver) { frame *frame = &FRAME (level); const unsigned ilit = frame->decision; const unsigned mlit = kissat_map_literal (solver, ilit, true); - assert (mlit != INVALID_LIT); + KISSAT_assert (mlit != INVALID_LIT); frame->decision = mlit; } } static void compact_export (kissat *solver, unsigned vars) { LOG ("compacting export"); - const size_t size = SIZE_STACK (solver->export); - assert (size <= UINT_MAX); - assert (size == solver->vars); + const size_t size = SIZE_STACK (solver->export_); + KISSAT_assert (size <= UINT_MAX); + KISSAT_assert (size == solver->vars); 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) continue; const unsigned midx = map_idx (solver, iidx); if (midx == INVALID_IDX) continue; - POKE_STACK (solver->export, midx, elit); + POKE_STACK (solver->export_, midx, elit); } - RESIZE_STACK (solver->export, vars); - SHRINK_STACK (solver->export); -#ifndef NDEBUG - assert (SIZE_STACK (solver->export) == vars); + RESIZE_STACK (solver->export_, vars); + SHRINK_STACK (solver->export_); +#ifndef KISSAT_NDEBUG + KISSAT_assert (SIZE_STACK (solver->export_) == vars); for (unsigned iidx = 0; iidx < vars; iidx++) { - const int elit = PEEK_STACK (solver->export, iidx); - assert (VALID_EXTERNAL_LITERAL (elit)); + const int elit = PEEK_STACK (solver->export_, iidx); + KISSAT_assert (VALID_EXTERNAL_LITERAL (elit)); const unsigned eidx = ABS (elit); const import *const import = &PEEK_STACK (solver->import, eidx); - assert (import->imported); + KISSAT_assert (import->imported); if (import->eliminated) continue; unsigned mlit = import->lit; if (elit < 0) mlit = NOT (mlit); const unsigned ilit = LIT (iidx); - assert (mlit == ilit); + KISSAT_assert (mlit == ilit); } #endif } static void compact_units (kissat *solver, unsigned 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)) { const unsigned eidx = ABS (elit); const unsigned mlit = elit < 0 ? NOT (mfixed) : mfixed; const import *const import = &PEEK_STACK (solver->import, eidx); - assert (import->imported); - assert (!import->eliminated); + KISSAT_assert (import->imported); + KISSAT_assert (!import->eliminated); const unsigned ilit = import->lit; if (mlit != ilit) 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, unsigned mfixed) { LOG ("finalizing compacting"); - assert (vars <= solver->vars); + KISSAT_assert (vars <= solver->vars); #ifdef LOGGING - assert (solver->compacting); + KISSAT_assert (solver->compacting); #endif if (vars == solver->vars) { #ifdef LOGGING @@ -341,7 +343,7 @@ void kissat_finalize_compacting (kissat *solver, unsigned vars, if (flags->fixed && first) first = false; else if (!flags->active) - POKE_STACK (solver->export, iidx, 0); + POKE_STACK (solver->export_, iidx, 0); } compact_trail (solver); @@ -374,3 +376,5 @@ void kissat_finalize_compacting (kissat *solver, unsigned vars, #endif kissat_decrease_size (solver); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/compact.h b/src/sat/kissat/compact.h index 89d5ecd31..6c281af23 100644 --- a/src/sat/kissat/compact.h +++ b/src/sat/kissat/compact.h @@ -1,9 +1,14 @@ #ifndef _compact_h_INCLUDED #define _compact_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; unsigned kissat_compact_literals (struct kissat *, unsigned *mfixed_ptr); void kissat_finalize_compacting (struct kissat *, unsigned vars, unsigned mfixed); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/config.c b/src/sat/kissat/config.c index 3c79f7a1e..b1f322ba4 100644 --- a/src/sat/kissat/config.c +++ b/src/sat/kissat/config.c @@ -1,4 +1,6 @@ -#ifndef NOPTIONS +#include "global.h" + +#ifndef KISSAT_NOPTIONS #include "config.h" #include "kissat.h" diff --git a/src/sat/kissat/config.h b/src/sat/kissat/config.h index 16eac8c05..d3d34fe49 100644 --- a/src/sat/kissat/config.h +++ b/src/sat/kissat/config.h @@ -1,8 +1,14 @@ -#ifndef NOPTIONS #ifndef _config_h_INCLUDED #define _config_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#ifndef KISSAT_NOPTIONS + void kissat_configuration_usage (void); #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/congruence.c b/src/sat/kissat/congruence.c index 01b7dde00..221f6a13a 100644 --- a/src/sat/kissat/congruence.c +++ b/src/sat/kissat/congruence.c @@ -19,6 +19,8 @@ #include #include +ABC_NAMESPACE_IMPL_START + // #define INDEX_LARGE_CLAUSES // #define INDEX_BINARY_CLAUSES #define MERGE_CONDITIONAL_EQUIVALENCES @@ -31,7 +33,7 @@ #define MAX_ARITY ((1 << LD_MAX_ARITY) - 1) struct gate { -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) size_t id; #endif unsigned lhs; @@ -132,10 +134,10 @@ struct closure { #ifdef CHECKING_OR_PROVING unsigneds chain; #endif -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) size_t gates_added; #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG unsigneds implied; #endif }; @@ -144,8 +146,8 @@ typedef struct closure closure; static void init_closure (kissat *solver, closure *closure) { closure->solver = solver; - CALLOC (closure->scheduled, VARS); - CALLOC (closure->occurrences, LITS); + CALLOC (bool, closure->scheduled, VARS); + CALLOC (gates, closure->occurrences, LITS); INIT_STACK (closure->garbage); INIT_STACK (closure->lits); INIT_STACK (closure->rhs); @@ -153,7 +155,7 @@ static void init_closure (kissat *solver, closure *closure) { INIT_STACK (closure->binaries); INIT_FIFO (closure->schedule); - NALLOC (closure->repr, LITS); + NALLOC (unsigned, closure->repr, LITS); for (all_literals (lit)) closure->repr[lit] = lit; @@ -167,10 +169,10 @@ static void init_closure (kissat *solver, closure *closure) { #ifdef CHECKING_OR_PROVING INIT_STACK (closure->chain); #endif -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) closure->gates_added = 0; #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG INIT_STACK (closure->implied); #endif } @@ -190,21 +192,21 @@ static unsigned actual_gate_arity (gate *g) { #define CLOGANDGATE(G, ...) \ do { \ - assert ((G)->tag == AND_GATE); \ + KISSAT_assert ((G)->tag == AND_GATE); \ LOGANDGATE ((G)->id, closure->repr, (G)->lhs, (G)->arity, (G)->rhs, \ __VA_ARGS__); \ } while (0) #define CLOGXORGATE(G, ...) \ do { \ - assert ((G)->tag == XOR_GATE); \ + KISSAT_assert ((G)->tag == XOR_GATE); \ LOGXORGATE ((G)->id, closure->repr, (G)->lhs, (G)->arity, (G)->rhs, \ __VA_ARGS__); \ } while (0) #define CLOGITEGATE(G, ...) \ do { \ - assert ((G)->tag == ITE_GATE); \ + KISSAT_assert ((G)->tag == ITE_GATE); \ LOGITEGATE ((G)->id, closure->repr, (G)->lhs, (G)->rhs[0], \ (G)->rhs[1], (G)->rhs[2], __VA_ARGS__); \ } while (0) @@ -218,7 +220,7 @@ static unsigned actual_gate_arity (gate *g) { else if ((G)->tag == XOR_GATE) \ CLOGXORGATE (G, __VA_ARGS__); \ else { \ - assert ((G)->tag == ITE_GATE); \ + KISSAT_assert ((G)->tag == ITE_GATE); \ CLOGITEGATE (G, __VA_ARGS__); \ } \ } while (0) @@ -264,7 +266,7 @@ static void reset_closure (closure *closure) { #ifdef CHECKING_OR_PROVING RELEASE_STACK (closure->chain); #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG RELEASE_STACK (closure->implied); #endif @@ -284,7 +286,7 @@ static unsigned reset_repr (closure *closure) { return res; } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG static void check_lits_sorted (size_t size, const unsigned *lits) { unsigned prev = INVALID_LIT; @@ -292,38 +294,38 @@ static void check_lits_sorted (size_t size, const unsigned *lits) { for (const unsigned *p = lits; p != end_lits; p++) { const unsigned lit = *p; if (prev != INVALID_LIT) { - assert (prev != lit); + KISSAT_assert (prev != lit); const unsigned not_lit = lit ^ 1; - assert (prev != not_lit); - assert (prev < lit); + KISSAT_assert (prev != not_lit); + KISSAT_assert (prev < lit); } prev = lit; } } static void check_and_lits_normalized (size_t arity, const unsigned *lits) { - assert (arity > 1); + KISSAT_assert (arity > 1); check_lits_sorted (arity, lits); } static void check_xor_lits_normalized (const unsigned arity, const unsigned *lits) { - assert (arity > 1); + KISSAT_assert (arity > 1); check_lits_sorted (arity, lits); for (size_t i = 1; i != arity; i++) - assert (lits[i - 1] < lits[i]); + KISSAT_assert (lits[i - 1] < lits[i]); } static void check_ite_lits_normalized (kissat *solver, const unsigned *lits) { - assert (!NEGATED (lits[0])); - assert (!NEGATED (lits[1])); - assert (lits[0] != lits[1]); - assert (lits[0] != lits[2]); - assert (lits[1] != lits[2]); - assert (lits[0] != NOT (lits[1])); - assert (lits[0] != NOT (lits[2])); - assert (lits[1] != NOT (lits[2])); + KISSAT_assert (!NEGATED (lits[0])); + KISSAT_assert (!NEGATED (lits[1])); + KISSAT_assert (lits[0] != lits[1]); + KISSAT_assert (lits[0] != lits[2]); + KISSAT_assert (lits[1] != lits[2]); + KISSAT_assert (lits[0] != NOT (lits[1])); + KISSAT_assert (lits[0] != NOT (lits[2])); + KISSAT_assert (lits[1] != NOT (lits[2])); } #else @@ -347,13 +349,13 @@ static void sort_lits (kissat *solver, size_t arity, unsigned *lits) { static unsigned hash_lits (closure *closure, unsigned tag, size_t arity, const unsigned *lits) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG if (tag == AND_GATE) check_and_lits_normalized (arity, lits); else if (tag == XOR_GATE) check_xor_lits_normalized (arity, lits); else { - assert (tag == ITE_GATE); + KISSAT_assert (tag == ITE_GATE); check_ite_lits_normalized (closure->solver, lits); } #endif @@ -362,7 +364,7 @@ static unsigned hash_lits (closure *closure, unsigned tag, size_t arity, const uint64_t *const end_nonces = nonces + SIZE_NONCES; const uint64_t *n = nonces + tag; uint64_t hash = 0; - assert (n < end_nonces); + KISSAT_assert (n < end_nonces); for (const unsigned *l = lits; l != end_lits; l++) { hash += *l; hash *= *n++; @@ -374,19 +376,19 @@ static unsigned hash_lits (closure *closure, unsigned tag, size_t arity, return hash; } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG static bool is_power_of_two (size_t n) { return n && ~(n & (n - 1)); } #endif static size_t reduce_hash (unsigned hash, size_t size, size_t size2) { - assert (size <= size2); - assert (size2 <= 2 * size); - assert (is_power_of_two (size2)); + KISSAT_assert (size <= size2); + KISSAT_assert (size2 <= 2 * size); + KISSAT_assert (is_power_of_two (size2)); unsigned res = hash; res &= size2 - 1; if (res >= size) res -= size; - assert (res < size); + KISSAT_assert (res < size); return res; } @@ -402,7 +404,7 @@ static bool closure_hash_table_is_full (closure *closure) { static bool match_lits (gate *g, unsigned tag, unsigned hash, size_t size, const unsigned *lits) { - assert (!g->garbage); + KISSAT_assert (!g->garbage); if (g->tag != tag) return false; if (g->hash != hash) @@ -427,7 +429,7 @@ static void resize_gate_hash_table (closure *closure) { "resizing gate table of size %zu filled with %zu entries %.0f%%", old_size, old_entries, kissat_percent (old_entries, old_size)); gate **old_table = hash->table, **new_table; - CALLOC (new_table, new_size); + CALLOC (gate*, new_table, new_size); size_t flushed = 0; for (size_t old_pos = 0; old_pos != old_size; old_pos++) { gate *g = old_table[old_pos]; @@ -439,7 +441,7 @@ static void resize_gate_hash_table (closure *closure) { } size_t new_pos = reduce_hash (g->hash, new_size, new_size); while (new_table[new_pos]) { - assert (new_table[new_pos] != REMOVED); + KISSAT_assert (new_table[new_pos] != REMOVED); if (++new_pos == new_size) new_pos = 0; } @@ -449,7 +451,7 @@ static void resize_gate_hash_table (closure *closure) { solver, "flushed %zu entries %.0f%% resizing table of size %zu", flushed, kissat_percent (flushed, old_size), old_size); DEALLOC (old_table, old_size); - assert (flushed <= old_entries); + KISSAT_assert (flushed <= old_entries); const size_t new_entries = old_entries - flushed; hash->table = new_table; hash->size = new_size; @@ -463,7 +465,7 @@ static bool remove_gate (closure *closure, gate *g) { if (!g->indexed) return false; kissat *solver = closure->solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); const size_t hash_size = closure->hash.size; size_t pos = reduce_hash (g->hash, hash_size, hash_size); gate **table = closure->hash.table; @@ -485,12 +487,12 @@ static bool remove_gate (closure *closure, gate *g) { static gate *find_gate (closure *closure, unsigned tag, unsigned hash, size_t size, const unsigned *lits, gate *except) { - assert (!except || !except->garbage); + KISSAT_assert (!except || !except->garbage); if (!closure->hash.entries) return 0; kissat *solver = closure->solver; - assert (!solver->inconsistent); - assert (hash == hash_lits (closure, tag, size, lits)); + KISSAT_assert (!solver->inconsistent); + KISSAT_assert (hash == hash_lits (closure, tag, size, lits)); const size_t hash_size = closure->hash.size; size_t start_pos = reduce_hash (hash, hash_size, hash_size); gate **table = closure->hash.table, *g; @@ -503,7 +505,7 @@ static gate *find_gate (closure *closure, unsigned tag, unsigned hash, if (g == REMOVED) ; else if (g->garbage) { - assert (g->indexed); + KISSAT_assert (g->indexed); g->indexed = false; table[pos] = REMOVED; } else if (g != except && match_lits (g, tag, hash, size, lits)) { @@ -523,15 +525,15 @@ static gate *find_gate (closure *closure, unsigned tag, unsigned hash, } static void index_gate (closure *closure, gate *g) { - assert (!g->indexed); + KISSAT_assert (!g->indexed); kissat *solver = closure->solver; - assert (!solver->inconsistent); - assert (g->arity > 1); + KISSAT_assert (!solver->inconsistent); + KISSAT_assert (g->arity > 1); if (closure_hash_table_is_full (closure)) resize_gate_hash_table (closure); LOGATE (g, "adding to hash table"); INC (congruent_indexed); - assert (g->hash == hash_lits (closure, g->tag, g->arity, g->rhs)); + KISSAT_assert (g->hash == hash_lits (closure, g->tag, g->arity, g->rhs)); const size_t hash_size = closure->hash.size; size_t pos = reduce_hash (g->hash, hash_size, hash_size); gate **table = closure->hash.table, *h; @@ -552,7 +554,7 @@ static unsigned parity_lits (kissat *solver, unsigneds *lits) { unsigned res = 0; for (all_stack (unsigned, lit, *lits)) res ^= NEGATED (lit); -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) solver; #endif return res; @@ -568,12 +570,12 @@ static void inc_lits (kissat *solver, unsigneds *lits) { carry = !NEGATED (not_lit); *p++ = not_lit; } -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) solver; #endif } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG #define LESS_LITERAL(A, B) ((A) < (B)) @@ -617,14 +619,14 @@ static void check_binary_implied (closure *closure, unsigned a, unsigned b) { kissat *const solver = closure->solver; unsigneds *implied = &closure->implied; - assert (EMPTY_STACK (*implied)); + KISSAT_assert (EMPTY_STACK (*implied)); PUSH_STACK (*implied, a); PUSH_STACK (*implied, b); check_implied (closure); } static void check_and_gate_implied (closure *closure, gate *g) { - assert (g->tag == AND_GATE); + KISSAT_assert (g->tag == AND_GATE); kissat *const solver = closure->solver; if (GET_OPTION (check) < 2) return; @@ -634,7 +636,7 @@ static void check_and_gate_implied (closure *closure, gate *g) { for (all_rhs_literals_in_gate (other, g)) check_binary_implied (closure, not_lhs, other); unsigneds *implied = &closure->implied; - assert (EMPTY_STACK (*implied)); + KISSAT_assert (EMPTY_STACK (*implied)); PUSH_STACK (*implied, lhs); for (all_rhs_literals_in_gate (other, g)) { const unsigned not_other = NOT (other); @@ -644,7 +646,7 @@ static void check_and_gate_implied (closure *closure, gate *g) { } static void check_xor_gate_implied (closure *closure, gate *g) { - assert (g->tag == XOR_GATE); + KISSAT_assert (g->tag == XOR_GATE); kissat *const solver = closure->solver; if (GET_OPTION (check) < 2) return; @@ -652,16 +654,16 @@ static void check_xor_gate_implied (closure *closure, gate *g) { const unsigned lhs = g->lhs; const unsigned not_lhs = NOT (lhs); unsigneds *clause = &solver->clause; - assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*clause)); PUSH_STACK (*clause, not_lhs); for (all_rhs_literals_in_gate (other, g)) { - assert (!NEGATED (other)); + KISSAT_assert (!NEGATED (other)); PUSH_STACK (*clause, other); } unsigned arity = g->arity; unsigned end = 1u << arity; unsigned parity = NEGATED (not_lhs); - assert (parity == parity_lits (solver, clause)); + KISSAT_assert (parity == parity_lits (solver, clause)); for (unsigned i = 0; i != end; i++) { while (i && parity_lits (solver, clause) != parity) inc_lits (solver, clause); @@ -702,9 +704,9 @@ static void check_ite_implied (closure *closure, unsigned lhs, } static void check_ite_gate_implied (closure *closure, gate *g) { - assert (g->tag == ITE_GATE); - assert (g->arity == 3); -#ifndef NOPTIONS + KISSAT_assert (g->tag == ITE_GATE); + KISSAT_assert (g->arity == 3); +#ifndef KISSAT_NOPTIONS kissat *const solver = closure->solver; #endif if (GET_OPTION (check) < 2) @@ -741,17 +743,17 @@ static inline unsigned find_repr (closure *closure, unsigned lit) { static clause *find_other_two (kissat *solver, watches *watches, unsigned a, unsigned b, unsigned ignore) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); const value *const values = solver->values; const watch *const begin_watches = BEGIN_WATCHES (*watches); const watch *const end_watches = END_WATCHES (*watches); const watch *p = begin_watches; while (p != end_watches) { const watch watch = *p++; - assert (!watch.type.binary); + KISSAT_assert (!watch.type.binary); const reference ref = watch.large.ref; clause *c = kissat_dereference_clause (solver, ref); - assert (!c->garbage); + KISSAT_assert (!c->garbage); unsigned found = 0; for (all_literals_in_clause (lit, c)) { if (values[lit]) @@ -764,7 +766,7 @@ static clause *find_other_two (kissat *solver, watches *watches, unsigned a, } goto CONTINUE_WITH_NEXT_WATCH; } - assert (found <= 2); + KISSAT_assert (found <= 2); if (found == 2) return c; CONTINUE_WITH_NEXT_WATCH:; @@ -774,7 +776,7 @@ static clause *find_other_two (kissat *solver, watches *watches, unsigned a, static clause *find_ternary_clause (kissat *solver, unsigned a, unsigned b, unsigned c) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); watches *const a_watches = &WATCHES (a); watches *const b_watches = &WATCHES (b); watches *const c_watches = &WATCHES (c); @@ -785,7 +787,7 @@ static clause *find_ternary_clause (kissat *solver, unsigned a, unsigned b, return find_other_two (solver, a_watches, b, c, a); if (size_b <= size_a && size_b <= size_c) return find_other_two (solver, b_watches, a, c, b); - assert (size_c <= size_a && size_c <= size_b); + KISSAT_assert (size_c <= size_a && size_c <= size_b); return find_other_two (solver, c_watches, a, b, c); } @@ -793,7 +795,7 @@ static clause *find_ternary_clause (kissat *solver, unsigned a, unsigned b, static bool learn_congruence_unit (closure *closure, unsigned unit) { kissat *const solver = closure->solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); const value value = solver->values[unit]; if (value > 0) return true; @@ -810,7 +812,7 @@ static bool learn_congruence_unit (closure *closure, unsigned unit) { clause *conflict = kissat_probing_propagate (solver, 0, false); if (!conflict) return true; - assert (solver->inconsistent); + KISSAT_assert (solver->inconsistent); LOG ("propagating congruence unit %s yields conflict", LOGLIT (unit)); return false; } @@ -838,7 +840,7 @@ static void add_binary_clause (closure *closure, unsigned a, unsigned b) { (void) !learn_congruence_unit (closure, unit); return; } - assert (!a_value), assert (!b_value); + KISSAT_assert (!a_value), KISSAT_assert (!b_value); LOGBINARY (a, b, "adding representative"); if (solver->watching) kissat_new_binary_clause (solver, a, b); @@ -856,19 +858,19 @@ static void schedule_literal (closure *closure, unsigned lit) { if (*scheduled) return; *scheduled = true; - ENQUEUE_FIFO (closure->schedule, lit); + ENQUEUE_FIFO (unsigned, closure->schedule, lit); LOG ("scheduled propagation of merged %s", CLOGREPR (lit)); } static unsigned dequeue_next_scheduled_literal (closure *closure) { unsigned res; DEQUEUE_FIFO (closure->schedule, res); -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) kissat *const solver = closure->solver; #endif unsigned idx = IDX (res); bool *scheduled = closure->scheduled + idx; - assert (*scheduled); + KISSAT_assert (*scheduled); *scheduled = false; LOG ("dequeued from schedule %s", CLOGREPR (res)); return res; @@ -877,7 +879,7 @@ static unsigned dequeue_next_scheduled_literal (closure *closure) { static bool merge_literals (closure *closure, unsigned lit, unsigned other) { kissat *const solver = closure->solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); unsigned repr_lit = find_repr (closure, lit); unsigned repr_other = find_repr (closure, other); unsigned *const repr = closure->repr; @@ -889,8 +891,8 @@ static bool merge_literals (closure *closure, unsigned lit, const value *const values = solver->values; const value lit_value = values[lit]; const value other_value = values[other]; - assert (lit_value == values[repr_lit]); - assert (other_value == values[repr_other]); + KISSAT_assert (lit_value == values[repr_lit]); + KISSAT_assert (other_value == values[repr_other]); if (lit_value) { if (lit_value == other_value) { LOG ("not merging %s and %s assigned to the same value", @@ -905,7 +907,7 @@ static bool merge_literals (closure *closure, unsigned lit, ADD_EMPTY_TO_PROOF (); return false; } - assert (!other_value); + KISSAT_assert (!other_value); LOG ("merging assigned %s and unassigned %s", LOGREPR (lit, repr), LOGREPR (other, repr)); const unsigned unit = (lit_value < 0) ? NOT (other) : other; @@ -923,8 +925,8 @@ static bool merge_literals (closure *closure, unsigned lit, unsigned larger = repr_other; if (smaller > larger) SWAP (unsigned, smaller, larger); - assert (repr[smaller] == smaller); - assert (repr[larger] > smaller); + KISSAT_assert (repr[smaller] == smaller); + KISSAT_assert (repr[larger] > smaller); if (repr_lit == NOT (repr_other)) { LOG ("merging clashing %s and %s", LOGREPR (lit, repr), LOGREPR (other, repr)); @@ -960,8 +962,8 @@ static gate *new_gate (closure *closure, unsigned tag, unsigned hash, unsigned lhs, unsigned arity, const unsigned *lits) { kissat *const solver = closure->solver; const size_t bytes = bytes_gate (arity); - gate *g = kissat_malloc (solver, bytes); -#if defined(LOGGING) || !defined(NDEBUG) + gate *g = (gate*)kissat_malloc (solver, bytes); +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) g->id = closure->gates_added++; #endif g->tag = tag; @@ -1010,12 +1012,12 @@ static gate *new_and_gate (closure *closure, unsigned lhs) { for (all_stack (unsigned, lit, *all_lits)) if (lhs != lit) { unsigned not_lit = NOT (lit); - assert (lhs != not_lit); + KISSAT_assert (lhs != not_lit); PUSH_STACK (*rhs_stack, not_lit); } const unsigned arity = SIZE_STACK (*rhs_stack); unsigned *rhs_lits = BEGIN_STACK (*rhs_stack); - assert (arity + 1 == SIZE_STACK (*all_lits)); + KISSAT_assert (arity + 1 == SIZE_STACK (*all_lits)); unsigned hash; gate *g = find_and_lits (closure, &hash, arity, rhs_lits, 0); if (g) { @@ -1043,10 +1045,10 @@ static void simplify_and_add_to_proof_chain (kissat *solver, mark *marks, unsigneds *unsimplified, unsigneds *clause, unsigneds *chain) { - assert (EMPTY_STACK (*clause)); -#ifndef NDEBUG + KISSAT_assert (EMPTY_STACK (*clause)); +#ifndef KISSAT_NDEBUG for (all_stack (unsigned, lit, *unsimplified)) - assert (!(marks[lit] & 4)); + KISSAT_assert (!(marks[lit] & 4)); #endif bool trivial = false; for (all_stack (unsigned, lit, *unsimplified)) { @@ -1065,7 +1067,7 @@ static void simplify_and_add_to_proof_chain (kissat *solver, mark *marks, } for (all_stack (unsigned, lit, *clause)) { mark mark = marks[lit]; - assert (mark & 4); + KISSAT_assert (mark & 4); mark &= ~4u; marks[lit] = mark; } @@ -1093,9 +1095,9 @@ static void add_xor_matching_proof_chain (closure *closure, gate *g, unsigneds *const clause = &solver->clause; unsigneds *const chain = &closure->chain; mark *const marks = solver->marks; - assert (EMPTY_STACK (*unsimplified)); - assert (EMPTY_STACK (*chain)); - assert (g->arity > 1); + KISSAT_assert (EMPTY_STACK (*unsimplified)); + KISSAT_assert (EMPTY_STACK (*chain)); + KISSAT_assert (g->arity > 1); const unsigned reduced_arity = g->arity - 1; for (unsigned i = 0; i != reduced_arity; i++) PUSH_STACK (*unsimplified, g->rhs[i]); @@ -1103,7 +1105,7 @@ static void add_xor_matching_proof_chain (closure *closure, gate *g, const unsigned not_lhs2 = NOT (lhs2); do { const size_t size = SIZE_STACK (*unsimplified); - assert (size < 32); + KISSAT_assert (size < 32); for (unsigned i = 0; i != 1u << size; i++) { PUSH_STACK (*unsimplified, not_lhs1); PUSH_STACK (*unsimplified, lhs2); @@ -1115,7 +1117,7 @@ static void add_xor_matching_proof_chain (closure *closure, gate *g, unsimplified->end -= 2; inc_lits (solver, unsimplified); } - assert (!EMPTY_STACK (*unsimplified)); + KISSAT_assert (!EMPTY_STACK (*unsimplified)); unsimplified->end--; } while (!EMPTY_STACK (*unsimplified)); LOG ("finished XOR matching proof chain"); @@ -1125,14 +1127,14 @@ static void delete_proof_chain (closure *closure) { kissat *const solver = closure->solver; unsigneds *chain = &closure->chain; if (!kissat_checking_or_proving (solver)) { - assert (EMPTY_STACK (*chain)); + KISSAT_assert (EMPTY_STACK (*chain)); return; } if (EMPTY_STACK (*chain)) return; LOG ("starting deletion of proof chain"); unsigneds *clause = &solver->clause; - assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*clause)); const unsigned *start = BEGIN_STACK (*chain); const unsigned *end = END_STACK (*chain); const unsigned *p = start; @@ -1150,8 +1152,8 @@ static void delete_proof_chain (closure *closure) { } p++; } - assert (EMPTY_STACK (*clause)); - assert (start == end); + KISSAT_assert (EMPTY_STACK (*clause)); + KISSAT_assert (start == end); CLEAR_STACK (*chain); LOG ("finished deletion of proof chain"); } @@ -1196,12 +1198,12 @@ static gate *new_xor_gate (closure *closure, unsigned lhs) { const unsigned not_lhs = NOT (lhs); for (all_stack (unsigned, lit, *all_lits)) if (lit != lhs && lit != not_lhs) { - assert (!NEGATED (lit)); + KISSAT_assert (!NEGATED (lit)); PUSH_STACK (*rhs_stack, lit); } const unsigned arity = SIZE_STACK (*rhs_stack); unsigned *rhs_lits = BEGIN_STACK (*rhs_stack); - assert (arity + 1 == SIZE_STACK (*all_lits)); + KISSAT_assert (arity + 1 == SIZE_STACK (*all_lits)); unsigned hash; gate *g = find_xor_lits (closure, &hash, arity, rhs_lits, 0); if (g) { @@ -1233,8 +1235,8 @@ static void add_ite_matching_proof_chain (closure *closure, gate *g, unsigneds *clause = &solver->clause; mark *const marks = solver->marks; unsigneds *chain = &closure->chain; - assert (EMPTY_STACK (*clause)); - assert (EMPTY_STACK (*chain)); + KISSAT_assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*chain)); const unsigned *rhs = g->rhs; const unsigned cond = rhs[0]; const unsigned not_cond = NOT (cond); @@ -1274,8 +1276,8 @@ static void add_ite_turned_and_binary_clauses (closure *closure, gate *g) { unsigneds *clause = &solver->clause; unsigneds *chain = &closure->chain; mark *const marks = solver->marks; - assert (EMPTY_STACK (*unsimplified)); - assert (EMPTY_STACK (*chain)); + KISSAT_assert (EMPTY_STACK (*unsimplified)); + KISSAT_assert (EMPTY_STACK (*chain)); const unsigned not_lhs = NOT (g->lhs); const unsigned *rhs = g->rhs; PUSH_STACK (*unsimplified, not_lhs); @@ -1298,7 +1300,7 @@ static void add_ite_turned_and_binary_clauses (closure *closure, gate *g) { #endif static bool normalize_ite_lits (kissat *solver, unsigned *lits) { -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) solver; #endif if (NEGATED (lits[0])) { @@ -1316,7 +1318,7 @@ static gate *find_ite_lits (closure *closure, unsigned *hash_ptr, bool *negate_lhs_ptr, unsigned arity, unsigned *lits, gate *except) { kissat *const solver = closure->solver; - assert (arity == 3); + KISSAT_assert (arity == 3); LOGITEGATE (INVALID_GATE_ID, closure->repr, INVALID_LIT, lits[0], lits[1], lits[2], "finding not yet normalized"); bool negate_lhs = normalize_ite_lits (solver, lits); @@ -1371,7 +1373,7 @@ static gate *new_ite_gate (closure *closure, unsigned lhs, unsigned cond, PUSH_STACK (*rhs_stack, cond); PUSH_STACK (*rhs_stack, then_lit); PUSH_STACK (*rhs_stack, else_lit); - assert (SIZE_STACK (*rhs_stack) == 3); + KISSAT_assert (SIZE_STACK (*rhs_stack) == 3); const unsigned arity = 3; unsigned *rhs_lits = BEGIN_STACK (*rhs_stack); bool negate_lhs; @@ -1397,7 +1399,7 @@ static gate *new_ite_gate (closure *closure, unsigned lhs, unsigned cond, static void mark_gate_as_garbage (closure *closure, gate *g) { kissat *const solver = closure->solver; - assert (!g->garbage); + KISSAT_assert (!g->garbage); g->garbage = true; LOGATE (g, "marked as garbage"); PUSH_STACK (closure->garbage, g); @@ -1408,13 +1410,13 @@ static void shrink_gate (closure *closure, gate *g, unsigned *const rhs = g->rhs; const unsigned old_arity = g->arity; unsigned *const old_end_rhs = rhs + old_arity; - assert (rhs <= new_end_rhs); - assert (new_end_rhs <= old_end_rhs); + KISSAT_assert (rhs <= new_end_rhs); + KISSAT_assert (new_end_rhs <= old_end_rhs); if (new_end_rhs == old_end_rhs) return; const unsigned new_arity = new_end_rhs - rhs; if (!g->shrunken) { - assert (old_end_rhs[-1] != INVALID_LIT); + KISSAT_assert (old_end_rhs[-1] != INVALID_LIT); old_end_rhs[-1] = INVALID_LIT; g->shrunken = true; } @@ -1428,7 +1430,7 @@ static void shrink_gate (closure *closure, gate *g, } static bool skip_and_gate (closure *closure, gate *g) { - assert (g->tag == AND_GATE); + KISSAT_assert (g->tag == AND_GATE); if (g->garbage) return true; kissat *const solver = closure->solver; @@ -1439,7 +1441,7 @@ static bool skip_and_gate (closure *closure, gate *g) { mark_gate_as_garbage (closure, g); return true; } - assert (g->arity > 1); + KISSAT_assert (g->arity > 1); return false; } @@ -1451,7 +1453,7 @@ static bool gate_contains (gate *g, unsigned lit) { } static bool rewriting_lhs (closure *closure, gate *g, unsigned dst) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG kissat *const solver = closure->solver; #endif if (dst != g->lhs && dst != NOT (g->lhs)) @@ -1463,16 +1465,16 @@ static bool rewriting_lhs (closure *closure, gate *g, unsigned dst) { static void shrink_and_gate (closure *closure, gate *g, unsigned *new_end_rhs, unsigned falsifies, unsigned clashing) { - assert (g->tag == AND_GATE); -#ifndef NDEBUG + KISSAT_assert (g->tag == AND_GATE); +#ifndef KISSAT_NDEBUG kissat *const solver = closure->solver; #endif if (falsifies != INVALID_LIT) { - assert (g->arity); + KISSAT_assert (g->arity); g->rhs[0] = falsifies; new_end_rhs = g->rhs + 1; } else if (clashing != INVALID_LIT) { - assert (1 < g->arity); + KISSAT_assert (1 < g->arity); g->rhs[0] = clashing; g->rhs[1] = NOT (clashing); new_end_rhs = g->rhs + 2; @@ -1482,7 +1484,7 @@ static void shrink_and_gate (closure *closure, gate *g, static void update_and_gate (closure *closure, gate *g, unsigned falsifies, unsigned clashing) { - assert (g->tag == AND_GATE); + KISSAT_assert (g->tag == AND_GATE); bool garbage = true; kissat *const solver = closure->solver; if (falsifies != INVALID_LIT || clashing != INVALID_LIT) @@ -1501,7 +1503,7 @@ static void update_and_gate (closure *closure, gate *g, unsigned falsifies, unsigned hash; gate *h = find_and_gate (closure, &hash, g); if (h) { - assert (garbage); + KISSAT_assert (garbage); if (merge_literals (closure, g->lhs, h->lhs)) INC (congruent_ands); } else { @@ -1553,11 +1555,11 @@ static void rewrite_and_gate (closure *closure, gate *g, unsigned dst, return; if (!gate_contains (g, src)) return; - assert (src != INVALID_LIT); - assert (dst != INVALID_LIT); + KISSAT_assert (src != INVALID_LIT); + KISSAT_assert (dst != INVALID_LIT); kissat *const solver = closure->solver; const value *const values = solver->values; - assert (values[src] == values[dst]); + KISSAT_assert (values[src] == values[dst]); CLOGANDGATE (g, "rewriting %s by %s in", CLOGREPR (src), CLOGREPR (dst)); const unsigned old_arity = g->arity; const unsigned not_lhs = NOT (g->lhs); @@ -1597,18 +1599,18 @@ static void rewrite_and_gate (closure *closure, gate *g, unsigned dst, } if (lit == not_dst) { if (dst_count) { - assert (!not_dst_count); + KISSAT_assert (!not_dst_count); LOG ("clashing literals %s and %s", LOGLIT (dst), LOGLIT (not_dst)); clashing = dst; break; } - assert (!not_dst_count); + KISSAT_assert (!not_dst_count); not_dst_count++; } *q++ = lit; } - assert (dst_count <= 2); - assert (not_dst_count <= 1); + KISSAT_assert (dst_count <= 2); + KISSAT_assert (not_dst_count <= 1); shrink_and_gate (closure, g, q, falsifies, clashing); CLOGANDGATE (g, "rewritten"); check_and_gate_implied (closure, g); @@ -1618,10 +1620,10 @@ static void rewrite_and_gate (closure *closure, gate *g, unsigned dst, } static bool skip_xor_gate (gate *g) { - assert (g->tag == XOR_GATE); + KISSAT_assert (g->tag == XOR_GATE); if (g->garbage) return true; - assert (g->arity > 1); + KISSAT_assert (g->arity > 1); return false; } @@ -1634,7 +1636,7 @@ static void add_xor_shrinking_proof_chain (closure *closure, gate *g, return; LOG ("starting XOR shrinking proof chain"); unsigneds *clause = &solver->clause; - assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*clause)); for (unsigned i = 0; i != g->arity; i++) { unsigned lit = g->rhs[i]; PUSH_STACK (*clause, lit); @@ -1643,10 +1645,10 @@ static void add_xor_shrinking_proof_chain (closure *closure, gate *g, const unsigned not_lhs = NOT (lhs); PUSH_STACK (*clause, not_lhs); const unsigned parity = NEGATED (not_lhs); - assert (parity == parity_lits (solver, clause)); + KISSAT_assert (parity == parity_lits (solver, clause)); const unsigned not_pivot = NOT (pivot); const size_t size = SIZE_STACK (*clause); - assert (size < 32); + KISSAT_assert (size < 32); const unsigned end = 1u << size; for (unsigned i = 0; i != end; i++) { while (i && parity != parity_lits (solver, clause)) @@ -1684,12 +1686,12 @@ static void add_xor_shrinking_proof_chain (closure *closure, gate *g, static void shrink_xor_gate (closure *closure, gate *g, unsigned *new_end_rhs) { - assert (g->tag == XOR_GATE); + KISSAT_assert (g->tag == XOR_GATE); shrink_gate (closure, g, new_end_rhs); } static void update_xor_gate (closure *closure, gate *g) { - assert (g->tag == XOR_GATE); + KISSAT_assert (g->tag == XOR_GATE); kissat *const solver = closure->solver; bool garbage = true; if (g->arity == 0) @@ -1705,11 +1707,11 @@ static void update_xor_gate (closure *closure, gate *g) { INC (congruent_unary); } } else { - assert (g->arity > 1); + KISSAT_assert (g->arity > 1); unsigned hash; gate *h = find_xor_gate (closure, &hash, g); if (h) { - assert (garbage); + KISSAT_assert (garbage); add_xor_matching_proof_chain (closure, g, g->lhs, h->lhs); if (merge_literals (closure, g->lhs, h->lhs)) INC (congruent_xors); @@ -1736,7 +1738,7 @@ static void simplify_xor_gate (closure *closure, gate *g) { unsigned negate = 0; for (const unsigned *p = q; p != end_of_rhs; p++) { const unsigned lit = *p; - assert (!NEGATED (lit)); + KISSAT_assert (!NEGATED (lit)); const value value = values[lit]; if (value > 0) negate ^= 1; @@ -1773,7 +1775,7 @@ static void rewrite_xor_gate (closure *closure, gate *g, unsigned dst, dst = STRIP (dst); for (const unsigned *p = q; p != end_of_rhs; p++) { unsigned lit = *p; - assert (!NEGATED (lit)); + KISSAT_assert (!NEGATED (lit)); if (lit == src) lit = dst; const value value = values[lit]; @@ -1789,7 +1791,7 @@ static void rewrite_xor_gate (closure *closure, gate *g, unsigned dst, LOG ("flipping LHS literal %s", LOGLIT (g->lhs)); g->lhs = NOT (g->lhs); } - assert (dst_count <= 2); + KISSAT_assert (dst_count <= 2); if (dst_count == 2) { CLOGXORGATE (g, "literals %s and %s were both in", LOGLIT (src), LOGLIT (dst)); @@ -1800,7 +1802,7 @@ static void rewrite_xor_gate (closure *closure, gate *g, unsigned dst, if (lit != dst) *q++ = lit; } - assert (q + 2 == end_of_rhs); + KISSAT_assert (q + 2 == end_of_rhs); } shrink_xor_gate (closure, g, q); CLOGXORGATE (g, "rewritten"); @@ -1809,7 +1811,7 @@ static void rewrite_xor_gate (closure *closure, gate *g, unsigned dst, update_xor_gate (closure, g); if (!g->garbage && !solver->inconsistent && original_dst_negated && dst_count == 1) { - assert (!NEGATED (dst)); + KISSAT_assert (!NEGATED (dst)); connect_occurrence (closure, dst, g); } check_xor_gate_implied (closure, g); @@ -1818,7 +1820,7 @@ static void rewrite_xor_gate (closure *closure, gate *g, unsigned dst, } static bool skip_ite_gate (gate *g) { - assert (g->tag == ITE_GATE); + KISSAT_assert (g->tag == ITE_GATE); if (g->garbage) return true; return false; @@ -1830,7 +1832,7 @@ static void simplify_ite_gate (closure *closure, gate *g) { kissat *const solver = closure->solver; const value *const values = solver->values; CLOGITEGATE (g, "simplifying"); - assert (g->arity == 3); + KISSAT_assert (g->arity == 3); bool garbage = true; const unsigned lhs = g->lhs; unsigned *const rhs = g->rhs; @@ -1852,7 +1854,7 @@ static void simplify_ite_gate (closure *closure, gate *g) { const value then_value = values[then_lit]; const value else_value = values[else_lit]; const unsigned not_lhs = NOT (lhs); - assert (then_value || else_value); + KISSAT_assert (then_value || else_value); if (then_value > 0 && else_value > 0) learn_congruence_unit (closure, lhs); else if (then_value < 0 && else_value < 0) @@ -1869,42 +1871,42 @@ static void simplify_ite_gate (closure *closure, gate *g) { INC (congruent_unary); } } else { - assert (!!else_value + !!then_value == 1); + KISSAT_assert (!!else_value + !!then_value == 1); if (then_value > 0) { - assert (!else_value); + KISSAT_assert (!else_value); g->lhs = not_lhs; rhs[0] = NOT (cond); rhs[1] = NOT (else_lit); } else if (then_value < 0) { - assert (!else_value); + KISSAT_assert (!else_value); rhs[0] = NOT (cond); rhs[1] = else_lit; } else if (else_value > 0) { - assert (!then_value); + KISSAT_assert (!then_value); g->lhs = not_lhs; rhs[0] = NOT (then_lit); rhs[1] = cond; } else { - assert (else_value < 0); - assert (!then_value); + KISSAT_assert (else_value < 0); + KISSAT_assert (!then_value); rhs[0] = cond; rhs[1] = then_lit; } if (rhs[0] > rhs[1]) SWAP (unsigned, rhs[0], rhs[1]); - assert (!g->shrunken); + KISSAT_assert (!g->shrunken); g->shrunken = true; rhs[2] = INVALID_LIT; g->arity = 2; g->tag = AND_GATE; - assert (rhs[0] < rhs[1]); - assert (rhs[0] != NOT (rhs[1])); + KISSAT_assert (rhs[0] < rhs[1]); + KISSAT_assert (rhs[0] != NOT (rhs[1])); CLOGANDGATE (g, "simplified"); check_and_gate_implied (closure, g); unsigned hash; gate *h = find_and_gate (closure, &hash, g); if (h) { - assert (garbage); + KISSAT_assert (garbage); if (merge_literals (closure, g->lhs, h->lhs)) INC (congruent_ands); } else { @@ -1933,7 +1935,7 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, kissat *const solver = closure->solver; CLOGITEGATE (g, "rewriting %s by %s in", CLOGREPR (src), CLOGREPR (dst)); unsigned *const rhs = g->rhs; - assert (g->arity == 3); + KISSAT_assert (g->arity == 3); const unsigned lhs = g->lhs; const unsigned cond = rhs[0]; const unsigned then_lit = rhs[1]; @@ -1961,13 +1963,13 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, // !then_lit & then_lit | then_lit & else_lit // then_lit & else_lit rhs[0] = else_lit; - assert (rhs[1] == then_lit); + KISSAT_assert (rhs[1] == then_lit); } else if (dst == else_lit) { // else_list ? then_lit : else_lit // else_list & then_lit | !else_list & else_lit // else_list & then_lit rhs[0] = else_lit; - assert (rhs[1] == then_lit); + KISSAT_assert (rhs[1] == then_lit); } else if (not_dst == else_lit) { // !else_list ? then_lit : else_lit // !else_list & then_lit | else_lit & else_lit @@ -2010,20 +2012,20 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, // cond & !else_lit | !cond & else_lit // cond ^ else_lit new_tag = XOR_GATE; - assert (rhs[0] == cond); + KISSAT_assert (rhs[0] == cond); rhs[1] = else_lit; } else { shrink = false; rhs[1] = dst; } } else { - assert (src == else_lit); + KISSAT_assert (src == else_lit); if (dst == cond) { // cond ? then_lit : cond // cond & then_lit | !cond & cond // cond & then_lit - assert (rhs[0] == cond); - assert (rhs[1] == then_lit); + KISSAT_assert (rhs[0] == cond); + KISSAT_assert (rhs[1] == then_lit); } else if (not_dst == cond) { // cond ? then_lit : !cond // cond & then_lit | !cond & !cond @@ -2031,7 +2033,7 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, // then_lit | !cond // !(!then_lit & cond) g->lhs = not_lhs; - assert (rhs[0] == cond); + KISSAT_assert (rhs[0] == cond); rhs[1] = not_then_lit; } else if (dst == then_lit) { // cond ? then_lit : then_lit @@ -2047,8 +2049,8 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, // !(cond ^ then_lit) new_tag = XOR_GATE; g->lhs = not_lhs; - assert (rhs[0] == cond); - assert (rhs[1] == then_lit); + KISSAT_assert (rhs[0] == cond); + KISSAT_assert (rhs[1] == then_lit); } else { shrink = false; rhs[2] = dst; @@ -2071,13 +2073,13 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, if (negate_lhs) g->lhs = NOT (g->lhs); } - assert (!g->shrunken); + KISSAT_assert (!g->shrunken); g->shrunken = true; rhs[2] = INVALID_LIT; g->arity = 2; g->tag = new_tag; - assert (rhs[0] < rhs[1]); - assert (rhs[0] != NOT (rhs[1])); + KISSAT_assert (rhs[0] < rhs[1]); + KISSAT_assert (rhs[0] != NOT (rhs[1])); LOGATE (g, "rewritten"); gate *h; unsigned hash; @@ -2085,7 +2087,7 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, check_and_gate_implied (closure, g); h = find_and_gate (closure, &hash, g); } else { - assert (new_tag == XOR_GATE); + KISSAT_assert (new_tag == XOR_GATE); check_xor_gate_implied (closure, g); h = find_xor_gate (closure, &hash, g); } @@ -2104,7 +2106,7 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, remove_gate (closure, g); g->hash = hash; index_gate (closure, g); - assert (g->arity == 2); + KISSAT_assert (g->arity == 2); for (all_rhs_literals_in_gate (lit, g)) if (lit != dst) if (lit != cond && lit != then_lit && lit != else_lit) @@ -2115,18 +2117,18 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, } } else { CLOGITEGATE (g, "rewritten"); - assert (rhs[0] != rhs[1]); - assert (rhs[0] != rhs[2]); - assert (rhs[1] != rhs[2]); - assert (rhs[0] != NOT (rhs[1])); - assert (rhs[0] != NOT (rhs[2])); - assert (rhs[1] != NOT (rhs[2])); + KISSAT_assert (rhs[0] != rhs[1]); + KISSAT_assert (rhs[0] != rhs[2]); + KISSAT_assert (rhs[1] != rhs[2]); + KISSAT_assert (rhs[0] != NOT (rhs[1])); + KISSAT_assert (rhs[0] != NOT (rhs[2])); + KISSAT_assert (rhs[1] != NOT (rhs[2])); check_ite_gate_implied (closure, g); unsigned hash; bool negate_lhs; gate *h = find_ite_gate (closure, &hash, &negate_lhs, g); - assert (lhs == g->lhs); - assert (not_lhs == NOT (g->lhs)); + KISSAT_assert (lhs == g->lhs); + KISSAT_assert (not_lhs == NOT (g->lhs)); if (h) { garbage = true; unsigned normalized_lhs = negate_lhs ? not_lhs : lhs; @@ -2143,7 +2145,7 @@ static void rewrite_ite_gate (closure *closure, gate *g, unsigned dst, CLOGITEGATE (g, "normalized"); g->hash = hash; index_gate (closure, g); - assert (g->arity == 3); + KISSAT_assert (g->arity == 3); for (all_rhs_literals_in_gate (lit, g)) if (lit != dst) if (lit != cond && lit != then_lit && lit != else_lit) @@ -2190,7 +2192,7 @@ typedef struct offsetsize offsetsize; static bool find_binary (kissat *solver, litpair *binaries, offsetsize *offsetsize, unsigned lit, unsigned other) { - assert (lit != other); + KISSAT_assert (lit != other); if (lit > other) SWAP (unsigned, lit, other); size_t l = offsetsize[lit].offset; @@ -2203,8 +2205,8 @@ static bool find_binary (kissat *solver, litpair *binaries, else if (tmp > other) r = m; else { - assert (binaries[m].lits[0] == lit); - assert (binaries[m].lits[1] == other); + KISSAT_assert (binaries[m].lits[0] == lit); + KISSAT_assert (binaries[m].lits[1] == other); #ifdef LOGGING LOGBINARY (lit, other, "found"); #else @@ -2230,7 +2232,7 @@ static void extract_binaries (closure *closure) { START (extractbinaries); litpair *binaries = BEGIN_STACK (closure->binaries); offsetsize *offsetsize; - CALLOC (offsetsize, LITS); + CALLOC (struct offsetsize, offsetsize, LITS); { litpair *end = END_STACK (closure->binaries); litpair *p = binaries; @@ -2240,7 +2242,7 @@ static void extract_binaries (closure *closure) { while (q != end && q->lits[0] == lit) q++; const size_t size = q - p; - assert (size), assert (size <= UINT_MAX); + KISSAT_assert (size), KISSAT_assert (size <= UINT_MAX); const size_t offset = p - binaries; if (size < 32) SORT (litpair, size, p, LESS_OTHER); @@ -2301,9 +2303,9 @@ static void extract_binaries (closure *closure) { { litpair *end = END_STACK (closure->binaries); litpair *added = binaries + before; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG const size_t after = end - binaries; - assert (after - before == extracted); + KISSAT_assert (after - before == extracted); #endif RADIX_SORT (litpair, uint64_t, extracted, added, rank_litpair); litpair *q = added; @@ -2338,7 +2340,7 @@ static void extract_binaries (closure *closure) { static gate *find_first_and_gate (closure *closure, unsigned lhs, unsigneds *lits) { kissat *const solver = closure->solver; - assert (!solver->watching); + KISSAT_assert (!solver->watching); mark *const marks = solver->marks; const unsigned not_lhs = NOT (lhs); @@ -2347,11 +2349,11 @@ static gate *find_first_and_gate (closure *closure, unsigned lhs, closure->negbincount[lhs]); unsigneds *const marked = &solver->analyzed; - assert (EMPTY_STACK (*marked)); + KISSAT_assert (EMPTY_STACK (*marked)); const unsigned arity = SIZE_STACK (*lits) - 1; unsigned matched = 0; - assert (1 < arity); + KISSAT_assert (1 < arity); watches *watches = &WATCHES (not_lhs); const watch *const end = END_WATCHES (*watches); @@ -2359,12 +2361,12 @@ static gate *find_first_and_gate (closure *closure, unsigned lhs, while (p != end) { const watch watch = *p++; - assert (watch.type.binary); + KISSAT_assert (watch.type.binary); const unsigned other = watch.binary.lit; const mark tmp = marks[other]; if (tmp) { matched++; - assert (~(tmp & 2)); + KISSAT_assert (~(tmp & 2)); marks[other] |= 2; PUSH_STACK (*marked, other); } @@ -2380,13 +2382,13 @@ static gate *find_first_and_gate (closure *closure, unsigned lhs, static gate *find_remaining_and_gate (closure *closure, unsigned lhs, unsigneds *lits) { kissat *const solver = closure->solver; - assert (!solver->watching); + KISSAT_assert (!solver->watching); mark *const marks = solver->marks; const unsigned not_lhs = NOT (lhs); if (marks[not_lhs] < 2) { LOG ("skipping no-candidate LHS %s", LOGLIT (lhs)); - return false; + return NULL; } LOG ("trying to find AND gate with remaining LHS %s", LOGLIT (lhs)); @@ -2395,7 +2397,7 @@ static gate *find_remaining_and_gate (closure *closure, unsigned lhs, const unsigned arity = SIZE_STACK (*lits) - 1; unsigned matched = 0; - assert (1 < arity); + KISSAT_assert (1 < arity); { watches *watches = &WATCHES (not_lhs); @@ -2403,7 +2405,7 @@ static gate *find_remaining_and_gate (closure *closure, unsigned lhs, const watch *p = BEGIN_WATCHES (*watches); while (p != end_watches) { const watch watch = *p++; - assert (watch.type.binary); + KISSAT_assert (watch.type.binary); const unsigned other = watch.binary.lit; mark mark = marks[other]; if (!mark) @@ -2411,19 +2413,19 @@ static gate *find_remaining_and_gate (closure *closure, unsigned lhs, matched++; if (!(mark & 2)) continue; - assert (!(mark & 4)); + KISSAT_assert (!(mark & 4)); marks[other] = mark | 4; } } { unsigneds *const marked = &solver->analyzed; - assert (!EMPTY_STACK (*marked)); + KISSAT_assert (!EMPTY_STACK (*marked)); unsigned *const begin_marked = BEGIN_STACK (*marked); const unsigned *const end_marked = END_STACK (*marked); unsigned *q = begin_marked; const unsigned *p = q; - assert (marks[not_lhs] == 3); + KISSAT_assert (marks[not_lhs] == 3); while (p != end_marked) { const unsigned lit = *p++; if (lit == not_lhs) { @@ -2431,7 +2433,7 @@ static gate *find_remaining_and_gate (closure *closure, unsigned lhs, continue; } mark mark = marks[lit]; - assert ((mark & 3) == 3); + KISSAT_assert ((mark & 3) == 3); if (mark & 4) { mark = 3; *q++ = lit; @@ -2442,8 +2444,8 @@ static gate *find_remaining_and_gate (closure *closure, unsigned lhs, } marks[lit] = mark; } - assert (q != end_marked); - assert (marks[not_lhs] == 1); + KISSAT_assert (q != end_marked); + KISSAT_assert (marks[not_lhs] == 1); SET_END_OF_STACK (*marked, q); LOG ("after filtering %zu LHS candidates remain", SIZE_STACK (*marked)); } @@ -2485,7 +2487,7 @@ static unsigned hash_binary (closure *closure, binary_clause *binary) { static bool indexed_binary (closure *closure, unsigned lit, unsigned other) { - assert (lit != other); + KISSAT_assert (lit != other); #ifdef LOGGING kissat *const solver = closure->solver; #endif @@ -2494,7 +2496,7 @@ static bool indexed_binary (closure *closure, unsigned lit, LOG ("did not find binary %s %s", LOGLIT (lit), LOGLIT (other)); return false; } - assert (bintab->size); + KISSAT_assert (bintab->size); SWAP (unsigned, lit, other); if (lit > other) SWAP (unsigned, lit, other); @@ -2508,7 +2510,7 @@ static bool indexed_binary (closure *closure, unsigned lit, while ((lit1 = table[pos].lits[1])) { if (lit1 == other) { lit0 = table[pos].lits[0]; - assert (lit0 < other); + KISSAT_assert (lit0 < other); if (lit0 == lit) { LOG ("found binary %s %s", LOGLIT (lit), LOGLIT (other)); return true; @@ -2525,9 +2527,9 @@ static bool indexed_binary (closure *closure, unsigned lit, static void extract_and_gates_with_base_clause (closure *closure, clause *c) { - assert (!c->garbage); + KISSAT_assert (!c->garbage); kissat *const solver = closure->solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); value *values = solver->values; unsigned arity_limit = MIN (GET_OPTION (congruenceandarity), MAX_ARITY); const unsigned size_limit = arity_limit + 1; @@ -2540,7 +2542,7 @@ static void extract_and_gates_with_base_clause (closure *closure, if (value < 0) continue; if (value > 0) { - assert (!solver->level); + KISSAT_assert (!solver->level); LOGCLS (c, "found satisfied %s in", LOGLIT (lit)); kissat_mark_clause_as_garbage (solver, c); return; @@ -2580,7 +2582,7 @@ static void extract_and_gates_with_base_clause (closure *closure, #ifndef INDEX_BINARY_CLAUSES mark *const marks = solver->marks; unsigneds *marked = &solver->analyzed; - assert (EMPTY_STACK (*marked)); + KISSAT_assert (EMPTY_STACK (*marked)); #endif for (unsigned *p = begin_lits; p != end_lits; p++) { const unsigned lit = *p, count = negbincount[lit]; @@ -2595,9 +2597,9 @@ static void extract_and_gates_with_base_clause (closure *closure, reduced_lits++; } } - assert (reduced_lits < end_lits); + KISSAT_assert (reduced_lits < end_lits); const size_t reduced_size = end_lits - reduced_lits; - assert (reduced_size); + KISSAT_assert (reduced_size); LOGCLS (c, "trying as base arity %u AND gate", arity); sort_lits_by_negbincount (closure, reduced_size, reduced_lits); #ifdef LOGGING @@ -2624,7 +2626,7 @@ static void extract_and_gates_with_base_clause (closure *closure, const unsigned lhs = *p; LOG ("trying LHS candidate literal %s with %u negated occurrences", LOGLIT (lhs), negbincount[lhs]); - assert (arity <= negbincount[lhs]); + KISSAT_assert (arity <= negbincount[lhs]); #ifdef INDEX_BINARY_CLAUSES const unsigned not_lhs = NOT (lhs); for (const unsigned *q = begin_lits; q != end_lits; q++) @@ -2641,7 +2643,7 @@ static void extract_and_gates_with_base_clause (closure *closure, #else if (first) { first = false; - assert (EMPTY_STACK (*marked)); + KISSAT_assert (EMPTY_STACK (*marked)); if (find_first_and_gate (closure, lhs, lits)) { #ifdef LOGGING extracted++; @@ -2680,7 +2682,7 @@ static clause *find_indexed_large_clause (closure *closure, unsigneds *lits) { kissat *const solver = closure->solver; size_t size_lits = SIZE_STACK (*lits); - assert (size_lits > 2); + KISSAT_assert (size_lits > 2); #ifdef LOGGING { unsigned *begin = BEGIN_STACK (*lits); @@ -2695,13 +2697,13 @@ static clause *find_indexed_large_clause (closure *closure, const value *const values = solver->values; mark *const marks = solver->marks; unsigneds *sorted = &solver->clause; - assert (EMPTY_STACK (*sorted)); + KISSAT_assert (EMPTY_STACK (*sorted)); for (all_stack (unsigned, lit, *lits)) { - assert (!values[lit]); + KISSAT_assert (!values[lit]); PUSH_STACK (*sorted, lit); marks[lit] = 1; } - assert (size_lits == SIZE_STACK (*sorted)); + KISSAT_assert (size_lits == SIZE_STACK (*sorted)); unsigned *begin_sorted = BEGIN_STACK (*sorted); sort_lits (solver, size_lits, begin_sorted); const unsigned hash = hash_lits (closure, 0, size_lits, begin_sorted); @@ -2714,7 +2716,7 @@ static clause *find_indexed_large_clause (closure *closure, if (hash_ref->hash == hash) { reference ref = hash_ref->ref; if (ref == INVALID_REF) { - assert (!hash); + KISSAT_assert (!hash); ref = 0; } clause *c = kissat_dereference_clause (solver, ref); @@ -2744,33 +2746,33 @@ static clause *find_indexed_large_clause (closure *closure, static clause *find_large_xor_side_clause (closure *closure, unsigneds *lits) { kissat *const solver = closure->solver; - assert (!solver->watching); + KISSAT_assert (!solver->watching); const unsigned *const largecount = closure->largecount; unsigned least_occurring_literal = INVALID_LIT; unsigned count_least_occurring = UINT_MAX; mark *marks = solver->marks; const size_t size_lits = SIZE_STACK (*lits); -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) const unsigned arity = size_lits - 1; #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG const unsigned count_limit = 1u << (arity - 1); #endif const value *const values = solver->values; LOGCOUNTEDLITS (size_lits, BEGIN_STACK (*lits), largecount, "trying to find arity %u XOR side clause", arity); for (all_stack (unsigned, lit, *lits)) { - assert (!values[lit]); + KISSAT_assert (!values[lit]); marks[lit] = 1; unsigned count = largecount[lit]; - assert (count_limit <= count); + KISSAT_assert (count_limit <= count); if (count >= count_least_occurring) continue; count_least_occurring = count; least_occurring_literal = lit; } clause *res = 0; - assert (least_occurring_literal != INVALID_LIT); + KISSAT_assert (least_occurring_literal != INVALID_LIT); LOG ("searching XOR side clause watched by %s#%u", LOGLIT (least_occurring_literal), count_least_occurring); watches *const watches = &WATCHES (least_occurring_literal); @@ -2794,7 +2796,7 @@ static clause *find_large_xor_side_clause (closure *closure, if (value > 0) { LOGCLS (c, "found satisfied %s in", LOGLIT (other)); kissat_mark_clause_as_garbage (solver, c); - assert (c->garbage); + KISSAT_assert (c->garbage); break; } if (marks[other]) @@ -2822,9 +2824,9 @@ static clause *find_large_xor_side_clause (closure *closure, static void extract_xor_gates_with_base_clause (closure *closure, clause *c) { - assert (!c->garbage); + KISSAT_assert (!c->garbage); kissat *const solver = closure->solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); const value *const values = solver->values; unsigned smallest = INVALID_LIT, largest = INVALID_LIT; const unsigned arity_limit = @@ -2852,8 +2854,8 @@ static void extract_xor_gates_with_base_clause (closure *closure, largest = smallest = lit; first = false; } else { - assert (smallest != INVALID_LIT); - assert (largest != INVALID_LIT); + KISSAT_assert (smallest != INVALID_LIT); + KISSAT_assert (largest != INVALID_LIT); if (lit < smallest) smallest = lit; if (lit > largest) { @@ -2877,7 +2879,7 @@ static void extract_xor_gates_with_base_clause (closure *closure, PUSH_STACK (*lits, lit); size++; } - assert (size == SIZE_STACK (*lits)); + KISSAT_assert (size == SIZE_STACK (*lits)); if (size < 3) { LOGCLS (c, "short XOR base clause"); return; @@ -2897,11 +2899,11 @@ static void extract_xor_gates_with_base_clause (closure *closure, return; } LOGCLS (c, "trying arity %u XOR base", arity); - assert (smallest != INVALID_LIT); - assert (largest != INVALID_LIT); + KISSAT_assert (smallest != INVALID_LIT); + KISSAT_assert (largest != INVALID_LIT); const unsigned end = 1u << arity; - assert (negated == parity_lits (solver, lits)); -#if !defined(NDEBUG) || defined(LOGGING) + KISSAT_assert (negated == parity_lits (solver, lits)); +#if !defined(KISSAT_NDEBUG) || defined(LOGGING) unsigned found = 0; #endif for (unsigned i = 0; i != end; i++) { @@ -2915,11 +2917,11 @@ static void extract_xor_gates_with_base_clause (closure *closure, #endif if (!d) return; - assert (!d->redundant); + KISSAT_assert (!d->redundant); } else - assert (!c->redundant); + KISSAT_assert (!c->redundant); inc_lits (solver, lits); -#if !defined(NDEBUG) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || defined(LOGGING) found++; #endif } @@ -2927,7 +2929,7 @@ static void extract_xor_gates_with_base_clause (closure *closure, inc_lits (solver, lits); LOGUNSIGNEDS2 (size, BEGIN_STACK (*lits), "back to original"); LOG ("found all needed %u matching clauses:", found); - assert (found == 1u << arity); + KISSAT_assert (found == 1u << arity); if (negated) { unsigned *p = BEGIN_STACK (*lits), lit; while (!NEGATED (lit = *p)) @@ -2958,9 +2960,9 @@ static void init_bintab (closure *closure) { size_t size2 = 1; while (size > size2) size2 *= 2; - assert (!limit || size2 <= 2 * size); + KISSAT_assert (!limit || size2 <= 2 * size); binary_hash_table *bintab = &closure->bintab; - CALLOC (bintab->table, size); + CALLOC (binary_hash_table, bintab->table, size); bintab->count = 0; bintab->size = size; bintab->size2 = size2; @@ -2968,7 +2970,7 @@ static void init_bintab (closure *closure) { solver, "allocated binary clause hash table of size %zu", size); } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG static bool binaries_hash_table_is_full (binary_hash_table *bintab) { if (bintab->size == MAX_HASH_TABLE_SIZE) @@ -2981,9 +2983,9 @@ static bool binaries_hash_table_is_full (binary_hash_table *bintab) { #endif static void index_binary (closure *closure, unsigned lit, unsigned other) { - assert (lit < other); + KISSAT_assert (lit < other); binary_hash_table *bintab = &closure->bintab; - assert (!binaries_hash_table_is_full (bintab)); + KISSAT_assert (!binaries_hash_table_is_full (bintab)); binary_clause binary = {.lits = {lit, other}}; const unsigned hash = hash_binary (closure, &binary); const size_t size = bintab->size; @@ -3011,9 +3013,9 @@ static void reset_bintab (closure *closure) { static void init_and_gate_extraction (closure *closure) { kissat *const solver = closure->solver; - assert (!solver->watching); + KISSAT_assert (!solver->watching); unsigned *negbincount; - CALLOC (negbincount, LITS); + CALLOC (unsigned, negbincount, LITS); litpairs *binaries = &closure->binaries; #ifdef INDEX_BINARY_CLAUSES init_bintab (closure); @@ -3027,7 +3029,7 @@ static void init_and_gate_extraction (closure *closure) { index_binary (closure, lit, other); #endif } -#ifndef QUIET +#ifndef KISSAT_QUIET size_t connected = SIZE_STACK (*binaries); kissat_very_verbose (solver, "connected %zu binary clauses", connected); #endif @@ -3051,9 +3053,9 @@ static void init_large_clauses (closure *closure, size_t expected) { size_t size2 = 1; while (size > size2) size2 *= 2; - assert (!expected || size2 <= 2 * size); + KISSAT_assert (!expected || size2 <= 2 * size); large_clause_hash_table *clauses = &closure->clauses; - CALLOC (clauses->table, size); + CALLOC (large_clause_hash_table, clauses->table, size); clauses->count = 0; clauses->size = size; clauses->size2 = size2; @@ -3061,7 +3063,7 @@ static void init_large_clauses (closure *closure, size_t expected) { solver, "allocated large clause hash table of size %zu", size); } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG static bool large_clause_hash_table_is_full (closure *closure) { if (closure->clauses.size == MAX_HASH_TABLE_SIZE) @@ -3074,7 +3076,7 @@ static bool large_clause_hash_table_is_full (closure *closure) { #endif static void index_large_clause (closure *closure, reference ref) { - assert (!large_clause_hash_table_is_full (closure)); + KISSAT_assert (!large_clause_hash_table_is_full (closure)); kissat *const solver = closure->solver; clause *c = kissat_dereference_clause (solver, ref); const value *const values = solver->values; @@ -3085,13 +3087,13 @@ static void index_large_clause (closure *closure, reference ref) { PUSH_STACK (*lits, lit); const size_t size_lits = SIZE_STACK (*lits); unsigned *begin_lits = BEGIN_STACK (*lits); - assert (3 <= size_lits); + KISSAT_assert (3 <= size_lits); sort_lits (solver, size_lits, begin_lits); const unsigned hash = hash_lits (closure, 0, size_lits, begin_lits); large_clause_hash_table *clauses = &closure->clauses; if (!hash && !ref) { ref = INVALID_REF; - assert (ref); + KISSAT_assert (ref); } const size_t hash_size = clauses->size; const size_t hash_size2 = clauses->size2; @@ -3102,7 +3104,7 @@ static void index_large_clause (closure *closure, reference ref) { pos = 0; clause->hash = hash; clause->ref = ref; - assert (valid_large_clause (clause)); + KISSAT_assert (valid_large_clause (clause)); clauses->count++; LOGCLS (c, "indexed"); } @@ -3117,15 +3119,15 @@ static void reset_large_clauses (closure *closure) { static void init_xor_gate_extraction (closure *closure, references *candidates) { - assert (EMPTY_STACK (*candidates)); + KISSAT_assert (EMPTY_STACK (*candidates)); kissat *const solver = closure->solver; - assert (!solver->watching); + KISSAT_assert (!solver->watching); const unsigned arity_limit = GET_OPTION (congruencexorarity); const unsigned size_limit = arity_limit + 1; clause *last_irredundant = kissat_last_irredundant_clause (solver); const value *const values = solver->values; unsigned *largecount; - CALLOC (largecount, LITS); + CALLOC (unsigned, largecount, LITS); for (all_clauses (c)) { if (c->garbage) continue; @@ -3134,6 +3136,7 @@ static void init_xor_gate_extraction (closure *closure, if (c->redundant) continue; unsigned size = 0; + int continue_counting_next_clause = 0; for (all_literals_in_clause (lit, c)) { const value value = values[lit]; if (value < 0) @@ -3141,12 +3144,18 @@ static void init_xor_gate_extraction (closure *closure, if (value > 0) { LOGCLS (c, "satisfied %s in", LOGLIT (lit)); kissat_mark_clause_as_garbage (solver, c); - goto CONTINUE_COUNTING_NEXT_CLAUSE; + continue_counting_next_clause = 1; + break; + } + if (size == size_limit) { + continue_counting_next_clause = 1; + break; } - if (size == size_limit) - goto CONTINUE_COUNTING_NEXT_CLAUSE; size++; } + if(continue_counting_next_clause) { + continue; + } if (size < 3) continue; for (all_literals_in_clause (lit, c)) @@ -3154,9 +3163,8 @@ static void init_xor_gate_extraction (closure *closure, largecount[lit]++; reference ref = kissat_reference_clause (solver, c); PUSH_STACK (*candidates, ref); - CONTINUE_COUNTING_NEXT_CLAUSE:; } -#ifndef QUIET +#ifndef KISSAT_QUIET size_t considered_clauses = IRREDUNDANT_CLAUSES; size_t original_candidates = SIZE_STACK (*candidates); kissat_very_verbose ( @@ -3171,7 +3179,7 @@ static void init_xor_gate_extraction (closure *closure, for (unsigned round = 1; round <= counting_rounds; round++) { size_t removed = 0; unsigned *new_largecount; - CALLOC (new_largecount, LITS); + CALLOC (unsigned, new_largecount, LITS); const reference *const end_candidates = END_STACK (*candidates); reference *q = BEGIN_STACK (*candidates), *p = q; while (p != end_candidates) { @@ -3181,8 +3189,8 @@ static void init_xor_gate_extraction (closure *closure, for (all_literals_in_clause (lit, c)) if (!values[lit]) size++; - assert (3 <= size); - assert (size <= size_limit); + KISSAT_assert (3 <= size); + KISSAT_assert (size <= size_limit); const unsigned arity = size - 1; const unsigned needed_clauses = 1u << (arity - 1); for (all_literals_in_clause (lit, c)) @@ -3201,7 +3209,7 @@ static void init_xor_gate_extraction (closure *closure, SET_END_OF_STACK (*candidates, q); if (!removed) break; -#ifndef QUIET +#ifndef KISSAT_QUIET size_t remaining_candidates = SIZE_STACK (*candidates); const char *how_often; char buffer[64]; @@ -3233,7 +3241,7 @@ static void init_xor_gate_extraction (closure *closure, index_large_clause (closure, ref); #endif } -#ifndef QUIET +#ifndef KISSAT_QUIET size_t connected = SIZE_STACK (*candidates); kissat_very_verbose (solver, "connected %zu large clauses %.0f%%", connected, @@ -3252,12 +3260,12 @@ static void reset_xor_gate_extraction (closure *closure) { static void init_ite_gate_extraction (closure *closure, references *candidates) { - assert (EMPTY_STACK (*candidates)); + KISSAT_assert (EMPTY_STACK (*candidates)); kissat *const solver = closure->solver; clause *last_irredundant = kissat_last_irredundant_clause (solver); const value *const values = solver->values; unsigned *largecount; - CALLOC (largecount, LITS); + CALLOC (unsigned, largecount, LITS); references ternary; INIT_STACK (ternary); for (all_clauses (c)) { @@ -3268,6 +3276,7 @@ static void init_ite_gate_extraction (closure *closure, if (c->redundant) continue; unsigned size = 0; + int continue_counting_next_clause = 0; for (all_literals_in_clause (lit, c)) { const value value = values[lit]; if (value < 0) @@ -3275,24 +3284,29 @@ static void init_ite_gate_extraction (closure *closure, if (value > 0) { LOGCLS (c, "satisfied %s in", LOGLIT (lit)); kissat_mark_clause_as_garbage (solver, c); - goto CONTINUE_COUNTING_NEXT_CLAUSE; + continue_counting_next_clause = 1; + break; + } + if (size == 3) { + continue_counting_next_clause = 1; + break; } - if (size == 3) - goto CONTINUE_COUNTING_NEXT_CLAUSE; size++; } + if(continue_counting_next_clause) { + continue; + } if (size < 3) continue; - assert (size == 3); + KISSAT_assert (size == 3); const reference ref = kissat_reference_clause (solver, c); PUSH_STACK (ternary, ref); LOGCLS (c, "counting original ITE gate base"); for (all_literals_in_clause (lit, c)) if (!values[lit]) largecount[lit]++; - CONTINUE_COUNTING_NEXT_CLAUSE:; } -#ifndef QUIET +#ifndef KISSAT_QUIET size_t counted = SIZE_STACK (ternary); kissat_very_verbose (solver, "counted %zu ternary ITE clauses " @@ -3304,7 +3318,7 @@ static void init_ite_gate_extraction (closure *closure, #endif for (all_stack (reference, ref, ternary)) { clause *c = kissat_dereference_clause (solver, ref); - assert (!c->garbage); + KISSAT_assert (!c->garbage); unsigned positive = 0, negative = 0, twice = 0; for (all_literals_in_clause (lit, c)) { if (values[lit]) @@ -3314,7 +3328,7 @@ static void init_ite_gate_extraction (closure *closure, if (!count_not_lit) goto CONTINUE_WITH_NEXT_TERNARY_CLAUSE; const unsigned count_lit = largecount[lit]; - assert (count_lit); + KISSAT_assert (count_lit); if (count_lit > 1 && count_not_lit > 1) twice++; if (NEGATED (lit)) @@ -3324,7 +3338,7 @@ static void init_ite_gate_extraction (closure *closure, } if (twice < 2) goto CONTINUE_WITH_NEXT_TERNARY_CLAUSE; -#ifndef QUIET +#ifndef KISSAT_QUIET connected++; #endif kissat_connect_clause (solver, c); @@ -3333,7 +3347,7 @@ static void init_ite_gate_extraction (closure *closure, CONTINUE_WITH_NEXT_TERNARY_CLAUSE:; } RELEASE_STACK (ternary); -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_very_verbose (solver, "connected %zu ITE clauses " "(%.0f%% of %" PRIu64 " counted clauses)", @@ -3375,7 +3389,7 @@ static void unmark_all (unsigneds *marked, signed char *marks) { static void copy_conditional_equivalences (kissat *solver, unsigned lit, watches *watches, litpairs *condbin) { - assert (EMPTY_STACK (*condbin)); + KISSAT_assert (EMPTY_STACK (*condbin)); const value *const values = solver->values; const watch *const begin_watches = BEGIN_WATCHES (*watches); const watch *const end_watches = END_WATCHES (*watches); @@ -3394,17 +3408,17 @@ static void copy_conditional_equivalences (kissat *solver, unsigned lit, if (first == INVALID_LIT) first = other; else { - assert (second == INVALID_LIT); + KISSAT_assert (second == INVALID_LIT); second = other; } } - assert (first != INVALID_LIT); - assert (second != INVALID_LIT); + KISSAT_assert (first != INVALID_LIT); + KISSAT_assert (second != INVALID_LIT); litpair pair; if (first < second) pair = (litpair){.lits = {first, second}}; else { - assert (second < first); + KISSAT_assert (second < first); pair = (litpair){.lits = {second, first}}; } LOG ("literal %s conditional binary clause %s %s", LOGLIT (lit), @@ -3439,7 +3453,7 @@ static bool find_litpair_second_literal (unsigned lit, const litpair *begin, const litpair *l = begin, *r = end; while (l != r) { const litpair *m = l + (r - l) / 2; - assert (begin <= m), assert (m < end); + KISSAT_assert (begin <= m), KISSAT_assert (m < end); unsigned other = m->lits[1]; if (other < lit) l = m + 1; @@ -3456,12 +3470,12 @@ static void search_condeq (closure *closure, unsigned lit, unsigned pos_lit, unsigned neg_lit, const litpair *neg_begin, const litpair *neg_end, litpairs *condeq) { kissat *const solver = closure->solver; - assert (neg_lit == NOT (pos_lit)); - assert (pos_begin < pos_end); - assert (neg_begin < neg_end); - assert (pos_begin->lits[0] == pos_lit); - assert (neg_begin->lits[0] == neg_lit); - assert (pos_end <= neg_begin || neg_end <= pos_begin); + KISSAT_assert (neg_lit == NOT (pos_lit)); + KISSAT_assert (pos_begin < pos_end); + KISSAT_assert (neg_begin < neg_end); + KISSAT_assert (pos_begin->lits[0] == pos_lit); + KISSAT_assert (neg_begin->lits[0] == neg_lit); + KISSAT_assert (pos_end <= neg_begin || neg_end <= pos_begin); for (const litpair *p = pos_begin; p != pos_end; p++) { const unsigned other = p->lits[1]; const unsigned not_other = NOT (other); @@ -3473,8 +3487,8 @@ static void search_condeq (closure *closure, unsigned lit, unsigned pos_lit, first = pos_lit, second = not_other; LOG ("found conditional %s equivalence %s = %s", LOGLIT (lit), LOGLIT (first), LOGLIT (second)); - assert (!NEGATED (first)); - assert (first < second); + KISSAT_assert (!NEGATED (first)); + KISSAT_assert (first < second); check_ternary (closure, lit, first, NOT (second)); check_ternary (closure, lit, NOT (first), second); litpair equivalence = {.lits = {first, second}}; @@ -3495,7 +3509,7 @@ static void search_condeq (closure *closure, unsigned lit, unsigned pos_lit, static void extract_condeq_pairs (closure *closure, unsigned lit, litpairs *condbin, litpairs *condeq) { -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) kissat *const solver = closure->solver; #endif const litpair *const begin = BEGIN_STACK (*condbin); @@ -3511,9 +3525,9 @@ static void extract_condeq_pairs (closure *closure, unsigned lit, pos_begin++; } for (;;) { - assert (pos_begin != end); - assert (next_lit == pos_begin->lits[0]); - assert (!NEGATED (next_lit)); + KISSAT_assert (pos_begin != end); + KISSAT_assert (next_lit == pos_begin->lits[0]); + KISSAT_assert (!NEGATED (next_lit)); const unsigned pos_lit = next_lit; const litpair *pos_end = pos_begin + 1; for (;;) { @@ -3524,8 +3538,8 @@ static void extract_condeq_pairs (closure *closure, unsigned lit, break; pos_end++; } - assert (pos_end != end); - assert (next_lit == pos_end->lits[0]); + KISSAT_assert (pos_end != end); + KISSAT_assert (next_lit == pos_end->lits[0]); const unsigned neg_lit = NOT (pos_lit); if (next_lit != neg_lit) { if (NEGATED (next_lit)) { @@ -3579,7 +3593,7 @@ static void extract_condeq_pairs (closure *closure, unsigned lit, } if (neg_end == end) return; - assert (next_lit == neg_end->lits[0]); + KISSAT_assert (next_lit == neg_end->lits[0]); if (NEGATED (next_lit)) { pos_begin = neg_end + 1; for (;;) { @@ -3599,9 +3613,9 @@ static void find_conditional_equivalences (closure *closure, unsigned lit, watches *watches, litpairs *condbin, litpairs *condeq) { - assert (EMPTY_STACK (*condbin)); - assert (EMPTY_STACK (*condeq)); - assert (SIZE_WATCHES (*watches) > 1); + KISSAT_assert (EMPTY_STACK (*condbin)); + KISSAT_assert (EMPTY_STACK (*condeq)); + KISSAT_assert (SIZE_WATCHES (*watches) > 1); kissat *const solver = closure->solver; copy_conditional_equivalences (solver, lit, watches, condbin); sort_pairs (solver, condbin); @@ -3630,7 +3644,7 @@ static void find_conditional_equivalences (closure *closure, unsigned lit, static void merge_condeq (closure *closure, unsigned cond, litpairs *condeq, litpairs *not_condeq) { kissat *solver = closure->solver; - assert (!NEGATED (cond)); + KISSAT_assert (!NEGATED (cond)); const litpair *const begin_condeq = BEGIN_STACK (*condeq); const litpair *const end_condeq = END_STACK (*condeq); const litpair *const begin_not_condeq = BEGIN_STACK (*not_condeq); @@ -3641,7 +3655,7 @@ static void merge_condeq (closure *closure, unsigned cond, litpairs *condeq, litpair cond_pair = *p++; const unsigned lhs = cond_pair.lits[0]; const unsigned then_lit = cond_pair.lits[1]; - assert (!NEGATED (lhs)); + KISSAT_assert (!NEGATED (lhs)); while (q != end_not_condeq && q->lits[0] < lhs) q++; while (q != end_not_condeq && q->lits[0] == lhs) { @@ -3658,7 +3672,7 @@ static void extract_ite_gates_of_literal (closure *closure, unsigned lit, unsigned not_lit, watches *lit_watches, watches *not_lit_watches) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG kissat *solver = closure->solver; #endif litpairs *condbin = closure->condbin; @@ -3706,8 +3720,8 @@ static void extract_ite_gates_of_variable (closure *closure, unsigned idx) { static void mark_third_literal_in_ternary_clauses ( kissat *solver, const value *const values, unsigneds *marked, mark *marks, unsigned a, unsigned b) { - assert (!solver->watching); - assert (EMPTY_STACK (*marked)); + KISSAT_assert (!solver->watching); + KISSAT_assert (EMPTY_STACK (*marked)); watches *a_watches = &WATCHES (a); watches *b_watches = &WATCHES (b); const size_t size_a = SIZE_WATCHES (*a_watches); @@ -3717,10 +3731,10 @@ static void mark_third_literal_in_ternary_clauses ( const watch *const end = END_WATCHES (*watches); for (const watch *p = begin; p != end; p++) { const watch watch = *p; - assert (!watch.type.binary); + KISSAT_assert (!watch.type.binary); const reference ref = watch.large.ref; clause *c = kissat_dereference_clause (solver, ref); - assert (!c->garbage); + KISSAT_assert (!c->garbage); unsigned third = INVALID_LIT, found = 0; for (all_literals_in_clause (lit, c)) { if (values[lit]) @@ -3733,10 +3747,10 @@ static void mark_third_literal_in_ternary_clauses ( goto NEXT_WATCH; third = lit; } - assert (found <= 2); + KISSAT_assert (found <= 2); if (found < 2) goto NEXT_WATCH; - assert (third != INVALID_LIT); + KISSAT_assert (third != INVALID_LIT); if (third == INVALID_LIT) goto NEXT_WATCH; if (marks[third]) @@ -3752,7 +3766,7 @@ static void extract_ite_gate (closure *closure, const value *const values, mark *const marks, unsigned lhs, unsigned cond, unsigned then_lit) { kissat *const solver = closure->solver; - assert (!solver->watching); + KISSAT_assert (!solver->watching); unsigned a = NOT (lhs), b = cond; watches *a_watches = &WATCHES (a); watches *b_watches = &WATCHES (b); @@ -3763,10 +3777,10 @@ static void extract_ite_gate (closure *closure, const value *const values, const watch *const end = END_WATCHES (*watches); for (const watch *p = begin; p != end; p++) { const watch watch = *p; - assert (!watch.type.binary); + KISSAT_assert (!watch.type.binary); const reference ref = watch.large.ref; clause *c = kissat_dereference_clause (solver, ref); - assert (!c->garbage); + KISSAT_assert (!c->garbage); unsigned else_lit = INVALID_LIT, found = 0; for (all_literals_in_clause (lit, c)) { if (values[lit]) @@ -3779,10 +3793,10 @@ static void extract_ite_gate (closure *closure, const value *const values, goto NEXT_WATCH; else_lit = lit; } - assert (found <= 2); + KISSAT_assert (found <= 2); if (found < 2) goto NEXT_WATCH; - assert (else_lit != INVALID_LIT); + KISSAT_assert (else_lit != INVALID_LIT); unsigned not_else_lit = NOT (else_lit); if (!marks[not_else_lit]) goto NEXT_WATCH; @@ -3797,9 +3811,9 @@ static void extract_ite_gate (closure *closure, const value *const values, static void extract_ite_gates_with_base_clause (closure *closure, clause *c) { - assert (!c->garbage); + KISSAT_assert (!c->garbage); kissat *const solver = closure->solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); const value *const values = solver->values; const unsigned *const largecount = closure->largecount; unsigneds *lits = &closure->lits; @@ -3818,7 +3832,7 @@ static void extract_ite_gates_with_base_clause (closure *closure, sum ^= lit; } const size_t size = SIZE_STACK (*lits); - assert (size <= 3); + KISSAT_assert (size <= 3); if (size < 3) return; mark *const marks = solver->marks; @@ -3866,8 +3880,8 @@ static void extract_and_gates (closure *closure) { if (!GET_OPTION (congruenceands)) return; START (extractands); -#ifndef QUIET - const statistics *s = &solver->statistics; +#ifndef KISSAT_QUIET + const statistics *s = &solver->statistics_; const uint64_t matched_before = s->congruent_matched_ands; const uint64_t gates_before = s->congruent_gates_ands; #endif @@ -3887,7 +3901,7 @@ static void extract_and_gates (closure *closure) { extract_and_gates_with_base_clause (closure, c); } reset_and_gate_extraction (closure); -#ifndef QUIET +#ifndef KISSAT_QUIET const uint64_t matched = s->congruent_matched_ands - matched_before; const uint64_t extracted = s->congruent_gates_ands - gates_before; const uint64_t found = matched + extracted; @@ -3909,8 +3923,8 @@ static void extract_xor_gates (closure *closure) { INIT_STACK (candidates); init_xor_gate_extraction (closure, &candidates); SHRINK_STACK (candidates); -#ifndef QUIET - const statistics *s = &solver->statistics; +#ifndef KISSAT_QUIET + const statistics *s = &solver->statistics_; const uint64_t matched_before = s->congruent_matched_xors; const uint64_t gates_before = s->congruent_gates_xors; #endif @@ -3926,7 +3940,7 @@ static void extract_xor_gates (closure *closure) { } reset_xor_gate_extraction (closure); RELEASE_STACK (candidates); -#ifndef QUIET +#ifndef KISSAT_QUIET const uint64_t matched = s->congruent_matched_xors - matched_before; const uint64_t extracted = s->congruent_gates_xors - gates_before; const uint64_t found = matched + extracted; @@ -3947,8 +3961,8 @@ static void extract_ite_gates (closure *closure) { references candidates; INIT_STACK (candidates); init_ite_gate_extraction (closure, &candidates); -#ifndef QUIET - const statistics *s = &solver->statistics; +#ifndef KISSAT_QUIET + const statistics *s = &solver->statistics_; const uint64_t matched_before = s->congruent_matched_ites; const uint64_t gates_before = s->congruent_gates_ites; #endif @@ -3973,7 +3987,7 @@ static void extract_ite_gates (closure *closure) { #endif reset_ite_gate_extraction (closure); RELEASE_STACK (candidates); -#ifndef QUIET +#ifndef KISSAT_QUIET const uint64_t matched = s->congruent_matched_ites - matched_before; const uint64_t extracted = s->congruent_gates_ites - gates_before; const uint64_t found = matched + extracted; @@ -4000,14 +4014,14 @@ static void reset_extraction (closure *closure) { static void extract_gates (closure *closure) { kissat *const solver = closure->solver; START (extract); - assert (!solver->level); -#ifndef QUIET - const statistics *s = &solver->statistics; + KISSAT_assert (!solver->level); +#ifndef KISSAT_QUIET + const statistics *s = &solver->statistics_; const uint64_t before = s->congruent_gates + s->congruent_matched; #endif init_extraction (closure); extract_binaries (closure); - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); extract_and_gates (closure); if (!solver->inconsistent && !TERMINATED (congruence_terminated_4)) { extract_xor_gates (closure); @@ -4015,7 +4029,7 @@ static void extract_gates (closure *closure) { extract_ite_gates (closure); } reset_extraction (closure); -#ifndef QUIET +#ifndef KISSAT_QUIET const uint64_t after = s->congruent_gates + s->congruent_matched; const uint64_t found = after - before; kissat_phase (solver, "congruence", GET (closures), @@ -4027,9 +4041,9 @@ static void extract_gates (closure *closure) { static void find_units (closure *closure) { kissat *const solver = closure->solver; - assert (solver->watching); - assert (!solver->inconsistent); - assert (kissat_propagated (solver)); + KISSAT_assert (solver->watching); + KISSAT_assert (!solver->inconsistent); + KISSAT_assert (kissat_propagated (solver)); closure->units = solver->propagate; unsigneds *marked = &solver->analyzed; mark *const marks = solver->marks; @@ -4043,7 +4057,7 @@ static void find_units (closure *closure) { watches *const watches = &WATCHES (lit); const watch *p = BEGIN_WATCHES (*watches); const watch *const end = END_WATCHES (*watches); - assert (EMPTY_STACK (*marked)); + KISSAT_assert (EMPTY_STACK (*marked)); while (p != end) { const watch watch = *p++; if (!watch.type.binary) @@ -4070,8 +4084,8 @@ static void find_units (closure *closure) { unmark_all (marked, marks); } } - assert (EMPTY_STACK (*marked)); -#ifndef QUIET + KISSAT_assert (EMPTY_STACK (*marked)); +#ifndef KISSAT_QUIET kissat_very_verbose (solver, "found %zu units", units); #else (void) units; @@ -4080,11 +4094,11 @@ static void find_units (closure *closure) { static void find_equivalences (closure *closure) { kissat *const solver = closure->solver; - assert (solver->watching); - assert (!solver->inconsistent); + KISSAT_assert (solver->watching); + KISSAT_assert (!solver->inconsistent); unsigneds *const marked = &solver->analyzed; mark *const marks = solver->marks; - assert (EMPTY_STACK (*marked)); + KISSAT_assert (EMPTY_STACK (*marked)); for (all_variables (idx)) { RESTART: if (!ACTIVE (idx)) @@ -4093,7 +4107,7 @@ static void find_equivalences (closure *closure) { watches *lit_watches = &WATCHES (lit); const watch *p = BEGIN_WATCHES (*lit_watches); const watch *const end_lit_watches = END_WATCHES (*lit_watches); - assert (EMPTY_STACK (*marked)); + KISSAT_assert (EMPTY_STACK (*marked)); while (p != end_lit_watches) { const watch watch = *p++; if (!watch.type.binary) @@ -4138,8 +4152,8 @@ static void find_equivalences (closure *closure) { } unmark_all (marked, marks); } - assert (EMPTY_STACK (*marked)); -#ifndef QUIET + KISSAT_assert (EMPTY_STACK (*marked)); +#ifndef KISSAT_QUIET size_t found = SIZE_FIFO (closure->schedule); kissat_very_verbose (solver, "found %zu equivalences", found); #endif @@ -4148,7 +4162,7 @@ static void find_equivalences (closure *closure) { static bool simplify_gates (closure *closure, unsigned lit) { kissat *const solver = closure->solver; LOG ("simplifying gates with RHS literal %s", LOGLIT (lit)); - assert (solver->values[lit]); + KISSAT_assert (solver->values[lit]); gates *lit_occurrences = closure->occurrences + lit; for (all_pointers (gate, g, *lit_occurrences)) if (!simplify_gate (closure, g)) @@ -4176,7 +4190,7 @@ static bool propagate_unit (closure *closure, unsigned lit) { kissat *const solver = closure->solver; LOG ("propagation of congruence unit %s", LOGLIT (lit)); (void) solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); const unsigned not_lit = NOT (lit); return simplify_gates (closure, lit) && simplify_gates (closure, not_lit); } @@ -4184,7 +4198,7 @@ static bool propagate_unit (closure *closure, unsigned lit) { static bool propagate_equivalence (closure *closure, unsigned lit) { kissat *const solver = closure->solver; LOG ("propagation of congruence equivalence %s", CLOGREPR (lit)); - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); if (VALUE (lit)) return true; const unsigned lit_repr = find_repr (closure, lit); @@ -4198,7 +4212,7 @@ static bool propagate_equivalence (closure *closure, unsigned lit) { static bool propagate_units (closure *closure) { kissat *const solver = closure->solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); const unsigned_array *const trail = &solver->trail; while (closure->units != trail->end) if (!propagate_unit (closure, *closure->units++)) @@ -4208,7 +4222,7 @@ static bool propagate_units (closure *closure) { static size_t propagate_units_and_equivalences (closure *closure) { kissat *const solver = closure->solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); START (merge); unsigned_fifo *schedule = &closure->schedule; size_t propagated = 0; @@ -4219,7 +4233,7 @@ static size_t propagate_units_and_equivalences (closure *closure) { if (!propagate_equivalence (closure, lit)) break; } -#ifndef QUIET +#ifndef KISSAT_QUIET const size_t units = closure->units - solver->trail.begin; kissat_very_verbose (solver, "propagated %zu congruence units", units); kissat_very_verbose (solver, "propagated %zu congruence equivalences", @@ -4229,7 +4243,7 @@ static size_t propagate_units_and_equivalences (closure *closure) { return propagated; } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG static void dump_closure_literal (closure *closure, unsigned ilit) { kissat *const solver = closure->solver; @@ -4241,7 +4255,7 @@ static void dump_closure_literal (closure *closure, unsigned ilit) { printf ("[%u(%d)]", repr_ilit, repr_elit); } const int value = VALUE (ilit); - assert (!solver->level); + KISSAT_assert (!solver->level); if (value) printf ("@0=%d", value); } @@ -4344,7 +4358,7 @@ void kissat_dump_closure (closure *closure) { #endif static bool find_subsuming_clause (closure *closure, clause *c) { - assert (!c->garbage); + KISSAT_assert (!c->garbage); kissat *const solver = closure->solver; const reference c_ref = kissat_reference_clause (solver, c); const value *const values = solver->values; @@ -4353,15 +4367,15 @@ static bool find_subsuming_clause (closure *closure, clause *c) { const unsigned *const end_lits = c->lits + c->size; for (const unsigned *p = c->lits; p != end_lits; p++) { const unsigned lit = *p; - assert (values[lit] <= 0); + KISSAT_assert (values[lit] <= 0); const unsigned repr_lit = find_repr (closure, lit); const value value_repr_lit = values[repr_lit]; - assert (value_repr_lit <= 0); + KISSAT_assert (value_repr_lit <= 0); if (value_repr_lit < 0) continue; if (marks[repr_lit]) continue; - assert (!marks[NOT (repr_lit)]); + KISSAT_assert (!marks[NOT (repr_lit)]); marks[repr_lit] = 1; } } @@ -4375,25 +4389,25 @@ static bool find_subsuming_clause (closure *closure, clause *c) { const watch *p = BEGIN_WATCHES (*watches); const watch *const end = END_WATCHES (*watches); const size_t count = end - p; - assert (count <= UINT_MAX); + KISSAT_assert (count <= UINT_MAX); if (count < count_least_occurring) { count_least_occurring = count; least_occurring_literal = repr_lit; } while (p != end) { const watch watch = *p++; - assert (!watch.type.binary); + KISSAT_assert (!watch.type.binary); const reference d_ref = watch.large.ref; clause *const d = kissat_dereference_clause (solver, d_ref); - assert (c != d); - assert (!d->garbage); + KISSAT_assert (c != d); + KISSAT_assert (!d->garbage); if (!c->redundant && d->redundant) continue; for (all_literals_in_clause (other, d)) { const value value = values[other]; if (value < 0) continue; - assert (!value); + KISSAT_assert (!value); const unsigned repr_other = find_repr (closure, other); if (!marks[repr_other]) goto CONTINUE_WITH_NEXT_CLAUSE; @@ -4417,8 +4431,8 @@ FOUND_SUBSUMING: INC (congruent_subsumed); return true; } else { - assert (least_occurring_literal != INVALID_LIT); - assert (count_least_occurring < UINT_MAX); + KISSAT_assert (least_occurring_literal != INVALID_LIT); + KISSAT_assert (count_least_occurring < UINT_MAX); LOGCLS (c, "forward subsumption failed of"); LOG ("connecting %u occurring %s", count_least_occurring, LOGLIT (least_occurring_literal)); @@ -4450,10 +4464,10 @@ static void forward_subsume_matching_clauses (closure *closure) { INIT_STACK (binaries); kissat_enter_dense_mode (solver, &binaries); bool *matchable; -#ifndef QUIET +#ifndef KISSAT_QUIET unsigned count_matchable = 0; #endif - CALLOC (matchable, VARS); + CALLOC (bool, matchable, VARS); for (all_variables (idx)) if (ACTIVE (idx)) { const unsigned lit = LIT (idx); @@ -4464,14 +4478,14 @@ static void forward_subsume_matching_clauses (closure *closure) { if (!matchable[idx]) { LOG ("matchable %s", LOGVAR (idx)); matchable[idx] = true; -#ifndef QUIET +#ifndef KISSAT_QUIET count_matchable++; #endif } if (!matchable[repr_idx]) { LOG ("matchable %s", LOGVAR (repr_idx)); matchable[repr_idx] = true; -#ifndef QUIET +#ifndef KISSAT_QUIET count_matchable++; #endif } @@ -4493,7 +4507,7 @@ static void forward_subsume_matching_clauses (closure *closure) { break; potential++; bool contains_matchable = false; - assert (EMPTY_STACK (*marked)); + KISSAT_assert (EMPTY_STACK (*marked)); LOGREPRCLS (c, closure->repr, "considering"); for (all_literals_in_clause (lit, c)) { const value value = values[lit]; @@ -4510,7 +4524,7 @@ static void forward_subsume_matching_clauses (closure *closure) { contains_matchable = true; } const unsigned repr = find_repr (closure, lit); - assert (!values[repr]); + KISSAT_assert (!values[repr]); if (marks[repr]) continue; const unsigned not_repr = NOT (repr); @@ -4534,12 +4548,12 @@ static void forward_subsume_matching_clauses (closure *closure) { continue; } const reference ref = kissat_reference_clause (solver, c); - assert (size <= UINT_MAX); - refsize refsize = {.ref = ref, .size = size}; + KISSAT_assert (size <= UINT_MAX); + refsize refsize = {.ref = ref, .size = (unsigned)size}; PUSH_STACK (candidates, refsize); } DEALLOC (matchable, VARS); -#ifndef QUIET +#ifndef KISSAT_QUIET const size_t size_candidates = SIZE_STACK (candidates); kissat_very_verbose ( solver, "considering %zu matchable subsumption candidates %.0f%%", @@ -4548,19 +4562,19 @@ static void forward_subsume_matching_clauses (closure *closure) { (void) potential; #endif sort_references_by_clause_size (solver, &candidates); -#ifndef QUIET +#ifndef KISSAT_QUIET size_t tried = 0, subsumed = 0; #endif for (all_stack (refsize, refsize, candidates)) { if (TERMINATED (congruence_terminated_7)) break; -#ifndef QUIET +#ifndef KISSAT_QUIET tried++; #endif const unsigned ref = refsize.ref; clause *c = kissat_dereference_clause (solver, ref); if (find_subsuming_clause (closure, c)) { -#ifndef QUIET +#ifndef KISSAT_QUIET subsumed++; #endif } @@ -4578,15 +4592,15 @@ bool kissat_congruence (kissat *solver) { if (solver->inconsistent) return false; kissat_check_statistics (solver); - assert (!solver->level); - assert (solver->probing); - assert (solver->watching); + KISSAT_assert (!solver->level); + KISSAT_assert (solver->probing); + KISSAT_assert (solver->watching); if (!GET_OPTION (congruence)) return false; if (!GET_OPTION (congruenceands) && !GET_OPTION (congruenceites) && !GET_OPTION (congruencexors)) return false; - if (GET_OPTION (congruenceonce) && solver->statistics.closures) + if (GET_OPTION (congruenceonce) && solver->statistics_.closures) return false; if (TERMINATED (congruence_terminated_8)) return false; @@ -4618,8 +4632,8 @@ bool kissat_congruence (kissat *solver) { kissat_phase (solver, "congruence", GET (closures), "merged %u equivalent variables %.2f%%", equivalent, kissat_percent (equivalent, solver->active)); - assert (solver->active >= equivalent); -#ifndef QUIET + KISSAT_assert (solver->active >= equivalent); +#ifndef KISSAT_QUIET solver->active -= equivalent; REPORT (!equivalent, 'c'); if (!solver->inconsistent) @@ -4633,3 +4647,5 @@ bool kissat_congruence (kissat *solver) { kissat_check_statistics (solver); return equivalent; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/congruence.h b/src/sat/kissat/congruence.h index 84e1eb643..79a2ff0f6 100644 --- a/src/sat/kissat/congruence.h +++ b/src/sat/kissat/congruence.h @@ -3,7 +3,12 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_congruence (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/cover.h b/src/sat/kissat/cover.h index f5a82b71e..6c8eb1ee6 100644 --- a/src/sat/kissat/cover.h +++ b/src/sat/kissat/cover.h @@ -4,6 +4,9 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define COVER(COND) \ ((COND) ? \ \ @@ -25,4 +28,6 @@ } while (0) #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/decide.c b/src/sat/kissat/decide.c index 522930e26..7c2fa82d9 100644 --- a/src/sat/kissat/decide.c +++ b/src/sat/kissat/decide.c @@ -6,15 +6,17 @@ #include +ABC_NAMESPACE_IMPL_START + static unsigned last_enqueued_unassigned_variable (kissat *solver) { - assert (solver->unassigned); + KISSAT_assert (solver->unassigned); const links *const links = solver->links; const value *const values = solver->values; unsigned res = solver->queue.search.idx; if (values[LIT (res)]) { do { res = links[res].prev; - assert (!DISCONNECTED (res)); + KISSAT_assert (!DISCONNECTED (res)); } while (values[LIT (res)]); kissat_update_queue (solver, links, res); } @@ -24,7 +26,7 @@ static unsigned last_enqueued_unassigned_variable (kissat *solver) { #endif #ifdef CHECK_QUEUE for (unsigned i = links[res].next; !DISCONNECTED (i); i = links[i].next) - assert (VALUE (LIT (i))); + KISSAT_assert (VALUE (LIT (i))); #endif return res; } @@ -48,7 +50,7 @@ static unsigned largest_score_unassigned_variable (kissat *solver) { if (VALUE (LIT (idx))) continue; const double idx_score = kissat_get_heap_score (scores, idx); - assert (score >= idx_score); + KISSAT_assert (score >= idx_score); } #endif return res; @@ -71,7 +73,7 @@ void kissat_start_random_sequence (kissat *solver) { FORMAT_COUNT (CONFLICTS)); else { 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); kissat_very_verbose (solver, "starting random decision sequence " @@ -100,7 +102,7 @@ static unsigned next_random_decision (kissat *solver) { return INVALID_IDX; if (!solver->randec) { - assert (solver->level); + KISSAT_assert (solver->level); if (solver->level > 1) return INVALID_IDX; @@ -176,7 +178,7 @@ int kissat_decide_phase (kissat *solver, unsigned idx) { value res = 0; if (!solver->stable) { - switch ((solver->statistics.switched >> 1) & 7) { + switch ((solver->statistics_.switched >> 1) & 7) { case 1: res = INITIAL_PHASE; break; @@ -201,14 +203,14 @@ int kissat_decide_phase (kissat *solver, unsigned idx) { LOG ("%s uses initial decision phase %d", LOGVAR (idx), (int) res); INC (initial_decisions); } - assert (res); + KISSAT_assert (res); return res < 0 ? -1 : 1; } void kissat_decide (kissat *solver) { START (decide); - assert (solver->unassigned); + KISSAT_assert (solver->unassigned); if (solver->warming) INC (warming_decisions); else { @@ -219,26 +221,28 @@ void kissat_decide (kissat *solver) { INC (focused_decisions); } solver->level++; - assert (solver->level != INVALID_LEVEL); + KISSAT_assert (solver->level != INVALID_LEVEL); const unsigned idx = kissat_next_decision_variable (solver); const value value = kissat_decide_phase (solver, idx); unsigned lit = LIT (idx); if (value < 0) lit = NOT (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)); kissat_assign_decision (solver, lit); STOP (decide); } void kissat_internal_assume (kissat *solver, unsigned lit) { - assert (solver->unassigned); - assert (!VALUE (lit)); + KISSAT_assert (solver->unassigned); + KISSAT_assert (!VALUE (lit)); solver->level++; - assert (solver->level != INVALID_LEVEL); + KISSAT_assert (solver->level != INVALID_LEVEL); 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)); kissat_assign_decision (solver, lit); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/decide.h b/src/sat/kissat/decide.h index 9864ae2e1..df368771f 100644 --- a/src/sat/kissat/decide.h +++ b/src/sat/kissat/decide.h @@ -1,6 +1,9 @@ #ifndef _decide_h_INCLUDED #define _decide_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + 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) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/deduce.c b/src/sat/kissat/deduce.c index be1235f69..dc2ceaa53 100644 --- a/src/sat/kissat/deduce.c +++ b/src/sat/kissat/deduce.c @@ -3,8 +3,10 @@ #include "promote.h" #include "strengthen.h" +ABC_NAMESPACE_IMPL_START + 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 new_glue = kissat_recompute_glue (solver, c, 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"); recompute_and_promote (solver, c); 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) INC (clauses_used_stable); 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) { - assert (c->redundant); + KISSAT_assert (c->redundant); const unsigned old_glue = c->glue; const unsigned new_glue = kissat_recompute_glue (solver, c, 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, frame *frames, unsigned lit) { - assert (VALUE (lit) < 0); + KISSAT_assert (VALUE (lit) < 0); const unsigned idx = IDX (lit); assigned *a = all_assigned + idx; const unsigned level = a->level; @@ -49,14 +51,14 @@ static inline bool analyze_literal (kissat *solver, assigned *all_assigned, return false; LOG ("analyzing literal %s", LOGLIT (lit)); kissat_push_analyzed (solver, all_assigned, idx); - assert (level <= solver->level); -#if defined(LOGGING) || !defined(NDEBUG) + KISSAT_assert (level <= solver->level); +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) PUSH_STACK (solver->resolvent, lit); #endif solver->resolvent_size++; if (level == solver->level) return true; - assert (a->analyzed); + KISSAT_assert (a->analyzed); PUSH_STACK (solver->clause, lit); LOG ("learned literal %s", LOGLIT (lit)); 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) { START (deduce); - assert (EMPTY_STACK (solver->analyzed)); - assert (EMPTY_STACK (solver->levels)); - assert (EMPTY_STACK (solver->clause)); -#if defined(LOGGING) || !defined(NDEBUG) + KISSAT_assert (EMPTY_STACK (solver->analyzed)); + KISSAT_assert (EMPTY_STACK (solver->levels)); + KISSAT_assert (EMPTY_STACK (solver->clause)); +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) CLEAR_STACK (solver->resolvent); #endif if (conflict->size > 2) @@ -84,16 +86,16 @@ clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) { assigned *all_assigned = solver->assigned; frame *frames = BEGIN_STACK (solver->frames); for (all_literals_in_clause (lit, conflict)) { - assert (VALUE (lit) < 0); + KISSAT_assert (VALUE (lit) < 0); if (LEVEL (lit)) conflict_size++; if (analyze_literal (solver, all_assigned, frames, lit)) 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", unresolved_on_current_level); - assert (solver->antecedent_size == solver->resolvent_size); + KISSAT_assert (solver->antecedent_size == solver->resolvent_size); LOGRES2 ("initial"); const bool otfs = GET_OPTION (otfs); unsigned const *t = END_ARRAY (solver->trail); @@ -102,14 +104,14 @@ clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) { assigned *a = 0; for (;;) { do { - assert (t > BEGIN_ARRAY (solver->trail)); + KISSAT_assert (t > BEGIN_ARRAY (solver->trail)); uip = *--t; a = ASSIGNED (uip); } while (!a->analyzed || a->level != solver->level); if (unresolved_on_current_level == 1) break; - assert (a->reason != DECISION_REASON); - assert (a->level == solver->level); + KISSAT_assert (a->reason != DECISION_REASON); + KISSAT_assert (a->level == solver->level); solver->antecedent_size = 1; resolved++; if (a->binary) { @@ -127,38 +129,38 @@ clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) { unresolved_on_current_level++; mark_clause_as_used (solver, reason); } - assert (unresolved_on_current_level > 0); + KISSAT_assert (unresolved_on_current_level > 0); unresolved_on_current_level--; LOG ("after resolving %s there are %u literals left " "on current decision level", LOGLIT (uip), unresolved_on_current_level); - assert (solver->resolvent_size > 0); + KISSAT_assert (solver->resolvent_size > 0); solver->resolvent_size--; -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) LOG2 ("actual antecedent size %u", solver->antecedent_size); 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"); #endif if (otfs && solver->antecedent_size > 2 && solver->resolvent_size < solver->antecedent_size) { - assert (!a->binary); - assert (solver->antecedent_size && solver->resolvent_size + 1); + KISSAT_assert (!a->binary); + KISSAT_assert (solver->antecedent_size && solver->resolvent_size + 1); 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); if (resolved == 1 && solver->resolvent_size < conflict_size) { - assert (!conflict->garbage); - assert (conflict_size > 2); + KISSAT_assert (!conflict->garbage); + KISSAT_assert (conflict_size > 2); kissat_on_the_fly_subsume (solver, res, conflict); } STOP (deduce); return res; } } - assert (uip != INVALID_LIT); + KISSAT_assert (uip != INVALID_LIT); 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)); LOGTMP ("deduced not yet minimized 1st UIP"); if (!solver->probing) @@ -166,3 +168,5 @@ clause *kissat_deduce_first_uip_clause (kissat *solver, clause *conflict) { STOP (deduce); return 0; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/deduce.h b/src/sat/kissat/deduce.h index 38a5ec4c0..1783ce955 100644 --- a/src/sat/kissat/deduce.h +++ b/src/sat/kissat/deduce.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct clause; struct kissat; @@ -11,4 +14,6 @@ struct clause *kissat_deduce_first_uip_clause (struct kissat *, bool kissat_recompute_and_promote (struct kissat *, struct clause *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/definition.c b/src/sat/kissat/definition.c index 759a4f906..75db5b8f5 100644 --- a/src/sat/kissat/definition.c +++ b/src/sat/kissat/definition.c @@ -5,6 +5,8 @@ #include "kitten.h" #include "print.h" +ABC_NAMESPACE_IMPL_START + typedef struct definition_extractor definition_extractor; struct definition_extractor { @@ -14,13 +16,13 @@ struct definition_extractor { }; static void traverse_definition_core (void *state, unsigned id) { - definition_extractor *extractor = state; + definition_extractor *extractor = (definition_extractor*)state; kissat *solver = extractor->solver; watch watch; watches *watches0 = extractor->watches[0]; watches *watches1 = extractor->watches[1]; const size_t size_watches0 = SIZE_WATCHES (*watches0); - assert (size_watches0 <= UINT_MAX); + KISSAT_assert (size_watches0 <= UINT_MAX); unsigned sign; if (id < size_watches0) { watch = BEGIN_WATCHES (*watches0)[id]; @@ -28,10 +30,10 @@ static void traverse_definition_core (void *state, unsigned id) { sign = 0; } else { unsigned tmp = id - size_watches0; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG const size_t size_watches1 = SIZE_WATCHES (*watches1); - assert (size_watches1 <= UINT_MAX); - assert (tmp < size_watches1); + KISSAT_assert (size_watches1 <= UINT_MAX); + KISSAT_assert (tmp < size_watches1); #endif watch = BEGIN_WATCHES (*watches1)[tmp]; 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); } -#if !defined(NDEBUG) || !defined(NPROOFS) +#if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) 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; const unsigned unit = extractor->unit; unsigneds *added = &solver->added; - assert (extractor->lemmas || EMPTY_STACK (*added)); + KISSAT_assert (extractor->lemmas || EMPTY_STACK (*added)); if (size) { PUSH_STACK (*added, size + 1); 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++) PUSH_STACK (*added, *p); 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); ADD_LITS_TO_PROOF (size + 1, extended); } else { @@ -77,7 +79,7 @@ static void traverse_one_sided_core_lemma (void *state, bool learned, unsigned *begin = BEGIN_STACK (*added); for (unsigned *p = begin, size; p != end; p += size) { size = *p++; - assert (p + size <= end); + KISSAT_assert (p + size <= end); REMOVE_CHECKER_LITS (size, p); DELETE_LITS_FROM_PROOF (size, p); } @@ -93,7 +95,7 @@ bool kissat_find_definition (kissat *solver, unsigned lit) { return false; START (definition); struct kitten *kitten = solver->kitten; - assert (kitten); + KISSAT_assert (kitten); kitten_clear (kitten); const unsigned not_lit = NOT (lit); definition_extractor extractor; @@ -103,7 +105,7 @@ bool kissat_find_definition (kissat *solver, unsigned lit) { extractor.watches[1] = &WATCHES (not_lit); kitten_track_antecedents (kitten); unsigned exported = 0; -#if !defined(QUIET) || !defined(NDEBUG) +#if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG) size_t occs[2] = {0, 0}; #endif 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, c->lits, except); } -#if !defined(QUIET) || !defined(NDEBUG) +#if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG) occs[sign]++; #endif exported++; @@ -143,19 +145,19 @@ bool kissat_find_definition (kissat *solver, unsigned lit) { kitten_shuffle_clauses (kitten); kitten_set_ticks_limit (kitten, 10 * limit); int tmp = kitten_solve (kitten); - assert (!tmp || tmp == 20); + KISSAT_assert (!tmp || tmp == 20); if (!tmp) { LOG ("aborting core extraction"); goto ABORT; } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG unsigned previous = reduced; #endif reduced = kitten_compute_clausal_core (kitten, &learned); LOG ("%s sub-solver core of size %u original clauses out of %u", FORMAT_ORDINAL (i), reduced, exported); - assert (reduced <= previous); -#if defined(QUIET) && defined(NDEBUG) + KISSAT_assert (reduced <= previous); +#if defined(KISSAT_QUIET) && defined(KISSAT_NDEBUG) (void) reduced; #endif } @@ -164,8 +166,8 @@ bool kissat_find_definition (kissat *solver, unsigned lit) { size_t size[2]; size[0] = SIZE_STACK (solver->gates[0]); size[1] = SIZE_STACK (solver->gates[1]); -#if !defined(QUIET) || !defined(NDEBUG) - assert (reduced == size[0] + size[1]); +#if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG) + KISSAT_assert (reduced == size[0] + size[1]); #ifdef METRICS kissat_extremely_verbose ( solver, @@ -188,7 +190,7 @@ bool kissat_find_definition (kissat *solver, unsigned lit) { unsigned unit = INVALID_LIT; if (!size[0]) { unit = not_lit; - assert (size[1]); + KISSAT_assert (size[1]); } else if (!size[1]) unit = lit; @@ -198,12 +200,12 @@ bool kissat_find_definition (kissat *solver, unsigned lit) { kissat_extremely_verbose (solver, "one sided core " "definition extraction yields " "failed literal"); -#if !defined(NDEBUG) || !defined(NPROOFS) +#if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) if (false -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG || GET_OPTION (check) > 1 #endif -#ifndef NPROOFS +#ifndef KISSAT_NPROOFS || solver->proof #endif ) { @@ -228,3 +230,5 @@ bool kissat_find_definition (kissat *solver, unsigned lit) { STOP (definition); return res; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/definition.h b/src/sat/kissat/definition.h index 2fea782c0..9d87de466 100644 --- a/src/sat/kissat/definition.h +++ b/src/sat/kissat/definition.h @@ -3,8 +3,13 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_find_definition (struct kissat *, unsigned lit); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/dense.c b/src/sat/kissat/dense.c index d7592419a..65c668cbc 100644 --- a/src/sat/kissat/dense.c +++ b/src/sat/kissat/dense.c @@ -10,9 +10,11 @@ #include +ABC_NAMESPACE_IMPL_START + static void flush_large_watches (kissat *solver, litpairs *irredundant) { - assert (!solver->level); - assert (solver->watching); + KISSAT_assert (!solver->level); + KISSAT_assert (solver->watching); #ifndef LOGGING LOG ("flushing large watches"); if (irredundant) @@ -22,9 +24,9 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) { #endif const value *const values = solver->values; mark *const marks = solver->marks; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG for (all_literals (lit)) - assert (!marks[lit]); + KISSAT_assert (!marks[lit]); #endif size_t flushed = 0, collected = 0; #ifdef LOGGING @@ -37,7 +39,7 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) { watches *watches = all_watches + lit; watch *begin = BEGIN_WATCHES (*watches), *q = begin; const watch *const end_watches = END_WATCHES (*watches), *p = q; - assert (EMPTY_STACK (*marked)); + KISSAT_assert (EMPTY_STACK (*marked)); while (p != end_watches) { const watch watch = *p++; if (watch.type.binary) { @@ -65,7 +67,7 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) { *q++ = watch; } } else { - assert (lit_value > 0 || other_value > 0); + KISSAT_assert (lit_value > 0 || other_value > 0); if (lit < other) { kissat_delete_binary (solver, lit, other); collected++; @@ -84,7 +86,7 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) { marks[other] = 0; CLEAR_ARRAY (*marked); } - assert (EMPTY_STACK (*marked)); + KISSAT_assert (EMPTY_STACK (*marked)); LOG ("flushed %zu large watches", flushed); LOG ("removed %zu duplicated binary clauses", deduplicated); 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) { - assert (!solver->level); - assert (solver->watching); - assert (kissat_propagated (solver)); + KISSAT_assert (!solver->level); + KISSAT_assert (solver->watching); + KISSAT_assert (kissat_propagated (solver)); LOG ("entering dense mode with full occurrence lists"); if (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, litpairs *binaries) { - assert (binaries); + KISSAT_assert (binaries); #ifdef LOGGING size_t resumed_watching = 0; #endif @@ -120,8 +122,8 @@ static void resume_watching_irredundant_binaries (kissat *solver, const unsigned first = litpair.lits[0]; const unsigned second = litpair.lits[1]; - assert (!ELIMINATED (IDX (first))); - assert (!ELIMINATED (IDX (second))); + KISSAT_assert (!ELIMINATED (IDX (first))); + KISSAT_assert (!ELIMINATED (IDX (second))); watches *first_watches = all_watches + first; watch first_watch = kissat_binary_watch (second); @@ -172,7 +174,7 @@ resume_watching_large_clauses_after_elimination (kissat *solver) { continue; } - assert (c->size > 2); + KISSAT_assert (c->size > 2); unsigned *lits = c->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, litpairs *irredundant) { - assert (!solver->level); - assert (!solver->watching); + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->watching); if (solver->inconsistent) return; LOG ("resuming sparse mode watching clauses"); @@ -224,12 +226,14 @@ void kissat_resume_sparse_mode (kissat *solver, bool flush_eliminated, else conflict = kissat_search_propagate (solver); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG if (conflict) - assert (solver->inconsistent); + KISSAT_assert (solver->inconsistent); else - assert (kissat_trail_flushed (solver)); + KISSAT_assert (kissat_trail_flushed (solver)); #else (void) conflict; #endif } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/dense.h b/src/sat/kissat/dense.h index 171e4e5ac..225d7367d 100644 --- a/src/sat/kissat/dense.h +++ b/src/sat/kissat/dense.h @@ -3,10 +3,15 @@ #include "watch.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + void kissat_enter_dense_mode (struct kissat *, litpairs *saved_irredundant_binary_clauses); void kissat_resume_sparse_mode (struct kissat *, bool flush_eliminated, litpairs *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/dump.c b/src/sat/kissat/dump.c index e8598b130..c1b2796d3 100644 --- a/src/sat/kissat/dump.c +++ b/src/sat/kissat/dump.c @@ -1,4 +1,6 @@ -#ifndef NDEBUG +#include "global.h" + +#ifndef KISSAT_NDEBUG #include "inline.h" @@ -64,14 +66,14 @@ static void dump_trail (kissat *solver) { const unsigned lit = PEEK_ARRAY (solver->trail, i); dump_literal (solver, lit); const unsigned lit_level = LEVEL (lit); - assert (lit_level <= level); + KISSAT_assert (lit_level <= level); if (lit_level < level) printf (" out-of-order"); assigned *a = ASSIGNED (lit); if (!lit_level) { printf (" UNIT\n"); - assert (!a->binary); - assert (a->reason == UNIT_REASON); + KISSAT_assert (!a->binary); + KISSAT_assert (a->reason == UNIT_REASON); } else { fputc (' ', stdout); if (a->binary) { @@ -80,7 +82,7 @@ static void dump_trail (kissat *solver) { } else if (a->reason == DECISION_REASON) printf ("DECISION\n"); else { - assert (a->reason != UNIT_REASON); + KISSAT_assert (a->reason != UNIT_REASON); const reference ref = a->reason; dump_ref (solver, ref); } @@ -129,18 +131,18 @@ static void dump_scores (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++) printf ("export[%u] = %u\n", LIT (idx), - PEEK_STACK (solver->export, idx)); + PEEK_STACK (solver->export_, idx)); } void dump_map (kissat *solver) { - const unsigned size = SIZE_STACK (solver->export); + const unsigned size = SIZE_STACK (solver->export_); unsigned first = INVALID_LIT; for (unsigned idx = 0; idx < size; 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); if (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 end = END_STACK (solver->extend); 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); if (!p[1].blocking) fputs (" :", stdout); diff --git a/src/sat/kissat/eliminate.c b/src/sat/kissat/eliminate.c index 9b7164c83..7b3bb713f 100644 --- a/src/sat/kissat/eliminate.c +++ b/src/sat/kissat/eliminate.c @@ -18,10 +18,12 @@ #include #include +ABC_NAMESPACE_IMPL_START + bool kissat_eliminating (kissat *solver) { if (!solver->enabled.eliminate) return false; - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; if (!statistics->clauses_irredundant) return false; const uint64_t conflicts = statistics->conflicts; @@ -51,9 +53,9 @@ static inline double variable_score (kissat *solver, unsigned idx) { double prod = pos * neg; double sum = pos + neg; double occlim2 = occlim * (double) occlim; - assert (prod <= occlim2); + KISSAT_assert (prod <= occlim2); double score = prod - sum; - assert (score <= occlim2); + KISSAT_assert (score <= occlim2); double relevancy; if (solver->stable) 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, unsigned idx) { - assert (schedule->size); - assert (schedule == &solver->schedule); + KISSAT_assert (schedule->size); + KISSAT_assert (schedule == &solver->schedule); double new_score = variable_score (solver, idx); LOG ("new score %g for variable %s", new_score, LOGVAR (idx)); 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, unsigneds *stack) { - assert (!solver->probing); + KISSAT_assert (!solver->probing); heap *schedule = &solver->schedule; if (!schedule->size) return; @@ -96,11 +98,11 @@ static inline void update_after_removing_variable (kissat *solver, heap *schedule = &solver->schedule; if (!schedule->size) return; - assert (!solver->probing); + KISSAT_assert (!solver->probing); flags *f = solver->flags + idx; if (f->fixed) return; - assert (!f->eliminated); + KISSAT_assert (!f->eliminated); update_variable_score (solver, schedule, idx); if (!kissat_heap_contains (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) { if (!solver->schedule.size) return; - assert (c->garbage); + KISSAT_assert (c->garbage); for (all_literals_in_clause (lit, c)) if (lit != except) 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) { LOG ("initializing variable schedule"); - assert (!solver->schedule.size); + KISSAT_assert (!solver->schedule.size); kissat_resize_heap (solver, &solver->schedule, solver->vars); @@ -147,8 +149,8 @@ static unsigned schedule_variables (kissat *solver) { scheduled++; update_after_removing_variable (solver, idx); } - assert (scheduled == kissat_size_heap (&solver->schedule)); -#ifndef QUIET + KISSAT_assert (scheduled == kissat_size_heap (&solver->schedule)); +#ifndef KISSAT_QUIET size_t active = solver->active; kissat_phase (solver, "eliminate", GET (eliminations), "scheduled %zu variables %.0f%%", scheduled, @@ -160,7 +162,7 @@ static unsigned schedule_variables (kissat *solver) { void kissat_flush_units_while_connected (kissat *solver) { const unsigned *propagate = solver->propagate; const unsigned *end_trail = END_ARRAY (solver->trail); - assert (propagate <= end_trail); + KISSAT_assert (propagate <= end_trail); const size_t units = end_trail - propagate; if (!units) return; @@ -191,11 +193,11 @@ void kissat_flush_units_while_connected (kissat *solver) { clause *c = kissat_dereference_clause (solver, ref); if (!c->garbage) kissat_eliminate_clause (solver, c, unit); - assert (c->garbage); + KISSAT_assert (c->garbage); q--; } } - assert (q <= end); + KISSAT_assert (q <= end); size_t flushed = end - q; if (!flushed) continue; @@ -206,7 +208,7 @@ void kissat_flush_units_while_connected (kissat *solver) { static void connect_resolvents (kissat *solver) { const value *const values = solver->values; - assert (EMPTY_STACK (solver->clause)); + KISSAT_assert (EMPTY_STACK (solver->clause)); bool satisfied = false; #ifdef LOGGING uint64_t added = 0; @@ -219,7 +221,7 @@ static void connect_resolvents (kissat *solver) { LOGTMP ("temporary resolvent"); const size_t size = SIZE_STACK (solver->clause); if (!size) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); LOG ("resolved empty clause"); CHECK_AND_ADD_EMPTY (); ADD_EMPTY_TO_PROOF (); @@ -230,7 +232,7 @@ static void connect_resolvents (kissat *solver) { LOG ("resolved unit clause %s", LOGLIT (unit)); kissat_learned_unit (solver, unit); } else { - assert (size > 1); + KISSAT_assert (size > 1); (void) kissat_new_irredundant_clause (solver); update_after_adding_stack (solver, &solver->clause); #ifdef LOGGING @@ -258,7 +260,7 @@ static void weaken_clauses (kissat *solver, unsigned lit) { const unsigned not_lit = NOT (lit); const value *const values = solver->values; - assert (!values[lit]); + KISSAT_assert (!values[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 current_bound = solver->bounds.eliminate.additional_clauses; - assert (current_bound <= max_bound); + KISSAT_assert (current_bound <= max_bound); if (complete) { if (current_bound == max_bound) { @@ -348,11 +350,11 @@ static void set_next_elimination_bound (kissat *solver, bool complete) { "completed maximum elimination bound %u", current_bound); limits *limits = &solver->limits; - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; limits->eliminate.variables.eliminate = statistics->variables_eliminate; limits->eliminate.variables.subsume = statistics->variables_subsume; -#ifndef QUIET +#ifndef KISSAT_QUIET bool first = !solver->bounds.eliminate.max_bound_completed++; REPORT (!first, first ? '!' : ':'); #endif @@ -389,8 +391,8 @@ static bool eliminate_variable (kissat *solver, unsigned idx) { (void) variable_score (solver, idx); #endif - assert (!solver->inconsistent); - assert (can_eliminate_variable (solver, idx)); + KISSAT_assert (!solver->inconsistent); + KISSAT_assert (can_eliminate_variable (solver, idx)); LOG ("marking %s as not removed", LOGVAR (idx)); FLAGS (idx)->eliminate = false; @@ -406,7 +408,7 @@ static bool eliminate_variable (kissat *solver, unsigned idx) { if (solver->gate_eliminated) { INC (gates_eliminated); #ifdef METRICS - assert (*solver->gate_eliminated < UINT64_MAX); + KISSAT_assert (*solver->gate_eliminated < UINT64_MAX); *solver->gate_eliminated += 1; #endif } @@ -417,8 +419,8 @@ static void eliminate_variables (kissat *solver) { kissat_very_verbose (solver, "trying to eliminate variables with bound %u", solver->bounds.eliminate.additional_clauses); - assert (!solver->inconsistent); -#ifndef QUIET + KISSAT_assert (!solver->inconsistent); +#ifndef KISSAT_QUIET unsigned before = solver->active; unsigned eliminated = 0; uint64_t tried = 0; @@ -452,7 +454,7 @@ static void eliminate_variables (kissat *solver) { complete = true; } -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned last_round_scheduled = #endif schedule_variables (solver); @@ -474,7 +476,7 @@ static void eliminate_variables (kissat *solver) { unsigned idx = kissat_pop_max_heap (solver, &solver->schedule); if (!can_eliminate_variable (solver, idx)) continue; - statistics *s = &solver->statistics; + statistics *s = &solver->statistics_; if (s->eliminate_resolutions > resolution_limit) { kissat_extremely_verbose ( solver, @@ -484,7 +486,7 @@ static void eliminate_variables (kissat *solver) { complete = false; break; } -#ifndef QUIET +#ifndef KISSAT_QUIET tried++; #endif if (eliminate_variable (solver, idx)) @@ -496,7 +498,7 @@ static void eliminate_variables (kissat *solver) { if (last_round_eliminated) { complete = false; -#ifndef QUIET +#ifndef KISSAT_QUIET eliminated += last_round_eliminated; #endif } @@ -520,7 +522,7 @@ static void eliminate_variables (kissat *solver) { break; if (round == GET_OPTION (eliminaterounds)) break; - if (solver->statistics.eliminate_resolutions > resolution_limit) + if (solver->statistics_.eliminate_resolutions > resolution_limit) break; if (TERMINATED (eliminate_terminated_2)) break; @@ -528,7 +530,7 @@ static void eliminate_variables (kissat *solver) { const unsigned remain = kissat_size_heap (&solver->schedule); kissat_release_heap (solver, &solver->schedule); -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_very_verbose (solver, "eliminated %u variables %.0f%% of %" PRIu64 " tried" " (%u remain %.0f%%)", @@ -545,13 +547,13 @@ static void eliminate_variables (kissat *solver) { set_next_elimination_bound (solver, complete); if (!complete) { const flags *end = solver->flags + VARS; -#ifndef QUIET +#ifndef KISSAT_QUIET unsigned dropped = 0; #endif for (struct flags *f = solver->flags; f != end; f++) if (f->eliminate) { f->eliminate = false; -#ifndef QUIET +#ifndef KISSAT_QUIET dropped++; #endif } @@ -565,7 +567,7 @@ static void eliminate_variables (kissat *solver) { static void init_map_and_kitten (kissat *solver) { if (!GET_OPTION (definitions)) return; - assert (!solver->kitten); + KISSAT_assert (!solver->kitten); solver->kitten = kitten_embedded (solver); } @@ -578,7 +580,7 @@ static void reset_map_and_kitten (kissat *solver) { static void eliminate (kissat *solver) { kissat_backtrack_propagate_and_flush_trail (solver); - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); STOP_SEARCH_AND_START_SIMPLIFIER (eliminate); kissat_phase (solver, "eliminate", GET (eliminations), "elimination limit of %" PRIu64 " conflicts hit", @@ -593,11 +595,13 @@ static void eliminate (kissat *solver) { } int kissat_eliminate (kissat *solver) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); INC (eliminations); eliminate (solver); kissat_classify (solver); 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; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/eliminate.h b/src/sat/kissat/eliminate.h index 0d6cfe9a5..cdc73b98b 100644 --- a/src/sat/kissat/eliminate.h +++ b/src/sat/kissat/eliminate.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; struct clause; 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_update_variable_score (struct kissat *, unsigned idx); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/equivalences.c b/src/sat/kissat/equivalences.c index c06215d24..41bf9a34c 100644 --- a/src/sat/kissat/equivalences.c +++ b/src/sat/kissat/equivalences.c @@ -2,6 +2,8 @@ #include "inlinevector.h" #include "logging.h" +ABC_NAMESPACE_IMPL_START + bool kissat_find_equivalence_gate (kissat *solver, unsigned lit) { if (!GET_OPTION (equivalences)) return false; @@ -35,3 +37,5 @@ bool kissat_find_equivalence_gate (kissat *solver, unsigned lit) { INC (equivalences_extracted); return true; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/equivalences.h b/src/sat/kissat/equivalences.h index ad9c14d57..30ada11a7 100644 --- a/src/sat/kissat/equivalences.h +++ b/src/sat/kissat/equivalences.h @@ -3,8 +3,13 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_find_equivalence_gate (struct kissat *, unsigned lit); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/error.c b/src/sat/kissat/error.c index c4c55d18d..8b687e604 100644 --- a/src/sat/kissat/error.c +++ b/src/sat/kissat/error.c @@ -5,6 +5,8 @@ #include #include +ABC_NAMESPACE_IMPL_START + static void (*kissat_abort_function) (void); void kissat_call_function_instead_of_abort (void (*f) (void)) { @@ -60,3 +62,5 @@ void kissat_fatal (const char *fmt, ...) { va_end (ap); kissat_abort (); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/error.h b/src/sat/kissat/error.h index 69ee50706..32a265f86 100644 --- a/src/sat/kissat/error.h +++ b/src/sat/kissat/error.h @@ -3,6 +3,9 @@ #include "attribute.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + // clang-format off void kissat_error (const char *fmt, ...) ATTRIBUTE_FORMAT (1, 2); @@ -15,4 +18,6 @@ void kissat_abort (void); // clang-format on +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/extend.c b/src/sat/kissat/extend.c index cd0dfa006..67a0839a5 100644 --- a/src/sat/kissat/extend.c +++ b/src/sat/kissat/extend.c @@ -1,6 +1,8 @@ #include "colors.h" #include "inline.h" +ABC_NAMESPACE_IMPL_START + static void undo_eliminated_assignment (kissat *solver) { size_t size_etrail = SIZE_STACK (solver->etrail); #ifdef LOGGING @@ -18,32 +20,32 @@ static void undo_eliminated_assignment (kissat *solver) { while (!EMPTY_STACK (solver->etrail)) { const unsigned pos = POP_STACK (solver->etrail); - assert (pos < SIZE_STACK (solver->eliminated)); - assert (values[pos]); + KISSAT_assert (pos < SIZE_STACK (solver->eliminated)); + KISSAT_assert (values[pos]); LOG2 ("unassigned eliminated[%u] external variable", pos); values[pos] = 0; } } static void extend_assign (kissat *solver, value *values, int lit) { - assert (lit); - assert (lit != INT_MIN); + KISSAT_assert (lit); + KISSAT_assert (lit != INT_MIN); const unsigned idx = ABS (lit); import *import = &PEEK_STACK (solver->import, idx); - assert (import->eliminated); - assert (import->imported); + KISSAT_assert (import->eliminated); + KISSAT_assert (import->imported); 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; 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); PUSH_STACK (solver->etrail, pos); } void kissat_extend (kissat *solver) { - assert (!EMPTY_STACK (solver->extend)); - assert (!solver->extended); + KISSAT_assert (!EMPTY_STACK (solver->extend)); + KISSAT_assert (!solver->extended); START (extend); solver->extended = true; @@ -79,7 +81,7 @@ void kissat_extend (kissat *solver) { #endif do { size++; - assert (begin < p); + KISSAT_assert (begin < p); const extension ext = *--p; const int elit = ext.lit; if (ext.blocking) @@ -88,15 +90,15 @@ void kissat_extend (kissat *solver) { if (satisfied) continue; - assert (elit != INT_MIN); + KISSAT_assert (elit != INT_MIN); const unsigned eidx = ABS (elit); - assert (eidx < SIZE_STACK (solver->import)); + KISSAT_assert (eidx < SIZE_STACK (solver->import)); const import *const import = imports + eidx; - assert (import->imported); + KISSAT_assert (import->imported); if (import->eliminated) { const unsigned tmp = import->lit; - assert (tmp < SIZE_STACK (solver->eliminated)); + KISSAT_assert (tmp < SIZE_STACK (solver->eliminated)); value value = evalues[tmp]; if (elit < 0) @@ -120,7 +122,7 @@ void kissat_extend (kissat *solver) { } else { const unsigned ilit = import->lit; value value = ivalues[ilit]; - assert (value); + KISSAT_assert (value); if (elit < 0) value = -value; @@ -151,10 +153,10 @@ void kissat_extend (kissat *solver) { #ifdef LOGGING const unsigned blocking_idx = ABS (blocking); - assert (blocking_idx < SIZE_STACK (solver->import)); - assert (imports[blocking_idx].eliminated); + KISSAT_assert (blocking_idx < SIZE_STACK (solver->import)); + KISSAT_assert (imports[blocking_idx].eliminated); 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]; LOGEXT2 (size, p, "%s blocking external literal %d " @@ -179,3 +181,5 @@ void kissat_extend (kissat *solver) { STOP (extend); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/extend.h b/src/sat/kissat/extend.h index 049028b25..c66d9efd2 100644 --- a/src/sat/kissat/extend.h +++ b/src/sat/kissat/extend.h @@ -4,6 +4,9 @@ #include "stack.h" #include "utilities.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct extension extension; struct extension { @@ -16,7 +19,7 @@ typedef STACK (extension) extensions; // clang-format on static inline extension kissat_extension (bool blocking, int lit) { - assert (ABS (lit) < (1 << 30)); + KISSAT_assert (ABS (lit) < (1 << 30)); extension res; res.blocking = blocking; res.lit = lit; @@ -27,4 +30,6 @@ struct kissat; void kissat_extend (struct kissat *solver); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/factor.c b/src/sat/kissat/factor.c index e234d0957..5586243c8 100644 --- a/src/sat/kissat/factor.c +++ b/src/sat/kissat/factor.c @@ -19,6 +19,8 @@ #include +ABC_NAMESPACE_IMPL_START + #define FACTOR 1 #define QUOTIENT 2 #define NOUNTED 4 @@ -73,19 +75,19 @@ static void init_factoring (kissat *solver, factoring *factoring, factoring->hops = GET_OPTION (factorhops); const unsigned hops = factoring->hops; if (hops) { - CALLOC (factoring->scores, hops); + CALLOC (scores, factoring->scores, hops); for (unsigned i = 0; i != hops; i++) { scores *scores = factoring->scores + i; - NALLOC (scores->score, VARS); + NALLOC (double, scores->score, VARS); double *score = scores->score; for (all_variables (idx)) score[idx] = -1; } } - CALLOC (factoring->count, factoring->allocated); -#ifndef NDEBUG + CALLOC (unsigned, factoring->count, factoring->allocated); +#ifndef KISSAT_NDEBUG for (all_literals (lit)) - assert (!solver->marks[lit]); + KISSAT_assert (!solver->marks[lit]); #endif } @@ -95,7 +97,7 @@ static void release_quotients (factoring *factoring) { for (quotient *q = factoring->quotients.first, *next; q; q = next) { next = q->next; unsigned factor = q->factor; - assert (marks[factor] == FACTOR); + KISSAT_assert (marks[factor] == FACTOR); marks[factor] = 0; RELEASE_STACK (q->clauses); RELEASE_STACK (q->matches); @@ -118,10 +120,10 @@ static void release_quotients (factoring *factoring) { static void release_factoring (factoring *factoring) { kissat *const solver = factoring->solver; - assert (EMPTY_STACK (solver->analyzed)); - assert (EMPTY_STACK (factoring->counted)); - assert (EMPTY_STACK (factoring->nounted)); - assert (EMPTY_STACK (factoring->qlauses)); + KISSAT_assert (EMPTY_STACK (solver->analyzed)); + KISSAT_assert (EMPTY_STACK (factoring->counted)); + KISSAT_assert (EMPTY_STACK (factoring->nounted)); + KISSAT_assert (EMPTY_STACK (factoring->qlauses)); DEALLOC (factoring->count, factoring->allocated); RELEASE_STACK (factoring->counted); RELEASE_STACK (factoring->nounted); @@ -129,7 +131,7 @@ static void release_factoring (factoring *factoring) { RELEASE_STACK (factoring->qlauses); release_quotients (factoring); kissat_release_heap (solver, &factoring->schedule); - assert (!(factoring->allocated & 1)); + KISSAT_assert (!(factoring->allocated & 1)); const size_t allocated_score = factoring->allocated / 2; const unsigned hops = factoring->hops; if (hops) { @@ -141,9 +143,9 @@ static void release_factoring (factoring *factoring) { } DEALLOC (factoring->scores, hops); } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG for (all_literals (lit)) - assert (!solver->marks[lit]); + KISSAT_assert (!solver->marks[lit]); #endif } @@ -174,7 +176,7 @@ static void schedule_factorization (factoring *factoring) { update_candidate (factoring, not_lit); } } -#ifndef QUIET +#ifndef KISSAT_QUIET heap *cands = &factoring->schedule; size_t size_cands = kissat_size_heap (cands); kissat_very_verbose ( @@ -186,19 +188,19 @@ static void schedule_factorization (factoring *factoring) { static quotient *new_quotient (factoring *factoring, unsigned factor) { kissat *const solver = factoring->solver; mark *marks = solver->marks; - assert (!marks[factor]); + KISSAT_assert (!marks[factor]); marks[factor] = FACTOR; - quotient *res = kissat_malloc (solver, sizeof *res); + quotient *res = (quotient*)kissat_malloc (solver, sizeof *res); memset (res, 0, sizeof *res); res->factor = factor; quotient *last = factoring->quotients.last; if (last) { - assert (factoring->quotients.first); - assert (!last->next); + KISSAT_assert (factoring->quotients.first); + KISSAT_assert (!last->next); last->next = res; res->id = last->id + 1; } else { - assert (!factoring->quotients.first); + KISSAT_assert (!factoring->quotients.first); factoring->quotients.first = res; } factoring->quotients.last = res; @@ -211,24 +213,24 @@ static size_t first_factor (factoring *factoring, unsigned factor) { kissat *const solver = factoring->solver; watches *all_watches = solver->watches; watches *factor_watches = all_watches + factor; - assert (!factoring->quotients.first); + KISSAT_assert (!factoring->quotients.first); quotient *quotient = new_quotient (factoring, factor); statches *clauses = "ient->clauses; uint64_t ticks = 0; for (all_binary_large_watches (watch, *factor_watches)) { PUSH_STACK (*clauses, watch); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG if (watch.type.binary) continue; const reference ref = watch.large.ref; clause *const c = kissat_dereference_clause (solver, ref); - assert (!c->quotient); + KISSAT_assert (!c->quotient); #endif ticks++; } size_t res = SIZE_STACK (*clauses); LOG ("quotient[0] factor %s size %zu", LOGLIT (factor), res); - assert (res > 1); + KISSAT_assert (res > 1); ADD (factor_ticks, ticks); return res; } @@ -236,7 +238,7 @@ static size_t first_factor (factoring *factoring, unsigned factor) { static void clear_nounted (kissat *solver, unsigneds *nounted) { mark *marks = solver->marks; for (all_stack (unsigned, lit, *nounted)) { - assert (marks[lit] & NOUNTED); + KISSAT_assert (marks[lit] & NOUNTED); marks[lit] &= ~NOUNTED; } CLEAR_STACK (*nounted); @@ -246,7 +248,7 @@ static void clear_qlauses (kissat *solver, references *qlauses) { ward *const arena = BEGIN_STACK (solver->arena); for (all_stack (reference, ref, *qlauses)) { clause *const c = (clause *) (arena + ref); - assert (c->quotient); + KISSAT_assert (c->quotient); c->quotient = false; } CLEAR_STACK (*qlauses); @@ -286,7 +288,7 @@ static double distinct_paths (factoring *factoring, unsigned src_lit, } ADD (factor_ticks, ticks); } - assert (res >= 0); + KISSAT_assert (res >= 0); score[src_idx] = res; unsigneds *scored = &scores->scored; 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) { const quotient *first_quotient = factoring->quotients.first; - assert (first_quotient); + KISSAT_assert (first_quotient); const unsigned first_factor = first_quotient->factor; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG kissat *const solver = factoring->solver; #endif 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, unsigned *next_count_ptr) { quotient *last_quotient = factoring->quotients.last; - assert (last_quotient); + KISSAT_assert (last_quotient); statches *last_clauses = &last_quotient->clauses; kissat *const solver = factoring->solver; watches *all_watches = solver->watches; unsigned *count = factoring->count; unsigneds *counted = &factoring->counted; references *qlauses = &factoring->qlauses; - assert (EMPTY_STACK (*counted)); - assert (EMPTY_STACK (*qlauses)); + KISSAT_assert (EMPTY_STACK (*counted)); + KISSAT_assert (EMPTY_STACK (*qlauses)); ward *const arena = BEGIN_STACK (solver->arena); mark *marks = solver->marks; const unsigned initial = factoring->initial; @@ -362,7 +364,7 @@ static unsigned next_factor (factoring *factoring, } else { const reference c_ref = quotient_watch.large.ref; clause *const c = (clause *) (arena + c_ref); - assert (!c->quotient); + KISSAT_assert (!c->quotient); unsigned min_lit = INVALID_LIT, factors = 0; size_t min_size = 0; ticks++; @@ -371,7 +373,7 @@ static unsigned next_factor (factoring *factoring, if (factors++) break; } else { - assert (!(marks[other] & QUOTIENT)); + KISSAT_assert (!(marks[other] & QUOTIENT)); marks[other] |= QUOTIENT; watches *other_watches = all_watches + other; const size_t other_size = SIZE_WATCHES (*other_watches); @@ -381,13 +383,13 @@ static unsigned next_factor (factoring *factoring, min_size = other_size; } } - assert (factors); + KISSAT_assert (factors); if (factors == 1) { - assert (min_lit != INVALID_LIT); + KISSAT_assert (min_lit != INVALID_LIT); watches *min_watches = all_watches + min_lit; unsigned c_size = c->size; unsigneds *nounted = &factoring->nounted; - assert (EMPTY_STACK (*nounted)); + KISSAT_assert (EMPTY_STACK (*nounted)); ticks += 1 + kissat_cache_lines (SIZE_WATCHES (*min_watches), sizeof (watch)); for (all_binary_large_watches (min_watch, *min_watches)) { @@ -403,25 +405,35 @@ static unsigned next_factor (factoring *factoring, if (d->size != c_size) continue; unsigned next = INVALID_LIT; + int continue_with_next_min_watch = 0; for (all_literals_in_clause (other, d)) { const mark mark = marks[other]; if (mark & QUOTIENT) continue; - if (mark & FACTOR) - goto CONTINUE_WITH_NEXT_MIN_WATCH; - if (mark & NOUNTED) - goto CONTINUE_WITH_NEXT_MIN_WATCH; - if (next != INVALID_LIT) - goto CONTINUE_WITH_NEXT_MIN_WATCH; + if (mark & FACTOR) { + continue_with_next_min_watch = 1; + break; + } + if (mark & NOUNTED) { + continue_with_next_min_watch = 1; + break; + } + if (next != INVALID_LIT) { + continue_with_next_min_watch = 1; + break; + } next = other; } - assert (next != INVALID_LIT); + if(continue_with_next_min_watch) { + continue; + } + KISSAT_assert (next != INVALID_LIT); if (next > initial) continue; const unsigned next_idx = IDX (next); if (!ACTIVE (next_idx)) continue; - assert (!(marks[next] & (FACTOR | NOUNTED))); + KISSAT_assert (!(marks[next] & (FACTOR | NOUNTED))); marks[next] |= NOUNTED; PUSH_STACK (*nounted, next); d->quotient = true; @@ -429,7 +441,6 @@ static unsigned next_factor (factoring *factoring, if (!count[next]) PUSH_STACK (*counted, next); count[next]++; - CONTINUE_WITH_NEXT_MIN_WATCH:; } clear_nounted (solver, nounted); } @@ -438,22 +449,22 @@ static unsigned next_factor (factoring *factoring, } ADD (factor_ticks, ticks); ticks = 0; - if (solver->statistics.factor_ticks > factoring->limit) + if (solver->statistics_.factor_ticks > factoring->limit) break; } clear_qlauses (solver, qlauses); unsigned next_count = 0, next = INVALID_LIT; - if (solver->statistics.factor_ticks <= factoring->limit) { + if (solver->statistics_.factor_ticks <= factoring->limit) { unsigned ties = 0; for (all_stack (unsigned, lit, *counted)) { const unsigned lit_count = count[lit]; if (lit_count < next_count) continue; if (lit_count == next_count) { - assert (lit_count); + KISSAT_assert (lit_count); ties++; } else { - assert (lit_count > next_count); + KISSAT_assert (lit_count > next_count); next_count = lit_count; next = lit; ties = 1; @@ -471,7 +482,7 @@ static unsigned next_factor (factoring *factoring, if (lit_count != next_count) continue; 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, LOGLIT (lit)); if (lit_score <= next_score) @@ -479,11 +490,11 @@ static unsigned next_factor (factoring *factoring, next_score = lit_score; next = lit; } - assert (next_score >= 0); - assert (next != INVALID_LIT); + KISSAT_assert (next_score >= 0); + KISSAT_assert (next != INVALID_LIT); LOG ("best score %g of next factor %s", next_score, LOGLIT (next)); } else { - assert (ties == 1); + KISSAT_assert (ties == 1); LOG ("single next factor %s with count %u", LOGLIT (next), next_count); } @@ -491,7 +502,7 @@ static unsigned next_factor (factoring *factoring, for (all_stack (unsigned, lit, *counted)) count[lit] = 0; CLEAR_STACK (*counted); - assert (next == INVALID_LIT || next_count > 1); + KISSAT_assert (next == INVALID_LIT || next_count > 1); *next_count_ptr = next_count; return next; } @@ -506,12 +517,12 @@ static void factorize_next (factoring *factoring, unsigned next, ward *const arena = BEGIN_STACK (solver->arena); mark *marks = solver->marks; - assert (last_quotient); + KISSAT_assert (last_quotient); statches *last_clauses = &last_quotient->clauses; statches *next_clauses = &next_quotient->clauses; sizes *matches = &next_quotient->matches; references *qlauses = &factoring->qlauses; - assert (EMPTY_STACK (*qlauses)); + KISSAT_assert (EMPTY_STACK (*qlauses)); uint64_t ticks = 1 + kissat_cache_lines (SIZE_STACK (*last_clauses), sizeof (watch)); @@ -535,7 +546,7 @@ static void factorize_next (factoring *factoring, unsigned next, } else { const reference c_ref = last_watch.large.ref; clause *const c = (clause *) (arena + c_ref); - assert (!c->quotient); + KISSAT_assert (!c->quotient); unsigned min_lit = INVALID_LIT, factors = 0; size_t min_size = 0; ticks++; @@ -544,7 +555,7 @@ static void factorize_next (factoring *factoring, unsigned next, if (factors++) break; } else { - assert (!(marks[other] & QUOTIENT)); + KISSAT_assert (!(marks[other] & QUOTIENT)); marks[other] |= QUOTIENT; watches *other_watches = all_watches + other; 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; } } - assert (factors); + KISSAT_assert (factors); if (factors == 1) { - assert (min_lit != INVALID_LIT); + KISSAT_assert (min_lit != INVALID_LIT); watches *min_watches = all_watches + min_lit; unsigned c_size = c->size; 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); 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; } @@ -643,9 +654,9 @@ static quotient *best_quotient (factoring *factoring, static void resize_factoring (factoring *factoring, unsigned lit) { kissat *const solver = factoring->solver; - assert (lit > NOT (lit)); + KISSAT_assert (lit > NOT (lit)); const size_t old_size = factoring->size; - assert (lit > old_size); + KISSAT_assert (lit > old_size); const size_t old_allocated = factoring->allocated; size_t new_size = lit + 1; if (new_size > old_allocated) { @@ -653,20 +664,20 @@ static void resize_factoring (factoring *factoring, unsigned lit) { while (new_size > new_allocated) new_allocated *= 2; 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); const size_t delta_allocated = new_allocated - old_allocated; const size_t delta_bytes = delta_allocated * sizeof *count; memset (count + old_size, 0, delta_bytes); factoring->count = count; - assert (!(old_allocated & 1)); - assert (!(new_allocated & 1)); + KISSAT_assert (!(old_allocated & 1)); + KISSAT_assert (!(new_allocated & 1)); const size_t old_allocated_score = old_allocated / 2; const size_t new_allocated_score = new_allocated / 2; for (unsigned i = 0; i != factoring->hops; i++) { scores *scores = factoring->scores + i; 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); for (size_t i = old_allocated_score; i != new_allocated_score; i++) 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; statches *q_clauses = &q->clauses, *prev_clauses = &prev->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; size_t i = 0; while (i != n) { size_t j = PEEK_STACK (*q_matches, i); - assert (i <= j); + KISSAT_assert (i <= j); if (!prev_is_first) { size_t matches = PEEK_STACK (*prev_matches, j); 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; clause *const c = kissat_dereference_clause (solver, c_ref); unsigneds *clause = &solver->clause; - assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*clause)); const unsigned factor = q->factor; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG bool found = false; #endif PUSH_STACK (*clause, not_fresh); for (all_literals_in_clause (other, c)) { if (other == factor) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG found = true; #endif continue; } PUSH_STACK (*clause, other); } - assert (found); + KISSAT_assert (found); ADD (literals_factored, c->size); kissat_new_irredundant_clause (solver); CLEAR_STACK (*clause); @@ -756,10 +767,10 @@ static void eagerly_remove_watch (kissat *solver, watches *watches, watch needle) { watch *p = BEGIN_WATCHES (*watches); watch *end = END_WATCHES (*watches); - assert (p != end); + KISSAT_assert (p != end); watch *last = end - 1; while (p->raw != needle.raw) - p++, assert (p != end); + p++, KISSAT_assert (p != end); if (p != last) memmove (p, p + 1, (last - p) * sizeof *p); SET_END_OF_WATCHES (*watches, last); @@ -833,7 +844,7 @@ static bool apply_factoring (factoring *factoring, quotient *q) { delete_unfactored (factoring, p); for (quotient *p = q; p; p = p->prev) update_factored (factoring, p); - assert (fresh < not_fresh); + KISSAT_assert (fresh < not_fresh); resize_factoring (factoring, not_fresh); return true; } @@ -871,16 +882,16 @@ adjust_scores_and_phases_of_fresh_varaibles (factoring *factoring) { const unsigned idx = IDX (lit); struct links *l = links + idx; if (DISCONNECTED (queue->first)) { - assert (DISCONNECTED (queue->last)); + KISSAT_assert (DISCONNECTED (queue->last)); queue->last = idx; } else { struct links *first = links + queue->first; - assert (DISCONNECTED (first->prev)); + KISSAT_assert (DISCONNECTED (first->prev)); first->prev = idx; } l->next = queue->first; queue->first = idx; - assert (DISCONNECTED (l->prev)); + KISSAT_assert (DISCONNECTED (l->prev)); l->stamp = ++queue->stamp; } while (!DISCONNECTED (rest)) { @@ -898,10 +909,10 @@ static bool run_factorization (kissat *solver, uint64_t limit) { init_factoring (solver, &factoring, limit); schedule_factorization (&factoring); bool done = false; -#ifndef QUIET +#ifndef KISSAT_QUIET unsigned factored = 0; #endif - uint64_t *ticks = &solver->statistics.factor_ticks; + uint64_t *ticks = &solver->statistics_.factor_ticks; kissat_extremely_verbose ( solver, "factorization limit of %" PRIu64 " ticks", limit - *ticks); 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); if (next == INVALID_LIT) break; - assert (next_count > 1); + KISSAT_assert (next_count > 1); if (next_count < 2) break; 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); if (q && reduction > factoring.bound) { if (apply_factoring (&factoring, q)) { -#ifndef QUIET +#ifndef KISSAT_QUIET factored++; #endif } else @@ -965,12 +976,12 @@ static void connect_clauses_to_factor (kissat *solver) { ward *const arena = BEGIN_STACK (solver->arena); watches *all_watches = solver->watches; unsigned *bincount, *largecount; - CALLOC (bincount, LITS); + CALLOC (unsigned, bincount, LITS); for (all_literals (lit)) { if (!ACTIVE (IDX (lit))) continue; for (all_binary_large_watches (watch, WATCHES (lit))) { - assert (watch.type.binary); + KISSAT_assert (watch.type.binary); const unsigned other = watch.type.lit; if (lit > other) continue; @@ -978,7 +989,7 @@ static void connect_clauses_to_factor (kissat *solver) { bincount[other]++; } } - CALLOC (largecount, LITS); + CALLOC (unsigned, largecount, LITS); size_t initial_candidates = 0; for (all_clauses (c)) { if (c->garbage) @@ -1001,7 +1012,7 @@ static void connect_clauses_to_factor (kissat *solver) { for (unsigned round = 1; round <= rounds; round++) { size_t new_candidates = 0; unsigned *newlargecount; - CALLOC (newlargecount, LITS); + CALLOC (unsigned, newlargecount, LITS); for (all_clauses (c)) { if (c->garbage) continue; @@ -1035,7 +1046,7 @@ static void connect_clauses_to_factor (kissat *solver) { "round %u", candidates, kissat_percent (candidates, initial_candidates), round); } -#ifndef QUIET +#ifndef KISSAT_QUIET size_t connected = 0; #endif for (all_clauses (c)) { @@ -1047,15 +1058,20 @@ static void connect_clauses_to_factor (kissat *solver) { continue; if (c->size > size_limit) continue; + int continue_with_next_clause2 = 0; for (all_literals_in_clause (lit, c)) - if (bincount[lit] + largecount[lit] < 2) - goto CONTINUE_WITH_NEXT_CLAUSE2; + if (bincount[lit] + largecount[lit] < 2) { + continue_with_next_clause2 = 1; + break; + } + if(continue_with_next_clause2) { + continue; + } const reference ref = (ward *) c - arena; kissat_inlined_connect_clause (solver, all_watches, c, ref); -#ifndef QUIET +#ifndef KISSAT_QUIET connected++; #endif - CONTINUE_WITH_NEXT_CLAUSE2:; } DEALLOC (largecount, LITS); DEALLOC (bincount, LITS); @@ -1065,12 +1081,12 @@ static void connect_clauses_to_factor (kissat *solver) { } void kissat_factor (kissat *solver) { - assert (!solver->level); + KISSAT_assert (!solver->level); if (solver->inconsistent) return; if (!GET_OPTION (factor)) return; - statistics *s = &solver->statistics; + statistics *s = &solver->statistics_; if (solver->limits.factor.marked >= s->literals_factor) { kissat_extremely_verbose ( solver, @@ -1095,7 +1111,7 @@ void kissat_factor (kissat *solver) { limit *= 1e6; limit += s->factor_ticks; } -#ifndef QUIET +#ifndef KISSAT_QUIET struct { int64_t variables, binary, clauses, ticks; } before, after, delta; @@ -1108,7 +1124,7 @@ void kissat_factor (kissat *solver) { connect_clauses_to_factor (solver); bool completed = run_factorization (solver, limit); kissat_resume_sparse_mode (solver, false, 0); -#ifndef QUIET +#ifndef KISSAT_QUIET after.variables = s->variables_extension + s->variables_original; after.binary = BINARY_CLAUSES; after.clauses = IRREDUNDANT_CLAUSES; @@ -1134,3 +1150,5 @@ void kissat_factor (kissat *solver) { solver->limits.factor.marked = s->literals_factor; STOP (factor); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/factor.h b/src/sat/kissat/factor.h index 0223186cf..fd433c8eb 100644 --- a/src/sat/kissat/factor.h +++ b/src/sat/kissat/factor.h @@ -3,7 +3,12 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_factor (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/fastassign.h b/src/sat/kissat/fastassign.h index 6951ed893..c0ad7b9ce 100644 --- a/src/sat/kissat/fastassign.h +++ b/src/sat/kissat/fastassign.h @@ -6,6 +6,9 @@ #include "inline.h" #include "inlineassign.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + static inline void kissat_fast_binary_assign ( kissat *solver, const bool probing, const unsigned level, value *values, assigned *assigned, unsigned lit, unsigned other) { @@ -27,15 +30,17 @@ static inline void kissat_fast_assign_reference (kissat *solver, value *values, assigned *assigned, unsigned lit, reference ref, clause *reason) { - assert (reason == kissat_dereference_clause (solver, ref)); + KISSAT_assert (reason == kissat_dereference_clause (solver, ref)); const unsigned level = kissat_assignment_level (solver, values, assigned, lit, reason); - assert (level <= solver->level); - assert (ref != DECISION_REASON); - assert (ref != UNIT_REASON); + KISSAT_assert (level <= solver->level); + KISSAT_assert (ref != DECISION_REASON); + KISSAT_assert (ref != UNIT_REASON); kissat_fast_assign (solver, solver->probing, level, values, assigned, false, lit, ref); LOGREF (ref, "assign %s reason", LOGLIT (lit)); } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/fastel.c b/src/sat/kissat/fastel.c index 64ddccf3a..a6de22f82 100644 --- a/src/sat/kissat/fastel.c +++ b/src/sat/kissat/fastel.c @@ -9,9 +9,11 @@ #include "terminate.h" #include "weaken.h" +ABC_NAMESPACE_IMPL_START + static bool fast_forward_subsumed (kissat *solver, clause *c) { - assert (!c->garbage); - assert (!c->redundant); + KISSAT_assert (!c->garbage); + KISSAT_assert (!c->redundant); unsigned max_occurring = INVALID_LIT; size_t max_occurrence = 0; watches *all_watches = solver->watches; @@ -58,7 +60,7 @@ static bool fast_forward_subsumed (kissat *solver, clause *c) { continue; if (d->size > c->size) continue; - assert (!d->redundant); + KISSAT_assert (!d->redundant); subsumed = true; for (all_literals_in_clause (other2, d)) { 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, unsigned clit, unsigned dlit) { - assert (!FLAGS (IDX (clit))->eliminated); - assert (!FLAGS (IDX (dlit))->eliminated); + KISSAT_assert (!FLAGS (IDX (clit))->eliminated); + KISSAT_assert (!FLAGS (IDX (dlit))->eliminated); if (clit == NOT (dlit)) { LOG ("resolvent tautological"); return; @@ -165,7 +167,7 @@ static void do_fast_resolve_binary_binary (kissat *solver, unsigned pivot, return; } if (cval < 0 && dval < 0) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); solver->inconsistent = true; LOG ("resolved empty clause"); CHECK_AND_ADD_EMPTY (); @@ -190,10 +192,10 @@ static void do_fast_resolve_binary_binary (kissat *solver, unsigned pivot, kissat_learned_unit (solver, clit); return; } - assert (!cval); - assert (!dval); + KISSAT_assert (!cval); + KISSAT_assert (!dval); unsigneds *clause = &solver->clause; - assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*clause)); PUSH_STACK (*clause, clit); PUSH_STACK (*clause, dlit); 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, unsigned lit, clause *c) { - assert (!FLAGS (IDX (lit))->eliminated); + KISSAT_assert (!FLAGS (IDX (lit))->eliminated); if (c->garbage) return; - assert (!c->redundant); + KISSAT_assert (!c->redundant); value *values = solver->values; value lit_val = values[lit]; if (lit_val > 0) { @@ -217,7 +219,7 @@ static void do_fast_resolve_binary_large (kissat *solver, unsigned pivot, return; } unsigneds *clause = &solver->clause; - assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*clause)); if (!lit_val) PUSH_STACK (*clause, lit); 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); if (!size) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); solver->inconsistent = true; LOG ("resolved empty clause"); CHECK_AND_ADD_EMPTY (); @@ -276,12 +278,12 @@ static void do_fast_resolve_large_large (kissat *solver, unsigned pivot, return; if (d->garbage) return; - assert (!c->redundant); - assert (!d->redundant); + KISSAT_assert (!c->redundant); + KISSAT_assert (!d->redundant); value *values = solver->values; mark *marks = solver->marks; unsigneds *clause = &solver->clause; - assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*clause)); bool satisfied = false, tautological = false; for (all_literals_in_clause (other, c)) { 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); if (!size) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); solver->inconsistent = true; LOG ("resolved empty clause"); 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, watch dwatch) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); LOGWATCH (LIT (pivot), cwatch, "1st fast %s elimination antecedent", LOGVAR (pivot)); 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) do_fast_resolve_binary_large (solver, pivot, dlit, c); else { - assert (!cbin), assert (!dbin); + KISSAT_assert (!cbin), KISSAT_assert (!dbin); 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; q = begin_not_lit_watches + j; } - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); INC (eliminated); INC (fast_eliminated); 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, unsigned dlit) { - assert (!FLAGS (IDX (clit))->eliminated); - assert (!FLAGS (IDX (dlit))->eliminated); + KISSAT_assert (!FLAGS (IDX (clit))->eliminated); + KISSAT_assert (!FLAGS (IDX (dlit))->eliminated); if (clit == NOT (dlit)) return false; value *values = solver->values; @@ -471,7 +473,7 @@ static bool can_fast_resolve_binary_binary (kissat *solver, unsigned clit, if (dval > 0) return false; if (cval < 0 && dval < 0) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); solver->inconsistent = true; LOG ("resolved empty clause"); CHECK_AND_ADD_EMPTY (); @@ -496,17 +498,17 @@ static bool can_fast_resolve_binary_binary (kissat *solver, unsigned clit, kissat_learned_unit (solver, clit); return false; } - assert (!cval); - assert (!dval); + KISSAT_assert (!cval); + KISSAT_assert (!dval); return true; } static bool can_fast_resolve_binary_large (kissat *solver, unsigned pivot, unsigned lit, clause *c) { - assert (!FLAGS (IDX (lit))->eliminated); + KISSAT_assert (!FLAGS (IDX (lit))->eliminated); if (c->garbage) return false; - assert (!c->redundant); + KISSAT_assert (!c->redundant); value *values = solver->values; value lit_val = values[lit]; if (lit_val > 0) @@ -527,7 +529,7 @@ static bool can_fast_resolve_binary_large (kissat *solver, unsigned pivot, } if (found_lit) { unsigneds *clause = &solver->clause; - assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*clause)); for (all_literals_in_clause (other, c)) { const unsigned idx = IDX (other); if (idx == pivot) @@ -535,7 +537,7 @@ static bool can_fast_resolve_binary_large (kissat *solver, unsigned pivot, value value = values[other]; if (value < 0) continue; - assert (!value); + KISSAT_assert (!value); PUSH_STACK (*clause, other); } 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 reference ref = kissat_reference_clause (solver, c); if (!size) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); solver->inconsistent = true; LOG ("resolved empty clause"); CHECK_AND_ADD_EMPTY (); @@ -571,13 +573,13 @@ static bool can_fast_resolve_large_large (kissat *solver, unsigned pivot, return false; if (d->garbage) return false; - assert (!c->redundant); - assert (!d->redundant); + KISSAT_assert (!c->redundant); + KISSAT_assert (!d->redundant); value *values = solver->values; mark *marks = solver->marks; bool satisfied = false; unsigneds *clause = &solver->clause; - assert (EMPTY_STACK (*clause)); + KISSAT_assert (EMPTY_STACK (*clause)); for (all_literals_in_clause (other, c)) { const unsigned idx_other = IDX (other); 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); break; } - assert (!marks[other]); + KISSAT_assert (!marks[other]); marks[other] = 1; PUSH_STACK (*clause, other); } @@ -628,7 +630,7 @@ static bool can_fast_resolve_large_large (kissat *solver, unsigned pivot, if (!satisfied && !tautological) { const size_t size = SIZE_STACK (*clause); if (!size) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); solver->inconsistent = true; LOG ("resolved empty clause"); 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, watch dwatch) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); const unsigned clit = cwatch.binary.lit; const unsigned dlit = dwatch.binary.lit; 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); if (!cbin && dbin) 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); } @@ -752,7 +754,7 @@ static bool resolvents_limited (kissat *solver, unsigned pivot, } static bool try_to_fast_eliminate (kissat *solver, unsigned pivot) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); if (!ACTIVE (pivot)) return false; const unsigned lit = LIT (pivot); @@ -824,16 +826,16 @@ void kissat_fast_variable_elimination (kissat *solver) { return; if (!GET_OPTION (fastel)) return; -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned variables_before = solver->active; #endif - assert (!solver->level); + KISSAT_assert (!solver->level); START (fastel); kissat_enter_dense_mode (solver, 0); kissat_connect_irredundant_large_clauses (solver); const unsigned fastelrounds = GET_OPTION (fastelrounds); const size_t fasteloccs = GET_OPTION (fasteloccs); -#ifndef QUIET +#ifndef KISSAT_QUIET unsigned eliminated = 0; #endif unsigned round = 0; @@ -846,7 +848,7 @@ void kissat_fast_variable_elimination (kissat *solver) { kissat_extremely_verbose ( solver, "gathering candidates for fast elimination round %u", round); - assert (EMPTY_STACK (candidates)); + KISSAT_assert (EMPTY_STACK (candidates)); flags *all_flags = solver->flags; for (all_variables (pivot)) { flags *pivot_flags = all_flags + pivot; @@ -868,7 +870,7 @@ void kissat_fast_variable_elimination (kissat *solver) { candidate candidate = {pivot, score}; PUSH_STACK (candidates, candidate); } -#ifndef QUIET +#ifndef KISSAT_QUIET const size_t size_candidates = SIZE_STACK (candidates); const size_t active_variables = solver->active; kissat_extremely_verbose ( @@ -903,7 +905,7 @@ void kissat_fast_variable_elimination (kissat *solver) { } } CLEAR_STACK (candidates); -#ifndef QUIET +#ifndef KISSAT_QUIET eliminated += eliminated_this_round; kissat_very_verbose ( 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; flush_eliminated_binary_clauses (solver); kissat_resume_sparse_mode (solver, true, 0); -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned original_variables = solver->statistics.variables_original; const unsigned variables_after = solver->active; kissat_verbose ( @@ -932,3 +934,5 @@ void kissat_fast_variable_elimination (kissat *solver) { STOP (fastel); REPORT (!eliminated, 'e'); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/fastel.h b/src/sat/kissat/fastel.h index a2a5cfcd5..56d711edd 100644 --- a/src/sat/kissat/fastel.h +++ b/src/sat/kissat/fastel.h @@ -1,6 +1,11 @@ #ifndef _fastel_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_fast_variable_elimination (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/fifo.h b/src/sat/kissat/fifo.h index 508989aa5..b94cfa628 100644 --- a/src/sat/kissat/fifo.h +++ b/src/sat/kissat/fifo.h @@ -5,6 +5,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define FIFO(TYPE) \ struct { \ TYPE *begin; \ @@ -29,7 +32,7 @@ #define MOVABLE_FIFO(F) (BEGIN_FIFO (F) == LIMIT_FIFO (F)) #define CAPACITY_FIFO(F) (ALLOCATED_FIFO (F) - START_FIFO (F)) -#define ENLARGE_FIFO(F) \ +#define ENLARGE_FIFO(T, F) \ do { \ size_t OLD_BEGIN_OFFSET = BEGIN_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 NEW_BYTES = NEW_CAPACITY * sizeof *BEGIN_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; \ LIMIT_FIFO (F) = START_FIFO (F) + NEW_CAPACITY / 2; \ BEGIN_FIFO (F) = START_FIFO (F) + OLD_BEGIN_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) #define MOVE_FIFO(F) \ @@ -55,22 +58,22 @@ END_FIFO (F) = BEGIN_FIFO (F) + SIZE; \ } while (0) -#define ENQUEUE_FIFO(F, E) \ +#define ENQUEUE_FIFO(T, F, E) \ do { \ if (FULL_FIFO (F)) \ - ENLARGE_FIFO (F); \ + ENLARGE_FIFO (T, F); \ *END_FIFO (F)++ = (E); \ } while (0) #define DEQUEUE_FIFO(F, E) \ do { \ - assert (!EMPTY_FIFO (F)); \ + KISSAT_assert (!EMPTY_FIFO (F)); \ (E) = *BEGIN_FIFO (F)++; \ if (MOVABLE_FIFO (F)) \ MOVE_FIFO (F); \ } 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) \ do { \ @@ -94,4 +97,6 @@ typedef struct unsigned_fifo unsigned_fifo; #define all_fifo all_stack +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/file.c b/src/sat/kissat/file.c index b6bda097b..e4486783d 100644 --- a/src/sat/kissat/file.c +++ b/src/sat/kissat/file.c @@ -7,7 +7,17 @@ #include #include #include + +#ifdef WIN32 +#define unlink _unlink +#define access _access +#define R_OK 4 +#define W_OK 2 +#else #include +#endif + +ABC_NAMESPACE_IMPL_START bool kissat_file_exists (const char *path) { if (!path) @@ -57,7 +67,7 @@ bool kissat_file_writable (const char *path) { res = 5; else { const size_t len = p - path; - char *dirname = malloc (len + 1); + char *dirname = (char*)malloc (len + 1); if (dirname) { strncpy (dirname, path, len); dirname[len] = 0; @@ -98,7 +108,7 @@ bool kissat_find_executable (const char *name) { if (!environment) return false; const size_t dirs_len = strlen (environment); - char *dirs = malloc (dirs_len + 1); + char *dirs = (char*)malloc (dirs_len + 1); if (!dirs) return false; strcpy (dirs, environment); @@ -106,16 +116,16 @@ bool kissat_find_executable (const char *name) { const char *end = dirs + dirs_len + 1; for (char *dir = dirs, *q; !res && dir != end; dir = q) { for (q = dir; *q && *q != ':'; q++) - assert (q + 1 < end); + KISSAT_assert (q + 1 < end); *q++ = 0; const size_t path_len = (q - dir) + name_len; - char *path = malloc (path_len + 1); + char *path = (char*)malloc (path_len + 1); if (!path) { free (dirs); return false; } sprintf (path, "%s/%s", dir, name); - assert (strlen (path) == path_len); + KISSAT_assert (strlen (path) == path_len); res = kissat_file_readable (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 bool match_signature (const char *path, const int *sig) { - assert (path); + KISSAT_assert (path); FILE *tmp = fopen (path, "r"); if (!tmp) return false; @@ -149,7 +159,7 @@ static FILE *open_pipe (const char *fmt, const char *path, size_t name_len = 0; while (fmt[name_len] && fmt[name_len] != ' ') name_len++; - char *name = malloc (name_len + 1); + char *name = (char*)malloc (name_len + 1); if (!name) return 0; strncpy (name, fmt, name_len); @@ -158,7 +168,7 @@ static FILE *open_pipe (const char *fmt, const char *path, free (name); if (!found) return 0; - char *cmd = malloc (strlen (fmt) + strlen (path)); + char *cmd = (char*)malloc (strlen (fmt) + strlen (path)); if (!cmd) return 0; 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) { - assert (file); - assert (file->file); + KISSAT_assert (file); + KISSAT_assert (file->file); #ifdef KISSAT_HAS_COMPRESSION if (file->close && file->compressed) pclose (file->file); #else - assert (!file->compressed); + KISSAT_assert (!file->compressed); #endif if (file->close && !file->compressed) fclose (file->file); file->file = 0; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/file.h b/src/sat/kissat/file.h index 300cdb138..7658fa7d2 100644 --- a/src/sat/kissat/file.h +++ b/src/sat/kissat/file.h @@ -9,6 +9,9 @@ #include "attribute.h" #include "keatures.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + bool kissat_file_exists (const char *path); bool kissat_file_readable (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 static inline size_t kissat_read (file *file, void *ptr, size_t bytes) { - assert (file); - assert (file->file); - assert (file->reading); + KISSAT_assert (file); + KISSAT_assert (file->file); + KISSAT_assert (file->reading); #ifdef KISSAT_HAS_UNLOCKEDIO size_t res = fread_unlocked (ptr, 1, bytes, file->file); #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) { - assert (file); - assert (file->file); - assert (!file->reading); + KISSAT_assert (file); + KISSAT_assert (file->file); + KISSAT_assert (!file->reading); #ifdef KISSAT_HAS_UNLOCKEDIO size_t res = fwrite_unlocked (ptr, 1, bytes, file->file); #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) { - assert (file); - assert (file->file); - assert (file->reading); + KISSAT_assert (file); + KISSAT_assert (file->file); + KISSAT_assert (file->reading); #ifdef KISSAT_HAS_UNLOCKEDIO int res = getc_unlocked (file->file); #else @@ -97,9 +100,9 @@ static inline int kissat_getc (file *file) { } static inline int kissat_putc (file *file, int ch) { - assert (file); - assert (file->file); - assert (!file->reading); + KISSAT_assert (file); + KISSAT_assert (file->file); + KISSAT_assert (!file->reading); #ifdef KISSAT_HAS_UNLOCKEDIO int res = putc_unlocked (ch, file->file); #else @@ -111,9 +114,9 @@ static inline int kissat_putc (file *file, int ch) { } static inline void kissat_flush (file *file) { - assert (file); - assert (file->file); - assert (!file->reading); + KISSAT_assert (file); + KISSAT_assert (file->file); + KISSAT_assert (!file->reading); #ifdef KISSAT_HAS_UNLOCKEDIO fflush_unlocked (file->file); #else @@ -121,4 +124,6 @@ static inline void kissat_flush (file *file) { #endif } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/flags.c b/src/sat/kissat/flags.c index b7189350e..86a6d6186 100644 --- a/src/sat/kissat/flags.c +++ b/src/sat/kissat/flags.c @@ -2,6 +2,8 @@ #include "inlineheap.h" #include "inlinequeue.h" +ABC_NAMESPACE_IMPL_START + static inline void activate_literal (kissat *solver, unsigned lit) { const unsigned idx = IDX (lit); flags *f = FLAGS (idx); @@ -10,37 +12,37 @@ static inline void activate_literal (kissat *solver, unsigned lit) { lit = STRIP (lit); LOG ("activating %s", LOGVAR (idx)); f->active = true; - assert (!f->fixed); - assert (!f->eliminated); + KISSAT_assert (!f->fixed); + KISSAT_assert (!f->eliminated); solver->active++; INC (variables_activated); 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); if (solver->stable) { const unsigned lit = LIT (idx); if (!VALUE (lit)) kissat_push_heap (solver, &solver->scores, idx); } - assert (solver->unassigned < UINT_MAX); + KISSAT_assert (solver->unassigned < UINT_MAX); solver->unassigned++; kissat_mark_removed_literal (solver, lit); kissat_mark_added_literal (solver, lit); - assert (!VALUE (lit)); - assert (!VALUE (NOT (lit))); - assert (!SAVED (idx)); - assert (!TARGET (idx)); - assert (!BEST (idx)); + KISSAT_assert (!VALUE (lit)); + KISSAT_assert (!VALUE (NOT (lit))); + KISSAT_assert (!SAVED (idx)); + KISSAT_assert (!TARGET (idx)); + KISSAT_assert (!BEST (idx)); } static inline void deactivate_variable (kissat *solver, flags *f, unsigned idx) { - assert (solver->flags + idx == f); + KISSAT_assert (solver->flags + idx == f); LOG ("deactivating %s", LOGVAR (idx)); - assert (f->active); - assert (f->eliminated || f->fixed); + KISSAT_assert (f->active); + KISSAT_assert (f->eliminated || f->fixed); f->active = false; - assert (solver->active > 0); + KISSAT_assert (solver->active > 0); solver->active--; kissat_dequeue (solver, 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) { - assert (VALUE (lit) > 0); + KISSAT_assert (VALUE (lit) > 0); const unsigned idx = IDX (lit); LOG ("marking internal %s as fixed", LOGVAR (idx)); flags *f = FLAGS (idx); - assert (f->active); - assert (!f->eliminated); - assert (!f->fixed); + KISSAT_assert (f->active); + KISSAT_assert (!f->eliminated); + KISSAT_assert (!f->fixed); f->fixed = true; deactivate_variable (solver, f, idx); INC (units); int elit = kissat_export_literal (solver, lit); - assert (elit); + KISSAT_assert (elit); PUSH_STACK (solver->units, elit); LOG ("pushed external unit literal %d (internal %u)", elit, lit); } void kissat_mark_eliminated_variable (kissat *solver, unsigned idx) { const unsigned lit = LIT (idx); - assert (!VALUE (lit)); + KISSAT_assert (!VALUE (lit)); LOG ("marking internal %s as eliminated", LOGVAR (idx)); flags *f = FLAGS (idx); - assert (f->active); - assert (!f->eliminated); - assert (!f->fixed); + KISSAT_assert (f->active); + KISSAT_assert (!f->eliminated); + KISSAT_assert (!f->fixed); f->eliminated = true; deactivate_variable (solver, f, idx); int elit = kissat_export_literal (solver, lit); - assert (elit); - assert (elit != INT_MIN); + KISSAT_assert (elit); + KISSAT_assert (elit != INT_MIN); unsigned eidx = ABS (elit); import *import = &PEEK_STACK (solver->import, eidx); - assert (!import->eliminated); - assert (import->imported); - assert (STRIP (import->lit) == STRIP (lit)); + KISSAT_assert (!import->eliminated); + KISSAT_assert (import->imported); + KISSAT_assert (STRIP (import->lit) == STRIP (lit)); size_t pos = SIZE_STACK (solver->eliminated); - assert (pos < (1u << 30)); + KISSAT_assert (pos < (1u << 30)); import->lit = pos; import->eliminated = true; PUSH_STACK (solver->eliminated, (value) 0); LOG ("marked external variable %u as eliminated", eidx); - assert (solver->unassigned > 0); + KISSAT_assert (solver->unassigned > 0); solver->unassigned--; } @@ -113,3 +115,5 @@ void kissat_mark_added_literals (kissat *solver, unsigned size, for (unsigned i = 0; i < size; i++) kissat_mark_added_literal (solver, lits[i]); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/flags.h b/src/sat/kissat/flags.h index fd73b2f5b..33248314a 100644 --- a/src/sat/kissat/flags.h +++ b/src/sat/kissat/flags.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct flags flags; struct flags { @@ -18,7 +21,7 @@ struct flags { 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 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_removed_literals (struct kissat *, unsigned, unsigned *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/format.c b/src/sat/kissat/format.c index d8e247d1a..b091a86bb 100644 --- a/src/sat/kissat/format.c +++ b/src/sat/kissat/format.c @@ -7,8 +7,10 @@ #include #include -char *kissat_next_format_string (format *format) { - assert (format->pos < NUM_FORMAT_STRINGS); +ABC_NAMESPACE_IMPL_START + +char *kissat_next_format_string (kormat *format) { + KISSAT_assert (format->pos < NUM_FORMAT_STRINGS); char *res = format->str[format->pos++]; if (format->pos == NUM_FORMAT_STRINGS) 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)) { unsigned 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); } else if (w >= 1000 && !(w % 1000)) { unsigned l; @@ -30,13 +32,13 @@ static void format_count (char *res, uint64_t 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); format_count (res, w); 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) return "true"; if (boolean && !value) @@ -54,7 +56,7 @@ const char *kissat_format_value (format *format, bool boolean, int value) { 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); if (bytes < (1u << 10)) sprintf (res, "%" PRIu64 " bytes", bytes); @@ -70,7 +72,7 @@ const char *kissat_format_bytes (format *format, uint64_t bytes) { return res; } -const char *kissat_format_time (format *format, double seconds) { +const char *kissat_format_time (kormat *format, double seconds) { if (!seconds) return "0s"; char *res = kissat_next_format_string (format); @@ -106,10 +108,10 @@ const char *kissat_format_time (format *format, double seconds) { return res; } -const char *kissat_format_signs (format *format, unsigned size, +const char *kissat_format_signs (kormat *format, unsigned size, word signs) { char *res = kissat_next_format_string (format); - assert (size + 1 < FORMAT_STRING_SIZE); + KISSAT_assert (size + 1 < FORMAT_STRING_SIZE); char *p = res; word 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; } -const char *kissat_format_ordinal (format *format, uint64_t ordinal) { +const char *kissat_format_ordinal (kormat *format, uint64_t ordinal) { char const *suffix; unsigned mod100 = ordinal % 100; 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); return res; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/format.h b/src/sat/kissat/format.h index d52e93d71..62e345e3b 100644 --- a/src/sat/kissat/format.h +++ b/src/sat/kissat/format.h @@ -6,24 +6,27 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define NUM_FORMAT_STRINGS 16 #define FORMAT_STRING_SIZE 128 -typedef struct format format; +typedef struct kormat kormat; -struct format { +struct kormat { unsigned pos; 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_count (format *, uint64_t); -char const *kissat_format_ordinal (format *, uint64_t); -char const *kissat_format_signs (format *, unsigned size, word); -char const *kissat_format_time (format *, double seconds); -char const *kissat_format_value (format *, bool boolean, int value); +char const *kissat_format_bytes (kormat *, uint64_t bytes); +char const *kissat_format_count (kormat *, uint64_t); +char const *kissat_format_ordinal (kormat *, uint64_t); +char const *kissat_format_signs (kormat *, unsigned size, word); +char const *kissat_format_time (kormat *, double seconds); +char const *kissat_format_value (kormat *, bool boolean, int value); #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) \ kissat_format_value (&solver->format, BOOLEAN, VALUE) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/forward.c b/src/sat/kissat/forward.c index d2bbbab47..098de2367 100644 --- a/src/sat/kissat/forward.c +++ b/src/sat/kissat/forward.c @@ -10,6 +10,8 @@ #include +ABC_NAMESPACE_IMPL_START + static size_t remove_duplicated_binaries_with_literal (kissat *solver, unsigned lit) { watches *watches = &WATCHES (lit); @@ -21,7 +23,7 @@ static size_t remove_duplicated_binaries_with_literal (kissat *solver, while (p != end) { const watch watch = *q++ = *p++; - assert (watch.type.binary); + KISSAT_assert (watch.type.binary); const unsigned other = watch.binary.lit; struct flags *f = flags + IDX (other); 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) { LOG ("removing all duplicated irredundant binary clauses"); -#if !defined(QUIET) || !defined(NDEBUG) +#if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG) size_t removed = 0; #endif - assert (EMPTY_STACK (solver->delayed)); + KISSAT_assert (EMPTY_STACK (solver->delayed)); const flags *const all_flags = solver->flags; @@ -82,16 +84,16 @@ static void remove_all_duplicated_binary_clauses (kissat *solver) { continue; const unsigned int lit = LIT (idx); const unsigned int not_lit = NOT (lit); -#if !defined(QUIET) || !defined(NDEBUG) +#if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG) removed += #endif remove_duplicated_binaries_with_literal (solver, lit); -#if !defined(QUIET) || !defined(NDEBUG) +#if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG) removed += #endif remove_duplicated_binaries_with_literal (solver, not_lit); } - assert (!(removed & 1)); + KISSAT_assert (!(removed & 1)); size_t units = SIZE_STACK (solver->delayed); if (units) { @@ -141,7 +143,7 @@ static void find_forward_subsumption_candidates (kissat *solver, continue; if (c->size > clslim) continue; - assert (c->size > 2); + KISSAT_assert (c->size > 2); unsigned subsume = 0; for (all_literals_in_clause (lit, c)) { const unsigned idx = IDX (lit); @@ -151,7 +153,7 @@ static void find_forward_subsumption_candidates (kissat *solver, if (values[lit] > 0) { LOGCLS (c, "satisfied by %s", LOGLIT (lit)); kissat_mark_clause_as_garbage (solver, c); - assert (c->garbage); + KISSAT_assert (c->garbage); break; } } @@ -166,7 +168,7 @@ static void find_forward_subsumption_candidates (kissat *solver, static inline unsigned 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); (void) solver; return c->size; @@ -223,14 +225,14 @@ static inline bool forward_literal (kissat *solver, unsigned lit, const unsigned not_other = NOT (other); if (marks[not_other]) { LOGBINARY (lit, other, "forward %s strengthener", LOGLIT (other)); - assert (!subsume); + KISSAT_assert (!subsume); *remove = not_other; break; } } } else { const reference ref = watch.large.ref; - assert (ref < SIZE_STACK (solver->arena)); + KISSAT_assert (ref < SIZE_STACK (solver->arena)); clause *d = (clause *) (arena + ref); steps++; @@ -253,34 +255,34 @@ static inline bool forward_literal (kissat *solver, unsigned lit, if (value > 0) { LOGCLS (d, "satisfied by %s", LOGLIT (other)); kissat_mark_clause_as_garbage (solver, d); - assert (d->garbage); + KISSAT_assert (d->garbage); candidate = INVALID_LIT; subsume = false; break; } if (!subsume) { - assert (candidate != INVALID_LIT); + KISSAT_assert (candidate != INVALID_LIT); candidate = INVALID_LIT; break; } subsume = false; const unsigned not_other = NOT (other); if (!marks[not_other]) { - assert (candidate == INVALID_LIT); + KISSAT_assert (candidate == INVALID_LIT); break; } candidate = not_other; } if (d->garbage) { - assert (!subsume); + KISSAT_assert (!subsume); q--; break; } if (subsume) { LOGCLS (d, "forward subsuming"); - assert (subsume); + KISSAT_assert (subsume); break; } @@ -316,7 +318,7 @@ static inline bool forward_marked_clause (kissat *solver, clause *c, if (!flags[idx].active) continue; - assert (!VALUE (lit)); + KISSAT_assert (!VALUE (lit)); if (forward_literal (solver, lit, true, remove, limit)) 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, bool *strengthened, unsigneds *new_binaries) { - assert (!c->garbage); + KISSAT_assert (!c->garbage); LOGCLS2 (c, "trying to forward subsume"); value *marks = solver->marks; @@ -344,7 +346,7 @@ static bool forward_subsumed_clause (kissat *solver, clause *c, if (value > 0) { LOGCLS (c, "satisfied by %s", LOGLIT (lit)); kissat_mark_clause_as_garbage (solver, c); - assert (c->garbage); + KISSAT_assert (c->garbage); break; } marks[lit] = 1; @@ -370,7 +372,7 @@ static bool forward_subsumed_clause (kissat *solver, clause *c, } 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)); kissat_learned_unit (solver, unit); 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)); if (non_false == 2) { unit ^= remove; - assert (VALID_INTERNAL_LITERAL (unit)); + KISSAT_assert (VALID_INTERNAL_LITERAL (unit)); LOG ("forward strengthened unit clause %s", LOGLIT (unit)); kissat_learned_unit (solver, unit); 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]; if (value < 0) continue; - assert (!value); + KISSAT_assert (!value); lits[new_size++] = lit; kissat_mark_added_literal (solver, lit); } - assert (new_size == non_false - 1); - assert (new_size > 2); + KISSAT_assert (new_size == non_false - 1); + KISSAT_assert (new_size > 2); if (!c->shrunken) { c->shrunken = true; lits[c->size - 1] = INVALID_LIT; @@ -431,9 +433,9 @@ static bool forward_subsumed_clause (kissat *solver, clause *c, c->subsume = true; LOGCLS (c, "forward strengthened"); } else { - assert (non_false == 3); + KISSAT_assert (non_false == 3); LOGCLS (c, "garbage"); - assert (!c->garbage); + KISSAT_assert (!c->garbage); const size_t bytes = kissat_actual_bytes_of_clause (c); ADD (arena_garbage, bytes); c->garbage = true; @@ -444,25 +446,25 @@ static bool forward_subsumed_clause (kissat *solver, clause *c, const value value = values[lit]; if (value < 0) continue; - assert (!value); + KISSAT_assert (!value); if (first == INVALID_LIT) first = lit; else { - assert (second == INVALID_LIT); + KISSAT_assert (second == INVALID_LIT); second = lit; } kissat_mark_added_literal (solver, lit); } - assert (first != INVALID_LIT); - assert (second != INVALID_LIT); + KISSAT_assert (first != INVALID_LIT); + KISSAT_assert (second != INVALID_LIT); LOGBINARY (first, second, "forward strengthened"); kissat_watch_other (solver, first, second); kissat_watch_other (solver, second, first); - assert (new_binaries); - assert (solver->statistics.clauses_irredundant); - solver->statistics.clauses_irredundant--; - assert (solver->statistics.clauses_binary < UINT64_MAX); - solver->statistics.clauses_binary++; + KISSAT_assert (new_binaries); + KISSAT_assert (solver->statistics_.clauses_irredundant); + solver->statistics_.clauses_irredundant--; + KISSAT_assert (solver->statistics_.clauses_binary < UINT64_MAX); + solver->statistics_.clauses_binary++; PUSH_STACK (*new_binaries, first); 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) { - assert (!c->garbage); + KISSAT_assert (!c->garbage); unsigned min_lit = INVALID_LIT; size_t min_occs = MAX_SIZE_T; @@ -513,19 +515,19 @@ static bool forward_subsume_all_clauses (kissat *solver) { INIT_STACK (candidates); find_forward_subsumption_candidates (solver, &candidates); -#ifndef QUIET +#ifndef KISSAT_QUIET size_t scheduled = SIZE_STACK (candidates); kissat_phase ( solver, "forward", GET (forward_subsumptions), "scheduled %zu irredundant clauses %.0f%%", scheduled, - kissat_percent (scheduled, solver->statistics.clauses_irredundant)); + kissat_percent (scheduled, solver->statistics_.clauses_irredundant)); #endif sort_forward_subsumption_candidates (solver, &candidates); const reference *const end_of_candidates = END_STACK (candidates); reference *p = BEGIN_STACK (candidates); -#ifndef QUIET +#ifndef KISSAT_QUIET size_t subsumed = 0; size_t strengthened = 0; size_t checked = 0; @@ -541,25 +543,25 @@ static bool forward_subsume_all_clauses (kissat *solver) { ward *arena = BEGIN_STACK (solver->arena); while (p != end_of_candidates) { - if (solver->statistics.forward_steps > steps_limit) + if (solver->statistics_.forward_steps > steps_limit) break; if (TERMINATED (forward_terminated_1)) break; reference ref = *p++; clause *c = (clause *) (arena + ref); - assert (kissat_clause_in_arena (solver, c)); - assert (!c->garbage); -#ifndef QUIET + KISSAT_assert (kissat_clause_in_arena (solver, c)); + KISSAT_assert (!c->garbage); +#ifndef KISSAT_QUIET checked++; #endif bool not_subsumed_but_strengthened = false; if (forward_subsumed_clause ( solver, c, ¬_subsumed_but_strengthened, &new_binaries)) { -#ifndef QUIET +#ifndef KISSAT_QUIET subsumed++; #endif } else if (not_subsumed_but_strengthened) { -#ifndef QUIET +#ifndef KISSAT_QUIET strengthened++; #endif } @@ -569,7 +571,7 @@ static bool forward_subsume_all_clauses (kissat *solver) { connect_subsuming (solver, occlim, c); } } -#ifndef QUIET +#ifndef KISSAT_QUIET if (subsumed) kissat_phase (solver, "forward", GET (forward_subsumptions), "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); unsigned reactivated = 0; -#ifndef QUIET +#ifndef KISSAT_QUIET size_t remain = 0; #endif for (reference *q = BEGIN_STACK (candidates); q != end_of_candidates; q++) { const reference ref = *q; clause *c = (clause *) (arena + ref); - assert (kissat_clause_in_arena (solver, c)); + KISSAT_assert (kissat_clause_in_arena (solver, c)); if (c->garbage) continue; if (q < p && !c->subsume) continue; -#ifndef QUIET +#ifndef KISSAT_QUIET remain++; #endif for (all_literals_in_clause (lit, c)) { @@ -618,7 +620,7 @@ static bool forward_subsume_all_clauses (kissat *solver) { "in remaining or strengthened", LOGVAR (idx)); f->subsume = true; - assert (reactivated < UINT_MAX); + KISSAT_assert (reactivated < UINT_MAX); reactivated++; } } @@ -638,7 +640,7 @@ static bool forward_subsume_all_clauses (kissat *solver) { "in strengthened binary clause", LOGVAR (idx)); f->subsume = true; - assert (reactivated < UINT_MAX); + KISSAT_assert (reactivated < UINT_MAX); reactivated++; } } @@ -649,7 +651,7 @@ static bool forward_subsume_all_clauses (kissat *solver) { "in next forward subsumption", reactivated, kissat_percent (reactivated, solver->active)); -#ifndef QUIET +#ifndef KISSAT_QUIET if (remain) kissat_phase (solver, "forward", GET (forward_subsumptions), "%zu unchecked clauses remain %.0f%%", remain, @@ -668,7 +670,7 @@ static bool forward_subsume_all_clauses (kissat *solver) { completed = false; else completed = true; -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_very_verbose (solver, "forward subsumption considered %scomplete", completed ? "" : "in"); #endif @@ -678,9 +680,9 @@ static bool forward_subsume_all_clauses (kissat *solver) { bool kissat_forward_subsume_during_elimination (kissat *solver) { START (subsume); START (forward); - assert (GET_OPTION (forward)); + KISSAT_assert (GET_OPTION (forward)); INC (forward_subsumptions); - assert (!solver->watching); + KISSAT_assert (!solver->watching); remove_all_duplicated_binary_clauses (solver); bool complete = true; if (!solver->inconsistent) @@ -689,3 +691,5 @@ bool kissat_forward_subsume_during_elimination (kissat *solver) { STOP (subsume); return complete; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/forward.h b/src/sat/kissat/forward.h index 95a8dc5d3..193173166 100644 --- a/src/sat/kissat/forward.h +++ b/src/sat/kissat/forward.h @@ -3,8 +3,13 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_forward_subsume_during_elimination (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/frames.h b/src/sat/kissat/frames.h index 088877b2a..fd997cda9 100644 --- a/src/sat/kissat/frames.h +++ b/src/sat/kissat/frames.h @@ -6,6 +6,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct frame frame; typedef struct slice slice; @@ -14,7 +17,7 @@ struct frame { unsigned decision; unsigned trail; unsigned used; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG unsigned saved; #endif }; @@ -29,4 +32,6 @@ struct kissat; #define FRAME(LEVEL) (PEEK_STACK (solver->frames, (LEVEL))) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/gates.c b/src/sat/kissat/gates.c index 7da560181..b63d4b25b 100644 --- a/src/sat/kissat/gates.c +++ b/src/sat/kissat/gates.c @@ -6,6 +6,8 @@ #include "ifthenelse.h" #include "inline.h" +ABC_NAMESPACE_IMPL_START + size_t kissat_mark_binaries (kissat *solver, unsigned lit) { value *marks = solver->marks; size_t res = 0; @@ -14,7 +16,7 @@ size_t kissat_mark_binaries (kissat *solver, unsigned lit) { if (!watch.type.binary) continue; const unsigned other = watch.binary.lit; - assert (!solver->values[other]); + KISSAT_assert (!solver->values[other]); if (marks[other]) continue; marks[other] = 1; @@ -60,14 +62,14 @@ bool kissat_find_gates (kissat *solver, unsigned lit) { static void get_antecedents (kissat *solver, unsigned lit, unsigned negative) { - assert (!solver->watching); - assert (!negative || negative == 1); + KISSAT_assert (!solver->watching); + KISSAT_assert (!negative || negative == 1); statches *gates = solver->gates + negative; watches *watches = &WATCHES (lit); 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 end_gates = END_STACK (*gates); @@ -85,7 +87,7 @@ static void get_antecedents (kissat *solver, unsigned lit, PUSH_STACK (*antecedents, watch); } - assert (g == end_gates); + KISSAT_assert (g == end_gates); #ifdef LOGGING size_t size_gates = SIZE_STACK (*gates); 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, NOT (lit), 1); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/gates.h b/src/sat/kissat/gates.h index f5ce18a90..8f941aa3d 100644 --- a/src/sat/kissat/gates.h +++ b/src/sat/kissat/gates.h @@ -4,6 +4,9 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; struct clause; @@ -19,4 +22,6 @@ void kissat_unmark_binaries (struct kissat *, unsigned lit); #define GATE_ELIMINATED(NAME) (&solver->statistics.NAME##_eliminated) #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/global.h b/src/sat/kissat/global.h new file mode 100644 index 000000000..e6c20bc05 --- /dev/null +++ b/src/sat/kissat/global.h @@ -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 diff --git a/src/sat/kissat/handle.h b/src/sat/kissat/handle.h index 132fc3b68..03e5529ba 100644 --- a/src/sat/kissat/handle.h +++ b/src/sat/kissat/handle.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + void kissat_init_signal_handler (void (*handler) (int)); void kissat_reset_signal_handler (void); @@ -40,4 +43,6 @@ kissat_signal_name (int sig) // clang-format on +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/heap.c b/src/sat/kissat/heap.c index 12deaad75..584c58e6b 100644 --- a/src/sat/kissat/heap.c +++ b/src/sat/kissat/heap.c @@ -5,6 +5,8 @@ #include +ABC_NAMESPACE_IMPL_START + void kissat_release_heap (kissat *solver, heap *heap) { RELEASE_STACK (heap->stack); DEALLOC (heap->pos, heap->size); @@ -12,7 +14,7 @@ void kissat_release_heap (kissat *solver, heap *heap) { memset (heap, 0, sizeof *heap); } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG void kissat_check_heap (heap *heap) { 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++) { const unsigned idx = stack[i]; const unsigned idx_pos = pos[idx]; - assert (idx_pos == i); + KISSAT_assert (idx_pos == i); unsigned child_pos = HEAP_CHILD (idx_pos); unsigned parent_pos = HEAP_PARENT (child_pos); - assert (parent_pos == idx_pos); + KISSAT_assert (parent_pos == idx_pos); if (child_pos < end) { unsigned child = stack[child_pos]; - assert (score[idx] >= score[child]); + KISSAT_assert (score[idx] >= score[child]); if (++child_pos < end) { parent_pos = HEAP_PARENT (child_pos); - assert (parent_pos == idx_pos); + KISSAT_assert (parent_pos == idx_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", (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)); 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)); } else { if (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; #ifdef CHECK_HEAP @@ -69,7 +71,7 @@ void kissat_rescale_heap (kissat *solver, heap *heap, double factor) { double *score = heap->score; for (unsigned i = 0; i < heap->vars; i++) score[i] *= factor; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG kissat_check_heap (heap); #endif #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) { const unsigned old_vars = heap->vars; - assert (old_vars < new_vars); - assert (new_vars <= heap->size); + KISSAT_assert (old_vars < new_vars); + KISSAT_assert (new_vars <= heap->size); const size_t delta = new_vars - heap->vars; memset (heap->pos + old_vars, 0xff, delta * sizeof (unsigned)); heap->vars = new_vars; @@ -92,7 +94,7 @@ void kissat_enlarge_heap (kissat *solver, heap *heap, unsigned new_vars) { #endif } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG static void dump_heap (heap *heap) { 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); } #endif + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/heap.h b/src/sat/kissat/heap.h index 8a9736ee2..724ff2ab3 100644 --- a/src/sat/kissat/heap.h +++ b/src/sat/kissat/heap.h @@ -8,6 +8,9 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define DISCONTAIN UINT_MAX #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) { - assert (!kissat_empty_heap (heap)); + KISSAT_assert (!kissat_empty_heap (heap)); 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) { if (!heap->tainted) return 0; - assert (heap->vars); + KISSAT_assert (heap->vars); const double *const score = heap->score; const double *const end = score + heap->vars; double res = score[0]; @@ -70,11 +73,11 @@ static inline double kissat_max_score_on_heap (heap *heap) { return res; } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG void kissat_dump_heap (heap *); #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG void kissat_check_heap (heap *); #else #define kissat_check_heap(...) \ @@ -82,4 +85,6 @@ void kissat_check_heap (heap *); } while (0) #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/ifthenelse.c b/src/sat/kissat/ifthenelse.c index db4031f68..b4224422e 100644 --- a/src/sat/kissat/ifthenelse.c +++ b/src/sat/kissat/ifthenelse.c @@ -3,6 +3,8 @@ #include "gates.h" #include "inline.h" +ABC_NAMESPACE_IMPL_START + static bool get_ternary_clause (kissat *solver, reference ref, unsigned *p, unsigned *q, unsigned *r) { 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) return false; - assert (a != INVALID_LIT); - assert (b != INVALID_LIT); - assert (c != INVALID_LIT); + KISSAT_assert (a != INVALID_LIT); + KISSAT_assert (b != INVALID_LIT); + KISSAT_assert (c != INVALID_LIT); *p = a; *q = b; *r = c; @@ -121,7 +123,7 @@ bool kissat_find_if_then_else_gate (kissat *solver, unsigned lit, SWAP (unsigned, a1, b1); if (c1 == lit) SWAP (unsigned, a1, c1); - assert (a1 == lit); + KISSAT_assert (a1 == lit); for (const watch *p2 = p1 + 1; steps < limit && p2 != end; p2++) { watch w2 = *p2; if (w2.type.binary) @@ -133,7 +135,7 @@ bool kissat_find_if_then_else_gate (kissat *solver, unsigned lit, SWAP (unsigned, a2, b2); if (c2 == lit) SWAP (unsigned, a2, c2); - assert (a2 == lit); + KISSAT_assert (a2 == lit); if (STRIP (b1) == STRIP (c2)) SWAP (unsigned, b2, c2); if (STRIP (c1) == STRIP (c2)) @@ -172,3 +174,5 @@ bool kissat_find_if_then_else_gate (kissat *solver, unsigned lit, } return false; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/ifthenelse.h b/src/sat/kissat/ifthenelse.h index 82097883e..8a9437d65 100644 --- a/src/sat/kissat/ifthenelse.h +++ b/src/sat/kissat/ifthenelse.h @@ -3,9 +3,14 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_find_if_then_else_gate (struct kissat *, unsigned lit, unsigned negative); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/import.c b/src/sat/kissat/import.c index 38ca379c0..6f70ff58f 100644 --- a/src/sat/kissat/import.c +++ b/src/sat/kissat/import.c @@ -2,6 +2,8 @@ #include "logging.h" #include "resize.h" +ABC_NAMESPACE_IMPL_START + static void adjust_imports_for_external_literal (kissat *solver, unsigned eidx) { while (eidx >= SIZE_STACK (solver->import)) { @@ -27,13 +29,13 @@ static void adjust_exports_for_external_literal (kissat *solver, INC (variables_extension); else INC (variables_original); - assert (!import->eliminated); + KISSAT_assert (!import->eliminated); import->lit = ilit; LOG ("importing %s external variable %u as internal literal %u", extension ? "extension" : "original", eidx, ilit); - while (iidx >= SIZE_STACK (solver->export)) - PUSH_STACK (solver->export, 0); - POKE_STACK (solver->export, iidx, (int) eidx); + while (iidx >= SIZE_STACK (solver->export_)) + PUSH_STACK (solver->export_, 0); + POKE_STACK (solver->export_, iidx, (int) 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; if (!import->imported) adjust_exports_for_external_literal (solver, eidx, extension); - assert (import->imported); + KISSAT_assert (import->imported); ilit = import->lit; if (elit < 0) ilit = NOT (ilit); - assert (VALID_INTERNAL_LITERAL (ilit)); + KISSAT_assert (VALID_INTERNAL_LITERAL (ilit)); return ilit; } unsigned kissat_import_literal (kissat *solver, int elit) { - assert (VALID_EXTERNAL_LITERAL (elit)); + KISSAT_assert (VALID_EXTERNAL_LITERAL (elit)); if (GET_OPTION (tumble)) return import_literal (solver, elit, false); 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); if (eidx < other) return import_literal (solver, elit, false); @@ -69,7 +71,7 @@ unsigned kissat_import_literal (kissat *solver, int elit) { unsigned ilit = 0; do { - assert (VALID_EXTERNAL_LITERAL ((int) other)); + KISSAT_assert (VALID_EXTERNAL_LITERAL ((int) other)); ilit = import_literal (solver, other, false); } while (other++ < eidx); @@ -81,20 +83,22 @@ unsigned kissat_import_literal (kissat *solver, int elit) { unsigned kissat_fresh_literal (kissat *solver) { size_t imported = SIZE_STACK (solver->import); - assert (imported <= EXTERNAL_MAX_VAR); + KISSAT_assert (imported <= EXTERNAL_MAX_VAR); if (imported == EXTERNAL_MAX_VAR) { LOG ("can not get another external variable"); return INVALID_LIT; } - assert (imported <= (unsigned) INT_MAX); + KISSAT_assert (imported <= (unsigned) INT_MAX); int eidx = (int) imported; unsigned res = import_literal (solver, eidx, true); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG struct import *import = &PEEK_STACK (solver->import, imported); - assert (import->imported); - assert (import->extension); + KISSAT_assert (import->imported); + KISSAT_assert (import->extension); #endif INC (fresh); kissat_activate_literal (solver, res); return res; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/import.h b/src/sat/kissat/import.h index 4b82a5f3c..87261ec2f 100644 --- a/src/sat/kissat/import.h +++ b/src/sat/kissat/import.h @@ -1,9 +1,14 @@ #ifndef _import_h_INLCUDED #define _import_h_INLCUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; unsigned kissat_import_literal (struct kissat *solver, int lit); unsigned kissat_fresh_literal (struct kissat *solver); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/inline.h b/src/sat/kissat/inline.h index d1f9b789f..e78cdeeea 100644 --- a/src/sat/kissat/inline.h +++ b/src/sat/kissat/inline.h @@ -4,6 +4,9 @@ #include "inlinevector.h" #include "logging.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + #ifdef METRICS static inline size_t kissat_allocated (kissat *solver) { @@ -13,8 +16,8 @@ static inline size_t kissat_allocated (kissat *solver) { #endif static inline bool kissat_propagated (kissat *solver) { - assert (BEGIN_ARRAY (solver->trail) <= solver->propagate); - assert (solver->propagate <= END_ARRAY (solver->trail)); + KISSAT_assert (BEGIN_ARRAY (solver->trail) <= solver->propagate); + KISSAT_assert (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) { - assert (lit < LITS); + KISSAT_assert (lit < LITS); const value res = solver->values[lit]; if (!res) return 0; @@ -83,7 +86,7 @@ static inline void kissat_push_blocking_watch (kissat *solver, watches *watches, unsigned blocking, reference ref) { - assert (solver->watching); + KISSAT_assert (solver->watching); const watch head = kissat_blocking_watch (blocking); PUSH_WATCHES (*watches, head); 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, unsigned blocking, reference ref) { - assert (solver->watching); + KISSAT_assert (solver->watching); LOGREF3 (ref, "watching %s blocking %s in", LOGLIT (lit), LOGLIT (blocking)); 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, reference ref) { - assert (solver->watching); + KISSAT_assert (solver->watching); LOGREF3 (ref, "unwatching %s in", LOGLIT (lit)); watches *watches = &WATCHES (lit); 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, unsigned other) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); watches *watches = &WATCHES (lit); const watch watch = kissat_binary_watch (other); REMOVE_WATCHES (*watches, watch); @@ -132,7 +135,7 @@ static inline void kissat_disconnect_binary (kissat *solver, unsigned lit, static inline void kissat_disconnect_reference (kissat *solver, unsigned lit, reference ref) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); LOGREF3 (ref, "disconnecting %s in", LOGLIT (lit)); const watch watch = kissat_large_watch (ref); 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, unsigned b, reference ref) { - assert (solver->watching); + KISSAT_assert (solver->watching); kissat_watch_blocking (solver, a, b, ref); kissat_watch_blocking (solver, b, a, ref); } static inline void kissat_connect_literal (kissat *solver, unsigned lit, reference ref) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); LOGREF3 (ref, "connecting %s in", LOGLIT (lit)); watches *watches = &WATCHES (lit); 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, reference 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; } static inline reference kissat_reference_clause (kissat *solver, 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); } @@ -176,33 +179,33 @@ static inline void kissat_inlined_connect_clause (kissat *solver, watches *all_watches, clause *c, reference ref) { - assert (!solver->watching); - assert (ref == kissat_reference_clause (solver, c)); - assert (c == kissat_dereference_clause (solver, ref)); + KISSAT_assert (!solver->watching); + KISSAT_assert (ref == kissat_reference_clause (solver, c)); + KISSAT_assert (c == kissat_dereference_clause (solver, ref)); for (all_literals_in_clause (lit, c)) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); LOGREF3 (ref, "connecting %s in", LOGLIT (lit)); - assert (lit < LITS); + KISSAT_assert (lit < LITS); watches *lit_watches = all_watches + lit; kissat_push_large_watch (solver, lit_watches, ref); } } 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); kissat_watch_reference (solver, c->lits[0], c->lits[1], ref); } static inline int kissat_export_literal (kissat *solver, unsigned ilit) { const unsigned iidx = IDX (ilit); - assert (iidx < (unsigned) INT_MAX); - int elit = PEEK_STACK (solver->export, iidx); + KISSAT_assert (iidx < (unsigned) INT_MAX); + int elit = PEEK_STACK (solver->export_, iidx); if (!elit) return 0; if (NEGATED (ilit)) elit = -elit; - assert (VALID_EXTERNAL_LITERAL (elit)); + KISSAT_assert (VALID_EXTERNAL_LITERAL (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, unsigned idx) { - assert (idx < VARS); + KISSAT_assert (idx < VARS); struct assigned *a = assigned + idx; - assert (!a->analyzed); + KISSAT_assert (!a->analyzed); a->analyzed = true; PUSH_STACK (solver->analyzed, idx); LOG2 ("%s analyzed", LOGVAR (idx)); @@ -256,9 +259,9 @@ static inline bool kissat_analyzed (kissat *solver) { static inline void kissat_push_removable (kissat *solver, assigned *assigned, unsigned idx) { - assert (idx < VARS); + KISSAT_assert (idx < VARS); struct assigned *a = assigned + idx; - assert (!a->removable); + KISSAT_assert (!a->removable); a->removable = true; PUSH_STACK (solver->removable, 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, unsigned idx) { - assert (idx < VARS); + KISSAT_assert (idx < VARS); struct assigned *a = assigned + idx; - assert (!a->poisoned); + KISSAT_assert (!a->poisoned); a->poisoned = true; PUSH_STACK (solver->poisoned, idx); LOG2 ("%s poisoned", LOGVAR (idx)); @@ -276,17 +279,17 @@ static inline void kissat_push_poisoned (kissat *solver, assigned *assigned, static inline void kissat_push_shrinkable (kissat *solver, assigned *assigned, unsigned idx) { - assert (idx < VARS); + KISSAT_assert (idx < VARS); struct assigned *a = assigned + idx; - assert (!a->shrinkable); + KISSAT_assert (!a->shrinkable); a->shrinkable = true; PUSH_STACK (solver->shrinkable, idx); LOG2 ("%s shrinkable", LOGVAR (idx)); } static inline int kissat_checking (kissat *solver) { -#ifndef NDEBUG -#ifdef NOPTIONS +#ifndef KISSAT_NDEBUG +#ifdef KISSAT_NOPTIONS (void) solver; #endif return GET_OPTION (check); @@ -298,7 +301,7 @@ static inline int kissat_checking (kissat *solver) { static inline bool kissat_logging (kissat *solver) { #ifdef LOGGING -#ifdef NOPTIONS +#ifdef KISSAT_NOPTIONS (void) solver; #endif return GET_OPTION (log) > 0; @@ -309,7 +312,7 @@ static inline bool kissat_logging (kissat *solver) { } static inline bool kissat_proving (kissat *solver) { -#ifdef NPROOFS +#ifdef KISSAT_NPROOFS (void) solver; return false; #else @@ -321,8 +324,10 @@ static inline bool kissat_checking_or_proving (kissat *solver) { return kissat_checking (solver) || kissat_proving (solver); } -#if !defined(NDEBUG) || !defined(NPROOFS) +#if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) #define CHECKING_OR_PROVING #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/inlineassign.h b/src/sat/kissat/inlineassign.h index b8d3b88a1..8ac2b7c7c 100644 --- a/src/sat/kissat/inlineassign.h +++ b/src/sat/kissat/inlineassign.h @@ -1,6 +1,9 @@ #ifndef _inlineassign_h_INLCUDED #define _inlineassign_h_INLCUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + #ifdef FAST_ASSIGN #define kissat_assign kissat_fast_assign #endif @@ -17,24 +20,26 @@ static inline void kissat_assign (kissat *solver, const bool probing, watches watches = WATCHES (not_lit); if (!kissat_empty_vector (&watches)) { watch *w = BEGIN_WATCHES (watches); +#ifndef WIN32 __builtin_prefetch (w, 0, 1); +#endif } #ifndef FAST_ASSIGN value *values = solver->values; #endif - assert (!values[lit]); - assert (!values[not_lit]); + KISSAT_assert (!values[lit]); + KISSAT_assert (!values[not_lit]); values[lit] = 1; values[not_lit] = -1; - assert (solver->unassigned > 0); + KISSAT_assert (solver->unassigned > 0); solver->unassigned--; if (!level) { kissat_mark_fixed_literal (solver, lit); - assert (solver->unflushed < UINT_MAX); + KISSAT_assert (solver->unflushed < UINT_MAX); solver->unflushed++; if (reason != UNIT_REASON) { 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)) { if (other == lit) continue; - assert (values[other] < 0), (void) values; + KISSAT_assert (values[other] < 0), (void) values; const unsigned other_idx = IDX (other); struct assigned *a = assigned + other_idx; const unsigned level = a->level; if (res < level) res = level; } -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) solver; #endif return res; } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/inlineframes.h b/src/sat/kissat/inlineframes.h index 75c5186a6..09c772681 100644 --- a/src/sat/kissat/inlineframes.h +++ b/src/sat/kissat/inlineframes.h @@ -4,8 +4,11 @@ #include "allocate.h" #include "internal.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + 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); frame frame; frame.decision = decision; @@ -15,4 +18,6 @@ static inline void kissat_push_frame (kissat *solver, unsigned decision) { PUSH_STACK (solver->frames, frame); } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/inlineheap.h b/src/sat/kissat/inlineheap.h index 0bc8c122d..cf379b488 100644 --- a/src/sat/kissat/inlineheap.h +++ b/src/sat/kissat/inlineheap.h @@ -5,9 +5,12 @@ #include "internal.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, unsigned idx) { @@ -75,7 +78,7 @@ static inline void kissat_bubble_down (kissat *solver, heap *heap, #define HEAP_IMPORT(IDX) \ do { \ - assert ((IDX) < UINT_MAX - 1); \ + KISSAT_assert ((IDX) < UINT_MAX - 1); \ if (heap->vars <= (IDX)) \ kissat_enlarge_heap (solver, heap, (IDX) + 1); \ } 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, unsigned idx) { LOG ("push heap %u", idx); - assert (!kissat_heap_contains (heap, idx)); + KISSAT_assert (!kissat_heap_contains (heap, idx)); HEAP_IMPORT (idx); heap->pos[idx] = SIZE_STACK (heap->stack); 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, unsigned 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); heap->pos[last] = DISCONTAIN; 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) { - assert (!EMPTY_STACK (heap->stack)); + KISSAT_assert (!EMPTY_STACK (heap->stack)); unsigneds *stack = &heap->stack; unsigned *const begin = BEGIN_STACK (*stack); const unsigned idx = *begin; - assert (!heap->pos[idx]); + KISSAT_assert (!heap->pos[idx]); LOG ("pop max heap %u", idx); const unsigned last = POP_STACK (*stack); 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; while (idx >= new_size) new_size *= 2; - assert (new_size < DISCONTAIN); + KISSAT_assert (new_size < DISCONTAIN); kissat_resize_heap (solver, heap, new_size); } kissat_enlarge_heap (solver, heap, idx + 1); @@ -173,4 +176,6 @@ static inline void kissat_update_heap (kissat *solver, heap *heap, #endif } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/inlinequeue.h b/src/sat/kissat/inlinequeue.h index 017522679..3f83dd895 100644 --- a/src/sat/kissat/inlinequeue.h +++ b/src/sat/kissat/inlinequeue.h @@ -4,9 +4,12 @@ #include "internal.h" #include "logging.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + static inline void kissat_update_queue (kissat *solver, const links *links, unsigned idx) { - assert (!DISCONNECTED (idx)); + KISSAT_assert (!DISCONNECTED (idx)); const unsigned stamp = links[idx].stamp; LOG ("queue updated to %s stamped %u", LOGVAR (idx), stamp); 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, links *links, queue *queue) { struct links *p = links + i; - assert (DISCONNECTED (p->prev)); - assert (DISCONNECTED (p->next)); + KISSAT_assert (DISCONNECTED (p->prev)); + KISSAT_assert (DISCONNECTED (p->next)); const unsigned j = p->prev = queue->last; queue->last = i; if (DISCONNECTED (j)) queue->first = i; else { struct links *l = links + j; - assert (DISCONNECTED (l->next)); + KISSAT_assert (DISCONNECTED (l->next)); l->next = i; } if (queue->stamp == UINT_MAX) { kissat_reassign_queue_stamps (solver); - assert (p->stamp == queue->stamp); + KISSAT_assert (p->stamp == queue->stamp); } else 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; l->prev = l->next = DISCONNECT; if (DISCONNECTED (j)) { - assert (queue->first == i); + KISSAT_assert (queue->first == i); queue->first = k; } else { struct links *p = links + j; - assert (p->next == i); + KISSAT_assert (p->next == i); p->next = k; } if (DISCONNECTED (k)) { - assert (queue->last == i); + KISSAT_assert (queue->last == i); queue->last = j; } else { struct links *n = links + k; - assert (n->prev == i); + KISSAT_assert (n->prev == i); n->prev = j; } } 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; l->prev = l->next = DISCONNECT; 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) { - assert (idx < solver->vars); + KISSAT_assert (idx < solver->vars); LOG ("dequeued %s", LOGVAR (idx)); links *links = solver->links; 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; links *links = solver->links; if (idx == queue->last) { - assert (DISCONNECTED (links[idx].next)); + KISSAT_assert (DISCONNECTED (links[idx].next)); return; } - assert (idx < solver->vars); + KISSAT_assert (idx < solver->vars); const value tmp = VALUE (LIT (idx)); if (tmp && queue->search.idx == idx) { 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); else { unsigned next = links[idx].next; - assert (!DISCONNECTED (next)); + KISSAT_assert (!DISCONNECTED (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); } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/inlinevector.h b/src/sat/kissat/inlinevector.h index b7adbbf7e..d7242c8eb 100644 --- a/src/sat/kissat/inlinevector.h +++ b/src/sat/kissat/inlinevector.h @@ -3,9 +3,12 @@ #include "internal.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + static inline unsigned *kissat_begin_vector (kissat *solver, vector *vector) { -#ifdef COMPACT +#ifdef KISSAT_COMPACT return BEGIN_STACK (solver->vectors.stack) + vector->offset; #else (void) solver; @@ -14,7 +17,7 @@ static inline unsigned *kissat_begin_vector (kissat *solver, } static inline unsigned *kissat_end_vector (kissat *solver, vector *vector) { -#ifdef COMPACT +#ifdef KISSAT_COMPACT return kissat_begin_vector (solver, vector) + vector->size; #else (void) solver; @@ -24,7 +27,7 @@ static inline unsigned *kissat_end_vector (kissat *solver, vector *vector) { static inline const unsigned * kissat_begin_const_vector (kissat *solver, const vector *vector) { -#ifdef COMPACT +#ifdef KISSAT_COMPACT return BEGIN_STACK (solver->vectors.stack) + vector->offset; #else (void) solver; @@ -34,7 +37,7 @@ kissat_begin_const_vector (kissat *solver, const vector *vector) { static inline const unsigned * kissat_end_const_vector (kissat *solver, const vector *vector) { -#ifdef COMPACT +#ifdef KISSAT_COMPACT return kissat_begin_const_vector (solver, vector) + vector->size; #else (void) solver; @@ -45,7 +48,7 @@ kissat_end_const_vector (kissat *solver, const vector *vector) { #if defined(LOGGING) || defined(TEST_VECTOR) static inline size_t kissat_offset_vector (kissat *solver, vector *vector) { -#ifdef COMPACT +#ifdef KISSAT_COMPACT (void) solver; return vector->offset; #else @@ -58,7 +61,7 @@ static inline size_t kissat_offset_vector (kissat *solver, vector *vector) { #endif static inline size_t kissat_size_vector (const vector *vector) { -#ifdef COMPACT +#ifdef KISSAT_COMPACT return vector->size; #else 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) { -#ifdef COMPACT +#ifdef KISSAT_COMPACT return !vector->size; #else 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) { - assert (MAX_SECTOR > solver->vectors.usable); + KISSAT_assert (MAX_SECTOR > solver->vectors.usable); solver->vectors.usable++; } 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; } static inline unsigned *kissat_last_vector_pointer (kissat *solver, vector *vector) { - assert (!kissat_empty_vector (vector)); -#ifdef COMPACT - assert (vector->size); + KISSAT_assert (!kissat_empty_vector (vector)); +#ifdef KISSAT_COMPACT + KISSAT_assert (vector->size); unsigned *begin = kissat_begin_vector (solver, vector); return begin + vector->size - 1; #else @@ -99,8 +102,8 @@ static inline unsigned *kissat_last_vector_pointer (kissat *solver, #ifdef TEST_VECTOR static inline void kissat_pop_vector (kissat *solver, vector *vector) { - assert (!kissat_empty_vector (vector)); -#ifdef COMPACT + KISSAT_assert (!kissat_empty_vector (vector)); +#ifdef KISSAT_COMPACT unsigned *p = kissat_last_vector_pointer (solver, vector); vector->size--; *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) { - assert (solver->vectors.usable > 0); + KISSAT_assert (solver->vectors.usable > 0); solver->vectors.usable--; } static inline void kissat_push_vectors (kissat *solver, vector *vector, unsigned e) { unsigneds *stack = &solver->vectors.stack; - assert (e != INVALID_VECTOR_ELEMENT); + KISSAT_assert (e != INVALID_VECTOR_ELEMENT); if ( -#ifdef COMPACT +#ifdef KISSAT_COMPACT !vector->size && !vector->offset #else !vector->begin @@ -137,21 +140,21 @@ static inline void kissat_push_vectors (kissat *solver, vector *vector, PUSH_STACK (*stack, 0); if (FULL_STACK (*stack)) { unsigned *end = kissat_enlarge_vector (solver, vector); - assert (*end == INVALID_VECTOR_ELEMENT); + KISSAT_assert (*end == INVALID_VECTOR_ELEMENT); *end = e; kissat_dec_usable (solver); } else { -#ifdef COMPACT - assert ((uint64_t) SIZE_STACK (*stack) < MAX_VECTORS); +#ifdef KISSAT_COMPACT + KISSAT_assert ((uint64_t) SIZE_STACK (*stack) < MAX_VECTORS); vector->offset = SIZE_STACK (*stack); - assert (vector->offset); + KISSAT_assert (vector->offset); *stack->end++ = e; #else - assert (stack->end < stack->allocated); + KISSAT_assert (stack->end < stack->allocated); *(vector->begin = stack->end++) = e; #endif } -#if !defined(COMPACT) +#if !defined(KISSAT_COMPACT) vector->end = vector->begin; #endif } else { @@ -159,7 +162,7 @@ static inline void kissat_push_vectors (kissat *solver, vector *vector, if (end == END_STACK (*stack)) { if (FULL_STACK (*stack)) { end = kissat_enlarge_vector (solver, vector); - assert (*end == INVALID_VECTOR_ELEMENT); + KISSAT_assert (*end == INVALID_VECTOR_ELEMENT); *end = e; kissat_dec_usable (solver); } else @@ -167,12 +170,12 @@ static inline void kissat_push_vectors (kissat *solver, vector *vector, } else { if (*end != INVALID_VECTOR_ELEMENT) end = kissat_enlarge_vector (solver, vector); - assert (*end == INVALID_VECTOR_ELEMENT); + KISSAT_assert (*end == INVALID_VECTOR_ELEMENT); *end = e; kissat_dec_usable (solver); } } -#ifndef COMPACT +#ifndef KISSAT_COMPACT vector->end++; #else vector->size++; @@ -190,4 +193,6 @@ static inline void kissat_push_vectors (kissat *solver, vector *vector, #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/internal.c b/src/sat/kissat/internal.c index 1c0002019..bf7046159 100644 --- a/src/sat/kissat/internal.c +++ b/src/sat/kissat/internal.c @@ -17,24 +17,26 @@ #include #include +ABC_NAMESPACE_IMPL_START + void kissat_reset_last_learned (kissat *solver) { for (really_all_last_learned (p)) *p = INVALID_REF; } kissat *kissat_init (void) { - kissat *solver = kissat_calloc (0, 1, sizeof *solver); -#ifndef NOPTIONS + kissat *solver = (kissat*)kissat_calloc (0, 1, sizeof *solver); +#ifndef KISSAT_NOPTIONS kissat_init_options (&solver->options); #else kissat_init_options (); #endif -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_init_profiles (&solver->profiles); #endif START (total); kissat_init_queue (solver); - assert (INTERNAL_MAX_LIT < UINT_MAX); + KISSAT_assert (INTERNAL_MAX_LIT < UINT_MAX); kissat_push_frame (solver, UINT_MAX); solver->watching = true; solver->conflict.size = 2; @@ -42,7 +44,7 @@ kissat *kissat_init (void) { solver->first_reducible = INVALID_REF; solver->last_irredundant = INVALID_REF; kissat_reset_last_learned (solver); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG kissat_init_checker (solver); #endif solver->prefix = kissat_strdup (solver, "c "); @@ -83,7 +85,7 @@ void kissat_release (kissat *solver) { kissat_release_vectors (solver); kissat_release_phases (solver); - RELEASE_STACK (solver->export); + RELEASE_STACK (solver->export_); RELEASE_STACK (solver->import); DEALLOC_VARIABLE_INDEXED (assigned); @@ -104,7 +106,7 @@ void kissat_release (kissat *solver) { RELEASE_STACK (solver->clause); RELEASE_STACK (solver->shadow); -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) RELEASE_STACK (solver->resolvent); #endif @@ -136,26 +138,26 @@ void kissat_release (kissat *solver) { RELEASE_STACK (solver->gates[1]); RELEASE_STACK (solver->resolvents); -#if !defined(NDEBUG) || !defined(NPROOFS) +#if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) RELEASE_STACK (solver->added); RELEASE_STACK (solver->removed); #endif -#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) || defined(LOGGING) RELEASE_STACK (solver->original); #endif -#ifndef QUIET +#ifndef KISSAT_QUIET RELEASE_STACK (solver->profiles.stack); #endif kissat_freestr (solver, solver->prefix); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG kissat_release_checker (solver); #endif -#if !defined(NDEBUG) && defined(METRICS) - uint64_t leaked = solver->statistics.allocated_current; +#if !defined(KISSAT_NDEBUG) && defined(METRICS) + uint64_t leaked = solver->statistics_.allocated_current; if (leaked) if (!getenv ("LEAK")) 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) { kissat_require_initialized (solver); kissat_require (name, "name zero pointer"); -#ifndef NOPTIONS +#ifndef KISSAT_NOPTIONS return kissat_options_get (&solver->options, name); #else (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) { -#ifndef NOPTIONS +#ifndef KISSAT_NOPTIONS kissat_require_initialized (solver); kissat_require (name, "name zero pointer"); -#ifndef NOPTIONS +#ifndef KISSAT_NOPTIONS return kissat_options_set (&solver->options, name, new_value); #else return kissat_options_set (name, new_value); @@ -209,9 +211,9 @@ void kissat_set_decision_limit (kissat *solver, unsigned limit) { kissat_require_initialized (solver); limits *limits = &solver->limits; limited *limited = &solver->limited; - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; limited->decisions = true; - assert (UINT64_MAX - limit >= statistics->decisions); + KISSAT_assert (UINT64_MAX - limit >= statistics->decisions); limits->decisions = statistics->decisions + limit; LOG ("set decision limit to %" PRIu64 " after %u decisions", limits->decisions, limit); @@ -221,16 +223,16 @@ void kissat_set_conflict_limit (kissat *solver, unsigned limit) { kissat_require_initialized (solver); limits *limits = &solver->limits; limited *limited = &solver->limited; - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; limited->conflicts = true; - assert (UINT64_MAX - limit >= statistics->conflicts); + KISSAT_assert (UINT64_MAX - limit >= statistics->conflicts); limits->conflicts = statistics->conflicts + limit; LOG ("set conflict limit to %" PRIu64 " after %u conflicts", limits->conflicts, limit); } void kissat_print_statistics (kissat *solver) { -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_require_initialized (solver); const int verbosity = kissat_verbosity (solver); if (verbosity < 0) @@ -243,13 +245,13 @@ void kissat_print_statistics (kissat *solver) { kissat_section (solver, "statistics"); const bool verbose = (complete || verbosity > 0); kissat_statistics_print (solver, verbose); -#ifndef NPROOFS +#ifndef KISSAT_NPROOFS if (solver->proof) { kissat_section (solver, "proof"); kissat_print_proof_statistics (solver, verbose); } #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG if (GET_OPTION (check) > 1) { kissat_section (solver, "checker"); kissat_print_checker_statistics (solver, verbose); @@ -266,14 +268,14 @@ void kissat_print_statistics (kissat *solver) { void kissat_add (kissat *solver, int elit) { kissat_require_initialized (solver); 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 bool logging = kissat_logging (solver); const bool proving = kissat_proving (solver); #endif if (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) PUSH_STACK (solver->original, elit); #endif @@ -297,18 +299,18 @@ void kissat_add (kissat *solver, int elit) { } else { MARK (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); } } else if (mark < 0) { - assert (mark < 0); + KISSAT_assert (mark < 0); if (!solver->clause_trivial) { LOG ("adding dual literal %u(%d) and %u(%d)", NOT (ilit), -elit, ilit, elit); solver->clause_trivial = true; } } else { - assert (mark > 0); + KISSAT_assert (mark > 0); LOG ("adding duplicated literal %u(%d)", ilit, elit); if (!solver->clause_shrink) { solver->clause_shrink = true; @@ -316,16 +318,16 @@ void kissat_add (kissat *solver, int elit) { } } } 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; size_t esize = SIZE_STACK (solver->original) - offset; int *elits = BEGIN_STACK (solver->original) + offset; - assert (esize <= UINT_MAX); + KISSAT_assert (esize <= UINT_MAX); #endif ADD_UNCHECKED_EXTERNAL (esize, elits); const size_t isize = SIZE_STACK (solver->clause); unsigned *ilits = BEGIN_STACK (solver->clause); - assert (isize < (unsigned) INT_MAX); + KISSAT_assert (isize < (unsigned) INT_MAX); if (solver->inconsistent) LOG ("inconsistent thus skipping original clause"); @@ -380,38 +382,38 @@ void kissat_add (kissat *solver, int elit) { assign = true; } else if (u < 0 && k == l) { LOG ("both watches falsified at level @%u", k); - assert (v < 0); - assert (k > 0); + KISSAT_assert (v < 0); + KISSAT_assert (k > 0); kissat_backtrack_without_updating_phases (solver, k - 1); } else if (u < 0) { LOG ("watches falsified at levels @%u and @%u", k, l); - assert (v < 0); - assert (k > l); - assert (l > 0); + KISSAT_assert (v < 0); + KISSAT_assert (k > l); + KISSAT_assert (l > 0); assign = true; } else if (u > 0 && v < 0) { LOG ("first watch satisfied at level @%u " "second falsified at level @%u", k, l); - assert (k <= l); + KISSAT_assert (k <= l); } else if (!u && v > 0) { LOG ("first watch unassigned " "second falsified at level @%u", l); assign = true; } else { - assert (!u); - assert (!v); + KISSAT_assert (!u); + KISSAT_assert (!v); } if (assign) { - assert (solver->level > 0); + KISSAT_assert (solver->level > 0); if (isize == 2) { - assert (res == INVALID_REF); + KISSAT_assert (res == INVALID_REF); kissat_assign_binary (solver, a, b); } else { - assert (res != INVALID_REF); + KISSAT_assert (res != INVALID_REF); clause *c = kissat_dereference_clause (solver, res); 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) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG if (checking > 1) kissat_remove_checker_external (solver, esize, elits); #endif -#ifndef NPROOFS +#ifndef KISSAT_NPROOFS if (proving) { if (esize == 1) LOG ("skipping deleting unit from proof"); @@ -434,13 +436,13 @@ void kissat_add (kissat *solver, int elit) { } #endif } else if (!solver->inconsistent && solver->clause_shrink) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG if (checking > 1) { kissat_check_and_add_internal (solver, isize, ilits); kissat_remove_checker_external (solver, esize, elits); } #endif -#ifndef NPROOFS +#ifndef KISSAT_NPROOFS if (proving) { kissat_add_lits_to_proof (solver, isize, ilits); kissat_delete_external_from_proof (solver, esize, elits); @@ -449,7 +451,7 @@ void kissat_add (kissat *solver, int elit) { } #endif -#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) || defined(LOGGING) if (checking) { LOGINTS (esize, elits, "saved original"); PUSH_STACK (solver->original, 0); @@ -483,7 +485,7 @@ int kissat_solve (kissat *solver) { void kissat_terminate (kissat *solver) { kissat_require_initialized (solver); solver->termination.flagged = ~(unsigned) 0; - assert (solver->termination.flagged); + KISSAT_assert (solver->termination.flagged); } void kissat_set_terminate (kissat *solver, void *state, @@ -518,3 +520,9 @@ int kissat_value (kissat *solver, int elit) { tmp = -tmp; return tmp < 0 ? -elit : elit; } + +int kissat_is_inconsistent(kissat *solver) { + return solver->inconsistent; +} + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/internal.h b/src/sat/kissat/internal.h index 8a4b46c80..a3777a961 100644 --- a/src/sat/kissat/internal.h +++ b/src/sat/kissat/internal.h @@ -33,6 +33,9 @@ #include "vector.h" #include "watch.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct datarank datarank; struct datarank { @@ -74,7 +77,7 @@ typedef STACK (watch *) patches; struct kitten; struct kissat { -#if !defined(NDEBUG) || defined(METRICS) +#if !defined(KISSAT_NDEBUG) || defined(METRICS) bool backbone_computing; #endif #ifdef LOGGING @@ -85,11 +88,11 @@ struct kissat { bool iterating; bool preprocessing; bool probing; -#ifndef QUIET +#ifndef KISSAT_QUIET bool sectioned; #endif bool stable; -#if !defined(NDEBUG) || defined(METRICS) +#if !defined(KISSAT_NDEBUG) || defined(METRICS) bool transitive_reducing; bool vivifying; #endif @@ -105,7 +108,7 @@ struct kissat { unsigned active; unsigned randec; - ints export; + ints export_; ints units; imports import; extensions extend; @@ -144,7 +147,7 @@ struct kissat { unsigneds delayed; -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) unsigneds resolvent; #endif unsigned resolvent_size; @@ -197,7 +200,7 @@ struct kissat { uint64_t ticks; - format format; + kormat format; char *prefix; statches antecedents[2]; @@ -215,33 +218,33 @@ struct kissat { bool sweep_incomplete; unsigneds sweep_schedule; -#if !defined(NDEBUG) || !defined(NPROOFS) +#if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) unsigneds added; unsigneds removed; #endif -#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) || defined(LOGGING) ints original; size_t offset_of_last_original_clause; #endif -#ifndef QUIET +#ifndef KISSAT_QUIET profiles profiles; #endif -#ifndef NOPTIONS +#ifndef KISSAT_NOPTIONS options options; #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG checker *checker; #endif -#ifndef NPROOFS +#ifndef KISSAT_NPROOFS proof *proof; #endif - statistics statistics; + statistics statistics_; }; #define VARS (solver->vars) @@ -259,7 +262,7 @@ struct kissat { #define SCORES (&solver->scores) static inline unsigned kissat_assigned (kissat *solver) { - assert (VARS >= solver->unassigned); + KISSAT_assert (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); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/keatures.h b/src/sat/kissat/keatures.h index d0652be99..e3d4cb912 100644 --- a/src/sat/kissat/keatures.h +++ b/src/sat/kissat/keatures.h @@ -1,6 +1,9 @@ #ifndef _keatures_h_INCLUDED #define _keatures_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define KISSAT_IS_BIG_ENDIAN #endif @@ -15,4 +18,6 @@ #define KISSAT_HAS_UNLOCKEDIO #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/kimits.c b/src/sat/kissat/kimits.c index 9fe4dcf05..f5507e098 100644 --- a/src/sat/kissat/kimits.c +++ b/src/sat/kissat/kimits.c @@ -10,29 +10,31 @@ #include #include +ABC_NAMESPACE_IMPL_START + double kissat_logn (uint64_t count) { - assert (count > 0); + KISSAT_assert (count > 0); const double res = log10 (count + 9); - assert (res >= 1); + KISSAT_assert (res >= 1); return res; } double kissat_sqrt (uint64_t count) { - assert (count > 0); + KISSAT_assert (count > 0); const double res = sqrt (count); - assert (res >= 1); + KISSAT_assert (res >= 1); return res; } double kissat_nlogpown (uint64_t count, unsigned exponent) { - assert (count > 0); + KISSAT_assert (count > 0); const double tmp = log10 (count + 9); double factor = 1; while (exponent--) factor *= tmp; - assert (factor >= 1); + KISSAT_assert (factor >= 1); const double res = count * factor; - assert (res >= 1); + KISSAT_assert (res >= 1); return res; } @@ -41,10 +43,10 @@ uint64_t kissat_scale_delta (kissat *solver, const char *pretty, const uint64_t C = BINIRR_CLAUSES; double f = kissat_logn (C + 1) - 5; const double ff = f * f; - assert (ff >= 0); + KISSAT_assert (ff >= 0); const double fff = 4.5 * ff + 25; uint64_t scaled = fff * delta; - assert (delta <= scaled); + KISSAT_assert (delta <= scaled); // clang-format off kissat_very_verbose (solver, "scaled %s delta %" PRIu64 @@ -97,7 +99,7 @@ static void init_enabled (kissat *solver) { } while (0) void kissat_init_limits (kissat *solver) { - assert (solver->statistics.searches == 1); + KISSAT_assert (solver->statistics.searches == 1); init_enabled (solver); @@ -131,7 +133,7 @@ void kissat_init_limits (kissat *solver) { INIT_CONFLICT_LIMIT (probe, true); } -#ifndef QUIET +#ifndef KISSAT_QUIET static const char *delay_description (kissat *solver, delay *delay) { delays *delays = &solver->delays; @@ -142,7 +144,7 @@ static const char *delay_description (kissat *solver, delay *delay) { else if (delay == &delays->sweep) return "sweeping"; else { - assert (delay == &delays->vivifyirr); + KISSAT_assert (delay == &delays->vivifyirr); return "vivifying irredundant clauses"; } } @@ -160,7 +162,7 @@ void kissat_reduce_delay (kissat *solver, delay *delay) { solver, "%s delay interval decreased to %u", delay_description (solver, delay), delay->current); delay->count = delay->current; -#ifdef QUIET +#ifdef KISSAT_QUIET (void) solver; #endif } @@ -171,7 +173,7 @@ void kissat_bump_delay (kissat *solver, delay *delay) { solver, "%s delay interval increased to %u", delay_description (solver, delay), delay->current); delay->count = delay->current; -#ifdef QUIET +#ifdef KISSAT_QUIET (void) solver; #endif } @@ -188,7 +190,9 @@ bool kissat_delaying (kissat *solver, delay *delay) { delay_description (solver, delay)); return false; } -#ifdef QUIET +#ifdef KISSAT_QUIET (void) solver; #endif } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/kimits.h b/src/sat/kissat/kimits.h index 93339b3b5..1696f05ed 100644 --- a/src/sat/kissat/kimits.h +++ b/src/sat/kissat/kimits.h @@ -4,6 +4,9 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct bounds bounds; typedef struct changes changes; typedef struct delays delays; @@ -114,12 +117,12 @@ double kissat_logn (uint64_t); do { \ if (solver->inconsistent) \ break; \ - const struct statistics *statistics = &solver->statistics; \ - assert (statistics->COUNT > 0); \ + const struct statistics *statistics = &solver->statistics_; \ + KISSAT_assert (statistics->COUNT > 0); \ struct limits *limits = &solver->limits; \ uint64_t DELTA = GET_OPTION (NAME##int); \ const double SCALING = SCALE_COUNT_FUNCTION (statistics->COUNT); \ - assert (SCALING >= 1); \ + KISSAT_assert (SCALING >= 1); \ DELTA *= SCALING; \ const uint64_t SCALED = \ !(SCALE_DELTA) ? DELTA \ @@ -135,8 +138,8 @@ double kissat_logn (uint64_t); #define SET_EFFORT_LIMIT(LIMIT, NAME, START) \ uint64_t LIMIT; \ do { \ - const uint64_t OLD_LIMIT = solver->statistics.START; \ - const uint64_t TICKS = solver->statistics.search_ticks; \ + const uint64_t OLD_LIMIT = solver->statistics_.START; \ + const uint64_t TICKS = solver->statistics_.search_ticks; \ const uint64_t LAST = solver->probing ? solver->last.ticks.probe \ : solver->last.ticks.eliminate; \ uint64_t REFERENCE = TICKS - LAST; \ @@ -182,4 +185,6 @@ void kissat_reduce_delay (struct kissat *, delay *); #define REDUCE_DELAY(NAME) \ kissat_reduce_delay (solver, &solver->delays.NAME) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/kissat.h b/src/sat/kissat/kissat.h index eec380566..10fade7ea 100644 --- a/src/sat/kissat/kissat.h +++ b/src/sat/kissat/kissat.h @@ -1,6 +1,9 @@ #ifndef _kissat_h_INCLUDED #define _kissat_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct kissat kissat; // Default (partial) IPASIR interface. @@ -41,4 +44,9 @@ void kissat_set_decision_limit (kissat *solver, unsigned); void kissat_print_statistics (kissat *solver); +// Extra API functions. +int kissat_is_inconsistent(kissat *solver); + +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/kissatSolver.c b/src/sat/kissat/kissatSolver.c new file mode 100644 index 000000000..8d8cb81cc --- /dev/null +++ b/src/sat/kissat/kissatSolver.c @@ -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 diff --git a/src/sat/kissat/kissatSolver.h b/src/sat/kissat/kissatSolver.h new file mode 100644 index 000000000..aa154dd46 --- /dev/null +++ b/src/sat/kissat/kissatSolver.h @@ -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 /// +//////////////////////////////////////////////////////////////////////// diff --git a/src/sat/kissat/kissatTest.c b/src/sat/kissat/kissatTest.c new file mode 100644 index 000000000..879db8799 --- /dev/null +++ b/src/sat/kissat/kissatTest.c @@ -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 diff --git a/src/sat/kissat/kitten.c b/src/sat/kissat/kitten.c index 903230f81..ea2e7f360 100644 --- a/src/sat/kissat/kitten.c +++ b/src/sat/kissat/kitten.c @@ -67,9 +67,9 @@ static inline void *kitten_calloc (size_t n, size_t size) { return res; } -#define CALLOC(P, N) \ +#define CALLOC(T, P, N) \ do { \ - (P) = kitten_calloc (N, sizeof *(P)); \ + (P) = (T*) kitten_calloc (N, sizeof *(P)); \ } while (0) #define DEALLOC(P, N) free (P) @@ -77,7 +77,7 @@ static inline void *kitten_calloc (size_t n, size_t size) { #define ENLARGE_STACK(S) \ do { \ - assert (FULL_STACK (S)); \ + KISSAT_assert (FULL_STACK (S)); \ const size_t SIZE = SIZE_STACK (S); \ const size_t OLD_CAPACITY = CAPACITY_STACK (S); \ const size_t NEW_CAPACITY = OLD_CAPACITY ? 2 * OLD_CAPACITY : 1; \ @@ -94,14 +94,14 @@ static inline void *kitten_calloc (size_t n, size_t size) { #define INC(NAME) \ do { \ statistics *statistics = &kitten->statistics; \ - assert (statistics->NAME < UINT64_MAX); \ + KISSAT_assert (statistics->NAME < UINT64_MAX); \ statistics->NAME++; \ } while (0) #define ADD(NAME, DELTA) \ do { \ statistics *statistics = &kitten->statistics; \ - assert (statistics->NAME <= UINT64_MAX - (DELTA)); \ + KISSAT_assert (statistics->NAME <= UINT64_MAX - (DELTA)); \ statistics->NAME += (DELTA); \ } while (0) @@ -116,12 +116,14 @@ static inline void *kitten_calloc (size_t n, size_t size) { #include "internal.h" // Also use 'kissat' statistics if embedded. #include "terminate.h" // For macros defining termination macro. -#define KITTEN_TICKS (solver->statistics.kitten_ticks) +#define KITTEN_TICKS (solver->statistics_.kitten_ticks) /*------------------------------------------------------------------------*/ #endif // STAND_ALONE_KITTEN /*------------------------------------------------------------------------*/ +ABC_NAMESPACE_IMPL_START + #define INVALID UINT_MAX #define MAX_VARS ((1u << 31) - 1) @@ -257,7 +259,7 @@ struct kitten { unsigneds assumptions; unsigneds core; unsigneds eclause; - unsigneds export; + unsigneds export_; unsigneds klause; unsigneds klauses; unsigneds resolved; @@ -288,7 +290,7 @@ static inline void unset_core_klause (klause *c) { c->flags &= ~CORE_FLAG; } static inline klause *dereference_klause (kitten *kitten, unsigned ref) { unsigned *res = BEGIN_STACK (kitten->klauses) + ref; - assert (res < END_STACK (kitten->klauses)); + KISSAT_assert (res < END_STACK (kitten->klauses)); return (klause *) res; } @@ -297,8 +299,8 @@ static inline klause *dereference_klause (kitten *kitten, unsigned ref) { static inline unsigned reference_klause (kitten *kitten, const klause *c) { const unsigned *const begin = BEGIN_STACK (kitten->klauses); const unsigned *p = (const unsigned *) c; - assert (begin <= p); - assert (p < END_STACK (kitten->klauses)); + KISSAT_assert (begin <= p); + KISSAT_assert (p < END_STACK (kitten->klauses)); const unsigned res = p - begin; return res; } @@ -307,7 +309,7 @@ static inline unsigned reference_klause (kitten *kitten, const klause *c) { /*------------------------------------------------------------------------*/ -#define KATCHES(KIT) (kitten->watches[assert ((KIT) < kitten->lits), (KIT)]) +#define KATCHES(KIT) (kitten->watches[KISSAT_assert ((KIT) < kitten->lits), (KIT)]) #define all_klauses(C) \ klause *C = begin_klauses (kitten), *end_##C = end_klauses (kitten); \ @@ -342,7 +344,7 @@ static inline unsigned reference_klause (kitten *kitten, const klause *c) { ++KIT##_PTR #define all_antecedents(REF, C) \ - unsigned REF, *REF##_PTR = antecedents (C), \ + unsigned REF, *REF##_PTR = antecedents_func (C), \ *REF##_END = REF##_PTR + (C)->aux; \ REF##_PTR != REF##_END && ((REF = *REF##_PTR), true); \ ++REF##_PTR @@ -359,7 +361,7 @@ static void log_basic (kitten *, const char *, ...) __attribute__ ((format (printf, 2, 3))); static void log_basic (kitten *kitten, const char *fmt, ...) { - assert (logging); + KISSAT_assert (logging); printf ("c KITTEN %u ", kitten->level); va_list ap; va_start (ap, fmt); @@ -375,7 +377,7 @@ static void log_reference (kitten *, unsigned, const char *, ...) static void log_reference (kitten *kitten, unsigned ref, const char *fmt, ...) { klause *c = dereference_klause (kitten, ref); - assert (logging); + KISSAT_assert (logging); printf ("c KITTEN %u ", kitten->level); va_list ap; va_start (ap, fmt); @@ -435,26 +437,26 @@ static void check_queue (kitten *kitten) { for (unsigned idx = kitten->queue.first, next; idx != INVALID; idx = next) { kink *link = links + idx; - assert (link->prev == prev); - assert (!found || stamp < link->stamp); - assert (link->stamp < kitten->queue.stamp); + KISSAT_assert (link->prev == prev); + KISSAT_assert (!found || stamp < link->stamp); + KISSAT_assert (link->stamp < kitten->queue.stamp); stamp = link->stamp; next = link->next; prev = idx; found++; } - assert (found == vars); + KISSAT_assert (found == vars); unsigned next = INVALID; found = 0; for (unsigned idx = kitten->queue.last, prev; idx != INVALID; idx = prev) { kink *link = links + idx; - assert (link->next == next); + KISSAT_assert (link->next == next); prev = link->prev; next = idx; found++; } - assert (found == vars); + KISSAT_assert (found == vars); value *values = kitten->values; bool first = true; for (unsigned idx = kitten->queue.search, next; idx != INVALID; @@ -462,7 +464,7 @@ static void check_queue (kitten *kitten) { kink *link = links + idx; next = link->next; const unsigned lit = 2 * idx; - assert (first || values[lit]); + KISSAT_assert (first || values[lit]); first = false; } #else @@ -512,8 +514,8 @@ static void dequeue (kitten *kitten, unsigned idx) { static void init_queue (kitten *kitten, size_t old_vars, size_t new_vars) { for (size_t idx = old_vars; idx < new_vars; idx++) { - assert (!kitten->values[2 * idx]); - assert (kitten->unassigned < UINT_MAX); + KISSAT_assert (!kitten->values[2 * idx]); + KISSAT_assert (kitten->unassigned < UINT_MAX); kitten->unassigned++; enqueue (kitten, idx); } @@ -541,35 +543,35 @@ static void clear_kitten (kitten *kitten) { initialize_kitten (kitten); } -#define RESIZE1(P) \ +#define RESIZE1(T, P) \ do { \ void *OLD_PTR = (P); \ - CALLOC ((P), new_size / 2); \ + CALLOC (T, (P), new_size / 2); \ const size_t BYTES = old_vars * sizeof *(P); \ if (BYTES) \ memcpy ((P), OLD_PTR, BYTES); \ void *NEW_PTR = (P); \ - (P) = OLD_PTR; \ + (P) = (T*) OLD_PTR; \ DEALLOC ((P), old_size / 2); \ - (P) = NEW_PTR; \ + (P) = (T*) NEW_PTR; \ } while (0) -#define RESIZE2(P) \ +#define RESIZE2(T, P) \ do { \ void *OLD_PTR = (P); \ - CALLOC ((P), new_size); \ + CALLOC (T, (P), new_size); \ const size_t BYTES = old_lits * sizeof *(P); \ if (BYTES) \ memcpy ((P), OLD_PTR, BYTES); \ void *NEW_PTR = (P); \ - (P) = OLD_PTR; \ + (P) = (T*) OLD_PTR; \ DEALLOC ((P), old_size); \ - (P) = NEW_PTR; \ + (P) = (T*) NEW_PTR; \ } while (0) static void enlarge_internal (kitten *kitten, size_t new_lits) { const size_t old_lits = kitten->lits; - assert (old_lits < new_lits); + KISSAT_assert (old_lits < new_lits); const size_t old_size = kitten->size; const unsigned new_vars = new_lits / 2; const unsigned old_vars = old_lits / 2; @@ -580,13 +582,13 @@ static void enlarge_internal (kitten *kitten, size_t new_lits) { LOG ("internal literals resized to %zu from %zu (requested %zu)", new_size, old_size, new_lits); - RESIZE1 (kitten->marks); - RESIZE1 (kitten->phases); - RESIZE2 (kitten->values); - RESIZE2 (kitten->failed); - RESIZE1 (kitten->vars); - RESIZE1 (kitten->links); - RESIZE2 (kitten->watches); + RESIZE1 (value, kitten->marks); + RESIZE1 (unsigned char, kitten->phases); + RESIZE2 (value, kitten->values); + RESIZE2 (bool, kitten->failed); + RESIZE1 (kar, kitten->vars); + RESIZE1 (kink, kitten->links); + RESIZE2 (katches, kitten->watches); kitten->size = new_size; } @@ -605,7 +607,7 @@ static const char *status_to_string (int status) { case 21: return "formula inconsistent and core computed"; default: - assert (!status); + KISSAT_assert (!status); return "formula unsolved"; } } @@ -652,7 +654,7 @@ static void invalid_api_usage (const char *fun, const char *fmt, ...) { kitten *kitten_init (void) { kitten *kitten; - CALLOC (kitten, 1); + CALLOC (struct kitten, kitten, 1); initialize_kitten (kitten); return kitten; } @@ -667,7 +669,7 @@ kitten *kitten_embedded (struct kissat *kissat) { struct kitten dummy; dummy.kissat = kissat; kitten = &dummy; - CALLOC (kitten, 1); + CALLOC (struct kitten, kitten, 1); kitten->kissat = kissat; initialize_kitten (kitten); return kitten; @@ -827,8 +829,8 @@ void kitten_shuffle_clauses (kitten *kitten) { shuffle_units (kitten); } -static inline unsigned *antecedents (klause *c) { - assert (is_learned_klause (c)); +static inline unsigned *antecedents_func (klause *c) { + KISSAT_assert (is_learned_klause (c)); return c->lits + c->size; } @@ -840,11 +842,11 @@ static inline void watch_klause (kitten *kitten, unsigned lit, klause *c, katch.ref = ref; #ifdef KITTEN_BLIT const unsigned size = c->size; - assert (lit == c->lits[0] || lit == c->lits[1]); + KISSAT_assert (lit == c->lits[0] || lit == c->lits[1]); const unsigned blit = c->lits[0] ^ c->lits[1] ^ lit; const bool binary = size == 2; - assert (size > 1); - assert (ref < (1u << 31)); + KISSAT_assert (size > 1); + KISSAT_assert (ref < (1u << 31)); katch.blit = blit; katch.binary = binary; #else @@ -883,7 +885,7 @@ static unsigned new_reference (kitten *kitten) { #endif } const unsigned res = (unsigned) ref; - assert (res != INVALID); + KISSAT_assert (res != INVALID); INC (kitten_ticks); return res; } @@ -907,7 +909,7 @@ static void new_original_klause (kitten *kitten, unsigned id) { static void enlarge_external (kitten *kitten, size_t eidx) { const size_t old_size = kitten->esize; const unsigned old_evars = kitten->evars; - assert (old_evars <= eidx); + KISSAT_assert (old_evars <= eidx); const unsigned new_evars = eidx + 1; if (old_size <= eidx) { size_t new_size = old_size ? 2 * old_size : 1; @@ -916,7 +918,7 @@ static void enlarge_external (kitten *kitten, size_t eidx) { LOG ("external resizing to %zu variables from %zu (requested %u)", new_size, old_size, new_evars); unsigned *old_import = kitten->import; - CALLOC (kitten->import, new_size); + CALLOC (unsigned, kitten->import, new_size); const size_t bytes = old_evars * sizeof *kitten->import; if (bytes) memcpy (kitten->import, old_import, bytes); @@ -934,16 +936,16 @@ static unsigned import_literal (kitten *kitten, unsigned elit) { unsigned iidx = kitten->import[eidx]; if (!iidx) { - iidx = SIZE_STACK (kitten->export); - PUSH_STACK (kitten->export, eidx); + iidx = SIZE_STACK (kitten->export_); + PUSH_STACK (kitten->export_, eidx); kitten->import[eidx] = iidx + 1; } else iidx--; unsigned ilit = 2 * iidx + (elit & 1); LOG ("imported external literal %u as internal literal %u", elit, ilit); const size_t new_lits = (ilit | 1) + (size_t) 1; - assert (ilit < new_lits); - assert (ilit / 2 < new_lits / 2); + KISSAT_assert (ilit < new_lits); + KISSAT_assert (ilit / 2 < new_lits / 2); if (new_lits > kitten->lits) enlarge_internal (kitten, new_lits); return ilit; @@ -951,8 +953,8 @@ static unsigned import_literal (kitten *kitten, unsigned elit) { static unsigned export_literal (kitten *kitten, unsigned ilit) { const unsigned iidx = ilit / 2; - assert (iidx < SIZE_STACK (kitten->export)); - const unsigned eidx = PEEK_STACK (kitten->export, iidx); + KISSAT_assert (iidx < SIZE_STACK (kitten->export_)); + const unsigned eidx = PEEK_STACK (kitten->export_, iidx); const unsigned elit = 2 * eidx + (ilit & 1); return elit; } @@ -961,10 +963,10 @@ unsigned new_learned_klause (kitten *kitten) { unsigned res = new_reference (kitten); unsigneds *klauses = &kitten->klauses; const size_t size = SIZE_STACK (kitten->klause); - assert (size <= UINT_MAX); + KISSAT_assert (size <= UINT_MAX); const size_t aux = kitten->antecedents ? SIZE_STACK (kitten->resolved) : 0; - assert (aux <= UINT_MAX); + KISSAT_assert (aux <= UINT_MAX); PUSH_STACK (*klauses, (unsigned) aux); PUSH_STACK (*klauses, (unsigned) size); PUSH_STACK (*klauses, LEARNED_FLAG); @@ -984,10 +986,10 @@ unsigned new_learned_klause (kitten *kitten) { void kitten_clear (kitten *kitten) { LOG ("clear kitten of size %zu", kitten->size); - assert (EMPTY_STACK (kitten->analyzed)); - assert (EMPTY_STACK (kitten->klause)); - assert (EMPTY_STACK (kitten->eclause)); - assert (EMPTY_STACK (kitten->resolved)); + KISSAT_assert (EMPTY_STACK (kitten->analyzed)); + KISSAT_assert (EMPTY_STACK (kitten->klause)); + KISSAT_assert (EMPTY_STACK (kitten->eclause)); + KISSAT_assert (EMPTY_STACK (kitten->resolved)); CLEAR_STACK (kitten->assumptions); CLEAR_STACK (kitten->core); @@ -999,15 +1001,15 @@ void kitten_clear (kitten *kitten) { for (all_kits (kit)) CLEAR_STACK (KATCHES (kit)); - while (!EMPTY_STACK (kitten->export)) - kitten->import[POP_STACK (kitten->export)] = 0; + while (!EMPTY_STACK (kitten->export_)) + kitten->import[POP_STACK (kitten->export_)] = 0; const size_t lits = kitten->size; const unsigned vars = lits / 2; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG for (unsigned i = 0; i < vars; i++) - assert (!kitten->marks[i]); + KISSAT_assert (!kitten->marks[i]); #endif if (vars) { @@ -1028,7 +1030,7 @@ void kitten_release (kitten *kitten) { RELEASE_STACK (kitten->assumptions); RELEASE_STACK (kitten->core); RELEASE_STACK (kitten->eclause); - RELEASE_STACK (kitten->export); + RELEASE_STACK (kitten->export_); RELEASE_STACK (kitten->klause); RELEASE_STACK (kitten->klauses); RELEASE_STACK (kitten->resolved); @@ -1063,7 +1065,7 @@ static inline void move_to_front (kitten *kitten, unsigned idx) { LOG ("move to front variable %u", idx); dequeue (kitten, idx); enqueue (kitten, idx); - assert (kitten->values[2 * idx]); + KISSAT_assert (kitten->values[2 * idx]); } static inline void assign (kitten *kitten, unsigned lit, unsigned reason) { @@ -1075,8 +1077,8 @@ static inline void assign (kitten *kitten, unsigned lit, unsigned reason) { #endif value *values = kitten->values; const unsigned not_lit = lit ^ 1; - assert (!values[lit]); - assert (!values[not_lit]); + KISSAT_assert (!values[lit]); + KISSAT_assert (!values[not_lit]); values[lit] = 1; values[not_lit] = -1; const unsigned idx = lit / 2; @@ -1086,7 +1088,7 @@ static inline void assign (kitten *kitten, unsigned lit, unsigned reason) { kar *v = kitten->vars + idx; v->level = kitten->level; if (!v->level) { - assert (reason != INVALID); + KISSAT_assert (reason != INVALID); klause *c = dereference_klause (kitten, reason); if (c->size > 1) { if (kitten->antecedents) { @@ -1095,7 +1097,7 @@ static inline void assign (kitten *kitten, unsigned lit, unsigned reason) { if (other != lit) { const unsigned other_idx = other / 2; const unsigned other_ref = kitten->vars[other_idx].reason; - assert (other_ref != INVALID); + KISSAT_assert (other_ref != INVALID); PUSH_STACK (kitten->resolved, other_ref); } } @@ -1106,14 +1108,14 @@ static inline void assign (kitten *kitten, unsigned lit, unsigned reason) { } } v->reason = reason; - assert (kitten->unassigned); + KISSAT_assert (kitten->unassigned); kitten->unassigned--; } static inline unsigned propagate_literal (kitten *kitten, unsigned lit) { LOG ("propagating %u", lit); value *values = kitten->values; - assert (values[lit] > 0); + KISSAT_assert (values[lit] > 0); const unsigned not_lit = lit ^ 1; katches *watches = kitten->watches + not_lit; unsigned conflict = INVALID; @@ -1126,7 +1128,7 @@ static inline unsigned propagate_literal (kitten *kitten, unsigned lit) { const unsigned ref = katch.ref; #ifdef KITTEN_BLIT const unsigned blit = katch.blit; - assert (blit != not_lit); + KISSAT_assert (blit != not_lit); const value blit_value = values[blit]; if (blit_value > 0) continue; @@ -1137,14 +1139,14 @@ static inline unsigned propagate_literal (kitten *kitten, unsigned lit) { conflict = ref; break; } else { - assert (!blit_value); + KISSAT_assert (!blit_value); assign (kitten, blit, ref); continue; } } #endif klause *c = dereference_klause (kitten, ref); - assert (c->size > 1); + KISSAT_assert (c->size > 1); unsigned *lits = c->lits; const unsigned other = lits[0] ^ lits[1] ^ not_lit; const value other_value = values[other]; @@ -1166,7 +1168,7 @@ static inline unsigned propagate_literal (kitten *kitten, unsigned lit) { break; } if (replacement_value >= 0) { - assert (replacement != INVALID); + KISSAT_assert (replacement != INVALID); ROG (ref, "unwatching %u in", not_lit); lits[0] = other; lits[1] = replacement; @@ -1179,7 +1181,7 @@ static inline unsigned propagate_literal (kitten *kitten, unsigned lit) { conflict = ref; break; } else { - assert (!other_value); + KISSAT_assert (!other_value); assign (kitten, other, ref); } } @@ -1191,7 +1193,7 @@ static inline unsigned propagate_literal (kitten *kitten, unsigned lit) { } static inline unsigned propagate (kitten *kitten) { - assert (kitten->inconsistent == INVALID); + KISSAT_assert (kitten->inconsistent == INVALID); unsigned propagated = 0; unsigned conflict = INVALID; while (conflict == INVALID && @@ -1216,8 +1218,8 @@ static void bump (kitten *kitten) { static inline void unassign (kitten *kitten, value *values, unsigned lit) { const unsigned not_lit = lit ^ 1; - assert (values[lit]); - assert (values[not_lit]); + KISSAT_assert (values[lit]); + KISSAT_assert (values[not_lit]); const unsigned idx = lit / 2; #ifdef LOGGING kar *var = kitten->vars + idx; @@ -1225,7 +1227,7 @@ static inline void unassign (kitten *kitten, value *values, unsigned lit) { LOG ("unassign %u", lit); #endif values[lit] = values[not_lit] = 0; - assert (kitten->unassigned < kitten->lits / 2); + KISSAT_assert (kitten->unassigned < kitten->lits / 2); kitten->unassigned++; kink *links = kitten->links; kink *link = links + idx; @@ -1235,7 +1237,7 @@ static inline void unassign (kitten *kitten, value *values, unsigned lit) { static void backtrack (kitten *kitten, unsigned jump) { check_queue (kitten); - assert (jump < kitten->level); + KISSAT_assert (jump < kitten->level); LOG ("back%s to level %u", (kitten->level == jump + 1 ? "tracking" : "jumping"), jump); kar *vars = kitten->vars; @@ -1260,11 +1262,11 @@ void completely_backtrack_to_root_level (kitten *kitten) { LOG ("completely backtracking to level 0"); value *values = kitten->values; unsigneds *trail = &kitten->trail; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG kar *vars = kitten->vars; #endif for (all_stack (unsigned, lit, *trail)) { - assert (vars[lit / 2].level); + KISSAT_assert (vars[lit / 2].level); unassign (kitten, values, lit); } CLEAR_STACK (*trail); @@ -1274,11 +1276,11 @@ void completely_backtrack_to_root_level (kitten *kitten) { } static void analyze (kitten *kitten, unsigned conflict) { - assert (kitten->level); - assert (kitten->inconsistent == INVALID); - assert (EMPTY_STACK (kitten->analyzed)); - assert (EMPTY_STACK (kitten->resolved)); - assert (EMPTY_STACK (kitten->klause)); + KISSAT_assert (kitten->level); + KISSAT_assert (kitten->inconsistent == INVALID); + KISSAT_assert (EMPTY_STACK (kitten->analyzed)); + KISSAT_assert (EMPTY_STACK (kitten->resolved)); + KISSAT_assert (EMPTY_STACK (kitten->klause)); PUSH_STACK (kitten->klause, INVALID); unsigned reason = conflict; value *marks = kitten->marks; @@ -1287,16 +1289,16 @@ static void analyze (kitten *kitten, unsigned conflict) { unsigned const *p = END_STACK (kitten->trail); unsigned open = 0, jump = 0, size = 1, uip; for (;;) { - assert (reason != INVALID); + KISSAT_assert (reason != INVALID); klause *c = dereference_klause (kitten, reason); - assert (c); + KISSAT_assert (c); ROG (reason, "analyzing"); PUSH_STACK (kitten->resolved, reason); for (all_literals_in_klause (lit, c)) { const unsigned idx = lit / 2; if (marks[idx]) continue; - assert (kitten->values[lit] < 0); + KISSAT_assert (kitten->values[lit] < 0); LOG ("analyzed %u", lit); marks[idx] = true; PUSH_STACK (kitten->analyzed, idx); @@ -1318,10 +1320,10 @@ static void analyze (kitten *kitten, unsigned conflict) { } unsigned idx; do { - assert (BEGIN_STACK (kitten->trail) < p); + KISSAT_assert (BEGIN_STACK (kitten->trail) < p); uip = *--p; } while (!marks[idx = uip / 2]); - assert (open); + KISSAT_assert (open); if (!--open) break; reason = vars[idx].reason; @@ -1339,11 +1341,11 @@ static void analyze (kitten *kitten, unsigned conflict) { } static void failing (kitten *kitten) { - assert (kitten->inconsistent == INVALID); - assert (!EMPTY_STACK (kitten->assumptions)); - assert (EMPTY_STACK (kitten->analyzed)); - assert (EMPTY_STACK (kitten->resolved)); - assert (EMPTY_STACK (kitten->klause)); + KISSAT_assert (kitten->inconsistent == INVALID); + KISSAT_assert (!EMPTY_STACK (kitten->assumptions)); + KISSAT_assert (EMPTY_STACK (kitten->analyzed)); + KISSAT_assert (EMPTY_STACK (kitten->resolved)); + KISSAT_assert (EMPTY_STACK (kitten->klause)); LOG ("analyzing failing assumptions"); const value *const values = kitten->values; const kar *const vars = kitten->vars; @@ -1371,7 +1373,7 @@ static void failing (kitten *kitten) { failed = failed_clashing; else failed = first_failed; - assert (failed != INVALID); + KISSAT_assert (failed != INVALID); const unsigned failed_idx = failed / 2; const kar *const failed_var = vars + failed_idx; const unsigned failed_reason = failed_var->reason; @@ -1379,7 +1381,7 @@ static void failing (kitten *kitten) { kitten->failed[failed] = true; if (failed_unit != INVALID) { - assert (dereference_klause (kitten, failed_reason)->size == 1); + KISSAT_assert (dereference_klause (kitten, failed_reason)->size == 1); LOG ("root-level falsified assumption %u", failed); kitten->failing = failed_reason; ROG (kitten->failing, "failing reason"); @@ -1390,19 +1392,19 @@ static void failing (kitten *kitten) { if (failed_clashing != INVALID) { LOG ("clashing with negated assumption %u", not_failed); kitten->failed[not_failed] = true; - assert (kitten->failing == INVALID); + KISSAT_assert (kitten->failing == INVALID); return; } value *marks = kitten->marks; - assert (!marks[failed_idx]); + KISSAT_assert (!marks[failed_idx]); marks[failed_idx] = true; PUSH_STACK (kitten->analyzed, failed_idx); PUSH_STACK (kitten->klause, not_failed); for (size_t next = 0; next < SIZE_STACK (kitten->analyzed); next++) { const unsigned idx = PEEK_STACK (kitten->analyzed, next); - assert (marks[idx]); + KISSAT_assert (marks[idx]); const kar *var = vars + idx; const unsigned reason = var->reason; if (reason == INVALID) { @@ -1410,7 +1412,7 @@ static void failing (kitten *kitten) { if (values[lit] < 0) lit ^= 1; LOG ("failed assumption %u", lit); - assert (!kitten->failed[lit]); + KISSAT_assert (!kitten->failed[lit]); kitten->failed[lit] = true; const unsigned not_lit = lit ^ 1; PUSH_STACK (kitten->klause, not_lit); @@ -1432,11 +1434,11 @@ static void failing (kitten *kitten) { } for (all_stack (unsigned, idx, kitten->analyzed)) - assert (marks[idx]), marks[idx] = 0; + KISSAT_assert (marks[idx]), marks[idx] = 0; CLEAR_STACK (kitten->analyzed); const size_t resolved = SIZE_STACK (kitten->resolved); - assert (resolved); + KISSAT_assert (resolved); if (resolved == 1) { kitten->failing = PEEK_STACK (kitten->resolved, 0); @@ -1453,7 +1455,7 @@ static void failing (kitten *kitten) { static void flush_trail (kitten *kitten) { unsigneds *trail = &kitten->trail; LOG ("flushing %zu root-level literals from trail", SIZE_STACK (*trail)); - assert (!kitten->level); + KISSAT_assert (!kitten->level); kitten->propagated = 0; CLEAR_STACK (*trail); } @@ -1502,7 +1504,7 @@ static int decide (kitten *kitten) { unsigned idx = kitten->queue.search; const kink *const links = kitten->links; for (;;) { - assert (idx != INVALID); + KISSAT_assert (idx != INVALID); if (!values[2 * idx]) break; idx = links[idx].prev; @@ -1519,8 +1521,8 @@ static int decide (kitten *kitten) { } static void inconsistent (kitten *kitten, unsigned ref) { - assert (ref != INVALID); - assert (kitten->inconsistent == INVALID); + KISSAT_assert (ref != INVALID); + KISSAT_assert (kitten->inconsistent == INVALID); if (!kitten->antecedents) { kitten->inconsistent = ref; @@ -1531,25 +1533,25 @@ static void inconsistent (kitten *kitten, unsigned ref) { unsigneds *analyzed = &kitten->analyzed; unsigneds *resolved = &kitten->resolved; - assert (EMPTY_STACK (*analyzed)); - assert (EMPTY_STACK (*resolved)); + KISSAT_assert (EMPTY_STACK (*analyzed)); + KISSAT_assert (EMPTY_STACK (*resolved)); value *marks = kitten->marks; const kar *const vars = kitten->vars; unsigned next = 0; for (;;) { - assert (ref != INVALID); + KISSAT_assert (ref != INVALID); klause *c = dereference_klause (kitten, ref); - assert (c); + KISSAT_assert (c); ROG (ref, "analyzing inconsistent"); PUSH_STACK (*resolved, ref); for (all_literals_in_klause (lit, c)) { const unsigned idx = lit / 2; - assert (!vars[idx].level); + KISSAT_assert (!vars[idx].level); if (marks[idx]) continue; - assert (kitten->values[lit] < 0); + KISSAT_assert (kitten->values[lit] < 0); LOG ("analyzed %u", lit); marks[idx] = true; PUSH_STACK (kitten->analyzed, idx); @@ -1559,10 +1561,10 @@ static void inconsistent (kitten *kitten, unsigned ref) { const unsigned idx = PEEK_STACK (kitten->analyzed, next); next++; const kar *const v = vars + idx; - assert (!v->level); + KISSAT_assert (!v->level); ref = v->reason; } - assert (EMPTY_STACK (kitten->klause)); + KISSAT_assert (EMPTY_STACK (kitten->klause)); ref = new_learned_klause (kitten); ROG (ref, "registering final inconsistent empty"); kitten->inconsistent = ref; @@ -1590,9 +1592,9 @@ static int propagate_units (kitten *kitten) { for (size_t next = 0; next < SIZE_STACK (kitten->units); next++) { const unsigned ref = PEEK_STACK (kitten->units, next); - assert (ref != INVALID); + KISSAT_assert (ref != INVALID); klause *c = dereference_klause (kitten, ref); - assert (c->size == 1); + KISSAT_assert (c->size == 1); ROG (ref, "propagating unit"); const unsigned unit = c->lits[0]; const value value = values[unit]; @@ -1628,8 +1630,8 @@ static klause *end_klauses (kitten *kitten) { } static klause *next_klause (kitten *kitten, klause *c) { - assert (begin_klauses (kitten) <= c); - assert (c < end_klauses (kitten)); + KISSAT_assert (begin_klauses (kitten) <= c); + KISSAT_assert (c < end_klauses (kitten)); unsigned *res = c->lits + c->size; if (kitten->antecedents && is_learned_klause (c)) res += c->aux; @@ -1654,9 +1656,9 @@ static void reset_assumptions (kitten *kitten) { const unsigned assumption = POP_STACK (kitten->assumptions); kitten->failed[assumption] = false; } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG for (size_t i = 0; i < kitten->size; i++) - assert (!kitten->failed[i]); + KISSAT_assert (!kitten->failed[i]); #endif CLEAR_STACK (kitten->assumptions); if (kitten->failing != INVALID) { @@ -1671,7 +1673,7 @@ static void reset_incremental (kitten *kitten) { if (!EMPTY_STACK (kitten->assumptions)) reset_assumptions (kitten); else - assert (kitten->failing == INVALID); + KISSAT_assert (kitten->failing == INVALID); if (kitten->status == 21) reset_core (kitten); UPDATE_STATUS (0); @@ -1682,7 +1684,7 @@ static void reset_incremental (kitten *kitten) { static bool flip_literal (kitten *kitten, unsigned lit) { INC (kitten_flip); signed char *values = kitten->values; - assert (values[lit]); + KISSAT_assert (values[lit]); if (!kitten->vars[lit / 2].level) { LOG ("can not flip root-level assigned literal %u", lit); return false; @@ -1690,7 +1692,7 @@ static bool flip_literal (kitten *kitten, unsigned lit) { if (values[lit] < 0) lit ^= 1; LOG ("trying to flip value of satisfied literal %u", lit); - assert (values[lit] > 0); + KISSAT_assert (values[lit] > 0); katches *watches = kitten->watches + lit; katch *q = BEGIN_STACK (*watches); const katch *const end_watches = END_STACK (*watches); @@ -1701,7 +1703,7 @@ static bool flip_literal (kitten *kitten, unsigned lit) { const katch katch = *q++ = *p++; #ifdef KITTEN_BLIT const unsigned blit = katch.blit; - assert (blit != lit); + KISSAT_assert (blit != lit); const value blit_value = values[blit]; if (blit_value > 0) continue; @@ -1720,14 +1722,14 @@ static bool flip_literal (kitten *kitten, unsigned lit) { unsigned *r; for (r = lits + 2; r != end_lits; r++) { replacement = *r; - assert (replacement != lit); + KISSAT_assert (replacement != lit); replacement_value = values[replacement]; - assert (replacement_value); + KISSAT_assert (replacement_value); if (replacement_value > 0) break; } if (replacement_value > 0) { - assert (replacement != INVALID); + KISSAT_assert (replacement != INVALID); ROG (ref, "unwatching %u in", lit); lits[0] = other; lits[1] = replacement; @@ -1735,7 +1737,7 @@ static bool flip_literal (kitten *kitten, unsigned lit) { watch_klause (kitten, replacement, c, ref); q--; } else { - assert (replacement_value < 0); + KISSAT_assert (replacement_value < 0); ROG (ref, "single satisfied"); res = false; break; @@ -1774,14 +1776,14 @@ void kitten_clause_with_id_and_exception (kitten *kitten, unsigned id, REQUIRE_INITIALIZED (); if (kitten->status) reset_incremental (kitten); - assert (EMPTY_STACK (kitten->klause)); + KISSAT_assert (EMPTY_STACK (kitten->klause)); const unsigned *const end = elits + size; for (const unsigned *p = elits; p != end; p++) { const unsigned elit = *p; if (elit == except) continue; const unsigned ilit = import_literal (kitten, elit); - assert (ilit < kitten->lits); + KISSAT_assert (ilit < kitten->lits); const unsigned iidx = ilit / 2; if (kitten->marks[iidx]) INVALID_API_USAGE ("variable '%u' of literal '%u' occurs twice", @@ -1877,7 +1879,7 @@ unsigned kitten_compute_clausal_core (kitten *kitten, LOG ("computing clausal core"); unsigneds *resolved = &kitten->resolved; - assert (EMPTY_STACK (*resolved)); + KISSAT_assert (EMPTY_STACK (*resolved)); unsigned original = 0; uint64_t learned = 0; @@ -1885,17 +1887,33 @@ unsigned kitten_compute_clausal_core (kitten *kitten, unsigned reason_ref = kitten->inconsistent; if (reason_ref == INVALID) { - assert (!EMPTY_STACK (kitten->assumptions)); + KISSAT_assert (!EMPTY_STACK (kitten->assumptions)); reason_ref = kitten->failing; if (reason_ref == INVALID) { LOG ("assumptions mutually inconsistent"); - goto DONE; + + + // goto DONE; + if (learned_ptr) + *learned_ptr = learned; + + LOG ("clausal core of %u original clauses", original); + LOG ("clausal core of %" PRIu64 " learned clauses", learned); +#ifdef STAND_ALONE_KITTEN + kitten->statistics.original = original; + kitten->statistics.learned = 0; +#endif + UPDATE_STATUS (21); + + return original; + + } } PUSH_STACK (*resolved, reason_ref); unsigneds *core = &kitten->core; - assert (EMPTY_STACK (*core)); + KISSAT_assert (EMPTY_STACK (*core)); while (!EMPTY_STACK (*resolved)) { const unsigned c_ref = POP_STACK (*resolved); @@ -1904,7 +1922,7 @@ unsigned kitten_compute_clausal_core (kitten *kitten, ROG (d_ref, "core[%zu]", SIZE_STACK (*core)); PUSH_STACK (*core, d_ref); klause *d = dereference_klause (kitten, d_ref); - assert (!is_core_klause (d)); + KISSAT_assert (!is_core_klause (d)); set_core_klause (d); if (is_learned_klause (d)) learned++; @@ -1927,7 +1945,7 @@ unsigned kitten_compute_clausal_core (kitten *kitten, } } -DONE: + //DONE: if (learned_ptr) *learned_ptr = learned; @@ -1952,7 +1970,7 @@ void kitten_traverse_core_ids (kitten *kitten, void *state, unsigned traversed = 0; for (all_original_klauses (c)) { - assert (!is_learned_klause (c)); + KISSAT_assert (!is_learned_klause (c)); if (is_learned_klause (c)) continue; if (!is_core_klause (c)) @@ -1965,7 +1983,7 @@ void kitten_traverse_core_ids (kitten *kitten, void *state, LOG ("traversed %u original core clauses", traversed); (void) traversed; - assert (kitten->status == 21); + KISSAT_assert (kitten->status == 21); } void kitten_traverse_core_clauses (kitten *kitten, void *state, @@ -1979,10 +1997,10 @@ void kitten_traverse_core_clauses (kitten *kitten, void *state, for (all_stack (unsigned, c_ref, kitten->core)) { klause *c = dereference_klause (kitten, c_ref); - assert (is_core_klause (c)); + KISSAT_assert (is_core_klause (c)); const bool learned = is_learned_klause (c); unsigneds *eclause = &kitten->eclause; - assert (EMPTY_STACK (*eclause)); + KISSAT_assert (EMPTY_STACK (*eclause)); for (all_literals_in_klause (ilit, c)) { const unsigned elit = export_literal (kitten, ilit); PUSH_STACK (*eclause, elit); @@ -1998,7 +2016,7 @@ void kitten_traverse_core_clauses (kitten *kitten, void *state, LOG ("traversed %u core clauses", traversed); (void) traversed; - assert (kitten->status == 21); + KISSAT_assert (kitten->status == 21); } void kitten_shrink_to_clausal_core (kitten *kitten) { @@ -2019,7 +2037,7 @@ void kitten_shrink_to_clausal_core (kitten *kitten) { for (all_kits (lit)) CLEAR_STACK (KATCHES (lit)); - assert (kitten->inconsistent != INVALID); + KISSAT_assert (kitten->inconsistent != INVALID); klause *inconsistent = dereference_klause (kitten, kitten->inconsistent); if (is_learned_klause (inconsistent) || inconsistent->size) { ROG (kitten->inconsistent, "resetting inconsistent"); @@ -2036,7 +2054,7 @@ void kitten_shrink_to_clausal_core (kitten *kitten) { #endif for (klause *c = begin, *next; c != end; c = next) { next = next_klause (kitten, c); - assert (!is_learned_klause (c)); + KISSAT_assert (!is_learned_klause (c)); if (is_learned_klause (c)) continue; if (!is_core_klause (c)) @@ -2313,7 +2331,7 @@ static kitten *parse (parser *parser, ints *originals, int *max_var) { } else if (offset > UINT_MAX) ERROR ("too many original literals"); else { - assert (SIZE_STACK (clause) <= UINT_MAX); + KISSAT_assert (SIZE_STACK (clause) <= UINT_MAX); const unsigned size = SIZE_STACK (clause); const unsigned *const lits = BEGIN_STACK (clause); kitten_clause_with_id_and_exception (kitten, offset, size, lits, @@ -2334,7 +2352,7 @@ static kitten *parse (parser *parser, ints *originals, int *max_var) { while (uidx >= new_size_marks) new_size_marks *= 2; signed char *new_marks; - CALLOC (new_marks, new_size_marks); + CALLOC (signed char, new_marks, new_size_marks); if (size_marks) memcpy (new_marks, marks, size_marks); DEALLOC (marks, size_marks); @@ -2393,7 +2411,7 @@ static inline void print_lit (line *line, int lit) { } static void print_witness (kitten *kitten, int max_var) { - assert (max_var >= 0); + KISSAT_assert (max_var >= 0); line line = {.size = 0}; const size_t parsed_lits = 2 * (size_t) max_var; for (size_t ulit = 0; ulit < parsed_lits; ulit += 2) { @@ -2413,14 +2431,14 @@ typedef struct core_writer core_writer; struct core_writer { FILE *file; ints *originals; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG unsigned written; #endif }; static void write_offset (void *ptr, unsigned offset) { core_writer *writer = ptr; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG writer->written++; #endif int const *p = &PEEK_STACK (*writer->originals, offset); @@ -2432,19 +2450,19 @@ static void write_offset (void *ptr, unsigned offset) { static void write_core (kitten *kitten, unsigned reduced, ints *originals, FILE *file) { - assert (originals); + KISSAT_assert (originals); fprintf (file, "p cnf %zu %u\n", kitten->evars, reduced); core_writer writer; writer.file = file; writer.originals = originals; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG writer.written = 0; #endif kitten_traverse_core_ids (kitten, &writer, write_offset); - assert (writer.written == reduced); + KISSAT_assert (writer.written == reduced); } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG typedef struct lemma_writer lemma_writer; @@ -2460,7 +2478,7 @@ static void write_lemma (void *ptr, bool learned, size_t size, if (!learned) return; const unsigned *const end = lits + size; -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG FILE *file = ptr; #else lemma_writer *writer = ptr; @@ -2471,7 +2489,7 @@ static void write_lemma (void *ptr, bool learned, size_t size, const unsigned ulit = *p; const unsigned idx = ulit / 2; const unsigned sign = ulit & 1; - assert (idx + 1 <= (unsigned) INT_MAX); + KISSAT_assert (idx + 1 <= (unsigned) INT_MAX); int ilit = idx + 1; if (sign) ilit = -ilit; @@ -2482,7 +2500,7 @@ static void write_lemma (void *ptr, bool learned, size_t size, static void write_lemmas (kitten *kitten, uint64_t reduced, FILE *file) { void *state; -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG state = file; (void) reduced; #else @@ -2492,7 +2510,7 @@ static void write_lemmas (kitten *kitten, uint64_t reduced, FILE *file) { state = &writer; #endif kitten_traverse_core_clauses (kitten, state, write_lemma); - assert (writer.written == reduced); + KISSAT_assert (writer.written == reduced); } static void print_statistics (statistics statistics) { @@ -2562,7 +2580,7 @@ static void catch_signal (int sig) { } static void catch_alarm (int sig) { - assert (sig == SIGALRM); + KISSAT_assert (sig == SIGALRM); if (time_limit > 0) time_limit_hit = true; (void) sig; @@ -2757,7 +2775,7 @@ int main (int argc, char **argv) { reset_alarm (); res = kitten_solve (kitten); - assert (res == 20); + KISSAT_assert (res == 20); } FILE *output_file = fopen (output_path, "w"); if (!output_file) @@ -2792,3 +2810,5 @@ int main (int argc, char **argv) { } #endif + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/kitten.h b/src/sat/kissat/kitten.h index e7ead94dc..2ea9d6d36 100644 --- a/src/sat/kissat/kitten.h +++ b/src/sat/kissat/kitten.h @@ -5,6 +5,9 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct kitten kitten; kitten *kitten_init (void); @@ -51,4 +54,6 @@ void kitten_traverse_core_clauses (kitten *, void *state, struct kissat; kitten *kitten_embedded (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/options.c b/src/sat/kissat/kptions.c similarity index 94% rename from src/sat/kissat/options.c rename to src/sat/kissat/kptions.c index cf618905e..8a07b693d 100644 --- a/src/sat/kissat/options.c +++ b/src/sat/kissat/kptions.c @@ -8,7 +8,9 @@ #include #include -#ifdef NOPTIONS +ABC_NAMESPACE_IMPL_START + +#ifdef KISSAT_NOPTIONS static const opt table[] = { #define OPTION(N, V, L, H, D) {#N, (int) (V), D}, @@ -32,7 +34,7 @@ const opt *kissat_options_begin = table; const opt *kissat_options_end = table + size_table; static void check_table_sorted (void) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG opt const *p = 0; for (all_options (o)) if (p && strcmp (p->name, o->name) >= 0) @@ -46,7 +48,7 @@ const opt *kissat_options_has (const char *name) { size_t l = 0, m, r = size_table; int tmp; opt const *o; - assert (l < r); + KISSAT_assert (l < r); while (l + 1 < r) { m = l + (r - l) / 2; tmp = strcmp (name, (o = table + m)->name); @@ -148,7 +150,7 @@ bool kissat_parse_option_value (const char *val_str, int *res_ptr) { return false; // '0^0' invalid } else if (ch) return false; - assert (res <= max); + KISSAT_assert (res <= max); if (sign > 0 && res == max) return false; res *= sign; @@ -171,7 +173,7 @@ const char *kissat_parse_option_name (const char *arg, const char *name) { return p + 1; } -#ifdef NOPTIONS +#ifdef KISSAT_NOPTIONS void kissat_init_options (void) { check_table_sorted (); } @@ -182,12 +184,16 @@ int kissat_options_get (const char *name) { #else +ABC_NAMESPACE_IMPL_END + #include "format.h" #include #include #include +ABC_NAMESPACE_IMPL_START + static void kissat_printf_usage (const char *option, const char *fmt, ...) { va_list ap; printf (" %-26s ", option); @@ -217,7 +223,7 @@ static void check_ranges (void) { } static void check_name_length (void) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG #define OPTION(N, V, L, H, D) \ if (strlen (#N) + 1 > kissat_options_max_name_buffer_size) \ kissat_fatal ("option '%s' name length %zu " \ @@ -235,8 +241,8 @@ int kissat_options_get (const options *options, const char *name) { } int kissat_options_set_opt (options *options, const opt *o, int value) { - assert (kissat_options_begin <= o); - assert (o < kissat_options_end); + KISSAT_assert (kissat_options_begin <= o); + KISSAT_assert (o < kissat_options_end); int *p = (int *) options + (o - table); int res = *p; if (value == res) @@ -261,8 +267,8 @@ void kissat_init_options (options *options) { check_name_length (); check_table_sorted (); #define OPTION(N, V, L, H, D) \ - assert ((L) <= (V)); \ - assert ((V) <= (H)); \ + KISSAT_assert ((L) <= (V)); \ + KISSAT_assert ((V) <= (H)); \ options->N = (V); OPTIONS #undef OPTION @@ -306,7 +312,7 @@ bool kissat_options_parse_arg (const char *arg, char *buffer, while ((ch = *p) && ch != '=') p++; if (ch) { - assert (ch == '='); + KISSAT_assert (ch == '='); const size_t len = p - name; if (len >= kissat_options_max_name_buffer_size) return false; @@ -333,7 +339,7 @@ bool kissat_options_parse_arg (const char *arg, char *buffer, if (!o || o->high < (value = 1)) return false; } - assert (strlen (name) < kissat_options_max_name_buffer_size); + KISSAT_assert (strlen (name) < kissat_options_max_name_buffer_size); strcpy (buffer, name); *val_ptr = value; } @@ -345,7 +351,7 @@ static bool ignore_embedded_option_for_fuzzing (const char *name) { if (!strcmp (name, "embedded")) return true; #endif -#ifndef QUIET +#ifndef KISSAT_QUIET if (!strcmp (name, "quiet")) return true; #endif @@ -370,7 +376,7 @@ static bool ignore_range_option_for_fuzzing (const char *name) { if (!strcmp (name, "embedded")) return true; #endif -#ifndef QUIET +#ifndef KISSAT_QUIET if (!strcmp (name, "quiet")) return true; #endif @@ -394,3 +400,5 @@ void kissat_print_option_range_list (void) { } #endif + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/krite.c b/src/sat/kissat/krite.c index 85d91d9d9..04c9a810d 100644 --- a/src/sat/kissat/krite.c +++ b/src/sat/kissat/krite.c @@ -5,12 +5,14 @@ #include +ABC_NAMESPACE_IMPL_START + void kissat_write_dimacs (kissat *solver, FILE *file) { size_t imported = SIZE_STACK (solver->import); if (imported) imported--; fprintf (file, "p cnf %zu %" PRIu64 "\n", imported, BINIRR_CLAUSES); - assert (solver->watching); + KISSAT_assert (solver->watching); if (solver->watching) { for (all_literals (ilit)) for (all_binary_blocking_watches (watch, WATCHES (ilit))) @@ -43,3 +45,5 @@ void kissat_write_dimacs (kissat *solver, FILE *file) { fputs ("0\n", file); } } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/krite.h b/src/sat/kissat/krite.h index a8af42c9c..3b6fe6bb4 100644 --- a/src/sat/kissat/krite.h +++ b/src/sat/kissat/krite.h @@ -3,7 +3,12 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_write_dimacs (struct kissat *, FILE *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/lucky.c b/src/sat/kissat/kucky.c similarity index 89% rename from src/sat/kissat/lucky.c rename to src/sat/kissat/kucky.c index 74219b095..3e3121b2d 100644 --- a/src/sat/kissat/lucky.c +++ b/src/sat/kissat/kucky.c @@ -8,6 +8,8 @@ #include "proprobe.h" #include "report.h" +ABC_NAMESPACE_IMPL_START + static bool no_all_negative_clauses (struct kissat *solver) { clause *last_irredundant = kissat_last_irredundant_clause (solver); for (all_clauses (c)) { @@ -24,7 +26,7 @@ static bool no_all_negative_clauses (struct kissat *solver) { return false; CONTINUE_WITH_NEXT_CLAUSE:; } - assert (solver->watching); + KISSAT_assert (solver->watching); for (all_variables (idx)) { if (!ACTIVE (idx)) continue; @@ -60,7 +62,7 @@ static bool no_all_positive_clauses (struct kissat *solver) { return false; CONTINUE_WITH_NEXT_CLAUSE:; } - assert (solver->watching); + KISSAT_assert (solver->watching); for (all_variables (idx)) { if (!ACTIVE (idx)) continue; @@ -80,8 +82,8 @@ static bool no_all_positive_clauses (struct kissat *solver) { } static int forward_false_satisfiable (struct kissat *solver) { - assert (!solver->level); -#ifndef QUIET + KISSAT_assert (!solver->level); +#ifndef KISSAT_QUIET unsigned conflicts = 0; #endif for (all_stack (import, import, solver->import)) { @@ -100,7 +102,7 @@ static int forward_false_satisfiable (struct kissat *solver) { clause *c = kissat_probing_propagate (solver, 0, true); if (!c) continue; -#ifndef QUIET +#ifndef KISSAT_QUIET conflicts++; #endif if (solver->level > 1) { @@ -118,11 +120,11 @@ static int forward_false_satisfiable (struct kissat *solver) { } else { LOG ("failed literal %s", LOGLIT (not_lit)); kissat_analyze (solver, c); - assert (!solver->level); + KISSAT_assert (!solver->level); clause *d = kissat_probing_propagate (solver, 0, true); if (d) { kissat_analyze (solver, d); - assert (solver->inconsistent); + KISSAT_assert (solver->inconsistent); kissat_verbose (solver, "lucky inconsistency forward assigning to false"); return 20; @@ -135,8 +137,8 @@ static int forward_false_satisfiable (struct kissat *solver) { } static int forward_true_satisfiable (struct kissat *solver) { - assert (!solver->level); -#ifndef QUIET + KISSAT_assert (!solver->level); +#ifndef KISSAT_QUIET unsigned conflicts = 0; #endif for (all_stack (import, import, solver->import)) { @@ -154,7 +156,7 @@ static int forward_true_satisfiable (struct kissat *solver) { clause *c = kissat_probing_propagate (solver, 0, true); if (!c) continue; -#ifndef QUIET +#ifndef KISSAT_QUIET conflicts++; #endif if (solver->level > 1) { @@ -173,11 +175,11 @@ static int forward_true_satisfiable (struct kissat *solver) { } else { LOG ("failed literal %s", LOGLIT (lit)); kissat_analyze (solver, c); - assert (!solver->level); + KISSAT_assert (!solver->level); clause *d = kissat_probing_propagate (solver, 0, true); if (d) { kissat_analyze (solver, d); - assert (solver->inconsistent); + KISSAT_assert (solver->inconsistent); kissat_verbose (solver, "lucky inconsistency forward assigning to true"); return 20; @@ -189,8 +191,8 @@ static int forward_true_satisfiable (struct kissat *solver) { } static int backward_false_satisfiable (struct kissat *solver) { - assert (!solver->level); -#ifndef QUIET + KISSAT_assert (!solver->level); +#ifndef KISSAT_QUIET unsigned conflicts = 0; #endif import *begin = BEGIN_STACK (solver->import); @@ -213,7 +215,7 @@ static int backward_false_satisfiable (struct kissat *solver) { clause *c = kissat_probing_propagate (solver, 0, true); if (!c) continue; -#ifndef QUIET +#ifndef KISSAT_QUIET conflicts++; #endif if (solver->level > 1) { @@ -231,11 +233,11 @@ static int backward_false_satisfiable (struct kissat *solver) { } else { LOG ("failed literal %s", LOGLIT (not_lit)); kissat_analyze (solver, c); - assert (!solver->level); + KISSAT_assert (!solver->level); clause *d = kissat_probing_propagate (solver, 0, true); if (d) { kissat_analyze (solver, d); - assert (solver->inconsistent); + KISSAT_assert (solver->inconsistent); kissat_verbose (solver, "lucky inconsistency backward assigning to false"); return 20; @@ -247,8 +249,8 @@ static int backward_false_satisfiable (struct kissat *solver) { } static int backward_true_satisfiable (struct kissat *solver) { - assert (!solver->level); -#ifndef QUIET + KISSAT_assert (!solver->level); +#ifndef KISSAT_QUIET unsigned conflicts = 0; #endif import *begin = BEGIN_STACK (solver->import); @@ -270,7 +272,7 @@ static int backward_true_satisfiable (struct kissat *solver) { clause *c = kissat_probing_propagate (solver, 0, true); if (!c) continue; -#ifndef QUIET +#ifndef KISSAT_QUIET conflicts++; #endif if (solver->level > 1) { @@ -289,11 +291,11 @@ static int backward_true_satisfiable (struct kissat *solver) { } else { LOG ("failed literal %s", LOGLIT (lit)); kissat_analyze (solver, c); - assert (!solver->level); + KISSAT_assert (!solver->level); clause *d = kissat_probing_propagate (solver, 0, true); if (d) { kissat_analyze (solver, d); - assert (solver->inconsistent); + KISSAT_assert (solver->inconsistent); kissat_verbose (solver, "lucky inconsistency backward assigning to true"); return 20; @@ -313,10 +315,10 @@ int kissat_lucky (struct kissat *solver) { return 0; START (lucky); - assert (!solver->level); - assert (!solver->probing); + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->probing); solver->probing = true; - assert (kissat_propagated (solver)); + KISSAT_assert (kissat_propagated (solver)); int res = 0; @@ -328,15 +330,15 @@ int kissat_lucky (struct kissat *solver) { if (VALUE (lit)) continue; kissat_internal_assume (solver, lit); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG clause *c = #endif kissat_probing_propagate (solver, 0, true); - assert (!c); + KISSAT_assert (!c); } kissat_verbose (solver, "set all variables to true"); - assert (kissat_propagated (solver)); - assert (!solver->unassigned); + KISSAT_assert (kissat_propagated (solver)); + KISSAT_assert (!solver->unassigned); res = 10; } @@ -349,15 +351,15 @@ int kissat_lucky (struct kissat *solver) { continue; const unsigned not_lit = NOT (lit); kissat_internal_assume (solver, not_lit); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG clause *c = #endif kissat_probing_propagate (solver, 0, true); - assert (!c); + KISSAT_assert (!c); } kissat_verbose (solver, "set all variables to false"); - assert (kissat_propagated (solver)); - assert (!solver->unassigned); + KISSAT_assert (kissat_propagated (solver)); + KISSAT_assert (!solver->unassigned); res = 10; } @@ -381,13 +383,15 @@ int kissat_lucky (struct kissat *solver) { if (!res && units) kissat_message (solver, "lucky %u units", units); -#ifndef QUIET +#ifndef KISSAT_QUIET bool success = res || units; #endif - assert (solver->probing); + KISSAT_assert (solver->probing); solver->probing = false; REPORT (!success, 'l'); STOP (lucky); return res; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/learn.c b/src/sat/kissat/learn.c index 36a25be89..401fc0b56 100644 --- a/src/sat/kissat/learn.c +++ b/src/sat/kissat/learn.c @@ -5,8 +5,10 @@ #include +ABC_NAMESPACE_IMPL_START + static unsigned backjump_limit (struct kissat *solver) { -#ifdef NOPTIONS +#ifdef KISSAT_NOPTIONS (void) solver; #endif return GET_OPTION (chrono) ? (unsigned) GET_OPTION (chronolevels) @@ -14,9 +16,9 @@ static unsigned backjump_limit (struct kissat *solver) { } unsigned kissat_determine_new_level (kissat *solver, unsigned jump) { - assert (solver->level); + KISSAT_assert (solver->level); const unsigned back = solver->level - 1; - assert (jump <= back); + KISSAT_assert (jump <= back); const unsigned delta = back - jump; const unsigned limit = backjump_limit (solver); @@ -42,7 +44,7 @@ unsigned kissat_determine_new_level (kissat *solver, unsigned jump) { } static void learn_unit (kissat *solver, unsigned not_uip) { - assert (not_uip == PEEK_STACK (solver->clause, 0)); + KISSAT_assert (not_uip == PEEK_STACK (solver->clause, 0)); LOG ("learned unit clause %s triggers iteration", LOGLIT (not_uip)); const unsigned new_level = kissat_determine_new_level (solver, 0); kissat_backtrack_after_conflict (solver, new_level); @@ -59,11 +61,11 @@ static void learn_binary (kissat *solver, unsigned not_uip) { const unsigned new_level = kissat_determine_new_level (solver, jump_level); kissat_backtrack_after_conflict (solver, new_level); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG const reference ref = #endif kissat_new_redundant_clause (solver, 1); - assert (ref == INVALID_REF); + KISSAT_assert (ref == INVALID_REF); kissat_assign_binary (solver, not_uip, other); } @@ -80,10 +82,10 @@ static void insert_last_learned (kissat *solver, reference ref) { static reference learn_reference (kissat *solver, unsigned not_uip, unsigned glue) { - assert (solver->level > 1); - assert (SIZE_STACK (solver->clause) > 2); + KISSAT_assert (solver->level > 1); + KISSAT_assert (SIZE_STACK (solver->clause) > 2); unsigned *lits = BEGIN_STACK (solver->clause); - assert (lits[0] == not_uip); + KISSAT_assert (lits[0] == not_uip); unsigned *q = lits + 1; unsigned jump_lit = *q; unsigned jump_level = LEVEL (jump_lit); @@ -105,7 +107,7 @@ static reference learn_reference (kissat *solver, unsigned not_uip, *q = lits[1]; lits[1] = jump_lit; const reference ref = kissat_new_redundant_clause (solver, glue); - assert (ref != INVALID_REF); + KISSAT_assert (ref != INVALID_REF); clause *c = kissat_dereference_clause (solver, ref); c->used = MAX_USED; const unsigned new_level = @@ -116,14 +118,14 @@ static reference learn_reference (kissat *solver, unsigned not_uip, } void kissat_update_learned (kissat *solver, unsigned glue, unsigned size) { - assert (!solver->probing); + KISSAT_assert (!solver->probing); INC (clauses_learned); LOG ("learned[%" PRIu64 "] clause glue %u size %u", GET (clauses_learned), glue, size); if (solver->stable) kissat_tick_reluctant (&solver->reluctant); ADD (literals_learned, size); -#ifndef QUIET +#ifndef KISSAT_QUIET UPDATE_AVERAGE (size, size); #endif UPDATE_AVERAGE (fast_glue, glue); @@ -145,7 +147,7 @@ static void flush_last_learned (kissat *solver) { static void eagerly_subsume_last_learned (kissat *solver) { value *marks = solver->marks; for (all_stack (unsigned, lit, solver->clause)) { - assert (!marks[lit]); + KISSAT_assert (!marks[lit]); marks[lit] = 1; } unsigned clause_size = SIZE_STACK (solver->clause); @@ -191,10 +193,10 @@ void kissat_learn_clause (kissat *solver) { const unsigned not_uip = PEEK_STACK (solver->clause, 0); const unsigned size = SIZE_STACK (solver->clause); const size_t glue = SIZE_STACK (solver->levels); - assert (glue <= UINT_MAX); + KISSAT_assert (glue <= UINT_MAX); if (!solver->probing) kissat_update_learned (solver, glue, size); - assert (size > 0); + KISSAT_assert (size > 0); reference ref = INVALID_REF; if (size == 1) learn_unit (solver, not_uip); @@ -208,3 +210,5 @@ void kissat_learn_clause (kissat *solver) { insert_last_learned (solver, ref); } } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/learn.h b/src/sat/kissat/learn.h index b11923966..42c3bad5e 100644 --- a/src/sat/kissat/learn.h +++ b/src/sat/kissat/learn.h @@ -1,10 +1,15 @@ #ifndef _learn_h_INCLUDED #define _learn_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_learn_clause (struct kissat *); void kissat_update_learned (struct kissat *, unsigned glue, unsigned size); unsigned kissat_determine_new_level (struct kissat *, unsigned jump); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/literal.h b/src/sat/kissat/literal.h index 75d7814c6..9014e5dd4 100644 --- a/src/sat/kissat/literal.h +++ b/src/sat/kissat/literal.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define LD_MAX_VAR 30u #define LD_MAX_LIT (1 + LD_MAX_VAR) @@ -23,14 +26,16 @@ ((LIT) && ((LIT) != INT_MIN) && ABS (LIT) <= EXTERNAL_MAX_VAR) #define IDX(LIT) \ - (assert (VALID_INTERNAL_LITERAL (LIT)), (((unsigned) (LIT)) >> 1)) + (KISSAT_assert (VALID_INTERNAL_LITERAL (LIT)), (((unsigned) (LIT)) >> 1)) -#define LIT(IDX) (assert (VALID_INTERNAL_INDEX (IDX)), ((IDX) << 1)) +#define LIT(IDX) (KISSAT_assert (VALID_INTERNAL_INDEX (IDX)), ((IDX) << 1)) -#define NOT(LIT) (assert (VALID_INTERNAL_LITERAL (LIT)), ((LIT) ^ 1u)) +#define NOT(LIT) (KISSAT_assert (VALID_INTERNAL_LITERAL (LIT)), ((LIT) ^ 1u)) -#define NEGATED(LIT) (assert (VALID_INTERNAL_LITERAL (LIT)), ((LIT) & 1u)) +#define NEGATED(LIT) (KISSAT_assert (VALID_INTERNAL_LITERAL (LIT)), ((LIT) & 1u)) -#define STRIP(LIT) (assert (VALID_INTERNAL_LITERAL (LIT)), ((LIT) & ~1u)) +#define STRIP(LIT) (KISSAT_assert (VALID_INTERNAL_LITERAL (LIT)), ((LIT) & ~1u)) + +ABC_NAMESPACE_HEADER_END #endif diff --git a/src/sat/kissat/logging.c b/src/sat/kissat/logging.c index 36abd33ce..6955873fe 100644 --- a/src/sat/kissat/logging.c +++ b/src/sat/kissat/logging.c @@ -1,4 +1,6 @@ -#if defined(LOGGING) && !defined(QUIET) +#include "global.h" + +#if defined(LOGGING) && !defined(KISSAT_QUIET) #include "colors.h" #include "inline.h" @@ -9,7 +11,7 @@ static void begin_logging (kissat *solver, const char *prefix, const char *fmt, va_list *ap) { TERMINAL (stdout, 1); - assert (GET_OPTION (log)); + KISSAT_assert (GET_OPTION (log)); fputs (solver->prefix, stdout); COLOR (MAGENTA); printf ("%s %u ", prefix, solver->level); @@ -52,7 +54,7 @@ static void append_sprintf (char *str, const char *fmt, ...) { const char *kissat_log_repr (kissat *solver, unsigned lit, const unsigned *repr) { - assert (solver); + KISSAT_assert (solver); char *res = kissat_next_format_string (&solver->format); sprintf (res, "%u", lit); if (!solver->compacting && GET_OPTION (log) > 1) @@ -74,7 +76,7 @@ const char *kissat_log_repr (kissat *solver, unsigned lit, append_sprintf (res, "@%u", LEVEL (lit)); } } - assert (strlen (res) < FORMAT_STRING_SIZE); + KISSAT_assert (strlen (res) < FORMAT_STRING_SIZE); return res; } @@ -83,11 +85,11 @@ const char *kissat_log_lit (kissat *solver, unsigned lit) { } const char *kissat_log_var (kissat *solver, unsigned idx) { - assert (solver); + KISSAT_assert (solver); char *res = kissat_next_format_string (&solver->format); const unsigned lit = LIT (idx); sprintf (res, "variable %u (literal %s)", idx, LOGLIT (lit)); - assert (strlen (res) < FORMAT_STRING_SIZE); + KISSAT_assert (strlen (res) < FORMAT_STRING_SIZE); return res; } @@ -301,7 +303,7 @@ void kissat_log_ite_gate (kissat *solver, const char *prefix, size_t id, void kissat_log_extensions (kissat *solver, const char *prefix, size_t size, const extension *const exts, const char *fmt, ...) { - assert (size > 0); + KISSAT_assert (size > 0); va_list ap; va_start (ap, fmt); begin_logging (solver, prefix, fmt, &ap); diff --git a/src/sat/kissat/logging.h b/src/sat/kissat/logging.h index bb2b53218..65f06ef6b 100644 --- a/src/sat/kissat/logging.h +++ b/src/sat/kissat/logging.h @@ -1,8 +1,6 @@ #ifndef _logging_h_INCLUDED #define _logging_h_INCLUDED -#if defined(LOGGING) && !defined(QUIET) - #include "attribute.h" #include "extend.h" #include "reference.h" @@ -10,6 +8,11 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#if defined(LOGGING) && !defined(KISSAT_QUIET) + // clang-format off const char * kissat_log_lit (kissat *, unsigned lit); @@ -461,4 +464,6 @@ ATTRIBUTE_FORMAT (5, 6); LOGLITS (SIZE_STACK (solver->clause), BEGIN_STACK (solver->clause), \ __VA_ARGS__) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/lucky.h b/src/sat/kissat/lucky.h index ef97c67dc..2e7538ba8 100644 --- a/src/sat/kissat/lucky.h +++ b/src/sat/kissat/lucky.h @@ -1,7 +1,12 @@ #ifndef _lucky_h_INCLUDED #define _lucky_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; int kissat_lucky (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/minimize.c b/src/sat/kissat/minimize.c index 94dcb63d5..6739d7c6b 100644 --- a/src/sat/kissat/minimize.c +++ b/src/sat/kissat/minimize.c @@ -1,17 +1,19 @@ #include "minimize.h" #include "inline.h" +ABC_NAMESPACE_IMPL_START + static inline int minimized_index (kissat *solver, bool minimizing, assigned *a, unsigned lit, unsigned idx, unsigned depth) { -#if !defined(LOGGING) && defined(NDEBUG) +#if !defined(LOGGING) && defined(KISSAT_NDEBUG) (void) lit; #endif -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) idx; #endif - assert (IDX (lit) == idx); - assert (solver->assigned + idx == a); + KISSAT_assert (IDX (lit) == idx); + KISSAT_assert (solver->assigned + idx == a); if (!a->level) { LOG2 ("skipping root level literal %s", LOGLIT (lit)); return 1; @@ -20,7 +22,7 @@ static inline int minimized_index (kissat *solver, bool minimizing, LOG2 ("skipping removable literal %s", LOGLIT (lit)); return 1; } - assert (a->reason != UNIT_REASON); + KISSAT_assert (a->reason != UNIT_REASON); if (a->reason == DECISION_REASON) { LOG2 ("can not remove decision literal %s", LOGLIT (lit)); return -1; @@ -81,7 +83,7 @@ static inline bool minimize_binary (kissat *solver, bool minimizing, } unsigned *begin = BEGIN_STACK (solver->minimize) + saved; const unsigned *const end = END_STACK (solver->minimize); - assert (begin <= end); + KISSAT_assert (begin <= end); if (res) for (const unsigned *p = begin; p != end; p++) kissat_push_removable (solver, assigned, *p); @@ -97,9 +99,9 @@ static bool minimize_literal (kissat *solver, bool minimizing, unsigned depth) { LOG ("trying to minimize literal %s at recursion depth %d", LOGLIT (lit), depth); - assert (VALUE (lit) < 0); - assert (depth || EMPTY_STACK (solver->minimize)); - assert (GET_OPTION (minimizedepth) > 0); + KISSAT_assert (VALUE (lit) < 0); + KISSAT_assert (depth || EMPTY_STACK (solver->minimize)); + KISSAT_assert (GET_OPTION (minimizedepth) > 0); if (depth >= (unsigned) GET_OPTION (minimizedepth)) return false; const unsigned idx = IDX (lit); @@ -135,7 +137,7 @@ static bool minimize_literal (kissat *solver, bool minimizing, bool kissat_minimize_literal (kissat *solver, unsigned lit, bool lit_in_clause) { - assert (EMPTY_STACK (solver->minimize)); + KISSAT_assert (EMPTY_STACK (solver->minimize)); return minimize_literal (solver, false, solver->assigned, lit, !lit_in_clause); } @@ -144,9 +146,9 @@ void kissat_reset_poisoned (kissat *solver) { LOG ("reset %zu poisoned variables", SIZE_STACK (solver->poisoned)); assigned *assigned = solver->assigned; for (all_stack (unsigned, idx, solver->poisoned)) { - assert (idx < VARS); + KISSAT_assert (idx < VARS); struct assigned *a = assigned + idx; - assert (a->poisoned); + KISSAT_assert (a->poisoned); a->poisoned = false; } CLEAR_STACK (solver->poisoned); @@ -155,19 +157,19 @@ void kissat_reset_poisoned (kissat *solver) { void kissat_minimize_clause (kissat *solver) { START (minimize); - assert (EMPTY_STACK (solver->minimize)); - assert (EMPTY_STACK (solver->removable)); - assert (EMPTY_STACK (solver->poisoned)); - assert (!EMPTY_STACK (solver->clause)); + KISSAT_assert (EMPTY_STACK (solver->minimize)); + KISSAT_assert (EMPTY_STACK (solver->removable)); + KISSAT_assert (EMPTY_STACK (solver->poisoned)); + KISSAT_assert (!EMPTY_STACK (solver->clause)); unsigned *lits = BEGIN_STACK (solver->clause); unsigned *end = END_STACK (solver->clause); assigned *assigned = solver->assigned; -#ifndef NDEBUG - assert (lits < end); +#ifndef KISSAT_NDEBUG + KISSAT_assert (lits < end); const unsigned not_uip = lits[0]; - assert (assigned[IDX (not_uip)].level == solver->level); + KISSAT_assert (assigned[IDX (not_uip)].level == solver->level); #endif for (const unsigned *p = lits; p != end; p++) kissat_push_removable (solver, assigned, IDX (*p)); @@ -181,7 +183,7 @@ void kissat_minimize_clause (kissat *solver) { for (unsigned *p = end; --p > lits;) { const unsigned lit = *p; - assert (lit != not_uip); + KISSAT_assert (lit != not_uip); if (minimize_literal (solver, true, assigned, lit, 0)) { LOG ("minimized literal %s", LOGLIT (lit)); *p = INVALID_LIT; @@ -196,11 +198,11 @@ void kissat_minimize_clause (kissat *solver) { if (lit != INVALID_LIT) *q++ = lit; } - assert (q + minimized == end); + KISSAT_assert (q + minimized == end); SET_END_OF_STACK (solver->clause, q); LOG ("clause minimization removed %u literals", minimized); - assert (!solver->probing); + KISSAT_assert (!solver->probing); ADD (literals_minimized, minimized); LOGTMP ("minimized learned"); @@ -209,3 +211,5 @@ void kissat_minimize_clause (kissat *solver) { STOP (minimize); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/minimize.h b/src/sat/kissat/minimize.h index ae06fb9ad..25d2f4d33 100644 --- a/src/sat/kissat/minimize.h +++ b/src/sat/kissat/minimize.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_reset_poisoned (struct kissat *); @@ -11,4 +14,6 @@ void kissat_minimize_clause (struct kissat *); bool kissat_minimize_literal (struct kissat *, unsigned, bool lit_in_clause); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/mode.c b/src/sat/kissat/mode.c index b1390eca1..e42027339 100644 --- a/src/sat/kissat/mode.c +++ b/src/sat/kissat/mode.c @@ -8,7 +8,9 @@ #include -#ifndef QUIET +ABC_NAMESPACE_IMPL_START + +#ifndef KISSAT_QUIET static const char *mode_string (kissat *solver) { return solver->stable ? "stable" : "focused"; @@ -20,12 +22,12 @@ void kissat_init_mode_limit (kissat *solver) { limits *limits = &solver->limits; if (GET_OPTION (stable) == 1) { - assert (!solver->stable); + KISSAT_assert (!solver->stable); const uint64_t conflicts_delta = GET_OPTION (modeinit); const uint64_t conflicts_limit = CONFLICTS + conflicts_delta; - assert (conflicts_limit); + KISSAT_assert (conflicts_limit); limits->mode.conflicts = conflicts_limit; limits->mode.ticks = 0; @@ -38,11 +40,11 @@ void kissat_init_mode_limit (kissat *solver) { FORMAT_COUNT (conflicts_limit), FORMAT_COUNT (conflicts_delta)); - solver->mode.ticks = solver->statistics.search_ticks; -#ifndef QUIET + solver->mode.ticks = solver->statistics_.search_ticks; +#ifndef KISSAT_QUIET solver->mode.conflicts = CONFLICTS; #ifdef METRICS - solver->mode.propagations = solver->statistics.search_propagations; + solver->mode.propagations = solver->statistics_.search_propagations; #endif // clang-format off solver->mode.entered = kissat_process_time (); @@ -70,14 +72,14 @@ static void update_mode_limit (kissat *solver, uint64_t delta_ticks) { kissat_init_averages (solver, &AVERAGES); limits *limits = &solver->limits; - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; - assert (GET_OPTION (stable) == 1); + KISSAT_assert (GET_OPTION (stable) == 1); if (limits->mode.count & 1) { limits->mode.ticks = statistics->search_ticks + delta_ticks; -#ifndef QUIET - assert (solver->stable); +#ifndef KISSAT_QUIET + KISSAT_assert (solver->stable); kissat_phase (solver, "stable", GET (stable_modes), "new stable mode switching limit of %s " "after %s ticks", @@ -85,13 +87,13 @@ static void update_mode_limit (kissat *solver, uint64_t delta_ticks) { FORMAT_COUNT (delta_ticks)); #endif } else { - assert (limits->mode.ticks); + KISSAT_assert (limits->mode.ticks); const uint64_t interval = GET_OPTION (modeint); const uint64_t count = (statistics->switched + 1) / 2; const uint64_t scaled = interval * kissat_nlogpown (count, 4); limits->mode.conflicts = statistics->conflicts + scaled; -#ifndef QUIET - assert (!solver->stable); +#ifndef KISSAT_QUIET + KISSAT_assert (!solver->stable); kissat_phase (solver, "focused", GET (focused_modes), "new focused mode switching limit of %s " "after %s conflicts", @@ -101,7 +103,7 @@ static void update_mode_limit (kissat *solver, uint64_t delta_ticks) { } solver->mode.ticks = statistics->search_ticks; -#ifndef QUIET +#ifndef KISSAT_QUIET solver->mode.conflicts = statistics->conflicts; #ifdef METRICS solver->mode.propagations = statistics->search_propagations; @@ -111,10 +113,10 @@ static void update_mode_limit (kissat *solver, uint64_t delta_ticks) { static void report_switching_from_mode (kissat *solver, uint64_t *delta_ticks) { - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; *delta_ticks = statistics->search_ticks - solver->mode.ticks; -#ifndef QUIET +#ifndef KISSAT_QUIET if (kissat_verbosity (solver) < 2) return; @@ -148,7 +150,7 @@ static void report_switching_from_mode (kissat *solver, } static void switch_to_focused_mode (kissat *solver) { - assert (solver->stable); + KISSAT_assert (solver->stable); uint64_t delta; report_switching_from_mode (solver, &delta); REPORT (0, ']'); @@ -166,7 +168,7 @@ static void switch_to_focused_mode (kissat *solver) { } static void switch_to_stable_mode (kissat *solver) { - assert (!solver->stable); + KISSAT_assert (!solver->stable); uint64_t delta; report_switching_from_mode (solver, &delta); REPORT (0, '}'); @@ -184,13 +186,13 @@ static void switch_to_stable_mode (kissat *solver) { } bool kissat_switching_search_mode (kissat *solver) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); if (GET_OPTION (stable) != 1) return false; limits *limits = &solver->limits; - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; if (limits->mode.count & 1) return statistics->search_ticks >= limits->mode.ticks; @@ -199,7 +201,7 @@ bool kissat_switching_search_mode (kissat *solver) { } void kissat_switch_search_mode (kissat *solver) { - assert (kissat_switching_search_mode (solver)); + KISSAT_assert (kissat_switching_search_mode (solver)); INC (switched); solver->limits.mode.count++; @@ -213,3 +215,5 @@ void kissat_switch_search_mode (kissat *solver) { kissat_start_random_sequence (solver); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/mode.h b/src/sat/kissat/mode.h index 915e746e4..0b658113c 100644 --- a/src/sat/kissat/mode.h +++ b/src/sat/kissat/mode.h @@ -1,13 +1,16 @@ #ifndef _mode_h_INCLUDED #define _mode_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; typedef struct mode mode; struct mode { uint64_t ticks; -#ifndef QUIET +#ifndef KISSAT_QUIET double entered; uint64_t conflicts; #ifdef METRICS @@ -21,4 +24,6 @@ void kissat_init_mode_limit (struct kissat *); bool kissat_switching_search_mode (struct kissat *); void kissat_switch_search_mode (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/module.make b/src/sat/kissat/module.make new file mode 100644 index 000000000..e6ca01394 --- /dev/null +++ b/src/sat/kissat/module.make @@ -0,0 +1,91 @@ +SRC += src/sat/kissat/kissatSolver.c \ +src/sat/kissat/kissatTest.c\ +src/sat/kissat/allocate.c \ +src/sat/kissat/analyze.c \ +src/sat/kissat/ands.c \ +src/sat/kissat/arena.c \ +src/sat/kissat/assign.c \ +src/sat/kissat/averages.c \ +src/sat/kissat/backbone.c \ +src/sat/kissat/backtrack.c \ +src/sat/kissat/build.c \ +src/sat/kissat/bump.c \ +src/sat/kissat/check.c \ +src/sat/kissat/classify.c \ +src/sat/kissat/clause.c \ +src/sat/kissat/collect.c \ +src/sat/kissat/colors.c \ +src/sat/kissat/compact.c \ +src/sat/kissat/config.c \ +src/sat/kissat/congruence.c \ +src/sat/kissat/decide.c \ +src/sat/kissat/deduce.c \ +src/sat/kissat/definition.c \ +src/sat/kissat/dense.c \ +src/sat/kissat/dump.c \ +src/sat/kissat/eliminate.c \ +src/sat/kissat/equivalences.c \ +src/sat/kissat/error.c \ +src/sat/kissat/extend.c \ +src/sat/kissat/factor.c \ +src/sat/kissat/fastel.c \ +src/sat/kissat/file.c \ +src/sat/kissat/flags.c \ +src/sat/kissat/format.c \ +src/sat/kissat/forward.c \ +src/sat/kissat/gates.c \ +src/sat/kissat/heap.c \ +src/sat/kissat/ifthenelse.c \ +src/sat/kissat/import.c \ +src/sat/kissat/internal.c \ +src/sat/kissat/kimits.c \ +src/sat/kissat/kitten.c \ +src/sat/kissat/krite.c \ +src/sat/kissat/learn.c \ +src/sat/kissat/logging.c \ +src/sat/kissat/kucky.c \ +src/sat/kissat/minimize.c \ +src/sat/kissat/mode.c \ +src/sat/kissat/kptions.c \ +src/sat/kissat/phases.c \ +src/sat/kissat/preprocess.c \ +src/sat/kissat/print.c \ +src/sat/kissat/probe.c \ +src/sat/kissat/profile.c \ +src/sat/kissat/promote.c \ +src/sat/kissat/proof.c \ +src/sat/kissat/propbeyond.c \ +src/sat/kissat/propdense.c \ +src/sat/kissat/propinitially.c \ +src/sat/kissat/proprobe.c \ +src/sat/kissat/propsearch.c \ +src/sat/kissat/queue.c \ +src/sat/kissat/reduce.c \ +src/sat/kissat/reluctant.c \ +src/sat/kissat/reorder.c \ +src/sat/kissat/rephase.c \ +src/sat/kissat/report.c \ +src/sat/kissat/resize.c \ +src/sat/kissat/resolve.c \ +src/sat/kissat/resources.c \ +src/sat/kissat/restart.c \ +src/sat/kissat/search.c \ +src/sat/kissat/shrink.c \ +src/sat/kissat/smooth.c \ +src/sat/kissat/sort.c \ +src/sat/kissat/stack.c \ +src/sat/kissat/statistics.c \ +src/sat/kissat/strengthen.c \ +src/sat/kissat/substitute.c \ +src/sat/kissat/sweep.c \ +src/sat/kissat/terminate.c \ +src/sat/kissat/tiers.c \ +src/sat/kissat/trail.c \ +src/sat/kissat/transitive.c \ +src/sat/kissat/utilities.c \ +src/sat/kissat/vector.c \ +src/sat/kissat/vivify.c \ +src/sat/kissat/walk.c \ +src/sat/kissat/warmup.c \ +src/sat/kissat/watch.c \ +src/sat/kissat/weaken.c \ diff --git a/src/sat/kissat/options.h b/src/sat/kissat/options.h index 26cd6f066..3746014bd 100644 --- a/src/sat/kissat/options.h +++ b/src/sat/kissat/options.h @@ -4,6 +4,9 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + // clang-format off #define OPTIONS \ @@ -191,19 +194,19 @@ #define STABLE_DEFAULT STABLE_UNSAT #endif -#if defined(LOGGING) && !defined(QUIET) +#if defined(LOGGING) && !defined(KISSAT_QUIET) #define LOGOPT OPTION #else #define LOGOPT(...) /**/ #endif -#ifndef QUIET +#ifndef KISSAT_QUIET #define NQTOPT OPTION #else #define NQTOPT(...) /**/ #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG #define DBGOPT OPTION #else #define DBGOPT(...) /**/ @@ -224,7 +227,7 @@ typedef struct opt opt; struct opt { const char *name; -#ifndef NOPTIONS +#ifndef KISSAT_NOPTIONS int value; const int low; const int high; @@ -245,7 +248,7 @@ extern const opt *kissat_options_end; const char *kissat_parse_option_name (const char *arg, const char *name); bool kissat_parse_option_value (const char *val_str, int *res_ptr); -#ifndef NOPTIONS +#ifndef KISSAT_NOPTIONS void kissat_options_usage (void); @@ -277,8 +280,8 @@ static inline int *kissat_options_ref (const options *options, const opt *o) { if (!o) return 0; - assert (kissat_options_begin <= o); - assert (o < kissat_options_end); + KISSAT_assert (kissat_options_begin <= o); + KISSAT_assert (o < kissat_options_end); return (int *) options + (o - kissat_options_begin); } @@ -296,4 +299,6 @@ OPTIONS #undef OPTION #endif #define GET1K_OPTION(NAME) (((int64_t) 1000) * GET_OPTION (NAME)) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/parse.h b/src/sat/kissat/parse.h index 665371259..709464648 100644 --- a/src/sat/kissat/parse.h +++ b/src/sat/kissat/parse.h @@ -3,6 +3,9 @@ #include "file.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + enum strictness { RELAXED_PARSING = 0, NORMAL_PARSING = 1, @@ -16,4 +19,6 @@ struct kissat; const char *kissat_parse_dimacs (struct kissat *, strictness, file *, uint64_t *linenoptr, int *max_var_ptr); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/phases.c b/src/sat/kissat/phases.c index 5fb84c20d..ac1ea70df 100644 --- a/src/sat/kissat/phases.c +++ b/src/sat/kissat/phases.c @@ -4,22 +4,24 @@ #include +ABC_NAMESPACE_IMPL_START + #define realloc_phases(NAME) \ do { \ solver->phases.NAME = \ - kissat_realloc (solver, solver->phases.NAME, old_size, new_size); \ + (value*) kissat_realloc (solver, solver->phases.NAME, old_size, new_size); \ } while (0) #define increase_phases(NAME) \ do { \ - assert (old_size < new_size); \ + KISSAT_assert (old_size < new_size); \ realloc_phases (NAME); \ memset (solver->phases.NAME + old_size, 0, new_size - old_size); \ } while (0) void kissat_increase_phases (kissat *solver, unsigned new_size) { const unsigned old_size = solver->size; - assert (old_size < new_size); + KISSAT_assert (old_size < new_size); LOG ("increasing phases from %u to %u", old_size, new_size); increase_phases (best); increase_phases (saved); @@ -28,7 +30,7 @@ void kissat_increase_phases (kissat *solver, unsigned new_size) { void kissat_decrease_phases (kissat *solver, unsigned new_size) { const unsigned old_size = solver->size; - assert (old_size > new_size); + KISSAT_assert (old_size > new_size); LOG ("decreasing phases from %u to %u", old_size, new_size); realloc_phases (best); realloc_phases (saved); @@ -52,17 +54,19 @@ static void save_phases (kissat *solver, value *phases) { for (value *p = phases, tmp; p != end; p++, v += 2) if ((tmp = *v)) *p = tmp; - assert (v == values + LITS); + KISSAT_assert (v == values + LITS); } void kissat_save_best_phases (kissat *solver) { - assert (sizeof (value) == 1); + KISSAT_assert (sizeof (value) == 1); LOG ("saving %u best values", VARS); save_phases (solver, solver->phases.best); } void kissat_save_target_phases (kissat *solver) { - assert (sizeof (value) == 1); + KISSAT_assert (sizeof (value) == 1); LOG ("saving %u target values", VARS); save_phases (solver, solver->phases.target); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/phases.h b/src/sat/kissat/phases.h index 4a2456fec..7f852b4e0 100644 --- a/src/sat/kissat/phases.h +++ b/src/sat/kissat/phases.h @@ -3,6 +3,9 @@ #include "value.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct phases phases; struct phases { @@ -12,13 +15,13 @@ struct phases { }; #define BEST(IDX) \ - (solver->phases.best[assert (VALID_INTERNAL_INDEX (IDX)), (IDX)]) + (solver->phases.best[KISSAT_assert (VALID_INTERNAL_INDEX (IDX)), (IDX)]) #define SAVED(IDX) \ - (solver->phases.saved[assert (VALID_INTERNAL_INDEX (IDX)), (IDX)]) + (solver->phases.saved[KISSAT_assert (VALID_INTERNAL_INDEX (IDX)), (IDX)]) #define TARGET(IDX) \ - (solver->phases.target[assert (VALID_INTERNAL_INDEX (IDX)), (IDX)]) + (solver->phases.target[KISSAT_assert (VALID_INTERNAL_INDEX (IDX)), (IDX)]) struct kissat; @@ -29,4 +32,6 @@ void kissat_release_phases (struct kissat *); void kissat_save_best_phases (struct kissat *); void kissat_save_target_phases (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/preprocess.c b/src/sat/kissat/preprocess.c index 96a0beee0..875b8f49a 100644 --- a/src/sat/kissat/preprocess.c +++ b/src/sat/kissat/preprocess.c @@ -11,33 +11,35 @@ #include +ABC_NAMESPACE_IMPL_START + bool kissat_preprocessing (struct kissat *solver) { - assert (!solver->level); - assert (!solver->inconsistent); + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->inconsistent); if (!GET_OPTION (preprocess)) return false; if (!GET_OPTION (probe)) return false; if (!GET_OPTION (preprocessprobe)) return false; -#if defined(NDEBUG) && defined(NOPTIONS) +#if defined(KISSAT_NDEBUG) && defined(KISSAT_NOPTIONS) (void) solver; #endif return true; } int kissat_preprocess (struct kissat *solver) { - assert (kissat_preprocessing (solver)); + KISSAT_assert (kissat_preprocessing (solver)); if (!kissat_initially_propagate (solver)) { - assert (solver->inconsistent); + KISSAT_assert (solver->inconsistent); return 20; } START (preprocess); - assert (!solver->preprocessing); + KISSAT_assert (!solver->preprocessing); solver->preprocessing = true; REPORT (0, '('); const unsigned max_rounds = GET_OPTION (preprocessrounds); -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned variables_initially = solver->active; const uint64_t clauses_initially = BINIRR_CLAUSES; const unsigned variables_originally = SIZE_STACK (solver->import); @@ -63,7 +65,7 @@ int kissat_preprocess (struct kissat *solver) { break; const unsigned variables_before = solver->active; const uint64_t clauses_before = BINIRR_CLAUSES; -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_verbose (solver, "[preprocess-%u] started preprocessing round %u", round, round); @@ -74,7 +76,7 @@ int kissat_preprocess (struct kissat *solver) { kissat_fast_variable_elimination (solver); const unsigned variables_after = solver->active; const uint64_t clauses_after = BINIRR_CLAUSES; -#ifndef QUIET +#ifndef KISSAT_QUIET if (variables_after < variables_before) { unsigned removed = variables_before - variables_after; kissat_verbose ( @@ -119,7 +121,7 @@ int kissat_preprocess (struct kissat *solver) { break; round++; } -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned variables_finally = solver->active; const uint64_t clauses_finally = BINIRR_CLAUSES; kissat_verbose (solver, "[preprocess] finished after %u rounds", round); @@ -171,8 +173,10 @@ int kissat_preprocess (struct kissat *solver) { kissat_percent (clauses_finally, clauses_originally)); #endif REPORT (0, ')'); - assert (solver->preprocessing); + KISSAT_assert (solver->preprocessing); solver->preprocessing = false; STOP (preprocess); return solver->inconsistent ? 20 : 0; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/preprocess.h b/src/sat/kissat/preprocess.h index 056b5ecde..7826a656e 100644 --- a/src/sat/kissat/preprocess.h +++ b/src/sat/kissat/preprocess.h @@ -3,8 +3,13 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_preprocessing (struct kissat *); int kissat_preprocess (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/print.c b/src/sat/kissat/print.c index 454b8f343..3d50141fd 100644 --- a/src/sat/kissat/print.c +++ b/src/sat/kissat/print.c @@ -1,4 +1,6 @@ -#ifndef QUIET +#include "global.h" + +#ifndef KISSAT_QUIET #include "print.h" #include "colors.h" @@ -16,7 +18,7 @@ static inline int verbosity (kissat *solver) { if (GET_OPTION (log)) return 3; #endif -#ifndef QUIET +#ifndef KISSAT_QUIET if (GET_OPTION (quiet)) return -1; return GET_OPTION (verbose); @@ -39,7 +41,7 @@ void kissat_warning (kissat *solver, const char *fmt, ...) { vprintf (fmt, ap); va_end (ap); fputc ('\n', stdout); -#ifdef NOPTIONS +#ifdef KISSAT_NOPTIONS (void) solver; #endif } diff --git a/src/sat/kissat/print.h b/src/sat/kissat/print.h index d6f8a329f..941e94c50 100644 --- a/src/sat/kissat/print.h +++ b/src/sat/kissat/print.h @@ -3,12 +3,15 @@ #ifndef _print_h_INCLUDED #define _print_h_INCLUDED -#ifndef QUIET - #include #include "attribute.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#ifndef KISSAT_QUIET + struct kissat; int kissat_verbosity (struct kissat *); @@ -60,6 +63,8 @@ do { \ kissat_very_verbose (SOLVER, __VA_ARGS__); \ } while (0) +ABC_NAMESPACE_HEADER_END + #endif // clang-format on diff --git a/src/sat/kissat/probe.c b/src/sat/kissat/probe.c index 606710577..f77ba6619 100644 --- a/src/sat/kissat/probe.c +++ b/src/sat/kissat/probe.c @@ -13,10 +13,12 @@ #include +ABC_NAMESPACE_IMPL_START + bool kissat_probing (kissat *solver) { if (!solver->enabled.probe) return false; - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; const uint64_t conflicts = statistics->conflicts; if (solver->last.conflicts.reduce == conflicts) return false; @@ -25,7 +27,7 @@ bool kissat_probing (kissat *solver) { static void probe (kissat *solver) { kissat_backtrack_propagate_and_flush_trail (solver); - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); STOP_SEARCH_AND_START_SIMPLIFIER (probe); kissat_phase (solver, "probe", GET (probings), "probing limit hit after %" PRIu64 " conflicts", @@ -43,8 +45,8 @@ static void probe (kissat *solver) { } static void probe_initially (kissat *solver) { - assert (!solver->level); - assert (!solver->inconsistent); + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->inconsistent); kissat_phase (solver, "probe", GET (probings), "initial probing"); bool substitute_at_the_end = true; if (GET_OPTION (preprocesscongruence)) { @@ -68,9 +70,9 @@ static void probe_initially (kissat *solver) { } int kissat_probe (kissat *solver) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); INC (probings); - assert (!solver->probing); + KISSAT_assert (!solver->probing); solver->probing = true; const unsigned max_rounds = GET_OPTION (proberounds); for (unsigned round = 0; round != max_rounds; round++) { @@ -83,22 +85,24 @@ int kissat_probe (kissat *solver) { } kissat_classify (solver); UPDATE_CONFLICT_LIMIT (probe, probings, NLOGN, true); - solver->last.ticks.probe = solver->statistics.search_ticks; - assert (solver->probing); + solver->last.ticks.probe = solver->statistics_.search_ticks; + KISSAT_assert (solver->probing); solver->probing = false; return solver->inconsistent ? 20 : 0; } int kissat_probe_initially (kissat *solver) { - assert (!solver->level); - assert (!solver->inconsistent); + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->inconsistent); INC (probings); START (probe); - assert (!solver->probing); + KISSAT_assert (!solver->probing); solver->probing = true; probe_initially (solver); - assert (solver->probing); + KISSAT_assert (solver->probing); solver->probing = false; STOP (probe); return solver->inconsistent ? 20 : 0; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/probe.h b/src/sat/kissat/probe.h index a788918f3..8226325fb 100644 --- a/src/sat/kissat/probe.h +++ b/src/sat/kissat/probe.h @@ -3,10 +3,15 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_probing (struct kissat *); int kissat_probe (struct kissat *); int kissat_probe_initially (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/profile.c b/src/sat/kissat/profile.c index 01cd65573..d301e8cbb 100644 --- a/src/sat/kissat/profile.c +++ b/src/sat/kissat/profile.c @@ -1,4 +1,6 @@ -#ifndef QUIET +#include "global.h" + +#ifndef KISSAT_QUIET #include "internal.h" #include "resources.h" @@ -73,7 +75,7 @@ void kissat_start (kissat *solver, profile *profile) { } void kissat_stop (kissat *solver, profile *profile) { - assert (TOP_STACK (solver->profiles.stack) == profile); + KISSAT_assert (TOP_STACK (solver->profiles.stack) == profile); (void) POP_STACK (solver->profiles.stack); const double now = kissat_process_time (); flush_profile (profile, now); @@ -82,23 +84,23 @@ void kissat_stop (kissat *solver, profile *profile) { void kissat_stop_search_and_start_simplifier (kissat *solver, profile *profile) { struct profile *search = &PROFILE (search); - assert (search->level <= GET_OPTION (profile)); + KISSAT_assert (search->level <= GET_OPTION (profile)); const double now = kissat_process_time (); while (TOP_STACK (solver->profiles.stack) != search) { struct profile *mode = POP_STACK (solver->profiles.stack); - assert (search->level <= mode->level); -#ifndef NDEBUG + KISSAT_assert (search->level <= mode->level); +#ifndef KISSAT_NDEBUG if (solver->stable) - assert (mode == &PROFILE (stable)); + KISSAT_assert (mode == &PROFILE (stable)); else - assert (mode == &PROFILE (focused)); + KISSAT_assert (mode == &PROFILE (focused)); #endif flush_profile (mode, now); } (void) POP_STACK (solver->profiles.stack); struct profile *simplify = &PROFILE (simplify); - assert (search->level == simplify->level); - assert (simplify->level <= profile->level); + KISSAT_assert (search->level == simplify->level); + KISSAT_assert (simplify->level <= profile->level); flush_profile (search, now); push_profile (solver, simplify, now); if (profile->level <= GET_OPTION (profile)) @@ -111,28 +113,28 @@ void kissat_stop_simplifier_and_resume_search (kissat *solver, struct profile *top = POP_STACK (solver->profiles.stack); const double now = kissat_process_time (); const double delta = flush_profile (simplify, now); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG const double entered = now - delta; - assert (solver->mode.entered <= entered); + KISSAT_assert (solver->mode.entered <= entered); #endif solver->mode.entered += delta; if (top == profile) { flush_profile (profile, now); - assert (TOP_STACK (solver->profiles.stack) == simplify); + KISSAT_assert (TOP_STACK (solver->profiles.stack) == simplify); (void) POP_STACK (solver->profiles.stack); } else { - assert (simplify == top); - assert (profile->level > GET_OPTION (profile)); + KISSAT_assert (simplify == top); + KISSAT_assert (profile->level > GET_OPTION (profile)); } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG struct profile *search = &PROFILE (search); - assert (search->level == simplify->level); + KISSAT_assert (search->level == simplify->level); #endif - assert (simplify->level <= profile->level); + KISSAT_assert (simplify->level <= profile->level); push_profile (solver, &PROFILE (search), now); struct profile *mode = solver->stable ? &PROFILE (stable) : &PROFILE (focused); - assert (search->level <= mode->level); + KISSAT_assert (search->level <= mode->level); if (mode->level <= GET_OPTION (profile)) push_profile (solver, mode, now); } diff --git a/src/sat/kissat/profile.h b/src/sat/kissat/profile.h index 62d03cf71..155724f26 100644 --- a/src/sat/kissat/profile.h +++ b/src/sat/kissat/profile.h @@ -1,10 +1,13 @@ #ifndef _profile_h_INCLUDED #define _profile_h_INCLUDED -#ifndef QUIET - #include "stack.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#ifndef KISSAT_QUIET + typedef struct profile profile; typedef struct profiles profiles; @@ -140,4 +143,6 @@ double kissat_time (struct kissat *); #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/promote.c b/src/sat/kissat/promote.c index 152cfed4c..19d519596 100644 --- a/src/sat/kissat/promote.c +++ b/src/sat/kissat/promote.c @@ -2,35 +2,37 @@ #include "internal.h" #include "logging.h" +ABC_NAMESPACE_IMPL_START + void kissat_promote_clause (kissat *solver, clause *c, unsigned new_glue) { if (!GET_OPTION (promote)) return; - assert (c->redundant); + KISSAT_assert (c->redundant); const unsigned old_glue = c->glue; - assert (new_glue < old_glue); + KISSAT_assert (new_glue < old_glue); const unsigned tier1 = TIER1; const unsigned tier2 = MAX (TIER2, TIER1); if (old_glue <= tier1) { LOGCLS (c, "keeping with new glue %u in tier1", new_glue); INC (clauses_kept1); } else if (new_glue <= tier1) { - assert (tier1 < old_glue); - assert (new_glue <= tier1); + KISSAT_assert (tier1 < old_glue); + KISSAT_assert (new_glue <= tier1); LOGCLS (c, "promoting with new glue %u to tier1", new_glue); INC (clauses_promoted1); } else if (tier2 < old_glue && new_glue <= tier2) { - assert (tier2 < old_glue); - assert (tier1 < new_glue), assert (new_glue <= tier2); + KISSAT_assert (tier2 < old_glue); + KISSAT_assert (tier1 < new_glue), KISSAT_assert (new_glue <= tier2); LOGCLS (c, "promoting with new glue %u to tier2", new_glue); INC (clauses_promoted2); } else if (old_glue <= tier2) { - assert (tier1 < old_glue), assert (old_glue <= tier2); - assert (tier1 < new_glue), assert (new_glue <= tier2); + KISSAT_assert (tier1 < old_glue), KISSAT_assert (old_glue <= tier2); + KISSAT_assert (tier1 < new_glue), KISSAT_assert (new_glue <= tier2); LOGCLS (c, "keeping with new glue %u in tier2", new_glue); INC (clauses_kept2); } else { - assert (tier2 < old_glue); - assert (tier2 < new_glue); + KISSAT_assert (tier2 < old_glue); + KISSAT_assert (tier2 < new_glue); LOGCLS (c, "keeping with new glue %u in tier3", new_glue); INC (clauses_kept3); } @@ -40,3 +42,5 @@ void kissat_promote_clause (kissat *solver, clause *c, unsigned new_glue) { (void) solver; #endif } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/promote.h b/src/sat/kissat/promote.h index 3a6073cf6..0d96577bf 100644 --- a/src/sat/kissat/promote.h +++ b/src/sat/kissat/promote.h @@ -3,15 +3,18 @@ #include "internal.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + void kissat_promote_clause (struct kissat *, clause *, unsigned new_glue); static inline unsigned kissat_recompute_glue (kissat *solver, clause *c, unsigned limit) { - assert (limit); - assert (EMPTY_STACK (solver->promote)); + KISSAT_assert (limit); + KISSAT_assert (EMPTY_STACK (solver->promote)); unsigned res = 0; for (all_literals_in_clause (lit, c)) { - assert (VALUE (lit)); + KISSAT_assert (VALUE (lit)); const unsigned level = LEVEL (lit); frame *frame = &FRAME (level); if (frame->promote) @@ -23,11 +26,13 @@ static inline unsigned kissat_recompute_glue (kissat *solver, clause *c, } for (all_stack (unsigned, level, solver->promote)) { frame *frame = &FRAME (level); - assert (frame->promote); + KISSAT_assert (frame->promote); frame->promote = false; } CLEAR_STACK (solver->promote); return res; } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/proof.c b/src/sat/kissat/proof.c index 5c819906b..769655de8 100644 --- a/src/sat/kissat/proof.c +++ b/src/sat/kissat/proof.c @@ -1,13 +1,15 @@ -#ifndef NPROOFS +#include "global.h" + +#ifndef KISSAT_NPROOFS #include "allocate.h" #include "error.h" #include "file.h" #include "inline.h" -#undef NDEBUG +#undef KISSAT_NDEBUG -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG #include #endif @@ -30,12 +32,12 @@ struct proof { uint64_t deleted; uint64_t lines; uint64_t literals; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG bool empty; char *units; size_t size_units; #endif -#if !defined(NDEBUG) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || defined(LOGGING) unsigneds imported; #endif }; @@ -52,8 +54,8 @@ struct proof { __VA_ARGS__) void kissat_init_proof (kissat *solver, file *file, bool binary) { - assert (file); - assert (!solver->proof); + KISSAT_assert (file); + KISSAT_assert (!solver->proof); proof *proof = kissat_calloc (solver, 1, sizeof (struct proof)); proof->binary = binary; proof->file = file; @@ -74,22 +76,22 @@ static void flush_buffer (proof *proof) { void kissat_release_proof (kissat *solver) { proof *proof = solver->proof; - assert (proof); + KISSAT_assert (proof); LOG ("stopping to trace proof"); flush_buffer (proof); kissat_flush (proof->file); RELEASE_STACK (proof->line); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG kissat_free (solver, proof->units, proof->size_units); #endif -#if !defined(NDEBUG) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || defined(LOGGING) RELEASE_STACK (proof->imported); #endif kissat_free (solver, proof, sizeof (struct proof)); solver->proof = 0; } -#ifndef QUIET +#ifndef KISSAT_QUIET #include @@ -138,27 +140,27 @@ static inline void import_internal_proof_literal (kissat *solver, proof *proof, unsigned ilit) { int elit = kissat_export_literal (solver, ilit); - assert (elit); + KISSAT_assert (elit); PUSH_STACK (proof->line, elit); proof->literals++; -#if !defined(NDEBUG) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || defined(LOGGING) PUSH_STACK (proof->imported, ilit); #endif } static inline void import_external_proof_literal (kissat *solver, proof *proof, int elit) { - assert (elit); + KISSAT_assert (elit); PUSH_STACK (proof->line, elit); proof->literals++; -#ifndef NDEBUG - assert (EMPTY_STACK (proof->imported)); +#ifndef KISSAT_NDEBUG + KISSAT_assert (EMPTY_STACK (proof->imported)); #endif } static void import_internal_proof_binary (kissat *solver, proof *proof, unsigned a, unsigned b) { - assert (EMPTY_STACK (proof->line)); + KISSAT_assert (EMPTY_STACK (proof->line)); import_internal_proof_literal (solver, proof, a); import_internal_proof_literal (solver, proof, b); } @@ -166,16 +168,16 @@ static void import_internal_proof_binary (kissat *solver, proof *proof, static void import_internal_proof_literals (kissat *solver, proof *proof, size_t size, const unsigned *ilits) { - assert (EMPTY_STACK (proof->line)); - assert (size <= UINT_MAX); + KISSAT_assert (EMPTY_STACK (proof->line)); + KISSAT_assert (size <= UINT_MAX); for (size_t i = 0; i < size; i++) import_internal_proof_literal (solver, proof, ilits[i]); } static void import_external_proof_literals (kissat *solver, proof *proof, size_t size, const int *elits) { - assert (EMPTY_STACK (proof->line)); - assert (size <= UINT_MAX); + KISSAT_assert (EMPTY_STACK (proof->line)); + KISSAT_assert (size <= UINT_MAX); for (size_t i = 0; i < size; i++) import_external_proof_literal (solver, proof, elits[i]); } @@ -186,7 +188,7 @@ static void import_proof_clause (kissat *solver, proof *proof, } static void print_binary_proof_line (proof *proof) { - assert (proof->binary); + KISSAT_assert (proof->binary); for (all_stack (int, elit, proof->line)) { unsigned x = 2u * ABS (elit) + (elit < 0); unsigned char ch; @@ -201,15 +203,15 @@ static void print_binary_proof_line (proof *proof) { } static void print_non_binary_proof_line (proof *proof) { - assert (!proof->binary); + KISSAT_assert (!proof->binary); char buffer[16]; char *end_of_buffer = buffer + sizeof buffer; *--end_of_buffer = 0; for (all_stack (int, elit, proof->line)) { char *p = end_of_buffer; - assert (!*p); - assert (elit); - assert (elit != INT_MIN); + KISSAT_assert (!*p); + KISSAT_assert (elit); + KISSAT_assert (elit != INT_MIN); unsigned eidx; if (elit < 0) { write_char (proof, '-'); @@ -233,10 +235,10 @@ static void print_proof_line (proof *proof) { else print_non_binary_proof_line (proof); CLEAR_STACK (proof->line); -#if !defined(NDEBUG) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || defined(LOGGING) CLEAR_STACK (proof->imported); #endif -#ifndef NOPTIONS +#ifndef KISSAT_NOPTIONS kissat *solver = proof->solver; #endif if (GET_OPTION (flushproof)) { @@ -245,11 +247,11 @@ static void print_proof_line (proof *proof) { } } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG static unsigned external_to_proof_literal (int elit) { - assert (elit); - assert (elit != INT_MIN); + KISSAT_assert (elit); + KISSAT_assert (elit != INT_MIN); return 2u * (abs (elit) - 1) + (elit < 0); } @@ -270,12 +272,12 @@ static void resize_proof_units (proof *proof, unsigned plit) { static void check_repeated_proof_lines (proof *proof) { size_t size = SIZE_STACK (proof->line); if (!size) { - assert (!proof->empty); + KISSAT_assert (!proof->empty); proof->empty = true; } else if (size == 1) { const int eunit = PEEK_STACK (proof->line, 0); const unsigned punit = external_to_proof_literal (eunit); - assert (punit != INVALID_LIT); + KISSAT_assert (punit != INVALID_LIT); if (!proof->size_units || proof->size_units <= punit) resize_proof_units (proof, punit); proof->units[punit] = 1; @@ -288,11 +290,11 @@ static void print_added_proof_line (proof *proof) { proof->added++; #ifdef LOGGING struct kissat *solver = proof->solver; - assert (SIZE_STACK (proof->imported) == SIZE_STACK (proof->line)); + KISSAT_assert (SIZE_STACK (proof->imported) == SIZE_STACK (proof->line)); LOGIMPORTED3 ("added proof line"); LOGLINE3 ("added proof line"); #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG check_repeated_proof_lines (proof); #endif if (proof->binary) @@ -316,37 +318,37 @@ static void print_delete_proof_line (proof *proof) { void kissat_add_binary_to_proof (kissat *solver, unsigned a, unsigned b) { proof *proof = solver->proof; - assert (proof); + KISSAT_assert (proof); import_internal_proof_binary (solver, proof, a, b); print_added_proof_line (proof); } void kissat_add_clause_to_proof (kissat *solver, const clause *c) { proof *proof = solver->proof; - assert (proof); + KISSAT_assert (proof); import_proof_clause (solver, proof, c); print_added_proof_line (proof); } void kissat_add_empty_to_proof (kissat *solver) { proof *proof = solver->proof; - assert (proof); - assert (EMPTY_STACK (proof->line)); + KISSAT_assert (proof); + KISSAT_assert (EMPTY_STACK (proof->line)); print_added_proof_line (proof); } void kissat_add_lits_to_proof (kissat *solver, size_t size, const unsigned *ilits) { proof *proof = solver->proof; - assert (proof); + KISSAT_assert (proof); import_internal_proof_literals (solver, proof, size, ilits); print_added_proof_line (proof); } void kissat_add_unit_to_proof (kissat *solver, unsigned ilit) { proof *proof = solver->proof; - assert (proof); - assert (EMPTY_STACK (proof->line)); + KISSAT_assert (proof); + KISSAT_assert (EMPTY_STACK (proof->line)); import_internal_proof_literal (solver, proof, ilit); print_added_proof_line (proof); } @@ -355,7 +357,7 @@ void kissat_shrink_clause_in_proof (kissat *solver, const clause *c, unsigned remove, unsigned keep) { proof *proof = solver->proof; const value *const values = solver->values; - assert (EMPTY_STACK (proof->line)); + KISSAT_assert (EMPTY_STACK (proof->line)); const unsigned *ilits = c->lits; const unsigned size = c->size; for (unsigned i = 0; i != size; i++) { @@ -374,14 +376,14 @@ void kissat_shrink_clause_in_proof (kissat *solver, const clause *c, void kissat_delete_binary_from_proof (kissat *solver, unsigned a, unsigned b) { proof *proof = solver->proof; - assert (proof); + KISSAT_assert (proof); import_internal_proof_binary (solver, proof, a, b); print_delete_proof_line (proof); } void kissat_delete_clause_from_proof (kissat *solver, const clause *c) { proof *proof = solver->proof; - assert (proof); + KISSAT_assert (proof); import_proof_clause (solver, proof, c); print_delete_proof_line (proof); } @@ -389,7 +391,7 @@ void kissat_delete_clause_from_proof (kissat *solver, const clause *c) { void kissat_delete_external_from_proof (kissat *solver, size_t size, const int *elits) { proof *proof = solver->proof; - assert (proof); + KISSAT_assert (proof); LOGINTS3 (size, elits, "explicitly deleted"); import_external_proof_literals (solver, proof, size, elits); print_delete_proof_line (proof); @@ -398,7 +400,7 @@ void kissat_delete_external_from_proof (kissat *solver, size_t size, void kissat_delete_internal_from_proof (kissat *solver, size_t size, const unsigned *ilits) { proof *proof = solver->proof; - assert (proof); + KISSAT_assert (proof); import_internal_proof_literals (solver, proof, size, ilits); print_delete_proof_line (proof); } diff --git a/src/sat/kissat/proof.h b/src/sat/kissat/proof.h index a87e60de5..d22fedb17 100644 --- a/src/sat/kissat/proof.h +++ b/src/sat/kissat/proof.h @@ -1,11 +1,14 @@ #ifndef _proof_h_INCLUDED #define _proof_h_INCLUDED -#ifndef NPROOFS - #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#ifndef KISSAT_NPROOFS + typedef struct proof proof; struct clause; @@ -14,7 +17,7 @@ struct file; void kissat_init_proof (struct kissat *, struct file *, bool binary); void kissat_release_proof (struct kissat *); -#ifndef QUIET +#ifndef KISSAT_QUIET void kissat_print_proof_statistics (struct kissat *, bool verbose); #endif @@ -161,4 +164,6 @@ void kissat_delete_internal_from_proof (struct kissat *, size_t, #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/propbeyond.c b/src/sat/kissat/propbeyond.c index b42192b05..8ffeb0432 100644 --- a/src/sat/kissat/propbeyond.c +++ b/src/sat/kissat/propbeyond.c @@ -2,6 +2,8 @@ #include "fastassign.h" #include "trail.h" +ABC_NAMESPACE_IMPL_START + #define PROPAGATE_LITERAL propagate_literal_beyond_conflicts #define CONTINUE_PROPAGATING_AFTER_CONFLICT #define PROPAGATION_TYPE "beyond conflict" @@ -11,7 +13,7 @@ static inline void update_beyond_propagation_statistics (kissat *solver, const unsigned *saved_propagate) { - assert (saved_propagate <= solver->propagate); + KISSAT_assert (saved_propagate <= solver->propagate); const unsigned propagated = solver->propagate - saved_propagate; LOG ("propagated %u literals", propagated); @@ -32,10 +34,10 @@ static void propagate_literals_beyond_conflicts (kissat *solver) { } void kissat_propagate_beyond_conflicts (kissat *solver) { - assert (!solver->probing); - assert (solver->watching); - assert (solver->warming); - assert (!solver->inconsistent); + KISSAT_assert (!solver->probing); + KISSAT_assert (solver->watching); + KISSAT_assert (solver->warming); + KISSAT_assert (!solver->inconsistent); START (propagate); @@ -46,3 +48,5 @@ void kissat_propagate_beyond_conflicts (kissat *solver) { STOP (propagate); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/propbeyond.h b/src/sat/kissat/propbeyond.h index 09eaf1b4e..85d78d75d 100644 --- a/src/sat/kissat/propbeyond.h +++ b/src/sat/kissat/propbeyond.h @@ -1,9 +1,14 @@ #ifndef _propall_h_INCLUDED #define _propall_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; struct clause; void kissat_propagate_beyond_conflicts (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/propdense.c b/src/sat/kissat/propdense.c index 48ccecb4f..18bbb49d6 100644 --- a/src/sat/kissat/propdense.c +++ b/src/sat/kissat/propdense.c @@ -1,11 +1,13 @@ #include "propdense.h" #include "fastassign.h" +ABC_NAMESPACE_IMPL_START + static inline bool non_watching_propagate_literal (kissat *solver, unsigned lit) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); LOG ("propagating %s", LOGLIT (lit)); - assert (VALUE (lit) > 0); + KISSAT_assert (VALUE (lit) > 0); const unsigned not_lit = NOT (lit); watches *watches = &WATCHES (not_lit); @@ -20,7 +22,7 @@ static inline bool non_watching_propagate_literal (kissat *solver, for (all_binary_large_watches (watch, *watches)) { if (watch.type.binary) { const unsigned other = watch.binary.lit; - assert (VALID_INTERNAL_LITERAL (other)); + KISSAT_assert (VALID_INTERNAL_LITERAL (other)); const value other_value = values[other]; if (other_value > 0) continue; @@ -31,15 +33,15 @@ static inline bool non_watching_propagate_literal (kissat *solver, const unsigned other_idx = IDX (other); if (flags[other_idx].eliminated) continue; - assert (!solver->level); + KISSAT_assert (!solver->level); kissat_fast_binary_assign (solver, solver->probing, 0, values, assigned, other, not_lit); } else { const reference ref = watch.large.ref; - assert (ref < SIZE_STACK (solver->arena)); + KISSAT_assert (ref < SIZE_STACK (solver->arena)); clause *c = (clause *) (arena + ref); - assert (c->size > 2); - assert (!c->redundant); + KISSAT_assert (c->size > 2); + KISSAT_assert (!c->redundant); ticks++; if (c->garbage) continue; @@ -49,13 +51,13 @@ static inline bool non_watching_propagate_literal (kissat *solver, for (all_literals_in_clause (other, c)) { if (other == not_lit) continue; - assert (VALID_INTERNAL_LITERAL (other)); + KISSAT_assert (VALID_INTERNAL_LITERAL (other)); const value other_value = values[other]; if (other_value < 0) continue; if (other_value > 0) { satisfied = true; - assert (!solver->level); + KISSAT_assert (!solver->level); LOGCLS (c, "%s satisfied", LOGLIT (other)); kissat_mark_clause_as_garbage (solver, c); break; @@ -84,9 +86,9 @@ static inline bool non_watching_propagate_literal (kissat *solver, } bool kissat_dense_propagate (kissat *solver) { - assert (!solver->level); - assert (!solver->watching); - assert (!solver->inconsistent); + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->watching); + KISSAT_assert (!solver->inconsistent); START (propagate); unsigned *propagate = solver->propagate; bool res = true; @@ -97,7 +99,7 @@ bool kissat_dense_propagate (kissat *solver) { ADD (dense_propagations, propagated); ADD (propagations, propagated); if (!res) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); LOG ("inconsistent root propagation"); CHECK_AND_ADD_EMPTY (); ADD_EMPTY_TO_PROOF (); @@ -106,3 +108,5 @@ bool kissat_dense_propagate (kissat *solver) { STOP (propagate); return res; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/propdense.h b/src/sat/kissat/propdense.h index adbaae1cd..cdfbc7280 100644 --- a/src/sat/kissat/propdense.h +++ b/src/sat/kissat/propdense.h @@ -4,8 +4,13 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_dense_propagate (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/propinitially.c b/src/sat/kissat/propinitially.c index 5f66db3d1..d534d0e86 100644 --- a/src/sat/kissat/propinitially.c +++ b/src/sat/kissat/propinitially.c @@ -4,6 +4,8 @@ #include "print.h" #include "trail.h" +ABC_NAMESPACE_IMPL_START + #define PROPAGATE_LITERAL initially_propagate_literal #define PROPAGATION_TYPE "initially" @@ -12,7 +14,7 @@ static inline void update_initial_propagation_statistics (kissat *solver, const unsigned *saved_propagate) { - assert (saved_propagate <= solver->propagate); + KISSAT_assert (saved_propagate <= solver->propagate); const unsigned propagated = solver->propagate - saved_propagate; LOG ("propagated %u literals", propagated); @@ -32,9 +34,9 @@ static clause *initially_propagate (kissat *solver) { } bool kissat_initially_propagate (kissat *solver) { - assert (!solver->probing); - assert (solver->watching); - assert (!solver->inconsistent); + KISSAT_assert (!solver->probing); + KISSAT_assert (solver->watching); + KISSAT_assert (!solver->inconsistent); START (propagate); @@ -45,8 +47,8 @@ bool kissat_initially_propagate (kissat *solver) { kissat_update_conflicts_and_trail (solver, conflict, true); if (conflict) { int res = kissat_analyze (solver, conflict); - assert (solver->inconsistent); - assert (res == 20); + KISSAT_assert (solver->inconsistent); + KISSAT_assert (res == 20); (void) res; } @@ -54,3 +56,5 @@ bool kissat_initially_propagate (kissat *solver) { return !conflict; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/propinitially.h b/src/sat/kissat/propinitially.h index d53f84c9a..7203cacaf 100644 --- a/src/sat/kissat/propinitially.h +++ b/src/sat/kissat/propinitially.h @@ -3,8 +3,13 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_initially_propagate (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/proplit.h b/src/sat/kissat/proplit.h index c8ae9c1cb..be0632d0c 100644 --- a/src/sat/kissat/proplit.h +++ b/src/sat/kissat/proplit.h @@ -1,18 +1,18 @@ static inline void kissat_watch_large_delayed (kissat *solver, watches *all_watches, unsigneds *delayed) { - assert (all_watches == solver->watches); - assert (delayed == &solver->delayed); + KISSAT_assert (all_watches == solver->watches); + KISSAT_assert (delayed == &solver->delayed); const unsigned *const end_delayed = END_STACK (*delayed); unsigned const *d = BEGIN_STACK (*delayed); while (d != end_delayed) { const unsigned lit = *d++; - assert (d != end_delayed); + KISSAT_assert (d != end_delayed); const watch watch = {.raw = *d++}; - assert (!watch.type.binary); - assert (lit < LITS); + KISSAT_assert (!watch.type.binary); + KISSAT_assert (lit < LITS); watches *const lit_watches = all_watches + lit; - assert (d != end_delayed); + KISSAT_assert (d != end_delayed); const reference ref = *d++; const unsigned blocking = watch.blocking.lit; LOGREF3 (ref, "watching %s blocking %s in", LOGLIT (lit), @@ -36,10 +36,10 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, const clause *const ignore, #endif const unsigned lit) { - assert (solver->watching); + KISSAT_assert (solver->watching); LOG (PROPAGATION_TYPE " propagating %s", LOGLIT (lit)); - assert (VALUE (lit) > 0); - assert (EMPTY_STACK (solver->delayed)); + KISSAT_assert (VALUE (lit) > 0); + KISSAT_assert (EMPTY_STACK (solver->delayed)); watches *const all_watches = solver->watches; ward *const arena = BEGIN_STACK (solver->arena); @@ -48,7 +48,7 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, const unsigned not_lit = NOT (lit); - assert (not_lit < LITS); + KISSAT_assert (not_lit < LITS); watches *watches = all_watches + not_lit; watch *const begin_watches = BEGIN_WATCHES (*watches); @@ -58,7 +58,7 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, const watch *p = q; unsigneds *const delayed = &solver->delayed; - assert (EMPTY_STACK (*delayed)); + KISSAT_assert (EMPTY_STACK (*delayed)); const size_t size_watches = SIZE_WATCHES (*watches); uint64_t ticks = 1 + kissat_cache_lines (size_watches, sizeof (watch)); @@ -71,7 +71,7 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, while (p != end_watches) { const watch head = *q++ = *p++; const unsigned blocking = head.blocking.lit; - assert (VALID_INTERNAL_LITERAL (blocking)); + KISSAT_assert (VALID_INTERNAL_LITERAL (blocking)); const value blocking_value = values[blocking]; const bool binary = head.type.binary; watch tail; @@ -86,14 +86,14 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, break; #endif } else { - assert (!blocking_value); + KISSAT_assert (!blocking_value); kissat_fast_binary_assign (solver, probing, level, values, assigned, blocking, not_lit); ticks++; } } else { const reference ref = tail.raw; - assert (ref < SIZE_STACK (solver->arena)); + KISSAT_assert (ref < SIZE_STACK (solver->arena)); clause *const c = (clause *) (arena + ref); ticks++; if (c->garbage) { @@ -102,10 +102,10 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, } unsigned *const lits = BEGIN_LITS (c); const unsigned other = lits[0] ^ lits[1] ^ not_lit; - assert (lits[0] != lits[1]); - assert (VALID_INTERNAL_LITERAL (other)); - assert (not_lit != other); - assert (lit != other); + KISSAT_assert (lits[0] != lits[1]); + KISSAT_assert (VALID_INTERNAL_LITERAL (other)); + KISSAT_assert (not_lit != other); + KISSAT_assert (lit != other); const value other_value = values[other]; if (other_value > 0) { q[-2].blocking.lit = other; @@ -113,13 +113,13 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, } const unsigned *const end_lits = lits + c->size; unsigned *const searched = lits + c->searched; - assert (c->lits + 2 <= searched); - assert (searched < end_lits); + KISSAT_assert (c->lits + 2 <= searched); + KISSAT_assert (searched < end_lits); unsigned *r, replacement = INVALID_LIT; value replacement_value = -1; for (r = searched; r != end_lits; r++) { replacement = *r; - assert (VALID_INTERNAL_LITERAL (replacement)); + KISSAT_assert (VALID_INTERNAL_LITERAL (replacement)); replacement_value = values[replacement]; if (replacement_value >= 0) break; @@ -127,7 +127,7 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, if (replacement_value < 0) { for (r = lits + 2; r != searched; r++) { replacement = *r; - assert (VALID_INTERNAL_LITERAL (replacement)); + KISSAT_assert (VALID_INTERNAL_LITERAL (replacement)); replacement_value = values[replacement]; if (replacement_value >= 0) break; @@ -136,20 +136,20 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, if (replacement_value >= 0) { c->searched = r - lits; - assert (replacement != INVALID_LIT); + KISSAT_assert (replacement != INVALID_LIT); LOGREF3 (ref, "unwatching %s in", LOGLIT (not_lit)); q -= 2; lits[0] = other; lits[1] = replacement; - assert (lits[0] != lits[1]); + KISSAT_assert (lits[0] != lits[1]); *r = not_lit; kissat_delay_watching_large (solver, delayed, replacement, other, ref); ticks++; } else if (other_value) { - assert (replacement_value < 0); - assert (blocking_value < 0); - assert (other_value < 0); + KISSAT_assert (replacement_value < 0); + KISSAT_assert (blocking_value < 0); + KISSAT_assert (other_value < 0); #if defined(PROBING_PROPAGATION) if (c == ignore) { LOGREF (ref, "conflicting but ignored"); @@ -162,7 +162,7 @@ static inline clause *PROPAGATE_LITERAL (kissat *solver, break; #endif } else { - assert (replacement_value < 0); + KISSAT_assert (replacement_value < 0); #if defined(PROBING_PROPAGATION) if (c == ignore) { LOGREF (ref, "forcing %s but ignored", LOGLIT (other)); diff --git a/src/sat/kissat/proprobe.c b/src/sat/kissat/proprobe.c index e95873317..f75799ed4 100644 --- a/src/sat/kissat/proprobe.c +++ b/src/sat/kissat/proprobe.c @@ -2,6 +2,8 @@ #include "fastassign.h" #include "trail.h" +ABC_NAMESPACE_IMPL_START + #define PROPAGATE_LITERAL probing_propagate_literal #define PROPAGATION_TYPE "probing" #define PROBING_PROPAGATION @@ -34,9 +36,9 @@ static void update_probing_propagation_statistics (kissat *solver, clause *kissat_probing_propagate (kissat *solver, clause *ignore, bool flush) { - assert (solver->probing); - assert (solver->watching); - assert (!solver->inconsistent); + KISSAT_assert (solver->probing); + KISSAT_assert (solver->watching); + KISSAT_assert (!solver->inconsistent); START (propagate); @@ -57,3 +59,5 @@ clause *kissat_probing_propagate (kissat *solver, clause *ignore, return conflict; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/proprobe.h b/src/sat/kissat/proprobe.h index 9fbebe8cc..327c8bd01 100644 --- a/src/sat/kissat/proprobe.h +++ b/src/sat/kissat/proprobe.h @@ -3,10 +3,15 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; struct clause; struct clause *kissat_probing_propagate (struct kissat *, struct clause *, bool flush); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/propsearch.c b/src/sat/kissat/propsearch.c index c1265301c..301bd02ca 100644 --- a/src/sat/kissat/propsearch.c +++ b/src/sat/kissat/propsearch.c @@ -3,6 +3,8 @@ #include "print.h" #include "trail.h" +ABC_NAMESPACE_IMPL_START + #define PROPAGATE_LITERAL search_propagate_literal #define PROPAGATION_TYPE "search" @@ -11,7 +13,7 @@ static inline void update_search_propagation_statistics (kissat *solver, const unsigned *saved_propagate) { - assert (saved_propagate <= solver->propagate); + KISSAT_assert (saved_propagate <= solver->propagate); const unsigned propagated = solver->propagate - saved_propagate; LOG ("propagated %u literals", propagated); @@ -42,9 +44,9 @@ static clause *search_propagate (kissat *solver) { } clause *kissat_search_propagate (kissat *solver) { - assert (!solver->probing); - assert (solver->watching); - assert (!solver->inconsistent); + KISSAT_assert (!solver->probing); + KISSAT_assert (solver->watching); + KISSAT_assert (!solver->inconsistent); START (propagate); @@ -69,3 +71,5 @@ clause *kissat_search_propagate (kissat *solver) { return conflict; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/propsearch.h b/src/sat/kissat/propsearch.h index a774d9c5b..c932e66fb 100644 --- a/src/sat/kissat/propsearch.h +++ b/src/sat/kissat/propsearch.h @@ -1,9 +1,14 @@ #ifndef _propsearch_h_INCLUDED #define _propsearch_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; struct clause; struct clause *kissat_search_propagate (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/queue.c b/src/sat/kissat/queue.c index f64dfe2a3..14deb0c6f 100644 --- a/src/sat/kissat/queue.c +++ b/src/sat/kissat/queue.c @@ -2,12 +2,14 @@ #include "inlinequeue.h" #include "print.h" +ABC_NAMESPACE_IMPL_START + void kissat_init_queue (kissat *solver) { queue *queue = &solver->queue; queue->first = queue->last = DISCONNECT; - assert (!queue->stamp); + KISSAT_assert (!queue->stamp); queue->search.idx = DISCONNECT; - assert (!queue->search.stamp); + KISSAT_assert (!queue->search.stamp); } void kissat_reset_search_of_queue (kissat *solver) { @@ -15,7 +17,7 @@ void kissat_reset_search_of_queue (kissat *solver) { queue *queue = &solver->queue; links *links = solver->links; const unsigned last = queue->last; - assert (!DISCONNECTED (last)); + KISSAT_assert (!DISCONNECTED (last)); kissat_update_queue (solver, links, last); } @@ -34,7 +36,7 @@ void kissat_reassign_queue_stamps (kissat *solver) { queue->search.stamp = links[queue->search.idx].stamp; } -#if defined(CHECK_QUEUE) && !defined(NDEBUG) +#if defined(CHECK_QUEUE) && !defined(KISSAT_NDEBUG) void kissat_check_queue (kissat *solver) { links *links = solver->links; queue *queue = &solver->queue; @@ -43,13 +45,15 @@ void kissat_check_queue (kissat *solver) { for (unsigned idx = queue->first, prev = DISCONNECT; !DISCONNECTED (idx); idx = links[idx].next) { if (!DISCONNECTED (prev)) - assert (links[prev].stamp < links[idx].stamp); + KISSAT_assert (links[prev].stamp < links[idx].stamp); if (focused && passed_search_idx) - assert (VALUE (LIT (idx))); + KISSAT_assert (VALUE (LIT (idx))); if (idx == queue->search.idx) passed_search_idx = true; } if (!DISCONNECTED (queue->search.idx)) - assert (links[queue->search.idx].stamp == queue->search.stamp); + KISSAT_assert (links[queue->search.idx].stamp == queue->search.stamp); } #endif + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/queue.h b/src/sat/kissat/queue.h index 271e7e567..c6e40ebe1 100644 --- a/src/sat/kissat/queue.h +++ b/src/sat/kissat/queue.h @@ -1,6 +1,9 @@ #ifndef _queue_h_INCLUDED #define _queue_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define DISCONNECT UINT_MAX #define DISCONNECTED(IDX) ((int) (IDX) < 0) @@ -25,9 +28,9 @@ void kissat_init_queue (struct kissat *); void kissat_reset_search_of_queue (struct kissat *); void kissat_reassign_queue_stamps (struct kissat *); -#define LINK(IDX) (solver->links[assert ((IDX) < VARS), (IDX)]) +#define LINK(IDX) (solver->links[KISSAT_assert ((IDX) < VARS), (IDX)]) -#if defined(CHECK_QUEUE) && !defined(NDEBUG) +#if defined(CHECK_QUEUE) && !defined(KISSAT_NDEBUG) void kissat_check_queue (struct kissat *); #else #define kissat_check_queue(...) \ @@ -35,4 +38,6 @@ void kissat_check_queue (struct kissat *); } while (0) #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/random.h b/src/sat/kissat/random.h index 7f00fbf99..5a8057950 100644 --- a/src/sat/kissat/random.h +++ b/src/sat/kissat/random.h @@ -5,6 +5,9 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef uint64_t generator; static inline uint64_t kissat_next_random64 (generator *rng) { @@ -19,17 +22,17 @@ static inline unsigned kissat_next_random32 (generator *rng) { static inline unsigned kissat_pick_random (generator *rng, unsigned l, unsigned r) { - assert (l <= r); + KISSAT_assert (l <= r); if (l == r) return l; const unsigned delta = r - l; const unsigned tmp = kissat_next_random32 (rng); const double fraction = tmp / 4294967296.0; - assert (0 <= fraction), assert (fraction < 1); + KISSAT_assert (0 <= fraction), KISSAT_assert (fraction < 1); const unsigned scaled = delta * fraction; - assert (scaled < delta); + KISSAT_assert (scaled < delta); const unsigned res = l + scaled; - assert (l <= res), assert (res < r); + KISSAT_assert (l <= res), KISSAT_assert (res < r); return res; } @@ -41,4 +44,6 @@ static inline double kissat_pick_double (generator *rng) { return kissat_next_random32 (rng) / 4294967296.0; } +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/rank.h b/src/sat/kissat/rank.h index 283536536..08ac1e8e8 100644 --- a/src/sat/kissat/rank.h +++ b/src/sat/kissat/rank.h @@ -5,17 +5,20 @@ #include -#ifdef NDEBUG +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#ifdef KISSAT_NDEBUG #define CHECK_RANKED(...) \ do { \ } while (0) #else #define CHECK_RANKED(N, A, RANK) \ do { \ - assert (0 < (N)); \ + KISSAT_assert (0 < (N)); \ for (size_t I_CHECK_RANKED = 0; I_CHECK_RANKED < N - 1; \ I_CHECK_RANKED++) \ - assert (RANK (A[I_CHECK_RANKED]) <= RANK (A[I_CHECK_RANKED + 1])); \ + KISSAT_assert (RANK (A[I_CHECK_RANKED]) <= RANK (A[I_CHECK_RANKED + 1])); \ } while (0) #endif @@ -33,7 +36,7 @@ const size_t WIDTH_RADIX = (1 << LENGTH_RADIX); \ const RTYPE MASK_RADIX = WIDTH_RADIX - 1; \ \ - size_t COUNT_RADIX[WIDTH_RADIX]; \ + size_t COUNT_RADIX[256]; \ \ VTYPE *TMP_RADIX = 0; \ const size_t BYTES_TMP_RADIX = N_RADIX * sizeof (VTYPE); \ @@ -100,12 +103,12 @@ } \ \ if (!TMP_RADIX) { \ - assert (C_RADIX == A_RADIX); \ - TMP_RADIX = kissat_malloc (solver, BYTES_TMP_RADIX); \ + KISSAT_assert (C_RADIX == A_RADIX); \ + TMP_RADIX = (VTYPE*)kissat_malloc (solver, BYTES_TMP_RADIX); \ B_RADIX = TMP_RADIX; \ } \ \ - assert (B_RADIX == TMP_RADIX); \ + KISSAT_assert (B_RADIX == TMP_RADIX); \ \ VTYPE *D_RADIX = (C_RADIX == A_RADIX) ? B_RADIX : A_RADIX; \ \ @@ -137,4 +140,6 @@ RADIX_SORT (VTYPE, RTYPE, N_RADIX_STACK, A_RADIX_STACK, RANK); \ } while (0) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/reduce.c b/src/sat/kissat/reduce.c index 027798520..8d8716cc3 100644 --- a/src/sat/kissat/reduce.c +++ b/src/sat/kissat/reduce.c @@ -11,10 +11,12 @@ #include #include +ABC_NAMESPACE_IMPL_START + bool kissat_reducing (kissat *solver) { if (!GET_OPTION (reduce)) return false; - if (!solver->statistics.clauses_redundant) + if (!solver->statistics_.clauses_redundant) return false; if (CONFLICTS < solver->limits.reduce.conflicts) return false; @@ -36,12 +38,12 @@ typedef STACK (reducible) reducibles; static bool collect_reducibles (kissat *solver, reducibles *reds, reference start_ref) { - assert (start_ref != INVALID_REF); - assert (start_ref <= SIZE_STACK (solver->arena)); + KISSAT_assert (start_ref != INVALID_REF); + KISSAT_assert (start_ref <= SIZE_STACK (solver->arena)); ward *const arena = BEGIN_STACK (solver->arena); clause *start = (clause *) (arena + start_ref); const clause *const end = (clause *) END_STACK (solver->arena); - assert (start < end); + KISSAT_assert (start < end); while (start != end && !start->redundant) start = kissat_next_clause (start); if (start == end) { @@ -61,7 +63,7 @@ static bool collect_reducibles (kissat *solver, reducibles *reds, solver->first_reducible = redundant; const unsigned tier1 = TIER1; const unsigned tier2 = MAX (tier1, TIER2); - assert (tier1 <= tier2); + KISSAT_assert (tier1 <= tier2); for (clause *c = start; c != end; c = kissat_next_clause (c)) { if (!c->redundant) continue; @@ -77,7 +79,7 @@ static bool collect_reducibles (kissat *solver, reducibles *reds, continue; if (glue <= tier2 && used >= MAX_USED - 1) continue; - assert (kissat_clause_in_arena (solver, c)); + KISSAT_assert (kissat_clause_in_arena (solver, c)); reducible red; const uint64_t negative_size = ~c->size; const uint64_t negative_glue = ~c->glue; @@ -101,7 +103,7 @@ static void sort_reducibles (kissat *solver, reducibles *reds) { static void mark_less_useful_clauses_as_garbage (kissat *solver, reducibles *reds) { - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; const double high = GET_OPTION (reducehigh) * 0.1; const double low = GET_OPTION (reducelow) * 0.1; double percent; @@ -113,7 +115,7 @@ static void mark_less_useful_clauses_as_garbage (kissat *solver, const double fraction = percent / 100.0; const size_t size = SIZE_STACK (*reds); size_t target = size * fraction; -#ifndef QUIET +#ifndef KISSAT_QUIET const size_t clauses = statistics->clauses_irredundant + statistics->clauses_redundant; kissat_phase (solver, "reduce", GET (reductions), @@ -130,10 +132,10 @@ static void mark_less_useful_clauses_as_garbage (kissat *solver, const unsigned tier2 = TIER2; for (const reducible *p = begin; p != end && target--; p++) { clause *c = (clause *) (arena + p->ref); - assert (kissat_clause_in_arena (solver, c)); - assert (!c->garbage); - assert (!c->reason); - assert (c->redundant); + KISSAT_assert (kissat_clause_in_arena (solver, c)); + KISSAT_assert (!c->garbage); + KISSAT_assert (!c->reason); + KISSAT_assert (c->redundant); LOGCLS (c, "reducing"); kissat_mark_clause_as_garbage (solver, c); reduced++; @@ -160,7 +162,7 @@ int kissat_reduce (kissat *solver) { bool compact = kissat_compacting (solver); reference start = compact ? 0 : solver->first_reducible; if (start != INVALID_REF) { -#ifndef QUIET +#ifndef KISSAT_QUIET size_t arena_size = SIZE_STACK (solver->arena); size_t words_to_sweep = arena_size - start; size_t bytes_to_sweep = sizeof (word) * words_to_sweep; @@ -186,7 +188,7 @@ int kissat_reduce (kissat *solver) { else kissat_unmark_reason_clauses (solver, start); } else - assert (solver->inconsistent); + KISSAT_assert (solver->inconsistent); } else kissat_phase (solver, "reduce", GET (reductions), "nothing to reduce"); kissat_classify (solver); @@ -196,3 +198,5 @@ int kissat_reduce (kissat *solver) { STOP (reduce); return solver->inconsistent ? 20 : 0; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/reduce.h b/src/sat/kissat/reduce.h index c82c0481d..134e654c3 100644 --- a/src/sat/kissat/reduce.h +++ b/src/sat/kissat/reduce.h @@ -3,9 +3,14 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_reducing (struct kissat *); int kissat_reduce (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/reference.h b/src/sat/kissat/reference.h index 028fc4b5f..437ad8642 100644 --- a/src/sat/kissat/reference.h +++ b/src/sat/kissat/reference.h @@ -3,6 +3,9 @@ #include "stack.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef unsigned reference; #define REFERENCE_FORMAT "u" @@ -16,4 +19,6 @@ typedef unsigned reference; typedef STACK (reference) references; // clang-format on +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/reluctant.c b/src/sat/kissat/reluctant.c index 54b4558e5..ddab37c45 100644 --- a/src/sat/kissat/reluctant.c +++ b/src/sat/kissat/reluctant.c @@ -1,6 +1,8 @@ #include "internal.h" #include "logging.h" +ABC_NAMESPACE_IMPL_START + void kissat_enable_reluctant (reluctant *reluctant, uint64_t period, uint64_t limit) { if (limit && period > limit) @@ -24,7 +26,7 @@ void kissat_tick_reluctant (reluctant *reluctant) { if (reluctant->trigger) return; - assert (reluctant->wait > 0); + KISSAT_assert (reluctant->wait > 0); if (--reluctant->wait) return; @@ -35,12 +37,12 @@ void kissat_tick_reluctant (reluctant *reluctant) { u++; v = 1; } else { - assert (UINT64_MAX / 2 >= v); + KISSAT_assert (UINT64_MAX / 2 >= v); v *= 2; } - assert (v); - assert (UINT64_MAX / v >= reluctant->period); + KISSAT_assert (v); + KISSAT_assert (UINT64_MAX / v >= reluctant->period); uint64_t wait = v * reluctant->period; if (reluctant->limited && wait > reluctant->limit) { @@ -65,3 +67,5 @@ void kissat_init_reluctant (kissat *solver) { kissat_disable_reluctant (&solver->reluctant); } } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/reluctant.h b/src/sat/kissat/reluctant.h index 93513aabe..1ee419f56 100644 --- a/src/sat/kissat/reluctant.h +++ b/src/sat/kissat/reluctant.h @@ -4,6 +4,9 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct reluctant reluctant; struct reluctant { @@ -30,4 +33,6 @@ struct kissat; void kissat_init_reluctant (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/reorder.c b/src/sat/kissat/reorder.c index e1d4fe8c5..fc04d3a9a 100644 --- a/src/sat/kissat/reorder.c +++ b/src/sat/kissat/reorder.c @@ -11,6 +11,8 @@ #include "report.h" #include "sort.h" +ABC_NAMESPACE_IMPL_START + bool kissat_reordering (kissat *solver) { if (!GET_OPTION (reorder)) return false; @@ -22,11 +24,11 @@ bool kissat_reordering (kissat *solver) { } static double *compute_weights (kissat *solver) { - double *weights = kissat_calloc (solver, LITS, sizeof *weights); + double *weights = (double*)kissat_calloc (solver, LITS, sizeof *weights); const unsigned max_size = GET_OPTION (reordermaxsize); LOG ("limiting weight computation to maximum clause size %u", max_size); - assert (2 <= max_size); - double *table = kissat_nalloc (solver, max_size + 1, sizeof *table); + KISSAT_assert (2 <= max_size); + double *table = (double*)kissat_nalloc (solver, max_size + 1, sizeof *table); { double weight = 1; for (unsigned size = 2; size <= max_size; size++) { @@ -35,7 +37,7 @@ static double *compute_weights (kissat *solver) { } } { - assert (!solver->level); + KISSAT_assert (!solver->level); const signed char *const values = solver->values; const clause *last = kissat_last_irredundant_clause (solver); for (all_clauses (c)) { @@ -46,20 +48,25 @@ static double *compute_weights (kissat *solver) { if (c->garbage) continue; unsigned size = 0; + int continue_with_next_clause = 0; for (all_literals_in_clause (lit, c)) { const signed char value = values[lit]; - if (value > 0) - goto CONTINUE_WITH_NEXT_CLAUSE; + if (value > 0) { + continue_with_next_clause = 1; + break; + } if (!value && size < max_size && ++size == max_size) break; } + if(continue_with_next_clause) { + continue; + } const double weight = table[size]; for (all_literals_in_clause (lit, c)) weights[lit] += weight; - CONTINUE_WITH_NEXT_CLAUSE:; } } - assert (solver->watching); + KISSAT_assert (solver->watching); { double weight = table[2]; kissat_dealloc (solver, table, max_size + 1, sizeof *table); @@ -161,13 +168,13 @@ static void sort_active_variables_by_weight (kissat *solver, static void reorder_focused (kissat *solver) { INC (reordered_focused); - assert (!solver->stable); + KISSAT_assert (!solver->stable); double *weights = compute_weights (solver); unsigneds sorted; sort_active_variables_by_weight (solver, &sorted, weights); kissat_dealloc (solver, weights, LITS, sizeof *weights); for (all_stack (unsigned, idx, sorted)) { - assert (ACTIVE (idx)); + KISSAT_assert (ACTIVE (idx)); kissat_move_to_front (solver, idx); } RELEASE_STACK (sorted); @@ -175,7 +182,7 @@ static void reorder_focused (kissat *solver) { static void reorder_stable (kissat *solver) { INC (reordered_stable); - assert (solver->stable); + KISSAT_assert (solver->stable); double *weights = compute_weights (solver); kissat_rescale_scores (solver); unsigneds sorted; @@ -183,7 +190,7 @@ static void reorder_stable (kissat *solver) { heap *scores = SCORES; while (!EMPTY_STACK (sorted)) { unsigned idx = POP_STACK (sorted); - assert (ACTIVE (idx)); + KISSAT_assert (ACTIVE (idx)); const double old_score = kissat_get_heap_score (scores, idx); const double weight = weights[idx]; const double new_score = old_score + weight; @@ -198,7 +205,7 @@ static void reorder_stable (kissat *solver) { void kissat_reorder (kissat *solver) { START (reorder); INC (reordered); - assert (!solver->level); + KISSAT_assert (!solver->level); kissat_phase (solver, "reorder", GET (reordered), "reorder limit %" PRIu64 " hit a after %" PRIu64 " conflicts in %s mode ", @@ -215,3 +222,5 @@ void kissat_reorder (kissat *solver) { REPORT (0, 'o'); STOP (reorder); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/reorder.h b/src/sat/kissat/reorder.h index 24351927e..d26dd0721 100644 --- a/src/sat/kissat/reorder.h +++ b/src/sat/kissat/reorder.h @@ -3,9 +3,14 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_reordering (struct kissat *); void kissat_reorder (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/rephase.c b/src/sat/kissat/rephase.c index 33783f675..00e0dfadb 100644 --- a/src/sat/kissat/rephase.c +++ b/src/sat/kissat/rephase.c @@ -11,6 +11,8 @@ #include #include +ABC_NAMESPACE_IMPL_START + static void kissat_reset_best_assigned (kissat *solver) { if (!solver->best_assigned) return; @@ -75,7 +77,7 @@ static char rephase_inverted (kissat *solver) { } static char rephase_walking (kissat *solver) { - assert (kissat_walking (solver)); + KISSAT_assert (kissat_walking (solver)); STOP (rephase); kissat_walk (solver); START (rephase); @@ -91,7 +93,7 @@ static char (*rephase_schedule[]) (kissat *) = { #define size_rephase_schedule \ (sizeof rephase_schedule / sizeof *rephase_schedule) -#ifndef QUIET +#ifndef KISSAT_QUIET static const char *rephase_type_as_string (char type) { if (type == 'B') @@ -100,7 +102,7 @@ static const char *rephase_type_as_string (char type) { return "inverted"; if (type == 'O') return "original"; - assert (type == 'W'); + KISSAT_assert (type == 'W'); return "walking"; } @@ -108,7 +110,7 @@ static const char *rephase_type_as_string (char type) { static char reset_phases (kissat *solver) { const uint64_t count = GET (rephased); - assert (count > 0); + KISSAT_assert (count > 0); const uint64_t select = (count - 1) % (uint64_t) size_rephase_schedule; const char type = rephase_schedule[select](solver); kissat_phase ( @@ -125,13 +127,15 @@ static char reset_phases (kissat *solver) { void kissat_rephase (kissat *solver) { kissat_backtrack_propagate_and_flush_trail (solver); - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); START (rephase); INC (rephased); -#ifndef QUIET +#ifndef KISSAT_QUIET const char type = #endif reset_phases (solver); REPORT (0, type); STOP (rephase); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/rephase.h b/src/sat/kissat/rephase.h index b59382e4e..4ab597866 100644 --- a/src/sat/kissat/rephase.h +++ b/src/sat/kissat/rephase.h @@ -3,9 +3,14 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_rephasing (struct kissat *); void kissat_rephase (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/report.c b/src/sat/kissat/report.c index a9fc092b5..820774b96 100644 --- a/src/sat/kissat/report.c +++ b/src/sat/kissat/report.c @@ -1,4 +1,6 @@ -#ifndef QUIET +#include "global.h" + +#ifndef KISSAT_QUIET #include "report.h" #include "colors.h" @@ -58,7 +60,7 @@ void kissat_report (kissat *solver, bool verbose, char type) { REPORTS #undef REP // clang-format on - assert (p < line + sizeof line); + KISSAT_assert (p < line + sizeof line); TERMINAL (stdout, 1); if (!(solver->limits.reports++ % 20)) { #define ROWS 3 @@ -86,9 +88,9 @@ void kissat_report (kissat *solver, bool verbose, char type) { } while (0); REPORTS #undef REP - assert (i == n); + KISSAT_assert (i == n); for (unsigned j = 0; j < ROWS; j++) { - assert (r[j] < rows[j] + sizeof rows[j]); + KISSAT_assert (r[j] < rows[j] + sizeof rows[j]); *r[j] = 0; } if (solver->limits.reports > 1) diff --git a/src/sat/kissat/report.h b/src/sat/kissat/report.h index 744aea32a..9b6207890 100644 --- a/src/sat/kissat/report.h +++ b/src/sat/kissat/report.h @@ -1,7 +1,11 @@ #ifndef _report_h_INCLUDED #define _report_h_INCLUDED -#ifdef QUIET +#include "global.h" + +#ifdef KISSAT_QUIET + +ABC_NAMESPACE_HEADER_START #define REPORT(...) \ do { \ @@ -11,6 +15,8 @@ #include +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_report (struct kissat *, bool verbose, char type); @@ -19,4 +25,6 @@ void kissat_report (struct kissat *, bool verbose, char type); #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/require.h b/src/sat/kissat/require.h index 9325c9b3f..d938691f3 100644 --- a/src/sat/kissat/require.h +++ b/src/sat/kissat/require.h @@ -1,6 +1,9 @@ #ifndef _require_h_INCLUDED #define _require_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define kissat_require(COND, ...) \ do { \ if ((COND)) \ @@ -24,7 +27,9 @@ kissat_require (TMP_IDX <= EXTERNAL_MAX_VAR, \ "invalid literal '%d' (variable larger than %d)", \ (LIT), EXTERNAL_MAX_VAR); \ - assert (VALID_EXTERNAL_LITERAL (LIT)); \ + KISSAT_assert (VALID_EXTERNAL_LITERAL (LIT)); \ } while (0) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/resize.c b/src/sat/kissat/resize.c index 593d813c8..83306a772 100644 --- a/src/sat/kissat/resize.c +++ b/src/sat/kissat/resize.c @@ -6,11 +6,13 @@ #include #include +ABC_NAMESPACE_IMPL_START + #define NREALLOC_GENERIC(TYPE, NAME, ELEMENTS_PER_BLOCK) \ do { \ const size_t block_size = sizeof (TYPE); \ solver->NAME = \ - kissat_nrealloc (solver, solver->NAME, old_size, new_size, \ + (TYPE*) kissat_nrealloc (solver, solver->NAME, old_size, new_size, \ ELEMENTS_PER_BLOCK * block_size); \ } while (0) @@ -18,7 +20,7 @@ do { \ const size_t block_size = sizeof (TYPE); \ TYPE *NAME = \ - kissat_calloc (solver, ELEMENTS_PER_BLOCK * new_size, block_size); \ + (TYPE*) kissat_calloc (solver, ELEMENTS_PER_BLOCK * new_size, block_size); \ if (old_size) { \ const size_t bytes = ELEMENTS_PER_BLOCK * old_size * block_size; \ memcpy (NAME, solver->NAME, bytes); \ @@ -43,12 +45,12 @@ static void reallocate_trail (kissat *solver, unsigned old_size, unsigned new_size) { unsigned propagated = solver->propagate - BEGIN_ARRAY (solver->trail); - REALLOCATE_ARRAY (solver->trail, old_size, new_size); + REALLOCATE_ARRAY (unsigned, solver->trail, old_size, new_size); solver->propagate = BEGIN_ARRAY (solver->trail) + propagated; } void kissat_increase_size (kissat *solver, unsigned new_size) { - assert (solver->vars <= new_size); + KISSAT_assert (solver->vars <= new_size); const unsigned old_size = solver->size; if (old_size >= new_size) return; @@ -57,13 +59,13 @@ void kissat_increase_size (kissat *solver, unsigned new_size) { LOG ("%s before increasing size from %u to %u", FORMAT_BYTES (kissat_allocated (solver)), old_size, new_size); #endif - CREALLOC_VARIABLE_INDEXED (assigned, assigned); - CREALLOC_VARIABLE_INDEXED (flags, flags); - NREALLOC_VARIABLE_INDEXED (links, links); + CREALLOC_VARIABLE_INDEXED (struct assigned, assigned); + CREALLOC_VARIABLE_INDEXED (struct flags, flags); + NREALLOC_VARIABLE_INDEXED (struct links, links); CREALLOC_LITERAL_INDEXED (mark, marks); CREALLOC_LITERAL_INDEXED (value, values); - CREALLOC_LITERAL_INDEXED (watches, watches); + CREALLOC_LITERAL_INDEXED (struct vector, watches); reallocate_trail (solver, old_size, new_size); kissat_resize_heap (solver, SCORES, new_size); @@ -109,7 +111,7 @@ void kissat_decrease_size (kissat *solver) { void kissat_enlarge_variables (kissat *solver, unsigned new_vars) { if (solver->vars >= new_vars) return; - assert (new_vars <= INTERNAL_MAX_VAR + 1); + KISSAT_assert (new_vars <= INTERNAL_MAX_VAR + 1); LOG ("enlarging variables from %u to %u", solver->vars, new_vars); const size_t old_size = solver->size; if (old_size < new_vars) { @@ -120,14 +122,14 @@ void kissat_enlarge_variables (kissat *solver, unsigned new_vars) { new_size = new_vars; else { if (kissat_is_power_of_two (old_size)) { - assert (old_size <= UINT_MAX / 2); + KISSAT_assert (old_size <= UINT_MAX / 2); new_size = 2 * old_size; } else { - assert (1 < old_size); + KISSAT_assert (1 < old_size); new_size = 2; } while (new_size < new_vars) { - assert (new_size <= UINT_MAX / 2); + KISSAT_assert (new_size <= UINT_MAX / 2); new_size *= 2; } } @@ -135,3 +137,5 @@ void kissat_enlarge_variables (kissat *solver, unsigned new_vars) { } solver->vars = new_vars; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/resize.h b/src/sat/kissat/resize.h index 089fe9394..55e578574 100644 --- a/src/sat/kissat/resize.h +++ b/src/sat/kissat/resize.h @@ -1,10 +1,15 @@ #ifndef _resize_h_INCLUDED #define _resize_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_decrease_size (struct kissat *solver); void kissat_increase_size (struct kissat *, unsigned new_size); void kissat_enlarge_variables (struct kissat *, unsigned new_vars); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/resolve.c b/src/sat/kissat/resolve.c index 49567b768..f6b1e6902 100644 --- a/src/sat/kissat/resolve.c +++ b/src/sat/kissat/resolve.c @@ -7,9 +7,11 @@ #include #include +ABC_NAMESPACE_IMPL_START + static inline unsigned occurrences_literal (kissat *solver, unsigned lit, bool *update) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); watches *watches = &WATCHES (lit); #ifdef LOGGING @@ -32,7 +34,7 @@ static inline unsigned occurrences_literal (kissat *solver, unsigned lit, if (head.type.binary) { const unsigned other = head.binary.lit; const value value = values[other]; - assert (value >= 0); + KISSAT_assert (value >= 0); if (value > 0) { kissat_eliminate_binary (solver, lit, other); q--; @@ -40,7 +42,7 @@ static inline unsigned occurrences_literal (kissat *solver, unsigned lit, res++; } else { const reference ref = head.large.ref; - assert (ref < SIZE_STACK (solver->arena)); + KISSAT_assert (ref < SIZE_STACK (solver->arena)); clause *const c = (struct clause *) (arena + ref); if (c->garbage) q--; @@ -76,10 +78,10 @@ static inline clause *watch_to_clause (kissat *solver, ward *const arena, res = tmp; } else { const reference ref = watch.large.ref; - assert (ref < SIZE_STACK (solver->arena)); + KISSAT_assert (ref < SIZE_STACK (solver->arena)); res = (struct clause *) (arena + ref); } -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) solver; #endif return res; @@ -109,7 +111,7 @@ static bool generate_resolvents (kissat *solver, unsigned lit, clause *const c = watch_to_clause (solver, arena, &tmp0, lit, watch0); if (c->garbage) { - assert (c != &tmp0); + KISSAT_assert (c != &tmp0); continue; } @@ -135,7 +137,7 @@ static bool generate_resolvents (kissat *solver, unsigned lit, for (all_literals_in_clause (other, c)) { if (other == lit) continue; - assert (!marks[other]); + KISSAT_assert (!marks[other]); marks[other] = 1; } @@ -144,7 +146,7 @@ static bool generate_resolvents (kissat *solver, unsigned lit, watch_to_clause (solver, arena, &tmp1, not_lit, watch1); if (d->garbage) { - assert (d != &tmp1); + KISSAT_assert (d != &tmp1); continue; } @@ -201,7 +203,7 @@ static bool generate_resolvents (kissat *solver, unsigned lit, if (other == lit) continue; const value value = values[other]; - assert (value <= 0); + KISSAT_assert (value <= 0); if (value < 0) { LOG2 ("dropping falsified literal %s", LOGLIT (other)); continue; @@ -214,7 +216,7 @@ static bool generate_resolvents (kissat *solver, unsigned lit, "resolvent"); if (!size_resolvent) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); solver->inconsistent = true; LOG ("resolved empty clause"); CHECK_AND_ADD_EMPTY (); @@ -248,7 +250,7 @@ static bool generate_resolvents (kissat *solver, unsigned lit, for (all_literals_in_clause (other, c)) { if (other == lit) continue; - assert (marks[other] == 1); + KISSAT_assert (marks[other] == 1); marks[other] = 0; } @@ -368,3 +370,5 @@ bool kissat_generate_resolvents (kissat *solver, unsigned idx, return !failed; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/resolve.h b/src/sat/kissat/resolve.h index 26bf7a0e9..dfa594ecc 100644 --- a/src/sat/kissat/resolve.h +++ b/src/sat/kissat/resolve.h @@ -3,9 +3,14 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_generate_resolvents (struct kissat *, unsigned idx, unsigned *lit_ptr); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/resources.c b/src/sat/kissat/resources.c index 31c0378af..82d398a90 100644 --- a/src/sat/kissat/resources.c +++ b/src/sat/kissat/resources.c @@ -1,15 +1,17 @@ #include "resources.h" -#include +//#include -double kissat_wall_clock_time (void) { - struct timeval tv; - if (gettimeofday (&tv, 0)) - return 0; - return 1e-6 * tv.tv_usec + tv.tv_sec; -} +ABC_NAMESPACE_IMPL_START -#ifndef QUIET +/* double kissat_wall_clock_time (void) { */ +/* struct timeval tv; */ +/* if (gettimeofday (&tv, 0)) */ +/* return 0; */ +/* return 1e-6 * tv.tv_usec + tv.tv_sec; */ +/* } */ + +#ifndef KISSAT_QUIET #include "internal.h" #include "statistics.h" @@ -102,3 +104,5 @@ void kissat_print_resources (kissat *solver) { } #endif + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/resources.h b/src/sat/kissat/resources.h index d9bce7853..e12635c52 100644 --- a/src/sat/kissat/resources.h +++ b/src/sat/kissat/resources.h @@ -1,9 +1,12 @@ #ifndef _resources_h_INCLUDED #define _resources_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + double kissat_wall_clock_time (void); -#ifndef QUIET +#ifndef KISSAT_QUIET #ifndef _resources_h_INLCUDED #define _resources_h_INLCUDED @@ -20,4 +23,6 @@ void kissat_print_resources (struct kissat *); #endif #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/restart.c b/src/sat/kissat/restart.c index dc4edf634..12ce99bf7 100644 --- a/src/sat/kissat/restart.c +++ b/src/sat/kissat/restart.c @@ -11,8 +11,10 @@ #include +ABC_NAMESPACE_IMPL_START + bool kissat_restarting (kissat *solver) { - assert (solver->unassigned); + KISSAT_assert (solver->unassigned); if (!GET_OPTION (restart)) return false; if (!solver->level) @@ -37,9 +39,9 @@ bool kissat_restarting (kissat *solver) { } void kissat_update_focused_restart_limit (kissat *solver) { - assert (!solver->stable); + KISSAT_assert (!solver->stable); limits *limits = &solver->limits; - uint64_t restarts = solver->statistics.restarts; + uint64_t restarts = solver->statistics_.restarts; uint64_t delta = GET_OPTION (restartint); if (restarts) delta += kissat_logn (restarts) - 1; @@ -84,8 +86,8 @@ static unsigned reuse_focused_trail (kissat *solver) { } static unsigned reuse_trail (kissat *solver) { - assert (solver->level); - assert (!EMPTY_STACK (solver->trail)); + KISSAT_assert (solver->level); + KISSAT_assert (!EMPTY_STACK (solver->trail)); if (!GET_OPTION (restartreusetrail)) return 0; @@ -129,3 +131,5 @@ void kissat_restart (kissat *solver) { REPORT (1, 'R'); STOP (restart); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/restart.h b/src/sat/kissat/restart.h index c17ab6499..7df4d64b5 100644 --- a/src/sat/kissat/restart.h +++ b/src/sat/kissat/restart.h @@ -1,6 +1,9 @@ #ifndef _restart_h_INCLUDED #define _restart_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + #include struct kissat; @@ -10,4 +13,6 @@ void kissat_restart (struct kissat *); void kissat_update_focused_restart_limit (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/search.c b/src/sat/kissat/search.c index 77f44ad99..ed283f50a 100644 --- a/src/sat/kissat/search.c +++ b/src/sat/kissat/search.c @@ -24,10 +24,12 @@ #include +ABC_NAMESPACE_IMPL_START + static void init_tiers (kissat *solver) { for (unsigned stable = 0; stable != 2; stable++) { if (!solver->tier1[stable]) { - assert (!solver->tier2[stable]); + KISSAT_assert (!solver->tier2[stable]); solver->tier1[stable] = GET_OPTION (tier1); solver->tier2[stable] = GET_OPTION (tier2); if (solver->tier2[stable] <= solver->tier1[stable]) @@ -70,7 +72,7 @@ static void start_search (kissat *solver) { solver->random = seed; LOG ("initialized random number generator with seed %u", seed); -#ifndef QUIET +#ifndef KISSAT_QUIET limits *limits = &solver->limits; limited *limited = &solver->limited; if (!limited->conflicts && !limited->decisions) @@ -127,7 +129,7 @@ static void stop_search (kissat *solver) { } static void report_search_result (kissat *solver, int res) { -#ifndef QUIET +#ifndef KISSAT_QUIET LOG ("search result %d", res); char type = (res == 10 ? '1' : res == 20 ? '0' : '?'); REPORT (0, type); @@ -137,7 +139,7 @@ static void report_search_result (kissat *solver, int res) { } static void iterate (kissat *solver) { - assert (solver->iterating); + KISSAT_assert (solver->iterating); solver->iterating = false; REPORT (0, 'i'); } @@ -145,22 +147,22 @@ static void iterate (kissat *solver) { static bool conflict_limit_hit (kissat *solver) { if (!solver->limited.conflicts) return false; - if (solver->limits.conflicts > solver->statistics.conflicts) + if (solver->limits.conflicts > solver->statistics_.conflicts) return false; kissat_very_verbose ( solver, "conflict limit %" PRIu64 " hit after %" PRIu64 " conflicts", - solver->limits.conflicts, solver->statistics.conflicts); + solver->limits.conflicts, solver->statistics_.conflicts); return true; } static bool decision_limit_hit (kissat *solver) { if (!solver->limited.decisions) return false; - if (solver->limits.decisions > solver->statistics.decisions) + if (solver->limits.decisions > solver->statistics_.decisions) return false; kissat_very_verbose ( solver, "decision limit %" PRIu64 " hit after %" PRIu64 " decisions", - solver->limits.decisions, solver->statistics.decisions); + solver->limits.decisions, solver->statistics_.decisions); return true; } @@ -227,3 +229,5 @@ int kissat_search (kissat *solver) { report_search_result (solver, res); return res; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/search.h b/src/sat/kissat/search.h index b7f17f894..33645269e 100644 --- a/src/sat/kissat/search.h +++ b/src/sat/kissat/search.h @@ -1,8 +1,13 @@ #ifndef _search_h_INCLUDED #define _search_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; int kissat_search (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/shrink.c b/src/sat/kissat/shrink.c index d0614df97..e368cc8bc 100644 --- a/src/sat/kissat/shrink.c +++ b/src/sat/kissat/shrink.c @@ -3,6 +3,8 @@ #include "inline.h" #include "minimize.h" +ABC_NAMESPACE_IMPL_START + static void reset_shrinkable (kissat *solver) { #ifdef LOGGING size_t reset = 0; @@ -10,7 +12,7 @@ static void reset_shrinkable (kissat *solver) { while (!EMPTY_STACK (solver->shrinkable)) { const unsigned idx = POP_STACK (solver->shrinkable); assigned *a = solver->assigned + idx; - assert (a->shrinkable); + KISSAT_assert (a->shrinkable); a->shrinkable = false; #ifdef LOGGING reset++; @@ -27,9 +29,9 @@ static void mark_shrinkable_as_removable (kissat *solver) { while (!EMPTY_STACK (solver->shrinkable)) { const unsigned idx = POP_STACK (solver->shrinkable); struct assigned *a = assigned + idx; - assert (a->shrinkable); + KISSAT_assert (a->shrinkable); a->shrinkable = false; - assert (!a->poisoned); + KISSAT_assert (!a->poisoned); #ifdef LOGGING reset++; #endif @@ -46,12 +48,12 @@ static void mark_shrinkable_as_removable (kissat *solver) { static inline int shrink_literal (kissat *solver, assigned *assigned, unsigned level, unsigned lit) { - assert (solver->assigned == assigned); - assert (VALUE (lit) < 0); + KISSAT_assert (solver->assigned == assigned); + KISSAT_assert (VALUE (lit) < 0); const unsigned idx = IDX (lit); struct assigned *a = assigned + idx; - assert (a->level <= level); + KISSAT_assert (a->level <= level); if (!a->level) { LOG2 ("skipping root level assigned %s", LOGLIT (lit)); return 0; @@ -84,17 +86,17 @@ static inline int shrink_literal (kissat *solver, assigned *assigned, static inline unsigned shrunken_block (kissat *solver, unsigned level, unsigned *begin_block, unsigned *end_block, unsigned uip) { - assert (uip != INVALID_LIT); + KISSAT_assert (uip != INVALID_LIT); const unsigned not_uip = NOT (uip); LOG ("found unique implication point %s on level %u", LOGLIT (uip), level); - assert (begin_block < end_block); -#if defined(LOGGING) || !defined(NDEBUG) + KISSAT_assert (begin_block < end_block); +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) const size_t tmp = end_block - begin_block; LOG ("shrinking %zu literals on level %u to single literal %s", tmp, level, LOGLIT (not_uip)); - assert (tmp > 1); + KISSAT_assert (tmp > 1); #endif #ifdef LOGGING @@ -116,7 +118,7 @@ static inline unsigned shrunken_block (kissat *solver, unsigned level, block_shrunken++; } *begin_block = not_uip; - assert (block_shrunken); + KISSAT_assert (block_shrunken); block_shrunken--; #ifdef LOGGING if (not_uip_was_in_clause) @@ -143,17 +145,17 @@ static inline void push_literals_of_block (kissat *solver, unsigned *begin_block, unsigned *end_block, unsigned level) { - assert (assigned == solver->assigned); + KISSAT_assert (assigned == solver->assigned); for (const unsigned *p = begin_block; p != end_block; p++) { const unsigned lit = *p; if (lit == INVALID_LIT) continue; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG int tmp = #endif shrink_literal (solver, assigned, level, lit); - assert (tmp > 0); + KISSAT_assert (tmp > 0); } } @@ -161,7 +163,7 @@ static inline unsigned shrink_along_binary (kissat *solver, assigned *assigned, unsigned level, unsigned uip, unsigned other) { - assert (VALUE (other) < 0); + KISSAT_assert (VALUE (other) < 0); LOGBINARY2 (uip, other, "shrinking along %s reason", LOGLIT (uip)); int tmp = shrink_literal (solver, assigned, level, other); #ifndef LOGGING @@ -181,7 +183,7 @@ shrink_along_large (kissat *solver, assigned *assigned, unsigned level, for (all_literals_in_clause (other, c)) { if (other == uip) continue; - assert (VALUE (other) < 0); + KISSAT_assert (VALUE (other) < 0); int tmp = shrink_literal (solver, assigned, level, other); if (tmp < 0) { *failed_ptr = true; @@ -201,9 +203,9 @@ static inline unsigned shrink_along_reason (kissat *solver, unsigned open = 0; const unsigned uip_idx = IDX (uip); struct assigned *a = assigned + uip_idx; - assert (a->shrinkable); - assert (a->level == level); - assert (a->reason != DECISION_REASON); + KISSAT_assert (a->shrinkable); + KISSAT_assert (a->level == level); + KISSAT_assert (a->reason != DECISION_REASON); if (a->binary) { const unsigned other = a->reason; open = shrink_along_binary (solver, assigned, level, uip, other); @@ -223,7 +225,7 @@ static inline unsigned shrink_along_reason (kissat *solver, static inline unsigned shrink_block (kissat *solver, unsigned *begin_block, unsigned *end_block, unsigned level, unsigned max_trail) { - assert (level < solver->level); + KISSAT_assert (level < solver->level); unsigned open = end_block - begin_block; @@ -234,7 +236,7 @@ static inline unsigned shrink_block (kissat *solver, unsigned *begin_block, push_literals_of_block (solver, assigned, begin_block, end_block, level); - assert (SIZE_STACK (solver->shrinkable) == open); + KISSAT_assert (SIZE_STACK (solver->shrinkable) == open); const unsigned *const begin_trail = BEGIN_ARRAY (solver->trail); @@ -247,14 +249,14 @@ static inline unsigned shrink_block (kissat *solver, unsigned *begin_block, while (!failed) { { do - assert (begin_trail <= t), uip = *t--; + KISSAT_assert (begin_trail <= t), uip = *t--; while (!assigned[IDX (uip)].shrinkable); } if (open == 1) break; open += shrink_along_reason (solver, assigned, level, uip, resolve_large_clauses, &failed); - assert (open > 1); + KISSAT_assert (open > 1); open--; } @@ -280,7 +282,7 @@ static unsigned *next_block (kissat *solver, unsigned *begin_lits, while (begin_lits < begin_block) { const unsigned lit = begin_block[-1]; - assert (lit != INVALID_LIT); + KISSAT_assert (lit != INVALID_LIT); const unsigned idx = IDX (lit); struct assigned *a = assigned + idx; unsigned lit_level = a->level; @@ -288,7 +290,7 @@ static unsigned *next_block (kissat *solver, unsigned *begin_lits, level = lit_level; LOG ("starting to shrink level %u", level); } else { - assert (lit_level >= level); + KISSAT_assert (lit_level >= level); if (lit_level > level) break; } @@ -310,7 +312,7 @@ static unsigned minimize_block (kissat *solver, unsigned *begin_block, for (unsigned *p = begin_block; p != end_block; p++) { const unsigned lit = *p; - assert (lit != INVALID_LIT); + KISSAT_assert (lit != INVALID_LIT); if (!kissat_minimize_literal (solver, lit, true)) continue; LOG ("minimize-shrunken literal %s", LOGLIT (lit)); @@ -325,7 +327,7 @@ static inline unsigned * minimize_and_shrink_block (kissat *solver, unsigned *begin_lits, unsigned *end_block, unsigned *total_shrunken, unsigned *total_minimized) { - assert (EMPTY_STACK (solver->shrinkable)); + KISSAT_assert (EMPTY_STACK (solver->shrinkable)); unsigned level, max_trail; @@ -333,7 +335,7 @@ minimize_and_shrink_block (kissat *solver, unsigned *begin_lits, next_block (solver, begin_lits, end_block, &level, &max_trail); unsigned open = end_block - begin_block; - assert (open > 0); + KISSAT_assert (open > 0); unsigned block_shrunken = 0; unsigned block_minimized = 0; @@ -358,9 +360,9 @@ minimize_and_shrink_block (kissat *solver, unsigned *begin_lits, } void kissat_shrink_clause (kissat *solver) { - assert (GET_OPTION (minimize) > 0); - assert (GET_OPTION (shrink) > 0); - assert (!EMPTY_STACK (solver->clause)); + KISSAT_assert (GET_OPTION (minimize) > 0); + KISSAT_assert (GET_OPTION (shrink) > 0); + KISSAT_assert (!EMPTY_STACK (solver->clause)); START (shrink); @@ -383,7 +385,7 @@ void kissat_shrink_clause (kissat *solver) { } LOG ("clause shrunken by %u literals (including %u minimized)", total_shrunken, total_minimized); - assert (q + total_shrunken == end_lits); + KISSAT_assert (q + total_shrunken == end_lits); SET_END_OF_STACK (solver->clause, q); ADD (literals_shrunken, total_shrunken); ADD (literals_minshrunken, total_minimized); @@ -393,3 +395,5 @@ void kissat_shrink_clause (kissat *solver) { STOP (shrink); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/shrink.h b/src/sat/kissat/shrink.h index 662df06ee..f50fc911c 100644 --- a/src/sat/kissat/shrink.h +++ b/src/sat/kissat/shrink.h @@ -1,8 +1,13 @@ #ifndef _shrink_h_INCLUDED #define _shrink_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_shrink_clause (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/smooth.c b/src/sat/kissat/smooth.c index 487680f06..6129a7b83 100644 --- a/src/sat/kissat/smooth.c +++ b/src/sat/kissat/smooth.c @@ -2,16 +2,18 @@ #include "internal.h" #include "logging.h" +ABC_NAMESPACE_IMPL_START + void kissat_init_smooth (kissat *solver, smooth *smooth, int window, const char *name) { - assert (window > 0); + KISSAT_assert (window > 0); const double alpha = 1.0 / window; LOG ("initialized %s EMA alpha %g window %d", name, alpha, window); smooth->value = 0; smooth->biased = 0; smooth->alpha = alpha; smooth->beta = 1.0 - alpha; - assert (smooth->beta > 0); + KISSAT_assert (smooth->beta > 0); smooth->exp = 1.0; #ifdef LOGGING smooth->name = name; @@ -42,7 +44,7 @@ void kissat_update_smooth (kissat *solver, smooth *smooth, double y) { double new_exp, div, new_value; if (old_exp) { new_exp = old_exp * beta; - assert (new_exp < 1); + KISSAT_assert (new_exp < 1); if (new_exp == old_exp) { new_exp = 0; new_value = new_biased; @@ -51,7 +53,7 @@ void kissat_update_smooth (kissat *solver, smooth *smooth, double y) { #endif } else { div = 1 - new_exp; - assert (div > 0); + KISSAT_assert (div > 0); new_value = new_biased / div; } smooth->exp = new_exp; @@ -71,3 +73,5 @@ void kissat_update_smooth (kissat *solver, smooth *smooth, double y) { (void) solver; #endif } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/smooth.h b/src/sat/kissat/smooth.h index 11f2efe9f..2fe4f1464 100644 --- a/src/sat/kissat/smooth.h +++ b/src/sat/kissat/smooth.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef struct smooth smooth; struct smooth { @@ -19,4 +22,6 @@ void kissat_init_smooth (struct kissat *, smooth *, int window, const char *); void kissat_update_smooth (struct kissat *, smooth *, double); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/sort.c b/src/sat/kissat/sort.c index ba1ea32b2..943a67ee4 100644 --- a/src/sat/kissat/sort.c +++ b/src/sat/kissat/sort.c @@ -1,13 +1,15 @@ #include "internal.h" #include "logging.h" +ABC_NAMESPACE_IMPL_START + static inline value move_smallest_literal_to_front (kissat *solver, const value *const values, const assigned *const assigned, bool satisfied_is_enough, unsigned start, unsigned size, unsigned *lits) { - assert (1 < size); - assert (start < size); + KISSAT_assert (1 < size); + KISSAT_assert (start < size); unsigned a = lits[start]; @@ -21,7 +23,7 @@ move_smallest_literal_to_front (kissat *solver, const value *const values, const unsigned i = IDX (a); unsigned k = (u ? assigned[i].level : UINT_MAX); - assert (start < UINT_MAX); + KISSAT_assert (start < UINT_MAX); for (unsigned i = start + 1; i < size; i++) { const unsigned b = lits[i]; const value v = values[b]; @@ -43,12 +45,12 @@ move_smallest_literal_to_front (kissat *solver, const value *const values, else if (u > 0 && v < 0) better = false; else if (u < 0) { - assert (v < 0); + KISSAT_assert (v < 0); better = (k < l); } else { - assert (u > 0); - assert (v > 0); - assert (!satisfied_is_enough); + KISSAT_assert (u > 0); + KISSAT_assert (v > 0); + KISSAT_assert (!satisfied_is_enough); better = (k > l); } @@ -96,3 +98,5 @@ static inline move_smallest_literal_to_front (solver, values, assigned, (u >= 0), 1, size, lits); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/sort.h b/src/sat/kissat/sort.h index 9e0e6ee94..a21aa4bba 100644 --- a/src/sat/kissat/sort.h +++ b/src/sat/kissat/sort.h @@ -3,6 +3,9 @@ #include "utilities.h" +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define GREATER_SWAP(TYPE, P, Q, LESS) \ do { \ if (LESS (Q, P)) \ @@ -40,8 +43,8 @@ #define QUICK_SORT(TYPE, N, A, LESS) \ do { \ - assert (N); \ - assert (EMPTY_STACK (SORTER)); \ + KISSAT_assert (N); \ + KISSAT_assert (EMPTY_STACK (SORTER)); \ \ size_t L_QUICK_SORT = 0; \ size_t R_QUICK_SORT = N - 1; \ @@ -61,8 +64,8 @@ size_t I_QUICK_SORT; \ \ PARTITION (TYPE, L_QUICK_SORT + 1, R_QUICK_SORT - 1, A, LESS); \ - assert (L_QUICK_SORT < I_QUICK_SORT); \ - assert (I_QUICK_SORT <= R_QUICK_SORT); \ + KISSAT_assert (L_QUICK_SORT < I_QUICK_SORT); \ + KISSAT_assert (I_QUICK_SORT <= R_QUICK_SORT); \ \ size_t LL_QUICK_SORT; \ size_t RR_QUICK_SORT; \ @@ -77,7 +80,7 @@ L_QUICK_SORT = I_QUICK_SORT + 1; \ } \ if (R_QUICK_SORT - L_QUICK_SORT > QUICK_SORT_LIMIT) { \ - assert (RR_QUICK_SORT - LL_QUICK_SORT > QUICK_SORT_LIMIT); \ + KISSAT_assert (RR_QUICK_SORT - LL_QUICK_SORT > QUICK_SORT_LIMIT); \ PUSH_STACK (SORTER, LL_QUICK_SORT); \ PUSH_STACK (SORTER, RR_QUICK_SORT); \ } else if (RR_QUICK_SORT - LL_QUICK_SORT > QUICK_SORT_LIMIT) { \ @@ -116,7 +119,7 @@ } \ } while (0) -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG #define CHECK_SORTED(...) \ do { \ } while (0) @@ -125,7 +128,7 @@ do { \ for (size_t I_CHECK_SORTED = 0; I_CHECK_SORTED < N - 1; \ I_CHECK_SORTED++) \ - assert (!LESS (A[I_CHECK_SORTED + 1], A[I_CHECK_SORTED])); \ + KISSAT_assert (!LESS (A[I_CHECK_SORTED + 1], A[I_CHECK_SORTED])); \ } while (0) #endif @@ -151,4 +154,6 @@ SORT (TYPE, N_SORT_STACK, A_SORT_STACK, LESS); \ } while (0) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/stack.c b/src/sat/kissat/stack.c index 4fc7f3352..30689adc8 100644 --- a/src/sat/kissat/stack.c +++ b/src/sat/kissat/stack.c @@ -4,10 +4,12 @@ #include +ABC_NAMESPACE_IMPL_START + void kissat_stack_enlarge (struct kissat *solver, chars *s, size_t bytes) { const size_t size = SIZE_STACK (*s); const size_t old_bytes = CAPACITY_STACK (*s); - assert (MAX_SIZE_T / 2 >= old_bytes); + KISSAT_assert (MAX_SIZE_T / 2 >= old_bytes); size_t new_bytes; if (old_bytes) new_bytes = 2 * old_bytes; @@ -16,19 +18,19 @@ void kissat_stack_enlarge (struct kissat *solver, chars *s, size_t bytes) { while (!kissat_aligned_word (new_bytes)) new_bytes <<= 1; } - s->begin = kissat_realloc (solver, s->begin, old_bytes, new_bytes); + s->begin = (char*)kissat_realloc (solver, s->begin, old_bytes, new_bytes); s->allocated = s->begin + new_bytes; s->end = s->begin + size; } void kissat_shrink_stack (struct kissat *solver, chars *s, size_t bytes) { - assert (bytes > 0); + KISSAT_assert (bytes > 0); const size_t old_bytes_capacity = CAPACITY_STACK (*s); - assert (kissat_aligned_word (old_bytes_capacity)); - assert (!(old_bytes_capacity % bytes)); - assert (kissat_is_zero_or_power_of_two (old_bytes_capacity / bytes)); + KISSAT_assert (kissat_aligned_word (old_bytes_capacity)); + KISSAT_assert (!(old_bytes_capacity % bytes)); + KISSAT_assert (kissat_is_zero_or_power_of_two (old_bytes_capacity / bytes)); const size_t old_bytes_size = SIZE_STACK (*s); - assert (!(old_bytes_size % bytes)); + KISSAT_assert (!(old_bytes_size % bytes)); const size_t old_size = old_bytes_size / bytes; size_t new_capacity; if (old_size) { @@ -36,16 +38,18 @@ void kissat_shrink_stack (struct kissat *solver, chars *s, size_t bytes) { new_capacity = ((size_t) 1) << ld_old_size; } else new_capacity = 0; - assert (kissat_is_zero_or_power_of_two (new_capacity)); + KISSAT_assert (kissat_is_zero_or_power_of_two (new_capacity)); size_t new_bytes_capacity = new_capacity * bytes; while (!kissat_aligned_word (new_bytes_capacity)) new_bytes_capacity <<= 1; if (new_bytes_capacity == old_bytes_capacity) return; - assert (new_bytes_capacity < old_bytes_capacity); - s->begin = kissat_realloc (solver, s->begin, old_bytes_capacity, + KISSAT_assert (new_bytes_capacity < old_bytes_capacity); + s->begin = (char*)kissat_realloc (solver, s->begin, old_bytes_capacity, new_bytes_capacity); s->allocated = s->begin + new_bytes_capacity; s->end = s->begin + old_bytes_size; - assert (s->end <= s->allocated); + KISSAT_assert (s->end <= s->allocated); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/stack.h b/src/sat/kissat/stack.h index 23e07f597..2024f5f3e 100644 --- a/src/sat/kissat/stack.h +++ b/src/sat/kissat/stack.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + #define STACK(TYPE) \ struct { \ TYPE *begin; \ @@ -20,21 +23,21 @@ (S).begin = (S).end = (S).allocated = 0; \ } while (0) -#define TOP_STACK(S) (END_STACK (S)[assert (!EMPTY_STACK (S)), -1]) +#define TOP_STACK(S) (END_STACK (S)[KISSAT_assert (!EMPTY_STACK (S)), -1]) #define PEEK_STACK(S, N) \ - (BEGIN_STACK (S)[assert ((N) < SIZE_STACK (S)), (N)]) + (BEGIN_STACK (S)[KISSAT_assert ((N) < SIZE_STACK (S)), (N)]) #define POKE_STACK(S, N, E) \ do { \ PEEK_STACK (S, N) = (E); \ } while (0) -#define POP_STACK(S) (assert (!EMPTY_STACK (S)), *--(S).end) +#define POP_STACK(S) (KISSAT_assert (!EMPTY_STACK (S)), *--(S).end) #define ENLARGE_STACK(S) \ do { \ - assert (FULL_STACK (S)); \ + KISSAT_assert (FULL_STACK (S)); \ kissat_stack_enlarge (solver, (chars *) &(S), sizeof *(S).begin); \ } while (0) @@ -63,14 +66,14 @@ #define RESIZE_STACK(S, NEW_SIZE) \ do { \ const size_t TMP_NEW_SIZE = (NEW_SIZE); \ - assert (TMP_NEW_SIZE <= SIZE_STACK (S)); \ + KISSAT_assert (TMP_NEW_SIZE <= SIZE_STACK (S)); \ (S).end = (S).begin + TMP_NEW_SIZE; \ } while (0) #define SET_END_OF_STACK(S, P) \ do { \ - assert (BEGIN_STACK (S) <= (P)); \ - assert ((P) <= END_STACK (S)); \ + KISSAT_assert (BEGIN_STACK (S) <= (P)); \ + KISSAT_assert ((P) <= END_STACK (S)); \ if ((P) == END_STACK (S)) \ break; \ (S).end = (P); \ @@ -84,12 +87,12 @@ #define REMOVE_STACK(T, S, E) \ do { \ - assert (!EMPTY_STACK (S)); \ + KISSAT_assert (!EMPTY_STACK (S)); \ T *END_REMOVE_STACK = END_STACK (S); \ T *P_REMOVE_STACK = BEGIN_STACK (S); \ while (*P_REMOVE_STACK != (E)) { \ P_REMOVE_STACK++; \ - assert (P_REMOVE_STACK != END_REMOVE_STACK); \ + KISSAT_assert (P_REMOVE_STACK != END_REMOVE_STACK); \ } \ P_REMOVE_STACK++; \ while (P_REMOVE_STACK != END_REMOVE_STACK) { \ @@ -137,4 +140,6 @@ void kissat_stack_enlarge (struct kissat *, chars *, size_t size_of_element); void kissat_shrink_stack (struct kissat *, chars *, size_t size_of_element); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/statistics.c b/src/sat/kissat/statistics.c index ad4bfa068..3a3c4bd3c 100644 --- a/src/sat/kissat/statistics.c +++ b/src/sat/kissat/statistics.c @@ -1,8 +1,10 @@ -#if !defined(QUIET) || !defined(NDEBUG) +#include "global.h" + +#if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG) #include "internal.h" #endif -#ifndef QUIET +#ifndef KISSAT_QUIET #include "resources.h" #include "tiers.h" @@ -344,13 +346,13 @@ kissat_statistics_print (kissat * solver, bool verbose) // clang-format on -#elif defined(NDEBUG) +#elif defined(KISSAT_NDEBUG) int kissat_statistics_dummy_to_avoid_warning; #endif /*------------------------------------------------------------------------*/ -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG #include "inlinevector.h" @@ -397,15 +399,15 @@ void kissat_check_statistics (kissat *solver) { } } - assert (!(binary & 1)); + KISSAT_assert (!(binary & 1)); binary /= 2; statistics *statistics = &solver->statistics; - assert (statistics->clauses_binary == binary); - assert (statistics->clauses_redundant == redundant); - assert (statistics->clauses_irredundant == irredundant); + KISSAT_assert (statistics->clauses_binary == binary); + KISSAT_assert (statistics->clauses_redundant == redundant); + KISSAT_assert (statistics->clauses_irredundant == irredundant); #ifdef METRICS - assert (statistics->arena_garbage == arena_garbage); + KISSAT_assert (statistics->arena_garbage == arena_garbage); #else (void) arena_garbage; #endif diff --git a/src/sat/kissat/statistics.h b/src/sat/kissat/statistics.h index 8c04f4d33..b0f4e6faf 100644 --- a/src/sat/kissat/statistics.h +++ b/src/sat/kissat/statistics.h @@ -4,6 +4,9 @@ #include #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + // clang-format off #define METRICS_COUNTERS_AND_STATISTICS \ @@ -329,12 +332,12 @@ struct statistics /*------------------------------------------------------------------------*/ #define CLAUSES (IRREDUNDANT_CLAUSES + BINARY_CLAUSES + REDUNDANT_CLAUSES) -#define CONFLICTS (solver->statistics.conflicts) -#define DECISIONS (solver->statistics.decisions) -#define IRREDUNDANT_CLAUSES (solver->statistics.clauses_irredundant) -#define LEARNED_CLAUSES (solver->statistics.learned) -#define REDUNDANT_CLAUSES (solver->statistics.clauses_redundant) -#define BINARY_CLAUSES (solver->statistics.clauses_binary) +#define CONFLICTS (solver->statistics_.conflicts) +#define DECISIONS (solver->statistics_.decisions) +#define IRREDUNDANT_CLAUSES (solver->statistics_.clauses_irredundant) +#define LEARNED_CLAUSES (solver->statistics_.learned) +#define REDUNDANT_CLAUSES (solver->statistics_.clauses_redundant) +#define BINARY_CLAUSES (solver->statistics_.clauses_binary) #define BINIRR_CLAUSES (BINARY_CLAUSES + IRREDUNDANT_CLAUSES) /*------------------------------------------------------------------------*/ @@ -342,24 +345,24 @@ struct statistics #define COUNTER(NAME, VERBOSE, OTHER, UNITS, TYPE) \ \ static inline void kissat_inc_##NAME (statistics *statistics) { \ - assert (statistics->NAME < UINT64_MAX); \ + KISSAT_assert (statistics->NAME < UINT64_MAX); \ statistics->NAME++; \ } \ \ static inline void kissat_dec_##NAME (statistics *statistics) { \ - assert (statistics->NAME); \ + KISSAT_assert (statistics->NAME); \ statistics->NAME--; \ } \ \ static inline void kissat_add_##NAME (statistics *statistics, \ uint64_t n) { \ - assert (UINT64_MAX - n >= statistics->NAME); \ + KISSAT_assert (UINT64_MAX - n >= statistics->NAME); \ statistics->NAME += n; \ } \ \ static inline void kissat_sub_##NAME (statistics *statistics, \ uint64_t n) { \ - assert (n <= statistics->NAME); \ + KISSAT_assert (n <= statistics->NAME); \ statistics->NAME -= n; \ } \ \ @@ -406,14 +409,14 @@ METRICS_COUNTERS_AND_STATISTICS // clang-format on /*------------------------------------------------------------------------*/ -#define INC(NAME) kissat_inc_##NAME (&solver->statistics) -#define DEC(NAME) kissat_dec_##NAME (&solver->statistics) -#define ADD(NAME, N) kissat_add_##NAME (&solver->statistics, (N)) -#define SUB(NAME, N) kissat_sub_##NAME (&solver->statistics, (N)) -#define GET(NAME) kissat_get_##NAME (&solver->statistics) +#define INC(NAME) kissat_inc_##NAME (&solver->statistics_) +#define DEC(NAME) kissat_dec_##NAME (&solver->statistics_) +#define ADD(NAME, N) kissat_add_##NAME (&solver->statistics_, (N)) +#define SUB(NAME, N) kissat_sub_##NAME (&solver->statistics_, (N)) +#define GET(NAME) kissat_get_##NAME (&solver->statistics_) /*------------------------------------------------------------------------*/ -#ifndef QUIET +#ifndef KISSAT_QUIET struct kissat; @@ -451,7 +454,7 @@ void kissat_print_glue_usage (struct kissat *); #endif -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG struct kissat; void kissat_check_statistics (struct kissat *); @@ -464,4 +467,6 @@ void kissat_check_statistics (struct kissat *); #endif +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/strengthen.c b/src/sat/kissat/strengthen.c index d5107d7f5..4d85b0d2a 100644 --- a/src/sat/kissat/strengthen.c +++ b/src/sat/kissat/strengthen.c @@ -3,22 +3,24 @@ #include "inline.h" #include "promote.h" +ABC_NAMESPACE_IMPL_START + static clause *large_on_the_fly_strengthen (kissat *solver, clause *c, unsigned lit) { - assert (solver->antecedent_size > 3); + KISSAT_assert (solver->antecedent_size > 3); LOGCLS (c, "large on-the-fly strengthening " "by removing %s from", LOGLIT (lit)); unsigned *lits = c->lits; - assert (lits[0] == lit || lits[1] == lit); + KISSAT_assert (lits[0] == lit || lits[1] == lit); INC (on_the_fly_strengthened); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG clause *old_next = kissat_next_clause (c); #endif if (lits[0] == lit) SWAP (unsigned, lits[0], lits[1]); - assert (lits[1] == lit); + KISSAT_assert (lits[1] == lit); const reference ref = kissat_reference_clause (solver, c); kissat_unwatch_blocking (solver, lit, ref); SHRINK_CLAUSE_IN_PROOF (c, lit, lits[0]); @@ -29,14 +31,14 @@ static clause *large_on_the_fly_strengthen (kissat *solver, clause *c, const bool irredundant = !c->redundant; for (unsigned i = 2; i < old_size; i++) { const unsigned other = lits[i]; - assert (VALUE (other) < 0); + KISSAT_assert (VALUE (other) < 0); if (!LEVEL (other)) continue; lits[new_size++] = other; if (irredundant) kissat_mark_added_literal (solver, other); } - assert (new_size > 2); + KISSAT_assert (new_size > 2); c->size = new_size; c->searched = 2; if (c->redundant && c->glue >= new_size) @@ -48,13 +50,13 @@ static clause *large_on_the_fly_strengthen (kissat *solver, clause *c, } LOGCLS (c, "unsorted on-the-fly strengthened"); { - assert (VALUE (lits[1]) < 0); + KISSAT_assert (VALUE (lits[1]) < 0); unsigned highest_pos = 1; unsigned highest_level = LEVEL (lits[1]); const unsigned size = c->size; for (unsigned i = 2; i < size; i++) { const unsigned other = lits[i]; - assert (VALUE (other) < 0); + KISSAT_assert (VALUE (other) < 0); const unsigned level = LEVEL (other); if (level <= highest_level) continue; @@ -68,17 +70,17 @@ static clause *large_on_the_fly_strengthen (kissat *solver, clause *c, } { watches *watches = &WATCHES (lits[0]); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG const watch *const end_of_watches = END_WATCHES (*watches); #endif watch *p = BEGIN_WATCHES (*watches); - assert (solver->watching); + KISSAT_assert (solver->watching); for (;;) { - assert (p != end_of_watches); + KISSAT_assert (p != end_of_watches); const watch head = *p++; if (head.type.binary) continue; - assert (p != end_of_watches); + KISSAT_assert (p != end_of_watches); const watch tail = *p++; if (tail.large.ref == ref) break; @@ -87,9 +89,9 @@ static clause *large_on_the_fly_strengthen (kissat *solver, clause *c, LOGREF (ref, "updating watching %s now blocking %s in", LOGLIT (lits[0]), LOGLIT (lits[1])); } -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG clause *new_next = kissat_next_clause (c); - assert (old_next == new_next); + KISSAT_assert (old_next == new_next); #endif LOGCLS (c, "conflicting"); return c; @@ -97,38 +99,38 @@ static clause *large_on_the_fly_strengthen (kissat *solver, clause *c, static clause *binary_on_the_fly_strengthen (kissat *solver, clause *c, unsigned lit) { - assert (solver->antecedent_size == 3); + KISSAT_assert (solver->antecedent_size == 3); LOGCLS (c, "binary on-the-fly strengthening " "by removing %s from", LOGLIT (lit)); unsigned first = INVALID_LIT, second = INVALID_LIT; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG bool found = false; #endif for (all_literals_in_clause (other, c)) { if (other == lit) { -#ifndef NDEBUG - assert (!found); +#ifndef KISSAT_NDEBUG + KISSAT_assert (!found); found = true; #endif continue; } - assert (VALUE (other) < 0); + KISSAT_assert (VALUE (other) < 0); if (!LEVEL (other)) continue; if (first == INVALID_LIT) first = other; else { - assert (second == INVALID_LIT); + KISSAT_assert (second == INVALID_LIT); second = other; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG break; #endif } } - assert (found); - assert (second != INVALID_LIT); + KISSAT_assert (found); + KISSAT_assert (second != INVALID_LIT); LOGBINARY (first, second, "on-the-fly strengthened"); kissat_new_binary_clause (solver, first, second); const reference ref = kissat_reference_clause (solver, c); @@ -141,8 +143,8 @@ static clause *binary_on_the_fly_strengthen (kissat *solver, clause *c, clause *kissat_on_the_fly_strengthen (kissat *solver, clause *c, unsigned lit) { - assert (!c->garbage); - assert (solver->antecedent_size > 2); + KISSAT_assert (!c->garbage); + KISSAT_assert (solver->antecedent_size > 2); if (!c->redundant) kissat_mark_removed_literal (solver, lit); clause *res; @@ -156,10 +158,10 @@ clause *kissat_on_the_fly_strengthen (kissat *solver, clause *c, void kissat_on_the_fly_subsume (kissat *solver, clause *c, clause *d) { LOGCLS (c, "on-the-fly subsuming"); LOGCLS (d, "on-the-fly subsumed"); - assert (c != d); - assert (!d->garbage); - assert (c->size > 1); - assert (c->size <= d->size); + KISSAT_assert (c != d); + KISSAT_assert (!d->garbage); + KISSAT_assert (c->size > 1); + KISSAT_assert (c->size <= d->size); kissat_mark_clause_as_garbage (solver, d); INC (on_the_fly_subsumed); if (d->redundant) { @@ -174,14 +176,16 @@ void kissat_on_the_fly_subsume (kissat *solver, clause *c, clause *d) { LOGCLS (c, "turned"); kissat_update_last_irredundant (solver, c); } - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; if (c->size > 2) { - assert (statistics->clauses_irredundant < UINT64_MAX); + KISSAT_assert (statistics->clauses_irredundant < UINT64_MAX); statistics->clauses_irredundant++; } else { - assert (statistics->clauses_binary < UINT64_MAX); + KISSAT_assert (statistics->clauses_binary < UINT64_MAX); statistics->clauses_binary++; } - assert (statistics->clauses_redundant > 0); + KISSAT_assert (statistics->clauses_redundant > 0); statistics->clauses_redundant--; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/strengthen.h b/src/sat/kissat/strengthen.h index 1e6a395fc..6624b684a 100644 --- a/src/sat/kissat/strengthen.h +++ b/src/sat/kissat/strengthen.h @@ -3,6 +3,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct clause; struct kissat; @@ -14,4 +17,6 @@ void kissat_on_the_fly_subsume (struct kissat *, struct clause *, bool issat_strengthen_clause (struct kissat *, struct clause *, unsigned); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/substitute.c b/src/sat/kissat/substitute.c index f95efe746..76982305c 100644 --- a/src/sat/kissat/substitute.c +++ b/src/sat/kissat/substitute.c @@ -11,6 +11,8 @@ #include +ABC_NAMESPACE_IMPL_START + static void assign_and_propagate_units (kissat *solver, unsigneds *units) { if (EMPTY_STACK (*units)) return; @@ -29,7 +31,7 @@ static void assign_and_propagate_units (kissat *solver, unsigneds *units) { } else { kissat_learned_unit (solver, unit); INC (substitute_units); - assert (!solver->level); + KISSAT_assert (!solver->level); (void) kissat_probing_propagate (solver, 0, false); } } @@ -37,8 +39,8 @@ static void assign_and_propagate_units (kissat *solver, unsigneds *units) { static void determine_representatives (kissat *solver, unsigned *repr) { size_t bytes = LITS * sizeof (unsigned); - unsigned *mark = kissat_calloc (solver, LITS, sizeof *mark); - unsigned *reach = kissat_malloc (solver, LITS * sizeof *reach); + unsigned *mark = (unsigned*)kissat_calloc (solver, LITS, sizeof *mark); + unsigned *reach = (unsigned*)kissat_malloc (solver, LITS * sizeof *reach); watches *all_watches = solver->watches; const flags *const flags = solver->flags; unsigned reached = 0; @@ -61,8 +63,8 @@ static void determine_representatives (kissat *solver, unsigned *repr) { continue; if (!ACTIVE (IDX (root))) continue; - assert (EMPTY_STACK (scc)); - assert (EMPTY_STACK (work)); + KISSAT_assert (EMPTY_STACK (scc)); + KISSAT_assert (EMPTY_STACK (work)); LOG ("substitute root %s", LOGLIT (root)); PUSH_STACK (work, root); bool failed = false; @@ -75,8 +77,8 @@ static void determine_representatives (kissat *solver, unsigned *repr) { const unsigned not_lit = NOT (lit); unsigned reach_lit = reach[lit]; unsigned mark_lit = mark[lit]; - assert (reach_lit == mark_lit); - assert (repr[lit] == INVALID_LIT); + KISSAT_assert (reach_lit == mark_lit); + KISSAT_assert (repr[lit] == INVALID_LIT); watches *watches = all_watches + not_lit; const size_t size_watches = SIZE_WATCHES (*watches); ticks += 1 + kissat_cache_lines (size_watches, sizeof (watch)); @@ -87,7 +89,7 @@ static void determine_representatives (kissat *solver, unsigned *repr) { const unsigned idx_other = IDX (other); if (!flags[idx_other].active) continue; - assert (mark[other]); + KISSAT_assert (mark[other]); unsigned reach_other = reach[other]; if (reach_other < reach_lit) reach_lit = reach_other; @@ -100,7 +102,7 @@ static void determine_representatives (kissat *solver, unsigned *repr) { unsigned *end_scc = END_STACK (scc); unsigned *begin_scc = end_scc; do - assert (begin_scc != BEGIN_STACK (scc)); + KISSAT_assert (begin_scc != BEGIN_STACK (scc)); while (*--begin_scc != lit); SET_END_OF_STACK (scc, begin_scc); const size_t size_scc = end_scc - begin_scc; @@ -121,7 +123,7 @@ static void determine_representatives (kissat *solver, unsigned *repr) { trivial_sccs++; #endif LOG ("trivial size one SCC with %s", LOGLIT (lit)); - assert (min_lit == lit); + KISSAT_assert (min_lit == lit); } for (const unsigned *p = begin_scc; p != end_scc; p++) { const unsigned other = *p; @@ -141,12 +143,12 @@ static void determine_representatives (kissat *solver, unsigned *repr) { inconsistent = true; break; } - assert (NOT (min_lit) == repr_not_other); + KISSAT_assert (NOT (min_lit) == repr_not_other); if (failed) continue; const unsigned mark_not_other = mark[not_other]; - assert (mark_not_other != INVALID_LIT); - assert (mark[root] == mark_root); + KISSAT_assert (mark_not_other != INVALID_LIT); + KISSAT_assert (mark[root] == mark_root); if (mark_root > mark_not_other) continue; LOG ("root %s implies both %s and %s", LOGLIT (root), @@ -193,7 +195,7 @@ static void determine_representatives (kissat *solver, unsigned *repr) { LOG ("found %u trivial SCCs", trivial_sccs); LOG ("found %zu units", SIZE_STACK (units)); assign_and_propagate_units (solver, &units); - assert (!inconsistent || solver->inconsistent); + KISSAT_assert (!inconsistent || solver->inconsistent); RELEASE_STACK (units); kissat_free (solver, reach, bytes); kissat_free (solver, mark, bytes); @@ -206,7 +208,7 @@ static bool *add_representative_equivalences (kissat *solver, unsigned *repr) { if (solver->inconsistent) return 0; - bool *eliminate = kissat_calloc (solver, VARS, sizeof *eliminate); + bool *eliminate = (bool*)kissat_calloc (solver, VARS, sizeof *eliminate); for (all_variables (idx)) { if (!ACTIVE (idx)) continue; @@ -214,7 +216,7 @@ static bool *add_representative_equivalences (kissat *solver, const unsigned other = repr[lit]; if (lit == other) continue; - assert (other < lit); + KISSAT_assert (other < lit); #ifdef CHECKING_OR_PROVING const unsigned not_lit = NOT (lit); const unsigned not_other = NOT (other); @@ -240,14 +242,14 @@ static void remove_representative_equivalences (kissat *solver, if (!eliminate[idx]) continue; - assert (ACTIVE (idx)); + KISSAT_assert (ACTIVE (idx)); const unsigned lit = LIT (idx); const unsigned other = repr[lit]; const unsigned not_lit = NOT (lit); const unsigned not_other = NOT (other); - assert (other < lit); - assert (not_other < not_lit); + KISSAT_assert (other < lit); + KISSAT_assert (not_other < not_lit); REMOVE_CHECKER_BINARY (not_lit, other); DELETE_BINARY_FROM_PROOF (not_lit, other); @@ -276,7 +278,7 @@ static void remove_representative_equivalences (kissat *solver, static void substitute_binaries (kissat *solver, unsigned *repr) { if (solver->inconsistent) return; - assert (sizeof (watch) == sizeof (unsigned)); + KISSAT_assert (sizeof (watch) == sizeof (unsigned)); statches *delayed_watched = (statches *) &solver->delayed; watches *all_watches = solver->watches; #ifdef LOGGING @@ -294,7 +296,7 @@ static void substitute_binaries (kissat *solver, unsigned *repr) { for (all_literals (lit)) { const unsigned repr_lit = repr[lit]; const unsigned not_repr_lit = NOT (repr_lit); - assert (EMPTY_STACK (*delayed_watched)); + KISSAT_assert (EMPTY_STACK (*delayed_watched)); watches *watches = all_watches + lit; watch *begin = BEGIN_WATCHES (*watches), *q = begin; const watch *const end = END_WATCHES (*watches), *p = q; @@ -366,7 +368,7 @@ static void substitute_binaries (kissat *solver, unsigned *repr) { for (all_stack (litwatch, litwatch, delayed_deleted)) { const unsigned lit = litwatch.lit; const watch watch = litwatch.watch; - assert (watch.type.binary); + KISSAT_assert (watch.type.binary); const unsigned other = watch.binary.lit; kissat_delete_binary (solver, lit, other); } @@ -401,7 +403,7 @@ static void substitute_clauses (kissat *solver, unsigned *repr) { if (c->garbage) continue; LOGCLS (c, "substituting"); - assert (EMPTY_STACK (solver->clause)); + KISSAT_assert (EMPTY_STACK (solver->clause)); bool shrink = false; bool satisfied = false; bool substitute = false; @@ -433,7 +435,7 @@ static void substitute_clauses (kissat *solver, unsigned *repr) { break; } if (lit != repr_lit) { - assert (!values[repr_lit]); + KISSAT_assert (!values[repr_lit]); LOG ("substituted literal %s (was %s)", LOGLIT (repr_lit), LOGLIT (lit)); substitute = true; @@ -471,7 +473,7 @@ static void substitute_clauses (kissat *solver, unsigned *repr) { solver->inconsistent = true; break; } else if (size == 1) { - assert (shrink); + KISSAT_assert (shrink); #ifdef LOGGING removed++; #endif @@ -481,7 +483,7 @@ static void substitute_clauses (kissat *solver, unsigned *repr) { const reference ref = kissat_reference_clause (solver, c); PUSH_STACK (delayed_garbage, ref); } else if (size == 2) { - assert (shrink); + KISSAT_assert (shrink); #ifdef LOGGING substituted++; #endif @@ -509,16 +511,16 @@ static void substitute_clauses (kissat *solver, unsigned *repr) { const unsigned old_size = c->size; unsigned *old_lits = c->lits; - assert (new_size <= old_size); + KISSAT_assert (new_size <= old_size); memcpy (old_lits, new_lits, new_size * sizeof *old_lits); - assert (shrink == (new_size < old_size)); + KISSAT_assert (shrink == (new_size < old_size)); if (new_size < old_size) { c->size = new_size; c->searched = 2; if (!c->shrunken) { c->shrunken = true; - assert (c->lits == old_lits); + KISSAT_assert (c->lits == old_lits); old_lits[old_size - 1] = INVALID_LIT; } } @@ -542,10 +544,10 @@ static void substitute_clauses (kissat *solver, unsigned *repr) { } static bool substitute_round (kissat *solver, unsigned round) { - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); const unsigned active = solver->active; size_t bytes = LITS * sizeof (unsigned); - unsigned *repr = kissat_malloc (solver, bytes); + unsigned *repr = (unsigned*)kissat_malloc (solver, bytes); memset (repr, 0xff, bytes); determine_representatives (solver, repr); bool *eliminate = add_representative_equivalences (solver, repr); @@ -559,7 +561,7 @@ static bool substitute_round (kissat *solver, unsigned round) { kissat_percent (removed, active)); kissat_check_statistics (solver); REPORT (!removed, 'd'); -#ifdef QUIET +#ifdef KISSAT_QUIET (void) round; #endif return !solver->inconsistent && removed; @@ -570,14 +572,14 @@ static void substitute_rounds (kissat *solver, bool complete) { INC (substitutions); const unsigned maxrounds = GET_OPTION (substituterounds); for (unsigned round = 1; round <= maxrounds; round++) { - const uint64_t before = solver->statistics.substitute_ticks; + const uint64_t before = solver->statistics_.substitute_ticks; if (!substitute_round (solver, round)) break; - const uint64_t after = solver->statistics.substitute_ticks; + const uint64_t after = solver->statistics_.substitute_ticks; const uint64_t ticks = after - before; if (!complete) { const uint64_t reference = - solver->statistics.search_ticks - solver->last.ticks.probe; + solver->statistics_.search_ticks - solver->last.ticks.probe; const double fraction = GET_OPTION (substituteeffort) * 1e-3; const uint64_t limit = fraction * reference; if (ticks > limit) { @@ -595,7 +597,7 @@ static void substitute_rounds (kissat *solver, bool complete) { LOG ("now all large clauses are watched after binary clauses"); solver->large_clauses_watched_after_binary_clauses = true; kissat_reset_propagate (solver); - assert (!solver->level); + KISSAT_assert (!solver->level); (void) kissat_probing_propagate (solver, 0, true); } STOP (substitute); @@ -604,9 +606,9 @@ static void substitute_rounds (kissat *solver, bool complete) { void kissat_substitute (kissat *solver, bool complete) { if (solver->inconsistent) return; - assert (solver->probing); - assert (solver->watching); - assert (!solver->level); + KISSAT_assert (solver->probing); + KISSAT_assert (solver->watching); + KISSAT_assert (!solver->level); LOG ("assuming not all large clauses watched after binary clauses"); solver->large_clauses_watched_after_binary_clauses = false; if (!GET_OPTION (substitute)) @@ -615,3 +617,5 @@ void kissat_substitute (kissat *solver, bool complete) { return; substitute_rounds (solver, complete); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/substitute.h b/src/sat/kissat/substitute.h index 63a464ee9..bf2f39b51 100644 --- a/src/sat/kissat/substitute.h +++ b/src/sat/kissat/substitute.h @@ -3,8 +3,13 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_substitute (struct kissat *, bool complete); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/sweep.c b/src/sat/kissat/sweep.c index 866867112..42420cc54 100644 --- a/src/sat/kissat/sweep.c +++ b/src/sat/kissat/sweep.c @@ -15,6 +15,8 @@ #include #include +ABC_NAMESPACE_IMPL_START + struct sweeper { kissat *solver; unsigned *depths; @@ -53,18 +55,18 @@ static int sweep_solve (sweeper *sweeper) { static void set_kitten_ticks_limit (sweeper *sweeper) { uint64_t remaining = 0; kissat *solver = sweeper->solver; - if (solver->statistics.kitten_ticks < sweeper->limit.ticks) - remaining = sweeper->limit.ticks - solver->statistics.kitten_ticks; + if (solver->statistics_.kitten_ticks < sweeper->limit.ticks) + remaining = sweeper->limit.ticks - solver->statistics_.kitten_ticks; LOG ("'kitten_ticks' remaining %" PRIu64, remaining); kitten_set_ticks_limit (solver->kitten, remaining); } static bool kitten_ticks_limit_hit (sweeper *sweeper, const char *when) { kissat *solver = sweeper->solver; - if (solver->statistics.kitten_ticks >= sweeper->limit.ticks) { + if (solver->statistics_.kitten_ticks >= sweeper->limit.ticks) { LOG ("'kitten_ticks' limit of %" PRIu64 " ticks hit after %" PRIu64 " ticks during %s", - sweeper->limit.ticks, solver->statistics.kitten_ticks, when); + sweeper->limit.ticks, solver->statistics_.kitten_ticks, when); return true; } #ifndef LOGGING @@ -76,19 +78,19 @@ static bool kitten_ticks_limit_hit (sweeper *sweeper, const char *when) { static void init_sweeper (kissat *solver, sweeper *sweeper) { sweeper->solver = solver; sweeper->encoded = 0; - CALLOC (sweeper->depths, VARS); - NALLOC (sweeper->reprs, LITS); + CALLOC (unsigned, sweeper->depths, VARS); + NALLOC (unsigned, sweeper->reprs, LITS); for (all_literals (lit)) sweeper->reprs[lit] = lit; - NALLOC (sweeper->prev, VARS); + NALLOC (unsigned, sweeper->prev, VARS); memset (sweeper->prev, 0xff, VARS * sizeof *sweeper->prev); - NALLOC (sweeper->next, VARS); + NALLOC (unsigned, sweeper->next, VARS); memset (sweeper->next, 0xff, VARS * sizeof *sweeper->next); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG for (all_variables (idx)) - assert (sweeper->prev[idx] == INVALID_IDX); + KISSAT_assert (sweeper->prev[idx] == INVALID_IDX); for (all_variables (idx)) - assert (sweeper->next[idx] == INVALID_IDX); + KISSAT_assert (sweeper->next[idx] == INVALID_IDX); #endif sweeper->first = sweeper->last = INVALID_IDX; INIT_STACK (sweeper->vars); @@ -98,13 +100,13 @@ static void init_sweeper (kissat *solver, sweeper *sweeper) { INIT_STACK (sweeper->partition); INIT_STACK (sweeper->core[0]); INIT_STACK (sweeper->core[1]); - assert (!solver->kitten); + KISSAT_assert (!solver->kitten); solver->kitten = kitten_embedded (solver); kitten_track_antecedents (solver->kitten); kissat_enter_dense_mode (solver, 0); kissat_connect_irredundant_large_clauses (solver); - unsigned completed = solver->statistics.sweep_completed; + unsigned completed = solver->statistics_.sweep_completed; const unsigned max_completed = 32; if (completed > max_completed) completed = max_completed; @@ -118,7 +120,7 @@ static void init_sweeper (kissat *solver, sweeper *sweeper) { kissat_extremely_verbose (solver, "sweeper variable limit %u", sweeper->limit.vars); - uint64_t depth_limit = solver->statistics.sweep_completed; + uint64_t depth_limit = solver->statistics_.sweep_completed; depth_limit += GET_OPTION (sweepdepth); const unsigned max_depth = GET_OPTION (sweepmaxdepth); if (depth_limit > max_depth) @@ -180,13 +182,13 @@ static void clear_sweeper (sweeper *sweeper) { kitten_clear (solver->kitten); kitten_track_antecedents (solver->kitten); for (all_stack (unsigned, idx, sweeper->vars)) { - assert (sweeper->depths[idx]); + KISSAT_assert (sweeper->depths[idx]); sweeper->depths[idx] = 0; } CLEAR_STACK (sweeper->vars); for (all_stack (reference, ref, sweeper->refs)) { clause *c = kissat_dereference_clause (solver, ref); - assert (c->swept); + KISSAT_assert (c->swept); c->swept = false; } CLEAR_STACK (sweeper->refs); @@ -205,7 +207,7 @@ static unsigned sweep_repr (sweeper *sweeper, unsigned lit) { } if (res == lit) return res; -#if defined(LOGGING) || !defined(NDEBUG) +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) kissat *solver = sweeper->solver; #endif LOG ("sweeping repr[%s] = %s", LOGLIT (lit), LOGLIT (res)); @@ -219,7 +221,7 @@ static unsigned sweep_repr (sweeper *sweeper, unsigned lit) { sweeper->reprs[prev] = res; prev = next; } - assert (sweeper->reprs[NOT (prev)] == not_res); + KISSAT_assert (sweeper->reprs[NOT (prev)] == not_res); } return res; } @@ -233,7 +235,7 @@ static void add_literal_to_environment (sweeper *sweeper, unsigned depth, const unsigned idx = IDX (lit); if (sweeper->depths[idx]) return; - assert (depth < UINT_MAX); + KISSAT_assert (depth < UINT_MAX); sweeper->depths[idx] = depth + 1; PUSH_STACK (sweeper->vars, idx); LOG ("sweeping[%u] adding literal %s", depth, LOGLIT (lit)); @@ -241,7 +243,7 @@ static void add_literal_to_environment (sweeper *sweeper, unsigned depth, static void sweep_clause (sweeper *sweeper, unsigned depth) { kissat *solver = sweeper->solver; - assert (SIZE_STACK (sweeper->clause) > 1); + KISSAT_assert (SIZE_STACK (sweeper->clause) > 1); for (all_stack (unsigned, lit, sweeper->clause)) add_literal_to_environment (sweeper, depth, lit); kitten_clause (solver->kitten, SIZE_STACK (sweeper->clause), @@ -259,7 +261,7 @@ static void sweep_binary (sweeper *sweeper, unsigned depth, unsigned lit, kissat *solver = sweeper->solver; LOGBINARY (lit, other, "sweeping[%u]", depth); value *values = solver->values; - assert (!values[lit]); + KISSAT_assert (!values[lit]); const value other_value = values[other]; if (other_value > 0) { LOGBINARY (lit, other, "skipping satisfied"); @@ -274,8 +276,8 @@ static void sweep_binary (sweeper *sweeper, unsigned depth, unsigned lit, LOGBINARY (lit, other, "skipping depth %u copied", other_depth); return; } - assert (!other_value); - assert (EMPTY_STACK (sweeper->clause)); + KISSAT_assert (!other_value); + KISSAT_assert (EMPTY_STACK (sweeper->clause)); PUSH_STACK (sweeper->clause, lit); PUSH_STACK (sweeper->clause, other); sweep_clause (sweeper, depth); @@ -283,7 +285,7 @@ static void sweep_binary (sweeper *sweeper, unsigned depth, unsigned lit, static void sweep_reference (sweeper *sweeper, unsigned depth, reference ref) { - assert (EMPTY_STACK (sweeper->clause)); + KISSAT_assert (EMPTY_STACK (sweeper->clause)); kissat *solver = sweeper->solver; clause *c = kissat_dereference_clause (solver, ref); if (c->swept) @@ -310,7 +312,7 @@ static void sweep_reference (sweeper *sweeper, unsigned depth, static void save_core_clause (void *state, bool learned, size_t size, const unsigned *lits) { - sweeper *sweeper = state; + sweeper *sweeper = (struct sweeper*)state; kissat *solver = sweeper->solver; if (solver->inconsistent) return; @@ -349,7 +351,7 @@ static void add_core (sweeper *sweeper, unsigned core_idx) { if (solver->inconsistent) return; LOG ("check and add extracted core[%u] lemmas to proof", core_idx); - assert (core_idx == 0 || core_idx == 1); + KISSAT_assert (core_idx == 0 || core_idx == 1); unsigneds *core = sweeper->core + core_idx; const value *const values = solver->values; @@ -400,7 +402,7 @@ static void add_core (sweeper *sweeper, unsigned core_idx) { if (new_size == 1) { q = d; - assert (unit != INVALID_LIT); + KISSAT_assert (unit != INVALID_LIT); LOG ("sweeping produced unit %s", LOGLIT (unit)); CHECK_AND_ADD_UNIT (unit); ADD_UNIT_TO_PROOF (unit); @@ -411,7 +413,7 @@ static void add_core (sweeper *sweeper, unsigned core_idx) { *q++ = INVALID_LIT; - assert (new_size > 1); + KISSAT_assert (new_size > 1); LOGLITS (new_size, d, "adding extracted core[%u] lemma", core_idx); CHECK_AND_ADD_LITS (new_size, d); ADD_LITS_TO_PROOF (new_size, d); @@ -425,8 +427,8 @@ static void add_core (sweeper *sweeper, unsigned core_idx) { static void save_core (sweeper *sweeper, unsigned core) { kissat *solver = sweeper->solver; LOG ("saving extracted core[%u] lemmas", core); - assert (core == 0 || core == 1); - assert (EMPTY_STACK (sweeper->core[core])); + KISSAT_assert (core == 0 || core == 1); + KISSAT_assert (EMPTY_STACK (sweeper->core[core])); sweeper->save = core; kitten_compute_clausal_core (solver->kitten, 0); kitten_traverse_core_clauses (solver->kitten, sweeper, save_core_clause); @@ -436,8 +438,8 @@ static void clear_core (sweeper *sweeper, unsigned core_idx) { kissat *solver = sweeper->solver; if (solver->inconsistent) return; -#if defined(LOGGING) || !defined(NDEBUG) || !defined(NPROOFS) - assert (core_idx == 0 || core_idx == 1); +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) || !defined(KISSAT_NPROOFS) + KISSAT_assert (core_idx == 0 || core_idx == 1); LOG ("clearing core[%u] lemmas", core_idx); #endif unsigneds *core = sweeper->core + core_idx; @@ -449,7 +451,7 @@ static void clear_core (sweeper *sweeper, unsigned core_idx) { while (*p != INVALID_LIT) p++; const size_t size = p - c; - assert (size > 1); + KISSAT_assert (size > 1); REMOVE_CHECKER_LITS (size, c); DELETE_LITS_FROM_PROOF (size, c); } @@ -492,9 +494,9 @@ static void init_backbone_and_partition (sweeper *sweeper) { } static void sweep_empty_clause (sweeper *sweeper) { - assert (!sweeper->solver->inconsistent); + KISSAT_assert (!sweeper->solver->inconsistent); save_add_clear_core (sweeper); - assert (sweeper->solver->inconsistent); + KISSAT_assert (sweeper->solver->inconsistent); } static void sweep_refine_partition (sweeper *sweeper) { @@ -625,7 +627,7 @@ static void flip_backbone_literals (struct sweeper *sweeper) { const unsigned max_rounds = GET_OPTION (sweepfliprounds); if (!max_rounds) return; - assert (!EMPTY_STACK (sweeper->backbone)); + KISSAT_assert (!EMPTY_STACK (sweeper->backbone)); struct kitten *kitten = solver->kitten; if (kitten_status (kitten) != 10) return; @@ -658,7 +660,7 @@ static void flip_backbone_literals (struct sweeper *sweeper) { if (TERMINATED (sweep_terminated_1)) break; - if (solver->statistics.kitten_ticks > sweeper->limit.ticks) + if (solver->statistics_.kitten_ticks > sweeper->limit.ticks) break; } while (flipped && round < max_rounds); LOG ("flipped %u backbone candidates in total in %u rounds", @@ -673,7 +675,7 @@ static bool sweep_backbone_candidate (sweeper *sweeper, unsigned lit) { if (value) { INC (sweep_fixed_backbone); LOG ("literal %s already fixed", LOGLIT (lit)); - assert (value > 0); + KISSAT_assert (value > 0); return false; } @@ -715,37 +717,37 @@ static void add_binary (kissat *solver, unsigned lit, unsigned other) { } static bool scheduled_variable (sweeper *sweeper, unsigned idx) { -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG kissat *const solver = sweeper->solver; - assert (VALID_INTERNAL_INDEX (idx)); + KISSAT_assert (VALID_INTERNAL_INDEX (idx)); #endif return sweeper->prev[idx] != INVALID_IDX || sweeper->first == idx; } static void schedule_inner (sweeper *sweeper, unsigned idx) { kissat *const solver = sweeper->solver; - assert (VALID_INTERNAL_INDEX (idx)); + KISSAT_assert (VALID_INTERNAL_INDEX (idx)); if (!ACTIVE (idx)) return; const unsigned next = sweeper->next[idx]; if (next != INVALID_IDX) { LOG ("rescheduling inner %s as last", LOGVAR (idx)); const unsigned prev = sweeper->prev[idx]; - assert (sweeper->prev[next] == idx); + KISSAT_assert (sweeper->prev[next] == idx); sweeper->prev[next] = prev; if (prev == INVALID_IDX) { - assert (sweeper->first == idx); + KISSAT_assert (sweeper->first == idx); sweeper->first = next; } else { - assert (sweeper->next[prev] == idx); + KISSAT_assert (sweeper->next[prev] == idx); sweeper->next[prev] = next; } const unsigned last = sweeper->last; if (last == INVALID_IDX) { - assert (sweeper->first == INVALID_IDX); + KISSAT_assert (sweeper->first == INVALID_IDX); sweeper->first = idx; } else { - assert (sweeper->next[last] == INVALID_IDX); + KISSAT_assert (sweeper->next[last] == INVALID_IDX); sweeper->next[last] = idx; } sweeper->prev[idx] = last; @@ -755,13 +757,13 @@ static void schedule_inner (sweeper *sweeper, unsigned idx) { LOG ("scheduling inner %s as last", LOGVAR (idx)); const unsigned last = sweeper->last; if (last == INVALID_IDX) { - assert (sweeper->first == INVALID_IDX); + KISSAT_assert (sweeper->first == INVALID_IDX); sweeper->first = idx; } else { - assert (sweeper->next[last] == INVALID_IDX); + KISSAT_assert (sweeper->next[last] == INVALID_IDX); sweeper->next[last] = idx; } - assert (sweeper->next[idx] == INVALID_IDX); + KISSAT_assert (sweeper->next[idx] == INVALID_IDX); sweeper->prev[idx] = last; sweeper->last = idx; } else @@ -769,28 +771,28 @@ static void schedule_inner (sweeper *sweeper, unsigned idx) { } static void schedule_outer (sweeper *sweeper, unsigned idx) { -#if !defined(NDEBUG) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || defined(LOGGING) kissat *const solver = sweeper->solver; #endif - assert (VALID_INTERNAL_INDEX (idx)); - assert (!scheduled_variable (sweeper, idx)); - assert (ACTIVE (idx)); + KISSAT_assert (VALID_INTERNAL_INDEX (idx)); + KISSAT_assert (!scheduled_variable (sweeper, idx)); + KISSAT_assert (ACTIVE (idx)); const unsigned first = sweeper->first; if (first == INVALID_IDX) { - assert (sweeper->last == INVALID_IDX); + KISSAT_assert (sweeper->last == INVALID_IDX); sweeper->last = idx; } else { - assert (sweeper->prev[first] == INVALID_IDX); + KISSAT_assert (sweeper->prev[first] == INVALID_IDX); sweeper->prev[first] = idx; } - assert (sweeper->prev[idx] == INVALID_IDX); + KISSAT_assert (sweeper->prev[idx] == INVALID_IDX); sweeper->next[idx] = first; sweeper->first = idx; LOG ("scheduling outer %s as first", LOGVAR (idx)); } static unsigned next_scheduled (sweeper *sweeper) { -#if !defined(NDEBUG) || defined(LOGGING) +#if !defined(KISSAT_NDEBUG) || defined(LOGGING) kissat *const solver = sweeper->solver; #endif unsigned res = sweeper->last; @@ -798,16 +800,16 @@ static unsigned next_scheduled (sweeper *sweeper) { LOG ("no more scheduled variables left"); return INVALID_IDX; } - assert (VALID_INTERNAL_INDEX (res)); + KISSAT_assert (VALID_INTERNAL_INDEX (res)); LOG ("dequeuing next scheduled %s", LOGVAR (res)); const unsigned prev = sweeper->prev[res]; - assert (sweeper->next[res] == INVALID_IDX); + KISSAT_assert (sweeper->next[res] == INVALID_IDX); sweeper->prev[res] = INVALID_IDX; if (prev == INVALID_IDX) { - assert (sweeper->first == res); + KISSAT_assert (sweeper->first == res); sweeper->first = INVALID_IDX; } else { - assert (sweeper->next[prev] == res); + KISSAT_assert (sweeper->next[prev] == res); sweeper->next[prev] = INVALID_IDX; } sweeper->last = prev; @@ -832,17 +834,17 @@ static void substitute_connected_clauses (sweeper *sweeper, unsigned lit, LOG ("substituting %s with %s in all irredundant clauses", LOGLIT (lit), LOGLIT (repr)); - assert (lit != repr); - assert (lit != NOT (repr)); + KISSAT_assert (lit != repr); + KISSAT_assert (lit != NOT (repr)); #ifdef CHECKING_OR_PROVING const bool checking_or_proving = kissat_checking_or_proving (solver); - assert (EMPTY_STACK (solver->added)); - assert (EMPTY_STACK (solver->removed)); + KISSAT_assert (EMPTY_STACK (solver->added)); + KISSAT_assert (EMPTY_STACK (solver->removed)); #endif unsigneds *const delayed = &solver->delayed; - assert (EMPTY_STACK (*delayed)); + KISSAT_assert (EMPTY_STACK (*delayed)); { watches *lit_watches = &WATCHES (lit); @@ -884,7 +886,7 @@ static void substitute_connected_clauses (sweeper *sweeper, unsigned lit, q--; } else { const reference ref = head.large.ref; - assert (EMPTY_STACK (sweeper->clause)); + KISSAT_assert (EMPTY_STACK (sweeper->clause)); clause *c = kissat_dereference_clause (solver, ref); if (c->garbage) continue; @@ -892,21 +894,21 @@ static void substitute_connected_clauses (sweeper *sweeper, unsigned lit, bool satisfied = false; bool repr_already_watched = false; const unsigned not_repr = NOT (repr); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG bool found = false; #endif for (all_literals_in_clause (other, c)) { if (other == lit) { -#ifndef NDEBUG - assert (!found); +#ifndef KISSAT_NDEBUG + KISSAT_assert (!found); found = true; #endif PUSH_STACK (solver->clause, repr); continue; } - assert (other != NOT (lit)); + KISSAT_assert (other != NOT (lit)); if (other == repr) { - assert (!repr_already_watched); + KISSAT_assert (!repr_already_watched); repr_already_watched = true; continue; } @@ -929,13 +931,13 @@ static void substitute_connected_clauses (sweeper *sweeper, unsigned lit, kissat_mark_clause_as_garbage (solver, c); continue; } - assert (found); + KISSAT_assert (found); const unsigned new_size = SIZE_STACK (solver->clause); if (new_size == 0) { LOGCLS (c, "substituted empty clause"); - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); solver->inconsistent = true; CHECK_AND_ADD_EMPTY (); ADD_EMPTY_TO_PROOF (); @@ -966,16 +968,16 @@ static void substitute_connected_clauses (sweeper *sweeper, unsigned lit, const unsigned first = POP_STACK (solver->clause); LOGCLS (c, "reduces to binary clause %s %s", LOGLIT (first), LOGLIT (second)); - assert (first == repr || second == repr); + KISSAT_assert (first == repr || second == repr); const unsigned other = first ^ second ^ repr; const watch src = {.raw = head.raw}; watch dst = kissat_binary_watch (repr); watches *other_watches = &WATCHES (other); kissat_substitute_large_watch (solver, other_watches, src, dst); - assert (solver->statistics.clauses_irredundant); - solver->statistics.clauses_irredundant--; - assert (solver->statistics.clauses_binary < UINT64_MAX); - solver->statistics.clauses_binary++; + KISSAT_assert (solver->statistics_.clauses_irredundant); + solver->statistics_.clauses_irredundant--; + KISSAT_assert (solver->statistics_.clauses_binary < UINT64_MAX); + solver->statistics_.clauses_binary++; dst.binary.lit = other; PUSH_STACK (*delayed, dst.raw); const size_t bytes = kissat_actual_bytes_of_clause (c); @@ -985,9 +987,9 @@ static void substitute_connected_clauses (sweeper *sweeper, unsigned lit, continue; } - assert (2 < new_size); + KISSAT_assert (2 < new_size); const unsigned old_size = c->size; - assert (new_size <= old_size); + KISSAT_assert (new_size <= old_size); const unsigned *const begin = BEGIN_STACK (solver->clause); const unsigned *const end = END_STACK (solver->clause); @@ -1045,12 +1047,12 @@ static void substitute_connected_clauses (sweeper *sweeper, unsigned lit, static void sweep_remove (sweeper *sweeper, unsigned lit) { kissat *solver = sweeper->solver; - assert (sweeper->reprs[lit] != lit); + KISSAT_assert (sweeper->reprs[lit] != lit); unsigneds *partition = &sweeper->partition; unsigned *const begin_partition = BEGIN_STACK (*partition), *p; const unsigned *const end_partition = END_STACK (*partition); for (p = begin_partition; *p != lit; p++) - assert (p + 1 != end_partition); + KISSAT_assert (p + 1 != end_partition); unsigned *begin_class = p; while (begin_class != begin_partition && begin_class[-1] != INVALID_LIT) begin_class--; @@ -1060,7 +1062,7 @@ static void sweep_remove (sweeper *sweeper, unsigned lit) { const unsigned size = end_class - begin_class; LOG ("removing non-representative %s from equivalence class of size %u", LOGLIT (lit), size); - assert (size > 1); + KISSAT_assert (size > 1); unsigned *q = begin_class; if (size == 2) { LOG ("completely squashing equivalence class of %s", LOGLIT (lit)); @@ -1082,7 +1084,7 @@ static void flip_partition_literals (struct sweeper *sweeper) { const unsigned max_rounds = GET_OPTION (sweepfliprounds); if (!max_rounds) return; - assert (!EMPTY_STACK (sweeper->partition)); + KISSAT_assert (!EMPTY_STACK (sweeper->partition)); struct kitten *kitten = solver->kitten; if (kitten_status (kitten) != 10) return; @@ -1097,10 +1099,10 @@ static void flip_partition_literals (struct sweeper *sweeper) { const unsigned *const end = END_STACK (sweeper->partition), *src = dst; while (src != end) { const unsigned *end_src = src; - while (assert (end_src != end), *end_src != INVALID_LIT) + while (KISSAT_assert (end_src != end), *end_src != INVALID_LIT) end_src++; unsigned size = end_src - src; - assert (size > 1); + KISSAT_assert (size > 1); unsigned *q = dst; for (const unsigned *p = src; p != end_src; p++) { const unsigned lit = *p; @@ -1128,7 +1130,7 @@ static void flip_partition_literals (struct sweeper *sweeper) { if (TERMINATED (sweep_terminated_2)) break; - if (solver->statistics.kitten_ticks > sweeper->limit.ticks) + if (solver->statistics_.kitten_ticks > sweeper->limit.ticks) break; } while (flipped && round < max_rounds); LOG ("flipped %u equivalence candidates in total in %u rounds", @@ -1145,9 +1147,9 @@ static bool sweep_equivalence_candidates (sweeper *sweeper, unsigned lit, kitten *kitten = solver->kitten; const unsigned *const begin = BEGIN_STACK (sweeper->partition); unsigned *const end = END_STACK (sweeper->partition); - assert (begin + 3 <= end); - assert (end[-3] == lit); - assert (end[-2] == other); + KISSAT_assert (begin + 3 <= end); + KISSAT_assert (end[-3] == lit); + KISSAT_assert (end[-2] == other); const unsigned third = (end - begin == 3) ? INVALID_LIT : end[-4]; const int status = kitten_status (kitten); if (status == 10 && kitten_flip_literal (kitten, lit)) { @@ -1269,22 +1271,22 @@ static bool sweep_equivalence_candidates (sweeper *sweeper, unsigned lit, static const char *sweep_variable (sweeper *sweeper, unsigned idx) { kissat *solver = sweeper->solver; - assert (!solver->inconsistent); + KISSAT_assert (!solver->inconsistent); if (!ACTIVE (idx)) return "inactive variable"; const unsigned start = LIT (idx); if (sweeper->reprs[start] != start) return "non-representative variable"; - assert (EMPTY_STACK (sweeper->vars)); - assert (EMPTY_STACK (sweeper->refs)); - assert (EMPTY_STACK (sweeper->backbone)); - assert (EMPTY_STACK (sweeper->partition)); - assert (!sweeper->encoded); + KISSAT_assert (EMPTY_STACK (sweeper->vars)); + KISSAT_assert (EMPTY_STACK (sweeper->refs)); + KISSAT_assert (EMPTY_STACK (sweeper->backbone)); + KISSAT_assert (EMPTY_STACK (sweeper->partition)); + KISSAT_assert (!sweeper->encoded); INC (sweep_variables); LOG ("sweeping %s", LOGVAR (idx)); - assert (!VALUE (start)); + KISSAT_assert (!VALUE (start)); LOG ("starting sweeping[0]"); add_literal_to_environment (sweeper, 0, start); LOG ("finished sweeping[0]"); @@ -1361,9 +1363,9 @@ static const char *sweep_variable (sweeper *sweeper, unsigned idx) { LOG ("sub-solver returns '%d'", res); if (res == 10) { init_backbone_and_partition (sweeper); -#ifndef QUIET - uint64_t units = solver->statistics.sweep_units; - uint64_t solved = solver->statistics.sweep_solved; +#ifndef KISSAT_QUIET + uint64_t units = solver->statistics_.sweep_units; + uint64_t solved = solver->statistics_.sweep_solved; #endif START (sweepbackbone); while (!EMPTY_STACK (sweeper->backbone)) { @@ -1389,19 +1391,19 @@ static const char *sweep_variable (sweeper *sweeper, unsigned idx) { success = true; } STOP (sweepbackbone); -#ifndef QUIET - units = solver->statistics.sweep_units - units; - solved = solver->statistics.sweep_solved - solved; +#ifndef KISSAT_QUIET + units = solver->statistics_.sweep_units - units; + solved = solver->statistics_.sweep_solved - solved; kissat_extremely_verbose ( solver, "complete swept variable %d backbone with %" PRIu64 " units in %" PRIu64 " solver calls", kissat_export_literal (solver, LIT (idx)), units, solved); #endif - assert (EMPTY_STACK (sweeper->backbone)); -#ifndef QUIET - uint64_t equivalences = solver->statistics.sweep_equivalences; - solved = solver->statistics.sweep_solved; + KISSAT_assert (EMPTY_STACK (sweeper->backbone)); +#ifndef KISSAT_QUIET + uint64_t equivalences = solver->statistics_.sweep_equivalences; + solved = solver->statistics_.sweep_solved; #endif START (sweepequivalences); while (!EMPTY_STACK (sweeper->partition)) { @@ -1422,7 +1424,7 @@ static const char *sweep_variable (sweeper *sweeper, unsigned idx) { break; if (SIZE_STACK (sweeper->partition) > 2) { const unsigned *end = END_STACK (sweeper->partition); - assert (end[-1] == INVALID_LIT); + KISSAT_assert (end[-1] == INVALID_LIT); unsigned lit = end[-3]; unsigned other = end[-2]; if (sweep_equivalence_candidates (sweeper, lit, other)) @@ -1431,9 +1433,9 @@ static const char *sweep_variable (sweeper *sweeper, unsigned idx) { CLEAR_STACK (sweeper->partition); } STOP (sweepequivalences); -#ifndef QUIET - equivalences = solver->statistics.sweep_equivalences - equivalences; - solved = solver->statistics.sweep_solved - solved; +#ifndef KISSAT_QUIET + equivalences = solver->statistics_.sweep_equivalences - equivalences; + solved = solver->statistics_.sweep_solved - solved; if (equivalences) kissat_extremely_verbose ( solver, @@ -1456,7 +1458,7 @@ DONE: return "unsuccessfully without reaching limit"; else if (success && !limit_reached) return "successfully without reaching limit"; - assert (!success && limit_reached); + KISSAT_assert (!success && limit_reached); return "unsuccessfully and reached limit"; } @@ -1520,7 +1522,7 @@ static unsigned schedule_all_other_not_scheduled_yet (sweeper *sweeper) { PUSH_STACK (fresh, cand); } const size_t size = SIZE_STACK (fresh); - assert (size <= UINT_MAX); + KISSAT_assert (size <= UINT_MAX); RADIX_STACK (sweep_candidate, unsigned, fresh, RANK_SWEEP_CANDIDATE); for (all_stack (sweep_candidate, cand, fresh)) schedule_outer (sweeper, cand.idx); @@ -1575,7 +1577,7 @@ static void mark_incomplete (sweeper *sweeper) { marked++; } solver->sweep_incomplete = true; -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_extremely_verbose ( solver, "marked %u scheduled sweeping variables as incomplete", marked); @@ -1590,7 +1592,7 @@ static unsigned schedule_sweeping (sweeper *sweeper) { const unsigned scheduled = fresh + rescheduled; const unsigned incomplete = incomplete_variables (sweeper); kissat *solver = sweeper->solver; -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_phase (solver, "sweep", GET (sweep), "scheduled %u variables %.0f%% " "(%u rescheduled %.0f%%, %u incomplete %.0f%%)", @@ -1600,7 +1602,7 @@ static unsigned schedule_sweeping (sweeper *sweeper) { incomplete, kissat_percent (incomplete, scheduled)); #endif if (incomplete) - assert (solver->sweep_incomplete); + KISSAT_assert (solver->sweep_incomplete); else { if (solver->sweep_incomplete) INC (sweep_completed); @@ -1612,18 +1614,18 @@ static unsigned schedule_sweeping (sweeper *sweeper) { static void unschedule_sweeping (sweeper *sweeper, unsigned swept, unsigned scheduled) { kissat *solver = sweeper->solver; -#ifdef QUIET +#ifdef KISSAT_QUIET (void) scheduled, (void) swept; #endif - assert (EMPTY_STACK (solver->sweep_schedule)); - assert (solver->sweep_incomplete); + KISSAT_assert (EMPTY_STACK (solver->sweep_schedule)); + KISSAT_assert (solver->sweep_incomplete); flags *flags = solver->flags; for (all_scheduled (idx)) if (flags[idx].active) { PUSH_STACK (solver->sweep_schedule, idx); LOG ("untried scheduled %s", LOGVAR (idx)); } -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned retained = SIZE_STACK (solver->sweep_schedule); kissat_extremely_verbose ( solver, "retained %u variables %.0f%% to be swept next time", @@ -1654,11 +1656,11 @@ bool kissat_sweep (kissat *solver) { return false; if (DELAYING (sweep)) return false; - assert (!solver->level); - assert (!solver->unflushed); + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->unflushed); START (sweep); INC (sweep); - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; uint64_t equivalences = statistics->sweep_equivalences; uint64_t units = statistics->sweep_units; sweeper sweeper; @@ -1670,13 +1672,13 @@ bool kissat_sweep (kissat *solver) { break; if (TERMINATED (sweep_terminated_8)) break; - if (solver->statistics.kitten_ticks > sweeper.limit.ticks) + if (solver->statistics_.kitten_ticks > sweeper.limit.ticks) break; unsigned idx = next_scheduled (&sweeper); if (idx == INVALID_IDX) break; FLAGS (idx)->sweep = false; -#ifndef QUIET +#ifndef KISSAT_QUIET const char *res = #endif sweep_variable (&sweeper, idx); @@ -1688,13 +1690,13 @@ bool kissat_sweep (kissat *solver) { "found %" PRIu64 " equivalences and %" PRIu64 " units after sweeping %" PRIu64 " variables ", statistics->sweep_equivalences - equivalences, - solver->statistics.sweep_units - units, swept); + solver->statistics_.sweep_units - units, swept); limit *= 10; } } kissat_very_verbose (solver, "swept %" PRIu64 " variables", swept); equivalences = statistics->sweep_equivalences - equivalences, - units = solver->statistics.sweep_units - units; + units = solver->statistics_.sweep_units - units; kissat_phase (solver, "sweep", GET (sweep), "found %" PRIu64 " equivalences and %" PRIu64 " units", equivalences, units); @@ -1707,8 +1709,8 @@ bool kissat_sweep (kissat *solver) { } uint64_t eliminated = equivalences + units; -#ifndef QUIET - assert (solver->active >= inactive); +#ifndef KISSAT_QUIET + KISSAT_assert (solver->active >= inactive); solver->active -= inactive; REPORT (!eliminated, '='); solver->active += inactive; @@ -1722,3 +1724,5 @@ bool kissat_sweep (kissat *solver) { STOP (sweep); return eliminated; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/sweep.h b/src/sat/kissat/sweep.h index a0f81b8b0..995c61c79 100644 --- a/src/sat/kissat/sweep.h +++ b/src/sat/kissat/sweep.h @@ -3,7 +3,12 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_sweep (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/terminate.c b/src/sat/kissat/terminate.c index c1cfe7549..25b91a866 100644 --- a/src/sat/kissat/terminate.c +++ b/src/sat/kissat/terminate.c @@ -1,7 +1,9 @@ #include "terminate.h" #include "print.h" -#ifndef QUIET +ABC_NAMESPACE_IMPL_START + +#ifndef KISSAT_QUIET void kissat_report_termination (kissat *solver, const char *name, const char *file, long lineno, @@ -13,3 +15,5 @@ void kissat_report_termination (kissat *solver, const char *name, #else int kissat_terminate_dummy_to_avoid_warning; #endif + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/terminate.h b/src/sat/kissat/terminate.h index 731f584b8..853adecd1 100644 --- a/src/sat/kissat/terminate.h +++ b/src/sat/kissat/terminate.h @@ -3,7 +3,10 @@ #include "internal.h" -#ifndef QUIET +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#ifndef KISSAT_QUIET void kissat_report_termination (kissat *, const char *name, const char *file, long lineno, const char *fun); @@ -12,7 +15,7 @@ void kissat_report_termination (kissat *, const char *name, static inline bool kissat_terminated (kissat *solver, int bit, const char *name, const char *file, long lineno, const char *fun) { - assert (0 <= bit), assert (bit < 64); + KISSAT_assert (0 <= bit), KISSAT_assert (bit < 64); #ifdef COVERAGE const uint64_t mask = (uint64_t) 1 << bit; if (!(solver->termination.flagged & mask)) @@ -22,7 +25,7 @@ static inline bool kissat_terminated (kissat *solver, int bit, if (!solver->termination.flagged) return false; #endif -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_report_termination (solver, name, file, lineno, fun); #else (void) file; @@ -30,7 +33,7 @@ static inline bool kissat_terminated (kissat *solver, int bit, (void) lineno; (void) name; #endif -#if !defined(COVERAGE) && defined(NDEBUG) +#if !defined(COVERAGE) && defined(KISSAT_NDEBUG) (void) bit; #endif return true; @@ -83,4 +86,6 @@ static inline bool kissat_terminated (kissat *solver, int bit, #define walk_terminated_1 42 #define warmup_terminated_1 43 +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/tiers.c b/src/sat/kissat/tiers.c index 3fb49e104..3f044d746 100644 --- a/src/sat/kissat/tiers.c +++ b/src/sat/kissat/tiers.c @@ -3,9 +3,11 @@ #include "logging.h" #include "print.h" +ABC_NAMESPACE_IMPL_START + static void compute_tier_limits (kissat *solver, bool stable, unsigned *tier1_ptr, unsigned *tier2_ptr) { - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; uint64_t *used_stats = statistics->used[stable].glue; uint64_t total_used = 0; for (unsigned glue = 0; glue <= MAX_GLUE_USED; glue++) @@ -40,8 +42,8 @@ static void compute_tier_limits (kissat *solver, bool stable, tier2 = MAX (GET_OPTION (tier2), tier1); } else if (tier2 < 0) tier2 = tier1; - assert (0 <= tier1); - assert (0 <= tier2); + KISSAT_assert (0 <= tier1); + KISSAT_assert (0 <= tier2); *tier1_ptr = tier1; *tier2_ptr = tier2; LOG ("%s tier1 limit %u", stable ? "stable" : "focused", tier1); @@ -74,16 +76,16 @@ static unsigned decimal_digits (uint64_t i) { void kissat_print_tier_usage_statistics (kissat *solver, bool stable) { unsigned tier1, tier2; compute_tier_limits (solver, stable, &tier1, &tier2); - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; uint64_t *used_stats = statistics->used[stable].glue; uint64_t total_used = 0; for (unsigned glue = 0; glue <= MAX_GLUE_USED; glue++) total_used += used_stats[glue]; const char *mode = stable ? "stable" : "focused"; - assert (tier1 <= tier2); + KISSAT_assert (tier1 <= tier2); unsigned span = tier2 - tier1 + 1; const unsigned max_printed = 5; - assert (max_printed & 1), assert (max_printed / 2 > 0); + KISSAT_assert (max_printed & 1), KISSAT_assert (max_printed / 2 > 0); unsigned prefix, suffix; if (span > max_printed) { prefix = tier1 + max_printed / 2 - 1; @@ -159,3 +161,5 @@ void kissat_print_tier_usage_statistics (kissat *solver, bool stable) { break; } } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/tiers.h b/src/sat/kissat/tiers.h index 3b7acb284..c706ccc62 100644 --- a/src/sat/kissat/tiers.h +++ b/src/sat/kissat/tiers.h @@ -3,10 +3,15 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_compute_and_set_tier_limits (struct kissat *); void kissat_print_tier_usage_statistics (struct kissat *solver, bool stable); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/trail.c b/src/sat/kissat/trail.c index 8b1882f53..256da6cfc 100644 --- a/src/sat/kissat/trail.c +++ b/src/sat/kissat/trail.c @@ -3,12 +3,14 @@ #include "inline.h" #include "propsearch.h" +ABC_NAMESPACE_IMPL_START + void kissat_flush_trail (kissat *solver) { - assert (!solver->level); - assert (solver->unflushed); - assert (!solver->inconsistent); - assert (kissat_propagated (solver)); - assert (SIZE_ARRAY (solver->trail) == solver->unflushed); + KISSAT_assert (!solver->level); + KISSAT_assert (solver->unflushed); + KISSAT_assert (!solver->inconsistent); + KISSAT_assert (kissat_propagated (solver)); + KISSAT_assert (SIZE_ARRAY (solver->trail) == solver->unflushed); LOG ("flushed %zu units from trail", SIZE_ARRAY (solver->trail)); CLEAR_ARRAY (solver->trail); kissat_reset_propagate (solver); @@ -18,24 +20,24 @@ void kissat_flush_trail (kissat *solver) { void kissat_mark_reason_clauses (kissat *solver, reference start) { LOG ("starting marking reason clauses at clause[%" REFERENCE_FORMAT "]", start); - assert (!solver->unflushed); + KISSAT_assert (!solver->unflushed); #ifdef LOGGING unsigned reasons = 0; #endif ward *arena = BEGIN_STACK (solver->arena); for (all_stack (unsigned, lit, solver->trail)) { assigned *a = ASSIGNED (lit); - assert (a->level > 0); + KISSAT_assert (a->level > 0); if (a->binary) continue; const reference ref = a->reason; - assert (ref != UNIT_REASON); + KISSAT_assert (ref != UNIT_REASON); if (ref == DECISION_REASON) continue; if (ref < start) continue; clause *c = (clause *) (arena + ref); - assert (kissat_clause_in_arena (solver, c)); + KISSAT_assert (kissat_clause_in_arena (solver, c)); c->reason = true; #ifdef LOGGING reasons++; @@ -46,9 +48,9 @@ void kissat_mark_reason_clauses (kissat *solver, reference start) { bool kissat_flush_and_mark_reason_clauses (kissat *solver, reference start) { - assert (solver->watching); - assert (!solver->inconsistent); - assert (kissat_propagated (solver)); + KISSAT_assert (solver->watching); + KISSAT_assert (!solver->inconsistent); + KISSAT_assert (kissat_propagated (solver)); if (solver->unflushed) { LOG ("need to flush %u units from trail", solver->unflushed); @@ -64,25 +66,25 @@ bool kissat_flush_and_mark_reason_clauses (kissat *solver, void kissat_unmark_reason_clauses (kissat *solver, reference start) { LOG ("starting unmarking reason clauses at clause[%" REFERENCE_FORMAT "]", start); - assert (!solver->unflushed); + KISSAT_assert (!solver->unflushed); #ifdef LOGGING unsigned reasons = 0; #endif ward *arena = BEGIN_STACK (solver->arena); for (all_stack (unsigned, lit, solver->trail)) { assigned *a = ASSIGNED (lit); - assert (a->level > 0); + KISSAT_assert (a->level > 0); if (a->binary) continue; const reference ref = a->reason; - assert (ref != UNIT_REASON); + KISSAT_assert (ref != UNIT_REASON); if (ref == DECISION_REASON) continue; if (ref < start) continue; clause *c = (clause *) (arena + ref); - assert (kissat_clause_in_arena (solver, c)); - assert (c->reason); + KISSAT_assert (kissat_clause_in_arena (solver, c)); + KISSAT_assert (c->reason); c->reason = false; #ifdef LOGGING reasons++; @@ -90,3 +92,5 @@ void kissat_unmark_reason_clauses (kissat *solver, reference start) { } LOG ("unmarked %u reason clauses", reasons); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/trail.h b/src/sat/kissat/trail.h index ca84203f2..8dcd3c57e 100644 --- a/src/sat/kissat/trail.h +++ b/src/sat/kissat/trail.h @@ -5,6 +5,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_flush_trail (struct kissat *); @@ -13,4 +16,6 @@ bool kissat_flush_and_mark_reason_clauses (struct kissat *, void kissat_unmark_reason_clauses (struct kissat *, reference start); void kissat_mark_reason_clauses (struct kissat *, reference start); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/transitive.c b/src/sat/kissat/transitive.c index 2c06ff5e5..3aa58e24e 100644 --- a/src/sat/kissat/transitive.c +++ b/src/sat/kissat/transitive.c @@ -14,12 +14,14 @@ #include +ABC_NAMESPACE_IMPL_START + static void transitive_assign (kissat *solver, unsigned lit) { LOG ("transitive assign %s", LOGLIT (lit)); value *values = solver->values; const unsigned not_lit = NOT (lit); - assert (!values[lit]); - assert (!values[not_lit]); + KISSAT_assert (!values[lit]); + KISSAT_assert (!values[not_lit]); values[lit] = 1; values[not_lit] = -1; PUSH_ARRAY (solver->trail, lit); @@ -29,14 +31,14 @@ static void transitive_backtrack (kissat *solver, unsigned *saved) { value *values = solver->values; unsigned *end_trail = END_ARRAY (solver->trail); - assert (saved <= end_trail); + KISSAT_assert (saved <= end_trail); while (end_trail != saved) { const unsigned lit = *--end_trail; LOG ("transitive unassign %s", LOGLIT (lit)); const unsigned not_lit = NOT (lit); - assert (values[lit] > 0); - assert (values[not_lit] < 0); + KISSAT_assert (values[lit] > 0); + KISSAT_assert (values[not_lit] < 0); values[lit] = values[not_lit] = 0; } @@ -46,12 +48,12 @@ static void transitive_backtrack (kissat *solver, unsigned *saved) { } static void prioritize_binaries (kissat *solver) { - assert (solver->watching); + KISSAT_assert (solver->watching); statches large; INIT_STACK (large); watches *all_watches = solver->watches; for (all_literals (lit)) { - assert (EMPTY_STACK (large)); + KISSAT_assert (EMPTY_STACK (large)); watches *watches = all_watches + lit; watch *begin_watches = BEGIN_WATCHES (*watches), *q = begin_watches; const watch *const end_watches = END_WATCHES (*watches), *p = q; @@ -68,7 +70,7 @@ static void prioritize_binaries (kissat *solver) { watch const *r = BEGIN_STACK (large); while (r != end_large) *q++ = *r++; - assert (q == end_watches); + KISSAT_assert (q == end_watches); CLEAR_STACK (large); } RELEASE_STACK (large); @@ -77,7 +79,7 @@ static void prioritize_binaries (kissat *solver) { static bool transitive_reduce (kissat *solver, unsigned src, uint64_t limit, uint64_t *reduced_ptr, unsigned *units) { bool res = false; - assert (!VALUE (src)); + KISSAT_assert (!VALUE (src)); LOG ("transitive reduce %s", LOGLIT (src)); watches *all_watches = solver->watches; watches *src_watches = all_watches + src; @@ -102,9 +104,9 @@ static bool transitive_reduce (kissat *solver, unsigned src, uint64_t limit, continue; if (VALUE (dst)) continue; - assert (kissat_propagated (solver)); + KISSAT_assert (kissat_propagated (solver)); unsigned *saved = solver->propagate; - assert (!solver->level); + KISSAT_assert (!solver->level); solver->level = 1; transitive_assign (solver, not_src); bool transitive = false; @@ -114,7 +116,7 @@ static bool transitive_reduce (kissat *solver, unsigned src, uint64_t limit, propagate != END_ARRAY (solver->trail)) { const unsigned lit = *propagate++; LOG ("transitive propagate %s", LOGLIT (lit)); - assert (VALUE (lit) > 0); + KISSAT_assert (VALUE (lit) > 0); const unsigned not_lit = NOT (lit); watches *lit_watches = all_watches + not_lit; const watch *const end_lit = END_WATCHES (*lit_watches); @@ -147,9 +149,9 @@ static bool transitive_reduce (kissat *solver, unsigned src, uint64_t limit, } } - assert (solver->probing); + KISSAT_assert (solver->probing); - assert (solver->propagate <= propagate); + KISSAT_assert (solver->propagate <= propagate); const unsigned propagated = propagate - solver->propagate; ADD (transitive_propagations, propagated); @@ -167,7 +169,7 @@ static bool transitive_reduce (kissat *solver, unsigned src, uint64_t limit, INC (transitive_reduced); watches *dst_watches = all_watches + dst; watch dst_watch = src_watch; - assert (dst_watch.binary.lit == dst); + KISSAT_assert (dst_watch.binary.lit == dst); dst_watch.binary.lit = src; REMOVE_WATCHES (*dst_watches, dst_watch); kissat_delete_binary (solver, src, dst); @@ -178,7 +180,7 @@ static bool transitive_reduce (kissat *solver, unsigned src, uint64_t limit, if (failed) break; - if (solver->statistics.transitive_ticks > limit) + if (solver->statistics_.transitive_ticks > limit) break; if (TERMINATED (transitive_terminated_1)) break; @@ -186,8 +188,8 @@ static bool transitive_reduce (kissat *solver, unsigned src, uint64_t limit, if (reduced) { *reduced_ptr += reduced; - assert (begin_src == BEGIN_WATCHES (WATCHES (src))); - assert (end_src == END_WATCHES (WATCHES (src))); + KISSAT_assert (begin_src == BEGIN_WATCHES (WATCHES (src))); + KISSAT_assert (end_src == END_WATCHES (WATCHES (src))); watch *q = begin_src; for (const watch *p = begin_src; p != end_src; p++) { const watch src_watch = *q++ = *p; @@ -198,7 +200,7 @@ static bool transitive_reduce (kissat *solver, unsigned src, uint64_t limit, if (src_watch.binary.lit == ILLEGAL_LIT) q--; } - assert (end_src - q == (ptrdiff_t) reduced); + KISSAT_assert (end_src - q == (ptrdiff_t) reduced); SET_END_OF_WATCHES (*src_watches, q); } @@ -210,7 +212,7 @@ static bool transitive_reduce (kissat *solver, unsigned src, uint64_t limit, kissat_learned_unit (solver, src); - assert (!solver->level); + KISSAT_assert (!solver->level); (void) kissat_probing_propagate (solver, 0, true); } @@ -221,7 +223,7 @@ static inline bool less_stable_transitive (kissat *solver, const flags *const flags, const heap *scores, unsigned a, unsigned b) { -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) solver; #endif const unsigned i = IDX (a); @@ -245,7 +247,7 @@ static inline unsigned less_focused_transitive (kissat *solver, const flags *const flags, const links *links, unsigned a, unsigned b) { -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) solver; #endif const unsigned i = IDX (a); @@ -287,7 +289,7 @@ static void sort_transitive (kissat *solver, unsigneds *probes) { } static void schedule_transitive (kissat *solver, unsigneds *probes) { - assert (EMPTY_STACK (*probes)); + KISSAT_assert (EMPTY_STACK (*probes)); for (all_variables (idx)) if (ACTIVE (idx)) PUSH_STACK (*probes, idx); @@ -299,17 +301,17 @@ static void schedule_transitive (kissat *solver, unsigneds *probes) { void kissat_transitive_reduction (kissat *solver) { if (solver->inconsistent) return; - assert (solver->watching); - assert (solver->probing); - assert (!solver->level); + KISSAT_assert (solver->watching); + KISSAT_assert (solver->probing); + KISSAT_assert (!solver->level); if (!GET_OPTION (transitive)) return; if (TERMINATED (transitive_terminated_2)) return; START (transitive); INC (transitive_reductions); -#if !defined(NDEBUG) || defined(METRICS) - assert (!solver->transitive_reducing); +#if !defined(KISSAT_NDEBUG) || defined(METRICS) + KISSAT_assert (!solver->transitive_reducing); solver->transitive_reducing = true; #endif prioritize_binaries (solver); @@ -319,9 +321,9 @@ void kissat_transitive_reduction (kissat *solver) { SET_EFFORT_LIMIT (limit, transitive, transitive_ticks); -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned active = solver->active; - const uint64_t old_ticks = solver->statistics.transitive_ticks; + const uint64_t old_ticks = solver->statistics_.transitive_ticks; kissat_extremely_verbose ( solver, "starting with %" PRIu64 " transitive ticks", old_ticks); unsigned probed = 0; @@ -339,14 +341,14 @@ void kissat_transitive_reduction (kissat *solver) { const unsigned lit = 2 * idx + sign; if (solver->values[lit]) continue; -#ifndef QUIET +#ifndef KISSAT_QUIET probed++; #endif if (transitive_reduce (solver, lit, limit, &reduced, &units)) success = true; if (solver->inconsistent) terminate = true; - else if (solver->statistics.transitive_ticks > limit) + else if (solver->statistics_.transitive_ticks > limit) terminate = true; else if (TERMINATED (transitive_terminated_3)) terminate = true; @@ -366,8 +368,8 @@ void kissat_transitive_reduction (kissat *solver) { kissat_very_verbose (solver, "transitive reduction complete"); RELEASE_STACK (probes); -#ifndef QUIET - const uint64_t new_ticks = solver->statistics.transitive_ticks; +#ifndef KISSAT_QUIET + const uint64_t new_ticks = solver->statistics_.transitive_ticks; const uint64_t delta_ticks = new_ticks - old_ticks; kissat_extremely_verbose ( solver, "finished at %" PRIu64 " after %" PRIu64 " transitive ticks", @@ -377,13 +379,15 @@ void kissat_transitive_reduction (kissat *solver) { "probed %u (%.0f%%): reduced %" PRIu64 ", units %u", probed, kissat_percent (probed, 2 * active), reduced, units); -#if !defined(NDEBUG) || defined(METRICS) - assert (solver->transitive_reducing); +#if !defined(KISSAT_NDEBUG) || defined(METRICS) + KISSAT_assert (solver->transitive_reducing); solver->transitive_reducing = false; #endif REPORT (!success, 't'); STOP (transitive); -#ifdef QUIET +#ifdef KISSAT_QUIET (void) success; #endif } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/transitive.h b/src/sat/kissat/transitive.h index ec0011460..214656824 100644 --- a/src/sat/kissat/transitive.h +++ b/src/sat/kissat/transitive.h @@ -1,8 +1,13 @@ #ifndef _transitive_h_INCLUDED #define _transitive_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_transitive_reduction (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/utilities.c b/src/sat/kissat/utilities.c index 4ea4e0b8f..9a6b08b84 100644 --- a/src/sat/kissat/utilities.c +++ b/src/sat/kissat/utilities.c @@ -2,6 +2,8 @@ #include +ABC_NAMESPACE_IMPL_START + bool kissat_has_suffix (const char *str, const char *suffix) { const char *p = str; while (*p) @@ -14,3 +16,5 @@ bool kissat_has_suffix (const char *str, const char *suffix) { return false; return q == suffix; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/utilities.h b/src/sat/kissat/utilities.h index 392aaafef..2a9896341 100644 --- a/src/sat/kissat/utilities.h +++ b/src/sat/kissat/utilities.h @@ -6,7 +6,35 @@ #include #include -typedef uintptr_t word; +#ifdef _MSC_VER +#include +static inline int __builtin_clz(unsigned x) { + unsigned long r; + _BitScanReverse(&r, x); + return (int)(r ^ 31); +} + +static inline int __builtin_clzll(unsigned long long x) { +#if defined(_WIN64) + unsigned long r; + _BitScanReverse64(&r, x); + return (int)(r ^ 63); +#else + int l = __builtin_clz((unsigned)x) + 32; + int h = __builtin_clz((unsigned)(x >> 32)); + return !!((unsigned)(x >> 32)) ? h : l; +#endif +} + +static inline int __builtin_clzl(unsigned long x) { + return sizeof(x) == 8 ? __builtin_clzll(x) : __builtin_clz((unsigned)x); +} +#endif + +#include "global.h" +ABC_NAMESPACE_HEADER_START + +//typedef uintptr_t word; typedef uintptr_t w2rd[2]; #define WORD_ALIGNMENT_MASK (sizeof (word) - 1) @@ -21,11 +49,11 @@ typedef uintptr_t w2rd[2]; static inline word kissat_cache_lines (word n, size_t size) { if (!n) return 0; -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) size; #endif - assert (size == 4); - assert (ASSUMED_LD_CACHE_LINE_BYTES > 2); + KISSAT_assert (size == 4); + KISSAT_assert (ASSUMED_LD_CACHE_LINE_BYTES > 2); const unsigned shift = ASSUMED_LD_CACHE_LINE_BYTES - 2u; const word mask = (((word) 1) << shift) - 1; const word masked = n + mask; @@ -131,6 +159,8 @@ static inline unsigned kissat_log2_ceiling_of_uint64 (uint64_t x) { #define MAX(A, B) ((A) < (B) ? (B) : (A)) -#define ABS(A) (assert ((int) (A) != INT_MIN), (A) < 0 ? -(A) : (A)) +#define ABS(A) (KISSAT_assert ((int) (A) != INT_MIN), (A) < 0 ? -(A) : (A)) + +ABC_NAMESPACE_HEADER_END #endif diff --git a/src/sat/kissat/value.h b/src/sat/kissat/value.h index efea7391a..92324ca53 100644 --- a/src/sat/kissat/value.h +++ b/src/sat/kissat/value.h @@ -1,13 +1,18 @@ #ifndef _value_h_INCLUDED #define _value_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef signed char value; typedef signed char mark; -#define VALUE(LIT) (solver->values[assert ((LIT) < LITS), (LIT)]) +#define VALUE(LIT) (solver->values[KISSAT_assert ((LIT) < LITS), (LIT)]) -#define MARK(LIT) (solver->marks[assert ((LIT) < LITS), (LIT)]) +#define MARK(LIT) (solver->marks[KISSAT_assert ((LIT) < LITS), (LIT)]) #define BOOL_TO_VALUE(B) ((signed char) ((B) ? -1 : 1)) +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/vector.c b/src/sat/kissat/vector.c index 728a66f6d..1383c97c5 100644 --- a/src/sat/kissat/vector.c +++ b/src/sat/kissat/vector.c @@ -9,7 +9,9 @@ #include #include -#ifndef COMPACT +ABC_NAMESPACE_IMPL_START + +#ifndef KISSAT_COMPACT static void fix_vector_pointers_after_moving_stack (kissat *solver, ptrdiff_t moved) { @@ -48,20 +50,20 @@ unsigned *kissat_enlarge_vector (kissat *solver, vector *vector) { LOG2 ("enlarging vector %zu[%zu] at %p", old_offset, old_vector_size, (void *) vector); #endif - assert (old_vector_size < MAX_VECTORS / 2); + KISSAT_assert (old_vector_size < MAX_VECTORS / 2); const size_t new_vector_size = old_vector_size ? 2 * old_vector_size : 1; size_t old_stack_size = SIZE_STACK (*stack); size_t capacity = CAPACITY_STACK (*stack); - assert (kissat_is_power_of_two (MAX_VECTORS)); - assert (capacity <= MAX_VECTORS); + KISSAT_assert (kissat_is_power_of_two (MAX_VECTORS)); + KISSAT_assert (capacity <= MAX_VECTORS); size_t available = capacity - old_stack_size; if (new_vector_size > available) { -#if !defined(QUIET) || !defined(COMPACT) +#if !defined(KISSAT_QUIET) || !defined(KISSAT_COMPACT) unsigned *old_begin_stack = BEGIN_STACK (*stack); #endif unsigned enlarged = 0; do { - assert (kissat_is_zero_or_power_of_two (capacity)); + KISSAT_assert (kissat_is_zero_or_power_of_two (capacity)); if (capacity == MAX_VECTORS) kissat_fatal ("maximum vector stack size " @@ -77,34 +79,34 @@ unsigned *kissat_enlarge_vector (kissat *solver, vector *vector) { if (enlarged) { INC (vectors_enlarged); -#if !defined(QUIET) || !defined(COMPACT) +#if !defined(KISSAT_QUIET) || !defined(KISSAT_COMPACT) unsigned *new_begin_stack = BEGIN_STACK (*stack); const ptrdiff_t moved = (char *) new_begin_stack - (char *) old_begin_stack; #endif -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_phase (solver, "vectors", GET (vectors_enlarged), "enlarged to %s entries %s (%s)", FORMAT_COUNT (capacity), FORMAT_BYTES (capacity * sizeof (unsigned)), (moved ? "moved" : "in place")); #endif -#ifndef COMPACT +#ifndef KISSAT_COMPACT if (moved) fix_vector_pointers_after_moving_stack (solver, moved); #endif } - assert (capacity <= MAX_VECTORS); - assert (new_vector_size <= available); + KISSAT_assert (capacity <= MAX_VECTORS); + KISSAT_assert (new_vector_size <= available); } unsigned *begin_old_vector = kissat_begin_vector (solver, vector); unsigned *begin_new_vector = END_STACK (*stack); unsigned *middle_new_vector = begin_new_vector + old_vector_size; unsigned *end_new_vector = begin_new_vector + new_vector_size; - assert (end_new_vector <= stack->allocated); + KISSAT_assert (end_new_vector <= stack->allocated); const size_t old_bytes = old_vector_size * sizeof (unsigned); const size_t delta_size = new_vector_size - old_vector_size; - assert (MAX_SIZE_T / sizeof (unsigned) >= delta_size); + KISSAT_assert (MAX_SIZE_T / sizeof (unsigned) >= delta_size); const size_t delta_bytes = delta_size * sizeof (unsigned); if (old_bytes) { memcpy (begin_new_vector, begin_old_vector, old_bytes); @@ -114,9 +116,9 @@ unsigned *kissat_enlarge_vector (kissat *solver, vector *vector) { kissat_add_usable (solver, delta_size); if (delta_bytes) memset (middle_new_vector, 0xff, delta_bytes); -#ifdef COMPACT +#ifdef KISSAT_COMPACT const uint64_t offset = SIZE_STACK (*stack); - assert (offset <= MAX_VECTORS); + KISSAT_assert (offset <= MAX_VECTORS); vector->offset = offset; LOG2 ("enlarged vector at %p to %u[%u]", (void *) vector, vector->offset, vector->size); @@ -130,12 +132,12 @@ unsigned *kissat_enlarge_vector (kissat *solver, vector *vector) { #endif #endif stack->end = end_new_vector; - assert (begin_new_vector < end_new_vector); - assert (kissat_size_vector (vector) == old_vector_size); + KISSAT_assert (begin_new_vector < end_new_vector); + KISSAT_assert (kissat_size_vector (vector) == old_vector_size); return middle_new_vector; } -#ifdef COMPACT +#ifdef KISSAT_COMPACT typedef unsigned rank; @@ -167,12 +169,12 @@ void kissat_defrag_vectors (kissat *solver, size_t size_unsorted, LOG ("defragmenting vectors size %zu capacity %zu usable %zu", size_vectors, CAPACITY_STACK (*stack), solver->vectors.usable); size_t bytes = size_unsorted * sizeof (unsigned); - unsigned *sorted = kissat_malloc (solver, bytes); + unsigned *sorted = (unsigned*)kissat_malloc (solver, bytes); unsigned size_sorted = 0; for (unsigned i = 0; i < size_unsorted; i++) { vector *vector = unsorted + i; if (kissat_empty_vector (vector)) -#ifdef COMPACT +#ifdef KISSAT_COMPACT vector->offset = 0; #else vector->begin = vector->end = 0; @@ -188,10 +190,10 @@ void kissat_defrag_vectors (kissat *solver, size_t size_unsorted, vector *vector = unsorted + j; const size_t size = kissat_size_vector (vector); unsigned *new_end_of_vector = p + size; -#ifdef COMPACT +#ifdef KISSAT_COMPACT const unsigned old_offset = vector->offset; const unsigned new_offset = p - old_begin_stack; - assert (new_offset <= old_offset); + KISSAT_assert (new_offset <= old_offset); vector->offset = new_offset; const unsigned *const q = old_begin_stack + old_offset; #else @@ -203,25 +205,25 @@ void kissat_defrag_vectors (kissat *solver, size_t size_unsorted, vector->begin = p; vector->end = new_end_of_vector; #endif - assert (MAX_SIZE_T / sizeof (unsigned) >= size); + KISSAT_assert (MAX_SIZE_T / sizeof (unsigned) >= size); memmove (p, q, size * sizeof (unsigned)); p = new_end_of_vector; } kissat_free (solver, sorted, bytes); -#ifndef QUIET +#ifndef KISSAT_QUIET const size_t freed = END_STACK (*stack) - p; double freed_fraction = kissat_percent (freed, size_vectors); kissat_phase (solver, "defrag", GET (defragmentations), "freed %zu usable entries %.0f%% thus %s", freed, freed_fraction, FORMAT_BYTES (freed * sizeof (unsigned))); - assert (freed == solver->vectors.usable); + KISSAT_assert (freed == solver->vectors.usable); #endif SET_END_OF_STACK (*stack, p); -#ifndef COMPACT - assert (old_begin_stack == BEGIN_STACK (*stack)); +#ifndef KISSAT_COMPACT + KISSAT_assert (old_begin_stack == BEGIN_STACK (*stack)); #endif SHRINK_STACK (*stack); -#ifndef COMPACT +#ifndef KISSAT_COMPACT unsigned *new_begin_stack = BEGIN_STACK (*stack); const ptrdiff_t moved = (char *) new_begin_stack - (char *) old_begin_stack; @@ -237,16 +239,16 @@ void kissat_remove_from_vector (kissat *solver, vector *vector, unsigned remove) { unsigned *begin = kissat_begin_vector (solver, vector), *p = begin; const unsigned *const end = kissat_end_vector (solver, vector); - assert (p != end); + KISSAT_assert (p != end); while (*p != remove) - p++, assert (p != end); + p++, KISSAT_assert (p != end); while (++p != end) p[-1] = *p; p[-1] = INVALID_VECTOR_ELEMENT; -#ifdef COMPACT +#ifdef KISSAT_COMPACT vector->size--; #else - assert (vector->begin < vector->end); + KISSAT_assert (vector->begin < vector->end); vector->end--; #endif kissat_inc_usable (solver); @@ -259,10 +261,10 @@ void kissat_remove_from_vector (kissat *solver, vector *vector, void kissat_resize_vector (kissat *solver, vector *vector, size_t new_size) { const size_t old_size = kissat_size_vector (vector); - assert (new_size <= old_size); + KISSAT_assert (new_size <= old_size); if (new_size == old_size) return; -#ifdef COMPACT +#ifdef KISSAT_COMPACT vector->size = new_size; #else vector->end = vector->begin + new_size; @@ -291,8 +293,8 @@ void kissat_check_vector (kissat *solver, vector *vector) { const unsigned *const end = kissat_end_vector (solver, vector); if (!solver->transitive_reducing) for (const unsigned *p = begin; p != end; p++) - assert (*p != INVALID_VECTOR_ELEMENT); -#ifdef NDEBUG + KISSAT_assert (*p != INVALID_VECTOR_ELEMENT); +#ifdef KISSAT_NDEBUG (void) solver; #endif } @@ -314,7 +316,9 @@ void kissat_check_vectors (kissat *solver) { for (const unsigned *p = begin + 1; p != end; p++) if (*p == INVALID_VECTOR_ELEMENT) invalid++; - assert (invalid == solver->vectors.usable); + KISSAT_assert (invalid == solver->vectors.usable); } #endif + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/vector.h b/src/sat/kissat/vector.h index 55ff2ac1d..5353a2e7b 100644 --- a/src/sat/kissat/vector.h +++ b/src/sat/kissat/vector.h @@ -6,7 +6,10 @@ #include -#ifdef COMPACT +#include "global.h" +ABC_NAMESPACE_HEADER_START + +#ifdef KISSAT_COMPACT #define LD_MAX_VECTORS (sizeof (word) == 8 ? 32u : 28u) #else #define LD_MAX_VECTORS (sizeof (word) == 8 ? 48u : 28u) @@ -27,7 +30,7 @@ struct vectors { }; struct vector { -#ifdef COMPACT +#ifdef KISSAT_COMPACT unsigned offset; unsigned size; #else @@ -52,4 +55,6 @@ void kissat_remove_from_vector (struct kissat *, vector *, unsigned); void kissat_resize_vector (struct kissat *, vector *, size_t); void kissat_release_vectors (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/vivify.c b/src/sat/kissat/vivify.c index 6627c640e..f1d677e4d 100644 --- a/src/sat/kissat/vivify.c +++ b/src/sat/kissat/vivify.c @@ -21,6 +21,8 @@ #include #include +ABC_NAMESPACE_IMPL_START + static inline bool more_occurrences (unsigned *counts, unsigned a, unsigned b) { const unsigned s = counts[a], t = counts[b]; @@ -57,7 +59,7 @@ static void count_clause (clause *c, unsigned *counts) { static bool simplify_vivification_candidate (kissat *solver, clause *const c) { - assert (!solver->level); + KISSAT_assert (!solver->level); CLEAR_STACK (solver->clause); const value *const values = solver->values; @@ -74,7 +76,7 @@ static bool simplify_vivification_candidate (kissat *solver, } unsigned non_false = SIZE_STACK (solver->clause); - assert (non_false <= c->size); + KISSAT_assert (non_false <= c->size); if (non_false == c->size) return false; @@ -87,7 +89,7 @@ static bool simplify_vivification_candidate (kissat *solver, return true; } - assert (2 < non_false); + KISSAT_assert (2 < non_false); CHECK_AND_ADD_STACK (solver->clause); ADD_STACK_TO_PROOF (solver->clause); @@ -100,14 +102,14 @@ static bool simplify_vivification_candidate (kissat *solver, for (unsigned i = 0; i < old_size; i++) { const unsigned lit = lits[i]; const value value = values[lit]; - assert (value <= 0); + KISSAT_assert (value <= 0); if (!value) lits[new_size++] = lit; } - assert (2 < new_size); - assert (new_size == non_false); - assert (new_size < old_size); + KISSAT_assert (2 < new_size); + KISSAT_assert (new_size == non_false); + KISSAT_assert (new_size < old_size); c->size = new_size; c->searched = 2; @@ -154,7 +156,7 @@ struct vivifier { size_t scheduled, tried, vivified; countrefs countrefs; unsigneds sorted; -#ifndef QUIET +#ifndef KISSAT_QUIET const char *mode; const char *name; char tag; @@ -166,7 +168,7 @@ typedef struct vivifier vivifier; static void init_vivifier (kissat *solver, vivifier *vivifier) { vivifier->solver = solver; - vivifier->counts = kissat_calloc (solver, LITS, sizeof (unsigned)); + vivifier->counts = (unsigned*)kissat_calloc (solver, LITS, sizeof (unsigned)); INIT_STACK (vivifier->schedule); INIT_STACK (vivifier->countrefs); INIT_STACK (vivifier->sorted); @@ -175,7 +177,7 @@ static void init_vivifier (kissat *solver, vivifier *vivifier) { static void set_vivifier_mode (vivifier *vivifier, int tier) { vivifier->tier = tier; -#ifndef QUIET +#ifndef KISSAT_QUIET switch (tier) { case 1: vivifier->mode = "vivify-tier1"; @@ -188,13 +190,13 @@ static void set_vivifier_mode (vivifier *vivifier, int tier) { vivifier->tag = 'v'; break; case 3: - assert (tier == 3); + KISSAT_assert (tier == 3); vivifier->mode = "vivify-tier3"; vivifier->name = "tier3"; vivifier->tag = 'w'; break; default: - assert (tier == 0); + KISSAT_assert (tier == 0); vivifier->mode = "vivify-irredundant"; vivifier->name = "irredundant"; vivifier->tag = 'x'; @@ -235,7 +237,7 @@ static void schedule_vivification_candidates (vivifier *vivifier) { unsigned lower_glue_limit, upper_glue_limit; unsigned tier1 = vivify_tier1_limit (solver); unsigned tier2 = MAX (tier1, vivify_tier2_limit (solver)); - assert (tier1 <= tier2); + KISSAT_assert (tier1 <= tier2); switch (tier) { case 1: lower_glue_limit = 0; @@ -250,12 +252,12 @@ static void schedule_vivification_candidates (vivifier *vivifier) { upper_glue_limit = UINT_MAX; break; default: - assert (tier == 0); + KISSAT_assert (tier == 0); lower_glue_limit = 0; upper_glue_limit = UINT_MAX; break; } - assert (lower_glue_limit <= upper_glue_limit); + KISSAT_assert (lower_glue_limit <= upper_glue_limit); ward *const arena = BEGIN_STACK (solver->arena); size_t prioritized = 0; unsigned *counts = vivifier->counts; @@ -296,7 +298,7 @@ static void schedule_vivification_candidates (vivifier *vivifier) { "prioritizing all %zu scheduled clauses", scheduled); for (all_stack (reference, ref, *schedule)) { clause *c = (clause *) (arena + ref); - assert (kissat_clause_in_arena (solver, c)); + KISSAT_assert (kissat_clause_in_arena (solver, c)); c->vivify = true; } } @@ -339,7 +341,7 @@ static inline bool worse_candidate (kissat *solver, unsigned *counts, if (p == e && q != f) return false; - assert (p == e && q == f); + KISSAT_assert (p == e && q == f); if (a < b) return true; @@ -371,8 +373,8 @@ static void sort_scheduled_candidate_literals (vivifier *vivifier) { static inline void init_countref (countref *cr, clause *c, reference ref, unsigned *counts) { - assert (COUNTREF_COUNTS <= c->size); - assert (c->size <= MAX_COUNTREF_SIZE); + KISSAT_assert (COUNTREF_COUNTS <= c->size); + KISSAT_assert (c->size <= MAX_COUNTREF_SIZE); cr->size = c->size; cr->vivify = c->vivify; cr->ref = ref; @@ -381,19 +383,24 @@ static inline void init_countref (countref *cr, clause *c, reference ref, unsigned best = INVALID_LIT; unsigned best_count = 0; for (all_literals_in_clause (lit, c)) { + int continue_with_next_literal = 0; for (unsigned j = 0; j != i; j++) - if (lits[j] == lit) - goto CONTINUE_WITH_NEXT_LITERAL; + if (lits[j] == lit) { + continue_with_next_literal = 1; + break; + } + if(continue_with_next_literal) { + continue; + } const unsigned lit_count = counts[lit]; - assert (lit_count); + KISSAT_assert (lit_count); if (lit_count <= best_count) continue; best_count = lit_count; best = lit; - CONTINUE_WITH_NEXT_LITERAL:; } - assert (best != INVALID_LIT); - assert (best_count); + KISSAT_assert (best != INVALID_LIT); + KISSAT_assert (best_count); cr->count[i] = best_count; lits[i] = best; } @@ -404,7 +411,7 @@ static void init_countrefs (vivifier *vivifier) { references *schedule = &vivifier->schedule; countrefs *countrefs = &vivifier->countrefs; unsigned *counts = vivifier->counts; - assert (EMPTY_STACK (*countrefs)); + KISSAT_assert (EMPTY_STACK (*countrefs)); for (all_stack (reference, ref, *schedule)) { clause *c = kissat_dereference_clause (solver, ref); countref countref; @@ -433,14 +440,14 @@ static void copy_countrefs (vivifier *vivifier) { kissat *solver = vivifier->solver; references *schedule = &vivifier->schedule; countrefs *countrefs = &vivifier->countrefs; - assert (EMPTY_STACK (*schedule)); + KISSAT_assert (EMPTY_STACK (*schedule)); for (all_stack (countref, cr, *countrefs)) PUSH_STACK (*schedule, cr.ref); RELEASE_STACK (*countrefs); } static void sort_vivification_candidates (vivifier *vivifier) { -#ifndef QUIET +#ifndef KISSAT_QUIET kissat *solver = vivifier->solver; #endif START (vivifysort); @@ -471,35 +478,35 @@ static void vivify_deduce (vivifier *vivifier, clause *candidate, bool redundant = false; bool subsumes = false; - assert (solver->level); - assert (EMPTY_STACK (solver->clause)); - assert (EMPTY_STACK (solver->analyzed)); + KISSAT_assert (solver->level); + KISSAT_assert (EMPTY_STACK (solver->clause)); + KISSAT_assert (EMPTY_STACK (solver->analyzed)); if (implied != INVALID_LIT) { unsigned not_implied = NOT (implied); LOG ("vivify analyzing %s", LOGLIT (not_implied)); assigned *const a = ASSIGNED (not_implied); - assert (a->level); - assert (!a->analyzed); + KISSAT_assert (a->level); + KISSAT_assert (!a->analyzed); a->analyzed = true; PUSH_STACK (solver->analyzed, not_implied); PUSH_STACK (solver->clause, implied); } else { clause *reason = conflict ? conflict : candidate; - assert (reason), assert (!reason->garbage); + KISSAT_assert (reason), KISSAT_assert (!reason->garbage); if (reason->redundant) redundant = true; subsumes = (reason != candidate); for (all_literals_in_clause (other, reason)) { - assert (VALUE (other) < 0); + KISSAT_assert (VALUE (other) < 0); const value value = kissat_fixed (solver, other); if (value < 0) continue; LOG ("vivify analyzing %s", LOGLIT (other)); - assert (!value); + KISSAT_assert (!value); assigned *const a = ASSIGNED (other); - assert (a->level); - assert (!a->analyzed); + KISSAT_assert (a->level); + KISSAT_assert (!a->analyzed); a->analyzed = true; PUSH_STACK (solver->analyzed, other); if (solver->marks[other] <= 0) @@ -520,11 +527,11 @@ static void vivify_deduce (vivifier *vivifier, clause *candidate, while (analyzed < SIZE_STACK (solver->analyzed)) { const unsigned not_lit = PEEK_STACK (solver->analyzed, analyzed); const unsigned lit = NOT (not_lit); - assert (VALUE (lit) > 0); + KISSAT_assert (VALUE (lit) > 0); analyzed++; assigned *a = ASSIGNED (lit); - assert (a->level); - assert (a->analyzed); + KISSAT_assert (a->level); + KISSAT_assert (a->analyzed); if (a->reason == DECISION_REASON) { LOG ("vivify analyzing decision %s", LOGLIT (not_lit)); PUSH_STACK (solver->clause, not_lit); @@ -536,9 +543,9 @@ static void vivify_deduce (vivifier *vivifier, clause *candidate, *subsuming_ptr = kissat_binary_conflict (solver, lit, other); return; } - assert (VALUE (other) < 0); + KISSAT_assert (VALUE (other) < 0); assigned *b = ASSIGNED (other); - assert (b->level); + KISSAT_assert (b->level); if (b->analyzed) continue; LOGBINARY (lit, other, "vivify analyzing %s reason", LOGLIT (lit)); @@ -548,7 +555,7 @@ static void vivify_deduce (vivifier *vivifier, clause *candidate, const reference ref = a->reason; LOGREF (ref, "vivify analyzing %s reason", LOGLIT (lit)); clause *reason = kissat_dereference_clause (solver, ref); - assert (reason != candidate); + KISSAT_assert (reason != candidate); if (reason->redundant) redundant = true; subsumes = true; @@ -557,8 +564,8 @@ static void vivify_deduce (vivifier *vivifier, clause *candidate, subsumes = false; if (other == lit) continue; - assert (other != not_lit); - assert (VALUE (other) < 0); + KISSAT_assert (other != not_lit); + KISSAT_assert (VALUE (other) < 0); assigned *b = ASSIGNED (other); if (!b->level) continue; @@ -600,7 +607,7 @@ static void reset_vivify_analyzed (vivifier *vivifier) { static bool vivify_shrinkable (kissat *solver, unsigneds *sorted, clause *conflict) { - assert (SIZE_STACK (solver->clause) <= SIZE_STACK (*sorted)); + KISSAT_assert (SIZE_STACK (solver->clause) <= SIZE_STACK (*sorted)); if (SIZE_STACK (solver->clause) == SIZE_STACK (*sorted)) return false; const assigned *const assigned = solver->assigned; @@ -623,10 +630,10 @@ static bool vivify_shrinkable (kissat *solver, unsigneds *sorted, return true; } } else { - assert (value < 0); + KISSAT_assert (value < 0); const unsigned idx = IDX (lit); const struct assigned *const a = assigned + idx; - assert (a->level); + KISSAT_assert (a->level); if (!a->analyzed) { LOG ("vivification non-analyzed %s thus shrinking", LOGLIT (lit)); return true; @@ -644,15 +651,15 @@ static bool vivify_shrinkable (kissat *solver, unsigneds *sorted, static void vivify_learn_unit (kissat *solver, clause *c) { LOG ("vivification learns unit clause"); - assert (SIZE_STACK (solver->clause) == 1); + KISSAT_assert (SIZE_STACK (solver->clause) == 1); kissat_backtrack_without_updating_phases (solver, 0); const unsigned unit = PEEK_STACK (solver->clause, 0); kissat_learned_unit (solver, unit); solver->iterating = true; kissat_mark_clause_as_garbage (solver, c); - assert (!solver->level); + KISSAT_assert (!solver->level); clause *conflict = kissat_probing_propagate (solver, 0, true); - assert (!conflict || solver->inconsistent); + KISSAT_assert (!conflict || solver->inconsistent); INC (vivify_units); (void) conflict; } @@ -660,7 +667,7 @@ static void vivify_learn_unit (kissat *solver, clause *c) { static void vivify_learn_binary (kissat *solver, clause *c) { LOG ("vivification learns binary clause"); kissat_backtrack_without_updating_phases (solver, 0); - assert (SIZE_STACK (solver->clause) == 2); + KISSAT_assert (SIZE_STACK (solver->clause) == 2); if (c->redundant) (void) kissat_new_redundant_clause (solver, 1); else @@ -671,7 +678,7 @@ static void vivify_learn_binary (kissat *solver, clause *c) { static void swap_first_literal_with_best_watch (kissat *solver, unsigned *lits, unsigned size) { - assert (size); + KISSAT_assert (size); unsigned *best_ptr = lits; unsigned first = *best_ptr, best = first; signed char value = VALUE (best); @@ -715,7 +722,7 @@ static void vivify_watch_clause (kissat *solver, clause *c) { static void vivify_learn_large (kissat *solver, clause *c, unsigned implied) { - assert (!c->garbage); + KISSAT_assert (!c->garbage); LOG ("vivification learns large clause"); CHECK_AND_ADD_STACK (solver->clause); @@ -736,7 +743,7 @@ static void vivify_learn_large (kissat *solver, clause *c, unsigneds *learned = &solver->clause; const unsigned old_size = c->size; const unsigned new_size = SIZE_STACK (*learned); - assert (new_size <= old_size); + KISSAT_assert (new_size <= old_size); unsigned *lits = c->lits; memcpy (lits, BEGIN_STACK (*learned), new_size * sizeof *lits); @@ -745,7 +752,7 @@ static void vivify_learn_large (kissat *solver, clause *c, for (all_literals_in_clause (lit, c)) kissat_mark_added_literal (solver, lit); - assert (new_size < old_size); + KISSAT_assert (new_size < old_size); if (!c->shrunken) { c->shrunken = true; lits[old_size - 1] = INVALID_LIT; @@ -760,7 +767,7 @@ static void vivify_learn_large (kissat *solver, clause *c, kissat_backtrack_without_updating_phases (solver, new_size - 2); } else { LOGCLS (c, "vivified shrunken after implied"); - assert (solver->level >= new_size - 1); + KISSAT_assert (solver->level >= new_size - 1); } vivify_watch_clause (solver, c); @@ -780,23 +787,23 @@ static void binary_strengthen_after_instantiation (kissat *solver, clause *c, unsigned remove) { LOG ("vivification instantiation yields binary clause"); - assert (solver->level == 3); + KISSAT_assert (solver->level == 3); unsigned first = INVALID_LIT, second = INVALID_LIT; for (all_literals_in_clause (lit, c)) if (lit != remove) { - assert (VALUE (lit) < 0); + KISSAT_assert (VALUE (lit) < 0); if (LEVEL (lit)) { if (first == INVALID_LIT) first = lit; else { - assert (second == INVALID_LIT); + KISSAT_assert (second == INVALID_LIT); second = lit; } } } - assert (first != INVALID_LIT); - assert (second != INVALID_LIT); + KISSAT_assert (first != INVALID_LIT); + KISSAT_assert (second != INVALID_LIT); LOGBINARY (first, second, "vivified strengthened through instantiation"); CLEAR_STACK (solver->clause); PUSH_STACK (solver->clause, first); @@ -813,7 +820,7 @@ static void binary_strengthen_after_instantiation (kissat *solver, static void large_strengthen_after_instantiation (kissat *solver, clause *c, unsigned remove) { LOG ("vivification instantiation yields large clause"); - assert (solver->level > 3); + KISSAT_assert (solver->level > 3); SHRINK_CLAUSE_IN_PROOF (c, remove, INVALID_LIT); CHECK_SHRINK_CLAUSE (c, remove, INVALID_LIT); @@ -822,7 +829,7 @@ static void large_strengthen_after_instantiation (kissat *solver, clause *c, bool irredundant = !c->redundant; const unsigned old_size = c->size; - assert (old_size > 3); + KISSAT_assert (old_size > 3); unsigned new_size = 0, *lits = c->lits; for (unsigned i = 0; i != old_size; i++) { const unsigned lit = lits[i]; @@ -835,8 +842,8 @@ static void large_strengthen_after_instantiation (kissat *solver, clause *c, kissat_mark_added_literal (solver, lit); } } - assert (2 < new_size); - assert (new_size < old_size); + KISSAT_assert (2 < new_size); + KISSAT_assert (new_size < old_size); if (!c->shrunken) { c->shrunken = true; lits[old_size - 1] = INVALID_LIT; @@ -854,9 +861,9 @@ static void large_strengthen_after_instantiation (kissat *solver, clause *c, static void vivify_strengthen_after_instantiation (kissat *solver, clause *c, unsigned remove) { - assert (solver->level >= 3); - assert (VALUE (remove) > 0); - assert (LEVEL (remove) == solver->level); + KISSAT_assert (solver->level >= 3); + KISSAT_assert (VALUE (remove) > 0); + KISSAT_assert (LEVEL (remove) == solver->level); if (solver->level == 3) binary_strengthen_after_instantiation (solver, c, remove); @@ -870,7 +877,7 @@ static void vivify_mark_sorted_literals (vivifier *vivifier) { unsigneds *sorted = &vivifier->sorted; value *marks = solver->marks; for (all_stack (unsigned, lit, *sorted)) - assert (!marks[lit]), marks[lit] = 1, marks[NOT (lit)] = -1; + KISSAT_assert (!marks[lit]), marks[lit] = 1, marks[NOT (lit)] = -1; } static void vivify_unmark_sorted_literals (vivifier *vivifier) { @@ -879,7 +886,7 @@ static void vivify_unmark_sorted_literals (vivifier *vivifier) { unsigneds *sorted = &vivifier->sorted; value *marks = solver->marks; for (all_stack (unsigned, lit, *sorted)) - assert (solver->marks[lit] > 0), assert (marks[NOT (lit)] < 0), + KISSAT_assert (solver->marks[lit] > 0), KISSAT_assert (marks[NOT (lit)] < 0), marks[lit] = marks[NOT (lit)] = 0; } @@ -912,10 +919,10 @@ static void reestablish_watch_invariant_for_candidate (kissat *solver, return; new_level = second_level; } else { - assert (first_val < 0), assert (second_val < 0); + KISSAT_assert (first_val < 0), KISSAT_assert (second_val < 0); new_level = MIN (first_level, second_level); } - assert (new_level); + KISSAT_assert (new_level); LOGCLS (candidate, "reestablish watch invariant by backtracking to %u", new_level - 1); kissat_backtrack_without_updating_phases (solver, new_level - 1); @@ -923,13 +930,13 @@ static void reestablish_watch_invariant_for_candidate (kissat *solver, static bool vivify_clause (vivifier *vivifier, clause *candidate) { - assert (!candidate->garbage); + KISSAT_assert (!candidate->garbage); kissat *solver = vivifier->solver; - assert (solver->probing); - assert (solver->watching); - assert (!solver->inconsistent); + KISSAT_assert (solver->probing); + KISSAT_assert (solver->watching); + KISSAT_assert (!solver->inconsistent); LOGCLS (candidate, "vivifying candidate"); LOGCOUNTEDCLS (candidate, vivifier->counts, @@ -950,12 +957,12 @@ static bool vivify_clause (vivifier *vivifier, clause *candidate) { PUSH_STACK (*sorted, lit); } - assert (!candidate->garbage); + KISSAT_assert (!candidate->garbage); const unsigned non_false = SIZE_STACK (*sorted); - assert (1 < non_false); - assert (non_false <= candidate->size); + KISSAT_assert (1 < non_false); + KISSAT_assert (non_false <= candidate->size); #ifdef LOGGING if (non_false == candidate->size) @@ -980,7 +987,7 @@ static bool vivify_clause (vivifier *vivifier, clause *candidate) { unit = INVALID_LIT; break; } - assert (value > 0); + KISSAT_assert (value > 0); if (unit != INVALID_LIT) { unit = INVALID_LIT; break; @@ -990,7 +997,7 @@ static bool vivify_clause (vivifier *vivifier, clause *candidate) { reference cand_ref = kissat_reference_clause (solver, candidate); if (unit != INVALID_LIT) { assigned *a = ASSIGNED (unit); - assert (a->level); + KISSAT_assert (a->level); if (a->binary) unit = INVALID_LIT; else { @@ -1003,13 +1010,13 @@ static bool vivify_clause (vivifier *vivifier, clause *candidate) { else { LOG ("candidate is the reason of %s", LOGLIT (unit)); const unsigned level = LEVEL (unit); - assert (level > 0); + KISSAT_assert (level > 0); LOG ("forced to backtrack to level %u", level - 1); kissat_backtrack_without_updating_phases (solver, level - 1); } - assert (EMPTY_STACK (solver->analyzed)); - assert (EMPTY_STACK (solver->clause)); + KISSAT_assert (EMPTY_STACK (solver->analyzed)); + KISSAT_assert (EMPTY_STACK (solver->clause)); unsigned *counts = vivifier->counts; vivify_sort_stack_by_counts (solver, sorted, counts); @@ -1038,7 +1045,7 @@ static bool vivify_clause (vivifier *vivifier, clause *candidate) { LOG ("reusing assumption %s", LOGLIT (not_lit)); INC (vivify_reused); INC (vivify_probes); - assert (VALUE (lit) < 0); + KISSAT_assert (VALUE (lit) < 0); continue; } @@ -1047,29 +1054,29 @@ static bool vivify_clause (vivifier *vivifier, clause *candidate) { } const value value = VALUE (lit); - assert (!value || LEVEL (lit) <= level); + KISSAT_assert (!value || LEVEL (lit) <= level); if (value < 0) { - assert (LEVEL (lit)); + KISSAT_assert (LEVEL (lit)); LOG ("literal %s already falsified", LOGLIT (lit)); continue; } if (value > 0) { - assert (LEVEL (lit)); + KISSAT_assert (LEVEL (lit)); LOG ("literal %s already initially satisfied", LOGLIT (lit)); implied = lit; break; } - assert (!value); + KISSAT_assert (!value); LOG ("literal %s unassigned", LOGLIT (lit)); const unsigned not_lit = NOT (lit); INC (vivify_probes); kissat_internal_assume (solver, not_lit); - assert (solver->level >= 1); + KISSAT_assert (solver->level >= 1); const unsigned *p = solver->propagate; conflict = kissat_probing_propagate (solver, candidate, true); @@ -1095,7 +1102,7 @@ EXIT_ASSUMPTION_LOOP:; LOG ("vivification assumptions propagate without conflict nor " "producing an implied literal"); #endif - assert (!conflict || implied == INVALID_LIT); + KISSAT_assert (!conflict || implied == INVALID_LIT); if (implied != INVALID_LIT) { unsigned better_implied = INVALID_LIT; @@ -1117,7 +1124,7 @@ EXIT_ASSUMPTION_LOOP:; } unsigned level_after_assumptions = solver->level; - assert (level_after_assumptions); + KISSAT_assert (level_after_assumptions); clause *subsuming = 0; bool redundant = false; @@ -1129,7 +1136,7 @@ EXIT_ASSUMPTION_LOOP:; bool res; if (subsuming) { - assert (!subsuming->garbage); + KISSAT_assert (!subsuming->garbage); if (candidate->redundant) { LOGCLS (candidate, "vivification subsumed"); kissat_mark_clause_as_garbage (solver, candidate); @@ -1141,22 +1148,22 @@ EXIT_ASSUMPTION_LOOP:; INC (vivified_subsumed); res = true; } else if (!subsuming->redundant) { - assert (!candidate->redundant); + KISSAT_assert (!candidate->redundant); LOGCLS (candidate, "vivification subsumed"); kissat_mark_clause_as_garbage (solver, candidate); INC (vivified_subirr); INC (vivified_subsumed); res = true; } else { - assert (!candidate->redundant); - assert (subsuming->redundant); + KISSAT_assert (!candidate->redundant); + KISSAT_assert (subsuming->redundant); LOGCLS (candidate, "vivification subsumed"); kissat_mark_clause_as_garbage (solver, candidate); subsuming->redundant = false; - assert (solver->statistics.clauses_redundant); - solver->statistics.clauses_redundant--; - assert (solver->statistics.clauses_irredundant < UINT64_MAX); - solver->statistics.clauses_irredundant++; + KISSAT_assert (solver->statistics_.clauses_redundant); + solver->statistics_.clauses_redundant--; + KISSAT_assert (solver->statistics_.clauses_irredundant < UINT64_MAX); + solver->statistics_.clauses_irredundant++; INC (vivified_promoted); LOGCLS (subsuming, "vivification promoted from redundant to"); kissat_update_last_irredundant (solver, subsuming); @@ -1188,20 +1195,20 @@ EXIT_ASSUMPTION_LOOP:; LOGCLS (candidate, "no vivification instantiation with implied literal %s", LOGLIT (implied)); - assert (!candidate->redundant); - assert (redundant); + KISSAT_assert (!candidate->redundant); + KISSAT_assert (redundant); res = false; } else { - assert (solver->level > 2); - assert (solver->level == SIZE_STACK (*sorted)); + KISSAT_assert (solver->level > 2); + KISSAT_assert (solver->level == SIZE_STACK (*sorted)); unsigned lit = TOP_STACK (*sorted); - assert (VALUE (lit) < 0); - assert (LEVEL (lit) == solver->level); + KISSAT_assert (VALUE (lit) < 0); + KISSAT_assert (LEVEL (lit) == solver->level); LOG ("trying vivification instantiation of %s#%u respectively %s#%u", LOGLIT (lit), counts[lit], LOGLIT (NOT (lit)), counts[NOT (lit)]); kissat_backtrack_without_updating_phases (solver, solver->level - 1); conflict = 0; - assert (!VALUE (lit)); + KISSAT_assert (!VALUE (lit)); kissat_internal_assume (solver, lit); LOGCLS (candidate, "vivification instantiation candidate"); conflict = kissat_probing_propagate (solver, candidate, true); @@ -1241,7 +1248,7 @@ EXIT_ASSUMPTION_LOOP:; INC (vivified_tier3); break; default: - assert (vivifier->tier == 0); + KISSAT_assert (vivifier->tier == 0); INC (vivified_irredundant); break; } @@ -1258,9 +1265,9 @@ static void vivify_round (vivifier *vivifier, uint64_t limit) { if (tier && !REDUNDANT_CLAUSES) return; - assert (0 <= tier && tier <= 3); - assert (solver->watching); - assert (solver->probing); + KISSAT_assert (0 <= tier && tier <= 3); + KISSAT_assert (solver->watching); + KISSAT_assert (solver->probing); kissat_flush_large_watches (solver); @@ -1274,8 +1281,8 @@ static void vivify_round (vivifier *vivifier, uint64_t limit) { } kissat_watch_large_clauses (solver); -#ifndef QUIET - uint64_t start = solver->statistics.probing_ticks; +#ifndef KISSAT_QUIET + uint64_t start = solver->statistics_.probing_ticks; uint64_t delta = limit - start; kissat_very_verbose (solver, "vivification %s effort limit %" PRIu64 " = %" PRIu64 @@ -1287,10 +1294,10 @@ static void vivify_round (vivifier *vivifier, uint64_t limit) { "scheduled %zu clauses %.0f%% of %zu", scheduled, kissat_percent (scheduled, total), total); #endif - assert (!vivifier->vivified); - assert (!vivifier->tried); + KISSAT_assert (!vivifier->vivified); + KISSAT_assert (!vivifier->tried); while (!EMPTY_STACK (vivifier->schedule)) { - const uint64_t probing_ticks = solver->statistics.probing_ticks; + const uint64_t probing_ticks = solver->statistics_.probing_ticks; if (probing_ticks > limit) { kissat_extremely_verbose (solver, "vivification %s ticks limit %" PRIu64 @@ -1302,7 +1309,7 @@ static void vivify_round (vivifier *vivifier, uint64_t limit) { break; const reference ref = POP_STACK (vivifier->schedule); clause *candidate = kissat_dereference_clause (solver, ref); - assert (!candidate->garbage); + KISSAT_assert (!candidate->garbage); vivifier->tried++; if (vivify_clause (vivifier, candidate)) vivifier->vivified++; @@ -1312,7 +1319,7 @@ static void vivify_round (vivifier *vivifier, uint64_t limit) { } if (solver->level) kissat_backtrack_without_updating_phases (solver, 0); -#ifndef QUIET +#ifndef KISSAT_QUIET kissat_phase (solver, vivifier->mode, GET (vivifications), "vivified %zu clauses %.0f%% out of %zu tried", vivifier->vivified, @@ -1350,7 +1357,7 @@ static void vivify_round (vivifier *vivifier, uint64_t limit) { } static void vivify_tier1 (vivifier *vivifier, uint64_t limit) { -#ifndef QUIET +#ifndef KISSAT_QUIET kissat *solver = vivifier->solver; #endif START (vivify1); @@ -1360,7 +1367,7 @@ static void vivify_tier1 (vivifier *vivifier, uint64_t limit) { } static void vivify_tier2 (vivifier *vivifier, uint64_t limit) { -#ifndef QUIET +#ifndef KISSAT_QUIET kissat *solver = vivifier->solver; #endif START (vivify2); @@ -1371,7 +1378,7 @@ static void vivify_tier2 (vivifier *vivifier, uint64_t limit) { } static void vivify_tier3 (vivifier *vivifier, uint64_t limit) { -#ifndef QUIET +#ifndef KISSAT_QUIET kissat *solver = vivifier->solver; #endif START (vivify3); @@ -1382,7 +1389,7 @@ static void vivify_tier3 (vivifier *vivifier, uint64_t limit) { } static void vivify_irredundant (vivifier *vivifier, uint64_t limit) { -#ifndef QUIET +#ifndef KISSAT_QUIET kissat *solver = vivifier->solver; #endif START (vivify0); @@ -1395,9 +1402,9 @@ static void vivify_irredundant (vivifier *vivifier, uint64_t limit) { void kissat_vivify (kissat *solver) { if (solver->inconsistent) return; - assert (!solver->level); - assert (solver->probing); - assert (solver->watching); + KISSAT_assert (!solver->level); + KISSAT_assert (solver->probing); + KISSAT_assert (solver->watching); if (!GET_OPTION (vivify)) return; if (TERMINATED (vivify_terminated_2)) @@ -1414,14 +1421,14 @@ void kissat_vivify (kissat *solver) { START (vivify); INC (vivifications); -#if !defined(NDEBUG) || defined(METRICS) - assert (!solver->vivifying); +#if !defined(KISSAT_NDEBUG) || defined(METRICS) + KISSAT_assert (!solver->vivifying); solver->vivifying = true; #endif SET_EFFORT_LIMIT (limit, vivify, probing_ticks); - const uint64_t total = limit - solver->statistics.probing_ticks; - limit = solver->statistics.probing_ticks; + const uint64_t total = limit - solver->statistics_.probing_ticks; + limit = solver->statistics_.probing_ticks; unsigned tier1_limit = vivify_tier1_limit (solver); unsigned tier2_limit = vivify_tier2_limit (solver); if (tier1_budget && tier2_budget && tier1_limit == tier2_limit) { @@ -1459,22 +1466,24 @@ void kissat_vivify (kissat *solver) { release_vivifier (&vivifier); } -#ifndef QUIET - if (solver->statistics.probing_ticks < limit) { - uint64_t delta = limit - solver->statistics.probing_ticks; +#ifndef KISSAT_QUIET + if (solver->statistics_.probing_ticks < limit) { + uint64_t delta = limit - solver->statistics_.probing_ticks; kissat_phase (solver, "vivify-limit", GET (vivifications), "has %" PRIu64 " ticks left %.2f%%", delta, kissat_percent (delta, total)); } else { - uint64_t delta = solver->statistics.probing_ticks - limit; + uint64_t delta = solver->statistics_.probing_ticks - limit; kissat_phase (solver, "vivify-limit", GET (vivifications), "exceeded by %" PRIu64 " ticks %.2f%%", delta, kissat_percent (delta, total)); } #endif -#if !defined(NDEBUG) || defined(METRICS) - assert (solver->vivifying); +#if !defined(KISSAT_NDEBUG) || defined(METRICS) + KISSAT_assert (solver->vivifying); solver->vivifying = false; #endif STOP (vivify); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/vivify.h b/src/sat/kissat/vivify.h index a83ac9303..42ec2f2c3 100644 --- a/src/sat/kissat/vivify.h +++ b/src/sat/kissat/vivify.h @@ -1,8 +1,13 @@ #ifndef _vivify_h_INCLUDED #define _vivify_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_vivify (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/walk.c b/src/sat/kissat/walk.c index 88974ee7a..72ce38a6c 100644 --- a/src/sat/kissat/walk.c +++ b/src/sat/kissat/walk.c @@ -12,6 +12,8 @@ #include +ABC_NAMESPACE_IMPL_START + typedef struct tagged tagged; typedef struct counter counter; typedef struct walker walker; @@ -25,8 +27,8 @@ struct tagged { }; static inline tagged make_tagged (bool binary, unsigned ref) { - assert (ref <= MAX_WALK_REF); - tagged res = {.binary = binary, .ref = ref}; + KISSAT_assert (ref <= MAX_WALK_REF); + tagged res = {.ref = ref, .binary = binary}; return res; } @@ -71,7 +73,7 @@ struct walker { uint64_t limit; uint64_t flipped; -#ifndef QUIET +#ifndef KISSAT_QUIET uint64_t start; struct { uint64_t flipped; @@ -83,7 +85,7 @@ struct walker { static const unsigned *dereference_literals (kissat *solver, walker *walker, unsigned counter_ref, unsigned *size_ptr) { - assert (counter_ref < walker->clauses); + KISSAT_assert (counter_ref < walker->clauses); tagged tagged = walker->refs[counter_ref]; unsigned const *lits; if (tagged.binary) { @@ -101,9 +103,9 @@ static const unsigned *dereference_literals (kissat *solver, walker *walker, static void push_unsat (kissat *solver, walker *walker, counter *counters, unsigned counter_ref) { - assert (counter_ref < walker->clauses); + KISSAT_assert (counter_ref < walker->clauses); counter *counter = counters + counter_ref; - assert (SIZE_STACK (walker->unsat) <= UINT_MAX); + KISSAT_assert (SIZE_STACK (walker->unsat) <= UINT_MAX); counter->pos = SIZE_STACK (walker->unsat); PUSH_STACK (walker->unsat, counter_ref); #ifdef LOGGING @@ -116,18 +118,18 @@ static void push_unsat (kissat *solver, walker *walker, counter *counters, static bool pop_unsat (kissat *solver, walker *walker, counter *counters, unsigned counter_ref, unsigned pos) { - assert (walker->current); - assert (counter_ref < walker->clauses); - assert (counters[counter_ref].pos == pos); - assert (walker->current == SIZE_STACK (walker->unsat)); + KISSAT_assert (walker->current); + KISSAT_assert (counter_ref < walker->clauses); + KISSAT_assert (counters[counter_ref].pos == pos); + KISSAT_assert (walker->current == SIZE_STACK (walker->unsat)); const unsigned other_counter_ref = POP_STACK (walker->unsat); walker->current--; bool res = false; if (counter_ref != other_counter_ref) { - assert (other_counter_ref < walker->clauses); + KISSAT_assert (other_counter_ref < walker->clauses); counter *other_counter = counters + other_counter_ref; - assert (other_counter->pos == walker->current); - assert (pos < other_counter->pos); + KISSAT_assert (other_counter->pos == walker->current); + KISSAT_assert (pos < other_counter->pos); other_counter->pos = pos; POKE_STACK (walker->unsat, pos, other_counter_ref); res = true; @@ -155,9 +157,9 @@ static double fit_cbval (double size) { const double x2 = cbvals[i + 1][0], x1 = cbvals[i][0]; const double y2 = cbvals[i + 1][1], y1 = cbvals[i][1]; const double dx = x2 - x1, dy = y2 - y1; - assert (dx); + KISSAT_assert (dx); const double res = dy * (size - x1) / dx + y1; - assert (res > 0); + KISSAT_assert (res > 0); return res; } @@ -172,14 +174,14 @@ static void init_score_table (walker *walker) { for (next = 1; next; next *= base) exponents++; - walker->table = kissat_malloc (solver, exponents * sizeof (double)); + walker->table = (double*)kissat_malloc (solver, exponents * sizeof (double)); unsigned i = 0; double epsilon; for (epsilon = next = 1; next; next = epsilon * base) walker->table[i++] = epsilon = next; - assert (i == exponents); + KISSAT_assert (i == exponents); walker->exponents = exponents; walker->epsilon = epsilon; @@ -198,22 +200,22 @@ static void import_decision_phases (walker *walker) { INC (walk_decisions); const flags *const flags = solver->flags; value *values = solver->values; - walker->best_values = kissat_calloc (solver, VARS, 1); + walker->best_values = (value*)kissat_calloc (solver, VARS, 1); value *best_values = walker->best_values; -#ifndef QUIET +#ifndef KISSAT_QUIET unsigned imported = 0; #endif for (all_variables (idx)) { if (!flags[idx].active) continue; value value = kissat_decide_phase (solver, idx); - assert (value); + KISSAT_assert (value); best_values[idx] = value; const unsigned lit = LIT (idx); const unsigned not_lit = NOT (lit); values[lit] = value; values[not_lit] = -value; -#ifndef QUIET +#ifndef KISSAT_QUIET imported++; #endif LOG ("copied %s decision phase %d", LOGVAR (idx), (int) value); @@ -230,7 +232,7 @@ static unsigned connect_binary_counters (walker *walker) { watches *all_watches = solver->watches; counter *counters = walker->counters; - assert (SIZE_STACK (*walker->binaries) <= UINT_MAX); + KISSAT_assert (SIZE_STACK (*walker->binaries) <= UINT_MAX); const unsigned size = SIZE_STACK (*walker->binaries); litpair *binaries = BEGIN_STACK (*walker->binaries); unsigned unsat = 0, counter_ref = 0; @@ -239,12 +241,12 @@ static unsigned connect_binary_counters (walker *walker) { const litpair *const litpair = binaries + binary_ref; const unsigned first = litpair->lits[0]; const unsigned second = litpair->lits[1]; - assert (first < LITS), assert (second < LITS); + KISSAT_assert (first < LITS), KISSAT_assert (second < LITS); const value first_value = values[first]; const value second_value = values[second]; if (!first_value || !second_value) continue; - assert (counter_ref < walker->clauses); + KISSAT_assert (counter_ref < walker->clauses); refs[counter_ref] = make_tagged (true, binary_ref); watches *first_watches = all_watches + first; watches *second_watches = all_watches + second; @@ -262,7 +264,7 @@ static unsigned connect_binary_counters (walker *walker) { kissat_phase (solver, "walk", GET (walks), "initially %u unsatisfied binary clauses %.0f%% out of %u", unsat, kissat_percent (unsat, counter_ref), counter_ref); -#ifdef QUIET +#ifdef KISSAT_QUIET (void) unsat; #endif walker->size += 2.0 * counter_ref; @@ -271,7 +273,7 @@ static unsigned connect_binary_counters (walker *walker) { static void connect_large_counters (walker *walker, unsigned counter_ref) { kissat *solver = walker->solver; - assert (!solver->level); + KISSAT_assert (!solver->level); const value *const original_values = walker->original_values; const value *const local_search_values = solver->values; ward *const arena = BEGIN_STACK (solver->arena); @@ -297,23 +299,23 @@ static void connect_large_counters (walker *walker, unsigned counter_ref) { continue; LOGCLS (c, "%s satisfied", LOGLIT (lit)); kissat_mark_clause_as_garbage (solver, c); - assert (c->garbage); + KISSAT_assert (c->garbage); continue_with_next_clause = true; break; } if (continue_with_next_clause) continue; large++; - assert (kissat_clause_in_arena (solver, c)); + KISSAT_assert (kissat_clause_in_arena (solver, c)); reference clause_ref = (ward *) c - arena; - assert (clause_ref <= MAX_WALK_REF); - assert (counter_ref < walker->clauses); + KISSAT_assert (clause_ref <= MAX_WALK_REF); + KISSAT_assert (counter_ref < walker->clauses); refs[counter_ref] = make_tagged (false, clause_ref); unsigned count = 0, size = 0; for (all_literals_in_clause (lit, c)) { const value value = local_search_values[lit]; if (!value) { - assert (original_values[lit] < 0); + KISSAT_assert (original_values[lit] < 0); continue; } watches *watches = &WATCHES (lit); @@ -335,13 +337,13 @@ static void connect_large_counters (walker *walker, unsigned counter_ref) { kissat_phase (solver, "walk", GET (walks), "initially %u unsatisfied large clauses %.0f%% out of %u", unsat, kissat_percent (unsat, large), large); -#ifdef QUIET +#ifdef KISSAT_QUIET (void) large; (void) unsat; #endif } -#ifndef QUIET +#ifndef KISSAT_QUIET static void report_initial_minimum (kissat *solver, walker *walker) { walker->report.minimum = walker->minimum; @@ -351,7 +353,7 @@ static void report_initial_minimum (kissat *solver, walker *walker) { static void report_minimum (const char *type, kissat *solver, walker *walker) { - assert (walker->minimum <= walker->report.minimum); + KISSAT_assert (walker->minimum <= walker->report.minimum); kissat_very_verbose (solver, "%s minimum of %u unsatisfied clauses after %" PRIu64 " flipped literals", @@ -370,24 +372,24 @@ static void report_minimum (const char *type, kissat *solver, static void init_walker (kissat *solver, walker *walker, litpairs *binaries) { uint64_t clauses = BINIRR_CLAUSES; - assert (clauses <= MAX_WALK_REF); + KISSAT_assert (clauses <= MAX_WALK_REF); memset (walker, 0, sizeof *walker); walker->solver = solver; walker->clauses = clauses; walker->binaries = binaries; - walker->random = solver->random ^ solver->statistics.walks; + walker->random = solver->random ^ solver->statistics_.walks; walker->original_values = solver->values; - solver->values = kissat_calloc (solver, LITS, 1); + solver->values = (value*)kissat_calloc (solver, LITS, 1); import_decision_phases (walker); - walker->counters = kissat_malloc (solver, clauses * sizeof (counter)); - walker->refs = kissat_malloc (solver, clauses * sizeof (tagged)); + walker->counters = (counter*)kissat_malloc (solver, clauses * sizeof (counter)); + walker->refs = (tagged*)kissat_malloc (solver, clauses * sizeof (tagged)); - assert (!walker->size); + KISSAT_assert (!walker->size); const unsigned counter_ref = connect_binary_counters (walker); connect_large_counters (walker, counter_ref); @@ -413,8 +415,8 @@ static void init_walker_limit (kissat *solver, walker *walker) { SET_EFFORT_LIMIT (limit, walk, walk_steps); walker->limit = limit; walker->flipped = 0; -#ifndef QUIET - walker->start = solver->statistics.walk_steps; +#ifndef KISSAT_QUIET + walker->start = solver->statistics_.walk_steps; walker->report.minimum = UINT_MAX; walker->report.flipped = 0; #endif @@ -438,21 +440,21 @@ static void release_walker (walker *walker) { static unsigned break_value (kissat *solver, walker *walker, value *values, unsigned lit) { - assert (values[lit] < 0); + KISSAT_assert (values[lit] < 0); const unsigned not_lit = NOT (lit); watches *watches = &WATCHES (not_lit); unsigned steps = 1; unsigned res = 0; for (all_binary_large_watches (watch, *watches)) { steps++; - assert (!watch.type.binary); + KISSAT_assert (!watch.type.binary); reference counter_ref = watch.large.ref; - assert (counter_ref < walker->clauses); + KISSAT_assert (counter_ref < walker->clauses); counter *counter = walker->counters + counter_ref; res += (counter->count == 1); } ADD (walk_steps, steps); -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) values; #endif return res; @@ -466,7 +468,7 @@ static double scale_score (walker *walker, unsigned breaks) { } static unsigned pick_literal (kissat *solver, walker *walker) { - assert (walker->current == SIZE_STACK (walker->unsat)); + KISSAT_assert (walker->current == SIZE_STACK (walker->unsat)); const unsigned pos = walker->flipped++ % walker->current; const unsigned counter_ref = PEEK_STACK (walker->unsat, pos); unsigned size; @@ -474,7 +476,7 @@ static unsigned pick_literal (kissat *solver, walker *walker) { dereference_literals (solver, walker, counter_ref, &size); LOGLITS (size, lits, "picked unsatisfied[%u]", pos); - assert (EMPTY_STACK (walker->scores)); + KISSAT_assert (EMPTY_STACK (walker->scores)); value *values = solver->values; @@ -489,21 +491,21 @@ static unsigned pick_literal (kissat *solver, walker *walker) { picked_lit = lit; const unsigned breaks = break_value (solver, walker, values, lit); const double score = scale_score (walker, breaks); - assert (score > 0); + KISSAT_assert (score > 0); LOG ("literal %s breaks %u score %g", LOGLIT (lit), breaks, score); PUSH_STACK (walker->scores, score); sum += score; } - assert (picked_lit != INVALID_LIT); - assert (0 < sum); + KISSAT_assert (picked_lit != INVALID_LIT); + KISSAT_assert (0 < sum); const double random = kissat_pick_double (&walker->random); - assert (0 <= random), assert (random < 1); + KISSAT_assert (0 <= random), KISSAT_assert (random < 1); const double threshold = sum * random; LOG ("score sum %g and random threshold %g", sum, threshold); - // assert (threshold < sum); // NOT TRUE!!!! + // KISSAT_assert (threshold < sum); // NOT TRUE!!!! double *scores = BEGIN_STACK (walker->scores); #ifdef LOGGING @@ -526,7 +528,7 @@ static unsigned pick_literal (kissat *solver, walker *walker) { break; } } - assert (picked_lit != INVALID_LIT); + KISSAT_assert (picked_lit != INVALID_LIT); LOG ("picked literal %s with score %g", LOGLIT (picked_lit), picked_score); @@ -541,7 +543,7 @@ static void break_clauses (kissat *solver, walker *walker, unsigned broken = 0; #endif const unsigned not_flipped = NOT (flipped); - assert (values[not_flipped] < 0); + KISSAT_assert (values[not_flipped] < 0); LOG ("breaking one-satisfied clauses containing negated flipped literal " "%s", LOGLIT (not_flipped)); @@ -550,11 +552,11 @@ static void break_clauses (kissat *solver, walker *walker, unsigned steps = 1; for (all_binary_large_watches (watch, *watches)) { steps++; - assert (!watch.type.binary); + KISSAT_assert (!watch.type.binary); const unsigned counter_ref = watch.large.ref; - assert (counter_ref < walker->clauses); + KISSAT_assert (counter_ref < walker->clauses); counter *counter = counters + counter_ref; - assert (counter->count); + KISSAT_assert (counter->count); if (--counter->count) continue; push_unsat (solver, walker, counters, counter_ref); @@ -566,14 +568,14 @@ static void break_clauses (kissat *solver, walker *walker, "negated flipped literal %s", broken, LOGLIT (not_flipped)); ADD (walk_steps, steps); -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) values; #endif } static void make_clauses (kissat *solver, walker *walker, const value *const values, unsigned flipped) { - assert (values[flipped] > 0); + KISSAT_assert (values[flipped] > 0); LOG ("making unsatisfied clauses containing flipped literal %s", LOGLIT (flipped)); watches *watches = &WATCHES (flipped); @@ -584,11 +586,11 @@ static void make_clauses (kissat *solver, walker *walker, #endif for (all_binary_large_watches (watch, *watches)) { steps++; - assert (!watch.type.binary); + KISSAT_assert (!watch.type.binary); const unsigned counter_ref = watch.large.ref; - assert (counter_ref < walker->clauses); + KISSAT_assert (counter_ref < walker->clauses); counter *counter = counters + counter_ref; - assert (counter->count < UINT_MAX); + KISSAT_assert (counter->count < UINT_MAX); if (counter->count++) continue; if (pop_unsat (solver, walker, counters, counter_ref, counter->pos)) @@ -600,14 +602,14 @@ static void make_clauses (kissat *solver, walker *walker, LOG ("made %u unsatisfied clauses containing flipped literal %s", made, LOGLIT (flipped)); ADD (walk_steps, steps); -#ifdef NDEBUG +#ifdef KISSAT_NDEBUG (void) values; #endif } static void save_all_values (kissat *solver, walker *walker) { - assert (EMPTY_STACK (walker->trail)); - assert (walker->best_trail_pos == INVALID_BEST_TRAIL_POS); + KISSAT_assert (EMPTY_STACK (walker->trail)); + KISSAT_assert (walker->best_trail_pos == INVALID_BEST_TRAIL_POS); LOG ("copying all values as best phases since trail is invalid"); const value *const current_values = solver->values; value *best_values = walker->best_values; @@ -622,11 +624,11 @@ static void save_all_values (kissat *solver, walker *walker) { } static void save_walker_trail (kissat *solver, walker *walker, bool keep) { -#if defined(LOGGING) || !defined(NDEBUG) - assert (walker->best_trail_pos != INVALID_BEST_TRAIL_POS); - assert (SIZE_STACK (walker->trail) <= UINT_MAX); +#if defined(LOGGING) || !defined(KISSAT_NDEBUG) + KISSAT_assert (walker->best_trail_pos != INVALID_BEST_TRAIL_POS); + KISSAT_assert (SIZE_STACK (walker->trail) <= UINT_MAX); const unsigned size_trail = SIZE_STACK (walker->trail); - assert (walker->best_trail_pos <= size_trail); + KISSAT_assert (walker->best_trail_pos <= size_trail); const unsigned kept = size_trail - walker->best_trail_pos; LOG ("saving %u values of flipped literals on trail of size %u", walker->best_trail_pos, size_trail); @@ -652,8 +654,8 @@ static void save_walker_trail (kissat *solver, walker *walker, bool keep) { unsigned *q = begin; for (const unsigned *p = best; p != end; p++) *q++ = *p; - assert ((size_t) (end - q) == walker->best_trail_pos); - assert ((size_t) (q - begin) == kept); + KISSAT_assert ((size_t) (end - q) == walker->best_trail_pos); + KISSAT_assert ((size_t) (q - begin) == kept); SET_END_OF_STACK (walker->trail, q); LOG ("keeping %u literals %.0f%% on trail", kept, kissat_percent (kept, size_trail)); @@ -666,13 +668,13 @@ static void push_flipped (kissat *solver, walker *walker, if (walker->best_trail_pos == INVALID_BEST_TRAIL_POS) { LOG ("not pushing flipped %s to already invalid trail", LOGLIT (flipped)); - assert (EMPTY_STACK (walker->trail)); + KISSAT_assert (EMPTY_STACK (walker->trail)); } else { - assert (SIZE_STACK (walker->trail) <= UINT_MAX); + KISSAT_assert (SIZE_STACK (walker->trail) <= UINT_MAX); const unsigned size_trail = SIZE_STACK (walker->trail); - assert (walker->best_trail_pos <= size_trail); + KISSAT_assert (walker->best_trail_pos <= size_trail); const unsigned limit = VARS / 4 + 1; - assert (limit < INVALID_BEST_TRAIL_POS); + KISSAT_assert (limit < INVALID_BEST_TRAIL_POS); if (size_trail < limit) { PUSH_STACK (walker->trail, flipped); LOG ("pushed flipped %s to trail which now has size %u", @@ -682,7 +684,7 @@ static void push_flipped (kissat *solver, walker *walker, walker->best_trail_pos); save_walker_trail (solver, walker, true); PUSH_STACK (walker->trail, flipped); - assert (SIZE_STACK (walker->trail) <= UINT_MAX); + KISSAT_assert (SIZE_STACK (walker->trail) <= UINT_MAX); LOG ("pushed flipped %s to trail which now has size %zu", LOGLIT (flipped), SIZE_STACK (walker->trail)); } else { @@ -699,7 +701,7 @@ static void flip_literal (kissat *solver, walker *walker, unsigned flip) { LOG ("flipping literal %s", LOGLIT (flip)); value *values = solver->values; const value value = values[flip]; - assert (value < 0); + KISSAT_assert (value < 0); values[flip] = -value; values[NOT (flip)] = value; make_clauses (solver, walker, values, flip); @@ -708,9 +710,9 @@ static void flip_literal (kissat *solver, walker *walker, unsigned flip) { } static void update_best (kissat *solver, walker *walker) { - assert (walker->current < walker->minimum); + KISSAT_assert (walker->current < walker->minimum); walker->minimum = walker->current; -#ifndef QUIET +#ifndef KISSAT_QUIET int verbosity = kissat_verbosity (solver); bool report = (verbosity > 2); if (verbosity == 2) { @@ -730,16 +732,16 @@ static void update_best (kissat *solver, walker *walker) { if (walker->best_trail_pos == INVALID_BEST_TRAIL_POS) save_all_values (solver, walker); else { - assert (SIZE_STACK (walker->trail) < INVALID_BEST_TRAIL_POS); + KISSAT_assert (SIZE_STACK (walker->trail) < INVALID_BEST_TRAIL_POS); walker->best_trail_pos = SIZE_STACK (walker->trail); LOG ("new best trail position %u", walker->best_trail_pos); } } static void local_search_step (kissat *solver, walker *walker) { - assert (walker->current); + KISSAT_assert (walker->current); INC (flipped); - assert (walker->flipped < UINT64_MAX); + KISSAT_assert (walker->flipped < UINT64_MAX); walker->flipped++; LOG ("starting local search flip %" PRIu64 " with %u unsatisfied clauses", GET (flipped), walker->current); @@ -754,18 +756,18 @@ static void local_search_step (kissat *solver, walker *walker) { static void local_search_round (walker *walker) { kissat *solver = walker->solver; -#ifndef QUIET +#ifndef KISSAT_QUIET const unsigned before = walker->minimum; #endif - statistics *statistics = &solver->statistics; + statistics *statistics = &solver->statistics_; while (walker->minimum && walker->limit > statistics->walk_steps) { if (TERMINATED (walk_terminated_1)) break; local_search_step (solver, walker); } -#ifndef QUIET +#ifndef KISSAT_QUIET report_minimum ("last", solver, walker); - assert (statistics->walk_steps >= walker->start); + KISSAT_assert (statistics->walk_steps >= walker->start); const uint64_t steps = statistics->walk_steps - walker->start; // clang-format off kissat_very_verbose (solver, @@ -785,15 +787,15 @@ static void export_best_values (walker *walker) { kissat *const solver = walker->solver; const value *const best = walker->best_values; value *const saved = solver->phases.saved; - assert (sizeof *saved == 1); - assert (sizeof *best == 1); + KISSAT_assert (sizeof *saved == 1); + KISSAT_assert (sizeof *best == 1); memcpy (saved, best, VARS); } static bool save_final_minimum (walker *walker) { kissat *solver = walker->solver; - assert (walker->minimum <= walker->initial); + KISSAT_assert (walker->minimum <= walker->initial); if (walker->minimum == walker->initial) { kissat_phase (solver, "walk", GET (walks), "no improvement thus keeping saved phases"); @@ -823,14 +825,14 @@ static void check_walk (kissat *solver, unsigned expected) { watches *all_watches = solver->watches; const value *const saved = solver->phases.saved; for (all_literals (lit)) { - assert (lit < LITS); + KISSAT_assert (lit < LITS); watches *watches = all_watches + lit; if (kissat_empty_vector (watches)) continue; value value = solver->values[lit]; if (!value) { value = saved[IDX (lit)]; - assert (value); + KISSAT_assert (value); if (NEGATED (lit)) value = -value; } @@ -844,7 +846,7 @@ static void check_walk (kissat *solver, unsigned expected) { value = solver->values[other]; if (!value) { value = saved[IDX (other)]; - assert (value); + KISSAT_assert (value); if (NEGATED (other)) value = -value; } @@ -864,7 +866,7 @@ static void check_walk (kissat *solver, unsigned expected) { value value = solver->values[lit]; if (!value) { value = saved[IDX (lit)]; - assert (value); + KISSAT_assert (value); if (NEGATED (lit)) value = -value; } @@ -878,7 +880,7 @@ static void check_walk (kissat *solver, unsigned expected) { } LOG ("expected %u unsatisfied", expected); LOG ("actually %u unsatisfied", unsatisfied); - assert (expected == unsatisfied); + KISSAT_assert (expected == unsatisfied); } #endif @@ -934,10 +936,10 @@ bool kissat_walking (kissat *solver) { } void kissat_walk (kissat *solver) { - assert (!solver->level); - assert (!solver->inconsistent); - assert (kissat_propagated (solver)); - assert (kissat_walking (solver)); + KISSAT_assert (!solver->level); + KISSAT_assert (!solver->inconsistent); + KISSAT_assert (kissat_propagated (solver)); + KISSAT_assert (kissat_walking (solver)); reference last_irredundant = solver->last_irredundant; if (last_irredundant == INVALID_REF) @@ -964,3 +966,5 @@ void kissat_walk (kissat *solver) { walking_phase (solver); STOP_SIMPLIFIER_AND_RESUME_SEARCH (walking); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/walk.h b/src/sat/kissat/walk.h index 0acc19193..43e626091 100644 --- a/src/sat/kissat/walk.h +++ b/src/sat/kissat/walk.h @@ -3,9 +3,14 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; bool kissat_walking (struct kissat *); void kissat_walk (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/warmup.c b/src/sat/kissat/warmup.c index d9fa9f534..fe7b981f8 100644 --- a/src/sat/kissat/warmup.c +++ b/src/sat/kissat/warmup.c @@ -6,16 +6,18 @@ #include "propbeyond.h" #include "terminate.h" +ABC_NAMESPACE_IMPL_START + void kissat_warmup (kissat *solver) { - assert (!solver->level); - assert (solver->watching); - assert (!solver->inconsistent); - assert (GET_OPTION (warmup)); + KISSAT_assert (!solver->level); + KISSAT_assert (solver->watching); + KISSAT_assert (!solver->inconsistent); + KISSAT_assert (GET_OPTION (warmup)); START (warmup); - assert (!solver->warming); + KISSAT_assert (!solver->warming); solver->warming = true; INC (warmups); -#ifndef QUIET +#ifndef KISSAT_QUIET const statistics *stats = &solver->statistics; uint64_t propagations = stats->warming_propagations; uint64_t decisions = stats->warming_decisions; @@ -26,8 +28,8 @@ void kissat_warmup (kissat *solver) { kissat_decide (solver); kissat_propagate_beyond_conflicts (solver); } - assert (!solver->inconsistent); -#ifndef QUIET + KISSAT_assert (!solver->inconsistent); +#ifndef KISSAT_QUIET decisions = stats->warming_decisions - decisions; propagations = stats->warming_propagations - propagations; @@ -48,7 +50,9 @@ void kissat_warmup (kissat *solver) { solver->level); #endif kissat_backtrack_without_updating_phases (solver, 0); - assert (solver->warming); + KISSAT_assert (solver->warming); solver->warming = false; STOP (warmup); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/warmup.h b/src/sat/kissat/warmup.h index e0fd47122..23cd6c7a7 100644 --- a/src/sat/kissat/warmup.h +++ b/src/sat/kissat/warmup.h @@ -1,8 +1,13 @@ #ifndef _warmup_h_INCLUDED #define _warmup_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_warmup (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/watch.c b/src/sat/kissat/watch.c index 39ceace6e..78f9a69ce 100644 --- a/src/sat/kissat/watch.c +++ b/src/sat/kissat/watch.c @@ -3,13 +3,15 @@ #include "inline.h" #include "sort.c" +ABC_NAMESPACE_IMPL_START + void kissat_remove_binary_watch (kissat *solver, watches *watches, unsigned lit) { watch *const begin = BEGIN_WATCHES (*watches); watch *const end = END_WATCHES (*watches); watch *q = begin; watch const *p = q; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG bool found = false; #endif while (p != end) { @@ -21,34 +23,34 @@ void kissat_remove_binary_watch (kissat *solver, watches *watches, const unsigned other = watch.binary.lit; if (other != lit) continue; -#ifndef NDEBUG - assert (!found); +#ifndef KISSAT_NDEBUG + KISSAT_assert (!found); found = true; #endif q--; } - assert (found); -#ifdef COMPACT + KISSAT_assert (found); +#ifdef KISSAT_COMPACT watches->size -= 1; #else - assert (begin + 1 <= end); + KISSAT_assert (begin + 1 <= end); watches->end -= 1; #endif const watch empty = {.raw = INVALID_VECTOR_ELEMENT}; end[-1] = empty; - assert (solver->vectors.usable < MAX_SECTOR - 1); + KISSAT_assert (solver->vectors.usable < MAX_SECTOR - 1); solver->vectors.usable += 1; kissat_check_vectors (solver); } void kissat_remove_blocking_watch (kissat *solver, watches *watches, reference ref) { - assert (solver->watching); + KISSAT_assert (solver->watching); watch *const begin = BEGIN_WATCHES (*watches); watch *const end = END_WATCHES (*watches); watch *q = begin; watch const *p = q; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG bool found = false; #endif while (p != end) { @@ -58,49 +60,49 @@ void kissat_remove_blocking_watch (kissat *solver, watches *watches, const watch tail = *q++ = *p++; if (tail.raw != ref) continue; -#ifndef NDEBUG - assert (!found); +#ifndef KISSAT_NDEBUG + KISSAT_assert (!found); found = true; #endif q -= 2; } - assert (found); -#ifdef COMPACT + KISSAT_assert (found); +#ifdef KISSAT_COMPACT watches->size -= 2; #else - assert (begin + 2 <= end); + KISSAT_assert (begin + 2 <= end); watches->end -= 2; #endif const watch empty = {.raw = INVALID_VECTOR_ELEMENT}; end[-2] = end[-1] = empty; - assert (solver->vectors.usable < MAX_SECTOR - 2); + KISSAT_assert (solver->vectors.usable < MAX_SECTOR - 2); solver->vectors.usable += 2; kissat_check_vectors (solver); } void kissat_substitute_large_watch (kissat *solver, watches *watches, watch src, watch dst) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); watch *const begin = BEGIN_WATCHES (*watches); const watch *const end = END_WATCHES (*watches); -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG bool found = false; #endif for (watch *p = begin; p != end; p++) { const watch head = *p; if (head.raw != src.raw) continue; -#ifndef NDEBUG +#ifndef KISSAT_NDEBUG found = true; #endif *p = dst; break; } - assert (found); + KISSAT_assert (found); } void kissat_flush_all_connected (kissat *solver) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); LOG ("flush all connected binaries and clauses"); watches *all_watches = solver->watches; for (all_literals (lit)) @@ -108,7 +110,7 @@ void kissat_flush_all_connected (kissat *solver) { } void kissat_flush_large_watches (kissat *solver) { - assert (solver->watching); + KISSAT_assert (solver->watching); LOG ("flush large clause watches"); watches *all_watches = solver->watches; signed char *marks = solver->marks; @@ -134,7 +136,7 @@ void kissat_flush_large_watches (kissat *solver) { } SET_END_OF_WATCHES (*lit_watches, q); for (p = begin; p != q; p++) { - assert (p->type.binary); + KISSAT_assert (p->type.binary); marks[p->binary.lit] = 0; } } @@ -142,7 +144,7 @@ void kissat_flush_large_watches (kissat *solver) { void kissat_watch_large_clauses (kissat *solver) { LOG ("watching all large clauses"); - assert (solver->watching); + KISSAT_assert (solver->watching); const value *const values = solver->values; const assigned *const assigned = solver->assigned; @@ -167,7 +169,7 @@ void kissat_watch_large_clauses (kissat *solver) { } void kissat_connect_irredundant_large_clauses (kissat *solver) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); LOG ("connecting all large irredundant clauses"); clause *last_irredundant = kissat_last_irredundant_clause (solver); @@ -184,7 +186,7 @@ void kissat_connect_irredundant_large_clauses (kissat *solver) { if (c->garbage) continue; bool satisfied = false; - assert (!solver->level); + KISSAT_assert (!solver->level); for (all_literals_in_clause (lit, c)) { const value value = values[lit]; if (value <= 0) @@ -202,7 +204,7 @@ void kissat_connect_irredundant_large_clauses (kissat *solver) { } void kissat_flush_large_connected (kissat *solver) { - assert (!solver->watching); + KISSAT_assert (!solver->watching); LOG ("flushing large connected clause references"); size_t flushed = 0; for (all_literals (lit)) { @@ -221,3 +223,5 @@ void kissat_flush_large_connected (kissat *solver) { LOG ("flushed %zu large clause references", flushed); (void) flushed; } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/watch.h b/src/sat/kissat/watch.h index 50afdb083..901e489b7 100644 --- a/src/sat/kissat/watch.h +++ b/src/sat/kissat/watch.h @@ -8,6 +8,9 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + typedef union watch watch; typedef struct binary_tagged_literal watch_type; @@ -77,7 +80,7 @@ static inline watch kissat_binary_watch (unsigned lit) { watch res; res.binary.lit = lit; res.binary.binary = true; - assert (res.type.binary); + KISSAT_assert (res.type.binary); return res; } @@ -85,7 +88,7 @@ static inline watch kissat_large_watch (reference ref) { watch res; res.large.ref = ref; res.large.binary = false; - assert (!res.type.binary); + KISSAT_assert (!res.type.binary); return res; } @@ -93,7 +96,7 @@ static inline watch kissat_blocking_watch (unsigned lit) { watch res; res.blocking.lit = lit; res.blocking.binary = false; - assert (!res.type.binary); + KISSAT_assert (!res.type.binary); return res; } @@ -102,7 +105,7 @@ static inline watch kissat_blocking_watch (unsigned lit) { #define PUSH_WATCHES(W, E) \ do { \ - assert (sizeof (E) == sizeof (unsigned)); \ + KISSAT_assert (sizeof (E) == sizeof (unsigned)); \ kissat_push_vectors (solver, &(W), (E).raw); \ } while (0) @@ -131,13 +134,13 @@ static inline watch kissat_blocking_watch (unsigned lit) { #define REMOVE_WATCHES(W, E) \ kissat_remove_from_vector (solver, &(W), (E).raw) -#define WATCHES(LIT) (solver->watches[assert ((LIT) < LITS), (LIT)]) +#define WATCHES(LIT) (solver->watches[KISSAT_assert ((LIT) < LITS), (LIT)]) // This iterator is currently only used in 'testreferences.c'. // #define all_binary_blocking_watch_ref(WATCH, REF, WATCHES) \ watch WATCH, \ - *WATCH##_PTR = (assert (solver->watching), BEGIN_WATCHES (WATCHES)), \ + *WATCH##_PTR = (KISSAT_assert (solver->watching), BEGIN_WATCHES (WATCHES)), \ *const WATCH##_END = END_WATCHES (WATCHES); \ WATCH##_PTR != WATCH##_END && \ ((WATCH = *WATCH##_PTR), \ @@ -147,7 +150,7 @@ static inline watch kissat_blocking_watch (unsigned lit) { #define all_binary_blocking_watches(WATCH, WATCHES) \ watch WATCH, \ - *WATCH##_PTR = (assert (solver->watching), BEGIN_WATCHES (WATCHES)), \ + *WATCH##_PTR = (KISSAT_assert (solver->watching), BEGIN_WATCHES (WATCHES)), \ *const WATCH##_END = END_WATCHES (WATCHES); \ WATCH##_PTR != WATCH##_END && ((WATCH = *WATCH##_PTR), true); \ WATCH##_PTR += 1u + !WATCH.type.binary @@ -155,7 +158,7 @@ static inline watch kissat_blocking_watch (unsigned lit) { #define all_binary_large_watches(WATCH, WATCHES) \ watch WATCH, \ *WATCH##_PTR = \ - (assert (!solver->watching), BEGIN_WATCHES (WATCHES)), \ + (KISSAT_assert (!solver->watching), BEGIN_WATCHES (WATCHES)), \ *const WATCH##_END = END_WATCHES (WATCHES); \ WATCH##_PTR != WATCH##_END && ((WATCH = *WATCH##_PTR), true); \ ++WATCH##_PTR @@ -173,4 +176,6 @@ void kissat_flush_large_connected (struct kissat *); void kissat_connect_irredundant_large_clauses (struct kissat *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/weaken.c b/src/sat/kissat/weaken.c index 149616546..5bd06371c 100644 --- a/src/sat/kissat/weaken.c +++ b/src/sat/kissat/weaken.c @@ -1,10 +1,12 @@ #include "weaken.h" #include "inline.h" +ABC_NAMESPACE_IMPL_START + static void push_witness_literal (kissat *solver, unsigned ilit) { - assert (!VALUE (ilit)); + KISSAT_assert (!VALUE (ilit)); int elit = kissat_export_literal (solver, ilit); - assert (elit); + KISSAT_assert (elit); LOG2 ("pushing external witness literal %d on extension stack", elit); const extension ext = kissat_extension (true, elit); PUSH_STACK (solver->extend, ext); @@ -12,14 +14,14 @@ static void push_witness_literal (kissat *solver, unsigned ilit) { static void push_clause_literal (kissat *solver, unsigned ilit) { const value value = VALUE (ilit); - assert (value <= 0); + KISSAT_assert (value <= 0); if (value < 0) LOG ("not pushing internal falsified clause literal %s " "on extension stack", LOGLIT (ilit)); else { int elit = kissat_export_literal (solver, ilit); - assert (elit); + KISSAT_assert (elit); LOG2 ("pushing external clause literal %d on extension stack", elit); const extension ext = kissat_extension (false, elit); PUSH_STACK (solver->extend, ext); @@ -58,3 +60,5 @@ void kissat_weaken_unit (kissat *solver, unsigned lit) { LOGEXT (1, END_STACK (solver->extend) - 1, "pushed witness labelled unit clause at"); } + +ABC_NAMESPACE_IMPL_END diff --git a/src/sat/kissat/weaken.h b/src/sat/kissat/weaken.h index beabcb0ce..8cd3dbbd8 100644 --- a/src/sat/kissat/weaken.h +++ b/src/sat/kissat/weaken.h @@ -1,6 +1,9 @@ #ifndef _weaken_h_INCLUDED #define _weaken_h_INCLUDED +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct clause; struct kissat; @@ -8,4 +11,6 @@ void kissat_weaken_unit (struct kissat *, unsigned lit); void kissat_weaken_binary (struct kissat *, unsigned lit, unsigned other); void kissat_weaken_clause (struct kissat *, unsigned lit, struct clause *); +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/sat/kissat/witness.h b/src/sat/kissat/witness.h index 2b0fdea63..dffeaaabe 100644 --- a/src/sat/kissat/witness.h +++ b/src/sat/kissat/witness.h @@ -3,8 +3,13 @@ #include +#include "global.h" +ABC_NAMESPACE_HEADER_START + struct kissat; void kissat_print_witness (struct kissat *, int max_var, bool partial); +ABC_NAMESPACE_HEADER_END + #endif