Skip to content

Commit 84d0e97

Browse files
author
Daniel Kroening
committed
added simplify_exprt::simplify_power
1 parent a00b34a commit 84d0e97

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/util/simplify_expr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,8 @@ bool simplify_exprt::simplify_node(exprt &expr)
25092509
result=simplify_bitwise(expr) && result;
25102510
else if(expr.id()==ID_ashr || expr.id()==ID_lshr || expr.id()==ID_shl)
25112511
result=simplify_shifts(expr) && result;
2512+
else if(expr.id()==ID_power)
2513+
result=simplify_power(expr) && result;
25122514
else if(expr.id()==ID_plus)
25132515
result=simplify_plus(expr) && result;
25142516
else if(expr.id()==ID_minus)

src/util/simplify_expr_class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class simplify_exprt
7171
bool simplify_floatbv_op(exprt &expr);
7272
bool simplify_floatbv_typecast(exprt &expr);
7373
bool simplify_shifts(exprt &expr);
74+
bool simplify_power(exprt &expr);
7475
bool simplify_bitwise(exprt &expr);
7576
bool simplify_if_preorder(if_exprt &expr);
7677
bool simplify_if(if_exprt &expr);

src/util/simplify_expr_int.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,40 @@ bool simplify_exprt::simplify_shifts(exprt &expr)
10161016

10171017
/*******************************************************************\
10181018
1019+
Function: simplify_exprt::simplify_power
1020+
1021+
Inputs:
1022+
1023+
Outputs:
1024+
1025+
Purpose:
1026+
1027+
\*******************************************************************/
1028+
1029+
bool simplify_exprt::simplify_power(exprt &expr)
1030+
{
1031+
if(!is_number(expr.type()))
1032+
return true;
1033+
1034+
if(expr.operands().size()!=2)
1035+
return true;
1036+
1037+
mp_integer base, exponent;
1038+
1039+
if(to_integer(expr.op0(), base))
1040+
return true;
1041+
1042+
if(to_integer(expr.op1(), exponent))
1043+
return true;
1044+
1045+
mp_integer result=power(base, exponent);
1046+
1047+
expr=from_integer(result, expr.type());
1048+
return false;
1049+
}
1050+
1051+
/*******************************************************************\
1052+
10191053
Function: simplify_exprt::simplify_extractbits
10201054
10211055
Inputs:

0 commit comments

Comments
 (0)