Skip to content

Commit 3e1b508

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 b0fb916 commit 3e1b508

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

minisat/core/Solver.cc

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

34883488
relocAll(to);
34893489
if (verbosity >= 2)
3490-
printf("c | Garbage collection: %12d bytes => %12d bytes |\n",
3490+
printf("c | Garbage collection: %12" PRIu64 " bytes => %12" PRIu64 " bytes |\n",
34913491
ca.size() * ClauseAllocator::Unit_Size, to.size() * ClauseAllocator::Unit_Size);
34923492
to.moveTo(ca);
34933493
}

minisat/core/SolverTypes.h

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

199199
friend class ClauseAllocator;
@@ -267,11 +267,14 @@ class Clause
267267
}
268268

269269
bool reloced() const { return header.reloced; }
270-
CRef relocation() const { return data[0].rel; }
270+
CRef relocation() const { assert(size() > 1); return ((uint64_t)data[0].rel << 32) + data[1].rel; }
271271
void relocate(CRef c)
272272
{
273+
assert(size() > 1 && "do not relocate non-unit clauses");
274+
assert(header.reloced == 0 && "do not relocate multiple times");
273275
header.reloced = 1;
274-
data[0].rel = c;
276+
data[0].rel = (uint32_t)(c >> 32);
277+
data[1].rel = (uint32_t)(c & (UINT32_MAX));
275278
}
276279

277280
/// remove the literal at the given position

minisat/mtl/Alloc.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ class AccessCounter
4848
template <class T> class RegionAllocator
4949
{
5050
T *memory;
51-
uint32_t sz;
52-
uint32_t cap;
53-
uint32_t wasted_;
51+
uint64_t sz;
52+
uint64_t cap;
53+
uint64_t wasted_;
5454
AccessCounter &counter;
5555

56-
void capacity(uint32_t min_cap);
56+
void capacity(uint64_t min_cap);
5757

5858
public:
5959
// TODO: make this a class for better type-checking?
60-
typedef uint32_t Ref;
61-
enum { Ref_Undef = UINT32_MAX };
62-
enum { Unit_Size = sizeof(uint32_t) };
60+
typedef uint64_t Ref;
61+
enum { Ref_Undef = UINT64_MAX };
62+
enum { Unit_Size = sizeof(Ref) };
6363

64-
explicit RegionAllocator(AccessCounter &_counter, uint32_t start_cap = 1024 * 1024)
64+
explicit RegionAllocator(AccessCounter &_counter, uint64_t start_cap = 1024 * 1024)
6565
: memory(NULL), sz(0), cap(0), wasted_(0), counter(_counter)
6666
{
6767
capacity(start_cap);
@@ -72,8 +72,8 @@ template <class T> class RegionAllocator
7272
}
7373

7474

75-
uint32_t size() const { return sz; }
76-
uint32_t wasted() const { return wasted_; }
75+
uint64_t size() const { return sz; }
76+
uint64_t wasted() const { return wasted_; }
7777

7878
Ref alloc(int size);
7979
void free(int size) { wasted_ += size; }
@@ -123,17 +123,17 @@ template <class T> class RegionAllocator
123123
AccessCounter &get_counter() { return counter; }
124124
};
125125

126-
template <class T> void RegionAllocator<T>::capacity(uint32_t min_cap)
126+
template <class T> void RegionAllocator<T>::capacity(uint64_t min_cap)
127127
{
128128
if (cap >= min_cap) return;
129129

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

139139
if (cap <= prev_cap) throw OutOfMemoryException();
@@ -151,7 +151,7 @@ template <class T> typename RegionAllocator<T>::Ref RegionAllocator<T>::alloc(in
151151
assert(size > 0);
152152
capacity(sz + size);
153153

154-
uint32_t prev_sz = sz;
154+
uint64_t prev_sz = sz;
155155
sz += size;
156156

157157
// Handle overflow:

minisat/simp/SimpSolver.cc

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

0 commit comments

Comments
 (0)