Skip to content

Commit 1d9e73b

Browse files
committed
Bugfix: flattening for non-binary bitnor, bitnand, bitxnor
This fixes the flattening for bitnor, bitnand, bitxnor for the case that the expression has one operand or more than two operands. For one operand, the result is now the bit-wise negation. For three or more operands, the result is now the bit-wise negation of the bitor, bitand, bitxor with the same operands.
1 parent c4aaafd commit 1d9e73b

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/solvers/flattening/boolbv_bitwise.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ bvt boolbvt::convert_bitwise(const exprt &expr)
2525
expr.id()==ID_bitnand || expr.id()==ID_bitnor ||
2626
expr.id()==ID_bitxnor)
2727
{
28+
std::function<literalt(literalt, literalt)> f;
29+
30+
if(expr.id() == ID_bitand || expr.id() == ID_bitnand)
31+
f = [this](literalt a, literalt b) { return prop.land(a, b); };
32+
else if(expr.id() == ID_bitor || expr.id() == ID_bitnor)
33+
f = [this](literalt a, literalt b) { return prop.lor(a, b); };
34+
else if(expr.id() == ID_bitxor || expr.id() == ID_bitxnor)
35+
f = [this](literalt a, literalt b) { return prop.lxor(a, b); };
36+
else
37+
UNIMPLEMENTED;
38+
2839
bvt bv;
2940
bv.resize(width);
3041

@@ -38,25 +49,19 @@ bvt boolbvt::convert_bitwise(const exprt &expr)
3849
{
3950
for(std::size_t i=0; i<width; i++)
4051
{
41-
if(expr.id()==ID_bitand)
42-
bv[i]=prop.land(bv[i], op[i]);
43-
else if(expr.id()==ID_bitor)
44-
bv[i]=prop.lor(bv[i], op[i]);
45-
else if(expr.id()==ID_bitxor)
46-
bv[i]=prop.lxor(bv[i], op[i]);
47-
else if(expr.id()==ID_bitnand)
48-
bv[i]=prop.lnand(bv[i], op[i]);
49-
else if(expr.id()==ID_bitnor)
50-
bv[i]=prop.lnor(bv[i], op[i]);
51-
else if(expr.id()==ID_bitxnor)
52-
bv[i]=prop.lequal(bv[i], op[i]);
53-
else
54-
UNIMPLEMENTED;
52+
bv[i] = f(bv[i], op[i]);
5553
}
5654
}
5755
}
5856

59-
return bv;
57+
if(
58+
expr.id() == ID_bitnand || expr.id() == ID_bitnor ||
59+
expr.id() == ID_bitxnor)
60+
{
61+
return bv_utils.inverted(bv);
62+
}
63+
else
64+
return bv;
6065
}
6166

6267
UNIMPLEMENTED;

0 commit comments

Comments
 (0)