bit arry[2:0] ;
How do I constraint the size of multidimensional array ?
I am looking for like how we initial the size of dynamic array . rand bit [2:0] my_array ;
constraint c {my_array.size==6;}
Is it possible to define the size of multidimensional array too ?
Thanks in advance !!
Please refer to the LRM section 18.5.8.1 foreach iterative constraints, this is actually an array of arrays so eachb individual array can have a different size
Also this might help you
class multiD_array;
rand bit [2:0] arry [] [] ;
constraint size_c{
arry.size() == 4; // set the total of arrays in arry
foreach(arry[i]) {
arry[i].size() inside {[1:3]}; //set the size of each array in arry
}
}
endclass
module test();
multiD_array h;
initial begin
repeat(2) begin
h = new();
if(!h.randomize()) $fatal(1, "Randomize Failed");
$display("h %p", h);
end
end
endmodule
# KERNEL: h '{arry:'{'{1, 2, 2}, '{2, 7}, '{4, 6, 0}, '{6}}}
# KERNEL: h '{arry:'{'{4, 6, 3}, '{1, 3}, '{2}, '{1, 7}}}