System verilog on Quartus synthesis issue

synthesissynthesizersystem-verilog

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

enter image description here

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.

enter image description here

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

y=x|c;
x=a&b;

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:

y<=x|c;
x<=a&b;

However, when you write

x=a&b;
y=x|c;

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:

x<=a&b;
y<=(a&b)|c;

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.