How to create the cover group's bins that based on array's values

I wrote a covergroup that receives an array and builds the bins according to it, how can I make it so that a bin is built for each of the indexes of the array when its size is not known? My code now looks like this:

covergroup fxp_reg_access_cg(string maps_name[], uvm_reg_addr_t maps_base[], uvm_reg_addr_t maps_size[$]) with function sample(uvm_reg_addr_t address );

accessed_block_cp : coverpoint address {

  bins maps_name[0] = {[ maps_base[0] : (maps_base[0] + maps_size[0] -1)]};

  bins maps_name[1] = {[ maps_base[1] : (maps_base[1] + maps_size[1] -1)]}; 

  bins maps_name[2] = {[ maps_base[2] : (maps_base[2] + maps_size[2] -1)]}; 

  bins out_of_blocks = default;

}
endgroup

In reply to faigenboim:

The size of the array must be known before constructing any covergroups.

You could create an array of covergroups, one for each range. You just need to make sure that the each element of the array gets sampled, or only sample the covergroup array element that is in the range.

covergroup fxp_reg_access_cg(string maps_name, uvm_reg_addr_t maps_base, uvm_reg_addr_t maps_size) with function sample(uvm_reg_addr_t address );
  option.per_instance = 1;
  option.name = maps_name;
  accessed_block_cp : coverpoint address {
    bins maps_name[2] = {[ maps_base[2] : (maps_base[2] + maps_size[2] -1)]};
  }
endgroup

fxp_reg_access_cg fxp_ra_cg[];

fxp_ra_cg = new[my_maps_name.size];
foreach(fxp_ra_cg[i]) fxp_ra_cg[i] = new(...);

Another option is creating a function map_range that returns a value 0 to N-1, where N is the size of the array. Then set up your coverpoint bins

accessed_block_cp : coverpoint map_range(address) {
  bins maps[N] = {[0:N-1]};
}

In reply to dave_59:

Thanks DAVE,
I liked this way, but I’m a bit confused by it

In reply to faigenboim:

accessed_block_cp : coverpoint map_range(address) {
bins maps[N] = {[0:N-1]};
}

I tried to make code like this:

 
   virtual function void start_of_simulation_phase(uvm_phase phase);
        super.start_of_simulation_phase(phase);
        fxp_reg_access_cg = new(cfg.maps_name);
        foreach (cfg.maps_name[i])
            maps_cg[i] = new(cfg.maps_name[i], cfg.maps_base_addr[i], cfg.maps_end_addr[i], cfg.maps_num_of_bins[i]);
        
    endfunction : start_of_simulation_phase
    
    virtual function int get_block(uvm_reg_addr_t addr);
        foreach (cfg.maps_name[i]) begin
            if(addr>= cfg.maps_base_addr[i] && addr<= cfg.maps_end_addr[i])
                return i;
        end
        return -1;
    endfunction 
    
    covergroup fxp_reg_access_cg(string maps_name[$]) with 
        function sample(svt_apb_transaction apb_transaction, ipu_uvm_reg accessed_reg, bit access_is_valid, 
        bit[4:0] accessed_reg_type, bit[2:0] dfd_fusees, bit func_rst_raw, bit rst_pre);
        
        accesse_blocks_cp : coverpoint get_block(apb_transaction.address) {
            bins maps[]  = {[0:maps_name.size()-1]};
            bins out_of_blocks = default;
        }
.....
endgroup

but I got compilation error:

Error-[PCECGNNA] Improper new call to embedded covergroup
/nfs/site/disks/mmg.fxp.integ.2/USERS/smilgrom/fxp_19_04/src/val/common/ip_lib/fxp_cs
Procedural call to ‘new’ of embedded covergroup
fxp_csr_apb_coverage::fxp_reg_access_cg not allowed outside new function of
encompassing class fxp_csr_apb_coverage or its derived classes.

I cannot call to ‘new’ in the new function off class because then the array has not yet been initialized (and its size is unknown)
And if I define the covergroup as external to the class then it will not have access to the get_block function.

Is there a way to overcome the problem?

In reply to faigenboim:

You can move the covergroup definition outside the class. Everything it needs is being based as arguments and there is no more need to embed it in the class.

In reply to dave_59:

Hi Dave,
Thanks for the response, but maybe I didn’t explain myself enough-
One of my coverpoints is based on the get_block function that is defined in the class, if I define the covergroup as external then it does not know the function

In reply to faigenboim:
You can pass a handle as a covergroup argument.


typedef class my_component;
covergroup fxp_reg_access_cg(my_component handle, string maps_name, uvm_reg_addr_t maps_base, uvm_reg_addr_t maps_size) with function sample(uvm_reg_addr_t address );
        accesse_blocks_cp : coverpoint handle.get_block(apb_transaction.address) {
...
endgroup
class my_component;
  virtual function void start_of_simulation_phase(uvm_phase phase);
        super.start_of_simulation_phase(phase);
        fxp_reg_access_cg = new(cfg.maps_name);
        foreach (cfg.maps_name[i])
            maps_cg[i] = new(this, cfg.maps_name[i], cfg.maps_base_addr[i], cfg.maps_end_addr[i], cfg.maps_num_of_bins[i]);
    endfunction : start_of_simulation_phase
...
endclass


In reply to dave_59:

There is a possibility that the bins will receive the map_names and not be numbered in map0, map1…?
Thank you
you helped me alot