这2个计数器有什么区别?

问题描述 投票:0回答:2

如果这两个语句是在一个叫作 "C "的语句里面,那么这两个语句有什么区别?always_ff @(posedge clk)

if(~Intf.DataFull) begin
   rWrPageCntr                <= rWrPageCntr - 1;
end

rWrPageCntr               <= rWrPageCntr - ~Intf.DataFull;
verilog system-verilog hdl
2个回答
0
投票

在下面的假设下,有很大的区别。

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.


0
投票

除了功能上的差异外,带有使能条件的例子可以让工具执行时钟门控。而另一个例子则需要额外的逻辑,导致面积和功耗增加。

© www.soinside.com 2019 - 2024. All rights reserved.