Verif
March 21, 2020, 2:51pm
1
How to write functional coverage for an array of 128 elements where each element is of 8-bit width?
Example:
rand bit [7:0]data[127:0];
I want to check if any value between {8’d1,8’d2,8’d4,8’d8,8’d16,8’d32,8’d64,8’d128,8’d255} is covered or not for each element of the array i.e. for 128 elements and display the 128 bins info
In reply to djmandela :
Maybe you can do something like this
module array_covergroup_test();
bit [7:0] data[127:0];
bit [7:0] values [$] = {8'd1,8'd2,8'd4,8'd8,8'd16,8'd32,8'd64,8'd128,8'd255};
covergroup array_cg with function sample (int index);
element_inside_cp : coverpoint (data[index] inside {values}) {
bins valid = {1};
}
endgroup
array_cg cg;
initial begin
cg = new();
foreach (data[i]) begin
data[i] = $urandom_range(0, 255);
cg.sample(i);
end
$display("array_cg instance coverage = %0f", cg.get_inst_coverage());
end
endmodule
HTH,
-R
Verif
March 22, 2020, 4:56pm
3
Thank you, but can we generate separate bins for each value
In reply to djmandela :
This is another implementation, where bin is created for each values per index basis.
module array_covergroup_test();
bit [7:0] data[127:0] ;
bit [7:0] values [$] = {8'd1,8'd2,8'd4};
covergroup array_cg (int index);
option.per_instance = 1;
coverpoint data[index] {
bins value[] = {8'd1,8'd2,8'd4}; //{values};
}
endgroup
array_cg cg[128];
initial begin
foreach(cg[i])begin
cg[i] = new(i);
end
repeat(100)begin
std::randomize(data);
foreach(cg[i])begin
cg[i].sample();
end
end
end
endmodule // array_covergroup_test
In reply to djmandela :
I understood you wanted to cover if any of the array values was in the set you mentioned, yourcheers’ solution is what you are probably looking for.
Verif
March 26, 2020, 4:44pm
7
Yes it works. I actually wanted to check if each bit of the variable “data” toggles or not that too for the entire depth of the array (128).