Skip to content

Commit

Permalink
Added demo scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-melchert committed Nov 1, 2024
1 parent 1b1690c commit 0dcb2e5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
Empty file modified apex_demo.sh
100644 → 100755
Empty file.
7 changes: 6 additions & 1 deletion canal_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

num_tracks = 5

# Create dictionary of input nodes
input_nodes = {}
for side in SwitchBoxSide:
input_nodes[side] = []
for track in range(num_tracks):
input_nodes[side].append(SwitchBoxNode(0, 0, track, 16, side, SwitchBoxIO.SB_IN))

# Create dictionary of output nodes
output_nodes = {}
for side in SwitchBoxSide:
output_nodes[side] = []
for track in range(num_tracks):
output_nodes[side].append(SwitchBoxNode(0, 0, track, 16, side, SwitchBoxIO.SB_OUT))

# Wire up input nodes to output nodes
for track in range(num_tracks):
for side_from in SwitchBoxSide:
for side_to in SwitchBoxSide:
Expand All @@ -22,4 +25,6 @@
input_node = input_nodes[side_from][track]
output_node = output_nodes[side_to][track]
print(f"Wire {input_node} -> {output_node}")
input_node.add_edge(output_node)
input_node.add_edge(output_node)


Empty file modified cascade_demo.sh
100644 → 100755
Empty file.
30 changes: 30 additions & 0 deletions hwtypes_demo.py
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))
'''

40 changes: 40 additions & 0 deletions peak_demo.py
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")
'''

0 comments on commit 0dcb2e5

Please sign in to comment.