Skip to content

Commit

Permalink
Implement std_mult_pipe (#1945)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayakayorihiro authored Mar 3, 2024
1 parent 9311f5f commit 4bc3007
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tools/firrtl/generate-firrtl-with-primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def generate_replacement_map(inst):
elif inst["name"] == "std_lsh":
width = replacement_map["WIDTH"]
replacement_map["BITS"] = math.ceil(math.log(width, 2)) + 1
elif inst["name"] == "std_mult_pipe":
width = replacement_map["WIDTH"]
replacement_map["W_SHIFTED_ONE"] = width << 1
replacement_map["HIGH"] = width - 1
replacement_map["LOW"] = 0


return replacement_map

Expand Down
2 changes: 1 addition & 1 deletion tools/firrtl/templates/std_ge.fir
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
input right : UInt<WIDTH>
output out : UInt<1>

out <= ge(left, right)
out <= geq(left, right)
2 changes: 1 addition & 1 deletion tools/firrtl/templates/std_le.fir
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
input right : UInt<WIDTH>
output out : UInt<1>

out <= le(left, right)
out <= leq(left, right)
49 changes: 49 additions & 0 deletions tools/firrtl/templates/std_mult_pipe.fir
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module std_mult_pipe_WIDTH :
input left : UInt<WIDTH>
input right : UInt<WIDTH>
input reset : UInt<1>
input go : UInt<1>
input clk : Clock
output out : UInt<WIDTH>
output done : UInt<1>

reg rtmp : UInt<WIDTH>, clk
reg ltmp : UInt<WIDTH>, clk
reg out_tmp : UInt<W_SHIFTED_ONE>, clk
reg done_buf : UInt<1>[2], clk

; Start sending the done signal.
when eq(go, UInt(1)):
done_buf[0] <= UInt(1)
else:
done_buf[0] <= UInt(0)

; Push the done signal through the pipeline.
when eq(go, UInt(1)):
done_buf[1] <= done_buf[0]
else:
done_buf[1] <= UInt(0)

; Register the inputs
when eq(reset, UInt(1)):
ltmp <= UInt(0)
rtmp <= UInt(0)
else:
when eq(go, UInt(1)):
ltmp <= left
rtmp <= right
else:
ltmp <= UInt(0)
rtmp <= UInt(0)

; Compute the output and save it to out_tmp
when eq(reset, UInt(1)):
out_tmp <= UInt(0)
else:
when eq(go, UInt(1)):
out_tmp <= mul(ltmp, rtmp)
else:
out_tmp <= out_tmp

out <= bits(out_tmp, HIGH, LOW)
done <= done_buf[1]

0 comments on commit 4bc3007

Please sign in to comment.