Skip to content

Commit 59db0f1

Browse files
hrkrshnnchriseth
authored andcommitted
An equivalence check for SIGNEXTEND opcode
Checking the implementation of SIGNEXTEND using Z3's native SignExt and Extract
1 parent 5906d25 commit 59db0f1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/formal/signextend_equivalence.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from rule import Rule
2+
from opcodes import *
3+
4+
"""
5+
Checking the implementation of SIGNEXTEND using Z3's native SignExt and Extract
6+
"""
7+
8+
rule = Rule()
9+
n_bits = 256
10+
11+
x = BitVec('X', n_bits)
12+
13+
def SIGNEXTEND_native(i, x):
14+
return SignExt(256 - 8 * i - 8, Extract(8 * i + 7, 0, x))
15+
16+
for i in range(0, 32):
17+
rule.check(
18+
SIGNEXTEND(BitVecVal(i, n_bits), x),
19+
SIGNEXTEND_native(i, x)
20+
)
21+
22+
i = BitVec('I', n_bits)
23+
rule.require(UGT(i, BitVecVal(31, n_bits)))
24+
rule.check(SIGNEXTEND(i, x), x)

0 commit comments

Comments
 (0)