Z80
Full Member level 1
Here at work I have been taught to use this coding style in Verilog...
Whenever possible, exclusively define combinational logic in combinational always blocks and use only one sequential always block that only thing it does is pass the outputs from the combinational logic in the output flip-flops.
Let me take an example to clarify what I am trying to say.
Rather than writing:
always @(posedge clk)
...if (x == 1'b1)
...begin
......out1 = a & b;
......out2 = c | d;
...end
...else
...begin
......out1 = a + b;
......out2 = c - d;
...end
write like this
// this always only controls out1_input and nothing else
always @(a or b)
...if (x == 1'b1)
......out1_input = a & b;
...else
......out1_input = a + b;
// always only controls out2_input and nothing else
always @(c or d)
...if (x == 1'b1)
......out2_input = c | d;
...else
......out2_input = c - d;
// no combinational logic here, only load outputs
// from combinational logic in output flip-flops
always @(posedge clk)
begin
...out1 = out1_input;
...out2 = out2_input;
end
Now my question: Is this style efficient? I haven't seen Verilog code that respects this and I wonder if it isn't too restrictive from the synthesis point of view.
Edit: I have replaced dots with spaces for readability because the forum strips spaces
Whenever possible, exclusively define combinational logic in combinational always blocks and use only one sequential always block that only thing it does is pass the outputs from the combinational logic in the output flip-flops.
Let me take an example to clarify what I am trying to say.
Rather than writing:
always @(posedge clk)
...if (x == 1'b1)
...begin
......out1 = a & b;
......out2 = c | d;
...end
...else
...begin
......out1 = a + b;
......out2 = c - d;
...end
write like this
// this always only controls out1_input and nothing else
always @(a or b)
...if (x == 1'b1)
......out1_input = a & b;
...else
......out1_input = a + b;
// always only controls out2_input and nothing else
always @(c or d)
...if (x == 1'b1)
......out2_input = c | d;
...else
......out2_input = c - d;
// no combinational logic here, only load outputs
// from combinational logic in output flip-flops
always @(posedge clk)
begin
...out1 = out1_input;
...out2 = out2_input;
end
Now my question: Is this style efficient? I haven't seen Verilog code that respects this and I wonder if it isn't too restrictive from the synthesis point of view.
Edit: I have replaced dots with spaces for readability because the forum strips spaces