-
Notifications
You must be signed in to change notification settings - Fork 86
smt: abstract multiplication #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/halmos/sevm.py
Outdated
return w2 | ||
|
||
if is_power_of_two(i1): | ||
return w2 << int(math.log(i1, 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return w2 << int(math.log(i1, 2)) | |
return w2 << i1.bit_length() - 1 |
quick check:
~/projects/halmos on code-fastpath wip *21 !2 ?50 ❯ python -m timeit --setup='import math' 'int(math.log(32, 2))'
2000000 loops, best of 5: 121 nsec per loop
~/projects/halmos on code-fastpath wip *21 !2 ?50 ❯ python -m timeit 'int(32).bit_length() - 1'
5000000 loops, best of 5: 66.1 nsec per loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done: 2ee4120
src/halmos/sevm.py
Outdated
@@ -1348,7 +1356,35 @@ def arith(self, ex: Exec, op: int, w1: Word, w2: Word) -> Word: | |||
return w1 - w2 | |||
|
|||
if op == EVM.MUL: | |||
return w1 * w2 | |||
if is_bv_value(w1) and is_bv_value(w2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we invoke is_bv_value(x)
once for each and reuse the results? in the worst case it results in 6 calls to that function, which itself makes more function calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done: e8490ee
@@ -1348,7 +1356,35 @@ def arith(self, ex: Exec, op: int, w1: Word, w2: Word) -> Word: | |||
return w1 - w2 | |||
|
|||
if op == EVM.MUL: | |||
return w1 * w2 | |||
if is_bv_value(w1) and is_bv_value(w2): | |||
return w1 * w2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to double check: we're fine here in case of overflow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, and it's indeed intended.
Abstract multiplication in a similar way to division and modulo operations.
The actual bitvector multiplication is used when either argument is concrete. Also, when an argument is a power of two, the left-shift is used instead of multiplication.