Skip to content

Commit

Permalink
Make room for cmd = 1 to have its own meaning
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanmohan committed Jul 27, 2023
1 parent 573b12a commit 7c01143
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 16 additions & 0 deletions calyx-py/calyx/builder_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ def insert_lt(comp: cb.ComponentBuilder, left, right, cellname, width):
return insert_comb_group(comp, left, right, lt_cell, f"{cellname}_group")


def insert_gt(comp: cb.ComponentBuilder, left, right, cellname, width):
"""Inserts wiring into component {comp} to check if {left} > {right}.
<cellname> = std_gt(<width>);
...
comb group <cellname>_group {
<cellname>.left = <left>;
<cellname>.right = <right>;
}
Returns handles to the cell and the combinational group.
"""
gt_cell = comp.gt(cellname, width)
return insert_comb_group(comp, left, right, gt_cell, f"{cellname}_group")


def insert_add(comp: cb.ComponentBuilder, left, right, cellname, width):
"""Inserts wiring into component {comp} to compute {left} + {right}.
Expand Down
16 changes: 9 additions & 7 deletions calyx-py/test/correctness/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def insert_fifo(prog, name):
"""

fifo: cb.ComponentBuilder = prog.component(name)
cmd = fifo.input("cmd", 32) # If this is 0, we pop. Otherwise, we push the value.
cmd = fifo.input("cmd", 32)
# If this is 0, we pop. If it is 1, we peek. Otherwise, we push the value.

mem = fifo.seq_mem_d1("mem", 32, 10, 32)

Expand All @@ -65,9 +66,9 @@ def insert_fifo(prog, name):

# Cells and groups to compute equality
cmd_eq_0 = util.insert_eq(fifo, cmd, 0, "cmd_eq_0", 32) # `cmd` == 0
cmd_neq_0 = util.insert_neq(
fifo, cmd, cb.const(32, 0), "cmd_neq_0", 32
) # `cmd` != 0
# cmd_eq_1 = util.insert_eq(fifo, cmd, 1, "cmd_eq_1", 32) # `cmd` == 1
cmd_gt_1 = util.insert_gt(fifo, cmd, 1, "cmd_gt_1", 32) # `cmd` > 1

write_eq_10 = util.insert_eq(
fifo, write.out, 10, "write_eq_10", 32
) # `write` == 10
Expand Down Expand Up @@ -129,8 +130,8 @@ def insert_fifo(prog, name):
),
cb.if_(
# Did the user call push?
cmd_neq_0[0].out,
cmd_neq_0[1],
cmd_gt_1[0].out,
cmd_gt_1[1],
cb.if_(
# Yes, the user called push. But is the queue full?
len_eq_10[0].out,
Expand Down Expand Up @@ -165,7 +166,8 @@ def insert_main(prog):
# - a list of commands (the input)
# where each command is a 32-bit unsigned integer, with the following format:
# `0`: pop
# any other value: push that value
# `1`: peek
# any value greater than 1: push that value
# - a list of answers (the output).
commands = main.seq_mem_d1("commands", 32, 15, 32, is_external=True)
ans_mem = main.seq_mem_d1("ans_mem", 32, 10, 32, is_external=True)
Expand Down

0 comments on commit 7c01143

Please sign in to comment.