Skip to content

Commit a820eaa

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 129a792 commit a820eaa

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
* structures: allow 64bit CR index for using many clauses
1011
* parallel: support proof generation
1112
* testing: use modgen generator during fuzzing runs
1213
* fix FPU control to compile on ARM

minisat/core/Solver.cc

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

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

minisat/core/SolverTypes.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class Clause
247247
float act;
248248
uint32_t abs;
249249
uint32_t touched;
250-
CRef rel;
250+
uint32_t rel;
251251
} data[0];
252252
#if defined __clang__
253253
#pragma clang diagnostic pop
@@ -345,11 +345,18 @@ class Clause
345345
}
346346

347347
bool reloced() const { return header.reloced; }
348-
CRef relocation() const { return data[0].rel; }
348+
CRef relocation() const
349+
{
350+
assert(size() > 1);
351+
return ((uint64_t)data[0].rel << 32) + data[1].rel;
352+
}
349353
void relocate(CRef c)
350354
{
355+
assert(size() > 1 && "do not relocate non-unit clauses");
356+
assert(header.reloced == 0 && "do not relocate multiple times");
351357
header.reloced = 1;
352-
data[0].rel = c;
358+
data[0].rel = (uint32_t)(c >> 32);
359+
data[1].rel = (uint32_t)(c & (UINT32_MAX));
353360
}
354361

355362
/// 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; }
@@ -125,17 +125,17 @@ template <class T> class RegionAllocator
125125
AccessCounter &get_counter() { return counter; }
126126
};
127127

128-
template <class T> void RegionAllocator<T>::capacity(uint32_t min_cap)
128+
template <class T> void RegionAllocator<T>::capacity(uint64_t min_cap)
129129
{
130130
if (cap >= min_cap) return;
131131

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

141141
if (cap <= prev_cap) throw OutOfMemoryException();
@@ -153,7 +153,7 @@ template <class T> typename RegionAllocator<T>::Ref RegionAllocator<T>::alloc(in
153153
assert(size > 0);
154154
capacity(sz + size);
155155

156-
uint32_t prev_sz = sz;
156+
uint64_t prev_sz = sz;
157157
sz += size;
158158

159159
// Handle overflow:

minisat/simp/SimpSolver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ void SimpSolver::garbageCollect()
916916
relocAll(to);
917917
Solver::relocAll(to);
918918
if (verbosity >= 2)
919-
printf("c | Garbage collection: %12d bytes => %12d bytes |\n",
919+
printf("c | Garbage collection: %12" PRIu64 " bytes => %12" PRIu64 " bytes |\n",
920920
ca.size() * ClauseAllocator::Unit_Size, to.size() * ClauseAllocator::Unit_Size);
921921
to.moveTo(ca);
922922
}

0 commit comments

Comments
 (0)