Skip to content

Commit c6f61f1

Browse files
CRef: support 64 bit
To be able to handle more clauses, make sure we can index the allocator area with 64bit values. This access allows to handle large formulas. Signed-off-by: Norbert Manthey <[email protected]>
1 parent 76cb34f commit c6f61f1

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

minisat/core/Solver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3483,7 +3483,7 @@ void Solver::garbageCollect()
34833483

34843484
relocAll(to);
34853485
if (verbosity >= 2)
3486-
printf("c | Garbage collection: %12d bytes => %12d bytes |\n",
3486+
printf("c | Garbage collection: %12lu bytes => %12lu bytes |\n",
34873487
ca.size() * ClauseAllocator::Unit_Size, to.size() * ClauseAllocator::Unit_Size);
34883488
to.moveTo(ca);
34893489
}

minisat/core/SolverTypes.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class Clause
192192
float act;
193193
uint32_t abs;
194194
uint32_t touched;
195-
CRef rel;
195+
uint32_t rel;
196196
} data[0];
197197

198198
friend class ClauseAllocator;
@@ -266,11 +266,14 @@ class Clause
266266
}
267267

268268
bool reloced() const { return header.reloced; }
269-
CRef relocation() const { return data[0].rel; }
269+
CRef relocation() const { return ((uint64_t)data[0].rel << 32) + data[1].rel; }
270270
void relocate(CRef c)
271271
{
272+
assert(size() > 1 && "do not relocate non-unit clauses");
273+
assert(header.reloced == 0 && "do not relocate multiple times");
272274
header.reloced = 1;
273-
data[0].rel = c;
275+
data[0].rel = c >> 32;
276+
data[1].rel = c & (UINT32_MAX - 1);
274277
}
275278

276279
/// remove the literal at the given position

minisat/mtl/Alloc.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ namespace MERGESAT_NSPACE
3333
template <class T> class RegionAllocator
3434
{
3535
T *memory;
36-
uint32_t sz;
37-
uint32_t cap;
38-
uint32_t wasted_;
36+
uint64_t sz;
37+
uint64_t cap;
38+
uint64_t wasted_;
3939

40-
void capacity(uint32_t min_cap);
40+
void capacity(uint64_t min_cap);
4141

4242
public:
4343
// TODO: make this a class for better type-checking?
44-
typedef uint32_t Ref;
45-
enum { Ref_Undef = UINT32_MAX };
44+
typedef uint64_t Ref;
45+
enum { Ref_Undef = UINT64_MAX };
4646
enum { Unit_Size = sizeof(uint32_t) };
4747

48-
explicit RegionAllocator(uint32_t start_cap = 1024 * 1024) : memory(NULL), sz(0), cap(0), wasted_(0)
48+
explicit RegionAllocator(uint64_t start_cap = 1024 * 1024) : memory(NULL), sz(0), cap(0), wasted_(0)
4949
{
5050
capacity(start_cap);
5151
}
@@ -55,8 +55,8 @@ template <class T> class RegionAllocator
5555
}
5656

5757

58-
uint32_t size() const { return sz; }
59-
uint32_t wasted() const { return wasted_; }
58+
uint64_t size() const { return sz; }
59+
uint64_t wasted() const { return wasted_; }
6060

6161
Ref alloc(int size);
6262
void free(int size) { wasted_ += size; }
@@ -102,17 +102,17 @@ template <class T> class RegionAllocator
102102
}
103103
};
104104

105-
template <class T> void RegionAllocator<T>::capacity(uint32_t min_cap)
105+
template <class T> void RegionAllocator<T>::capacity(uint64_t min_cap)
106106
{
107107
if (cap >= min_cap) return;
108108

109-
uint32_t prev_cap = cap;
109+
uint64_t prev_cap = cap;
110110
while (cap < min_cap) {
111111
// NOTE: Multiply by a factor (13/8) without causing overflow, then add 2 and make the
112112
// result even by clearing the least significant bit. The resulting sequence of capacities
113-
// is carefully chosen to hit a maximum capacity that is close to the '2^32-1' limit when
114-
// using 'uint32_t' as indices so that as much as possible of this space can be used.
115-
uint32_t delta = ((cap >> 1) + (cap >> 3) + 2) & ~1;
113+
// is carefully chosen to hit a maximum capacity that is close to the '2^64-1' limit when
114+
// using 'uint64_t' as indices so that as much as possible of this space can be used.
115+
uint64_t delta = ((cap >> 1) + (cap >> 3) + 2) & ~1;
116116
cap += delta;
117117

118118
if (cap <= prev_cap) throw OutOfMemoryException();
@@ -130,7 +130,7 @@ template <class T> typename RegionAllocator<T>::Ref RegionAllocator<T>::alloc(in
130130
assert(size > 0);
131131
capacity(sz + size);
132132

133-
uint32_t prev_sz = sz;
133+
uint64_t prev_sz = sz;
134134
sz += size;
135135

136136
// Handle overflow:

minisat/simp/SimpSolver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ void SimpSolver::garbageCollect()
933933
relocAll(to);
934934
Solver::relocAll(to);
935935
if (verbosity >= 2)
936-
printf("c | Garbage collection: %12d bytes => %12d bytes |\n",
936+
printf("c | Garbage collection: %12lu bytes => %12lu bytes |\n",
937937
ca.size() * ClauseAllocator::Unit_Size, to.size() * ClauseAllocator::Unit_Size);
938938
to.moveTo(ca);
939939
}

0 commit comments

Comments
 (0)