Coverage for 2D Matrix

I am trying to write a coverage for a 2D matrix where at any given time either one row can have 1 one’s or one column can have 1 one’s. Since system verilog coverage doesnt support unpacked array directly we slice it and send it to covergroup.

covergroup cg with function sample(bit a[3]);
// For rows i can do like this and for all rows
coverpoint $countones(a[0]) {bins row0 = {1}};
endcovergroup

For columns i may need a helper array and transpose the matrix to have column values and then can write coverpoints explicitly.

Questions

  1. why does system verilog doesnt support foreach syntax in covergroup?
  2. Even though i write and this will will satisfy given condition. Let’s say if i want to check the position where all the 1’s are present. The 1’s can be anywhere in a row or column so total of expecting 9 one’s based on location. How do we write bins for that?
  3. Is there any other way to write coverpoints which are simple?

You can create a 2D array of covergroups for each element of the matrix to see if they have been set. Remember that coverage is not a checker, so something else needs to make sure the matrix has valid values.