【问题标题】:What is the difference between these 2 counters?这两个计数器有什么区别?
【发布时间】:2020-06-16 20:49:36
【问题描述】:

如果这两个语句在always_ff @(posedge clk) 中,它们有什么区别

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

rWrPageCntr               <= rWrPageCntr - ~Intf.DataFull;

【问题讨论】:

    标签: verilog system-verilog hdl


    【解决方案1】:

    在以下关于信号位宽的假设下,存在很大差异:

    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。

    【讨论】:

      【解决方案2】:

      除了功能差异之外,具有启用条件的示例将允许工具执行时钟门控。另一个示例需要额外的逻辑,从而导致更大的面积和功耗。

      【讨论】:

        猜你喜欢
        • 2021-12-15
        • 1970-01-01
        • 2010-12-24
        • 1970-01-01
        • 2012-06-12
        • 2016-10-06
        • 1970-01-01
        相关资源
        最近更新 更多