diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2018-06-15 15:01:34 +0200 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2018-06-21 21:34:28 +0200 |
| commit | a1b21f745fddb7979a1baa8dd48d0ff253746677 (patch) | |
| tree | 13faaa9df74dbb77471741a9d10aba4f97f7d21c /miasm2/expression/simplifications_common.py | |
| parent | 98a60ebb7366cda9774fc0511185602cada1833b (diff) | |
| download | miasm-a1b21f745fddb7979a1baa8dd48d0ff253746677.tar.gz miasm-a1b21f745fddb7979a1baa8dd48d0ff253746677.zip | |
Expr: add simplification shift mask
Diffstat (limited to 'miasm2/expression/simplifications_common.py')
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index 13b25ce2..149c5b8d 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -250,6 +250,26 @@ def simp_cst_propagation(e_s, expr): e_s(Y.msb()) == ExprInt(0, 1)): args = [args[0].args[0], X + Y] + # ((var >> int1) << int1) => var & mask + # ((var << int1) >> int1) => var & mask + if (op_name in ['<<', '>>'] and + args[0].is_op() and + args[0].op in ['<<', '>>'] and + op_name != args[0]): + var = args[0].args[0] + int1 = args[0].args[1] + int2 = args[1] + if int1 == int2 and int1.is_int() and int(int1) < expr.size: + if op_name == '>>': + mask = ExprInt((1 << (expr.size - int(int1))) - 1, expr.size) + else: + mask = ExprInt( + ((1 << int(int1)) - 1) ^ ((1 << expr.size) - 1), + expr.size + ) + ret = var & mask + return ret + # ((A & A.mask) if op_name == "&" and args[-1] == expr.mask: return ExprOp('&', *args[:-1]) |