How do I write a cover group for each element in a multidimensional array to be unique. For example, Is this a correct method to write a cover group for all elements in “int addr[4][4]” to be unique?
covergroup cg @(posedge clk);
coverpoint addr
{
bins uni = unique array[4][4];
}
endgroup
In reply to sfenil1804:
Unfortunately, The unique construct is only defined in a constraint. So you could wrap the constraint in a call to randomize with no random variables.
module top;
int addr[4][4];
function bit uniq;
return randomize() with {unique {addr};};
endfunction
covergroup cg;
in: coverpoint uniq() {
bins uniq = {1};
}
endgroup
cg c=new;
initial begin
c.sample;
addr = '{{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}};
c.sample;
end
endmodule
Can I use this approach?
module top;
int addr[4][4];
function bit uniq (ref addr);
bit uniq_yes,uniq_no;
foreach (addr[i,j])
foreach (addr[a,b])
if !(i==a && j==b)
if (addr[i,j] != addr[a,b]) begin
uniq_yes = 1;
end else begin
uniq_no = 1;
end
return uniq_yes && (~uniq_no);
endfunction
covergroup cg;
in: coverpoint uniq(addr) {
bins uniq = {1};
}
endgroup
endmodule
In reply to sfenil1804:
Yes, but I’m sure you forgot that uniq_yes,uniq_no are static variables that don’t get reset to 0 each time the function gets called. But you don’t need these variables. You could have written
function bit uniq (ref addr);
foreach (addr[i,j])
foreach (addr[a,b])
if !(i!=a && j!=b)
if (addr[i,j] == addr[a,b])
return 0;
// can only get here if addr is unique
return 1;
endfunction
In reply to dave_59:
Yes, I missed that. Thanks for pointing out!