Skip to content

Commit

Permalink
Queues: more if then else (#1791)
Browse files Browse the repository at this point in the history
* FIFO without ifthenelse

* More ITE, less seq in FIFO

* PIFO futil unaltered

* Fewer seqs

* All but the big par

* More ifthenelse in PIFO

* PIFO tree with more ITE and less seqs

* SDN with fewer seqs, more ITE

* Static SDN with more ITE, fewer seqs

* Unused groups

* Revert FIFO and PIFO to get it to work

* Some small changes that still work...

* Another improvement

* Another par bites the dust

* Another one gone

* Another one gone

* Another seq bites the dust, yeah

* Regerate all queue futils

* Queues: more `par`s when possible (#1793)

* Some seqs could have been pars

* More opportunities in PIFO

* Other files benefit without any change needed

* Committing these was a bad idea

* Regernate queue futils

* Remove futil files
  • Loading branch information
anshumanmohan committed Nov 28, 2023
1 parent 58914de commit 89e644f
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 268 deletions.
56 changes: 26 additions & 30 deletions calyx-py/calyx/queue_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,34 @@ def insert_main(prog, queue):
i_lt_max_cmds = main.lt_use(i.out, queue_util.MAX_CMDS)
not_err = main.not_use(err.out)

main.control += [
cb.while_with(
i_lt_max_cmds, # Run while i < MAX_CMDS
[
read_cmd,
write_cmd_to_reg, # `cmd := commands[i]`
read_value,
write_value_to_reg, # `value := values[i]`
cb.invoke( # Invoke the queue.
queue,
in_cmd=cmd.out,
in_value=value.out,
ref_ans=ans,
ref_err=err,
),
main.control += cb.while_with(
i_lt_max_cmds, # Run while i < MAX_CMDS
[
read_cmd,
write_cmd_to_reg, # `cmd := commands[i]`
read_value,
write_value_to_reg, # `value := values[i]`
cb.invoke( # Invoke the queue.
queue,
in_cmd=cmd.out,
in_value=value.out,
ref_ans=ans,
ref_err=err,
),
cb.if_with(
not_err,
cb.if_with(
not_err,
cmd_le_1, # If the command was a pop or peek,
[
cb.if_with(
cmd_le_1, # If the command was a pop or peek,
[
write_ans, # Write the answer to the answer list
incr_j, # And increment the answer index.
],
),
write_ans, # Write the answer to the answer list
incr_j, # And increment the answer index.
],
),
lower_err, # Lower the error flag
incr_i, # Increment the command index
],
),
]
),
lower_err, # Lower the error flag
incr_i, # Increment the command index
],
)

return main

Expand Down Expand Up @@ -206,8 +202,8 @@ def insert_runner(prog, queue, name, stats_component):
[
cb.if_with(
cmd_le_1, # If the command was a pop or peek
[raise_has_ans], # then raise the `has_ans` flag
[lower_has_ans], # else lower the `has_ans` flag
raise_has_ans, # then raise the `has_ans` flag
lower_has_ans, # else lower the `has_ans` flag
),
],
),
Expand Down
100 changes: 49 additions & 51 deletions calyx-py/test/correctness/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,63 +64,61 @@ def insert_fifo(prog, name):
mem, ans, "read_payload_from_mem_phase2"
)

fifo.control += [
cb.par(
# Was it a pop or a push? We can do both cases in parallel.
fifo.control += cb.par(
# Was it a pop or a push? We can do both cases in parallel.
cb.if_with(
# Did the user call pop?
cmd_eq_0,
cb.if_with(
# Did the user call pop?
cmd_eq_0,
cb.if_with(
# Yes, the user called pop. But is the queue empty?
len_eq_0,
[raise_err, flash_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.
read_incr, # Increment the read pointer.
cb.if_with(
# Wrap around if necessary.
read_eq_max_queue_len,
flash_read,
),
len_decr, # Decrement the length.
],
),
# Yes, the user called pop. But is the queue empty?
len_eq_0,
cb.par(raise_err, flash_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.
read_incr, # Increment the read pointer.
cb.if_with(
# Wrap around if necessary.
read_eq_max_queue_len,
flash_read,
),
len_decr, # Decrement the length.
],
),
cb.if_with(
# Did the user call peek?
cmd_eq_1,
cb.if_with( # Yes, the user called peek. But is the queue empty?
len_eq_0,
[raise_err, flash_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_with(
# Did the user call peek?
cmd_eq_1,
cb.if_with( # Yes, the user called peek. But is the queue empty?
len_eq_0,
cb.par(raise_err, flash_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_with(
# Did the user call push?
cmd_eq_2,
cb.if_with(
# Did the user call push?
cmd_eq_2,
cb.if_with(
# Yes, the user called push. But is the queue full?
len_eq_max_queue_len,
[raise_err, flash_ans], # The queue is full: overflow.
[ # The queue is not full. Proceed.
write_to_mem, # Write `value` to the queue.
write_incr, # Increment the write pointer.
cb.if_with(
# Wrap around if necessary.
write_eq_max_queue_len,
flash_write,
),
len_incr, # Increment the length.
],
),
# Yes, the user called push. But is the queue full?
len_eq_max_queue_len,
cb.par(raise_err, flash_ans), # The queue is empty: underflow.
[ # The queue is not full. Proceed.
write_to_mem, # Write `value` to the queue.
write_incr, # Increment the write pointer.
cb.if_with(
# Wrap around if necessary.
write_eq_max_queue_len,
flash_write,
),
len_incr, # Increment the length.
],
),
),
]
)

return fifo

Expand Down
Loading

0 comments on commit 89e644f

Please sign in to comment.