module blockingbad(input logic clk,a,b,c,output logic y);
logic x;
always_ff @(posedge clk) begin
y=x|c;
x=a&b;
end
endmodule
For the above Sysverilog snippet, the quartus 13.1 synthesizes a netlist shown above.
But when I interchange the ordering of calculation of y and x, I get a synthesized netlist shown below.
Why exactly am I getting a different netlist? I know it has got to do with the blocking assignment "=" but I can't understand the change in number of flip flops. Can anybody explain it to me.
Thanks
Best Answer
When you type
it means that you want to calculate y = x|c, then you want to set x to a&b. Since this must be implemented with gates, the old value of x must be stored until the end of the clock cycle, hence the extra flip-flop. If you rewrote this with nonblocking assignments, you would do:
However, when you write
it means calculate x, then calculate y with the new value of x. If you wanted to implement this with nonblocking assignments, you would do:
You could also use an assign statement to set x earlier, or mix a blocking and a nonblocking assignment. In this case, if the registered x value is never used, the flip flop will be deleted automatically by the optimizer.