From 7c01143f7844a8751e49f1c2365bd06ec292081d Mon Sep 17 00:00:00 2001 From: Anshuman Mohan Date: Thu, 27 Jul 2023 11:55:15 -0400 Subject: [PATCH] Make room for cmd = 1 to have its own meaning --- calyx-py/calyx/builder_util.py | 16 ++++++++++++++++ calyx-py/test/correctness/fifo.py | 16 +++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/calyx-py/calyx/builder_util.py b/calyx-py/calyx/builder_util.py index 13086f580b..14c961a063 100644 --- a/calyx-py/calyx/builder_util.py +++ b/calyx-py/calyx/builder_util.py @@ -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}. + + = std_gt(); + ... + comb group _group { + .left = ; + .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}. diff --git a/calyx-py/test/correctness/fifo.py b/calyx-py/test/correctness/fifo.py index 50c16d0df8..8c4132b263 100644 --- a/calyx-py/test/correctness/fifo.py +++ b/calyx-py/test/correctness/fifo.py @@ -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) @@ -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 @@ -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, @@ -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)