2021-01-21 15:20:22 +00:00
|
|
|
from opcodes import SHL, MUL
|
2019-06-13 14:43:11 +00:00
|
|
|
from rule import Rule
|
2021-01-21 15:20:22 +00:00
|
|
|
from z3 import BitVec
|
2019-06-13 14:43:11 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
Rule:
|
|
|
|
MUL(X, SHL(Y, 1)) -> SHL(Y, X)
|
|
|
|
MUL(SHL(X, 1), Y) -> SHL(X, Y)
|
|
|
|
Requirements:
|
|
|
|
"""
|
|
|
|
|
|
|
|
rule = Rule()
|
|
|
|
|
|
|
|
n_bits = 64
|
|
|
|
|
|
|
|
# Input vars
|
|
|
|
X = BitVec('X', n_bits)
|
|
|
|
Y = BitVec('Y', n_bits)
|
|
|
|
|
|
|
|
# Requirements
|
|
|
|
|
|
|
|
# Non optimized result
|
2019-06-14 14:57:57 +00:00
|
|
|
nonopt_1 = MUL(X, SHL(Y, 1))
|
|
|
|
nonopt_2 = MUL(SHL(X, 1), Y)
|
2019-06-13 14:43:11 +00:00
|
|
|
|
|
|
|
# Optimized result
|
|
|
|
opt_1 = SHL(Y, X)
|
|
|
|
opt_2 = SHL(X, Y)
|
|
|
|
|
|
|
|
rule.check(nonopt_1, opt_1)
|
|
|
|
rule.check(nonopt_2, opt_2)
|