about summary refs log tree commit diff stats
path: root/miasm2/expression/expression_helper.py
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2015-07-29 16:28:14 +0200
committerserpilliere <fabrice.desclaux@cea.fr>2015-07-29 19:29:37 +0200
commitdb711b79cc5047757ab6af2f0960f0e3b52cba66 (patch)
tree0de14312ce47a7ebc69ee6dd88529964bcc1f23f /miasm2/expression/expression_helper.py
parent5291abfd3c70250277224635c40ee14578b84ae4 (diff)
downloadmiasm-db711b79cc5047757ab6af2f0960f0e3b52cba66.tar.gz
miasm-db711b79cc5047757ab6af2f0960f0e3b52cba66.zip
Expression/helper: add macro cmpu/cmps
Diffstat (limited to 'miasm2/expression/expression_helper.py')
-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()