1

I am wondering if it is OK to replace flip flop resets with the ternary operator to minimize line count and improve readability. Does the RTL below have the same effect in simulation and synthesis?

always_ff @(posedge clk, posedge ares) begin
   if (ares) begin
      signal <= a;
   end
   else begin
      signal <= b;
   end 
end

compared with:

always_ff @(posedge clk, posedge ares) begin
   signal <= ares ? a : b;
end

How about for the case of synchronous reset?

1
  • 1
    I would challenge the assertion that this improves readability. The first version is the de facto standard way to infer a flip-flop. If I saw your your method in some code I would have to spend some extra time trying to figure out what you were trying to do. Maybe it is better, but it is too late to establish a new standard. Commented Apr 29, 2023 at 19:43

1 Answer 1

2

You should expect both versions of your code to simulate the same way.

Synthesis results are likely to be dependent upon the tool you are using. The code example with the if/else maps to a conventional synthesis construct for a flip flop (if a is a constant, like a parameter). The code example with the ternary may not be supported by synthesis tools. Refer to your synthesis tool documentation to see what Verilog code patterns are allowed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.