Open hirooih opened 3 years ago
I tried to send the pull request of the fix on https://github.com/lowRISC/style-guides/pull/44/commits/957948ec27a580aa4f12a371c8dd6291e8b732ac. But something wrong... Sorry.
I was pointed to this conversation by a colleague. My thinking about this is along these lines:
The general rules (for flop-based designs) are: D1. State element updates are edge triggered on a clock and assigns must be NB D2. Combinational logic are always blocking. D3. Do not use delays (recommendation for cleanliness and avoidance of simulation-synthesis mismatch)
With these rules in place, I believe you should create all your clocks using blocking assigns. This forces all clock events into the active region and all state updates into the NB region, guaranteed to be after all clocks update.
I believe this is what you're proposing, i.e. to add a style guide statement that all clocks should be generated using blocking assigns. I think that perhaps the wording needs to be clearer and the reason made explicit.
@rich-ho, thank you for you comment.
I believe this is what you're proposing,
Yes.
In either case we need an example code of clock divider for readers.
I'm sorry I left this PR for a long time.
I've push update, but something wrong.
This branch cannot be rebased due to conflicts Only those with write access to this repository can merge pull requests.
I did "git rebase". Is it the cause?
Sorry for my mess.
Let me propose this again. It gets longer, but I hope this let you understand.
We have the following rule;
This rule does not work with a divided clock.
The following code demonstrates the issue.
q_nb_ng and q_b_ok are D-Flip-flops clocked by divided clocks. They capture the output value of d.
The following is the simulation result of the sample code above.
q_b_ok works as we expect, but q_nb_ok does not. For example at the timing on the yellow line they have to capture value 0b0010 as q_b_ok does.
The following shows how they works on the yellow line.
This is not the behavior expected. (cf. LRM 2017 Figure 4-1—Event scheduling regions)
Plan B: Use
#delay
for all FFs (when we have a divided clock)Many engineers are choosing this solution. But we know this degrades simulation performance.
Plan C: Use
#delay
for FFs clocked by divided clock and capture signals derived from FFs clocked by the original clock.This may be better performance than plan B, but very easy to cause bugs.
I should create a branch after fetching updated upstream. Sorry.