diff options
| author | Ajax <commial@gmail.com> | 2018-08-30 14:42:29 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2018-08-30 14:43:07 +0200 |
| commit | 579d439700d1944f067a2c28d4aa9ea6736d631a (patch) | |
| tree | a455d312cdc5a48c41c0676ab4ba98049ff555fd | |
| parent | a06f5c7703da2b5f0890f7681eed638ffe6698a1 (diff) | |
| download | miasm-579d439700d1944f067a2c28d4aa9ea6736d631a.tar.gz miasm-579d439700d1944f067a2c28d4aa9ea6736d631a.zip | |
Add support for floating is_zero, is_inf, is_denormal
| -rw-r--r-- | miasm2/expression/expression.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py index 69739990..c4b3cca1 100644 --- a/miasm2/expression/expression.py +++ b/miasm2/expression/expression.py @@ -1925,6 +1925,40 @@ def expr_is_NaN(expr): ExprInt(0, 1))) +def expr_is_infinite(expr): + """Return 1 or 0 on 1 bit if expr represent an infinite value according to + IEEE754 + """ + info = size_to_IEEE754_info[expr.size] + exponent = expr[info["significand"]: info["significand"] + info["exponent"]] + + # exponent is full of 1s and significand is NULL + return ExprCond(exponent - ExprInt(-1, exponent.size), + ExprInt(0, 1), + ExprCond(expr[:info["significand"]], ExprInt(0, 1), + ExprInt(1, 1))) + + +def expr_is_IEEE754_zero(expr): + """Return 1 or 0 on 1 bit if expr represent a zero value according to + IEEE754 + """ + info = size_to_IEEE754_info[expr.size] + # Sign is the msb + expr_no_sign = expr[:expr.size - 1] + return ExprCond(expr_no_sign, ExprInt(0, 1), ExprInt(1, 1)) + + +def expr_is_IEEE754_denormal(expr): + """Return 1 or 0 on 1 bit if expr represent a denormalized value according + to IEEE754 + """ + info = size_to_IEEE754_info[expr.size] + exponent = expr[info["significand"]: info["significand"] + info["exponent"]] + # exponent is full of 0s + return ExprCond(exponent, ExprInt(0, 1), ExprInt(1, 1)) + + def expr_is_qNaN(expr): """Return 1 or 0 on 1 bit if expr represent a qNaN (quiet) value according to IEEE754 |