Coverage for an array

Hi

i have a 8 bit dynamic array for which i want to add coverage with min,mid,max values.

bit [7:0] val ;

val is actually a single variable which is parsed like an array divided into 8bits.

And we want coverage for bins with 0-mid value , mid-max value that val can be.

how to achieve this.

Thank you!

In reply to theketi:
It is hard to understand your requirements. Can you show some example data and the coverage calculations you need to reach 100%.

In reply to dave_59:

Sure.

i have a big random variable 256bit which is something like
256’h7810d14500156891a8ff… etc

and its generated as an array of 8 bits
val[0] = 8’d78;
val[1] = 8’d0d;
val[2] = 8’d14;
and so on …

i want coverage for val variable to see if we hit the maximum value possible. which is max 256bit value , if it hit 0 and if it hit a medium value between 0 and max value for 256 bits.

for this i have to cover array values and put it together as one value and get coverage on it.
i already have everything else working so , i cannot change from array to single value.
hope its clear. let me know if you have questions.

In reply to theketi:

Much clearer, thanks.

covergroup cg;
      min: coverpoint val.or() == 0;
      max: coverpoint val.and() == 8'hFF;
      mid: cross min,max;
endgroup

In reply to dave_59:

Thank you Dave, just for my understanding,

bitwise OR of all array values= 0 will be minimum value
bitwise AND of all array values similarly wont it be 1? (if all bits are 1)

also if we want to do a cover point for range how to achieve this
0:maxval /2
maxval /2 : maxval

Thanks

In reply to theketi:
The array reduction methods and() and or() perform bitwise operations between each element, and the result is the same type as each element, in your case
bit 7:0]
. Same as val[0] & val[1] & … & val[7].

If the array always contains the same number of bits, you can cast to a fixed size integral value. Then you can bin whatever ranges you want

typedef bit [255:0] uint256_t;

cp: coverpoint uint256_t'(val) {
   bins a[] = {[0:maxval/2], [maxval/2:maxval]};
}

If the array is not a fixed size, you will need to get more creative with your covergroup expressions to represent your ranges. Perhaps write a function that returns an encoded value of each range you want detected.

In reply to dave_59:

Thank you so much for the explanation.
Its a dynamic array.

How about if the Array is dynamic, Is it possible to declare dynamic array as coverpoint

In reply to ganesh_b:

Below example shows how to declare the covergroup for dynamic array.



bit[7:0] dyn_array[];

covergroup cg_array with function sample(int i);
  c1: coverpoint dyn_array[i];
endgroup

//  sampling the covergroup can be done using loop 

foreach(dyn_array[i])
 cg_array.sample(i);