How to define a condition for a covergroup (using iff)?

Hello,

is it possible to write something like that ? (yes, getting error here)

covergroup condition_cfg_cg iff (config_ind == 1);
condition_id : coverpoint cond_id ;
condition_type : coverpoint event_cond;
condition_var : coverpoint start_var {
bins var_val[3] = {[0:10], [11:40], [40:63]};
};
endgroup

Thanks !

In reply to Noga_Tamir_V:

Not exactly sure how you want the condition to affect the covergroup, but maybe you simply want to use the condition when you construct the covergroup.

if (config_ind == 1) condition_cfg_cg = new();

In reply to dave_59:

Hi Dave,

Thanks for the answer. what i meant is that as we got condition for a cover point such as :

condition_type : coverpoint cond_val iff (event_cond inside {TIME} );

i wondered if i can write one for the covergroup.

Thanks

u could do by two ways

  1. use the sample method to trigger the cover group if the condition occurs.

i.e if(condition)
covergroup_name.sample()

  1. Suppose if you want to pass any value to the covergroup so that coverpoints could use that value then you can declare covergoup as the below example:
covergroup condition_cfg_cg with function sample(bit config_ind);
 
  cp_check : coverpoint value iff(config_ind == 1'b1); 
 endcovergroup

In reply to nchakravarthy:

Thanks !

In reply to dave_59:

Hello Dave,

I am getting fatal when i did constructing the covergoup under condition as you mentioned.

Fatal error reported during simulation. Cannot run ‘fcover’ command. Please look above output for the fatal error message(s).

I am working on UVM Based environment.If i have used as below also i am getting errors.

covergroup cov_sample iff(en) (params) @(triggering condition);

In reply to TransVerif:

You cannot use iff in the declaration of a covergroup. Please re-read this entire thread, then post the code you are trying to use and the error message you are getting.

In reply to dave_59:

I tried two different ways like below, but both ways give me syntax error in compilation. Can you please help?

`define ABC\
    if (type_a == XYZ)
    	bins out_bound[] = {[10:18],[37:45]};
    if (type_a == PQR)
    	bins ou_bound[] = {5,[10:18],25,[37:45]};

`define DEF\
	bins out_bound[] = {[10:18],[37:45]} iff (type_a == XYZ) or {5,[10:18],25,[37:45]} iff (type_a == PQR);

In reply to darp4u:


cp1 : coverpoint type_a iff(type_a == XYZ){
                       bins out_bound[] = {[10:18],[37:45]};
                       }
cp2 : coverpoint type_a iff(type_a == PQR){
                       bins ou_bound[] = {5,[10:18],25,[37:45]};     
                       }

In reply to Rahulkumar Patel:

thank you, i ll try what you said above and let you know.

I am also facing issue with doing this. How do i have same two different bin definition with iff condition. I dont want to change bings name out_bound

`define ABC
bins out_bound = {[10:15],[20:25],[30:35]} iff (type_a == XYZ) or {2,[10:15],17,[20:25],27,[30:35]} iff (type_a == PQR);

In reply to darp4u:

In reply to Rahulkumar Patel:
`define ABC
bins out_bound = {[10:15],[20:25],[30:35]} iff (type_a == XYZ) or {2,[10:15],17,[20:25],27,[30:35]} iff (type_a == PQR);

This isn’t correct.

you can use same bin name in different coverpoint.


//same bin name out_bound in 2 different coverpoint
cp1 : coverpoint type_a iff(type_a == XYZ){
                       bins out_bound[] = {[10:18],[37:45]};
                       }
cp2 : coverpoint type_a iff(type_a == PQR){
                       bins out_bound[] = {5,[10:18],25,[37:45]};     
                       }

if you don’t want to create 2 different cover point.


cp : coverpoint type_a { 
                      bins out_bound_pqr[] = {[10:18],[37:45]} iff(type_a == PQR);
                      bins out_bound_xyz[] = {5,[10:18],25,[37:45]} iff(type_a == XYZ);
                       }


In reply to Rahulkumar Patel:

This isn’t correct either. iff is only a guard against sampling a covergroup/point/bin. It has no place in construction. The with clause gets used in defining bins.

cp : coverpoint type_a { 
                      bins out_bound_pqr[] = {[10:18],[37:45]} with(type_a == PQR);
                      bins out_bound_xyz[] = {5,[10:18],25,[37:45]} with (type_a == XYZ);
}

This will likely generate a warning message saying you have an empty bin set.

In reply to dave_59:

Hi Dave,

From SV_LRM std 1800-2017, 19.5.1 Specifying bins for values
The expression within the iff construct at the end of a bin definition provides a per-bin guard condition. If the expression is false at a sampling point, the count for the bin is not incremented.

bins_keyword bin_identifier [ [ ] ] = trans_list [ iff ( expression ) ]


//This is working fine for me. i am able to dump the correct collected coverage value also.

cp : coverpoint type_a { 
                      bins out_bound_pqr[] = {[10:18],[37:45]} iff(type_a == PQR);
                      bins out_bound_xyz[] = {5,[10:18],25,[37:45]} iff(type_a == XYZ);
                       }

In reply to dave_59:

so can I use `define using with, like below?

`define ABC
bins out_bound = {[10:15],[20:25],[30:35]} with (type_a == XYZ) or {2,[10:15],17,[20:25],27,[30:35]} with (type_a == PQR);

In reply to Rahulkumar Patel:

You can collect coverage, but the calculation is incorrect.

If the expression is false at a sampling point, the count for the bin is not incremented.

The problem here is the bin gets created unconditionally, but is never incremented.

In reply to darp4u:

You can use `define for anything&mdash the macro pre-processor does not care about SystemVerilog syntax. But the end result has to be valid SystemVerilog to finish compilation.

In reply to dave_59:

In reply to Rahulkumar Patel:
You can collect coverage, but the calculation is incorrect.
The problem here is the bin gets created unconditionally, but is never incremented. If the expression is false at a sampling point, the count for the bin is not incremented.

Yes,bin gets created unconditionally.
Bin is incremented if expression is true and is not incremented when expression is false.


module check_cov; 

  int XYZ,PQR;
  int type_a;
  
  covergroup cg;
      cp : coverpoint type_a { 
                      bins out_bound_pqr[2] = {[37:38]} iff(type_a == PQR);
                      bins out_bound_xyz[3] = {[10:12]} iff(type_a == XYZ);
                       }
  endgroup
  
  cg m_cg;
  
  initial 
  begin
  XYZ = 0; type_a=10;  PQR = 0;
  m_cg = new();
  #5; PQR=0; XYZ=10; type_a=10; m_cg.sample(); #10; $display("COV : %f", m_cg.get_coverage()); // 20%
  #5; PQR=0; XYZ=15; type_a=10; m_cg.sample(); #10; $display("COV : %f", m_cg.get_coverage()); // 20% No change
  #5; PQR=37; XYZ=10; type_a=37; m_cg.sample(); #10; $display("COV : %f", m_cg.get_coverage()); // 40% 
  $finish;
  end 

endmodule


//output as expected: 
COV : 20.000000
COV : 20.000000
COV : 40.000000




In reply to Rahulkumar Patel:

I think you are confusing the goal behind the original question. This is why it’s usually a better practice to start a question in a new thread than tacking on to an existing question.

I believe they want conditional bin construction, not conditional sampling. Otherwise you wont up unable to get 100% coverage of your coverpoint.

In reply to dave_59:


covergroup dst_addr_cov @(dst_addr_event);
dst_addr_cp: coverpoint cov_dst_addr { ignore_bins invalid_dst_addr = {19, 24, [65:$]} with (cov_dst_addr != agent_num);} // illegal operand error
//dst_addr_cp: coverpoint cov_dst_addr { ignore_bins invalid_dst_addr = {19, 24, [65:$]} iff (cov_dst_addr != agent_num);} // compile clean
endgroup : fifoic_dst_addr_cov


 I trying to ignore if the cov_dst_addr is equal to agent_num ignore cov_dst_addr bins for that scenarios, and an invalid address as well