-
Notifications
You must be signed in to change notification settings - Fork 36
/
picosat.c
8502 lines (7091 loc) · 170 KB
/
picosat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
Copyright (c) 2006 - 2015, Armin Biere, Johannes Kepler University.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdint.h>
#include "picosat.h"
/* By default code for 'all different constraints' is disabled, since 'NADC'
* is defined.
*/
#define NADC
/* By default we enable failed literals, since 'NFL' is undefined.
*
#define NFL
*/
/* By default we 'detach satisfied (large) clauses', e.g. NDSC undefined.
*
#define NDSC
*/
/* Do not use luby restart schedule instead of inner/outer.
*
#define NLUBY
*/
/* Enabling this define, will use gnuplot to visualize how the scores evolve.
*
#define VISCORES
*/
#ifdef VISCORES
// #define WRITEGIF /* ... to generate a video */
#endif
#ifdef VISCORES
#ifndef WRITEGIF
#include <unistd.h> /* for 'usleep' */
#endif
#endif
#ifdef RCODE
#include <R.h>
#endif
#define MINRESTART 100 /* minimum restart interval */
#define MAXRESTART 1000000 /* maximum restart interval */
#define RDECIDE 1000 /* interval of random decisions */
#define FRESTART 110 /* restart increase factor in percent */
#define FREDUCE 110 /* reduce increase factor in percent */
#define FREDADJ 121 /* reduce increase adjustment factor */
#define MAXCILS 10 /* maximal number of unrecycled internals */
#define FFLIPPED 10000 /* flipped reduce factor */
#define FFLIPPEDPREC 10000000/* flipped reduce factor precision */
#define INTERRUPTLIM 1024 /* check interrupt after that many decisions */
#ifndef TRACE
#define NO_BINARY_CLAUSES /* store binary clauses more compactly */
#endif
/* For debugging purposes you may want to define 'LOGGING', which actually
* can be enforced by using './configure.sh --log'.
*/
#ifdef LOGGING
#define LOG(code) do { code; } while (0)
#else
#define LOG(code) do { } while (0)
#endif
#define NOLOG(code) do { } while (0) /* log exception */
#define ONLYLOG(code) do { code; } while (0) /* force logging */
#define FALSE ((Val)-1)
#define UNDEF ((Val)0)
#define TRUE ((Val)1)
#define COMPACT_TRACECHECK_TRACE_FMT 0
#define EXTENDED_TRACECHECK_TRACE_FMT 1
#define RUP_TRACE_FMT 2
#define NEWN(p,n) do { (p) = new (ps, sizeof (*(p)) * (n)); } while (0)
#define CLRN(p,n) do { memset ((p), 0, sizeof (*(p)) * (n)); } while (0)
#define CLR(p) CLRN(p,1)
#define DELETEN(p,n) \
do { delete (ps, p, sizeof (*(p)) * (n)); (p) = 0; } while (0)
#define RESIZEN(p,old_num,new_num) \
do { \
size_t old_size = sizeof (*(p)) * (old_num); \
size_t new_size = sizeof (*(p)) * (new_num); \
(p) = resize (ps, (p), old_size, new_size) ; \
} while (0)
#define ENLARGE(start,head,end) \
do { \
unsigned old_num = (ptrdiff_t)((end) - (start)); \
size_t new_num = old_num ? (2 * old_num) : 1; \
unsigned count = (head) - (start); \
assert ((start) <= (end)); \
RESIZEN((start),old_num,new_num); \
(head) = (start) + count; \
(end) = (start) + new_num; \
} while (0)
#define NOTLIT(l) (ps->lits + (1 ^ ((l) - ps->lits)))
#define LIT2IDX(l) ((ptrdiff_t)((l) - ps->lits) / 2)
#define LIT2IMPLS(l) (ps->impls + (ptrdiff_t)((l) - ps->lits))
#define LIT2INT(l) ((int)(LIT2SGN(l) * LIT2IDX(l)))
#define LIT2SGN(l) (((ptrdiff_t)((l) - ps->lits) & 1) ? -1 : 1)
#define LIT2VAR(l) (ps->vars + LIT2IDX(l))
#define LIT2HTPS(l) (ps->htps + (ptrdiff_t)((l) - ps->lits))
#define LIT2JWH(l) (ps->jwh + ((l) - ps->lits))
#ifndef NDSC
#define LIT2DHTPS(l) (ps->dhtps + (ptrdiff_t)((l) - ps->lits))
#endif
#ifdef NO_BINARY_CLAUSES
typedef uintptr_t Wrd;
#define ISLITREASON(C) (1&(Wrd)C)
#define LIT2REASON(L) \
(assert (L->val==TRUE), ((Cls*)(1 + (2*(L - ps->lits)))))
#define REASON2LIT(C) ((Lit*)(ps->lits + ((Wrd)C)/2))
#endif
#define ENDOFCLS(c) ((void*)((Lit**)(c)->lits + (c)->size))
#define SOC ((ps->oclauses == ps->ohead) ? ps->lclauses : ps->oclauses)
#define EOC (ps->lhead)
#define NXC(p) (((p) + 1 == ps->ohead) ? ps->lclauses : (p) + 1)
#define OIDX2IDX(idx) (2 * ((idx) + 1))
#define LIDX2IDX(idx) (2 * (idx) + 1)
#define ISLIDX(idx) ((idx)&1)
#define IDX2OIDX(idx) (assert(!ISLIDX(idx)), (idx)/2 - 1)
#define IDX2LIDX(idx) (assert(ISLIDX(idx)), (idx)/2)
#define EXPORTIDX(idx) \
((ISLIDX(idx) ? (IDX2LIDX (idx) + (ps->ohead - ps->oclauses)) : IDX2OIDX(idx)) + 1)
#define IDX2CLS(i) \
(assert(i), (ISLIDX(i) ? ps->lclauses : ps->oclauses)[(i)/2 - !ISLIDX(i)])
#define IDX2ZHN(i) (assert(i), (ISLIDX(i) ? ps->zhains[(i)/2] : 0))
#define CLS2TRD(c) (((Trd*)(c)) - 1)
#define CLS2IDX(c) ((((Trd*)(c)) - 1)->idx)
#define CLS2ACT(c) \
((Act*)((assert((c)->learned)),assert((c)->size>2),ENDOFCLS(c)))
#define VAR2LIT(v) (ps->lits + 2 * ((v) - ps->vars))
#define VAR2RNK(v) (ps->rnks + ((v) - ps->vars))
#define RNK2LIT(r) (ps->lits + 2 * ((r) - ps->rnks))
#define RNK2VAR(r) (ps->vars + ((r) - ps->rnks))
#define BLK_FILL_BYTES 8
#define SIZE_OF_BLK (sizeof (Blk) - BLK_FILL_BYTES)
#define PTR2BLK(void_ptr) \
((void_ptr) ? (Blk*)(((char*)(void_ptr)) - SIZE_OF_BLK) : 0)
#define AVERAGE(a,b) ((b) ? (((double)a) / (double)(b)) : 0.0)
#define PERCENT(a,b) (100.0 * AVERAGE(a,b))
#ifndef RCODE
#define ABORT(msg) \
do { \
fputs ("*** picosat: " msg "\n", stderr); \
abort (); \
} while (0)
#else
#define ABORT(msg) \
do { \
Rf_error (msg); \
} while (0)
#endif
#define ABORTIF(cond,msg) \
do { \
if (!(cond)) break; \
ABORT (msg); \
} while (0)
#define ZEROFLT (0x00000000u)
#define EPSFLT (0x00000001u)
#define INFFLT (0xffffffffu)
#define FLTCARRY (1u << 25)
#define FLTMSB (1u << 24)
#define FLTMAXMANTISSA (FLTMSB - 1)
#define FLTMANTISSA(d) ((d) & FLTMAXMANTISSA)
#define FLTEXPONENT(d) ((int)((d) >> 24) - 128)
#define FLTMINEXPONENT (-128)
#define FLTMAXEXPONENT (127)
#define CMPSWAPFLT(a,b) \
do { \
Flt tmp; \
if (((a) < (b))) \
{ \
tmp = (a); \
(a) = (b); \
(b) = tmp; \
} \
} while (0)
#define UNPACKFLT(u,m,e) \
do { \
(m) = FLTMANTISSA(u); \
(e) = FLTEXPONENT(u); \
(m) |= FLTMSB; \
} while (0)
#define INSERTION_SORT_LIMIT 10
#define SORTING_SWAP(T,p,q) \
do { \
T tmp = *(q); \
*(q) = *(p); \
*(p) = tmp; \
} while (0)
#define SORTING_CMP_SWAP(T,cmp,p,q) \
do { \
if ((cmp) (ps, *(p), *(q)) > 0) \
SORTING_SWAP (T, p, q); \
} while(0)
#define QUICKSORT_PARTITION(T,cmp,a,l,r) \
do { \
T pivot; \
int j; \
i = (l) - 1; /* result in 'i' */ \
j = (r); \
pivot = (a)[j]; \
for (;;) \
{ \
while ((cmp) (ps, (a)[++i], pivot) < 0) \
; \
while ((cmp) (ps, pivot, (a)[--j]) < 0) \
if (j == (l)) \
break; \
if (i >= j) \
break; \
SORTING_SWAP (T, (a) + i, (a) + j); \
} \
SORTING_SWAP (T, (a) + i, (a) + (r)); \
} while(0)
#define QUICKSORT(T,cmp,a,n) \
do { \
int l = 0, r = (n) - 1, m, ll, rr, i; \
assert (ps->ihead == ps->indices); \
if (r - l <= INSERTION_SORT_LIMIT) \
break; \
for (;;) \
{ \
m = (l + r) / 2; \
SORTING_SWAP (T, (a) + m, (a) + r - 1); \
SORTING_CMP_SWAP (T, cmp, (a) + l, (a) + r - 1); \
SORTING_CMP_SWAP (T, cmp, (a) + l, (a) + r); \
SORTING_CMP_SWAP (T, cmp, (a) + r - 1, (a) + r); \
QUICKSORT_PARTITION (T, cmp, (a), l + 1, r - 1); \
if (i - l < r - i) \
{ \
ll = i + 1; \
rr = r; \
r = i - 1; \
} \
else \
{ \
ll = l; \
rr = i - 1; \
l = i + 1; \
} \
if (r - l > INSERTION_SORT_LIMIT) \
{ \
assert (rr - ll > INSERTION_SORT_LIMIT); \
if (ps->ihead == ps->eoi) \
ENLARGE (ps->indices, ps->ihead, ps->eoi); \
*ps->ihead++ = ll; \
if (ps->ihead == ps->eoi) \
ENLARGE (ps->indices, ps->ihead, ps->eoi); \
*ps->ihead++ = rr; \
} \
else if (rr - ll > INSERTION_SORT_LIMIT) \
{ \
l = ll; \
r = rr; \
} \
else if (ps->ihead > ps->indices) \
{ \
r = *--ps->ihead; \
l = *--ps->ihead; \
} \
else \
break; \
} \
} while (0)
#define INSERTION_SORT(T,cmp,a,n) \
do { \
T pivot; \
int l = 0, r = (n) - 1, i, j; \
for (i = r; i > l; i--) \
SORTING_CMP_SWAP (T, cmp, (a) + i - 1, (a) + i); \
for (i = l + 2; i <= r; i++) \
{ \
j = i; \
pivot = (a)[i]; \
while ((cmp) (ps, pivot, (a)[j - 1]) < 0) \
{ \
(a)[j] = (a)[j - 1]; \
j--; \
} \
(a)[j] = pivot; \
} \
} while (0)
#ifdef NDEBUG
#define CHECK_SORTED(cmp,a,n) do { } while(0)
#else
#define CHECK_SORTED(cmp,a,n) \
do { \
int i; \
for (i = 0; i < (n) - 1; i++) \
assert ((cmp) (ps, (a)[i], (a)[i + 1]) <= 0); \
} while(0)
#endif
#define SORT(T,cmp,a,n) \
do { \
T * aa = (a); \
int nn = (n); \
QUICKSORT (T, cmp, aa, nn); \
INSERTION_SORT (T, cmp, aa, nn); \
assert (ps->ihead == ps->indices); \
CHECK_SORTED (cmp, aa, nn); \
} while (0)
#define WRDSZ (sizeof (long) * 8)
#ifdef RCODE
#define fprintf(...) do { } while (0)
#define vfprintf(...) do { } while (0)
#define fputs(...) do { } while (0)
#define fputc(...) do { } while (0)
#endif
typedef unsigned Flt; /* 32 bit deterministic soft float */
typedef Flt Act; /* clause and variable activity */
typedef struct Blk Blk; /* allocated memory block */
typedef struct Cls Cls; /* clause */
typedef struct Lit Lit; /* literal */
typedef struct Rnk Rnk; /* variable to score mapping */
typedef signed char Val; /* TRUE, UNDEF, FALSE */
typedef struct Var Var; /* variable */
#ifdef TRACE
typedef struct Trd Trd; /* trace data for clauses */
typedef struct Zhn Zhn; /* compressed chain (=zain) data */
typedef unsigned char Znt; /* compressed antecedent data */
#endif
#ifdef NO_BINARY_CLAUSES
typedef struct Ltk Ltk;
struct Ltk
{
Lit ** start;
unsigned count : WRDSZ == 32 ? 27 : 32;
unsigned ldsize : WRDSZ == 32 ? 5 : 32;
};
#endif
struct Lit
{
Val val;
};
struct Var
{
unsigned mark : 1; /*bit 1*/
unsigned resolved : 1; /*bit 2*/
unsigned phase : 1; /*bit 3*/
unsigned assigned : 1; /*bit 4*/
unsigned used : 1; /*bit 5*/
unsigned failed : 1; /*bit 6*/
unsigned internal : 1; /*bit 7*/
unsigned usedefphase : 1; /*bit 8*/
unsigned defphase : 1; /*bit 9*/
unsigned msspos : 1; /*bit 10*/
unsigned mssneg : 1; /*bit 11*/
unsigned humuspos : 1; /*bit 12*/
unsigned humusneg : 1; /*bit 13*/
unsigned partial : 1; /*bit 14*/
#ifdef TRACE
unsigned core : 1; /*bit 15*/
#endif
unsigned level;
Cls *reason;
#ifndef NADC
Lit ** inado;
Lit ** ado;
Lit *** adotabpos;
#endif
};
struct Rnk
{
Act score;
unsigned pos : 30; /* 0 iff not on heap */
unsigned moreimportant : 1;
unsigned lessimportant : 1;
};
struct Cls
{
unsigned size;
unsigned collect:1; /* bit 1 */
unsigned learned:1; /* bit 2 */
unsigned locked:1; /* bit 3 */
unsigned used:1; /* bit 4 */
#ifndef NDEBUG
unsigned connected:1; /* bit 5 */
#endif
#ifdef TRACE
unsigned collected:1; /* bit 6 */
unsigned core:1; /* bit 7 */
#endif
#define LDMAXGLUE 25 /* 32 - 7 */
#define MAXGLUE ((1<<LDMAXGLUE)-1)
unsigned glue:LDMAXGLUE;
Cls *next[2];
Lit *lits[2];
};
#ifdef TRACE
struct Zhn
{
unsigned ref:31;
unsigned core:1;
Znt * liz;
Znt znt[0];
};
struct Trd
{
unsigned idx;
Cls cls[0];
};
#endif
struct Blk
{
#ifndef NDEBUG
union
{
size_t size; /* this is what we really use */
void *as_two_ptrs[2]; /* 2 * sizeof (void*) alignment of data */
}
header;
#endif
char data[BLK_FILL_BYTES];
};
enum State
{
RESET = 0,
READY = 1,
SAT = 2,
UNSAT = 3,
UNKNOWN = 4,
};
enum Phase
{
POSPHASE,
NEGPHASE,
JWLPHASE,
RNDPHASE,
};
struct PicoSAT
{
enum State state;
enum Phase defaultphase;
int last_sat_call_result;
FILE *out;
char * prefix;
int verbosity;
int plain;
unsigned LEVEL;
unsigned max_var;
unsigned size_vars;
Lit *lits;
Var *vars;
Rnk *rnks;
Flt *jwh;
Cls **htps;
#ifndef NDSC
Cls **dhtps;
#endif
#ifdef NO_BINARY_CLAUSES
Ltk *impls;
Cls impl, cimpl;
int implvalid, cimplvalid;
#else
Cls **impls;
#endif
Lit **trail, **thead, **eot, **ttail, ** ttail2;
#ifndef NADC
Lit **ttailado;
#endif
unsigned adecidelevel;
Lit **als, **alshead, **alstail, **eoals;
Lit **CLS, **clshead, **eocls;
int *rils, *rilshead, *eorils;
int *cils, *cilshead, *eocils;
int *fals, *falshead, *eofals;
int *mass, szmass;
int *mssass, szmssass;
int *mcsass, nmcsass, szmcsass;
int *humus, szhumus;
Lit *failed_assumption;
int extracted_all_failed_assumptions;
Rnk **heap, **hhead, **eoh;
Cls **oclauses, **ohead, **eoo; /* original clauses */
Cls **lclauses, **lhead, ** EOL; /* learned clauses */
int * soclauses, * sohead, * eoso; /* saved original clauses */
int saveorig;
int partial;
#ifdef TRACE
int trace;
Zhn **zhains, **zhead, **eoz;
int ocore;
#endif
FILE * rup;
int rupstarted;
int rupvariables;
int rupclauses;
Cls *mtcls;
Cls *conflict;
Lit **added, **ahead, **eoa;
Var **marked, **mhead, **eom;
Var **dfs, **dhead, **eod;
Cls **resolved, **rhead, **eor;
unsigned char *levels, *levelshead, *eolevels;
unsigned *dused, *dusedhead, *eodused;
unsigned char *buffer, *bhead, *eob;
Act vinc, lscore, ilvinc, ifvinc;
#ifdef VISCORES
Act fvinc, nvinc;
#endif
Act cinc, lcinc, ilcinc, fcinc;
unsigned srng;
size_t current_bytes;
size_t max_bytes;
size_t recycled;
double seconds, flseconds;
double entered;
unsigned nentered;
int measurealltimeinlib;
char *rline[2];
int szrline, RCOUNT;
double levelsum;
unsigned iterations;
int reports;
int lastrheader;
unsigned calls;
unsigned decisions;
unsigned restarts;
unsigned simps;
unsigned fsimplify;
unsigned isimplify;
unsigned reductions;
unsigned lreduce;
unsigned lreduceadjustcnt;
unsigned lreduceadjustinc;
unsigned lastreduceconflicts;
unsigned llocked; /* locked large learned clauses */
unsigned lrestart;
#ifdef NLUBY
unsigned drestart;
unsigned ddrestart;
#else
unsigned lubycnt;
unsigned lubymaxdelta;
int waslubymaxdelta;
#endif
unsigned long long lsimplify;
unsigned long long propagations;
unsigned long long lpropagations;
unsigned fixed; /* top level assignments */
#ifndef NFL
unsigned failedlits;
unsigned ifailedlits;
unsigned efailedlits;
unsigned flcalls;
#ifdef STATS
unsigned flrounds;
unsigned long long flprops;
unsigned long long floopsed, fltried, flskipped;
#endif
unsigned long long fllimit;
int simplifying;
Lit ** saved;
unsigned saved_size;
#endif
unsigned conflicts;
unsigned contexts;
unsigned internals;
unsigned noclauses; /* current number large original clauses */
unsigned nlclauses; /* current number large learned clauses */
unsigned olits; /* current literals in large original clauses */
unsigned llits; /* current literals in large learned clauses */
unsigned oadded; /* added original clauses */
unsigned ladded; /* added learned clauses */
unsigned loadded; /* added original large clauses */
unsigned lladded; /* added learned large clauses */
unsigned addedclauses; /* oadded + ladded */
unsigned vused; /* used variables */
unsigned llitsadded; /* added learned literals */
unsigned long long visits;
#ifdef STATS
unsigned loused; /* used large original clauses */
unsigned llused; /* used large learned clauses */
unsigned long long bvisits;
unsigned long long tvisits;
unsigned long long lvisits;
unsigned long long othertrue;
unsigned long long othertrue2;
unsigned long long othertruel;
unsigned long long othertrue2u;
unsigned long long othertruelu;
unsigned long long ltraversals;
unsigned long long traversals;
#ifdef TRACE
unsigned long long antecedents;
#endif
unsigned uips;
unsigned znts;
unsigned assumptions;
unsigned rdecisions;
unsigned sdecisions;
size_t srecycled;
size_t rrecycled;
unsigned long long derefs;
#endif
unsigned minimizedllits;
unsigned nonminimizedllits;
#ifndef NADC
Lit *** ados, *** hados, *** eados;
Lit *** adotab;
unsigned nadotab;
unsigned szadotab;
Cls * adoconflict;
unsigned adoconflicts;
unsigned adoconflictlimit;
int addingtoado;
int adodisabled;
#endif
unsigned long long flips;
#ifdef STATS
unsigned long long FORCED;
unsigned long long assignments;
unsigned inclreduces;
unsigned staticphasedecisions;
unsigned skippedrestarts;
#endif
int * indices, * ihead, *eoi;
unsigned sdflips;
unsigned long long saved_flips;
unsigned saved_max_var;
unsigned min_flipped;
void * emgr;
picosat_malloc enew;
picosat_realloc eresize;
picosat_free edelete;
struct {
void * state;
int (*function) (void *);
} interrupt;
#ifdef VISCORES
FILE * fviscores;
#endif
};
typedef PicoSAT PS;
static Flt
packflt (unsigned m, int e)
{
Flt res;
assert (m < FLTMSB);
assert (FLTMINEXPONENT <= e);
assert (e <= FLTMAXEXPONENT);
res = m | ((unsigned)(e + 128) << 24);
return res;
}
static Flt
base2flt (unsigned m, int e)
{
if (!m)
return ZEROFLT;
if (m < FLTMSB)
{
do
{
if (e <= FLTMINEXPONENT)
return EPSFLT;
e--;
m <<= 1;
}
while (m < FLTMSB);
}
else
{
while (m >= FLTCARRY)
{
if (e >= FLTMAXEXPONENT)
return INFFLT;
e++;
m >>= 1;
}
}
m &= ~FLTMSB;
return packflt (m, e);
}
static Flt
addflt (Flt a, Flt b)
{
unsigned ma, mb, delta;
int ea, eb;
CMPSWAPFLT (a, b);
if (!b)
return a;
UNPACKFLT (a, ma, ea);
UNPACKFLT (b, mb, eb);
assert (ea >= eb);
delta = ea - eb;
if (delta < 32) mb >>= delta; else mb = 0;
if (!mb)
return a;
ma += mb;
if (ma & FLTCARRY)
{
if (ea == FLTMAXEXPONENT)
return INFFLT;
ea++;
ma >>= 1;
}
assert (ma < FLTCARRY);
ma &= FLTMAXMANTISSA;
return packflt (ma, ea);
}
static Flt
mulflt (Flt a, Flt b)
{
unsigned ma, mb;
unsigned long long accu;
int ea, eb;
CMPSWAPFLT (a, b);
if (!b)
return ZEROFLT;
UNPACKFLT (a, ma, ea);
UNPACKFLT (b, mb, eb);
ea += eb;
ea += 24;
if (ea > FLTMAXEXPONENT)
return INFFLT;
if (ea < FLTMINEXPONENT)
return EPSFLT;
accu = ma;
accu *= mb;
accu >>= 24;
if (accu >= FLTCARRY)
{
if (ea == FLTMAXEXPONENT)
return INFFLT;
ea++;
accu >>= 1;
if (accu >= FLTCARRY)
return INFFLT;
}
assert (accu < FLTCARRY);
assert (accu & FLTMSB);
ma = accu;
ma &= ~FLTMSB;
return packflt (ma, ea);
}
static Flt
ascii2flt (const char *str)
{
Flt ten = base2flt (10, 0);
Flt onetenth = base2flt (26843546, -28);
Flt res = ZEROFLT, tmp, base;
const char *p = str;
int ch;
ch = *p++;
if (ch != '.')
{
if (!isdigit (ch))
return INFFLT; /* better abort ? */
res = base2flt (ch - '0', 0);
while ((ch = *p++))
{
if (ch == '.')
break;
if (!isdigit (ch))
return INFFLT; /* better abort? */
res = mulflt (res, ten);
tmp = base2flt (ch - '0', 0);
res = addflt (res, tmp);
}
}
if (ch == '.')
{
ch = *p++;
if (!isdigit (ch))
return INFFLT; /* better abort ? */
base = onetenth;
tmp = mulflt (base2flt (ch - '0', 0), base);
res = addflt (res, tmp);
while ((ch = *p++))
{
if (!isdigit (ch))
return INFFLT; /* better abort? */
base = mulflt (base, onetenth);
tmp = mulflt (base2flt (ch - '0', 0), base);
res = addflt (res, tmp);
}
}
return res;
}
#if defined(VISCORES)
static double
flt2double (Flt f)
{
double res;
unsigned m;
int e, i;
UNPACKFLT (f, m, e);
res = m;
if (e < 0)
{
for (i = e; i < 0; i++)
res *= 0.5;
}
else
{
for (i = 0; i < e; i++)
res *= 2.0;
}
return res;
}
#endif
static int
log2flt (Flt a)
{
return FLTEXPONENT (a) + 24;
}
static int
cmpflt (Flt a, Flt b)
{
if (a < b)
return -1;
if (a > b)
return 1;
return 0;
}
static void *
new (PS * ps, size_t size)
{
size_t bytes;
Blk *b;
if (!size)
return 0;
bytes = size + SIZE_OF_BLK;
if (ps->enew)
b = ps->enew (ps->emgr, bytes);
else
b = malloc (bytes);
ABORTIF (!b, "out of memory in 'new'");
#ifndef NDEBUG
b->header.size = size;
#endif
ps->current_bytes += size;
if (ps->current_bytes > ps->max_bytes)
ps->max_bytes = ps->current_bytes;
return b->data;
}
static void
delete (PS * ps, void *void_ptr, size_t size)
{
size_t bytes;
Blk *b;
if (!void_ptr)
{
assert (!size);
return;
}
assert (size);