这两个计数器有什么区别?
What is the difference between these 2 counters?
如果这两个语句在 always_ff @(posedge clk)
中,它们之间有什么区别
if(~Intf.DataFull) begin
rWrPageCntr <= rWrPageCntr - 1;
end
对
rWrPageCntr <= rWrPageCntr - ~Intf.DataFull;
在以下关于信号位宽的假设下,有很大的不同:
module tb;
bit DataFull, clk;
bit [2:0] rWrPageCntr;
bit [2:0] rWrPageCntr2;
always #5 clk++;
always_ff @(posedge clk)
if(~DataFull) begin
rWrPageCntr <= rWrPageCntr - 1;
end
always_ff @(posedge clk)
rWrPageCntr2 <= rWrPageCntr2 - ~DataFull;
always @(negedge clk) $display("full=%b %d %d", DataFull, rWrPageCntr, rWrPageCntr2);
initial begin
DataFull = 1;
#150;
DataFull = 0;
#150 $finish;
end
endmodule
输出:
full=1 0 2
full=1 0 4
full=1 0 6
full=1 0 0
full=1 0 2
full=1 0 4
full=1 0 6
full=1 0 0
full=1 0 2
full=1 0 4
full=1 0 6
full=1 0 0
full=1 0 2
full=1 0 4
full=0 0 6
full=0 7 7
full=0 6 0
full=0 5 1
full=0 4 2
full=0 3 3
full=0 2 4
full=0 1 5
full=0 0 6
full=0 7 7
full=0 6 0
full=0 5 1
full=0 4 2
full=0 3 3
full=0 2 4
第一个示例的行为符合您的预期,但第二个示例更为复杂。
在您的第二个示例中,在减法之前,DataFull
将扩展为 3 位,然后按位反转,产生 7 和 6。当 DataFull
=0 时,~DataFull
=7。当DataFull
=1时,~DataFull
=6.
除了功能差异外,具有启用条件的示例将允许工具执行时钟门控。另一个示例需要额外的逻辑,从而导致更大的面积和功耗。
如果这两个语句在 always_ff @(posedge clk)
if(~Intf.DataFull) begin
rWrPageCntr <= rWrPageCntr - 1;
end
对
rWrPageCntr <= rWrPageCntr - ~Intf.DataFull;
在以下关于信号位宽的假设下,有很大的不同:
module tb;
bit DataFull, clk;
bit [2:0] rWrPageCntr;
bit [2:0] rWrPageCntr2;
always #5 clk++;
always_ff @(posedge clk)
if(~DataFull) begin
rWrPageCntr <= rWrPageCntr - 1;
end
always_ff @(posedge clk)
rWrPageCntr2 <= rWrPageCntr2 - ~DataFull;
always @(negedge clk) $display("full=%b %d %d", DataFull, rWrPageCntr, rWrPageCntr2);
initial begin
DataFull = 1;
#150;
DataFull = 0;
#150 $finish;
end
endmodule
输出:
full=1 0 2
full=1 0 4
full=1 0 6
full=1 0 0
full=1 0 2
full=1 0 4
full=1 0 6
full=1 0 0
full=1 0 2
full=1 0 4
full=1 0 6
full=1 0 0
full=1 0 2
full=1 0 4
full=0 0 6
full=0 7 7
full=0 6 0
full=0 5 1
full=0 4 2
full=0 3 3
full=0 2 4
full=0 1 5
full=0 0 6
full=0 7 7
full=0 6 0
full=0 5 1
full=0 4 2
full=0 3 3
full=0 2 4
第一个示例的行为符合您的预期,但第二个示例更为复杂。
在您的第二个示例中,在减法之前,DataFull
将扩展为 3 位,然后按位反转,产生 7 和 6。当 DataFull
=0 时,~DataFull
=7。当DataFull
=1时,~DataFull
=6.
除了功能差异外,具有启用条件的示例将允许工具执行时钟门控。另一个示例需要额外的逻辑,从而导致更大的面积和功耗。