-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b1690c
commit 0dcb2e5
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from hwtypes import BitVector, SMTBitVector | ||
|
||
def add3(a, b, c): | ||
return a + b + c | ||
|
||
#''' | ||
# Python bitvector types | ||
x = BitVector[8](2) | ||
y = BitVector[8](5) | ||
z = BitVector[8](11) | ||
|
||
print(add3(x,y,z)) | ||
#''' | ||
''' | ||
# SMT bitvector types | ||
x = SMTBitVector[8](2) | ||
y = SMTBitVector[8](5) | ||
z = SMTBitVector[8](11) | ||
print(add3(x,y,z)) | ||
''' | ||
''' | ||
# SMT symbolic bitvector types | ||
x = SMTBitVector[8](name="a") | ||
y = SMTBitVector[8](name="b") | ||
z = SMTBitVector[8](name="c") | ||
print(add3(x,y,z)) | ||
''' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from peak import Peak | ||
import hwtypes as ht | ||
|
||
|
||
class Opcode(ht.Enum): | ||
Add = 0 | ||
Sub = 1 | ||
Neg = 2 | ||
|
||
Word = ht.BitVector[8] | ||
|
||
class ALU(Peak): | ||
def __call__(self, inst: Opcode, i0: Word, i1: Word) -> Word: | ||
if inst == Opcode.Add: | ||
return i0 + i1 | ||
elif inst == Opcode.Sub: | ||
return i0 - i1 | ||
else: | ||
return -i0 | ||
|
||
alu = ALU() | ||
|
||
i0 = Word(54) | ||
i1 = Word(88) | ||
|
||
out = alu(Opcode.Add, i0, i1) | ||
|
||
assert out == i0 + i1 | ||
|
||
''' | ||
import pysmt | ||
from pysmt import shortcuts as sc | ||
with sc.Solver('z3') as s: | ||
s.add_assertion((out != i0 + i1).value) | ||
if s.solve(): | ||
print("Counter example found") | ||
else: | ||
print("Verified add") | ||
''' |