diff options
| author | Ajax <commial@gmail.com> | 2018-05-15 10:42:02 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2018-05-15 10:42:02 +0200 |
| commit | de4295331794e81937a5c4073c37808ec63beaa4 (patch) | |
| tree | a8b2bab4f9e91ab56442ea29d525ce6d5390536c /miasm2/expression/simplifications_common.py | |
| parent | c450ece842408d2abcfc0f2ec648a4841bf0673b (diff) | |
| download | miasm-de4295331794e81937a5c4073c37808ec63beaa4.tar.gz miasm-de4295331794e81937a5c4073c37808ec63beaa4.zip | |
Op bsr/bsf are replaced by cnttrailzeros / cntleadzeros, defined in 0
Diffstat (limited to 'miasm2/expression/simplifications_common.py')
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index a1301cba..13b25ce2 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -95,19 +95,21 @@ def simp_cst_propagation(e_s, expr): args.append(ExprInt(out, int1.size)) - # bsf(int) => int - if op_name == "bsf" and args[0].is_int() and args[0].arg != 0: + # cnttrailzeros(int) => int + if op_name == "cnttrailzeros" and args[0].is_int(): i = 0 - while args[0].arg & (1 << i) == 0: + while args[0].arg & (1 << i) == 0 and i < args[0].size: i += 1 return ExprInt(i, args[0].size) - # bsr(int) => int - if op_name == "bsr" and args[0].is_int() and args[0].arg != 0: + # cntleadzeros(int) => int + if op_name == "cntleadzeros" and args[0].is_int(): + if args[0].arg == 0: + return ExprInt(args[0].size, args[0].size) i = args[0].size - 1 while args[0].arg & (1 << i) == 0: i -= 1 - return ExprInt(i, args[0].size) + return ExprInt(expr.size - (i + 1), args[0].size) # -(-(A)) => A if (op_name == '-' and len(args) == 1 and args[0].is_op('-') and |