-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclause.c
97 lines (82 loc) · 2.7 KB
/
clause.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
#include "clause.h"
#include "logging.h"
#include "ring.h"
#include "tagging.h"
#include "trace.h"
#include "utilities.h"
#include <string.h>
struct clause *new_large_clause (size_t size, unsigned *literals,
bool redundant, unsigned glue) {
assert (2 <= size);
size_t bytes = size * sizeof (unsigned);
struct clause *clause = allocate_block (sizeof *clause + bytes);
#ifdef LOGGING
clause->id = atomic_fetch_add (&clause_ids, 1);
#endif
clause->shared = 0;
clause->origin = -1;
if (glue > MAX_GLUE)
glue = MAX_GLUE;
clause->glue = glue;
clause->cleaned = false;
clause->dirty = false;
clause->garbage = false;
clause->mapped = false;
clause->padding = 0;
clause->redundant = redundant;
clause->subsume = false;
clause->vivified = false;
clause->size = size;
memcpy (clause->literals, literals, bytes);
return clause;
}
void mark_clause (signed char *marks, struct clause *clause,
unsigned except) {
if (is_binary_pointer (clause))
mark_literal (marks, other_pointer (clause));
else
for (all_literals_in_clause (other, clause))
if (other != except)
mark_literal (marks, other);
}
void unmark_clause (signed char *marks, struct clause *clause,
unsigned except) {
if (is_binary_pointer (clause))
unmark_literal (marks, other_pointer (clause));
else
for (all_literals_in_clause (other, clause))
if (other != except)
unmark_literal (marks, other);
}
void trace_add_clause (struct trace *trace, struct clause *clause) {
assert (!is_binary_pointer (clause));
trace_add_literals (trace, clause->size, clause->literals, INVALID);
}
void trace_delete_clause (struct trace *trace, struct clause *clause) {
if (!clause->garbage)
trace_delete_literals (trace, clause->size, clause->literals);
}
static void delete_clause (struct ring *ring, struct clause *clause) {
assert (!is_binary_pointer (clause));
LOGCLAUSE (clause, "delete");
trace_delete_clause (&ring->trace, clause);
free (clause);
}
void reference_clause (struct ring *ring, struct clause *clause,
unsigned inc) {
assert (inc);
assert (!is_binary_pointer (clause));
unsigned shared = atomic_fetch_add (&clause->shared, inc);
LOGCLAUSE (clause, "reference %u times (was shared %u)", inc, shared);
assert (shared < MAX_THREADS - inc), (void) shared;
}
bool dereference_clause (struct ring *ring, struct clause *clause) {
assert (!is_binary_pointer (clause));
unsigned shared = atomic_fetch_sub (&clause->shared, 1);
LOGCLAUSE (clause, "dereference once (was shared %u)", shared);
assert (shared + 1);
if (shared)
return false;
delete_clause (ring, clause);
return true;
}