Skip to content

Commit

Permalink
Bugfix: flattening for non-binary bitnor, bitnand, bitxnor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kroening committed Dec 22, 2024
1 parent c4aaafd commit 1d9e73b
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/solvers/flattening/boolbv_bitwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ bvt boolbvt::convert_bitwise(const exprt &expr)
expr.id()==ID_bitnand || expr.id()==ID_bitnor ||
expr.id()==ID_bitxnor)
{
std::function<literalt(literalt, literalt)> f;

Check warning on line 29 in src/solvers/flattening/boolbv_bitwise.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_bitwise.cpp#L29

Added line #L29 was not covered by tests
if(expr.id() == ID_bitand || expr.id() == ID_bitnand)
f = [this](literalt a, literalt b) { return prop.land(a, b); };
else if(expr.id() == ID_bitor || expr.id() == ID_bitnor)
f = [this](literalt a, literalt b) { return prop.lor(a, b); };
else if(expr.id() == ID_bitxor || expr.id() == ID_bitxnor)
f = [this](literalt a, literalt b) { return prop.lxor(a, b); };
else
UNIMPLEMENTED;

Check warning on line 37 in src/solvers/flattening/boolbv_bitwise.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/boolbv_bitwise.cpp#L36-L37

Added lines #L36 - L37 were not covered by tests

bvt bv;
bv.resize(width);

Expand All @@ -38,25 +49,19 @@ bvt boolbvt::convert_bitwise(const exprt &expr)
{
for(std::size_t i=0; i<width; i++)
{
if(expr.id()==ID_bitand)
bv[i]=prop.land(bv[i], op[i]);
else if(expr.id()==ID_bitor)
bv[i]=prop.lor(bv[i], op[i]);
else if(expr.id()==ID_bitxor)
bv[i]=prop.lxor(bv[i], op[i]);
else if(expr.id()==ID_bitnand)
bv[i]=prop.lnand(bv[i], op[i]);
else if(expr.id()==ID_bitnor)
bv[i]=prop.lnor(bv[i], op[i]);
else if(expr.id()==ID_bitxnor)
bv[i]=prop.lequal(bv[i], op[i]);
else
UNIMPLEMENTED;
bv[i] = f(bv[i], op[i]);
}
}
}

return bv;
if(
expr.id() == ID_bitnand || expr.id() == ID_bitnor ||
expr.id() == ID_bitxnor)
{
return bv_utils.inverted(bv);
}
else
return bv;
}

UNIMPLEMENTED;
Expand Down

0 comments on commit 1d9e73b

Please sign in to comment.