Add behavioral verilog output#9539
Conversation
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature to generate a behavioral Verilog model for the RAM. The implementation is largely correct, but I've identified a critical bug in the address width calculation for an edge case that would lead to invalid Verilog. Additionally, I've provided suggestions to enhance code style consistency, aligning with repository guidelines, and to refine the formatting of the generated output.
src/ram/src/ram.cpp
Outdated
| } | ||
|
|
||
| const int word_size_bit = bytes_per_word * 8; | ||
| const int address_width = std::ceil(std::log2(word_count)); |
There was a problem hiding this comment.
The calculation of address_width is incorrect when word_count is 1. In this case, std::log2(1) is 0, so address_width becomes 0. This leads to address_width - 1 being -1, resulting in an invalid Verilog port declaration like input [-1:0] addr;. The address width should be at least 1.
const int address_width = (word_count <= 1) ? 1 : std::ceil(std::log2(word_count));e99a104 to
84c0f61
Compare
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
84c0f61 to
af4dd47
Compare
remove redundant initializer Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: tnguy19 <114105118+tnguy19@users.noreply.github.com>
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
rovinski
left a comment
There was a problem hiding this comment.
Can you please add a test against the behavioral verilog file, e.g. adding the model for the 8x8 ram as a .vok file?
I also want to talk about making sure the structural model and behavioral model actually match expected behavior when we next meet.
| std::ofstream vf(filename); | ||
| if (!vf.is_open()) { | ||
| logger_->error(RAM, 23, "Unable to open file {}", filename); | ||
| return; | ||
| } | ||
|
|
||
| vf << verilog_code; | ||
| vf.close(); |
There was a problem hiding this comment.
@maliberty isn't there a utility function for writing files? Should that be used here?
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
|
clang-tidy review says "All clean, LGTM! 👍" |
src/ram/test/make_8x8_behavioral.tcl
Outdated
There was a problem hiding this comment.
Does this need to be a separate test? Can't you just add the flag to the make8x8 test?
|
test still requires fixing for CI |
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
rovinski
left a comment
There was a problem hiding this comment.
Go ahead and fix this last item then mark as ready for review.
@maliberty this looks good to me.
There was a problem hiding this comment.
A few notes:
- No indentation for
module - Please name the module the exact same as the block. This will help developers seamlessly swap between the gate-level and behavioral versions.
- Indent ports (D, Q0, etc.)
- Please use 2-space indenting
- Power and ground ports should not be included
- Consistent indentation and spacing
** e.g.for (i=0; i< 1; i = i +1 )-->for (i = 0; i < 1; i = i + 1)
** e.g. no empty line after// read logic
|
CI is still failing though, please make sure everything is up to date. |
…nd .vok files Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
d4d2552 to
576ef0e
Compare
|
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
|
clang-tidy review says "All clean, LGTM! 👍" |
src/ram/src/ram.cpp
Outdated
| std::ofstream vf(filename); | ||
| if (!vf.is_open()) { | ||
| logger_->error(RAM, 23, "Unable to open file {}", filename); | ||
| return; |
There was a problem hiding this comment.
rm - return is unreachable as error will throw
Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
| always @(*) begin | ||
| Q0 = mem[addr]; | ||
| end | ||
|
|
||
| always @(*) begin | ||
| Q1 = mem[addr]; | ||
| end |
There was a problem hiding this comment.
Is this correct? You have two identical read ports using a single address?
There was a problem hiding this comment.
Yes, because the structural verilog code for the ram that the behavioral code generator is based on uses the same address bus shared with all the read ports. So all read ports currently read from the same address
There was a problem hiding this comment.
So a correct description of the hardware but not normal meaning to real ports afaik. @rovinski is this what you intend?
There was a problem hiding this comment.
@tnguy yeah, that's not right. If that's what the structural netlist does, then it's wrong.
There should be an address port per read port. Fix up the behavioral model for now and we'll have to modify the netlist to be correct later.
There was a problem hiding this comment.
Hmmm, I think this raises an issue on the lack of clarity for the tool interface. It is true that there is one write port and two read ports. But it is unclear whether this means that it should be 3 ports total (2 read 1 write) or 2 ports (1 read-write 1 read).
Right now, we only implicitly support 1 write port. I think it should be that there is always 1 read-write port and then additional read ports. In other words, the first addr port is used for both reading and writing, and then any additional ports are only for reading.
If you make this change, then we can mark it done for now and leave an issue to come back to it when more write ports are supported.
There was a problem hiding this comment.
I have added the updated code in 80c67ad, ready for review
There was a problem hiding this comment.
@rovinski you are wanting to merge this with code the writes a behavioral model that doesn't match the hardware generated? That seems confusing/dangerous.
There was a problem hiding this comment.
I am inclined to for now with the goal that the hardware is fixed to match. It didn't occur to me until now that essentially only 1rw memories actually work. Everything else is broken because there is no routine to implement multiple decoders.
Perhaps the ok test should be changed to be 1rw rather than having 2 broken read ports.
There was a problem hiding this comment.
Then let's put in an error if the user selects a broken configuration. I don't want to give misleading results.
…ort per read port and new address write input Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
… read-write port and additional read ports Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
|
@tnguy19 based on conversation, can you please do the following before merge:
|
…ted read_ports value !=1 Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
|
@maliberty I have added the updates in a526f03 code is ready for review |
|
@maliberty CI looks green now, I think this is ready to merge. I added fixing muli-read/write ports as a top priority item in #9392 |
-write_behavioral_verilog [filename]togenerate_ramallowing the user to generate a behavioral verilog file for RAMstorage_cellinMakeCellInst(line 122) to allow use of CLK and GATE pin for flip flop and latch cells@rovinski