about summary refs log tree commit diff stats
path: root/miasm2/expression
diff options
context:
space:
mode:
authorCamille Mougey <commial@gmail.com>2015-07-30 08:31:34 +0200
committerCamille Mougey <commial@gmail.com>2015-07-30 08:31:34 +0200
commitea4ca3425e49c59fa4cb9b5b5b91cc9431dcb843 (patch)
treedda7deef86d31ed01361eca60719f81ef2db79a5 /miasm2/expression
parent817fc666eac74c802d4d592f50a3872a3197f4a5 (diff)
parent5802dfd9ff93f755b648ff4a3ba236a80c121fb3 (diff)
downloadmiasm-ea4ca3425e49c59fa4cb9b5b5b91cc9431dcb843.tar.gz
miasm-ea4ca3425e49c59fa4cb9b5b5b91cc9431dcb843.zip
Merge pull request #199 from serpilliere/fix_x86_sem
Fix x86 sem
Diffstat (limited to 'miasm2/expression')
-rw-r--r--miasm2/expression/expression_helper.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/miasm2/expression/expression_helper.py b/miasm2/expression/expression_helper.py
index 3555530a..196ad5cd 100644
--- a/miasm2/expression/expression_helper.py
+++ b/miasm2/expression/expression_helper.py
@@ -533,3 +533,22 @@ class ExprRandom(object):
             cls.generated_elements = {}
 
         return got
+
+def _expr_cmp_gen(arg1, arg2):
+    return (arg2 - arg1) ^ ((arg2 ^ arg1) & ((arg2 - arg1) ^ arg2))
+
+def expr_cmpu(arg1, arg2):
+    """
+    Returns a one bit long Expression:
+    * 1 if @arg1 is strictly greater than @arg2 (unsigned)
+    * 0 otherwise.
+    """
+    return (_expr_cmp_gen(arg1, arg2) ^ arg2 ^ arg1).msb()
+
+def expr_cmps(arg1, arg2):
+    """
+    Returns a one bit long Expression:
+    * 1 if @arg1 is strictly greater than @arg2 (signed)
+    * 0 otherwise.
+    """
+    return _expr_cmp_gen(arg1, arg2).msb()