Skip to content

simplifier: sum and mul cleanup #3098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/util/fixedbv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ fixedbvt &fixedbvt::operator*=(const fixedbvt &o)
return *this;
}

fixedbvt &fixedbvt::operator+=(const fixedbvt &o)
{
v += o.v;
return *this;
}

fixedbvt &fixedbvt::operator-=(const fixedbvt &o)
{
v -= o.v;
return *this;
}

fixedbvt &fixedbvt::operator/=(const fixedbvt &o)
{
v*=power(2, o.spec.get_fraction_bits());
Expand Down
56 changes: 23 additions & 33 deletions src/util/simplify_expr_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ static bool sum_expr(

const irep_idt &type_id=dest.type().id();

if(type_id==ID_integer || type_id==ID_natural)
if(
type_id == ID_integer || type_id == ID_natural ||
type_id == ID_unsignedbv || type_id == ID_signedbv)
{
dest.set_value(integer2string(
string2integer(id2string(dest.get_value()))+
string2integer(id2string(expr.get_value()))));
return false;
mp_integer a, b;
if(!to_integer(dest, a) && !to_integer(expr, b))
{
dest = from_integer(a + b, dest.type());
return false;
}
}
else if(type_id==ID_rational)
{
Expand All @@ -86,26 +90,17 @@ static bool sum_expr(
return false;
}
}
else if(type_id==ID_unsignedbv || type_id==ID_signedbv)
{
dest.set_value(integer2binary(
binary2integer(id2string(dest.get_value()), false)+
binary2integer(id2string(expr.get_value()), false),
to_bitvector_type(dest.type()).get_width()));
return false;
}
else if(type_id==ID_fixedbv)
{
dest.set_value(integer2binary(
binary2integer(id2string(dest.get_value()), false)+
binary2integer(id2string(expr.get_value()), false),
to_bitvector_type(dest.type()).get_width()));
fixedbvt f(dest);
f += fixedbvt(expr);
dest = f.to_expr();
return false;
}
else if(type_id==ID_floatbv)
{
ieee_floatt f(to_constant_expr(dest));
f+=ieee_floatt(to_constant_expr(expr));
ieee_floatt f(dest);
f += ieee_floatt(expr);
dest=f.to_expr();
return false;
}
Expand All @@ -124,12 +119,16 @@ static bool mul_expr(

const irep_idt &type_id=dest.type().id();

if(type_id==ID_integer || type_id==ID_natural)
if(
type_id == ID_integer || type_id == ID_natural ||
type_id == ID_unsignedbv || type_id == ID_signedbv)
{
dest.set_value(integer2string(
string2integer(id2string(dest.get_value()))*
string2integer(id2string(expr.get_value()))));
return false;
mp_integer a, b;
if(!to_integer(dest, a) && !to_integer(expr, b))
{
dest = from_integer(a * b, dest.type());
return false;
}
}
else if(type_id==ID_rational)
{
Expand All @@ -140,15 +139,6 @@ static bool mul_expr(
return false;
}
}
else if(type_id==ID_unsignedbv || type_id==ID_signedbv)
{
// the following works for signed and unsigned integers
dest.set_value(integer2binary(
binary2integer(id2string(dest.get_value()), false)*
binary2integer(id2string(expr.get_value()), false),
to_bitvector_type(dest.type()).get_width()));
return false;
}
else if(type_id==ID_fixedbv)
{
fixedbvt f(to_constant_expr(dest));
Expand Down