Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
System verilog Systemverilog覆盖点,用于n的倍数_System Verilog - Fatal编程技术网

System verilog Systemverilog覆盖点,用于n的倍数

System verilog Systemverilog覆盖点,用于n的倍数,system-verilog,System Verilog,我正在尝试在我的覆盖率组中创建一个bin,以对n的倍数进行采样,在我的案例15中,n是一个常量整数。到目前为止,我已经来了 生成以下代码: class rx_port; int unsigned rx_rates[]; ... covergroup rx_cov with function sample (int unsigned rate); coverpoint rate{ bins no_rate

我正在尝试在我的覆盖率组中创建一个bin,以对n的倍数进行采样,在我的案例15中,n是一个常量整数。到目前为止,我已经来了 生成以下代码:

class rx_port;
      int unsigned rx_rates[];
      ...
      covergroup rx_cov with function sample (int unsigned rate);
           coverpoint rate{
               bins no_rate    = {0};
               bins mul_of_15  = {SOME_PRE_DEFINED_PATTERN};
           }
      endgroup;
      ....
endclass

其中一些预先定义的模式是从0到系统宏的整数数组,步长为15。我不确定这是否是生成此垃圾箱的正确/最佳方法。有更好的建议吗?

写一些帮助函数怎么样:

module FIFTEEN;

  class rx_port;

    typedef enum {IS_ZERO, IS_DIVISIBLE_BY_15, IS_NOT_DIVISIBLE_BY_15} rate_type;

    function new;
      rx_cov=new;
    endfunction

    local function rate_type covergroup_helper(input int unsigned i);
      if (i==0)    return IS_ZERO;
      if (i%15==0) return IS_DIVISIBLE_BY_15;
      return IS_NOT_DIVISIBLE_BY_15;
    endfunction

    function sample (input int unsigned i);
      rx_cov.sample(covergroup_helper(i));
    endfunction

    covergroup rx_cov with function sample (rate_type rate);
      coverpoint rate;
    endgroup;
  endclass

  rx_port R = new;

  initial
    begin
      void'(R.sample(0));
      void'(R.sample(30));
      void'(R.sample(31));
      $display("coverage R.rx_cov.get_coverage= %f", R.rx_cov.get_coverage);
    end

endmodule

在这里,我编写了一个函数来确定它的输入是否可以被15整除,还有一个函数调用它来进行采样。您可以将这些功能组合在一起,但我喜欢我的示例中的分工

事实证明有更好的方法:

module FIFTEEN;

  class rx_port;

    function new;
      rx_cov=new;
    endfunction

    function sample (input int unsigned i);
      rx_cov.sample(i);
    endfunction

    covergroup rx_cov with function sample (int unsigned rate);
      coverpoint rate { 
        bins IS_ZERO                = {0}; 
        bins IS_DIVISIBLE_BY_15     = {[1:$]} with ((item % 15)==0); 
        bins IS_NOT_DIVISIBLE_BY_15 = {[1:$]} with ((item % 15)!=0); 
      }
    endgroup;
  endclass

  rx_port R = new;

  initial
    begin
      void'(R.sample(0));
      void'(R.sample(30));
      void'(R.sample(31));
      $display("coverage R.rx_cov.get_coverage= %f", R.rx_cov.get_coverage);
    end

endmodule
可以使用与来指定存储箱。所以

bins IS_DIVISIBLE_BY_15     = {[1:$]} with ((item % 15)==0); 
提供一个bin,只要该值可被15整除,而不是0和0整除,该bin就会被命中

bins IS_NOT_DIVISIBLE_BY_15 = {[1:$]} with ((item % 15)!=0); 
为您提供一个当值不能被15整除时命中的箱子