Skip to content

Commit

Permalink
[Calyx-FIRRTL] Debugged FIRRTL implementations of primitives (#1907)
Browse files Browse the repository at this point in the history
* Debug std_reg FIRRTL implementation

* Fix std_const template typo

* Fix std_lsh FIRRTL primitive

* Fixed std_reg bug that was causing  to fail
  • Loading branch information
ayakayorihiro authored Feb 7, 2024
1 parent 40d6532 commit e7b1fbb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
6 changes: 5 additions & 1 deletion tools/firrtl/generate-firrtl-with-primitives.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import math
import os
import sys

Expand All @@ -13,6 +14,9 @@ def generate_replacement_map(inst):
replacement_map["DIFF"] = replacement_map["OUT_WIDTH"] - replacement_map["IN_WIDTH"]
elif inst["name"] == "std_slice":
replacement_map["DIFF"] = replacement_map["IN_WIDTH"] - replacement_map["OUT_WIDTH"]
elif inst["name"] == "std_lsh":
width = replacement_map["WIDTH"]
replacement_map["BITS"] = math.ceil(math.log(width, 2)) + 1

return replacement_map

Expand Down Expand Up @@ -62,4 +66,4 @@ def main():
generate(sys.argv[1], sys.argv[2])

if __name__ == '__main__':
main()
main()
2 changes: 1 addition & 1 deletion tools/firrtl/templates/std_const.fir
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module std_const_WIDTH_VAL :
module std_const_WIDTH_VALUE :
output out : UInt<WIDTH>
out <= UInt(VALUE)
2 changes: 1 addition & 1 deletion tools/firrtl/templates/std_lsh.fir
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
input right : UInt<WIDTH>
output out : UInt<WIDTH>

out <= dshl(left, right)
out <= dshl(left, bits(right, BITS, 0))
20 changes: 12 additions & 8 deletions tools/firrtl/templates/std_reg.fir
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
output done : UInt<1>

reg internal_reg : UInt<WIDTH>, clk
out <= UInt(0)
when eq(write_en, UInt(1)):
out <= in
done <= UInt(1)
reg done_reg : UInt<1>, clk

when eq(reset, UInt(1)):
internal_reg <= UInt(0)
done_reg <= UInt(0)
else:
when eq(reset, UInt(1)):
done <= UInt(0)
out <= UInt(0)
when eq(write_en, UInt(1)):
internal_reg <= in
done_reg <= UInt(1)
else:
done <= UInt(0)
done_reg <= UInt(0)

out <= internal_reg
done <= done_reg

0 comments on commit e7b1fbb

Please sign in to comment.