Skip to content

Commit

Permalink
Peek command
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanmohan committed Jul 27, 2023
1 parent 7c01143 commit edc09bd
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion calyx-py/test/correctness/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ 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_eq_1 = util.insert_eq(fifo, cmd, 1, "cmd_eq_1", 32) # `cmd` == 1
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(
Expand Down Expand Up @@ -128,6 +128,21 @@ def insert_fifo(prog, name):
],
),
),
cb.if_(
# Did the user call peek?
cmd_eq_1[0].out,
cmd_eq_1[1],
cb.if_( # Yes, the user called peek. But is the queue empty?
len_eq_0[0].out,
len_eq_0[1],
[raise_err, zero_out_ans], # The queue is empty: underflow.
[ # The queue is not empty. Proceed.
read_from_mem, # Read from the queue.
write_to_ans, # Write the answer to the answer register.
# But don't increment the read pointer or change the length.
],
),
),
cb.if_(
# Did the user call push?
cmd_gt_1[0].out,
Expand Down

0 comments on commit edc09bd

Please sign in to comment.