Skip to content

Commit 1e890a5

Browse files
committed
speed up construction of values for large bitvector types
This commit improves the complexity of boolbvt::get(...) from quadratic to linear. The difference is noticeable when using very large bitvectors, e.g., for encoding unions with large array members. E.g., the time taken for regression/cbmc/union/union_large_array.c when using --cprover-smt2 improves from 12s to 0.2s.
1 parent e3eb9c4 commit 1e890a5

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

regression/cbmc/bounds_check1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-z3-smt-backend
22
main.c
33
--bounds-check --pointer-check
44
^EXIT=10$

regression/cbmc/union/union_large_array.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-z3-smt-backend
22
union_large_array.c
33

44
^EXIT=10$

src/solvers/flattening/boolbv_get.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ exprt boolbvt::bv_get_rec(const exprt &expr, const bvt &bv, std::size_t offset)
199199
const std::size_t width = boolbv_width(type);
200200
PRECONDITION(bv.size() >= offset + width);
201201

202-
// most significant bit first
203202
std::string value;
203+
value.reserve(width);
204204

205205
for(std::size_t bit_nr=offset; bit_nr<offset+width; bit_nr++)
206206
{
@@ -214,9 +214,13 @@ exprt boolbvt::bv_get_rec(const exprt &expr, const bvt &bv, std::size_t offset)
214214
}
215215
// clang-format on
216216

217-
value=ch+value;
217+
value += ch;
218218
}
219219

220+
// The above collects bits starting with the least significant bit,
221+
// but we need the most significant bit first.
222+
std::reverse(value.begin(), value.end());
223+
220224
switch(bvtype)
221225
{
222226
case bvtypet::IS_UNKNOWN:

0 commit comments

Comments
 (0)