Hi There,
Can I have a local variable in a covergroup?
Can I have a user defined new function for a covergroup?
Thanks,
Sunil.
Hi There,
Can I have a local variable in a covergroup?
Can I have a user defined new function for a covergroup?
Thanks,
Sunil.
In reply to dave_59:
I am trying to do something like below (not exactly same but similar).
covergroup TYPE_t2_cg with function sample(TYPE_t2 item);
option.per_instance = 1;
bit signed [`NUM:0] min;
bit signed [`NUM:0] max;
byte data_type;
byte data_size;
function new(byte d_type, byte d_size);
data_type = d_type;
data_size = d_size;
if(data_type == 1) begin
min = 0;
max = (2**data_size);
end
else if(data_type == 2) begin
min = (2**data_size+1);
max = (3**data_size);
end
endfunction
cp_opA : coverpoint item.opA
{
bins b_min = { min };
bins b_lower = {[(min+ 1):(min+10)]};
bins b_intermediate = {[(min+11):(max-11)]};
bins b_higher = {[(max-10):(max- 1)]};
bins b_max = { max };
}
endgroup
function void some_function(TYPE_t1 s);
TYPE_t2_cg i_cg[byte][byte];
TYPE_t2 item;
item.map(s);
if(NULL == i_cg[s.data_type][s.data_size]) begin
i_cg[s.data_type][s.data_size] = new(s.data_type, s.data_size);
end
i_cg[s.data_type][s.data_size].sample(item);
endfunction
In reply to KumarSunilB:
You could do this as a function before constructing the covergroup
typedef bit signed [`N:0] intN;
function void TYPE_t2_new(input byte data_type, data_size, output intN min, max);
if(data_type == 1) begin
min = 0;
max = (2**data_size);
end
else if(data_type == 2) begin
min = (2**data_size+1);
max = (3**data_size);
end
endfunction
covergroup TYPE_t2_cg(intN min, max) with function sample(TYPE_t2 item);
option.per_instance = 1;
cp_opA : coverpoint item.opA
{
bins b_min = { min };
bins b_lower = {[(min+ 1):(min+10)]};
bins b_intermediate = {[(min+11):(max-11)]};
bins b_higher = {[(max-10):(max- 1)]};
bins b_max = { max };
}
endgroup
function void some_function(TYPE_t1 s);
intN min, max;
TYPE_t2_cg i_cg[byte][byte];
TYPE_t2 item;
item.map(s);
if(NULL == i_cg[s.data_type][s.data_size]) begin
TYPE_t2_new(s.data_type, s.data_size, min, max)
i_cg[s.data_type][s.data_size] = new(min, max);
end
i_cg[s.data_type][s.data_size].sample(item);
endfunction
In reply to dave_59:
Thanks Dave.
However I see issue in the following line
→ if(0 == i_cg[s.data_type][s.data_size])
Is it legal to check if the covergroup is initialized or not by comparing it to 0?
Sunil.
In reply to KumarSunilB:
handles can only be compared to other handles or NULL. so 0 is not allowed.