Array of cover points in a covergroup

covergroup spctl_hf_intg_cg @(posedge clk);
coverpoint `SPCTL_HF_INTG_INST.u_intg.g_regs[0].u_raw_edgedt.sig {
bins b = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
}
…< many other cover points>
endgroup

I want to write array of cover points using for loop…

Please suggest a way to write in simple terms

coverpoint SPCTL_HF_INTG_INST.u_intg.g_regs[0].u_raw_edgedt.sig { bins b[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824}; } coverpoint SPCTL_HF_INTG_INST.u_intg.g_regs[1].u_raw_edgedt.sig {
bins b = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
}
coverpoint `SPCTL_HF_INTG_INST.u_intg.g_regs[2].u_raw_edgedt.sig {
bins b = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
}
… many more …
writing manually all coverpoints doesn’t seem easy, want to write in simple and concise terms

In reply to kvenkatv: See this link for an easier way to generate the bin/bit encodings.

You cannot create an array of coverpoints each with a different sample array element. What you can do is create an array of covergroup instances each referencing a different array element. If g_regs is a generate block array, you will have to construct each covergroup instance in that generate block, or a seperate generate-for-loop block.

Please post an example code

In reply to kvenkatv:
This should get you started

package global_types;
   typedef bit [31:0] uint;
   typedef uint uint_da[];
endpackage
module bot;
   import global_types::*;
   uint sig;
endmodule
module top;
   import global_types::*;
   bit clk;
   
   uint_da encodings = onehots();
   function uint_da onehots;
      onehots = new[32];
      foreach (onehots[i]) onehots[i] = 32'b1 << i;
   endfunction : onehots
   covergroup cg(ref uint arg)  @(posedge clk);
      option.per_instance = 1;
      coverpoint arg {
	 bins b[] = encodings;
      }
   endgroup : cg
	 	  
  genvar i;
   for (i = 0; i<32;i++) begin : g_regs
      bot u();
   end
   for (i = 0; i<32;i++) begin
      cg cg_inst;
      initial cg_inst = new(g_regs[i].u.sig);
end
endmodule : top

In reply to dave_59:

Can anyone explain the need/application of this type of coverpoint array?

In reply to dave_59:

Hello Dave,

Can you please guide me to know is it possible to write like

covergroup cg(ref bit [3:0]hello.bye); 

   coverpoint hello.bye{
    bins a ...;
    bins b ...;
    ...
    ...
}

I mean to say can we use hierarchical reference in covergroup definition where array of covergroup is implemented. Please guide.

Regards
Sunils

In reply to sunils:
You can never use a “.” when declaring the name of an identifier. In this case, you are declaring the name of an argument to a covergroup constructor.

In reply to Sosale:

In this case, an array of covergroups is needed to cover signals in an array of instances.

*In reply to dave_59:*o

Hello Dave,

Thanks for the reply. I need to cover the variables which are defined in packet class. Now how to cover these packet class variable in coverage model class without using the dot operator(Hierarchical reference). Alongwith, these are all unpacked array variabels defined in packet class. Please guide.

Regards
Sunil.

In reply to sunils:

You just need to pass each element of the array into the covergroup

covergroup cg(ref bit [3:0] bye); 
  coverpoint bye;
...
endgroup

foreach (hello.bye[i]) cg_inst[i] = new (hello.bye[i]);

In reply to dave_59:

In reply to kvenkatv:
This should get you started

package global_types;
typedef bit [31:0] uint;
typedef uint uint_da[];
endpackage
module bot;
import global_types::*;
uint sig;
endmodule
module top;
import global_types::*;
bit clk;
uint_da encodings = onehots();
function uint_da onehots;
onehots = new[32];
foreach (onehots[i]) onehots[i] = 32'b1 << i;
endfunction : onehots
covergroup cg(ref uint arg)  @(posedge clk);
option.per_instance = 1;
coverpoint arg {
bins b[] = encodings;
}
endgroup : cg
genvar i;
for (i = 0; i<32;i++) begin : g_regs
bot u();
end
for (i = 0; i<32;i++) begin
cg cg_inst;
initial cg_inst = new(g_regs[i].u.sig);
end
endmodule : top

Just wanted to clarify should it be cg_inst[32] instead of cg_inst?


...
  cg cg_inst[32];
  genvar i;
   for (i = 0; i<32;i++) begin : g_regs
      bot u();
   end
   for (i = 0; i<32;i++) begin
      initial cg_inst[i] = new(g_regs[i].u.sig);

In reply to dave_59:

Could you able to help me with genvar? With usage and purpose??

1 Like