Skip to content

Commit 1f1a11e

Browse files
author
Daniel Kroening
committed
fix for multi-ary fixed-bv multiplication
1 parent 35c653d commit 1f1a11e

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

regression/cbmc/Fixedbv8/main.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
typedef __CPROVER_fixedbv[64][32] __plant_typet;
2+
extern __plant_typet A0, A1;
3+
4+
int main(void) {
5+
__CPROVER_assume(A0 == (__plant_typet)0.125);
6+
__CPROVER_assume(A1 == (__plant_typet)0.015625);
7+
8+
const __plant_typet XXX1a=A0 * A1;
9+
const __plant_typet XXX2a=(__plant_typet)-1 * XXX1a;
10+
const __plant_typet XXX2b=-0.001953125;
11+
__CPROVER_assert(XXX2a==XXX2b, "");
12+
return 0;
13+
}

regression/cbmc/Fixedbv8/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/solvers/flattening/boolbv_mult.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ bvt boolbvt::convert_mult(const exprt &expr)
5353
std::size_t fraction_bits=
5454
to_fixedbv_type(expr.type()).get_fraction_bits();
5555

56-
// do a sign extension by fraction_bits bits
57-
bv=bv_utils.sign_extension(bv, bv.size()+fraction_bits);
58-
5956
for(exprt::operandst::const_iterator it=operands.begin()+1;
6057
it!=operands.end(); it++)
6158
{
6259
if(it->type()!=expr.type())
6360
throw "multiplication with mixed types";
6461

62+
// do a sign extension by fraction_bits bits
63+
bv=bv_utils.sign_extension(bv, bv.size()+fraction_bits);
64+
6565
bvt op=convert_bv(*it);
6666

6767
if(op.size()!=width)
@@ -70,10 +70,10 @@ bvt boolbvt::convert_mult(const exprt &expr)
7070
op=bv_utils.sign_extension(op, bv.size());
7171

7272
bv=bv_utils.signed_multiplier(bv, op);
73-
}
7473

75-
// cut it down again
76-
bv.erase(bv.begin(), bv.begin()+fraction_bits);
74+
// cut it down again
75+
bv.erase(bv.begin(), bv.begin()+fraction_bits);
76+
}
7777

7878
return bv;
7979
}

0 commit comments

Comments
 (0)