mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
34 lines
480 B
Python
34 lines
480 B
Python
|
from rule import Rule
|
||
|
from opcodes import *
|
||
|
|
||
|
"""
|
||
|
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)
|
||
|
|
||
|
# Constants
|
||
|
ONE = BitVecVal(1, n_bits)
|
||
|
|
||
|
# Requirements
|
||
|
|
||
|
# Non optimized result
|
||
|
nonopt_1 = MUL(X, SHL(Y, ONE))
|
||
|
nonopt_2 = MUL(SHL(X, ONE), Y)
|
||
|
|
||
|
# Optimized result
|
||
|
opt_1 = SHL(Y, X)
|
||
|
opt_2 = SHL(X, Y)
|
||
|
|
||
|
rule.check(nonopt_1, opt_1)
|
||
|
rule.check(nonopt_2, opt_2)
|