There are 2 things you need to do
- Declare the array elements with an unsigned type. Either
int unsignedorbit [N:0] - The
sum()needs to be calculated in a context with no overflow. With 8 elements in the array, you need at least 3 extra bits.
class sample;
rand bit[3:0] arr[2][4]; // implicitly constrained to values 0-15
constraint xy {
arr.sum(row) with (row.sum(col) with ( 8'(col) )) == 10;
}
endclass