sv中关于coverage的写法

1. covergroup 。能够define在module,program,interface和class中。格式跟class类似,使用的时候需要new()。它可以定义为portlist的group,同时还可以加上event。比较简单的格式如下 

enum {reg,green,blue} color;

covergroup cg1 @(posedge clk);

   c: coverpoint color;

endgroup

cg cg_inst=new();其中cg_inst是cg的一个例化。 

covergroup里面可以定义的东西有coverage_spec(包括coverpoint和cover_cross) coverage_option.

首先说一下coverpoint。里面包含很多bin(容器)。bin里存放要采样的数据或者要传输的值。采到了值就成为cover到了这个值(自己理解)。bin的种类有bins,illegal_bins, ignore_bins

iff是个条件判断,一般用来判断什么情况下去cover设置的bin或者遇到的某种情况。

举例:

bit [4:1] v_a;

covergroup cg @(posedge clk);

    coverpoint v_a

    {

      bins sa = (4=>5=>6),([7:9],10=>11,12);//sa:4=>5=>6,or 7=>11,8=>11,9=>11,10=>11,7=>12.........

      bins sb [] =(4=>5=>6),([7:9],10 =>11,12);//sa[4=>5=>6],sa[7=>11],sa[8=>11]......

      bins allother = default sequence;//the bins allother tracks all other transitions that are not covered by the other bins: sa and sb.

}

   coverpoint c @(posedge clk);

{  

   bin a=(1,5 =>6,7);//1=>6,1=>7,5=>6,5=>7

   bin b=3 [*5];//3=>3=>3=>3=>3=>3

   bin c=3 [*3:5];//3=>3=>3,3=>3=>3=>3, 3=>3=>3=>3=>3

   bin d= 3 [-> 3];//......3=>......=>3......=>3总共出现3次

   bin e = 3 [= 2];//3=>...=>3....=>3

   coverpoint b

   {

      wildcard bins g12_16 = {4'b11??};//1100,1101,1110,1111

}

endgroup

exclude bins 的使用,ignored bins 会被整个coverage excluded掉。,ignored values or transitions are excluded 即使在其他bin里面定义过,也就是说在某些情况下实在是盖不到的点可以被exclude掉。

covergroup cg23;

   coverpoint a

   { 

      ignore_bins ignore_vals = {7,8};

      ignore_bins ignore_trans = (1=>3=>5);

   }

endgroup

covergroup c;

 coverpoint b

{

    illegal_bins bad_vals = {1,2,3};

   illegal_bins bad_trans = (4=>5=>6);//设置illegal的bins并exclude掉,可以判断run-time的error。

}

endgroup

其次说一下covercross。举例说明。cross一般指的是两个bins的范围交叉的情况。如下 a和b交叉会出现4×4=16种随机。binsof (a)intersect {[1:100]}指的是在1~100内的a

bit [7:0] v_a, v_b;

covergroup cg @(posedge clk);

a: coverpoint v_a

  bins a1 = {[0:63]};

  bins a2 = {[64:127]};

  bins a3 = {[128:191]};

  bins a4 = {[192:255]};

}

b: coverpoint v_b

{

 bins b1 = {0};

 bins b2 = {[1:84]};

 bins b3 = {[85:169]};

 bins b4 = {[170:255]};

}

c: cross v_a,v_b

{

  bins c1= ! binsof(a) intersect {[100:200]};// a不与[100:200]这个范围交叉。所有总共有(a1,b1)(a1,b2)(a1,b3),(a1,b4)总共4种情况

  bins c2= binsof(a.a2) || binsof(b.b2);//(a2,b1),(a2,b2),(a2,b3),(a2,b4),(a1,b2),(a3,b2),(a4,b2)

  bins c3= binsof(a.a1) && binsof(b.b4);//(a1,b4)

}

endgroup

ignore & illegal cross bins

covergroup yy;

cross a,b

{

   ignore_bins foo = binsof(a) intersect {[5:13]};//ignored bins are excluded

}

cross x,y

{

 illegal_bins foo = binsof(y) intersect {bad};//illegal bins are excluded but send run-time error.

}

endgroup

再次说一下coverage_option.option控制着covergroup,coverpoint和cross的行为。有两种类型的option。第一种叫做specific to an instance of a covergroup. 第二种叫做specify an option for the covergroup type as a whole.下面举例说明这些option的使用。

per_instance参数:指定单个实例的覆盖率,在covergroup中定义option.per_instance=1

comment:增加注释。一般使用在per_instance定义之后。option.comment="ooooo";

cross_num_print_missing:打印空仓,没有覆盖到的仓。option.cross_num_print_missing=1000;

goal:指定覆盖率的目标,一般不会去改。默认100%。option.goal=90;

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值