about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2018-08-30 14:42:29 +0200
committerAjax <commial@gmail.com>2018-08-30 14:43:07 +0200
commit579d439700d1944f067a2c28d4aa9ea6736d631a (patch)
treea455d312cdc5a48c41c0676ab4ba98049ff555fd
parenta06f5c7703da2b5f0890f7681eed638ffe6698a1 (diff)
downloadmiasm-579d439700d1944f067a2c28d4aa9ea6736d631a.tar.gz
miasm-579d439700d1944f067a2c28d4aa9ea6736d631a.zip
Add support for floating is_zero, is_inf, is_denormal
-rw-r--r--miasm2/expression/expression.py34
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